Skip to content

Commit

Permalink
- save latest jupyter notebooks and function_nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
JNmpi committed May 1, 2024
1 parent 4b3874f commit b69ca0b
Show file tree
Hide file tree
Showing 14 changed files with 4,894 additions and 3,881 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ _build/
apidoc/
.ipynb_checkpoints/
test_times.dat
.aider*
4,132 changes: 2,518 additions & 1,614 deletions notebooks/phonopy_wf.ipynb

Large diffs are not rendered by default.

4,534 changes: 2,321 additions & 2,213 deletions notebooks/pyiron_like_workflows.ipynb

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyiron_workflow/node_library/atomistic/calculator/ase.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pyiron_workflow.function import single_value_node, function_node
from pyiron_workflow.function import function_node


@single_value_node()
@function_node()
def static(atoms=None, engine=None, _internal=None, keys_to_store=None):
from pyiron_workflow.node_library.atomistic.calculator.data import OutputCalcStatic

Expand Down
4 changes: 2 additions & 2 deletions pyiron_workflow/node_library/atomistic/calculator/generic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pyiron_workflow.function import single_value_node
from pyiron_workflow.function import function_node

from pyiron_workflow.node_library.atomistic.calculator.data import (
InputCalcMinimize,
Expand All @@ -7,7 +7,7 @@
)


@single_value_node("generic")
@function_node("generic")
def static(structure=None, engine=None): # , keys_to_store=None):
output = engine(
structure=structure,
Expand Down
6 changes: 3 additions & 3 deletions pyiron_workflow/node_library/atomistic/engine/ase.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from pyiron_workflow.function import single_value_node
from pyiron_workflow.function import function_node


@single_value_node("engine")
@function_node("engine")
def EMT():
from ase.calculators.emt import EMT

return EMT()


@single_value_node("engine")
@function_node("engine")
def M3GNet():
import matgl
from matgl.ext.ase import M3GNetCalculator
Expand Down
38 changes: 19 additions & 19 deletions pyiron_workflow/node_library/atomistic/engine/lammps.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# from pyiron_atomistics.atomistics.structure.atoms import Atoms

from pyiron_workflow.function import single_value_node, function_node
from pyiron_workflow.function import function_node, function_node
from pyiron_workflow.workflow import Workflow

from pyiron_workflow.node_library.atomistic.calculator.data import (
Expand All @@ -20,53 +20,53 @@
from pyiron_atomistics.lammps.control import LammpsControl


@single_value_node("calculator")
@function_node("calculator")
def Calc(parameters):
from pyiron_atomistics.lammps.control import LammpsControl

calculator = LammpsControl()

if isinstance(parameters, InputCalcMD):
calculator.calc_md(**parameters)
calculator._mode = "md"
calculator.mode = "md"
elif isinstance(parameters, InputCalcMinimize):
calculator.calc_minimize(**parameters)
calculator._mode = "minimize"
calculator.mode = "minimize"
elif isinstance(parameters, InputCalcStatic):
calculator.calc_static(**parameters)
calculator._mode = "static"
calculator.mode = "static"
else:
raise TypeError(f"Unexpected parameters type {parameters}")

return calculator


@single_value_node("calculator")
@function_node("calculator")
def CalcStatic(calculator_input: Optional[InputCalcStatic | dict] = None):
calculator_kwargs = parse_input_kwargs(calculator_input, InputCalcStatic)
calculator = LammpsControl()
calculator.calc_static(**calculator_kwargs)
calculator._mode = "static"
calculator.mode = "static"

return calculator


@single_value_node("calculator")
@function_node("calculator")
def CalcMinimize(calculator_input: Optional[InputCalcMinimize | dict] = None):
calculator_kwargs = parse_input_kwargs(calculator_input, InputCalcMinimize)
calculator = LammpsControl()
calculator.calc_minimize(**calculator_kwargs)
calculator._mode = "static"
calculator.mode = "static"

return calculator


@single_value_node("calculator")
@function_node("calculator")
def CalcMD(calculator_input: Optional[InputCalcMD | dict] = None):
calculator_kwargs = parse_input_kwargs(calculator_input, InputCalcMD)
calculator = LammpsControl()
calculator.calc_md(**calculator_kwargs)
calculator._mode = "md"
calculator.mode = "md"

return calculator

Expand All @@ -89,13 +89,13 @@ def InitLammps(structure=None, potential=None, calculator=None, working_director

calculator.write_file(file_name="control.inp", cwd=working_directory)
bla = "bla"
# print("Lammps_init: ", calculator._mode, bla)
# print("Lammps_init: ", calculator.mode, bla)

# return os.path.abspath(working_directory), calculator._mode, bla
# return os.path.abspath(working_directory), calculator.mode, bla
return os.path.abspath(working_directory), bla


@single_value_node("log")
@function_node("log")
def ParseLogFile(log_file):
from pymatgen.io.lammps.outputs import parse_lammps_log

Expand All @@ -107,7 +107,7 @@ def ParseLogFile(log_file):
return log


@single_value_node("dump")
@function_node("dump")
def ParseDumpFile(dump_file):
from pymatgen.io.lammps.outputs import parse_lammps_dumps

Expand Down Expand Up @@ -171,7 +171,7 @@ class GenericOutput:
forces = []


@single_value_node()
@function_node()
def Collect(
out_dump,
out_log,
Expand All @@ -194,7 +194,7 @@ def Collect(
elif isinstance(calc_mode, (InputCalcMinimize, InputCalcMD, InputCalcStatic)):
calc_mode = calc_mode.__class__.__name__.replace("InputCalc", "").lower()
elif isinstance(calc_mode, LammpsControl):
calc_mode = calc_mode._mode
calc_mode = calc_mode.mode
else:
raise ValueError(f"Unexpected calc_mode {calc_mode}")

Expand All @@ -217,7 +217,7 @@ def Collect(
return generic


@single_value_node("potential")
@function_node("potential")
def Potential(structure, name=None, index=0):
from pyiron_atomistics.lammps.potential import list_potentials as lp

Expand All @@ -232,7 +232,7 @@ def Potential(structure, name=None, index=0):
return pot


@single_value_node("potentials")
@function_node("potentials")
def ListPotentials(structure):
from pyiron_atomistics.lammps.potential import list_potentials as lp

Expand Down
10 changes: 5 additions & 5 deletions pyiron_workflow/node_library/atomistic/property/elastic.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import numpy as np

from pyiron_workflow.function import single_value_node
from pyiron_workflow.function import function_node
from pyiron_workflow.node_library.dev_tools import wf_data_class
from dataclasses import field

Expand Down Expand Up @@ -39,7 +39,7 @@ class DataStructureContainer:
stress: list = field(default_factory=lambda: [])


@single_value_node()
@function_node()
def elastic_constants(structure, calculator=None, engine=None):
structure_table = generate_structures(structure).run()

Expand All @@ -63,7 +63,7 @@ def elastic_constants(structure, calculator=None, engine=None):
return elastic


@single_value_node()
@function_node()
def symmetry_analysis(structure, parameters: InputElasticTensor = InputElasticTensor()):
out = OutputElasticSymmetryAnalysis(structure)

Expand All @@ -78,7 +78,7 @@ def symmetry_analysis(structure, parameters: InputElasticTensor = InputElasticTe
return out


@single_value_node("structures")
@function_node("structures")
def generate_structures(
structure, parameters: InputElasticTensor = InputElasticTensor()
):
Expand Down Expand Up @@ -168,7 +168,7 @@ class OutputElasticAnalysis:
C_eigval: np.ndarray = field(default_factory=lambda: np.zeros(0))


@single_value_node("structures")
@function_node("structures")
def analyse_structures(
data_df: DataStructureContainer,
parameters: InputElasticTensor = InputElasticTensor(),
Expand Down
14 changes: 7 additions & 7 deletions pyiron_workflow/node_library/atomistic/property/phonons.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


# from pyiron_workflow.macro import Macro, macro_node
from pyiron_workflow.function import single_value_node, function_node
from pyiron_workflow.function import function_node, function_node
from pyiron_workflow.node_library.dev_tools import wf_data_class, parse_input_kwargs


Expand All @@ -22,7 +22,7 @@ class InputPhonopyGenerateSupercells:
max_distance: Optional[float] = None


# @single_value_node()
# @function_node()
def generate_supercells(phonopy, parameters: InputPhonopyGenerateSupercells):
from structuretoolkit.common import phonopy_to_atoms

Expand All @@ -32,7 +32,7 @@ def generate_supercells(phonopy, parameters: InputPhonopyGenerateSupercells):
return supercells


@single_value_node("parameters")
@function_node("parameters")
def PhonopyParameters(
distance: float = 0.01,
is_plusminus: Union[str, bool] = "auto",
Expand Down Expand Up @@ -89,7 +89,7 @@ def create_phonopy(
return phonopy, out


@single_value_node()
@function_node()
def get_dynamical_matrix(phonopy, q=[0, 0, 0]):
import numpy as np

Expand All @@ -101,15 +101,15 @@ def get_dynamical_matrix(phonopy, q=[0, 0, 0]):
return dynamical_matrix


@single_value_node()
@function_node()
def get_eigenvalues(matrix):
import numpy as np

ew = np.linalg.eigvalsh(matrix)
return ew


@single_value_node()
@function_node()
def check_consistency(phonopy, tolerance: float = 1e-10):
dyn_matrix = get_dynamical_matrix(phonopy).run()
ew = get_eigenvalues(dyn_matrix).run()
Expand All @@ -123,7 +123,7 @@ def check_consistency(phonopy, tolerance: float = 1e-10):
return has_imaginary_modes


@single_value_node()
@function_node()
def get_total_dos(phonopy, mesh=3 * [10]):
from pandas import DataFrame

Expand Down
12 changes: 6 additions & 6 deletions pyiron_workflow/node_library/atomistic/structure/build.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from pyiron_workflow.function import single_value_node
from pyiron_workflow.function import function_node
from pyiron_workflow.workflow import Workflow


@single_value_node("structure")
@function_node("structure")
def bulk(
name,
crystalstructure=None,
Expand Down Expand Up @@ -36,11 +36,11 @@ def cubic_bulk_cell(
repeat,
)

wf.structure = bulk(name=element, cubic=True)
wf.cell = repeat(structure=wf.structure, repeat_scalar=cell_size)
wf.bulk = bulk(name=element, cubic=True)
wf.cell = repeat(structure=wf.bulk, repeat_scalar=cell_size)

wf.cell_with_vacancies = create_vacancy(structure=wf.cell, index=vacancy_index)
return wf.cell_with_vacancies # .outputs.structure
wf.structure = create_vacancy(structure=wf.cell, index=vacancy_index)
return wf.structure # .outputs.structure


nodes = [bulk, cubic_bulk_cell]
4 changes: 2 additions & 2 deletions pyiron_workflow/node_library/atomistic/structure/calc.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from pyiron_workflow.function import single_value_node
from pyiron_workflow.function import function_node
from typing import Optional, Union

# Huge savings when replacing pyiron_atomistics atoms class with ase one!! (> 5s vs 40 ms)
# from pyiron_atomistics.atomistics.structure.atoms import Atoms
from ase import Atoms


@single_value_node("structure")
@function_node("structure")
def volume(structure: Optional[Atoms] = None) -> float:
return structure.get_volume()

Expand Down
10 changes: 5 additions & 5 deletions pyiron_workflow/node_library/atomistic/structure/transform.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
from pyiron_workflow.function import single_value_node
from pyiron_workflow.function import function_node
from typing import Optional, Union

# Huge savings when replacing pyiron_atomistics atoms class with ase one!! (> 5s vs 40 ms)
# from pyiron_atomistics.atomistics.structure.atoms import Atoms
from ase import Atoms


@single_value_node("structure")
@function_node("structure")
def repeat(structure: Atoms, repeat_scalar: int = 1) -> Atoms:
return structure.repeat(repeat_scalar)


@single_value_node("structure")
@function_node("structure")
def apply_strain(
structure: Optional[Atoms] = None, strain: Union[float, int] = 0
) -> Optional[Atoms]:
Expand All @@ -22,7 +22,7 @@ def apply_strain(
return struct


@single_value_node()
@function_node()
def create_vacancy(structure, index: int | None = 0):
structure = structure.copy()
if index is not None:
Expand All @@ -31,7 +31,7 @@ def create_vacancy(structure, index: int | None = 0):
return structure


@single_value_node("structure")
@function_node("structure")
def rotate_axis_angle(
structure: Atoms,
angle: float | int = 0,
Expand Down
2 changes: 1 addition & 1 deletion pyiron_workflow/node_library/atomistic_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def Lammps(wf, structure=Atoms(), potential=None):
wf.Collect = wf.create.atomistic.engine.lammps.Collect(
out_dump=wf.ParseDumpFile.outputs.dump,
out_log=wf.ParseLogFile.outputs.log,
calc_mode=wf.calc._mode, # SVN gives output -> inject attribute getter node
calc_mode=wf.calc.mode, # SVN gives output -> inject attribute getter node
)

return wf.Collect
Expand Down
4 changes: 2 additions & 2 deletions pyiron_workflow/node_library/databases/elasticity.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from pyiron_workflow.function import single_value_node
from pyiron_workflow.function import function_node
from typing import Optional


@single_value_node("dataframe")
@function_node("dataframe")
def de_jong(max_index: int | None = None, filename="ec.json"):
"""
Expects the file to be the "ec.json" database referenced by:
Expand Down

0 comments on commit b69ca0b

Please sign in to comment.