generated from pyiron/pyiron_module_template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restructering/modularizyation of the node library
Optimized import statements in nodes (pyiron_atomistics -> ase atom object) reduces import time from 5s to < 50 ms! Implementation of universal force field M3GNet
- Loading branch information
Showing
8 changed files
with
617 additions
and
345 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
from pyiron_workflow.function import single_value_node, function_node | ||
|
||
|
||
@single_value_node() | ||
def static(atoms=None, engine=None, _internal=None): | ||
if engine is None: | ||
from ase.calculators.emt import EMT | ||
|
||
engine = EMT() | ||
|
||
atoms.calc = engine | ||
|
||
out = {} | ||
# out['structure'] = atoms # not needed since identical to input | ||
out["forces"] = atoms.get_forces() | ||
out["energy"] = atoms.get_potential_energy() | ||
if _internal is not None: | ||
out["iter_index"] = _internal[ | ||
"iter_index" | ||
] # TODO: move _internal argument to decorator class | ||
return out | ||
|
||
|
||
@function_node("structure", "out") | ||
def minimize(atoms=None, engine=None, fmax=0.005, log_file="tmp.log"): | ||
from ase.optimize import BFGS | ||
import numpy as np | ||
|
||
if engine is None: | ||
from ase.calculators.emt import EMT | ||
|
||
engine = EMT() | ||
|
||
atoms.calc = engine | ||
|
||
if log_file is None: # write to standard io | ||
log_file = "-" | ||
|
||
dyn = BFGS(atoms, logfile=log_file) | ||
dyn.run(fmax=fmax) | ||
|
||
# it appears that r0 is the structure of the second to last step (check) | ||
atoms_relaxed = atoms.copy() | ||
atoms_relaxed.calc = atoms.calc | ||
if dyn.r0 is not None: | ||
atoms_relaxed.positions = dyn.r0.reshape(-1, 3) | ||
|
||
out = {} | ||
out["relaxed_structure"] = atoms_relaxed | ||
# out["forces"] = dyn.f0.reshape(-1, 3) | ||
out["forces"] = atoms_relaxed.get_forces() | ||
out["energy"] = atoms_relaxed.get_potential_energy() | ||
out["energy_initial"] = atoms.get_potential_energy() | ||
print("energy: ", out["energy"], "max_force: ", np.min(np.abs(out["forces"]))) | ||
|
||
return atoms_relaxed, out | ||
|
||
|
||
nodes = [ | ||
static, | ||
minimize, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from pyiron_workflow.function import single_value_node | ||
|
||
|
||
@single_value_node("engine") | ||
def EMT(): | ||
from ase.calculators.emt import EMT | ||
|
||
return EMT() | ||
|
||
|
||
@single_value_node("engine") | ||
def M3GNet(): | ||
import matgl | ||
from matgl.ext.ase import M3GNetCalculator | ||
|
||
return M3GNetCalculator(matgl.load_model("M3GNet-MP-2021.2.8-PES")) | ||
|
||
|
||
nodes = [ | ||
EMT, | ||
M3GNet, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
...kflow/node_library/structure_transform.py → ...kflow/node_library/structure/transform.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters