openforcefield.topology.
Topology
(other=None)[source]¶A Topology is a chemical representation of a system containing one or more molecules appearing in a specified order.
Warning
This API is experimental and subject to change.
Examples
Import some utilities
>>> from simtk.openmm import app
>>> from openforcefield.tests.utils import get_data_file_path, get_packmol_pdb_file_path
>>> pdb_filepath = get_packmol_pdb_file_path('cyclohexane_ethanol_0.4_0.6')
>>> monomer_names = ('cyclohexane', 'ethanol')
Create a Topology object from a PDB file and sdf files defining the molecular contents
>>> from openforcefield.topology import Molecule, Topology
>>> pdbfile = app.PDBFile(pdb_filepath)
>>> sdf_filepaths = [get_data_file_path(f'systems/monomers/{name}.sdf') for name in monomer_names]
>>> unique_molecules = [Molecule.from_file(sdf_filepath) for sdf_filepath in sdf_filepaths]
>>> topology = Topology.from_openmm(pdbfile.topology, unique_molecules=unique_molecules)
Create a Topology object from a PDB file and IUPAC names of the molecular contents
>>> pdbfile = app.PDBFile(pdb_filepath)
>>> unique_molecules = [Molecule.from_iupac(name) for name in monomer_names]
>>> topology = Topology.from_openmm(pdbfile.topology, unique_molecules=unique_molecules)
Create an empty Topology object and add a few copies of a single benzene molecule
>>> topology = Topology()
>>> molecule = Molecule.from_iupac('benzene')
>>> molecule_topology_indices = [topology.add_molecule(molecule) for index in range(10)]
angles
Iterable of Tuple[TopologyAtom]: iterator over the angles in this Topology.
aromaticity_model
Get the aromaticity model applied to all molecules in the topology.
box_vectors
Return the box vectors of the topology, if specified
charge_model
Get the partial charge model applied to all molecules in the topology.
constrained_atom_pairs
Returns the constrained atom pairs of the Topology
fractional_bond_order_model
Get the fractional bond order model for the Topology.
impropers
Iterable of Tuple[TopologyAtom]: iterator over the improper torsions in this Topology.
n_angles
int: number of angles in this Topology.
n_impropers
int: number of improper torsions in this Topology.
n_propers
int: number of proper torsions in this Topology.
n_reference_molecules
Returns the number of reference (unique) molecules in in this Topology.
n_topology_atoms
Returns the number of topology atoms in in this Topology.
n_topology_bonds
Returns the number of TopologyBonds in in this Topology.
n_topology_molecules
Returns the number of topology molecules in in this Topology.
n_topology_particles
Returns the number of topology particles (TopologyAtoms and TopologyVirtualSites) in in this Topology.
n_topology_virtual_sites
Returns the number of TopologyVirtualSites in in this Topology.
propers
Iterable of Tuple[TopologyAtom]: iterator over the proper torsions in this Topology.
reference_molecules
Get an iterator of reference molecules in this Topology.
topology_atoms
Returns an iterator over the atoms in this Topology.
topology_bonds
Returns an iterator over the bonds in this Topology
topology_molecules
Returns an iterator over all the TopologyMolecules in this Topology
topology_particles
Returns an iterator over the particles (TopologyAtoms and TopologyVirtualSites) in this Topology.
topology_virtual_sites
Get an iterator over the virtual sites in this Topology
Methods
|
Mark a pair of atoms as constrained. |
|
Add a Molecule to the Topology. |
|
Add a Particle to the Topology. |
|
Raise an exception if the specified atoms are not bonded in the topology. |
|
Get the TopologyAtom at a given Topology atom index. |
|
Get the TopologyBond at a given Topology bond index. |
|
Retrieve all matches for a given chemical environment query. |
|
Instantiate an object from a BSON serialized representation. |
|
Static constructor from dictionary representation. |
|
Instantiate an object from a JSON serialized representation. |
|
Construct an openforcefield Topology object from an MDTraj Topology object. |
|
Instantiate an object from a MessagePack serialized representation. |
|
Create a new Topology object containing one copy of each of the specified molecule(s). |
|
Construct an openforcefield Topology object from an OpenMM Topology object. |
|
Warning This functionality will be implemented in a future toolkit release. |
|
Instantiate an object from a pickle serialized representation. |
|
Instantiate an object from a TOML serialized representation. |
|
Instantiate an object from an XML serialized representation. |
|
Instantiate from a YAML serialized representation. |
|
Returns the bond between two atoms |
|
Retrieve the fractional bond order for a bond. |
|
Returns True if the two atoms are bonded |
|
Check if a pair of atoms are marked as constrained. |
|
Return a BSON serialized representation. |
|
Convert to dictionary representation. |
|
Return a JSON serialized representation. |
|
Return a MessagePack representation. |
|
Create an OpenMM Topology object. |
|
Warning This functionality will be implemented in a future toolkit release. |
|
Return a pickle serialized representation. |
|
Return a TOML serialized representation. |
|
Return an XML representation. |
|
Return a YAML serialized representation. |
|
Get the TopologyAtom at a given Topology atom index. |
__init__
(self, other=None)[source]¶Create a new Topology.
If specified, attempt to construct a copy of the Topology from the specified object. This might be a Topology object, or a file that can be used to construct a Topology object or serialized Topology object.
Methods
|
Create a new Topology. |
|
Mark a pair of atoms as constrained. |
|
Add a Molecule to the Topology. |
|
Add a Particle to the Topology. |
|
Raise an exception if the specified atoms are not bonded in the topology. |
|
Get the TopologyAtom at a given Topology atom index. |
|
Get the TopologyBond at a given Topology bond index. |
|
Retrieve all matches for a given chemical environment query. |
|
Instantiate an object from a BSON serialized representation. |
|
Static constructor from dictionary representation. |
|
Instantiate an object from a JSON serialized representation. |
|
Construct an openforcefield Topology object from an MDTraj Topology object. |
|
Instantiate an object from a MessagePack serialized representation. |
|
Create a new Topology object containing one copy of each of the specified molecule(s). |
|
Construct an openforcefield Topology object from an OpenMM Topology object. |
|
Warning This functionality will be implemented in a future toolkit release. |
|
Instantiate an object from a pickle serialized representation. |
|
Instantiate an object from a TOML serialized representation. |
|
Instantiate an object from an XML serialized representation. |
|
Instantiate from a YAML serialized representation. |
|
Returns the bond between two atoms |
|
Retrieve the fractional bond order for a bond. |
|
Returns True if the two atoms are bonded |
|
Check if a pair of atoms are marked as constrained. |
|
Return a BSON serialized representation. |
|
Convert to dictionary representation. |
|
Return a JSON serialized representation. |
|
Return a MessagePack representation. |
|
Create an OpenMM Topology object. |
|
Warning This functionality will be implemented in a future toolkit release. |
|
Return a pickle serialized representation. |
|
Return a TOML serialized representation. |
|
Return an XML representation. |
|
Return a YAML serialized representation. |
|
Get the TopologyAtom at a given Topology atom index. |
Attributes
Iterable of Tuple[TopologyAtom]: iterator over the angles in this Topology. |
|
Get the aromaticity model applied to all molecules in the topology. |
|
Return the box vectors of the topology, if specified Returns ——- box_vectors : simtk.unit.Quantity wrapped numpy array The unit-wrapped box vectors of this topology |
|
Get the partial charge model applied to all molecules in the topology. |
|
Returns the constrained atom pairs of the Topology |
|
Get the fractional bond order model for the Topology. |
|
Iterable of Tuple[TopologyAtom]: iterator over the improper torsions in this Topology. |
|
int: number of angles in this Topology. |
|
int: number of improper torsions in this Topology. |
|
int: number of proper torsions in this Topology. |
|
Returns the number of reference (unique) molecules in in this Topology. |
|
Returns the number of topology atoms in in this Topology. |
|
Returns the number of TopologyBonds in in this Topology. |
|
Returns the number of topology molecules in in this Topology. |
|
Returns the number of topology particles (TopologyAtoms and TopologyVirtualSites) in in this Topology. |
|
Returns the number of TopologyVirtualSites in in this Topology. |
|
Iterable of Tuple[TopologyAtom]: iterator over the proper torsions in this Topology. |
|
Get an iterator of reference molecules in this Topology. |
|
Returns an iterator over the atoms in this Topology. |
|
Returns an iterator over the bonds in this Topology |
|
Returns an iterator over all the TopologyMolecules in this Topology |
|
Returns an iterator over the particles (TopologyAtoms and TopologyVirtualSites) in this Topology. |
|
Get an iterator over the virtual sites in this Topology |
reference_molecules
¶Get an iterator of reference molecules in this Topology.
from_molecules
(molecules)[source]¶Create a new Topology object containing one copy of each of the specified molecule(s).
One or more molecules to be added to the Topology
The Topology created from the specified molecule(s)
assert_bonded
(self, atom1, atom2)[source]¶Raise an exception if the specified atoms are not bonded in the topology.
The atoms or atom topology indices to check to ensure they are bonded
aromaticity_model
¶Get the aromaticity model applied to all molecules in the topology.
Aromaticity model in use.
box_vectors
¶Return the box vectors of the topology, if specified Returns ——- box_vectors : simtk.unit.Quantity wrapped numpy array
The unit-wrapped box vectors of this topology
charge_model
¶Get the partial charge model applied to all molecules in the topology.
Charge model used for all molecules in the Topology.
constrained_atom_pairs
¶Returns the constrained atom pairs of the Topology
dictionary of the form d[(atom1_topology_index, atom2_topology_index)] = distance (float)
fractional_bond_order_model
¶Get the fractional bond order model for the Topology.
Fractional bond order model in use.
n_reference_molecules
¶Returns the number of reference (unique) molecules in in this Topology.
n_topology_molecules
¶Returns the number of topology molecules in in this Topology.
topology_molecules
¶Returns an iterator over all the TopologyMolecules in this Topology
n_topology_atoms
¶Returns the number of topology atoms in in this Topology.
topology_atoms
¶Returns an iterator over the atoms in this Topology. These will be in ascending order of topology index (Note that this is not necessarily the same as the reference molecule index)
n_topology_bonds
¶Returns the number of TopologyBonds in in this Topology.
topology_bonds
¶Returns an iterator over the bonds in this Topology
n_topology_particles
¶Returns the number of topology particles (TopologyAtoms and TopologyVirtualSites) in in this Topology.
topology_particles
¶Returns an iterator over the particles (TopologyAtoms and TopologyVirtualSites) in this Topology. The TopologyAtoms will be in order of ascending Topology index (Note that this may differ from the order of atoms in the reference molecule index).
n_topology_virtual_sites
¶Returns the number of TopologyVirtualSites in in this Topology.
topology_virtual_sites
¶Get an iterator over the virtual sites in this Topology
n_angles
¶int: number of angles in this Topology.
angles
¶Iterable of Tuple[TopologyAtom]: iterator over the angles in this Topology.
n_propers
¶int: number of proper torsions in this Topology.
propers
¶Iterable of Tuple[TopologyAtom]: iterator over the proper torsions in this Topology.
n_impropers
¶int: number of improper torsions in this Topology.
impropers
¶Iterable of Tuple[TopologyAtom]: iterator over the improper torsions in this Topology.
chemical_environment_matches
(self, query, aromaticity_model='MDL', toolkit_registry=<openforcefield.utils.toolkits.ToolkitRegistry object at 0x7f1ceff574e0>)[source]¶Retrieve all matches for a given chemical environment query.
TODO: * Do we want to generalize this to other kinds of queries too, like mdtraj DSL, pymol selections, atom index slices, etc?
We could just call it topology.matches(query)
SMARTS string (with one or more tagged atoms) or ChemicalEnvironment
query
Query will internally be resolved to SMARTS using query.as_smarts()
if it has an .as_smarts
method.
Override the default aromaticity model for this topology and use the specified aromaticity model instead. Allowed values: [‘MDL’]
A list of tuples, containing the topology indices of the matching atoms.
from_openmm
(openmm_topology, unique_molecules=None)[source]¶Construct an openforcefield Topology object from an OpenMM Topology object.
An OpenMM Topology object
All unique molecules must be provided, in any order, though multiple copies of each molecule are allowed.
The atomic elements and bond connectivity will be used to match the reference molecules
to molecule graphs appearing in the OpenMM Topology
. If bond orders are present in the
OpenMM Topology
, these will be used in matching as well.
If all bonds have bond orders assigned in mdtraj_topology
, these bond orders will be used to attempt to construct
the list of unique Molecules if the unique_molecules
argument is omitted.
An openforcefield Topology object
to_openmm
(self)[source]¶Create an OpenMM Topology object.
The OpenMM Topology
object will have one residue per topology
molecule. Currently, the number of chains depends on how many copies
of the same molecule are in the Topology
. Molecules with more
than 5 copies are all assigned to a single chain, otherwise one
chain is created for each molecule. This behavior may change in
the future.
An OpenMM Topology object
from_mdtraj
(mdtraj_topology, unique_molecules=None)[source]¶Construct an openforcefield Topology object from an MDTraj Topology object.
An MDTraj Topology object
All unique molecules mult be provided, in any order, though multiple copies of each molecule are allowed.
The atomic elements and bond connectivity will be used to match the reference molecules
to molecule graphs appearing in the MDTraj Topology
. If bond orders are present in the
MDTraj Topology
, these will be used in matching as well.
If all bonds have bond orders assigned in mdtraj_topology
, these bond orders will be used to attempt to construct
the list of unique Molecules if the unique_molecules
argument is omitted.
An openforcefield Topology object
from_parmed
(parmed_structure, unique_molecules=None)[source]¶Warning
This functionality will be implemented in a future toolkit release.
Construct an openforcefield Topology object from a ParmEd Structure object.
A ParmEd structure object
All unique molecules mult be provided, in any order, though multiple copies of each molecule are allowed.
The atomic elements and bond connectivity will be used to match the reference molecules
to molecule graphs appearing in the structure’s topology
object. If bond orders are present in the
structure’s topology
object, these will be used in matching as well.
If all bonds have bond orders assigned in the structure’s topology
object,
these bond orders will be used to attempt to construct
the list of unique Molecules if the unique_molecules
argument is omitted.
An openforcefield Topology object
to_parmed
(self)[source]¶Warning
This functionality will be implemented in a future toolkit release.
Create a ParmEd Structure object.
A ParmEd Structure objecft
get_bond_between
(self, i, j)[source]¶Returns the bond between two atoms
Atoms or atom indices to check
The bond between i and j.
is_bonded
(self, i, j)[source]¶Returns True if the two atoms are bonded
Atoms or atom indices to check
True if atoms are bonded, False otherwise.
atom
(self, atom_topology_index)[source]¶Get the TopologyAtom at a given Topology atom index.
The index of the TopologyAtom in this Topology
virtual_site
(self, vsite_topology_index)[source]¶Get the TopologyAtom at a given Topology atom index.
The index of the TopologyVirtualSite in this Topology
bond
(self, bond_topology_index)[source]¶Get the TopologyBond at a given Topology bond index.
The index of the TopologyBond in this Topology
add_particle
(self, particle)[source]¶Add a Particle to the Topology.
The Particle to be added. The Topology will take ownership of the Particle.
add_molecule
(self, molecule, local_topology_to_reference_index=None)[source]¶Add a Molecule to the Topology.
The Molecule to be added.
Dictionary of {TopologyMolecule_atom_index : Molecule_atom_index} for the TopologyMolecule that will be built
The index of this molecule in the topology
from_bson
(serialized)¶Instantiate an object from a BSON serialized representation.
Specification: http://bsonspec.org/
A BSON serialized representation of the object
An instantiated object
from_json
(serialized)¶Instantiate an object from a JSON serialized representation.
Specification: https://www.json.org/
A JSON serialized representation of the object
An instantiated object
from_messagepack
(serialized)¶Instantiate an object from a MessagePack serialized representation.
Specification: https://msgpack.org/index.html
A MessagePack-encoded bytes serialized representation
Instantiated object.
from_pickle
(serialized)¶Instantiate an object from a pickle serialized representation.
Warning
This is not recommended for safe, stable storage since the pickle specification may change between Python versions.
A pickled representation of the object
An instantiated object
from_toml
(serialized)¶Instantiate an object from a TOML serialized representation.
Specification: https://github.com/toml-lang/toml
A TOML serialized representation of the object
An instantiated object
from_xml
(serialized)¶Instantiate an object from an XML serialized representation.
Specification: https://www.w3.org/XML/
An XML serialized representation
Instantiated object.
from_yaml
(serialized)¶Instantiate from a YAML serialized representation.
Specification: http://yaml.org/
A YAML serialized representation of the object
Instantiated object
to_bson
(self)¶Return a BSON serialized representation.
Specification: http://bsonspec.org/
A BSON serialized representation of the objecft
to_json
(self, indent=None)¶Return a JSON serialized representation.
Specification: https://www.json.org/
If not None, will pretty-print with specified number of spaces for indentation
A JSON serialized representation of the object
to_messagepack
(self)¶Return a MessagePack representation.
Specification: https://msgpack.org/index.html
A MessagePack-encoded bytes serialized representation of the object
to_pickle
(self)¶Return a pickle serialized representation.
Warning
This is not recommended for safe, stable storage since the pickle specification may change between Python versions.
A pickled representation of the object
to_toml
(self)¶Return a TOML serialized representation.
Specification: https://github.com/toml-lang/toml
A TOML serialized representation of the object
to_xml
(self, indent=2)¶Return an XML representation.
Specification: https://www.w3.org/XML/
If not None, will pretty-print with specified number of spaces for indentation
A MessagePack-encoded bytes serialized representation.
to_yaml
(self)¶Return a YAML serialized representation.
Specification: http://yaml.org/
A YAML serialized representation of the object
add_constraint
(self, iatom, jatom, distance=True)[source]¶Mark a pair of atoms as constrained.
Constraints between atoms that are not bonded (e.g., rigid waters) are permissible.
Atoms to mark as constrained These atoms may be bonded or not in the Topology
Constraint distance
True
if distance has yet to be determined
False
if constraint is to be removed
is_constrained
(self, iatom, jatom)[source]¶Check if a pair of atoms are marked as constrained.
Indices of atoms to mark as constrained.
True if constrained but constraints have not yet been applied Distance if constraint has already been added to System
get_fractional_bond_order
(self, iatom, jatom)[source]¶Retrieve the fractional bond order for a bond.
An Exception is raised if it cannot be determined.
Atoms for which a fractional bond order is to be retrieved.
Fractional bond order between the two specified atoms.