simulation
Module for setting up and running the simulation
Classes for the simulation box, minimizer and integrator.
- class MDMC.MD.simulation.ConstraintAlgorithm(accuracy: float, max_iterations: int)[source]
Class describing the algorithm and parameters which are applied to constrain
BondedInteractionobjects- Parameters:
- class MDMC.MD.simulation.Ewald(**settings: dict)[source]
Holds the parameters that are required for the Ewald solver to be applied to both/either the electrostatic and/or dispersion interactions
- Parameters:
**settings –
accuracy(float)The relative RMS error in per-atom forces
- class MDMC.MD.simulation.KSpaceSolver(**settings: dict)[source]
Class describing the k-space solver that is applied to electrostatic and/or dispersion interactions
Different
MDEnginerequire different parameters to be specified for a k-space solver to be used. These parameters are specified in settings.- Parameters:
**settings –
accuracy(float)The relative RMS error in per-atom forces
- class MDMC.MD.simulation.PPPM(**settings: dict)[source]
Holds the parameters that are required for the PPPM solver to be applied to both/either the electrostatic and/or dispersion interactions
- Parameters:
**settings –
accuracy(float)The relative RMS error in per-atom forces
- class MDMC.MD.simulation.Rattle(accuracy: float, max_iterations: int)[source]
Holds the parameters which are required for the RATTLE algorithm to be applied to the constrained interactions
- class MDMC.MD.simulation.Shake(accuracy: float, max_iterations: int)[source]
Holds the parameters which are required for the SHAKE algorithm to be applied to the constrained interactions
- class MDMC.MD.simulation.Simulation(universe: Universe, traj_step: int, time_step: float = 1.0, engine: str = 'lammps', **settings)[source]
Sets up the molecular dynamics engine and parameters for how it should run
An ensemble is defined by whether a thermostat or barostat are present
- Parameters:
universe (Universe) – The
Universeon which the simulation is performed.traj_step (int) – How many steps the simulation should take between dumping each
CompactTrajectoryframe. Along withtime_stepdetermines the time separation of calculated variables such as energy.time_step (float, optional) – Simulation timestep in
fs. Default is 1.engine (str, optional) – The
MDEngineused for the simulation. Default is'lammps'.**settings –
temperature(float)Simulation temperature in
K. Note that velocities of atoms in the MD engine are set based on thetemperature. If all atoms in theuniversehave 0 velocity, then velocities for the MD engine will be randomly chosen from a uniform distribution and then scaled to give the correct temperature. If one or more velocities are set, then these will be scaled to give the correct temperature. In either case, only the velocities on theengine, not theuniverse, are affected.integrator(str)Simulation time integrator.
lj_options(dict)option:valuepairs for Lennard-Jones interactions.es_options(dict)option:valuepairs for electrostatic interactions.thermostat(str)The name of the thermostat e.g. Nose-Hoover.
barostat(str)The name of the barostat e.g. Nose-Hoover.
pressure(float)Simulation pressure in
Pa. This is required if a barostat is passed.verbose(str)If the output of the class instantiation should be reported, default to True.
- traj_step
How many steps the simulation should take between dumping each
CompactTrajectoryframe. Along withtime_stepdetermines the time separation of calculated variables such as energy.- Type:
- engine
A subclass of
MDEnginewhich provides the interface to the MD library. Default is'lammps'.- Type:
MDEngine, optional
- time_step
- trajectory
- auto_equilibrate(variables: list[str] = ['temp', 'pe'], eq_step: int = 10, window_size: int = 100, tolerance: float = 0.01) Tuple[int, dict][source]
Equilibrate until the specified list of variables have stabilised. Uses the KPSS stationarity test to determine whether the variables are stationary in a given window.
- Parameters:
variables (list[str], default ['temp', 'pe']) – The MD engine variables we use to monitor stability.
eq_step (int, default 10) – The number of equilibration steps between each stability check.
window_size (int, default 100) – The size of the rolling window of stability checks. The simulation is considered stable if it has been stationary for eq_step*window_size equilibration steps.
tolerance (float, 0.01) – The p-value used for the KPSS test.
- Returns:
int – The number of equilibration steps performed.
vals_dict – The value of each variable per step, for graphing if desired.
- minimize(n_steps: int, minimize_every: int = 10, verbose: bool = False, output_log: str = None, work_dir: str = None, **settings: dict) None[source]
Performs an MD run intertwined with periodic structure relaxation. This way after a local minimum is found, the system is taken out of the minimum to explore a larger volume of the parameter space.
- Parameters:
n_steps (int) – Total number of the MD run steps
minimize_every (int, optional) – Number of MD steps between two consecutive minimizations
verbose (bool, optional) – Whether to print statements when the minimization has been started and completed (including the number of minimization steps and time taken). Default is False.
output_log (str, optional) – Log file for the MD engine to write to. Default is None.
work_dir (str, optional) – Working directory for the MD engine to write to. Default is None.
**settings –
etol(float)If the energy change between iterations is less than
etol, minimization is stopped. Default depends on engine used.ftol(float)If the magnitude of the global force is less than
ftol, minimization is stopped. Default depends on engine used.maxiter(int)Maximum number of iterations of a single structure relaxation procedure. Default depends on engine used.
maxeval(int)Maximum number of force evaluations to perform. Default depends on engine used.
- run(n_steps: int, equilibration: bool = False, verbose: bool = False, output_log: str = None, work_dir: str = None, **settings: dict) None[source]
Runs the MD simulation for the specified number of steps. Trajectories for the simulation are only saved when
equilibrationis False. Additionally running equilibration for an NVE system (neither barostat nor thermostat set) will temporarily apply a Berendsen thermostat (it is removed from the simulation after the run is completed).- Parameters:
n_steps (int) – Number of simulation steps to run
equilibration (bool, optional) – If the run is for equilibration (True) or production (False). Default is False.
verbose (bool, optional) – Whether to print statements upon starting and completing the run. Default is False.
output_log (str, optional) – Log file for the MD engine to write to. Default is None.
work_dir (str, optional) – Working directory for the MD engine to write to. Default is None.
- property time_step: float
Get or set the simulation time step in
fs- Returns:
Simulation time step in
fs- Return type:
float
- class MDMC.MD.simulation.Universe(dimensions, force_field=None, structures=None, **settings)[source]
Class where the configuration and topology are defined
- Parameters:
dimensions (numpy.ndarray, list, float) – Dimensions of the
Universe, in units ofAng. A float can be used for a cubic universe.force_fields (ForceField, optional) – A force field to apply to the Universe. The force fields available are: SPC, TIP3P, OPLSAA, TIP3PFB, SPCE. Default is None.
structures (list, optional) –
Structureobjects contained in theUniverse. Default is None.**settings –
kspace_solver(KSpaceSolver)The k-space solver to be used for both electrostatic and dispersive interactions. If this is passed then no
electrostatic_solverordispersive_solvermay be passed.electrostatic_solver(KSpaceSolver)The k-space solver to be used for electrostatic interactions.
dispersive_solver(KSpaceSolver)The k-space solver to be used for dispersive interactions.
constraint_algorithm(ConstraintAlgorithm)The constraint algorithm which will be applied to constrained
BondedInteractions.verbose(str)If the output of the class instantiation should be reported, default to True.
- dimensions
Dimensions of the
Universein units ofAng.- Type:
- configuration
Stores the content, i.e. configuration of atoms etc within the universe
- Type:
- force_fields
Force field applied to apply to the Universe
- Type:
ForceField or None
- kspace_solver
The k-space solver to be used for both electrostatic and dispersive interactions.
- Type:
- electrostatic_solver
The k-space solver to be used for electrostatic interactions.
- Type:
- dispersive_solver
The k-space solver to be used for dispersive interactions.
- Type:
- constraint_algorithm
The constraint algorithm which will be applied to constrained
BondedInteractions.- Type:
- interactions
- bonded_interactions
- nonbonded_interactions
- bonded_interaction_pairs
- n_bonded
- n_nonbonded
- n_interactions
- parameters
- volume
- element_list
- element_dict
- element_lookup
- atoms
- n_atoms
- molecule_list
- n_molecules
- structure_list
- top_level_structure_list
- equivalent_top_level_structures_dict
- force_fields
- atom_types
- atom_type_interactions
- density
- solvent_density
- nbis_by_atom_type_pairs
- add_bonded_interaction_pairs(*bonded_interaction_pairs: tuple[Interaction, Atom]) None[source]
Adds one or more interaction pairs to the
Universe- Parameters:
*bonded_interaction_pairs – one or more (
interaction,atoms) pairs, whereatomsis a tuple of all atoms for that specific bondedinteraction
- add_force_field(force_field: str, *interactions: Interaction, **settings: dict) None[source]
Adds a force field to the specified
interactions. If nointeractionsare passed, the force field is applied to all interactions in theUniverse.- Parameters:
force_field (str) – The
ForceFieldto parameterizeinteractions(if provided), or all theinteractionsin theUniverse. The availableForceFieldare: SPC, TIP3P, OPLSAA, TIP3PFB, SPCE*interactions –
Interactionobjects to parameterize with theForceField**settings –
add_dispersions(bool or list ofAtoms)If True, a
Dispersioninteraction will be added to all atoms in theUniverse. If a list ofAtomobjects is provided, theDispersionwill be added to these instead. Any addedDispersioninteractions (and any previously defined) will then be parametrized by theForceField. TheDispersioninteractions added will only be like-like. By default, noDispersioninteractions are added.
- add_nonbonded_interaction(*nonbonded_interactions: tuple[Interaction, Atom]) None[source]
Adds one or more nonbonded interactions to the
Universe- Parameters:
*nonbonded_interactions –
Nonbonded interactions to be added to the
Universe. Can take any number of non-bonded interactions:Dispersion():either Lennard-Jones or Buckingham dispersion
Coulombic():normal or modified Coulomb interaction
with appropriate parameters for the interaction. See http://mdmcproject.org/tutorials/building-a-universe.html?highlight=interaction#Create-non-bonded-interactions for more details on non-bonded interactions.
- add_structure(structure: Structure | int, force_field: str = None, center: bool = False) None[source]
Adds a single
Structureto theUniverse, with optionalForceFieldapplying only to thatStructure- Parameters:
structure (Structure or int) – The
Structure(or itsIDas an int) to be added to theUniverseforce_field (str, optional) – The force field to be applied to the structure. The available
ForceFieldare: SPC, TIP3P, OPLSAA, TIP3PFB, SPCEcenter (bool, optional) – Whether to center structure within the Universe as it is added
- property atom_type_interactions: dict[int, list[Interaction]]
Get the atom types and the interactions for each atom type
- Returns:
atom_type:interactionspairs whereatom_typeis a int specifying the atom type andinteractionsis a list ofInteractionobjects acting on thatatom_type- Return type:
- property atom_types: list[Atom]
Get the atom types of atoms in the
Universe- Returns:
The atom types in the
Universe- Return type:
- property atoms: list[Atom]
Get a list of the atoms in the
Universe- Returns:
The atoms in the
Universe- Return type:
- property bonded_interaction_pairs: list
Get the bonded interactions and the atoms they apply to
- Returns:
The (
interaction,atoms) pairs in theUniverse, whereatomsis a tuple of allAtomobjects for that specificinteraction- Return type:
Example
For an O Atom with two bonds, one to H1 and one to H2:
>>> print(O.bonded_interaction_pairs) [(Bond, (H1, O)), (Bond, (H2, O))]
- property bonded_interactions: list
Get the bonded interactions in the
Universe- Returns:
The bonded interactions in the
Universe- Return type:
- property element_dict: dict[str, Atom]
Get the elements in the
Universeand exampleAtomobjects for each elementThis is required for MD engines which assign the same potential parameters for all identical element types.
- Returns:
element:atom pairs, whereatomis a singleAtomof the specifiedelement.- Return type:
- property element_list: list[str]
The elements of the atoms in the
Universe- Returns:
The elements in the
Universe- Return type:
- property element_lookup: dict[str, Atom]
Get the elements by ID in the
UniverseThis is required for MD engines which assign the same potential parameters for all identical element names.
- Returns:
element:atom pairs, whereatomis a singleAtomof the specifiedelement.- Return type:
- property equivalent_top_level_structures_dict: dict[Structure, int]
Get a dict of equivalent top level
Structureobjects that exist in theUniverseas keys, and the number ofStructurethat are equivalent to the key as a value. This does not include anyStructurethat are a subunit of another structure belonging to theUniverse.- Returns:
The top level
Structureobjects in theUniverseas keys, and the number of each as a value- Return type:
- fill(structures: Structure, force_field: str = None, num_density: float = None, num_struc_units: int = None) None[source]
A liquid-like filling of the
Universeindependent of existing atomsAdds copies of
structuresto existing configuration untilUniverseis full. As exclusion region is defined by the size of a bounding sphere, this method is most suitable for atoms or molecules with approximately equal dimensions.Note
CURRENT APPROACH RESULTS IN NUMBER DENSITY DIFFERENT TO WHAT IS SPECIFIED DEPENDING ON HOW CLOSE CUBE ROOT OF N_MOLECULES IS TO AN int.
Note
CURRENT IMPLEMENTATION SHOULD NOT BE USED WITH NON-CUBIC UNIVERSES AS THE DENSITY MAY OR MAY NOT BE ISOTROPIC DEPENDING ON THE DIMENSIONS AND NUMBER OF UNITS.
- Parameters:
structures (Structure or int) – The
Structurewith which to fill theUniverseforce_field (str) – Applies a
ForceFieldto theUniverse. The availableForceFieldare: SPC, TIP3P, OPLSAA, TIP3PFB, SPCEnum_density (float) – Non-negative float specifying the number density of the
Structure, in units ofStructure / Ang ^ -3num_struc_units (int) – Non-negative int specifying the number of passed
Structureobjects that the universe should be filled with, regardless ofUniverse.dimensions.
- Raises:
ValueError – If both
num_densityandnum_struc_unitsare passedValueError – If neither
num_densityornum_struc_unitsare passed
- property force_fields: None
Get the
ForceFieldacting on theUniverseThe available force fields are: SPC, TIP3P, OPLSAA, TIP3PFB, SPCE
- Returns:
ForceFieldthat applies to theUniverse- Return type:
- property interactions: list
Get the interactions in the
Universe- Returns:
The interactions in the
Universe- Return type:
- property molecule_list: list[Molecule]
Get a list of the
Moleculeobjects in theUniverse- Returns:
The
Moleculeobjects in theUniverse- Return type:
- property n_atoms: int
Get the number of atoms in the
Universe- Returns:
The number of atoms in the
Universe- Return type:
- property n_bonded: int
Get the number of bonded interactions in the
Universe- Returns:
The number of bonded interactions in the
Universe- Return type:
- property n_interactions: int
Get the number of interactions in the
Universe- Returns:
The number of interactions in the
Universe- Return type:
- property n_molecules: int
Get the number of molecules in the
Universe- Returns:
The number of molecules in the
Universe- Return type:
- property n_nonbonded: int
Get the number of nonbonded interactions in the
Universe- Returns:
The number of nonbonded interactions in the
Universe- Return type:
- property nbis_by_atom_type_pairs: dict[tuple[int], list[Interaction]]
Generates a dict of all nonbonded interactions possessed by all combinations of
atom_typepairs in theUniverse.- Returns:
- A dict of
{pair: interactions}pairs, where: pairis a tuple for a pair ofatom_typesin theUniverseinteractionsis a list of nonbonded interactions that exist for thispairofatom_types
Any
Dispersionsininteractionsare ones that exist explicity for thispair, whereas anyCoulombicsininteractionsare ones that exist for either of theatom_typesinpair.- A dict of
- Return type:
- property nonbonded_interactions: list
Get the nonbonded interactions in the
Universe- Returns:
The nonbonded interactions in the
Universe- Return type:
- property parameters: Parameters
Get the parameters of the interactions that exist within the
Universe- Returns:
The
Parametersobjects defined withinUniverse- Return type:
- solvate(density: float, tolerance: float = 1.0, solvent: str = 'SPCE', max_iterations: int = 100, **settings: dict) None[source]
Fills the
Universewith solvent molecules according to pre-defined coordinates.- Parameters:
density (float) – The desired density of the
Solventthat solvates theUniverse, in units ofamu Ang ^ -3tolerance (float, optional) – The +/- percentage tolerance of the density to be achieved. The default is 1 %. Tolerances of less than 1 % are at risk of not converging.
solvent (str, optional) – A str specifying an inbuilt
Solventfrom the following: SPC, TIP3P, TIP3PFB, SPCE. The default is ‘SPCE’.max_iterations (int, optional) – The maximum number of times to try to solvate the universe to within the required density before stopping. Defaults to 100.
**settings –
constraint_algorithm(ConstraintAlgorithm)A
ConstraintAlgorithmwhich is applied to theUniverse. If an inbuiltSolventis selected (e.g. ‘SPCE’) andconstraint_algorithmis not passed, theConstraintAlgorithmwill default toShake(1e-4, 100).
- Raises:
ValueError – If the
Universehas already been solvated with a different density.
- property structure_list: None
Get a list of all
Structureobjects that exist in theUniverse. This includes allStructurethat are a subunit of another structure belonging to theUniverse.- Returns:
The
Structureobjects in theUniverse- Return type: