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
BondedInteraction
objects- 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
MDEngine
require 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
Universe
on which the simulation is performed.traj_step (int) – How many steps the simulation should take between dumping each
CompactTrajectory
frame. Along withtime_step
determines the time separation of calculated variables such as energy.time_step (float, optional) – Simulation timestep in
fs
. Default is 1.engine (str, optional) – The
MDEngine
used 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 theuniverse
have 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:value
pairs for Lennard-Jones interactions.es_options
(dict)option:value
pairs 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
CompactTrajectory
frame. Along withtime_step
determines the time separation of calculated variables such as energy.- Type:
- engine
A subclass of
MDEngine
which 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
equilibration
is 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) –
Structure
objects 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_solver
ordispersive_solver
may 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
Universe
in 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, whereatoms
is 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 nointeractions
are passed, the force field is applied to all interactions in theUniverse
.- Parameters:
force_field (str) – The
ForceField
to parameterizeinteractions
(if provided), or all theinteractions
in theUniverse
. The availableForceField
are: SPC, TIP3P, OPLSAA, TIP3PFB, SPCE*interactions –
Interaction
objects to parameterize with theForceField
**settings –
add_dispersions
(bool or list ofAtoms
)If True, a
Dispersion
interaction will be added to all atoms in theUniverse
. If a list ofAtom
objects is provided, theDispersion
will be added to these instead. Any addedDispersion
interactions (and any previously defined) will then be parametrized by theForceField
. TheDispersion
interactions added will only be like-like. By default, noDispersion
interactions 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
Structure
to theUniverse
, with optionalForceField
applying only to thatStructure
- Parameters:
structure (Structure or int) – The
Structure
(or itsID
as an int) to be added to theUniverse
force_field (str, optional) – The force field to be applied to the structure. The available
ForceField
are: 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:interactions
pairs whereatom_type
is a int specifying the atom type andinteractions
is a list ofInteraction
objects 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
, whereatoms
is a tuple of allAtom
objects 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
Universe
and exampleAtom
objects for each elementThis is required for MD engines which assign the same potential parameters for all identical element types.
- Returns:
element:atom pairs
, whereatom
is a singleAtom
of 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
Universe
This is required for MD engines which assign the same potential parameters for all identical element names.
- Returns:
element:atom pairs
, whereatom
is a singleAtom
of the specifiedelement
.- Return type:
- property equivalent_top_level_structures_dict: dict[Structure, int]
Get a dict of equivalent top level
Structure
objects that exist in theUniverse
as keys, and the number ofStructure
that are equivalent to the key as a value. This does not include anyStructure
that are a subunit of another structure belonging to theUniverse
.- Returns:
The top level
Structure
objects in theUniverse
as 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
Universe
independent of existing atomsAdds copies of
structures
to existing configuration untilUniverse
is 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
Structure
with which to fill theUniverse
force_field (str) – Applies a
ForceField
to theUniverse
. The availableForceField
are: SPC, TIP3P, OPLSAA, TIP3PFB, SPCEnum_density (float) – Non-negative float specifying the number density of the
Structure
, in units ofStructure / Ang ^ -3
num_struc_units (int) – Non-negative int specifying the number of passed
Structure
objects that the universe should be filled with, regardless ofUniverse.dimensions
.
- Raises:
ValueError – If both
num_density
andnum_struc_units
are passedValueError – If neither
num_density
ornum_struc_units
are passed
- property force_fields: None
Get the
ForceField
acting on theUniverse
The available force fields are: SPC, TIP3P, OPLSAA, TIP3PFB, SPCE
- Returns:
ForceField
that 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
Molecule
objects in theUniverse
- Returns:
The
Molecule
objects 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_type
pairs in theUniverse
.- Returns:
- A dict of
{pair: interactions}
pairs, where: pair
is a tuple for a pair ofatom_types
in theUniverse
interactions
is a list of nonbonded interactions that exist for thispair
ofatom_types
Any
Dispersions
ininteractions
are ones that exist explicity for thispair
, whereas anyCoulombics
ininteractions
are ones that exist for either of theatom_types
inpair
.- 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
Parameters
objects defined withinUniverse
- Return type:
- solvate(density: float, tolerance: float = 1.0, solvent: str = 'SPCE', max_iterations: int = 100, **settings: dict) None [source]
Fills the
Universe
with solvent molecules according to pre-defined coordinates.- Parameters:
density (float) – The desired density of the
Solvent
that solvates theUniverse
, in units ofamu Ang ^ -3
tolerance (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
Solvent
from 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
ConstraintAlgorithm
which is applied to theUniverse
. If an inbuiltSolvent
is selected (e.g. ‘SPCE’) andconstraint_algorithm
is not passed, theConstraintAlgorithm
will default toShake(1e-4, 100)
.
- Raises:
ValueError – If the
Universe
has already been solvated with a different density.
- property structure_list: None
Get a list of all
Structure
objects that exist in theUniverse
. This includes allStructure
that are a subunit of another structure belonging to theUniverse
.- Returns:
The
Structure
objects in theUniverse
- Return type: