Utilities

Lammps IO

class mlacs.utilities.io_lammps.LammpsInput(preambule=None)
add_block(name, block, order=-1, before=None, after=None)
to_string()
class mlacs.utilities.io_lammps.LammpsBlockInput(name, title=None)
add_variable(name, line, order=-1, before=None, after=None)
extend(block)

Concatenate Blocks

pop(name)

Remove block line

to_string()

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 (float or list of float) – The frequency of the oscillator

  • T (float) – The temperature, in Kelvin

  • nat (int or list of int) – Number of atoms in the supercell associated with each frequency

  • classical (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 (float or list of float) – Spring constant of the harmonic oscillators, in eV/angs

  • T (float) – Temperature, in Kelvin

  • nat (int or list of int) – Number of atoms in the supercell associated with each frequency

  • masses (float or list of float) – 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^3

  • nat (int or list of int) – Number of atoms in the supercell associated with each masses

  • masses (float or list of float) – masses of atoms in the supercell

  • T (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^-3

  • p (int) – Parameter of the Uhlenbeck-Ford potential. Allowed values are 1, 25, 50, 75 or 100

  • sigma (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 (list of ase.Atoms) – The configurations of the quantum polymer

  • temperature (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 (list or PathAtoms) – mlacs.PathAtoms or list of ase.Atoms object. The list contain initial and final configurations of the reaction path.

  • xi (numpy.array or float) – Value of the reaction coordinate for the constrained MD. Default None

  • mode (float or string) –

    Value of the reaction coordinate or sampling mode
    • saddle return the saddle point.

    • float sampling at a precise coordinate.

    • rdm randomly return the coordinate of a splined images.

    • rdm_true randomly return the coordinate of an images.

    • rdm_memory homogeneous sampling of splined images.

    • gaussian Bayesian Inference sampling.

    Default saddle

  • interval (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 (list of str) – list of unique elements in the supercell

  • Z (list of int) – list of unique Z in the supercell

  • masses (list of float) – 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.Atoms or list of ase.Atoms) – ASE atoms objects to be rattled

  • std (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:

list of ase.Atoms

mlacs.utilities.miscellanous.compute_correlation(data, weight=None)

Function to compute the RMSE, MAE and Rsquared

Parameters:
  • data (numpy.ndarray of 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 model

  • weight (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 interpolate

  • y (numpy.array) – List of points to interpolate

  • xf (numpy.array) – New thiner list of points

  • order (int) – Order of the spline

  • smooth (int) – Smoothing parameter

  • periodic (int) – Activate periodic function boundary conditions

  • border (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 interpolate

  • y (numpy.array) – List of points to interpolate

  • xf (numpy.array) – New thiner list of points

  • order (int) – Order of the spline

  • smooth (int) – Smoothing parameter

  • periodic (int) – Activate periodic function boundary conditions

  • border (bol) – Impose a zero derivative condition at the function boundaries

Returns:

yf – Integral of spline from start to xf

Return type:

list