The topologyobjects module¶
The topologyobjects module contains a wide array of classes used
extensively in the core structure.Structure class.
|
An atom. |
|
A single residue that is composed of a small number of atoms |
|
Array of Atoms |
|
Array of Residue instances |
|
A covalent bond connecting two atoms. |
|
A valence angle between 3 atoms separated by two covalent bonds. |
|
A Urey-Bradley angle type with a set of parameters. |
|
A valence dihedral between 4 atoms separated by three covalent bonds. |
|
A CHARMM-style improper torsion between 4 atoms. |
|
A coupled-torsion correction map term defined between 5 atoms connected by four covalent bonds. |
|
Atom types can either be compared by indexes or names. |
|
A bond type with a set of bond parameters |
|
An angle type with a set of angle parameters |
|
A dihedral type with a set of dihedral parameters |
|
Dihedral types are a Fourier expansion of terms. |
|
An improper type with a set of improper torsion parameters |
Using the Atom class¶
The Atom class behaves much as you would expect it to. It has various
attributes, including the name of the atom, the type of the atom, its
mass, atomic_number, and many other properties typically stored in one
of the supported file formats. For example:
>>> atom = Atom(name="CA", mass=12.01, type="CT", atomic_number=12)
>>> atom.name
'CA'
>>> atom.type
'CT'
>>> atom.atomic_number
12
>>> atom.mass
12.01
It also stores references to all of the parameter types in which this belongs. For instance, the
bonds,angles,dihedrals,impropers, andcmapsattributes are lists of references to theBond,Angle,Dihedral,Improper, andCmapinstances in which this atom is a member.Instances of
Atomshould be considered singletons – that is, their equality is based on identity. As such, you should use theisoperator rather than==when comparing the equality of two atoms. In fact,Atom.__eq__is not implemented at all, so it works the same way thatisdoes in this case. This is an important distinction, because it makesAtominstances hashable, meaning that they can serve as keys in adictor can be added to aset.Atom ordering is determined based on positions within a particular
AtomList. When anAtombelongs to anAtomList, it knows its absolute position within that list via theidxattribute (which is set to-1if the Atom is not part of anAtomList). Theidxattribute is automatically updated if the parentAtomListis changed in any way (e.g., some atoms are deleted or inserted). This allows sublists ofAtominstances to be sorted according to their order in their mainAtomList. (Note, eachAtomcan belong to no more than oneAtomList)Atoms store lists of other
Atominstances that are connected to that atom via covalent bonds, angles, torsions, or coupled-torsions maps in thebond_partners,angle_partners,dihedral_partners, andtortor_partners, respectively. These are primarily used to determine pairs of atoms that are excluded from a nonbonded interaction in traditional force fields. There is an additionalexclusion_partnersarray that contains a list of arbitrary pairs of atoms that are not connected by any of the valence terms mentioned above. Each atom can appear in one, and only one list of another atom, with preference given to the “partner” arrays in the order they were listed above. Membership in these arrays is always symmetric—that is, if one atom is in thebond_partnersarray of another, that other atom is also in thebond_partnersarray of the first. These lists are populated automatically when the relevant valence terms are created (see below).
You will typically not have to instantiate an Atom or AtomList
instance on your own, as they are created as part of a
structure.Structure instance created by the various structure file
parsers.
Using the Residue class¶
The Residue class is an object that represents a typical residue in a
biomolecular system. Examples include a single amino or nucleic acid in a
peptide or nucleotide chain. A Residue is a collection of atoms, each
of which is connected to the other ones through a network of bonds (and may be
bonded to other residues as well, although that is not required).
Residues have 4 primary attributes of general use:
name: The name of the residue
chain: The chain identifier of the residue (a common identifier in the PDB)
insertion_code: Also used as part of the PDB, these are primarily used to align homologous sequences when some homologies have an extra residue compared to the other(s)
atoms: AlistofAtominstances contained within the residue
Residues are uniquely identified by their name, chain, and
insertion_code within a single system.
Common things you can do with a Residue¶
In the following code sample, assume atom is an instance of Atom
which is one of the atoms inside residue (an instance of Residue).
Iterate through the atoms:
for atom in residue: print(atom.name)
Get the i’th atom from a residue:
atomI = residue[i]
Determine if an atom is part of a residue:
if atom in residue: print("Atom %s is inside residue %s" % (atom.name, residue.name))
Find out how many atoms are in a residue:
n_atoms_in_res = len(residue)
Add an atom to a residue:
residue.add_atom(atom) assert atom in residue
Delete an atom from a residue:
residue.delete_atom(atom) assert atom not in residue
The AtomList class¶
AtomList is a subclass of the basic Python list type, with some added
features:
The
AtomListclaims ownership of anyAtomadded to it and sets theidxattribute of each of the atoms to their position in the array. Atoms should never be part of multipleAtomListinstances.The
AtomListhas achangedattribute that is set toTrueany time the list is changed (i.e., if an atom is added, deleted, inserted, moved, etc.) – you must manaully set thischangedattribute toFalseafterwards if you wish to track any future changes.
This class is also typically instantiated by the structure.Structure
parsers (e.g., structure.read_PDB(), structure.read_CIF(), …)
The ResidueList class¶
ResidueList is also a subclass of list with some added features of
its own:
The
ResidueListcontains a list ofResidueinstances, and sets theidxattribute on them to point to their current location in the list.Atoms can be added directly to the residue list. This is done because most file formats list atoms sequentially, and the beginning and end of each residue is detected by either the residue name, number, chain ID, or insertion code changing. As long as these residue properties are the same as the last
Atominstance you added, the atom will be added to that last residue. If it is a new residue,ResidueListwill create a newResidueobject, append it to itself, and add that atom to it. For example:>>> residues = ResidueList() >>> residues.add_atom(Atom(name='C1'), 'RE1', 1, 'A') >>> residues.add_atom(Atom(name='C2'), 'RE1', 1, 'A') >>> residues.add_atom(Atom(name='C3'), 'RE1', 1, 'A') >>> residues.add_atom(Atom(name='C4'), 'RE2', 2, 'A') # new residue >>> residues.add_atom(Atom(name='C5'), 'RE2', 3, 'A') # new residue >>> len(residues) 3 >>> len(residues[0]) 3 >>> len(residues[1]) 1 >>> len(residues[2]) 1
The Bond class¶
The covalent bond is the simplest of topological features in a molecule. The
Bond class represents a covalent bonds between two Atom
instances. Creating a Bond between two Atom instances adds
the resulting Bond to the bonds list of both atoms. It also adds
each atom to the bond_partners list of the other atom. For example:
>>> a1 = Atom(name='CA')
>>> a2 = Atom(name='CB')
>>> bond = Bond(a1, a2)
>>> a1.bonds[0] is bond
True
>>> a2.bonds[0] is bond
True
>>> a2 in a1.bond_partners
True
>>> a1 in a2.bond_partners
True
Bonds can also contain Atom instances. Continuing from the example
above:
>>> a1 in bond
True
>>> a2 in bond
True
>>> a3 = Atom(name='HA')
>>> a3 in bond
False
Bonds are unique valence terms since they are the simplest of valence terms.
Other valence terms (described below) can contain both Atom and
Bond instances.
The ordering of the two atoms in the Bond constructor does not matter,
as the bond a1--a2 and a2--a1 are equivalent.
The Angle class¶
The valence angle is formed from two adjacent bonds that form a common center.
The Angle class represents a valence angle between 3 atoms in which two
of the three atoms are bonded to a central atom. In this case, the order of the
middle atom in the constructor matters, but the order of the outer atoms does
not. For example:
>>> a1 = Atom(name='CA')
>>> a2 = Atom(name='CB')
>>> a3 = Atom(name='CG')
>>> b1 = Bond(a1, a2)
>>> b2 = Bond(a2, a3)
>>> b3 = Bond(a1, a3) # let's make this a triangle
>>> angle = Angle(a1, a2, a3)
In the above example, our angle is formed between the bonds a1--a2--a3, so
angle contains the three atoms as well as b1 and b2, but not
b3:
>>> a1 in angle
True
>>> a2 in angle
True
>>> a3 in angle
True
>>> b1 in angle
True
>>> b2 in angle
True
>>> b3 in angle
False
Like with the Bond class, creating an Angle adds the created
angle to the angles list on all three of the atoms. Furthermore, the
angle_partners attribute of a1 and a3 have a3 and a1 added
to them, respectively. As mentioned above, the same Atom instance will
never appear in two xxx_partners arrays. For example:
>>> a1 in a3.angle_partners
True
>>> a1 in a3.bond_partners
False
>>> a1 in a2.bond_partners
True
>>> a1 in a3.angle_partners
False
The UreyBradley class¶
The UreyBradley class defines a covalent bond-like interaction between
two atoms separated by a valence angle, adding anharmonicity to purely harmonic
angle terms. The interface to UreyBradley terms is analogous to those
for Bond and Angle above.
The Dihedral class¶
The Dihedral class follows the same trend as the Angle class
described above, and behaves in an analogous way. There are a couple unique
aspects to Dihedrals, though. A Dihedral can be an improper dihedral
(in which all 4 atoms are ideally coplanar, with the third atom being the
“central” atom bonded to all of the others). The Dihedral instance has
a boolean attribute improper that indicates whether or not it is an improper
torsion.
The Improper class¶
The Improper class is strictly an improper torsion, and is used where
certain force fields utilize a separate functional form for “proper” and
“improper” torsions (e.g., the CHARMM force field). You are forwarded to the API
documentation for Improper for more details.
The Cmap class¶
The Cmap class is a correction map defined between adjacent torsions
(i.e., 5 atoms separated by 4 bonds). Like the other valence terms described
above, it contains 5 Atom instances and may contain 4 Bond
instances (as tested via the in operator). See the API documentation for
Cmap for more details.
The XyzType classes¶
Every valence term described above contains a type attribute that is either
None if unassigned or the relevant ParameterType (e.g.,
BondType for Bond and UreyBradley classes) instance.
Certain functionality (e.g., simulations using OpenMM or writing Amber topology
files) requires all parameters be present and assigned. These types have, where
applicable, force constants and equilibrium values for the various parameter
types.
Amoeba-specific terms¶
The AMOEBA force field has nominal support in ParmEd (with improved support planned). This force field contains a large number of additional terms and parameters for use with the AMOEBA force field. For convenience, they are listed below. Consult the API documentation in the resulting links for more information.
|
A trigonal-angle term in the AMOEBA force field. |
|
Out-of-plane bending term in the AMOEBA force field. |
|
An angle type with a set of angle parameters |
|
Defines a pi-torsion term in the AMOEBA force field. |
|
This term models the stretching and bending of a standard valence angle, and is used in the AMOEBA force field |
|
A stretch-bend type with two distances and an angle in AMOEBA |
|
This is a coupled-torsion map used in the AMOEBA force field similar to the correction-map (CMAP) potential used by the CHARMM force field |
|
The type containing the parameter maps for the Amoeba torsion-torsion potentials. |
|
A chiral frame as defined in the AMOEBA force field. |
|
This defines the frame of reference for computing multipole interactions in the AMOEBA force field. |
|
The AMOEBA force field has complex exclusion and exception rules (referred to as “adjustments” in the Amber-converted files). |
|
A parameter describing how the various nonbonded interactions between a particular pair of atoms behaves in a specified nonbonded exception (e.g., in 1-4 interacting terms) |