matcalc.backend._ase module
This module implements convenience functions to perform various atomic simulation types, specifically relaxation and static, using either ASE or LAMMPS. This enables the code to use either for the computation of various properties.
- class TrajectoryObserver(atoms: Atoms, potential_energies: list[float] = <factory>, kinetic_energies: list[float] = <factory>, total_energies: list[float] = <factory>, forces: list[NDArray[np.float64]] = <factory>, stresses: list[NDArray[np.float64]] = <factory>, atom_positions: list[NDArray[np.float64]] = <factory>, cells: list[NDArray[np.float64]] = <factory>)[source]
Bases:
object
Handles the observation and tracking of the trajectory-related properties of an Atoms object.
The class captures and stores various physical properties of an Atoms object during relaxation steps or a simulation. It allows for the extraction of property snapshots, slicing trajectory data, and saving the stored data to a file for further analysis or reuse.
- potential_energies[source]
list[float] List to store the potential energies recorded during the trajectory.
- Type:
list[float]
- kinetic_energies[source]
list[float] List to store the kinetic energies recorded during the trajectory.
- Type:
list[float]
- total_energies[source]
list[float] List to store the total energies recorded during the trajectory.
- Type:
list[float]
- forces[source]
list[np.ndarray] List to store the atomic forces measured during the trajectory.
- Type:
list[NDArray[np.float64]]
- stresses[source]
list[np.ndarray] List to store the stress tensors recorded during the trajectory.
- Type:
list[NDArray[np.float64]]
- atom_positions[source]
list[np.ndarray] List to store the atomic positions recorded during the trajectory.
- Type:
list[NDArray[np.float64]]
- cells[source]
list[np.ndarray] List to store the simulation cell geometries recorded during the trajectory.
- Type:
list[NDArray[np.float64]]
- get_slice(sl: slice) TrajectoryObserver [source]
Gets a sliced view of the trajectory data encapsulated within a new TrajectoryObserver object, based on the provided slice. This method extracts the corresponding segment of the trajectory data for all relevant attributes and returns a new TrajectoryObserver object containing the sliced values.
- Parameters:
sl (slice) – The slice object specifying the indices to extract from the trajectory data.
- Returns:
- A new TrajectoryObserver instance containing the sliced
trajectory data.
- Return type:
- get_ase_optimizer(optimizer: str | Optimizer) Optimizer [source]
Retrieve an ASE optimizer instance based on the provided input. This function accepts either a string representing the name of a valid ASE optimizer or an instance/subclass of the Optimizer class. If a string is provided, it checks the validity of the optimizer name, and if valid, retrieves the corresponding optimizer from ASE. An error is raised if the optimizer name is invalid.
If an Optimizer subclass or instance is provided as input, it is returned directly.
- Parameters:
optimizer (str | Optimizer) – The optimizer to be retrieved. Can be a string representing a valid ASE optimizer name or an instance/subclass of the Optimizer class.
- Returns:
The corresponding ASE optimizer instance or the input Optimizer instance/subclass.
- Return type:
Optimizer
- Raises:
ValueError – If the optimizer name provided as a string is not among the valid ASE optimizer names defined by VALID_OPTIMIZERS.
- is_ase_optimizer(key: str | Optimizer) bool [source]
Determines whether the given key is an ASE optimizer. A key can either be a string representing the name of an optimizer class within ase.optimize or directly be an optimizer class that subclasses Optimizer.
If the key is a string, the function checks whether it corresponds to a class in ase.optimize that is a subclass of Optimizer.
- Parameters:
key – The key to check, either a string name of an ASE optimizer class or a class object that potentially subclasses Optimizer.
- Returns:
True if the key is either a string corresponding to an ASE optimizer subclass name in ase.optimize or a class that is a subclass of Optimizer. Otherwise, returns False.
- run_ase(structure: Structure | Atoms, calculator: Calculator, *, relax_atoms: bool = False, relax_cell: bool = False, optimizer: Optimizer | str = 'FIRE', max_steps: int = 500, traj_file: str | None = None, interval: int = 1, fmax: float = 0.1, cell_filter: Filter = <class 'ase.filters.FrechetCellFilter'>) SimulationResult [source]
Run ASE static calculation using the given structure and calculator.
Parameters: structure (Structure|Atoms): The input structure to calculate potential energy, forces, and stress. calculator (Calculator): The calculator object to use for the calculation.
Returns: PESResult: Object containing potential energy, forces, and stress of the input structure.