dptools.simulate package
- class dptools.simulate.CellOpt(atoms, graph, type_map, file_out='atoms.traj', path='./', **kwargs)
Bases:
Simulation- calc_type = 'cellopt'
- get_commands(nsw=1000, ftol=0.01, etol=0.0, opt_type='aniso', Ptarget=0.0, disp_freq=10, **kwargs)
- class dptools.simulate.DeepMD(graph, type_map=None, minimize=False, relax_cell=False, ftol=0.01, lmp=None, run_command=None, verbose=False, label='lamp', **kwargs)
Bases:
LmpCalcASE calculator to interface with LAMMPS and DeePMD-kit.
- Parameters:
graph (str) – Path to deepmd-kit .pb file with saved MLP model.
type_map (dict) – Dictionary of atom type mapping for graph. Should be able to infer automatically from graph, but for some reason (related to deepmd’s tensorflow version, I think) lammps crashes if DeepPotential is imported before running. In short, type_map is not optional until that issue is resolved.
minimize (bool) – Run lammps geometry optimizaiton. Shortcut to be used instead of entering the minimize commands in run_command.
relax_cell (bool) – Run lammps unit cell optimization. Shortcut to be used instead of entering the box/relax fix and minimize commands in run_command.
ftol (float) – Force tolerance for lammps minimize convergence, only used if minimize or relax_cell are set to True.
lmp (lammps.core.lammps) – lammps instance (from lmp = lammps.lammps()). Creates new instance if None specified.
run_command (list[str] or str) – lammps commands to run simulation beyond the general setup commands obtained from lammps_io.LammpsInput
verbose (bool) – Display lammps output in console if True.
- implemented_properties: List[str] = ['energy', 'forces', 'stress']
Properties calculator can handle (energy, forces, …)
- name = 'DP'
- set_atoms(atoms=None)
- set_charges()
- set_coeffs()
- set_types(atoms=None)
- write_input(atoms=None)
System / forcefield specific
- class dptools.simulate.NPT(atoms, graph, type_map, file_out='atoms.traj', path='./', **kwargs)
Bases:
Simulation- calc_type = 'npt-md'
- get_commands(steps=10000, timestep=0.5, Pi=0.0, Pf=0.0, Ti=298.0, Tf=298.0, equil_steps=1000, write_freq=100, disp_freq=100, **kwargs)
- process(file_out=None)
Simulation specific method to process and write results after calculation.
- setup(pre_opt=False, **kwargs)
Simulation specific method to do any needed setup before running (e.g., cell deformations). Must call self.get_commands() method.
- class dptools.simulate.NVT(atoms, graph, type_map, file_out='atoms.traj', path='./', **kwargs)
Bases:
Simulation- calc_type = 'nvt-md'
- get_commands(steps=10000, timestep=0.5, Ti=298.0, Tf=298.0, equil_steps=1000, write_freq=100, disp_freq=100, **kwargs)
- process(file_out=None)
Simulation specific method to process and write results after calculation.
- setup(pre_opt=False, **kwargs)
Simulation specific method to do any needed setup before running (e.g., cell deformations). Must call self.get_commands() method.
- class dptools.simulate.Opt(atoms, graph, type_map, file_out='atoms.traj', path='./', **kwargs)
Bases:
Simulation- calc_type = 'opt'
- get_commands(nsw=1000, ftol=0.01, etol=0.0, disp_freq=10, **kwargs)
- class dptools.simulate.SPE(atoms, graph, type_map, file_out='atoms.traj', path='./', **kwargs)
Bases:
SimulationSimple single point energy calculation, not much to it.
- calc_type = 'spe'
- get_commands(**kwargs)
Submodules
dptools.simulate.calculator module
- class dptools.simulate.calculator.BKS(type_map=None, minimize=False, relax_cell=False, ftol=0.01, lmp=None, run_command=None, verbose=False, label='lamp', cutoff=12.0, **kwargs)
Bases:
LmpCalc- implemented_properties: List[str] = ['energy', 'forces', 'stress']
Properties calculator can handle (energy, forces, …)
- write_input(atoms=None)
System / forcefield specific
- class dptools.simulate.calculator.ClayFF(type_map=None, minimize=False, relax_cell=False, ftol=0.01, lmp=None, run_command=None, verbose=False, label='lamp', cutoff=12.0, **kwargs)
Bases:
LmpCalc- implemented_properties: List[str] = ['energy', 'forces', 'stress']
Properties calculator can handle (energy, forces, …)
- write_input(atoms=None)
System / forcefield specific
- class dptools.simulate.calculator.DeepMD(graph, type_map=None, minimize=False, relax_cell=False, ftol=0.01, lmp=None, run_command=None, verbose=False, label='lamp', **kwargs)
Bases:
LmpCalcASE calculator to interface with LAMMPS and DeePMD-kit.
- Parameters:
graph (str) – Path to deepmd-kit .pb file with saved MLP model.
type_map (dict) – Dictionary of atom type mapping for graph. Should be able to infer automatically from graph, but for some reason (related to deepmd’s tensorflow version, I think) lammps crashes if DeepPotential is imported before running. In short, type_map is not optional until that issue is resolved.
minimize (bool) – Run lammps geometry optimizaiton. Shortcut to be used instead of entering the minimize commands in run_command.
relax_cell (bool) – Run lammps unit cell optimization. Shortcut to be used instead of entering the box/relax fix and minimize commands in run_command.
ftol (float) – Force tolerance for lammps minimize convergence, only used if minimize or relax_cell are set to True.
lmp (lammps.core.lammps) – lammps instance (from lmp = lammps.lammps()). Creates new instance if None specified.
run_command (list[str] or str) – lammps commands to run simulation beyond the general setup commands obtained from lammps_io.LammpsInput
verbose (bool) – Display lammps output in console if True.
- implemented_properties: List[str] = ['energy', 'forces', 'stress']
Properties calculator can handle (energy, forces, …)
- write_input(atoms=None)
System / forcefield specific
- class dptools.simulate.calculator.LmpCalc(type_map=None, minimize=False, relax_cell=False, ftol=0.01, lmp=None, run_command=None, verbose=False, label='lamp', **kwargs)
Bases:
CalculatorBase class for lammps ASE calculator.
- calculate(atoms=None, properties=['energy', 'forces', 'stress'], system_changes=['positions', 'numbers', 'cell', 'pbc', 'initial_charges', 'initial_magmoms'], update=True)
Run lammps calculation on.
- Parameters:
atoms (ase.Atoms, optional) – Atoms object to run the calculation on.
properties (list[str]) – unused, only for function signature compatibility,
system_changes (list[str]) – unused, only for function signature compatibility
update (bool) – Update atoms with new positions, energy, forces, etc. if True.
- implemented_properties: List[str] = ['energy', 'forces', 'stress']
Properties calculator can handle (energy, forces, …)
- read_cell()
- Returns:
(list) – Cell lengths and angles to use with ASE [a, b, c, alpha, beta, gamma].
- read_stress()
- Returns:
stress (np.array) – Stress tensor in Voigt notation.
- update_atoms(atoms)
Update positions of atoms and shift to origin if necessary after running calculation (i.e. align lammps positions with ASE unit cell).
- write_input()
System / forcefield specific
dptools.simulate.lammps_io module
- class dptools.simulate.lammps_io.LammpsInput(atoms, type_dict, charges=None, bonds=False, angles=False, dihedrals=False, impropers=False, name='atoms', atom_style='full', pair_style=None, bond_style=None, angle_style=None, kspace_style=None, pair_coeff=None, bond_coeff=None, angle_coeff=None, groups=None)
Bases:
objectCreates lammps input files from ASE Atoms object. Works by setting as str attributes all neccessary lammps input information and commands, which are then inserted into the appropriate Template subclass.
- Parameters:
atoms (ase.Atoms) – structure used for lammps calculation
type_dict (dict) – map atom type index to element symbol (Element_tag to specify multiple types of same element) e.g., {1: ‘O’, 2: ‘Si’, 3: ‘O_h2o’, 4: ‘H_h2o’}
charges (array-like) – List or array of charges (float) on each atom. Must have len(charges) == len(atoms).
bonds (bool) – Define all bonds in structure data file if True.
angles (bool) – Define all angles in structure data file if True.
dihedrals (bool) – Define all dihedral angles in structure data file if True.
impropers (bool) – Define impropers in structure data file if True.
name (str, optional) – Name used for creating input files (name.data, in.name).
atom_style (str, optional) – lammps style for atomic positions, groups, etc.
pair_style (str, optional) – lammps pair_style command.
bond_style (str, optional) – lammps bond_style command.
angle_style (str, optional) – lammps angle_style command.
kspace_style (str, optional) – lammps kspace_style command.
groups (array-like, optional) – List of groups (int) for each atom. Must have len(groups) == len(atoms).
pair_coeff (list[str] or str, optional) – lammps pair_coeff line(s) to define ij interactions
- static prepend_command(command, text)
Prepend command to corresponding arguments str.
- Parameters:
command (str) – Name of lammps command to prepend to text.
text (str) – lammps arg str corresponding to command.
- Returns:
str – Full lammps line with command prepended to text.
Examples
self.prepend_command(‘kspace_style’, ‘pppm 1e-5’) ‘kspace_style pppm 1e-5’
- set_lmp_cmd(command, text)
Set lammps commands that follow the pattern: command args
- Parameters:
command (str) – Name of lammps command, e.g., pair_style.
text (list[str] or str) – Arguments to use with command. If text doesn’t lead with command, then command is prepended to text.
- write(atoms=None, charges=None)
Writes lammps data file and input file for atoms.
- Parameters:
atoms (ase.Atoms or None) – New atoms object used to write data file (or self.atoms if atoms is None).
charges (array-like or None) – Optional charges corresponding to atoms.
- write_angles()
(Deprecated, may restore) Write all angles in self.atoms to lammps datafile.
- write_atoms(atoms=None, charges=None)
Write lammps data file from atoms. Writes unit cell info, atom types, atomic positions, and bonds, angles, dihedrals, impropers if specified in __init__().
- Parameters:
atoms (ase.Atoms or None) – New atoms object used to write data file (or self.atoms if atoms is None).
charges (array-like or None) – Optional charges corresponding to atoms.
- write_bonds()
(Deprecated, may restore) Write all bonds in self.atoms to lammps datafile.
- write_cell()
Transform and write self.atoms’
ase.cell.Cellto lammps data file.
- write_coords()
Write Coords section (atomic positions) in lammps datafile.
- write_dihedrals()
Deprecated before it was even written :(
- write_geometry(key)
Generalized method to write bonds, angles, maybe dihedrals (untested) to lammps data file. Uses
ase.geometry.Analysisto generate list of bonds, angles, etc.- Parameters:
key (str) – Geometry component to write (‘bonds’, ‘angles’, ‘dihedrals’, ‘impropers’).
- write_impropers()
Deprecated before it was even written :(
- write_infile()
Write lammps input file containing all general setup commands (e.g. define units, read data file, etc.).
- write_types()
Write Types section in lammps data file (atomic masses for each atom type).
- class dptools.simulate.lammps_io.MolInput(atoms, type_dict, name='mol')
Bases:
objectClass for writing simple molecule files in lammps for deepmd.
TODO: add bonds, charges, etc. for future applications
- Parameters:
atoms (ase.Atoms) – Atoms object of molecule to write.
type_dict (dict) – map atom type index to element symbol (Element_tag to specify multiple types of same element) e.g., {1: ‘O’, 2: ‘Si’, 3: ‘O_h2o’, 4: ‘H_h2o’}
name (str) – Name of molecule for saving file (mol.name)
- class dptools.simulate.lammps_io.Template(file_name, lammps_input)
Bases:
objectBase class for writing lammps data and input files. Replaces all <attr> sections in subclass self.text with corresponding LammpsInput instance attributes that contain strings for each section.
- Parameters:
file_name (str) – Name of file to write, generally name.data or in.name.
lammps_input (LammpsInput instance) – LammpsInput object with str attributes used to fill in self.text with appropriate commands / values.
- fill()
Replaces <attr> sections in self.text with corresponding LammpsInput object attribute text.
- trim()
Remove unneccessary blank lines from self.text caused by inserting empty strings as commands.
- write()
Write lammps file to current directory.
dptools.simulate.parameters module
Functions for interacting with simulation parameter files (.yaml). If adding a new simulation parameter, add a description/usage hint to dptools.parameters.descriptions, and the hint will appear in params.yaml.
- dptools.simulate.parameters.get_parameter_sets()
Load simulation parameter sets from parameter_sets.yaml.
- dptools.simulate.parameters.reset_params()
- dptools.simulate.parameters.set_parameter_set(param_dict)
Write simulation parameter set to parameter_sets.yaml for future use.
- Parameters:
param_dict (dict) – Dictionary containing each parameter and its corresponding value.
- dptools.simulate.parameters.write_yaml(param_dict, file)
Write simulation parameter set to yaml file. Used by the get to retrieve params.yaml files for specific simulation to be edited and then either used with set or run command.
- Parameters:
param_dict (dict) – Dictionary containing each parameter and its corresponding value.
file (file object) – File to write simulation parameter set to (generally params.yaml)
dptools.simulate.simulations module
- class dptools.simulate.simulations.CellOpt(atoms, graph, type_map, file_out='atoms.traj', path='./', **kwargs)
Bases:
Simulation- calc_type = 'cellopt'
- get_commands(nsw=1000, ftol=0.01, etol=0.0, opt_type='aniso', Ptarget=0.0, disp_freq=10, **kwargs)
- class dptools.simulate.simulations.EOS(atoms, graph, type_map, file_out='atoms.traj', path='./', **kwargs)
Bases:
Simulation- calc_type = 'eos'
- get_commands(nsw=300, ftol=0.001, etol=0.0, disp_freq=10, **kwargs)
- process(file_out=None)
Simulation specific method to process and write results after calculation.
- set_volumes(lo, hi, N)
- setup(N=5, lo=0.96, hi=1.04, pre_opt=True, **kwargs)
Simulation specific method to do any needed setup before running (e.g., cell deformations). Must call self.get_commands() method.
- class dptools.simulate.simulations.GCMC(atoms, graph, type_map, file_out='atoms.traj', path='./', **kwargs)
Bases:
SimulationGrand-canonical monte carlo simulation.
- calc_type = 'gcmc'
- get_commands(steps=100, n_ex=10, n_mc=10, T=298.0, P=1.0, dmax=1.0, equil_steps=0, write_freq=1, disp_freq=5, **kwargs)
- process(file_out=None)
Simulation specific method to process and write results after calculation.
- setup(molecule='H2O', pre_opt=False, pre_opt_mol=False, **kwargs)
Simulation specific method to do any needed setup before running (e.g., cell deformations). Must call self.get_commands() method.
- class dptools.simulate.simulations.NPT(atoms, graph, type_map, file_out='atoms.traj', path='./', **kwargs)
Bases:
Simulation- calc_type = 'npt-md'
- get_commands(steps=10000, timestep=0.5, Pi=0.0, Pf=0.0, Ti=298.0, Tf=298.0, equil_steps=1000, write_freq=100, disp_freq=100, **kwargs)
- process(file_out=None)
Simulation specific method to process and write results after calculation.
- setup(pre_opt=False, **kwargs)
Simulation specific method to do any needed setup before running (e.g., cell deformations). Must call self.get_commands() method.
- class dptools.simulate.simulations.NVT(atoms, graph, type_map, file_out='atoms.traj', path='./', **kwargs)
Bases:
Simulation- calc_type = 'nvt-md'
- get_commands(steps=10000, timestep=0.5, Ti=298.0, Tf=298.0, equil_steps=1000, write_freq=100, disp_freq=100, **kwargs)
- process(file_out=None)
Simulation specific method to process and write results after calculation.
- setup(pre_opt=False, **kwargs)
Simulation specific method to do any needed setup before running (e.g., cell deformations). Must call self.get_commands() method.
- class dptools.simulate.simulations.NewSimulation(atoms, graph, type_map, file_out='atoms.traj', path='./', **kwargs)
Bases:
SimulationTemplate/example for making new simulation types in lammps.
- Parameters:
setup_arg1 – Argument from params.yaml that is passed to setup method
setup_arg2 – Argument from params.yaml that is passed to setup method
param_arg1 – Argument from params.yaml that is passed to get_commands method
param_arg2 – Argument from params.yaml that is passed to get_commands method
- get_commands(**kwargs)
- process(file_out=None)
Only needed if additional proceessing from lammps output is necessary. Also useful for printing results summaries.
- run(file_out=None)
Rarely need subclass run method. Test without it and if Simulation.run fails for whatever reason, write your own run method.
- setup(setup_arg1=None, setup_arg2=None, **kwargs)
Simulation specific method to do any needed setup before running (e.g., cell deformations). Must call self.get_commands() method.
- class dptools.simulate.simulations.Opt(atoms, graph, type_map, file_out='atoms.traj', path='./', **kwargs)
Bases:
Simulation- calc_type = 'opt'
- get_commands(nsw=1000, ftol=0.01, etol=0.0, disp_freq=10, **kwargs)
- class dptools.simulate.simulations.SPE(atoms, graph, type_map, file_out='atoms.traj', path='./', **kwargs)
Bases:
SimulationSimple single point energy calculation, not much to it.
- calc_type = 'spe'
- get_commands(**kwargs)
- class dptools.simulate.simulations.Simulation(atoms, graph, type_map, file_out='atoms.traj', path='./', **kwargs)
Bases:
objectBase class for setting up, running, and processing specific simulations in LAMMPS using DP models for energy and force evaluations.
- Parameters:
atoms (str, ase.Atoms, or list[ase.Atoms]) – Input structure(s) to run simulation with. ase.Atoms object or str with path to .traj (or similar) file.
graph (str) – Path to deepmd model .pb file
type_map (dict) – Dictionary that maps elemental symbol keys to type index values.
path (str) – Path to directory to write results to if dir other than $PWD desired.
**kwargs – Simulation specific kwargs to pass to setup and get_commands methods.
- pre_opt(nsw, cell=False, ftol=0.01)
Run quick optimization on structure before running full simulation.
- Parameters:
nsw (int) – Max number of optimization steps to run.
cell (bool) – Optimize unit cell if True, else only positions.
ftol (float) – Max force convergence tolerance criterion.
- process(file_out=None)
Simulation specific method to process and write results after calculation.
- run(process=True, commands=None, file_out=None)
Runs simulation after setting everything up.
- Parameters:
process (bool) – If True calls self.process() method after running.
commands (list[str], optional) – List of lammps commands if different from self.commands. Rarely used, should set self.commands in self.setup() generally.
file_out (optional) – Name of output file if different from self.file_out for whatever reason. Also rarely used.
- setup(**kwargs)
Simulation specific method to do any needed setup before running (e.g., cell deformations). Must call self.get_commands() method.
- write_array(data)
- class dptools.simulate.simulations.Vib(atoms, graph, type_map, file_out='atoms.traj', path='./', **kwargs)
Bases:
Simulation- calc_type = 'vib'
- get_commands(delta=0.015, **kwargs)
- process()
Simulation specific method to process and write results after calculation.
- run()
Runs simulation after setting everything up.
- Parameters:
process (bool) – If True calls self.process() method after running.
commands (list[str], optional) – List of lammps commands if different from self.commands. Rarely used, should set self.commands in self.setup() generally.
file_out (optional) – Name of output file if different from self.file_out for whatever reason. Also rarely used.
- set_displacements(nfree, delta)
- setup(pre_opt=True, **kwargs)
Simulation specific method to do any needed setup before running (e.g., cell deformations). Must call self.get_commands() method.