structural_units
Module in which all structural units are defined.
Atom is the fundamental structural unit in terms of which all others must be
defined. All shared behaviour is included within the StructuralUnit base
class.
- class MDMC.MD.structural_units.Atom(element, position=(0.0, 0.0, 0.0), velocity=(0.0, 0.0, 0.0), charge=None, **settings)[source]
A single atom
- Parameters
element (str) – The atomic element label.
position (list, tuple, numpy.ndarray, optional) – A 3 element list, tuple or
arraywith the position in units ofAng. The default is(0., 0., 0.).velocity (list, tuple, numpy.ndarray, optional) – A 3 element list, tuple or
arraywith the velocity in units ofAng / fs. Note that if set, the velocity of atoms in the MD engine will be scaled when creating a Simulation in order to ensure the temperature is accurate. Otherwise, if the velocities of all Atom objects in a Simulation are 0, then the velocities of the atoms in the MD engine will be randomly chosen in order to provide an accurate temperature. The default is(0., 0., 0.).charge (float) – The charge of the
Atomin units of elementary charge (e). The default is None, meaning that aCoulombinteraction is not applied to theAtom.**settings –
mass(float)The atomic mass in
amu. If not provided a lookup table will be used.atom_type(int)All atoms with the same atom_type will have the same non-bonded interactions applied to them. If not provided, MDMC will automatically infer/assign atom types. All atoms with the same element and interactions will have the same atom type.
name(str)A name to uniquely identify the atom. Used by ForceFields (e.g. OPLSAA). Atoms should only have the same names if they are equivalent. Defaults to the element of the atom.
- add_interaction(interaction, from_interaction=False)[source]
Adds an interaction to the
Atom- Parameters
interaction (MDMC.MD.interactions.Interaction) – Any class dervied from
Interaction, or any object with base classInteraction. If anInteractionclass is passed then it must be aNonBondedInteractioni.e. only takes a singleAtomas an argument. If anInteractionobject is passed then thisAtommust be in theinteraction.atoms.from_interaction (bool, optional) – Specifies if this method has been called from an
Interaction. Default is False.
- property atom_type
Get or set the atom type of the
Atom- Returns
The atom type
- Return type
- Raises
AttributeError – The
atom_typecannot be changed once it has been set
- property atoms
Get a list of the atoms, just consisting of the
Atom- Returns
A list with a single item, the
Atom- Return type
- property bonded_interaction_pairs
Get bonded interactions acting on the
Atomand the other atoms to which theAtomis bonded- Returns
(
interaction,atoms) pairs acting on theAtom, whereatomsis a tuple of all Atom objects for that specific bondedinteraction.- Return type
Example
For an O
Atomwith two bonds, one to H1 and one to H2:>>> print(O.bonded_interaction_pairs) [(Bond, (H1, O)), (Bond, (H2, O))]
- property charge
Get or set the charge in
eif one has been applied to theAtomIf the
Atomdoes not have aCoulombicinteraction, setting a value of thechargewill create one, and a defaultcutoffof10. Angwill be applied- Returns
The charge in units of
e, or None if no charge has been set- Return type
- Raises
ValueError – When the
Atomhas more than oneCoulombicinteractionValueError – When the
Atomhas more than one parameter; i.e. should only have charge as a parameterValueError – When setting charge to None when a
Coulombicinteraction already exists.
- copy(position)[source]
Copies the
Atomand all attributes, exceptIDwhich is generatedCopying an
Atomcreates an exact duplicate at the specifiedposition. The copiedAtomwill have identical bonded and nonbonded interactions as the original. ForBondedInteractionsthis means that the copied atom will be bonded to all atoms to which the original atom is bonded. TheIDof the copied atom will differ from the original, as they are sequentially generated.- Parameters
position (list, tuple, numpy.ndarray) – A 3 element list, tuple or
arraywith thepositionof the newAtom- Returns
A copy of the
Atomwith the specifiedposition- Return type
Examples
If the following
Atomis copied:H1 = Atom('H', position=(0., 0., 0.), charge=0.4238) H2 = H1.copy(position=(1., 1., 1.))
then the new
Atom(H2) will have noBondedInteractions, but will have aCoulombicinteraction, with achargeof0.4238 eIf
H1andH2are then bonded together and a copy is made:HHbond = Bond((H1, H2)) H3 = H1.copy(position=(2., 2., 2.))
then the newest
Atom(H3) will have aCoulombicinteraction (also with achargeof0.4238 e), and it will also have aBondinteraction withH2(asH1had aBondinteraction withH2).
- copy_interactions(atom, memo=None)[source]
This replicates the interactions from
selfforAtom, but withselfsubstituted byatomin theInteraction.atoms. These interactions are added to any that already exist for theAtom.Passing the
memodict enables specific interactions to be excluded from being copied, duplicating the behaviour of__deepcopy__
- property nonbonded_interactions
Get a list of the nonbonded interactions acting on the
Atom- Returns
NonBondedInteractionsacting on theAtom- Return type
- class MDMC.MD.structural_units.BoundingBox(atoms: List)[source]
A box with the minimum and maximum extents of the positions of a collection of atoms
- Parameters
atoms (list) –
Atomobjects for which the minimum and maximum extents are determined
- property max
Get or set the maximum extent of the positions of a collection of atoms
- Returns
The maximum extent in
Ang- Return type
- property min
Get or set the minimum extent of the positions of a collection of atoms
- Returns
The minimum extent in
Ang- Return type
- class MDMC.MD.structural_units.CompositeStructuralUnit(position, velocity, name)[source]
Base class for structural units comprised of more than one
Atom- abstract property bonded_interaction_pairs
Get bonded interactions acting on the
StructuralUnitand the other atoms to which the atom is bonded- Returns
(
interaction,atoms) pairs acting on theStructuralUnit, whereatomsis a tuple of allAtomobjects for that specific bondedinteraction. At least one of theseAtomobjects belongs to theStructuralUnit- Return type
Example
For an O
Atomwith two bonds, one to H1 and one to H2:>>> print(O.bonded_interaction_pairs) [(Bond, (H1, O)), (Bond, (H2, O))]
- copy(position, rotation=None)[source]
Copies the
CompositeStructuralUnitand all attributes, exceptIDwhich is generatedCopying a
CompositeStructuralUnit(e.g. aMolecule) will copy all of theAtomobjects within it. All of these atoms will have identical bonded and nonbonded interactions to theCompositeStructuralUnitfrom which they were copied i.e. theCompositeStructuralUnitwill be exacltly duplicated. The only attributes of theCompositeStructuralUnitwhich will differ are theposition(which is passed as a Parameter tocopy), and theID, which is generated automatically.This will not currently work if the
CompositeStructuralUnithas any bonded interactions with atoms external to it (e.g. it may cause issues for copying molecules with groups)Interactions for
Atomobjects may be reordered with respect to initial atoms- Parameters
position (list, tuple, numpy.ndarray) – 3 element list, tuple or
arrayof float specifying thepositionof the newStructuralUnitrotation (list, tuple, numpy.ndarray, optional) – 3 element list, tuple or
arrayof floats specifying the degrees of anticlockwise rotation around the x, y, and z axes respectively. The rotation is centered on the center of mass of theCompositeStructuralUnit. The defaultrotationis None, which applies no rotation to the copiedCompositeStructuralUnit.
- Returns
A
CompositeStructuralUnitof the same type with all non-unique attributes copied and a newposition- Return type
- property formula
Get the chemical formula of the
CompositeStructuralUnit- Returns
The chemical formula using the Hill system
- Return type
- abstract property nonbonded_interactions
Get a list of the nonbonded interactions acting on the
StructuralUnit- Returns
NonBondedInteractionsacting on theStructuralUnit- Return type
- rotate(x=0.0, y=0.0, z=0.0)[source]
Rotates the
CompositeStructuralUnitaround its center of massIn all cases (e.g. x, y and z) the rotation is anticlockwise about the specific axis
- property structure_list
Get or set the
StructuralUnitobjects that are subunits of thisCompositeStructuralUnit- Returns
list of
StructuralUnitthat are subunits of thisCompositeStructuralUnit- Return type
- class MDMC.MD.structural_units.Molecule(position=None, velocity=(0, 0, 0), name=None, **settings)[source]
Two or more bonded atoms
Must be declared with at least 2
Atomobjects.- Parameters
position (list, tuple, numpy.ndarray, optional) – A 3 element list, tuple or
arraywith the position in units ofAng. The default is None, which sets the position of theMoleculeto be equal to the center of mass of the atoms in theMolecule.velocity (list, tuple, numpy.ndarray, optional) – A 3 element list, tuple or
arraywith the velocity in units ofAng / fs. The default is(0., 0., 0.).name (str, optional) – The name of the structure. The default is None.
**settings –
atoms(list)A list of
Atomwhich will be included in theMoleculeinteractions(list)A list of
Interactionacting on atoms within theMolecule. Theinteractionsprovides a convenience for declaring interactions on atoms when aMoleculeis initialized. It is not required and is exactly equivalent to initializing the interactions prior to theMolecule.
- property bonded_interaction_pairs
Get bonded interactions acting on the
Molecule- Returns
(
interaction,atoms) pairs acting on theMolecule, whereatomsis a tuple of all atoms for that specific bondedinteraction. At least one of theseatomsbelongs to theMolecule- Return type
Example
For an
OAtomwith two bonds, one toH1and one toH2:>>> print(O.bonded_interaction_pairs) [(Bond, (H1, O)), (Bond, (H2, O))]
- property nonbonded_interactions
Get a list of the nonbonded interactions acting on the
Molecule- Returns
NonBondedInteractionobjects acting on theMolecule- Return type
- property position
Get or set the position of the center of mass of the
MoleculeinAngAlso sets the positions of all subunits
- Return type
- class MDMC.MD.structural_units.StructuralUnit(position, velocity, name)[source]
Abstract base class for all structural units
- Parameters
position (list, tuple, numpy.ndarray) – A 3 element list, tuple or
arraywith the position in units ofAng.velocity (list, tuple, numpy.ndarray) – A 3 element list, tuple or
arraywith the velocity in units ofAng / fs.name (str) –
The name of the structure.
Attributes
---------- – ID : int A unique identifier for each
StructuralUnit.universe (Universe) – The
Universeto which theStructuralUnitbelongs.name – The name of the structure.
parent (StructuralUnit) –
StructuralUnitto which this unit belongs, orself
- property atoms
Get a list of all of the Atom objects in the structure by recursively calling
atomsfor all substructures- Returns
All atoms in the structure
- Return type
- abstract property bonded_interaction_pairs
Get bonded interactions acting on the
StructuralUnitand the other atoms to which the atom is bonded- Returns
(
interaction,atoms) pairs acting on theStructuralUnit, whereatomsis a tuple of allAtomobjects for that specific bondedinteraction. At least one of theseAtomobjects belongs to theStructuralUnit- Return type
Example
For an O
Atomwith two bonds, one to H1 and one to H2:>>> print(O.bonded_interaction_pairs) [(Bond, (H1, O)), (Bond, (H2, O))]
- property bonded_interactions
Get a list of the bonded interactions acting on the
StructuralUnit- Returns
BondedInteractionsacting on theStructuralUnit- Return type
- property bounding_box
returns: Contains the lower and upper extents of the
Molecule:rtype: BoundingBox
- copy(position)[source]
Copies the structural unit and sets the
position- Parameters
position (list, tuple, numpy.ndarray) – 3 element list, tuple or
arrayof float specifying thepositionof the newStructuralUnit- Returns
A
StructuralUnitof the same type with all non-unique attributes copied and a newposition- Return type
- property interactions
Get a list of the interactions acting on the
StructuralUnit- Returns
Interactions acting on the
StructuralUnit- Return type
- abstract property nonbonded_interactions
Get a list of the nonbonded interactions acting on the
StructuralUnit- Returns
NonBondedInteractionsacting on theStructuralUnit- Return type
- property position
Get or set the position of the center of mass of the
StructuralUnitinAng- Return type
- property structure_type
Get the class of the
StructuralUnit.- Returns
The name of the class
- Return type
- property top_level_structure
Get the top level structure (i.e.
StructuralUnitwhich has noparent) of theStructuralUnit- Returns
Highest level
StructuralUnitof which it is a member- Return type
- translate(displacement)[source]
Translate the structural unit by the specified displacement
- Parameters
Displacement (tuple, numpy.ndarray) – A three element tuple or
arrayof float
- abstract property universe
Get the
Universeto which theStructuralUnitbelongs- Returns
The
Universeto which theStructuralUnitbelongs or None- Return type
- valid_position(position=None)[source]
Checks if the specified
positionis within the bounds of theStructuralUnit.universe, if it has one- Parameters
position (list, tuple, numpy.ndarray) – 3 element list, tuple or
arraywith units ofAngor None. If None then thepositionof theStructuralUnitis used.- Returns
True if
positionis withinUniverseor there is no associatedUniverse. False ifStructuralUnithas an associatedUniversebut thepositionis not within its bounds.- Return type
- Raises
ValueError – If
positionif undefined
- property velocity
Get or set the velocity of the
StructuralUnitinAng/fs- Return type
- MDMC.MD.structural_units.filter_atoms(atoms, predicate)[source]
Filters a list of Atoms with a given predicate
- MDMC.MD.structural_units.filter_atoms_element(atoms, element)[source]
Filters a list of atoms based on the atomic element
- MDMC.MD.structural_units.get_reduced_chemical_formula(symbols, factor=None, system='Hill')[source]
Get the reduced chemical formula
- Parameters
symbols (list of str) – The chemical formula to be reduced. It is expressed as a list of elements, with a single element for each atom. Elements are grouped by type but not ordered e.g. all
'O'values, then all'H'values etc.factor (int, optional) – The factor by which the total number of symbols will be reduced. If None, the greatest common divisor of the different symbols will be used. The default is None.
system (str, optional) – Determines the order of the chemical formula. If
'Hill'the Hill system is used to determine the order. If None, the order is based on the order of`symbols. The default is'Hill'.
- Returns
The chemical formula corresponding to
symbols, except with onlyn_atoms. If system is'Hill', the formula will be ordered as per the Hill system, otherwise the formula will be ordered based on the order ofsymbols.- Return type
Example
Reducing the formula for four water molecules to a single water molecules:
>>> get_reduced_chemical_formula(['H'] * 8 + ['O'] * 4) 'H2O'
Reducing the formula for four water molecules to two water molecules:
>>> get_reduced_chemical_formula(['H'] * 8 + ['O'] * 4, factor=2) 'H4O2'