Utilities
Lammps IO
Abinit IO
- class mlacs.utilities.io_abinit.AbinitNC(workdir=None, prefix='abinit', suffix=None)
Class to read all netCDF files created by Abinit.
Can also convert a netCDF file into a list of ASE Atoms objects, cf. convert_to_atoms().
- Parameters:
workdir (
str(optional)) – The root for the directory. Default ‘DFT’prefix (
str(optional)) – The prefix of Abinit nc file, i.e. str before o_{suffix}.nc.suffix (
str(optional)) – ‘HIST’ or ‘GSR’ or ‘OUT’. If no suffix is given, it is set automatically by _update_suffix().
Examples
netCDF files can be loaded by defining the ncfile attribute, here for instance with a HIST.nc:
hist = AbinitNC() hist.ncfile = '/path/to/HIST.nc' atoms_list = hist.convert_to_atoms()
Alternatively, one can directly pass workdir, prefix, suffix as parameters of the AbinitNC class. The path of the ncfile must follow the syntax f’{workdir}{prefix}o_{suffix}.nc’. For instance with a GSR.nc:
gsr = AbinitNC(workdir=workdir, prefix=prefix, suffix='GSR') atoms_list = gsr.convert_to_atoms()
Once the netCDF files are loaded, the data can be extracted as a dictionary where keys are Abinit variable names and values are arrays in atomic units:
hist_results = hist.read() energy = hist_results['etotal'] # Atomic units
Alternatively, conversion to a list of ASE atoms can also be achieved in the following way:
hist_atoms_list = hist.convert_to_atoms() # ASE units gsr_atoms_list = gsr.convert_to_atoms() # ASE units
Thermodynamic
Functions to compute some thermodynamic properties
free_energy_harmonic_oscillator
- mlacs.utilities.thermo.free_energy_harmonic_oscillator(omega, T, nat, classical=True)
Function to compute the free energy of a Einstein crystal
- Parameters:
omega (
floatorlistoffloat) – The frequency of the oscillatorT (
float) – The temperature, in Kelvinnat (
intorlistofint) – Number of atoms in the supercell associated with each frequencyclassical (
Bool(optional)) – Whether to use the classical formulation (True) or the quantum formulation (False)
- Returns:
f_cm – Free energy of the Einstein crystal, in eV/at
- Return type:
float
free_energy_com_harmonic_oscillator
- mlacs.utilities.thermo.free_energy_com_harmonic_oscillator(k, T, nat, vol, masses)
Function to compute the free energy of the center of mass of an harmonic oscillator
- Parameters:
k (
floatorlistoffloat) – Spring constant of the harmonic oscillators, in eV/angsT (
float) – Temperature, in Kelvinnat (
intorlistofint) – Number of atoms in the supercell associated with each frequencymasses (
floatorlistoffloat) – masses of atoms in the supercell
- Returns:
f_cm – Free energy of the center of mass, in eV/at
- Return type:
float
free_energy_ideal_gas
- mlacs.utilities.thermo.free_energy_ideal_gas(vol, nat, mass, T)
Function to compute the free energy of an ideal gas, uses Stirling formula
- Parameters:
vol (
float) – Volume, in angstrom^3nat (
intorlistofint) – Number of atoms in the supercell associated with each massesmasses (
floatorlistoffloat) – masses of atoms in the supercellT (
float) – Temperature, in Kelvin
- Returns:
f_ig – Free energy of the ideal gas, in eV/at
- Return type:
float
free_energy_uhlenbeck_ford
- mlacs.utilities.thermo.free_energy_uhlenbeck_ford(rho, p, sigma, T)
Function to compute the free energy of the Uhlenbeck-Ford potential Adapted from the supplementary materials of
J. Chem. Phys. 145 194101 (2016) Rodolfo Paula Leite, Rodrigo Freitas, Rodolfo Azevedo and Maurice de Koning
- Parameters:
rho (
float) – Density, in angstrom^-3p (
int) – Parameter of the Uhlenbeck-Ford potential. Allowed values are1,25,50,75or100sigma (
float) – Sigma parameter of the Ulhenbeck-Ford potential.T (
float) – Temperature, in Kelvin
- Returns:
f_uf – Excess free energy of the Uhlenbeck-Ford potential compared to the ideal gas, in eV/at
- Return type:
float
Path Integral
compute_centroid_atoms
- mlacs.utilities.path_integral.compute_centroid_atoms(confs, temperature)
Function to compute the centroid
- Parameters:
confs (
listofase.Atoms) – The configurations of the quantum polymertemperature (
float) –
- Returns:
atoms – The centroid of the quantum polymer
- Return type:
ase.Atoms
Minimum Energy Path
- class mlacs.core.PathAtoms(images, xi=None, mode='saddle', interval=None, fixcom=True, **kwargs)
Base class for managing transiton state.
- Parameters:
images (
listor PathAtoms) – mlacs.PathAtoms or list of ase.Atoms object. The list contain initial and final configurations of the reaction path.xi (
numpy.arrayor float) – Value of the reaction coordinate for the constrained MD. DefaultNonemode (
floatorstring) –- Value of the reaction coordinate or sampling mode
saddlereturn the saddle point.floatsampling at a precise coordinate.rdmrandomly return the coordinate of a splined images.rdm_truerandomly return the coordinate of an images.rdm_memoryhomogeneous sampling of splined images.gaussianBayesian Inference sampling.
Default
saddleinterval (
list) – Define the interval limits to sample the reaction coordinate. Take only two values [min, max]. Default[0, 1]fixcom – Include the center of mass displacement along the reaction coordinate. Default
True
- property final
Get last image
- get_splined_atoms(xi=None)
Return splined Atoms objects at the xi coordinates.
- property images
Get true images
- property initial
Get first image
- property masses
Get the effective masses of particles
- set_splined_matrices(xi=None)
Compute a 1D CubicSpline interpolation from a NEB calculation. The function also set up the lammps data file for a constrained MD.
Three first columns: atomic positons at reaction coordinate xi.
- Three next columns: normalized atomic first derivatives at
reaction coordinate xi, with the corrections of the COM.
- Three last columns: normalized atomic second derivatives at
reaction coordinate xi.
- property splined
Get splined images
- property update
Update the reaction coordinate.
- property xi
Get the reaction coordinate.
Miscellanous
- mlacs.utilities.miscellanous.get_elements_Z_and_masses(supercell)
Get the unique chemical symbols and atomic numbers of a supercell. The list are returned according to the alphabetical order of the elements.
- Parameters:
supercell (
ase.Atoms) – ASE atoms object- Returns:
elements (
listofstr) – list of unique elements in the supercellZ (
listofint) – list of unique Z in the supercellmasses (
listoffloat) – list of unique masses in the supercell
- mlacs.utilities.miscellanous.create_random_structures(atoms, std, nconfs)
Create nconfs random structures by displacing atoms around positions.
- Parameters:
atoms (
ase.Atomsorlistofase.Atoms) – ASE atoms objects to be rattledstd (
float) – Standard deviation of the gaussian used to generate the random displacements. In angstrom.nconfs (
int) – Number of configurations to generate
- Returns:
confs – Configurations with random displacements
- Return type:
listofase.Atoms
- mlacs.utilities.miscellanous.compute_correlation(data, weight=None)
Function to compute the RMSE, MAE and Rsquared
- Parameters:
data (
numpy.ndarrayof shape (ndata, 2)) – The data for which to compute the correlation. The first column should be the ground truth and the second column should be the prediction of the modelweight (
numpy.ndarray) – Weight to be applied to compute the averages. Has to be a divisor of the length of the data
- Returns:
result – An length 3 array with (in order) the rmse, mae and
R^2- Return type:
numpy.ndarray
- mlacs.utilities.miscellanous.compute_averaged(traj, weights=None)
Function to compute the averaged Atoms configuration from a Trajectory.
- Parameters:
data (
ase.Trajectory) – List of ase.Atoms object.- Returns:
confs – Averaged configuration
- Return type:
ase.Atoms
- mlacs.utilities.miscellanous.interpolate_points(x, y, xf, order=0, smooth=0, periodic=0, border=None)
Interpolate points.
- Parameters:
x (
numpy.array) – List of points to interpolatey (
numpy.array) – List of points to interpolatexf (
numpy.array) – New thiner list of pointsorder (
int) – Order of the splinesmooth (
int) – Smoothing parameterperiodic (
int) – Activate periodic function boundary conditionsborder (
bol) – Impose a zero derivative condition at the function boundaries
- Returns:
yf – List of interpolated points
- Return type:
list
- mlacs.utilities.miscellanous.integrate_points(x, y, xf, order=0, smooth=0, periodic=0, border=None)
Interpolate points and return derivatives.
- Parameters:
x (
numpy.array) – List of points to interpolatey (
numpy.array) – List of points to interpolatexf (
numpy.array) – New thiner list of pointsorder (
int) – Order of the splinesmooth (
int) – Smoothing parameterperiodic (
int) – Activate periodic function boundary conditionsborder (
bol) – Impose a zero derivative condition at the function boundaries
- Returns:
yf – Integral of spline from start to xf
- Return type:
list