nanotools.relaxation.general_material module
- class nanotools.relaxation.general_material.NBRelaxer(atomcell, relaxation_type='atom_partial_relax', tolerance=0.05, max_steps=100, fix_atoms_index=[0], ase_atoms=None, atoms_relaxed=None)[source]
Bases:
object
NBRelaxer
class.The
NBRelaxer
class is used for the relaxation of atomic structures of general material systems. It uses the pretrained universal neural network potential, CHGNet, to accurately predict atomic forces and energies, facilitating the structural relaxation process using the Atomic Simulation Environment (ASE).- relaxation_type
The type of relaxation to perform. Available options are: “atom_partial_relax”: Relax the material while fixing certain atoms.
The indices of the atoms to be fixed are specified using the
fix_atoms_index
parameter. By default, the first atom is fixed.“cell_fractional_relax”: Relax the unit cell while keeping the scaled positions fixed. “unconstrained_relax”: Perform a full relaxation without any constraints.
- Type:
str
- tolerance
The atomic force tolerance for the relaxation. The unit is eV/Å.
- Type:
float
- max_steps
The maximum number of optimization steps to perform.
- Type:
int
- fix_atoms_index
The indices of atoms to fix during the relaxation. If not given, by default, the first atom is fixed.
- Type:
list
- plot_energy(filename: str | bytes | PathLike | None = None, show=False, trajectory_filename: str = 'relax.traj')[source]
Plot the energy during the optimization and save the plot to a file.
- Parameters:
filename (os.Pathlike, optional) – The filename of the file to save the plot to. Defaults to “Energy”.
show (bool, optional) – Whether to display the plot. Defaults to False.
trajectory_filename (str) – The filename of the trajectory file to load.
- Raises:
FileNotFoundError – If the trajectory file is not found.
- Returns:
None
- relax(use_device='cpu')[source]
Perform relaxation based on the relaxation type.
- Parameters:
use_device (str, optional) – The device to use for the calculation. Defaults to “cpu”.
- Returns:
None
- relax_full(calculator)[source]
Perform a full relaxation without any constraints using the provided calculator.
- Parameters:
calculator – The calculator to use for the relaxation.
- Returns:
None
- relax_position(calculator)[source]
Relax the position of atoms using the provided calculator.
- Parameters:
calculator – The calculator to use for the relaxation.
- Returns:
None
- relax_strain(calculator)[source]
Relax the unit cell until the stress is zero while keeping the scaled positions fixed using the provided calculator.
- Parameters:
calculator – The calculator to use for the relaxation.
- Returns:
None
- visualize_trajectory(trajectory_filename: str = 'relax.traj')[source]
Attempts to read a trajectory file and display it.
- Parameters:
trajectory_filename (str) – The filename of the trajectory file to load.
- Raises:
FileNotFoundError – If the trajectory file is not found, a warning message is printed and the program exits with status code 1.
- Returns:
None
- write(filename: str | bytes | PathLike | None = None, output_format: str = 'xyz')[source]
Write the relaxed atoms to a file in a specified format.
- Parameters:
filename (os.Pathlike, optional) – The filename of the file. Defaults to “relaxed”.
output_format (str, optional) – The format to write the file in. Defaults to “xyz”.
- Raises:
ValueError – If self.atoms_relaxed is None or if output_format is not a valid output format.
- Returns:
None