Skip to content
Draft
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
8 changes: 5 additions & 3 deletions atomistics/calculators/ase.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ def calc_molecular_dynamics_thermal_expansion_with_ase(
temperature_lst = np.arange(
temperature_start, temperature_stop + temperature_step, temperature_step
).tolist()
volume_md_lst, temperature_md_lst = [], []
volume_md_lst, temperature_md_lst, cell_md_lst = [], [], []
for temperature in get_tqdm_iterator(temperature_lst):
result_dict = calc_molecular_dynamics_npt_with_ase(
structure=structure_current.copy(),
Expand All @@ -410,11 +410,13 @@ def calc_molecular_dynamics_thermal_expansion_with_ase(
externalstress=externalstress,
)
structure_current.set_cell(cell=result_dict["cell"][-1], scale_atoms=True)
cell_md_lst.append(result_dict["cell"][-1])
temperature_md_lst.append(result_dict["temperature"][-1])
volume_md_lst.append(result_dict["volume"][-1])
return get_thermal_expansion_output(
temperatures_lst=temperature_md_lst,
volumes_lst=volume_md_lst,
cell_lst=np.array(cell_md_lst),
temperatures_lst=np.array(temperature_md_lst),
volumes_lst=np.array(volume_md_lst),
output_keys=output_keys,
)

Expand Down
8 changes: 5 additions & 3 deletions atomistics/calculators/lammps/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def lammps_thermal_expansion_loop(
**kwargs,
)

volume_md_lst, temperature_md_lst = [], []
volume_md_lst, cell_md_lst, temperature_md_lst = [], [], []
for temp in get_tqdm_iterator(temperature_lst):
run_str_rendered = Template(run_str).render(
run=run,
Expand All @@ -133,12 +133,14 @@ def lammps_thermal_expansion_loop(
)
for line in run_str_rendered.split("\n"):
lmp_instance.interactive_lib_command(line)
cell_md_lst.append(lmp_instance.interactive_cells_getter())
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 get_thermal_expansion_output(
temperatures_lst=temperature_md_lst,
volumes_lst=volume_md_lst,
cell_lst=np.array(cell_md_lst),
temperatures_lst=np.array(temperature_md_lst),
volumes_lst=np.array(volume_md_lst),
output_keys=output_keys,
)

Expand Down
1 change: 1 addition & 0 deletions atomistics/shared/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class OutputMolecularDynamics(Output):
class OutputThermalExpansion(Output):
temperatures: callable
volumes: callable
cells: callable


@dataclasses.dataclass
Expand Down
25 changes: 22 additions & 3 deletions atomistics/shared/thermal_expansion.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,32 @@


class ThermalExpansionProperties:
def __init__(self, temperatures_lst: np.ndarray, volumes_lst: np.ndarray):
def __init__(
self,
cell_lst: np.ndarray,
temperatures_lst: np.ndarray,
volumes_lst: np.ndarray,
):
"""
Initialize the ThermalExpansionProperties class.

Parameters:
temperatures_lst (np.ndarray): Array of temperatures.
volumes_lst (np.ndarray): Array of volumes.
"""
self._cell_lst = cell_lst
self._temperatures_lst = temperatures_lst
self._volumes_lst = volumes_lst

def cells(self) -> np.ndarray:
"""
Get the array of cells.

Returns:
np.ndarray: Array of cells.
"""
return self._cell_lst

def volumes(self) -> np.ndarray:
"""
Get the array of volumes.
Expand All @@ -35,21 +50,25 @@ def temperatures(self) -> np.ndarray:


def get_thermal_expansion_output(
temperatures_lst: np.ndarray, volumes_lst: np.ndarray, output_keys: tuple[str]
temperatures_lst: np.ndarray,
volumes_lst: np.ndarray,
cell_lst: np.ndarray,
output_keys: tuple[str],
) -> dict:
"""
Get the thermal expansion output.

Parameters:
temperatures_lst (np.ndarray): Array of temperatures.
cells_lst (np.ndarray): Array of cells.
volumes_lst (np.ndarray): Array of volumes.
output_keys (tuple[str]): Tuple of output keys.

Returns:
dict: Dictionary containing the thermal expansion output.
"""
thermal = ThermalExpansionProperties(
temperatures_lst=temperatures_lst, volumes_lst=volumes_lst
cell_lst=cell_lst, temperatures_lst=temperatures_lst, volumes_lst=volumes_lst
)
return OutputThermalExpansion(
**{k: getattr(thermal, k) for k in OutputThermalExpansion.keys()}
Expand Down
12 changes: 12 additions & 0 deletions atomistics/workflows/phonons/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,18 @@ def volumes(self) -> np.ndarray:
* len(self._thermal_properties["temperatures"])
)

def cells(self) -> np.ndarray:
"""
Get the cells.

Returns:
np.ndarray: The cells.
"""
return np.array(
[self._phonopy.unitcell.cell]
* len(self._thermal_properties["temperatures"])
)


def restore_magmoms(
structure_with_magmoms: Atoms,
Expand Down
Loading