Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename output parameter to output_keys #180

Merged
merged 6 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions atomistics/calculators/ase.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def evaluate_with_ase(
return calc_static_with_ase(
structure=structure,
ase_calculator=ase_calculator,
output=get_quantities_from_tasks(tasks=tasks),
output_keys=get_quantities_from_tasks(tasks=tasks),
)
else:
raise ValueError("The ASE calculator does not implement:", tasks)
Expand All @@ -113,28 +113,29 @@ def evaluate_with_ase(
def calc_static_with_ase(
structure,
ase_calculator,
output=OutputStatic.fields(),
output_keys=OutputStatic.fields(),
):
return ASEOutputStatic.get(
ASEExecutor(ase_structure=structure, ase_calculator=ase_calculator), *output
ASEExecutor(ase_structure=structure, ase_calculator=ase_calculator),
*output_keys,
)


def _calc_md_step_with_ase(
dyn, structure, ase_calculator, temperature, run, thermo, output
dyn, structure, ase_calculator, temperature, run, thermo, output_keys
):
structure.calc = ase_calculator
MaxwellBoltzmannDistribution(atoms=structure, temperature_K=temperature)
cache = {q: [] for q in output}
cache = {q: [] for q in output_keys}
for i in range(int(run / thermo)):
dyn.run(thermo)
calc_dict = ASEOutputMolecularDynamics.get(
ASEExecutor(ase_structure=structure, ase_calculator=ase_calculator),
*output,
*output_keys,
)
for k, v in calc_dict.items():
cache[k].append(v)
return {q: np.array(cache[q]) for q in output}
return {q: np.array(cache[q]) for q in output_keys}


def calc_molecular_dynamics_npt_with_ase(
Expand All @@ -147,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=ASEOutputMolecularDynamics.fields(),
output_keys=ASEOutputMolecularDynamics.fields(),
):
return _calc_md_step_with_ase(
dyn=NPT(
Expand All @@ -169,7 +170,7 @@ def calc_molecular_dynamics_npt_with_ase(
temperature=temperature,
run=run,
thermo=thermo,
output=output,
output_keys=output_keys,
)


Expand All @@ -181,7 +182,7 @@ def calc_molecular_dynamics_langevin_with_ase(
timestep=1 * units.fs,
temperature=100,
friction=0.002,
output=ASEOutputMolecularDynamics.fields(),
output_keys=ASEOutputMolecularDynamics.fields(),
):
return _calc_md_step_with_ase(
dyn=Langevin(
Expand All @@ -195,7 +196,7 @@ def calc_molecular_dynamics_langevin_with_ase(
temperature=temperature,
run=run,
thermo=thermo,
output=output,
output_keys=output_keys,
)


Expand Down Expand Up @@ -231,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=OutputThermalExpansionProperties.fields(),
output_keys=OutputThermalExpansionProperties.fields(),
):
structure_current = structure.copy()
temperature_lst = np.arange(
Expand All @@ -257,5 +258,5 @@ def calc_molecular_dynamics_thermal_expansion_with_ase(
ThermalExpansionProperties(
temperatures_lst=temperature_md_lst, volumes_lst=volume_md_lst
),
*output,
*output_keys,
)
26 changes: 13 additions & 13 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=LammpsOutputStatic.fields(),
output_keys=LammpsOutputStatic.fields(),
**kwargs,
):
template_str = LAMMPS_THERMO_STYLE + "\n" + LAMMPS_THERMO + "\n" + LAMMPS_RUN
Expand All @@ -134,7 +134,7 @@ def calc_static_with_lammps(
lmp=lmp,
**kwargs,
)
result_dict = LammpsOutputStatic.get(lmp_instance, *output)
result_dict = LammpsOutputStatic.get(lmp_instance, *output_keys)
lammps_shutdown(lmp_instance=lmp_instance, close_instance=lmp is None)
return result_dict

Expand All @@ -151,7 +151,7 @@ def calc_molecular_dynamics_nvt_with_lammps(
seed=4928459,
dist="gaussian",
lmp=None,
output=LammpsOutputMolecularDynamics.fields(),
output_keys=LammpsOutputMolecularDynamics.fields(),
**kwargs,
):
init_str = (
Expand Down Expand Up @@ -187,7 +187,7 @@ def calc_molecular_dynamics_nvt_with_lammps(
run_str=run_str,
run=run,
thermo=thermo,
output=output,
output_keys=output_keys,
)
lammps_shutdown(lmp_instance=lmp_instance, close_instance=lmp is None)
return result_dict
Expand All @@ -208,7 +208,7 @@ def calc_molecular_dynamics_npt_with_lammps(
seed=4928459,
dist="gaussian",
lmp=None,
output=LammpsOutputMolecularDynamics.fields(),
output_keys=LammpsOutputMolecularDynamics.fields(),
**kwargs,
):
init_str = (
Expand Down Expand Up @@ -247,7 +247,7 @@ def calc_molecular_dynamics_npt_with_lammps(
run_str=run_str,
run=run,
thermo=thermo,
output=output,
output_keys=output_keys,
)
lammps_shutdown(lmp_instance=lmp_instance, close_instance=lmp is None)
return result_dict
Expand All @@ -266,7 +266,7 @@ def calc_molecular_dynamics_nph_with_lammps(
seed=4928459,
dist="gaussian",
lmp=None,
output=LammpsOutputMolecularDynamics.fields(),
output_keys=LammpsOutputMolecularDynamics.fields(),
**kwargs,
):
init_str = (
Expand Down Expand Up @@ -302,7 +302,7 @@ def calc_molecular_dynamics_nph_with_lammps(
run_str=run_str,
run=run,
thermo=thermo,
output=output,
output_keys=output_keys,
)
lammps_shutdown(lmp_instance=lmp_instance, close_instance=lmp is None)
return result_dict
Expand All @@ -320,7 +320,7 @@ def calc_molecular_dynamics_langevin_with_lammps(
seed=4928459,
dist="gaussian",
lmp=None,
output=LammpsOutputMolecularDynamics.fields(),
output_keys=LammpsOutputMolecularDynamics.fields(),
**kwargs,
):
init_str = (
Expand Down Expand Up @@ -358,7 +358,7 @@ def calc_molecular_dynamics_langevin_with_lammps(
run_str=run_str,
run=run,
thermo=thermo,
output=output,
output_keys=output_keys,
)
lammps_shutdown(lmp_instance=lmp_instance, close_instance=lmp is None)
return result_dict
Expand All @@ -380,7 +380,7 @@ def calc_molecular_dynamics_thermal_expansion_with_lammps(
seed=4928459,
dist="gaussian",
lmp=None,
output=OutputThermalExpansionProperties.fields(),
output_keys=OutputThermalExpansionProperties.fields(),
**kwargs,
):
init_str = (
Expand Down Expand Up @@ -411,7 +411,7 @@ def calc_molecular_dynamics_thermal_expansion_with_lammps(
seed=seed,
dist=dist,
lmp=lmp,
output=output,
output_keys=output_keys,
**kwargs,
)

Expand Down Expand Up @@ -457,7 +457,7 @@ def evaluate_with_lammps_library(
structure=structure,
potential_dataframe=potential_dataframe,
lmp=lmp,
output=get_quantities_from_tasks(tasks=tasks),
output_keys=get_quantities_from_tasks(tasks=tasks),
)
else:
raise ValueError("The LAMMPS calculator does not implement:", tasks)
Expand Down
14 changes: 7 additions & 7 deletions atomistics/calculators/lammps/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,30 @@ def lammps_calc_md_step(
lmp_instance,
run_str,
run,
output=LammpsOutputMolecularDynamics.fields(),
output_keys=LammpsOutputMolecularDynamics.fields(),
):
run_str_rendered = Template(run_str).render(run=run)
lmp_instance.interactive_lib_command(run_str_rendered)
return LammpsOutputMolecularDynamics.get(lmp_instance, *output)
return LammpsOutputMolecularDynamics.get(lmp_instance, *output_keys)


def lammps_calc_md(
lmp_instance,
run_str,
run,
thermo,
output=LammpsOutputMolecularDynamics.fields(),
output_keys=LammpsOutputMolecularDynamics.fields(),
):
results_lst = [
lammps_calc_md_step(
lmp_instance=lmp_instance,
run_str=run_str,
run=thermo,
output=output,
output_keys=output_keys,
)
for _ in range(run // thermo)
]
return {q: np.array([d[q] for d in results_lst]) for q in output}
return {q: np.array([d[q] for d in results_lst]) for q in output_keys}


def lammps_thermal_expansion_loop(
Expand All @@ -88,7 +88,7 @@ def lammps_thermal_expansion_loop(
seed=4928459,
dist="gaussian",
lmp=None,
output=OutputThermalExpansionProperties.fields(),
output_keys=OutputThermalExpansionProperties.fields(),
**kwargs,
):
lmp_instance = lammps_run(
Expand Down Expand Up @@ -125,7 +125,7 @@ def lammps_thermal_expansion_loop(
ThermalExpansionProperties(
temperatures_lst=temperature_md_lst, volumes_lst=volume_md_lst
),
*output,
*output_keys,
)


Expand Down
6 changes: 3 additions & 3 deletions atomistics/calculators/qe.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ def calc_static_with_qe(
pseudopotentials=None,
tstress=True,
tprnfor=True,
output=OutputStatic.fields(),
output_keys=OutputStatic.fields(),
**kwargs,
):
input_file_name = os.path.join(working_directory, calculation_name + ".pwi")
Expand All @@ -213,7 +213,7 @@ def calc_static_with_qe(
calculation_name=calculation_name, working_directory=working_directory
)
return QuantumEspressoOutputStatic.get(
QEStaticParser(filename=output_file_name), *output
QEStaticParser(filename=output_file_name), *output_keys
)


Expand Down Expand Up @@ -252,7 +252,7 @@ def evaluate_with_qe(
pseudopotentials=pseudopotentials,
tstress=tstress,
tprnfor=tprnfor,
output=get_quantities_from_tasks(tasks=tasks),
output_keys=get_quantities_from_tasks(tasks=tasks),
**kwargs,
)
else:
Expand Down
6 changes: 3 additions & 3 deletions atomistics/workflows/elastic/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ def generate_structures(self):
)
return {"calc_energy": self._structure_dict}

def analyse_structures(self, output_dict, output=OutputElastic.fields()):
def analyse_structures(self, output_dict, output_keys=OutputElastic.fields()):
"""

Args:
output_dict (dict):
output (tuple):
output_keys (tuple):

Returns:

Expand All @@ -67,5 +67,5 @@ def analyse_structures(self, output_dict, output=OutputElastic.fields()):
self._data["e0"] = ene0
self._data["A2"] = A2
return elastic_matrix_output_elastic.get(
ElasticProperties(elastic_matrix=elastic_matrix), *output
ElasticProperties(elastic_matrix=elastic_matrix), *output_keys
)
4 changes: 2 additions & 2 deletions atomistics/workflows/evcurve/debye.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def get_thermal_properties(
temperatures=None,
constant_volume=False,
num_steps=50,
output=OutputThermodynamic.fields(),
output_keys=OutputThermodynamic.fields(),
):
return DebyeOutputThermodynamic.get(
DebyeThermalProperties(
Expand All @@ -245,5 +245,5 @@ def get_thermal_properties(
constant_volume=constant_volume,
num_steps=num_steps,
),
*output,
*output_keys,
)
10 changes: 6 additions & 4 deletions atomistics/workflows/evcurve/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ def generate_structures(self):
self._structure_dict[1 + np.round(strain, 7)] = basis
return {"calc_energy": self._structure_dict}

def analyse_structures(self, output_dict, output=OutputEnergyVolumeCurve.fields()):
def analyse_structures(
self, output_dict, output_keys=OutputEnergyVolumeCurve.fields()
):
self._fit_dict = EnergyVolumeCurveOutputEnergyVolumeCurve.get(
EnergyVolumeCurveProperties(
fit_module=fit_ev_curve_internal(
Expand All @@ -192,7 +194,7 @@ def analyse_structures(self, output_dict, output=OutputEnergyVolumeCurve.fields(
fit_order=self.fit_order,
)
),
*output,
*output_keys,
)
return self.fit_dict

Expand All @@ -206,7 +208,7 @@ def get_thermal_properties(
t_step=50,
temperatures=None,
constant_volume=False,
output=OutputThermodynamic.fields(),
output_keys=OutputThermodynamic.fields(),
):
return get_thermal_properties(
fit_dict=self.fit_dict,
Expand All @@ -216,5 +218,5 @@ def get_thermal_properties(
t_step=t_step,
temperatures=temperatures,
constant_volume=constant_volume,
output=output,
output_keys=output_keys,
)
Loading
Loading