Analyzer API
MoltenSaltAnalyzer
Class for analyzing molten salt simulation results.
__init__
__init__(
traj_files_npt: (
list[str] | list[Path] | str | Path | None
) = None,
traj_files_nvt: (
list[str] | list[Path] | str | Path | None
) = None,
temperatures_npt: list[float] | list[int] | None = None,
temperatures_nvt: list[float] | list[int] | None = None,
ids_npt: list[str] | None = None,
ids_nvt: list[str] | None = None,
timestep_fs: int | float | None = None,
calculator: Calculator | None = None,
)
Initialize the analyzer with the trajectories and the always used properties
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
traj_files_npt
|
(list, str, Path)
|
Path to the NPT trajectory file(s). Defaults to None. |
None
|
traj_files_nvt
|
(list, str, Path)
|
Path to the NVT trajectory file(s). Defaults to None. |
None
|
temperatures_npt
|
list
|
List of temperatures in K for the NPT trajectories. Defaults to None. |
None
|
temperatures_nvt
|
list
|
List of temperatures in K for the NVT trajectories. Defaults to None. |
None
|
ids_npt
|
list
|
List of identifiers for the NPT trajectories. Defaults to None. |
None
|
ids_nvt
|
list
|
List of identifiers for the NVT trajectories. Defaults to None. |
None
|
timestep_fs
|
(int, float)
|
Constant timestep in fs. Only applies if time_fs is not found in the trajectory files. Defaults to None which is treated as 10.0 later but a warning is issued. |
None
|
calculator
|
calculator
|
Calculator to use for the energy and forces predictions (needed in case they are not available from the trajectory files, but leads to a slow initialization). Defaults to None. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the number of trajectory files is not equal to the number of temperatures. |
ValueError
|
If ids are provided but the number of trajectory files is not equal to the number of ids. |
FileNotFoundError
|
If the trajectory file(s) does not exist. |
Defines
self.trajs_npt (list): List of Trajectory objects for the NPT trajectories. self.trajs_nvt (list): List of Trajectory objects for the NVT trajectories. self.times_fs_npt (list[np.ndarray]): List of arrays of times in fs for each NPT trajectory. self.times_fs_nvt (list[np.ndarray]): List of arrays of times in fs for each NVT trajectory. self.temperatures_npt (list): List of temperatures in K for the NPT trajectories. self.temperatures_nvt (list): List of temperatures in K for the NVT trajectories. self.ids_npt (list): List of identifiers for the NPT trajectories. self.ids_nvt (list): List of identifiers for the NVT trajectories. self.timestep_fs (float): Constant timestep in fs, only applies if time_fs is not found in the trajectory files.
recompute_times
recompute_times(timestep_fs: int | float)
Sets the times corresponding to the atoms in the trajectories according to the provided constant timestep.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timestep_fs
|
(int, float)
|
Newly chosen timestep in fs. |
required |
compute_density_vs_time
compute_density_vs_time(
traj_id: str | None = None, T: int | float | None = None
) -> tuple[np.ndarray, np.ndarray]
Compute the density from the trajectory file. If both NPT and NVT trajectories are loaded, the density is computed from the NPT trajectory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
traj_id
|
str
|
Identifier for the trajectory. Defaults to None. |
None
|
T
|
(int, float)
|
Temperature in K. The trajectory with the matching temperature is selected if traj_id is None. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[ndarray, ndarray]
|
Tuple[np.ndarray, np.ndarray]: Densities in g/cm³ and times in fs. |
compute_eq_density
compute_eq_density(
traj_id: str | None = None,
T: int | float | None = None,
eq_fraction: float = 0.1,
) -> float
Compute the density after equilibration (last x time% of the trajectory). If both NPT and NVT trajectories are loaded, the density is computed from the NPT trajectory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
traj_id
|
str
|
Identifier for the trajectory. Defaults to None. |
None
|
T
|
(int, float)
|
Temperature in K. The trajectory with the matching temperature is selected if traj_id is None. Defaults to None. |
None
|
eq_fraction
|
float
|
Final fraction of the simulation time to be considered as equilibrium. Defaults to 0.1. |
0.1
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Density in g/cm³ |
compute_thermal_expansion
compute_thermal_expansion(
eq_fraction: float = 0.1, ids: list[str] | None = None
) -> dict
Compute the thermal expansion coefficient from the initialized trajectory files and NPT temperatures.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
eq_fraction
|
float
|
Final fraction of the simulation time to be considered as equilibrium. Defaults to 0.1. |
0.1
|
ids
|
list
|
Identifiers for the trajectories to be used. Defaults to None. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If no trajectory identifiers are provided but were not initialized. |
ValueError
|
If at least one of the provided ids is not available in the initialized NPT trajectories. |
ValueError
|
If no NPT trajectory files are provided. |
ValueError
|
If no NPT temperatures are provided. |
ValueError
|
If less than two NPT trajectory files are provided. |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Thermal expansion results: - "temperatures": List of temperatures used - "eq_vols": Equilibrium volumes in ų for each temperature - "eq_vols_norm": Equilibrium volumes normalized to the mean volume - "fit": Fit parameters - "fit_line": Fit line - "thermal_expansion": Thermal expansion coefficient in 1/K |
compute_heat_capacity
compute_heat_capacity(
T: int | float,
traj_id: str | None = None,
eq_fraction: float = 0.1,
) -> float
Compute heat capacity from total energy fluctuations. If both NPT and NVT trajectories are loaded, the heat capacity is computed from the NVT trajectory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T
|
(int, float)
|
Temperature in K. The trajectory with the matching temperature is selected. |
required |
traj_id
|
str
|
Identifier for the trajectory, overrides T. Defaults to None. |
None
|
eq_fraction
|
float
|
Final fraction of the simulation time to be considered as equilibrium. Defaults to 0.1. |
0.1
|
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
Heat capacity in J/g/K |
compute_diffusion_coefficient
compute_diffusion_coefficient(
T: int | float, traj_id: str | None = None
) -> dict
Compute diffusion coefficients of each atom species present in the trajectory from the mean squared displacement. If both NPT and NVT trajectories are loaded, the diffusion coefficient is computed from the NVT trajectory, unless selected otherwise with traj_id.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T
|
(int, float)
|
Temperature in K. The trajectory with the matching temperature is selected. |
required |
traj_id
|
str
|
Identifier for the trajectory, overrides T to select the trajectory. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Diffusion coefficients in Ų/fs for each element, in the form {element: diffusion coefficient} |
fit_arrhenius
fit_arrhenius(
temperatures: list[int] | list[float],
diffusion_coeffs: list[float],
) -> dict
Fit Arrhenius law to diffusion coefficients and temperatures.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
temperatures
|
list
|
Temperatures in K. |
required |
diffusion_coeffs
|
list
|
Diffusion coefficients corresponding to the temperatures in Ų/fs. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Arrhenius parameters: - "Ea": Activation energy in J/mol - "D0": Exponential pre-factor of the Arrhenius law in Ų/fs - "slope": Slope of the Arrhenius law - "intercept": Intercept of the Arrhenius law |
compute_rdf
compute_rdf(
T: float,
traj_id: str | None = None,
max_num_frames: int | None = None,
rmax: float = 6.0,
nbins: int = 100,
pairs: (
list[tuple[int, int]] | list[tuple[str, str]] | None
) = None,
cell_constraints: (
list[tuple[float, float]] | None
) = None,
n_workers: int = 1,
) -> dict
Compute radial distribution functions. If both NPT and NVT trajectories are loaded, the RDF is computed from the NVT trajectory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T
|
float
|
Temperature in K. The trajectory with the matching temperature is selected. |
required |
traj_id
|
str
|
Identifier for the trajectory, overrides T. Defaults to None. |
None
|
max_num_frames
|
int
|
Maximum number of trajectory frames to compute the RDF for and average over. The frames are selected from the end of the simulation. Defaults to None which means all frames are considered. |
None
|
rmax
|
float
|
Maximum distance (Å) to consider. Defaults to 6.0. |
6.0
|
nbins
|
int
|
Number of bins for the RDF. Defaults to 100. |
100
|
pairs
|
list[tuple] | None
|
Atom pairs in terms of atomic numbers or symbols to compute the RDF for. Defaults to None which means all unique pairs in the system are analyzed. |
None
|
cell_constraints
|
list[tuple] | None
|
Whether to compute the RDF only for a subpart of the cell, given by the list of cell constraints. Each constraint is a tuple of the form (min, max) for the x, y, and z coordinates. The boundaries are inclusive. Defaults to None which means all atoms are included. |
None
|
n_workers
|
int
|
Number of workers to use for parallel RDF computation. Defaults to 1. |
1
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If no pairs are specified. |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
Dictionary with RDF results: - "(atomic number, atomic number)": (distances, avg_rdf) for each pair. Distances are in Å and avg_rdf is unitless (normalized). |
compute_viscosity
compute_viscosity(
T: float,
traj_id: str | None = None,
tmax_fs: int = 20000,
) -> tuple[float, tuple[np.ndarray, np.ndarray]]
Compute shear viscosity using Green-Kubo relation. The timestep between frames has to be constant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T
|
float
|
Temperature in K. The trajectory with the matching temperature is selected. |
required |
traj_id
|
str
|
Identifier for the trajectory, overrides T. Defaults to None. |
None
|
tmax_fs
|
int
|
Maximum correlation time in femtoseconds. Defaults to 20000. |
20000
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If the timestep between the frames is not constant. |
Returns:
| Type | Description |
|---|---|
tuple[float, tuple[ndarray, ndarray]]
|
Tuple[float, Tuple[np.ndarray, np.ndarray]]: Viscosity in Pa s and the autocorrelation function and times: - "eta": Viscosity in Pa s - "(autocorrelation, times)": (autocorrelation function, times) in eV²/Å⁶ fs and fs |