Machine-Learning Interatomic Potential Manager
Compute descriptors
Descriptor
- class mlacs.mlip.Descriptor(atoms, rcut=5.0, alpha=1.0, prefix='MLIP', **kwargs)
Base class for descriptors
- Parameters:
atoms (
ase.atoms) – Reference structure, with the elements for the descriptorrcut (
float) – The cutoff for the descriptor
SumDescriptor
- class mlacs.mlip.SumDescriptor(*args)
A class to mix several descriptors together.
- Parameters:
args (
listofDescriptor) – A list of all the descriptors to mix.
SnapDescriptor
- class mlacs.mlip.SnapDescriptor(atoms, rcut=5.0, parameters={}, model='linear', alpha=1.0, alpha_quad=1.0, prefix='SNAP', **kwargs)
Interface to the SNAP potential of LAMMPS.
- Parameters:
atoms (
ase.atoms) – Reference structure, with the elements for the descriptorrcut (
float) – The cutoff of the descriptor, in angstrom Default 5.0parameters (
dict) –A dictionnary of parameters for the descriptor input
The default values are
twojmax = 8
rfac0 = 0.99363
rmin0 = 0.0
switchflag = 1
bzeroflag = 1
wselfallflag = 0
model (
str) – The type of model use. Can be either ‘linear’ or ‘quadratic’ Default linearalpha (
float) – The multiplication factor to the regularization parameter for ridge regression. Default 1.0alpha_quad (
float) – A multiplication factor for the regularization that apply only to the quadratic component of the descriptor Default 1.0
Examples
>>> from ase.build import bulk >>> atoms = bulk("Cu", cubic=True).repeat(2) >>> >>> from mlacs.mlip import SnapDescriptor, LinearPotential >>> desc = SnapDescriptor(atoms, rcut=4.2, parameters=dict(twojmax=6)) >>> desc.compute_descriptor(atoms)
MliapDescriptor
- class mlacs.mlip.MliapDescriptor(atoms, rcut=5.0, parameters={}, model='linear', style='snap', alpha=1.0, prefix='MLIAP', **kwargs)
Interface to the MLIAP potential of LAMMPS.
- Parameters:
atoms (
ase.atoms) – Reference structure, with the elements for the descriptorrcut (
float) – The cutoff of the descriptor, in angstrom Default 5.0parameters (
dict) –A dictionnary of parameters for the descriptor input
If the style is set to snap, then the default values are
twojmax = 8
rfac0 = 0.99363
rmin0 = 0.0
switchflag = 1
bzeroflag = 1
wselfallflag = 0
If the style is set to so3, then the default values are
nmax = 4
lmax = 4
alpha = 1.0
model (
str) – The type of model use. Can be either ‘linear’ or ‘quadratic’ Default linearstyle (
str) – The style of the descriptor used. Can be either ‘snap’ or ‘so3’ Default ‘snap’alpha (
float) – The multiplication factor to the regularization parameter for ridge regression. Default 1.0
Examples
AceDescriptor
- class mlacs.mlip.AceDescriptor(atoms, free_at_e, rcut=5.0, tol_e=5, tol_f=25, bconf_dict=None, loss_dict=None, fitting_dict=None, backend_dict=None, nworkers=None)
Interface to the ACE potential using python-ace. Pace potential in LAMMPS. Usually a better generalization than SNAP but harder to train. Can be used with state at different pressure. Note : You will probably want to use 10-20 states since the
fitting is relatively slow
- Parameters:
atoms (
ase.atomsor list) – Reference structure, with the elements for the descriptorfree_at_e (
dict) – The energy of one atom for every element. The atom MUST be isolated in a big box (eV/at) e.g. : {‘Cu’: 12.1283, ‘O’: 3.237}rcut (
float) – The cutoff of the descriptor, in angstrom Default 5.0tol_e (
float) – The tolerance on energy between ACE and DFT (meV/at) Default 5tol_f (
float) – The tolerance on forces between ACE and DFT (meV/ang) Default 25bconf_dict (
dict) –A dictionnary of parameters for the BBasisConfiguration The default values are
deltaSplineBins: 0.001
elements: Found dynamically (e.g. Cu2O: [‘Cu’, ‘O’])
- embeddings: {“ALL”: {npot: ‘FinnisSinclairShiftedScaled’,
fs_parameters: [1, 1, 1, 0.5], ndensity: 2}}
- bonds: {“ALL”: {radbase: ‘ChebExpCos’,
NameOfCutoffFunction: ‘cos’, radparameters: [5.25], rcut: 7, dcut: 0.01}}
- functions: {“ALL”: {nradmax_by_orders: [15, 3, 2],
lmax_by_orders: [0, 2, 2]}}
loss_dict (
dict) –A dictionnary of parameters for the loss function The default values are
kappa: 0.3
L1_coeffs: 1e-12
L2_coeffs: 1e-12
w0_rad: 1e-12
w1_rad: 1e-12
w2_rad: 1e-12
fitting_dict (
dict) –A dictionnary of parameters for the minimization The default values are
weighting: MBAR|Uniform otherwise
loss: loss_dict
maxiter: 100
fit_cycles: 1
repulsion: ‘auto’
optimizer: ‘BFGS’
optimizer_options: {disp: True, gtol: 0, xrtol: 0}
backend_dict (
dict) –A dictionnary of parameters for the backend The default values are
evaluator: ‘tensorpot’
parallel_mode: ‘parallel’
n_workers : None
batch_size: 100
display_step: 50
Add a weighting policy
FixedWeight
- class mlacs.mlip.FixedWeight(static_weight=array([0]), subweight=None, energy_coefficient=1.0, forces_coefficient=1.0, stress_coefficient=1.0)
Class that gives a static weight to the first few configurations and then use the given WeightingPolicy for the other configurations. Can be used to give a fixed weight to the training configurations
- Parameters:
subweight (
WeightingPolicy) – Weight of the configurations after Default UniformWeightstatic_weight (
np.array) – Weights of the first configuration. The number of configuration is given by the length of the array. The weight must be normalized Default [0]
EnergyBasedWeight
- class mlacs.mlip.EnergyBasedWeight(delta=1.0, energy_coefficient=1.0, forces_coefficient=1.0, stress_coefficient=1.0, database=None, weight=None)
Class that gives weight according to w_n = C/[E_n - E_min + delta]**2 where C is a normalization constant.
- Parameters:
delta (
float) – Shift to avoid overweighting of the ground state (eV/at) Default 1.0
UniformWeight
- class mlacs.mlip.UniformWeight(nthrow=0, energy_coefficient=1.0, forces_coefficient=1.0, stress_coefficient=1.0, database=None, weight=None)
Class that gives uniform weight in MLACS.
- Parameters:
nthrow (
int) –Number of configurations to ignore when doing the fit. Three cases:
If nconf > 2*nthrow, remove the nthrow first configuration
If nthrow < nconf < 2*nthrow, remove the nconf-nthrow first conf
If nconf < nthrow, keep all conf
IncreasingWeight
- class mlacs.mlip.IncreasingWeight(nthrow=0, power=1, energy_coefficient=1.0, forces_coefficient=1.0, stress_coefficient=1.0, database=None, weight=None)
Class that gives increasing weight with the index of a configuration in MLACS. This weighting policy has been though for structural optimization.
- Parameters:
nthrow (
int) –Number of configurations to ignore when doing the fit. Three cases :
If nconf > 2*nthrow, remove the nthrow first configuration
If nthrow < nconf < 2*nthrow, remove the nconf-nthrow first conf
If nconf < nthrow, keep all conf
MbarManager
- class mlacs.mlip.MbarManager(parameters={}, energy_coefficient=1.0, forces_coefficient=1.0, stress_coefficient=1.0, **kwargs)
Computation of weight according to the multistate Bennett acceptance ratio (MBAR) method for the analysis of equilibrium samples from multiple arbitrary thermodynamic states.
- Parameters:
solver (
str) – Define type of solver for pymbar Default L-BFGS-Bscale (
float) – Imposes weights for the new configurations. Default 1.0start (
int) – Step to start weight computation. At least 2 since you need two potentials to compare them. Default 2database (
ase.Trajectory) – Initial database (optional) DefaultNoneweight (
listorstr) – If you use an initial database, it needs weight. Can a list or an np.array of values or a file. DefaultNone
Fitting model
MlipManager
- class mlacs.mlip.MlipManager(descriptor, weight=None, folder='MLIP', **kwargs)
Parent Class for the management of Machine-Learning Interatomic Potential
LinearPotential
- class mlacs.mlip.LinearPotential(descriptor, parameters={}, weight=None, **kwargs)
Potential that assume a linear relation between the descriptor and the energy.
- Parameters:
descriptor (
Descriptor) – The descriptor used in the model.parameters (
dict) – The parameters for the fit. By default, the fit is a simple ordinary least squares. Ridge regression can be use by setting a dictionnary asdict(method=ridge, lambda_ridge=alpha), with alpha the ridge coefficient.weight (
WeightingPolicy) – Weight used for the fitting and calculation of properties. DefaultNone, which results in the use of uniform weights.
Examples
>>> from ase.io import read >>> confs = read('Trajectory.traj', index=':') >>> >>> from mlacs.mlip import SnapDescriptor, LinearPotential >>> desc = SnapDescriptor(confs[0], rcut=6.2, parameters=dict(twojmax=6)) >>> mlip = LinearPotential(desc) >>> >>> mlip.update_matrices(confs) >>> mlip.train_mlip()
MomentTensorPotential
- class mlacs.mlip.MomentTensorPotential(atoms, mlpbin='mlp', mtp_parameters={}, fit_parameters={}, folder='MTP', **kwargs)
Interface to the Moment Tensor Potential of the MLIP package.
- Parameters:
atoms (
ase.Atoms) – Prototypical configuration for the MLIP. Should have the desired species.mlpbin (
str) – The path to the mlp binary. If mpi is desired, the command should be set as ‘mpirun /path/to/mlp’mtp_parameters (
dict) –The dictionnary with inputs for the potential.
The default values are set to
level = 8
radial_basis_type = ‘RBChebyshev’
min_dist=1.0,
max_dist=5.0,
radial_basis_size=8
fit_parameters (
dict) –The parameters for the fit of the potential
- The default parameters are set to
scale_by_forces=0
max_iter=1000
bfgs_conv_tol=1e-3
weighting=’vibrations’
(weight_scaling=1, weight_scaling_forces=0 for MLIP-3)
init_params=’random’
update_mindist=False
Examples
>>> from ase.io import read >>> confs = read('Trajectory.traj', index=':') >>> >>> from mlacs.mlip import MomentTensorPotential >>> mlip = MomentTensorPotential(confs[0], mtp_parameters=dict(level=6)) >>> mlip.update_matrices(confs) >>> mlip.train_mlip()
TensorpotPotential
- class mlacs.mlip.TensorpotPotential(descriptor, weight=None, **kwargs)
Potential that use Tensorpotential to minimize a cost function. For now, only works with AceDescriptor
- Parameters:
descriptor (
Descriptor) – The descriptor used in the model.weight (
WeightingPolicy) – Weight used for the fitting and calculation of properties. DefaultNone
Examples
>>> from ase.io import read >>> confs = read('Trajectory.traj', index=':') >>> >>> from mlacs.mlip import AceDescriptor, TensorpotPotential >>> desc = AceDescriptor(confs[0], free_at_e={'Cu': 0}, rcut=rcut) >>> mlip = TensorpotPotential(desc, folder="ACE") >>> >>> mlip.update_matrices(confs) >>> mlip.train_mlip()
DeltaLearningPotential
- class mlacs.mlip.DeltaLearningPotential(model, pair_style, pair_coeff, model_post=None, atom_style='atomic', folder=None, **kwargs)
- Parameters:
model (
MlipManager) – The MLIP model to train on the difference between the true energy and the energy of a LAMMPS reference model.pair_style (
strorlistofstr) – The pair_style of the LAMMPS reference potential. If only one pair style is used, can be set as astr. If an overlay of pair style is used, this input as to be alistofstrof the pair_style. For example :pair_coeff (
listofstr) – The pair_coeff of the LAMMPS reference potential.folder (
str(optional)) – The root for the directory in which the MLIP are stored. Default ‘MLIP’
Examples
>>> from ase.io import read >>> confs = read('Trajectory.traj', index=':') >>> >>> from mlacs.mlip import SnapDescriptor, LinearPotential >>> desc = SnapDescriptor(confs[0], rcut=6.2, parameters=dict(twojmax=6)) >>> mlip = LinearPotential(desc) >>> >>> from mlacs.mlip import DeltaLearningPotential >>> ps = ['sw', 'zbl 3.0 4.0'] >>> pc = [['* * Si.sw Si'], ['* * 14 14']] >>> dmlip = DeltaLearningPotential(mlip, pair_style=ps, pair_coeff=pc) >>> dmlip.update_matrices(confs) >>> dmlip.train_mlip()
MlipCalculator
- class mlacs.mlip.calculator.MlipCalculator(model, **kwargs)
Ase Caculator object for MLACS generated MLIP that can take atomic configurations from an Atoms object and calculate the energy, forces and also stresses.