Skip to content

Commit

Permalink
Merge pull request #182 from pyiron/rename_fields
Browse files Browse the repository at this point in the history
Rename fields() to keys()
  • Loading branch information
jan-janssen authored Jan 8, 2024
2 parents c02d8d9 + 66f8a8b commit faac2f3
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 38 deletions.
12 changes: 6 additions & 6 deletions atomistics/calculators/ase.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ def volume(self):


ASEOutputStatic = OutputStatic(
**{k: getattr(ASEExecutor, k) for k in OutputStatic.fields()}
**{k: getattr(ASEExecutor, k) for k in OutputStatic.keys()}
)

ASEOutputMolecularDynamics = OutputMolecularDynamics(
**{k: getattr(ASEExecutor, k) for k in OutputMolecularDynamics.fields()}
**{k: getattr(ASEExecutor, k) for k in OutputMolecularDynamics.keys()}
)


Expand Down Expand Up @@ -113,7 +113,7 @@ def evaluate_with_ase(
def calc_static_with_ase(
structure,
ase_calculator,
output_keys=OutputStatic.fields(),
output_keys=OutputStatic.keys(),
):
return ASEOutputStatic.get(
ASEExecutor(ase_structure=structure, ase_calculator=ase_calculator),
Expand Down Expand Up @@ -148,7 +148,7 @@ def calc_molecular_dynamics_npt_with_ase(
pfactor=2e6 * units.GPa * (units.fs**2),
temperature=100,
externalstress=np.array([0.0, 0.0, 0.0, 0.0, 0.0, 0.0]) * units.bar,
output_keys=ASEOutputMolecularDynamics.fields(),
output_keys=ASEOutputMolecularDynamics.keys(),
):
return _calc_md_step_with_ase(
dyn=NPT(
Expand Down Expand Up @@ -182,7 +182,7 @@ def calc_molecular_dynamics_langevin_with_ase(
timestep=1 * units.fs,
temperature=100,
friction=0.002,
output_keys=ASEOutputMolecularDynamics.fields(),
output_keys=ASEOutputMolecularDynamics.keys(),
):
return _calc_md_step_with_ase(
dyn=Langevin(
Expand Down Expand Up @@ -232,7 +232,7 @@ def calc_molecular_dynamics_thermal_expansion_with_ase(
ttime=100 * units.fs,
pfactor=2e6 * units.GPa * (units.fs**2),
externalstress=np.array([0.0, 0.0, 0.0, 0.0, 0.0, 0.0]) * units.bar,
output_keys=OutputThermalExpansionProperties.fields(),
output_keys=OutputThermalExpansionProperties.keys(),
):
structure_current = structure.copy()
temperature_lst = np.arange(
Expand Down
12 changes: 6 additions & 6 deletions atomistics/calculators/lammps/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def calc_static_with_lammps(
structure,
potential_dataframe,
lmp=None,
output_keys=LammpsOutputStatic.fields(),
output_keys=LammpsOutputStatic.keys(),
**kwargs,
):
template_str = LAMMPS_THERMO_STYLE + "\n" + LAMMPS_THERMO + "\n" + LAMMPS_RUN
Expand Down Expand Up @@ -151,7 +151,7 @@ def calc_molecular_dynamics_nvt_with_lammps(
seed=4928459,
dist="gaussian",
lmp=None,
output_keys=LammpsOutputMolecularDynamics.fields(),
output_keys=LammpsOutputMolecularDynamics.keys(),
**kwargs,
):
init_str = (
Expand Down Expand Up @@ -208,7 +208,7 @@ def calc_molecular_dynamics_npt_with_lammps(
seed=4928459,
dist="gaussian",
lmp=None,
output_keys=LammpsOutputMolecularDynamics.fields(),
output_keys=LammpsOutputMolecularDynamics.keys(),
**kwargs,
):
init_str = (
Expand Down Expand Up @@ -266,7 +266,7 @@ def calc_molecular_dynamics_nph_with_lammps(
seed=4928459,
dist="gaussian",
lmp=None,
output_keys=LammpsOutputMolecularDynamics.fields(),
output_keys=LammpsOutputMolecularDynamics.keys(),
**kwargs,
):
init_str = (
Expand Down Expand Up @@ -320,7 +320,7 @@ def calc_molecular_dynamics_langevin_with_lammps(
seed=4928459,
dist="gaussian",
lmp=None,
output_keys=LammpsOutputMolecularDynamics.fields(),
output_keys=LammpsOutputMolecularDynamics.keys(),
**kwargs,
):
init_str = (
Expand Down Expand Up @@ -380,7 +380,7 @@ def calc_molecular_dynamics_thermal_expansion_with_lammps(
seed=4928459,
dist="gaussian",
lmp=None,
output_keys=OutputThermalExpansionProperties.fields(),
output_keys=OutputThermalExpansionProperties.keys(),
**kwargs,
):
init_str = (
Expand Down
6 changes: 3 additions & 3 deletions atomistics/calculators/lammps/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def lammps_calc_md_step(
lmp_instance,
run_str,
run,
output_keys=LammpsOutputMolecularDynamics.fields(),
output_keys=LammpsOutputMolecularDynamics.keys(),
):
run_str_rendered = Template(run_str).render(run=run)
lmp_instance.interactive_lib_command(run_str_rendered)
Expand All @@ -58,7 +58,7 @@ def lammps_calc_md(
run_str,
run,
thermo,
output_keys=LammpsOutputMolecularDynamics.fields(),
output_keys=LammpsOutputMolecularDynamics.keys(),
):
results_lst = [
lammps_calc_md_step(
Expand Down Expand Up @@ -88,7 +88,7 @@ def lammps_thermal_expansion_loop(
seed=4928459,
dist="gaussian",
lmp=None,
output_keys=OutputThermalExpansionProperties.fields(),
output_keys=OutputThermalExpansionProperties.keys(),
**kwargs,
):
lmp_instance = lammps_run(
Expand Down
4 changes: 2 additions & 2 deletions atomistics/calculators/qe.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def volume(self):


QuantumEspressoOutputStatic = OutputStatic(
**{k: getattr(QEStaticParser, k) for k in OutputStatic.fields()}
**{k: getattr(QEStaticParser, k) for k in OutputStatic.keys()}
)


Expand Down Expand Up @@ -186,7 +186,7 @@ def calc_static_with_qe(
pseudopotentials=None,
tstress=True,
tprnfor=True,
output_keys=OutputStatic.fields(),
output_keys=OutputStatic.keys(),
**kwargs,
):
input_file_name = os.path.join(working_directory, calculation_name + ".pwi")
Expand Down
2 changes: 1 addition & 1 deletion atomistics/shared/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
@dataclasses.dataclass
class Output:
@classmethod
def fields(cls):
def keys(cls):
return tuple(field.name for field in dataclasses.fields(cls))

def get(self, engine, *output: str) -> dict:
Expand Down
5 changes: 1 addition & 4 deletions atomistics/shared/thermal_expansion.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,5 @@ def temperatures(self):


OutputThermalExpansionProperties = OutputThermalExpansion(
**{
k: getattr(ThermalExpansionProperties, k)
for k in OutputThermalExpansion.fields()
}
**{k: getattr(ThermalExpansionProperties, k) for k in OutputThermalExpansion.keys()}
)
4 changes: 2 additions & 2 deletions atomistics/workflows/elastic/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


elastic_matrix_output_elastic = OutputElastic(
**{k: getattr(ElasticProperties, k) for k in OutputElastic.fields()}
**{k: getattr(ElasticProperties, k) for k in OutputElastic.keys()}
)


Expand Down Expand Up @@ -44,7 +44,7 @@ def generate_structures(self):
)
return {"calc_energy": self._structure_dict}

def analyse_structures(self, output_dict, output_keys=OutputElastic.fields()):
def analyse_structures(self, output_dict, output_keys=OutputElastic.keys()):
"""
Args:
Expand Down
4 changes: 2 additions & 2 deletions atomistics/workflows/evcurve/debye.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def volumes(self):


DebyeOutputThermodynamic = OutputThermodynamic(
**{k: getattr(DebyeThermalProperties, k) for k in OutputThermodynamic.fields()}
**{k: getattr(DebyeThermalProperties, k) for k in OutputThermodynamic.keys()}
)


Expand Down Expand Up @@ -232,7 +232,7 @@ def get_thermal_properties(
temperatures=None,
constant_volume=False,
num_steps=50,
output_keys=OutputThermodynamic.fields(),
output_keys=OutputThermodynamic.keys(),
):
return DebyeOutputThermodynamic.get(
DebyeThermalProperties(
Expand Down
6 changes: 3 additions & 3 deletions atomistics/workflows/evcurve/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def fit_dict(self):
EnergyVolumeCurveOutputEnergyVolumeCurve = OutputEnergyVolumeCurve(
**{
k: getattr(EnergyVolumeCurveProperties, k)
for k in OutputEnergyVolumeCurve.fields()
for k in OutputEnergyVolumeCurve.keys()
}
)

Expand Down Expand Up @@ -181,7 +181,7 @@ def generate_structures(self):
return {"calc_energy": self._structure_dict}

def analyse_structures(
self, output_dict, output_keys=OutputEnergyVolumeCurve.fields()
self, output_dict, output_keys=OutputEnergyVolumeCurve.keys()
):
self._fit_dict = EnergyVolumeCurveOutputEnergyVolumeCurve.get(
EnergyVolumeCurveProperties(
Expand All @@ -208,7 +208,7 @@ def get_thermal_properties(
t_step=50,
temperatures=None,
constant_volume=False,
output_keys=OutputThermodynamic.fields(),
output_keys=OutputThermodynamic.keys(),
):
return get_thermal_properties(
fit_dict=self.fit_dict,
Expand Down
8 changes: 4 additions & 4 deletions atomistics/workflows/phonons/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ def volumes(self):


PhonopyOutputPhonons = OutputPhonons(
**{k: getattr(PhonopyProperties, k) for k in OutputPhonons.fields()}
**{k: getattr(PhonopyProperties, k) for k in OutputPhonons.keys()}
)
PhonopyOutputThermodynamic = OutputThermodynamic(
**{k: getattr(PhonopyThermalProperties, k) for k in OutputThermodynamic.fields()}
**{k: getattr(PhonopyThermalProperties, k) for k in OutputThermodynamic.keys()}
)


Expand Down Expand Up @@ -231,7 +231,7 @@ def _restore_magmoms(self, structure):
structure.set_initial_magnetic_moments(magmoms)
return structure

def analyse_structures(self, output_dict, output_keys=OutputPhonons.fields()):
def analyse_structures(self, output_dict, output_keys=OutputPhonons.keys()):
"""
Returns:
Expand Down Expand Up @@ -273,7 +273,7 @@ def get_thermal_properties(
pretend_real=False,
band_indices=None,
is_projection=False,
output_keys=OutputThermodynamic.fields(),
output_keys=OutputThermodynamic.keys(),
):
"""
Returns thermal properties at constant volume in the given temperature range. Can only be called after job
Expand Down
10 changes: 5 additions & 5 deletions atomistics/workflows/quasiharmonic.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def get_thermal_properties(
band_indices=None,
is_projection=False,
quantum_mechanical=True,
output_keys=OutputThermodynamic.fields(),
output_keys=OutputThermodynamic.keys(),
):
"""
Returns thermal properties at constant volume in the given temperature range. Can only be called after job
Expand Down Expand Up @@ -135,7 +135,7 @@ def _get_thermal_properties_quantum_mechanical(
pretend_real=False,
band_indices=None,
is_projection=False,
output_keys=OutputThermodynamic.fields(),
output_keys=OutputThermodynamic.keys(),
):
"""
Returns thermal properties at constant volume in the given temperature range. Can only be called after job
Expand Down Expand Up @@ -277,7 +277,7 @@ def volumes(self):
QuasiHarmonicOutputThermodynamic = OutputThermodynamic(
**{
k: getattr(QuasiHarmonicThermalProperties, k)
for k in OutputThermodynamic.fields()
for k in OutputThermodynamic.keys()
}
)

Expand Down Expand Up @@ -381,7 +381,7 @@ def get_thermal_properties(
band_indices=None,
is_projection=False,
quantum_mechanical=True,
output_keys=OutputThermodynamic.fields(),
output_keys=OutputThermodynamic.keys(),
):
"""
Returns thermal properties at constant volume in the given temperature range. Can only be called after job
Expand Down Expand Up @@ -417,5 +417,5 @@ def get_thermal_properties(
band_indices=band_indices,
is_projection=is_projection,
quantum_mechanical=quantum_mechanical,
output_keys=OutputThermodynamic.fields(),
output_keys=OutputThermodynamic.keys(),
)

0 comments on commit faac2f3

Please sign in to comment.