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

Introduce get_thermal_expansion_output() function #183

Merged
merged 3 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
17 changes: 7 additions & 10 deletions atomistics/calculators/ase.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@
from atomistics.calculators.interface import get_quantities_from_tasks
from atomistics.calculators.wrapper import as_task_dict_evaluator
from atomistics.shared.output import OutputStatic, OutputMolecularDynamics
from atomistics.shared.thermal_expansion import (
OutputThermalExpansionProperties,
ThermalExpansionProperties,
)
from atomistics.shared.thermal_expansion import get_thermal_expansion_output
from atomistics.shared.output import OutputThermalExpansion
from atomistics.shared.tqdm_iterator import get_tqdm_iterator

if TYPE_CHECKING:
Expand Down Expand Up @@ -232,7 +230,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.keys(),
output_keys=OutputThermalExpansion.keys(),
):
structure_current = structure.copy()
temperature_lst = np.arange(
Expand All @@ -254,9 +252,8 @@ def calc_molecular_dynamics_thermal_expansion_with_ase(
structure_current.set_cell(cell=result_dict["cell"][-1], scale_atoms=True)
temperature_md_lst.append(result_dict["temperature"][-1])
volume_md_lst.append(result_dict["volume"][-1])
return OutputThermalExpansionProperties.get(
ThermalExpansionProperties(
temperatures_lst=temperature_md_lst, volumes_lst=volume_md_lst
),
*output_keys,
return get_thermal_expansion_output(
temperatures_lst=temperature_md_lst,
volumes_lst=volume_md_lst,
output_keys=output_keys,
)
4 changes: 2 additions & 2 deletions atomistics/calculators/lammps/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
LammpsOutputStatic,
)
from atomistics.calculators.wrapper import as_task_dict_evaluator
from atomistics.shared.thermal_expansion import OutputThermalExpansionProperties
from atomistics.shared.output import OutputThermalExpansion

if TYPE_CHECKING:
from ase import Atoms
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.keys(),
output_keys=OutputThermalExpansion.keys(),
**kwargs,
):
init_str = (
Expand Down
17 changes: 7 additions & 10 deletions atomistics/calculators/lammps/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@

from atomistics.calculators.lammps.potential import validate_potential_dataframe
from atomistics.calculators.lammps.output import LammpsOutputMolecularDynamics
from atomistics.shared.thermal_expansion import (
OutputThermalExpansionProperties,
ThermalExpansionProperties,
)
from atomistics.shared.thermal_expansion import get_thermal_expansion_output
from atomistics.shared.output import OutputThermalExpansion
from atomistics.shared.tqdm_iterator import get_tqdm_iterator


Expand Down Expand Up @@ -88,7 +86,7 @@ def lammps_thermal_expansion_loop(
seed=4928459,
dist="gaussian",
lmp=None,
output_keys=OutputThermalExpansionProperties.keys(),
output_keys=OutputThermalExpansion.keys(),
**kwargs,
):
lmp_instance = lammps_run(
Expand Down Expand Up @@ -121,11 +119,10 @@ def lammps_thermal_expansion_loop(
volume_md_lst.append(lmp_instance.interactive_volume_getter())
temperature_md_lst.append(lmp_instance.interactive_temperatures_getter())
lammps_shutdown(lmp_instance=lmp_instance, close_instance=lmp is None)
return OutputThermalExpansionProperties.get(
ThermalExpansionProperties(
temperatures_lst=temperature_md_lst, volumes_lst=volume_md_lst
),
*output_keys,
return get_thermal_expansion_output(
temperatures_lst=temperature_md_lst,
volumes_lst=volume_md_lst,
output_keys=output_keys,
)


Expand Down
15 changes: 12 additions & 3 deletions atomistics/shared/thermal_expansion.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ def temperatures(self):
return self._temperatures_lst


OutputThermalExpansionProperties = OutputThermalExpansion(
**{k: getattr(ThermalExpansionProperties, k) for k in OutputThermalExpansion.keys()}
)
def get_thermal_expansion_output(temperatures_lst, volumes_lst, output_keys):
return OutputThermalExpansion(
**{
k: getattr(ThermalExpansionProperties, k)
for k in OutputThermalExpansion.keys()
}
).get(
ThermalExpansionProperties(
temperatures_lst=temperatures_lst, volumes_lst=volumes_lst
),
*output_keys,
)
Loading