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
array
with the position in units ofAng
. The default is(0., 0., 0.)
.velocity (list, tuple, numpy.ndarray, optional) – A 3 element list, tuple or
array
with 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
Atom
in units of elementary charge (e)
. The default is None, meaning that aCoulomb
interaction 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 anInteraction
class is passed then it must be aNonBondedInteraction
i.e. only takes a singleAtom
as an argument. If anInteraction
object is passed then thisAtom
must 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_type
cannot 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
Atom
and the other atoms to which theAtom
is bonded- Returns
(
interaction
,atoms
) pairs acting on theAtom
, whereatoms
is a tuple of all Atom objects for that specific bondedinteraction
.- 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 charge
Get or set the charge in
e
if one has been applied to theAtom
If the
Atom
does not have aCoulombic
interaction, setting a value of thecharge
will create one, and a defaultcutoff
of10. Ang
will be applied- Returns
The charge in units of
e
, or None if no charge has been set- Return type
- Raises
ValueError – When the
Atom
has more than oneCoulombic
interactionValueError – When the
Atom
has more than one parameter; i.e. should only have charge as a parameterValueError – When setting charge to None when a
Coulombic
interaction already exists.
- copy(position)[source]
Copies the
Atom
and all attributes, exceptID
which is generatedCopying an
Atom
creates an exact duplicate at the specifiedposition
. The copiedAtom
will have identical bonded and nonbonded interactions as the original. ForBondedInteractions
this means that the copied atom will be bonded to all atoms to which the original atom is bonded. TheID
of 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
array
with theposition
of the newAtom
- Returns
A copy of the
Atom
with the specifiedposition
- Return type
Examples
If the following
Atom
is 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 aCoulombic
interaction, with acharge
of0.4238 e
If
H1
andH2
are 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 aCoulombic
interaction (also with acharge
of0.4238 e
), and it will also have aBond
interaction withH2
(asH1
had aBond
interaction withH2
).
- copy_interactions(atom, memo=None)[source]
This replicates the interactions from
self
forAtom
, but withself
substituted byatom
in theInteraction.atoms
. These interactions are added to any that already exist for theAtom
.Passing the
memo
dict 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
NonBondedInteractions
acting 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) –
Atom
objects 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
StructuralUnit
and the other atoms to which the atom is bonded- Returns
(
interaction
,atoms
) pairs acting on theStructuralUnit
, whereatoms
is a tuple of allAtom
objects for that specific bondedinteraction
. At least one of theseAtom
objects belongs to theStructuralUnit
- 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))]
- copy(position, rotation=None)[source]
Copies the
CompositeStructuralUnit
and all attributes, exceptID
which is generatedCopying a
CompositeStructuralUnit
(e.g. aMolecule
) will copy all of theAtom
objects within it. All of these atoms will have identical bonded and nonbonded interactions to theCompositeStructuralUnit
from which they were copied i.e. theCompositeStructuralUnit
will be exacltly duplicated. The only attributes of theCompositeStructuralUnit
which will differ are theposition
(which is passed as a Parameter tocopy
), and theID
, which is generated automatically.This will not currently work if the
CompositeStructuralUnit
has any bonded interactions with atoms external to it (e.g. it may cause issues for copying molecules with groups)Interactions for
Atom
objects may be reordered with respect to initial atoms- Parameters
position (list, tuple, numpy.ndarray) – 3 element list, tuple or
array
of float specifying theposition
of the newStructuralUnit
rotation (list, tuple, numpy.ndarray, optional) – 3 element list, tuple or
array
of 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 defaultrotation
is None, which applies no rotation to the copiedCompositeStructuralUnit
.
- Returns
A
CompositeStructuralUnit
of 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
NonBondedInteractions
acting on theStructuralUnit
- Return type
- rotate(x=0.0, y=0.0, z=0.0)[source]
Rotates the
CompositeStructuralUnit
around 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
StructuralUnit
objects that are subunits of thisCompositeStructuralUnit
- Returns
list of
StructuralUnit
that 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
Atom
objects.- Parameters
position (list, tuple, numpy.ndarray, optional) – A 3 element list, tuple or
array
with the position in units ofAng
. The default is None, which sets the position of theMolecule
to be equal to the center of mass of the atoms in theMolecule
.velocity (list, tuple, numpy.ndarray, optional) – A 3 element list, tuple or
array
with 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
Atom
which will be included in theMolecule
interactions
(list)A list of
Interaction
acting on atoms within theMolecule
. Theinteractions
provides a convenience for declaring interactions on atoms when aMolecule
is 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
, whereatoms
is a tuple of all atoms for that specific bondedinteraction
. At least one of theseatoms
belongs to theMolecule
- Return type
Example
For an
O
Atom
with two bonds, one toH1
and 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
NonBondedInteraction
objects acting on theMolecule
- Return type
- property position
Get or set the position of the center of mass of the
Molecule
inAng
Also 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
array
with the position in units ofAng
.velocity (list, tuple, numpy.ndarray) – A 3 element list, tuple or
array
with 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
Universe
to which theStructuralUnit
belongs.name – The name of the structure.
parent (StructuralUnit) –
StructuralUnit
to which this unit belongs, orself
- property atoms
Get a list of all of the Atom objects in the structure by recursively calling
atoms
for all substructures- Returns
All atoms in the structure
- Return type
- abstract property bonded_interaction_pairs
Get bonded interactions acting on the
StructuralUnit
and the other atoms to which the atom is bonded- Returns
(
interaction
,atoms
) pairs acting on theStructuralUnit
, whereatoms
is a tuple of allAtom
objects for that specific bondedinteraction
. At least one of theseAtom
objects belongs to theStructuralUnit
- 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
Get a list of the bonded interactions acting on the
StructuralUnit
- Returns
BondedInteractions
acting 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
array
of float specifying theposition
of the newStructuralUnit
- Returns
A
StructuralUnit
of 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
NonBondedInteractions
acting on theStructuralUnit
- Return type
- property position
Get or set the position of the center of mass of the
StructuralUnit
inAng
- 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.
StructuralUnit
which has noparent
) of theStructuralUnit
- Returns
Highest level
StructuralUnit
of 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
array
of float
- abstract property universe
Get the
Universe
to which theStructuralUnit
belongs- Returns
The
Universe
to which theStructuralUnit
belongs or None- Return type
- valid_position(position=None)[source]
Checks if the specified
position
is within the bounds of theStructuralUnit.universe
, if it has one- Parameters
position (list, tuple, numpy.ndarray) – 3 element list, tuple or
array
with units ofAng
or None. If None then theposition
of theStructuralUnit
is used.- Returns
True if
position
is withinUniverse
or there is no associatedUniverse
. False ifStructuralUnit
has an associatedUniverse
but theposition
is not within its bounds.- Return type
- Raises
ValueError – If
position
if undefined
- property velocity
Get or set the velocity of the
StructuralUnit
inAng/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'