Molecule Class¶
This module contains the molecule class and all classes and functions related to molecules. This includes Bond, Angle, and Dihedral classes as well as helper functions that take in atom and bond lists and generate molecules.
-
class
molecule_class.
Angle
(angleID, angleType, atom1, atom2, atom3)[source]¶ The Angle object represents the angle between three connected atoms. The format is the same as in the Angles section of a LAMMPS input file.
- Parameters
angleID (int) – The unique integer identifier of the angle, the same as the one defined in the LAMMPS inpit file
angleType (int) – The integer identifier of the angle type which is the same as the angle type number defined in the LAMMPS input file
atom1 (int) – The atom ID of the first atom associated with the angle, same as the one defined in LAMMPS input file.
atom2 (int) – The atom ID of the second atom associated with the angle, same as the one defined in LAMMPS input file.
atom3 (int) – The atom ID of the third atom associated with the angle, same as the one defined in LAMMPS input file.
-
class
molecule_class.
Bond
(bondID, bondType, atom1, atom2)[source]¶ The Bond object represents a bond between two atoms. The format is similar to a LAMMPS bond, therefore a Bond object consists of a Bond ID which uniquely defines the bond, a bond type, and the atom ID’s of the two atoms involved in the bond.
- Parameters
bondID (int) – The unique integer identifying the bonds same as the one defined in the LAMMPS input file
bondType (int) – An integer which represents the type of bond this is, the same as the bond type number defined in LAMMPS input file.
atom1 (int) – The atom ID associated with the first atom in the bond
atom2 (int) – The atom ID associated with the second atom in the bond
-
class
molecule_class.
Dihedral
(dihID, dihType, atom1, atom2, atom3, atom4)[source]¶ The Dihedral object represents the dihedral between four connected atoms.
- Parameters
dihID (int) – The unique integer identifier for the dihedral same as the one in the LAMMPS input file.
dihType (int) – The unique integer identifier for the dihedral type which corresponds to the dihedral type in the LAMMPS input file.
atom1 (int) – The atom ID of the first atom in the dihedral.
atom2 (int) – The atom ID of the second atom in the dihedral.
atom3 (int) – The atom ID of the third atom in the dihedral.
atom4 (int) – The atom ID of the fourth atom in the dihedral.
-
class
molecule_class.
Molecule
(molID, atoms, bonds, angles, dihedrals)[source]¶ This class is used to represent a molecule in a simulation and holds all the objects related to a molecule including the related Atom, Bond, Angle, and Dihedral Objects.
- Parameters
molID (int) – The unique integer identifier of the molecule as set in the LAMMPS input file
atoms (list of type Atom) – The Atom objects associated with this molecule
bonds (list of type Bond) – The Bond objects associated with this molecule
angles (list of type Angle) – The Angle objects associated with this molecule
dihedrals (list of type Dihedral) – The Dihedral objects associated with this molecule
-
atomsAsGraph
()[source]¶ Returns the graph data structure of the atoms in the molecule defined by the connectivity defined by the Bond objects of the molecule. The nodes of the graph are the atom ID’s of the atoms.
- Returns
A Networkx Graph object with the nodes being the atom ID’s of the atoms in the molecule and the connections defined by the Molecule’s Bonds
- Return type
Networkx Graph Object
-
getAtomByID
(atomID)[source]¶ Returns the Atom object associated with the given atom ID as long as the atom is associated with the molecule.
- Parameters
atomID (int) – The unique atom ID identifier of the Atom object which you hope to retrieve
- Returns
The Atom object associated with the atom ID or None if the Atom is not associated with this molecule.
- Return type
-
getAtomByMolIndex
(index)[source]¶ Returns the Atom by it’s index in the molecule where the index is defined as the number of bonds away from the anchor atom (i.e. the atom at index 1 is the atom directly connected to the anchor atom)
- Parameters
index (int) – The molecular index of the Atom object one wishes to retrieve where the index is defined as the number of bonds away from the anchor atom.
- Returns
The Atom Object located at the specified index if the index is greater than the number of atoms in the molecule minus one then the function returns None as this is out of the range of the atom list.
- Return type
Atom Object
-
getDihedralAngle
(dihedral)[source]¶ Calculates the dihedral angle of a given dihedral.
- Parameters
dihedral (Dihedral) – Dihedral Object that one wishes to calculate the dihedral angle of.
- Returns
The current dihedral angle of the Dihedral object
- Return type
float
-
get_com
()[source]¶ Calculates the center of mass of the molecule.
- Returns
com – The center of mass of the molecule.
- Return type
array of floats
-
index2dihedral
(index)[source]¶ Returns the dihedral associated with the given atom index of the molecule.
- Parameters
index (int) – The index of the molecule that one wants the associated dihedral. Here the associated dihedral is the dihedral where the atom is the fourth atom of the dihedral.
- Returns
dihedral – The dihedral associated with the given index.
- Return type
-
rotateDihedral
(index, theta)[source]¶ Rotates the atoms of the molecule from the atom given by ‘index’ all the way to the last atom (here the last atom is the one opposite the defined “anchor atom”) about a dihedral axis. Here the dihedral axis is defined by the two atoms that come before the ‘index’ atom as defined by the graph of the molecule. Due to the way the function is defined the ‘index’ of the atom must be greater than 3, but of course less than the total length of the molecule.
- Parameters
index (int) – The index of the atom which is the starting atom of the rotation and consequently the last atom of the dihedral of whose axis you wish to rotate the molecule about.
theta (float) – The angle in radians which specifies the angle of rotation about the dihedral axis which you want to perform.
-
setAnchorAtom
(atomID)[source]¶ Sets the anchor atom of the molecule this is the atom of the molecule that is anchored to the nanoparticle. Setting this important when using the CBMC regrowth move.
- Parameters
atomID (int) – The unique atom ID identifier of the Atom object that is anchored to the nanoparticle.
-
molecule_class.
constructMolecules
(filename)[source]¶ From a LAMMPS input file construct a list of Molecule objects based on the molecules in the LAMMPS input file.
- Parameters
filename (str) – The name of the LAMMPS input file that contains the molecules
- Returns
molecules – A list of Molecule objects with the data specified by the LAMMPS input file passed in.
- Return type
Molecule List
-
molecule_class.
getAnglesFromAtoms
(atomlist, bondlist, angles)[source]¶ Given a list of Atoms find all the Angles in angles which contains these atoms.
- Parameters
atomlist (Atom List) – A list of Atoms used to search through the Angle List.
bondlist (Bond List) – A List of Bond objects used to get connectivity of atoms. The connectivity is used to find the possible angle combinations of the Atoms in atoms.
angles (Angle List) – A List of Angles which is searched through.
- Returns
anglelist – A list of Angles that are associated with the Atoms in atoms.
- Return type
Angle List
-
molecule_class.
getBondsFromAtoms
(atoms, bonds)[source]¶ Based on a list of atoms find all bonds in Bond list, bonds that contain these atoms.
- Parameters
atoms (Atom List) – A list of Atom objects which are the basis for searching through the bond list.
bonds (Bond List) – A List of Bond objects which the function searches through.
- Returns
A list of all Bond objects that contain any of the given Atom objects atoms.
- Return type
Bond List
-
molecule_class.
getDihedralsFromAtoms
(atomlist, bondlist, dihedrals)[source]¶ Given a list of Atoms find all the Dihedral objects in dihedrals which contains these atoms.
- Parameters
atomlist (Atom List) – A list of Atoms used to search through the Dihedral List.
bondlist (Bond List) – A List of Bond objects used to get connectivity of atoms. The connectivity is used to find the possible dihedral combinations of the Atoms in atoms.
angles (Angle List) – A List of Angles which is searched through.
- Returns
anglelist – A list of Angles that are associated with the Atoms in atoms.
- Return type
Angle List
-
molecule_class.
groupAnglesByMol
(mol_dict, bond_dict, angles)[source]¶ Group angles by their associated molecular ID
- Parameters
mol_dict (Atom List Dictionary) – A dictionary of Atom List with each entry indexed by molecule ID and the entries with that index being an Atom list of Atom objects associated with the molecule ID
bond_dict (Bond List Dictionary) – A dictionary of Bond List items indexed by their associated molecule ID.
angles (Angle List) – A list of Angle objects that you want grouped by molecule ID
- Returns
angle_dict – A dictionary with the molecule ID’s as keys and the list of angles associated with that molecule ID as the entries
- Return type
Angle List Dictionary
-
molecule_class.
groupAtomsByMol
(atoms)[source]¶ Group atoms by their associated molecular ID
- Parameters
atoms (Atom List) – A list of Atom objects that you want grouped by molecule ID
- Returns
mol_dict – A dictionary with the molecule ID’s as keys and the list of atoms associated with that molecule ID as the entries
- Return type
Atom List Dictionary
-
molecule_class.
groupBondsByMol
(mol_dict, bonds)[source]¶ Group bonds by their associated molecular ID
- Parameters
mol_dict (Atom List Dictionary) – A dictionary of Atom List with each entry indexed by molecule ID and the entries with that index being an Atom list of Atom objects associated with the molecule ID
bonds (Bond List) – A list of Bond objects that you want grouped by molecule ID
- Returns
bond_dict – A dictionary with the molecule ID’s as keys and the list of bonds associated with that molecule ID as the entries
- Return type
Bond List Dictionary
-
molecule_class.
groupDihedralsByMol
(mol_dict, bond_dict, dihedrals)[source]¶ Group dihedrals by theri associated molecule ID
- Parameters
mol_dict (Atom List Dictionary) – A dictionary of Atom Lists indexed by their associated molecule ID’s
bond_dict (Bond List Dictionary) – A dictionary of Bond Lists indexed by their associated molecule ID’s
dihedrals (Dihedral List) – A list of dihedrals to by grouped by molecule ID.
- Returns
dihedral_dict – A dictionary of Dihedral Lists indexed by their associated molecule ID.
- Return type
Dihedral List Dictionary
-
molecule_class.
loadAngles
(filename)[source]¶ This function loads the Angless from a LAMMPS input file and turns them into a list of Angle objects.
- Parameters
filename (str) – The filename of the LAMMPS input file which has the Angles you wish to use.
- Returns
A list of Angle objects with the same value as the Angles in the LAMMPS input file passed in.
- Return type
Angle List
-
molecule_class.
loadBonds
(filename)[source]¶ This function loads the Bonds from a LAMMPS input file and turns them into a list of Bond objects.
- Parameters
filename (str) – The filename of the LAMMPS input file which has the Bonds you wish to use.
- Returns
A list of Bond objects with the same value as the Bonds in the LAMMPS input file passed in.
- Return type
Bond List
-
molecule_class.
loadDihedrals
(filename)[source]¶ This function loads the Dihedrals from a LAMMPS input file and turns them into a list of Dihedral objects.
- Parameters
filename (str) – The filename of the LAMMPS input file which has the Dihedrals you wish to use.
- Returns
A list of Dihedral objects with the same value as the Dihedrals in the LAMMPS input file passed in.
- Return type
Dihedral List
-
molecule_class.
molecule2graph
(atomlist, bondlist)[source]¶ Converts the Atom list and Bond list of a molecule to a graph data object
- Parameters
atomlist (Atom List) – A list of atoms in the molecule
bondlist (Bond List) – A list of bonds associated with the molecule
- Returns
molecule_graph – A Networkx Graph object with the nodes being the atom ID’s of the atoms and the connectivity of the graph defined by the bonds in the bondlist.
- Return type
Networkx Graph
-
molecule_class.
rot_quat
(vector, theta, rot_axis)[source]¶ Rotates a vector about a specified axis a specified angle theta using the quaternion method
- Parameters
vector (float vector) – A vector of three elements that represents the X, Y, Z coordinates of the vector that one wishes to rotate
theta (float) – The angle in radians by which the vector rotates.
rot_axis (float vector) – A vector of three elements which represents the X,Y,Z elements of the rotation axis.
- Returns
new_vector – A vector of three elements representing the X,Y,Z coordinates of the old vector after rotation
- Return type
float vector
-
molecule_class.
set_anchor_atoms
(molecules, anchortype)[source]¶ For every molecule in molecules set the anchot atom to the atom with atom type anchortype.
- Parameters
molecules (list of Molecule) –
list of Molecule objects that will have their anchor atoms set to the atom with type anchortype. (A) –
anchortype (int) –
atom type of the atom to set as the anchor for each Molecule in molecules. (The) –