openforcefield.topology.
FrozenMolecule
(other=None, file_format=None, toolkit_registry=<openforcefield.utils.toolkits.ToolkitRegistry object>, allow_undefined_stereo=False)[source]¶Immutable chemical representation of a molecule, such as a small molecule or biopolymer.
Examples
Create a molecule from a sdf file
>>> from openforcefield.utils import get_data_file_path
>>> sdf_filepath = get_data_file_path('molecules/ethanol.sdf')
>>> molecule = FrozenMolecule.from_file(sdf_filepath)
Convert to OpenEye OEMol object
>>> oemol = molecule.to_openeye()
Create a molecule from an OpenEye molecule
>>> molecule = FrozenMolecule.from_openeye(oemol)
Convert to RDKit Mol object
>>> rdmol = molecule.to_rdkit()
Create a molecule from an RDKit molecule
>>> molecule = FrozenMolecule.from_rdkit(rdmol)
Create a molecule from IUPAC name (requires the OpenEye toolkit)
>>> molecule = FrozenMolecule.from_iupac('imatinib')
Create a molecule from SMILES
>>> molecule = FrozenMolecule.from_smiles('Cc1ccccc1')
Warning
This API is experimental and subject to change.
angles
Get an iterator over all i-j-k angles.
atoms
Iterate over all Atom objects.
bonds
Iterate over all Bond objects.
conformers
Iterate over all conformers in this molecule.
impropers
Iterate over all proper torsions in the molecule
n_angles
int: number of angles in the Molecule.
n_atoms
The number of Atom objects.
n_bonds
The number of Bond objects.
n_conformers
Iterate over all Atom objects.
n_impropers
int: number of improper torsions in the Molecule.
n_particles
The number of Particle objects, which corresponds to how many positions must be used.
n_propers
int: number of proper torsions in the Molecule.
n_virtual_sites
The number of VirtualSite objects.
name
The name (or title) of the molecule
partial_charges
Returns the partial charges (if present) on the molecule
particles
Iterate over all Particle objects.
propers
Iterate over all proper torsions in the molecule
properties
The properties dictionary of the molecule
torsions
Get an iterator over all i-j-k-l torsions.
total_charge
Return the total charge on the molecule
virtual_sites
Iterate over all VirtualSite objects.
Methods
|
Retrieve all matches for a given chemical environment query. |
|
Warning! Not Implemented! Calculate partial atomic charges for this molecule using an underlying toolkit |
|
Calculate partial atomic charges for this molecule using AM1-BCC run by an underlying toolkit |
|
Calculate wiberg bond orders for this molecule using an underlying toolkit |
|
Instantiate an object from a BSON serialized representation. |
|
Create a new Molecule from a dictionary representation |
|
Create one or more molecules from a file |
|
Generate a molecule from IUPAC or common name |
|
Instantiate an object from a JSON serialized representation. |
|
Instantiate an object from a MessagePack serialized representation. |
|
Create a Molecule from an OpenEye molecule. |
|
Instantiate an object from a pickle serialized representation. |
|
Create a Molecule from an RDKit molecule. |
|
Construct a Molecule from a SMILES representation |
|
Instantiate an object from a TOML serialized representation. |
|
Return a Molecule representation of an openforcefield Topology containing a single Molecule object. |
|
Instantiate an object from an XML serialized representation. |
|
Instantiate from a YAML serialized representation. |
|
Generate conformers for this molecule using an underlying toolkit |
|
Returns the bond between two atoms |
|
Get fractional bond orders. |
|
Determines whether the molecules are isomorphic by comparing their graphs. |
|
Return a BSON serialized representation. |
|
Return a dictionary representation of the molecule. |
|
Write the current molecule to a file or file-like object |
|
Generate IUPAC name from Molecule |
|
Return a JSON serialized representation. |
|
Return a MessagePack representation. |
|
Generate a NetworkX undirected graph from the Molecule. |
|
Create an OpenEye molecule |
|
Return a pickle serialized representation. |
|
Create an RDKit molecule |
|
Return a canonical isomeric SMILES representation of the current molecule |
|
Return a TOML serialized representation. |
|
Return an openforcefield Topology representation containing one copy of this molecule |
|
Return an XML representation. |
|
Return a YAML serialized representation. |
__init__
(self, other=None, file_format=None, toolkit_registry=<openforcefield.utils.toolkits.ToolkitRegistry object at 0x7f0a8dcfa208>, allow_undefined_stereo=False)[source]¶Create a new FrozenMolecule object
If specified, attempt to construct a copy of the Molecule from the specified object. This can be any one of the following:
If providing a file-like object, you must specify the format of the data. If providing a file, the file format will attempt to be guessed from the suffix.
ToolkitRegistry
or ToolkitWrapper
object, optional, default=GLOBAL_TOOLKIT_REGISTRYToolkitRegistry
or ToolkitWrapper
to use for I/O operations
If loaded from a file and False
, raises an exception if
undefined stereochemistry is detected during the molecule’s
construction.
Examples
Create an empty molecule:
>>> empty_molecule = FrozenMolecule()
Create a molecule from a file that can be used to construct a molecule, using either a filename or file-like object:
>>> from openforcefield.utils import get_data_file_path
>>> sdf_filepath = get_data_file_path('molecules/ethanol.sdf')
>>> molecule = FrozenMolecule(sdf_filepath)
>>> molecule = FrozenMolecule(open(sdf_filepath, 'r'), file_format='sdf')
>>> import gzip
>>> mol2_gz_filepath = get_data_file_path('molecules/toluene.mol2.gz')
>>> molecule = FrozenMolecule(gzip.GzipFile(mol2_gz_filepath, 'r'), file_format='mol2')
Create a molecule from another molecule:
>>> molecule_copy = FrozenMolecule(molecule)
Convert to OpenEye OEMol object
>>> oemol = molecule.to_openeye()
Create a molecule from an OpenEye molecule:
>>> molecule = FrozenMolecule(oemol)
Convert to RDKit Mol object
>>> rdmol = molecule.to_rdkit()
Create a molecule from an RDKit molecule:
>>> molecule = FrozenMolecule(rdmol)
Create a molecule from a serialized molecule object:
>>> serialized_molecule = molecule.__getstate__()
>>> molecule_copy = Molecule(serialized_molecule)
Methods
|
Create a new FrozenMolecule object |
|
Retrieve all matches for a given chemical environment query. |
|
Warning! Not Implemented! Calculate partial atomic charges for this molecule using an underlying toolkit |
|
Calculate partial atomic charges for this molecule using AM1-BCC run by an underlying toolkit |
|
Calculate wiberg bond orders for this molecule using an underlying toolkit |
|
Instantiate an object from a BSON serialized representation. |
|
Create a new Molecule from a dictionary representation |
|
Create one or more molecules from a file |
|
Generate a molecule from IUPAC or common name |
|
Instantiate an object from a JSON serialized representation. |
|
Instantiate an object from a MessagePack serialized representation. |
|
Create a Molecule from an OpenEye molecule. |
|
Instantiate an object from a pickle serialized representation. |
|
Create a Molecule from an RDKit molecule. |
|
Construct a Molecule from a SMILES representation |
|
Instantiate an object from a TOML serialized representation. |
|
Return a Molecule representation of an openforcefield Topology containing a single Molecule object. |
|
Instantiate an object from an XML serialized representation. |
|
Instantiate from a YAML serialized representation. |
|
Generate conformers for this molecule using an underlying toolkit |
|
Returns the bond between two atoms |
|
Get fractional bond orders. |
|
Determines whether the molecules are isomorphic by comparing their graphs. |
|
Return a BSON serialized representation. |
|
Return a dictionary representation of the molecule. |
|
Write the current molecule to a file or file-like object |
|
Generate IUPAC name from Molecule |
|
Return a JSON serialized representation. |
|
Return a MessagePack representation. |
|
Generate a NetworkX undirected graph from the Molecule. |
|
Create an OpenEye molecule |
|
Return a pickle serialized representation. |
|
Create an RDKit molecule |
|
Return a canonical isomeric SMILES representation of the current molecule |
|
Return a TOML serialized representation. |
|
Return an openforcefield Topology representation containing one copy of this molecule |
|
Return an XML representation. |
|
Return a YAML serialized representation. |
Attributes
Get an iterator over all i-j-k angles. |
|
Iterate over all Atom objects. |
|
Iterate over all Bond objects. |
|
Iterate over all conformers in this molecule. |
|
Iterate over all proper torsions in the molecule |
|
int: number of angles in the Molecule. |
|
The number of Atom objects. |
|
The number of Bond objects. |
|
Iterate over all Atom objects. |
|
int: number of improper torsions in the Molecule. |
|
The number of Particle objects, which corresponds to how many positions must be used. |
|
int: number of proper torsions in the Molecule. |
|
The number of VirtualSite objects. |
|
The name (or title) of the molecule |
|
Returns the partial charges (if present) on the molecule |
|
Iterate over all Particle objects. |
|
Iterate over all proper torsions in the molecule |
|
The properties dictionary of the molecule |
|
Get an iterator over all i-j-k-l torsions. |
|
Return the total charge on the molecule |
|
Iterate over all VirtualSite objects. |
to_dict
(self)[source]¶Return a dictionary representation of the molecule.
A dictionary representation of the molecule.
from_dict
(molecule_dict)[source]¶Create a new Molecule from a dictionary representation
A dictionary representation of the molecule.
A Molecule created from the dictionary representation
to_smiles
(self, toolkit_registry=<openforcefield.utils.toolkits.ToolkitRegistry object at 0x7f0a8dcfa208>)[source]¶Return a canonical isomeric SMILES representation of the current molecule
Note
RDKit and OpenEye versions will not necessarily return the same representation.
ToolkitRegistry
or ToolkitWrapper
to use for SMILES conversion
Canonical isomeric explicit-hydrogen SMILES
Examples
>>> from openforcefield.utils import get_data_file_path
>>> sdf_filepath = get_data_file_path('molecules/ethanol.sdf')
>>> molecule = Molecule(sdf_filepath)
>>> smiles = molecule.to_smiles()
from_smiles
(smiles, hydrogens_are_explicit=False, toolkit_registry=<openforcefield.utils.toolkits.ToolkitRegistry object at 0x7f0a8dcfa208>, allow_undefined_stereo=False)[source]¶Construct a Molecule from a SMILES representation
The SMILES representation of the molecule.
If False, the cheminformatics toolkit will perform hydrogen addition
ToolkitRegistry
or ToolkitWrapper
to use for SMILES-to-molecule conversion
Whether to accept SMILES with undefined stereochemistry. If False, an exception will be raised if a SMILES with undefined stereochemistry is passed into this function.
Examples
>>> molecule = Molecule.from_smiles('Cc1ccccc1')
is_isomorphic
(self, other, compare_atom_stereochemistry=True, compare_bond_stereochemistry=True)[source]¶Determines whether the molecules are isomorphic by comparing their graphs.
The molecule to test for isomorphism.
If False
, atoms’ stereochemistry is ignored for the
purpose of determining equality. Default is True
.
If False
, bonds’ stereochemistry is ignored for the
purpose of determining equality. Default is True
.
generate_conformers
(self, toolkit_registry=<openforcefield.utils.toolkits.ToolkitRegistry object at 0x7f0a8dcfa208>, n_conformers=10, clear_existing=True)[source]¶Generate conformers for this molecule using an underlying toolkit
ToolkitRegistry
or ToolkitWrapper
to use for SMILES-to-molecule conversion
The maximum number of conformers to produce
Whether to overwrite existing conformers for the molecule
If an invalid object is passed as the toolkit_registry parameter
Examples
>>> molecule = Molecule.from_smiles('CCCCCC')
>>> molecule.generate_conformers()
compute_partial_charges_am1bcc
(self, toolkit_registry=<openforcefield.utils.toolkits.ToolkitRegistry object at 0x7f0a8dcfa208>)[source]¶Calculate partial atomic charges for this molecule using AM1-BCC run by an underlying toolkit
ToolkitRegistry
or ToolkitWrapper
to use for the calculation
If an invalid object is passed as the toolkit_registry parameter
Examples
>>> molecule = Molecule.from_smiles('CCCCCC')
>>> molecule.generate_conformers()
>>> molecule.compute_partial_charges_am1bcc()
compute_partial_charges
(self, toolkit_registry=<openforcefield.utils.toolkits.ToolkitRegistry object at 0x7f0a8dcfa208>)[source]¶Warning! Not Implemented! Calculate partial atomic charges for this molecule using an underlying toolkit
The quantum chemical method to use for partial charge calculation.
The partial charge calculation method to use for partial charge calculation.
ToolkitRegistry
or ToolkitWrapper
to use for SMILES-to-molecule conversion
If an invalid object is passed as the toolkit_registry parameter
Examples
>>> molecule = Molecule.from_smiles('CCCCCC')
>>> molecule.generate_conformers()
compute_wiberg_bond_orders
(self, charge_model=None, toolkit_registry=<openforcefield.utils.toolkits.ToolkitRegistry object at 0x7f0a8dcfa208>)[source]¶Calculate wiberg bond orders for this molecule using an underlying toolkit
ToolkitRegistry
or ToolkitWrapper
to use for SMILES-to-molecule conversion
The charge model to use for partial charge calculation
If an invalid object is passed as the toolkit_registry parameter
Examples
>>> molecule = Molecule.from_smiles('CCCCCC')
>>> molecule.generate_conformers()
>>> molecule.compute_wiberg_bond_orders()
to_networkx
(self)[source]¶Generate a NetworkX undirected graph from the Molecule.
Nodes are Atoms labeled with particle indices and atomic elements (via the element
node atrribute).
Edges denote chemical bonds between Atoms.
Virtual sites are not included, since they lack a concept of chemical connectivity.
The resulting graph, with nodes (atoms) labeled with atom indices, elements, stereochemistry and aromaticity flags and bonds with two atom indices, bond order, stereochemistry, and aromaticity flags
Examples
Retrieve the bond graph for imatinib (OpenEye toolkit required)
>>> molecule = Molecule.from_iupac('imatinib')
>>> nxgraph = molecule.to_networkx()
partial_charges
¶Returns the partial charges (if present) on the molecule
The partial charges on this Molecule’s atoms.
n_particles
¶The number of Particle objects, which corresponds to how many positions must be used.
n_atoms
¶The number of Atom objects.
n_virtual_sites
¶The number of VirtualSite objects.
n_bonds
¶The number of Bond objects.
n_angles
¶int: number of angles in the Molecule.
n_propers
¶int: number of proper torsions in the Molecule.
n_impropers
¶int: number of improper torsions in the Molecule.
particles
¶Iterate over all Particle objects.
atoms
¶Iterate over all Atom objects.
conformers
¶Iterate over all conformers in this molecule.
n_conformers
¶Iterate over all Atom objects.
virtual_sites
¶Iterate over all VirtualSite objects.
bonds
¶Iterate over all Bond objects.
angles
¶Get an iterator over all i-j-k angles.
torsions
¶Get an iterator over all i-j-k-l torsions. Note that i-j-k-i torsions (cycles) are excluded.
propers
¶Iterate over all proper torsions in the molecule
impropers
¶Iterate over all proper torsions in the molecule
total_charge
¶Return the total charge on the molecule
name
¶The name (or title) of the molecule
properties
¶The properties dictionary of the molecule
chemical_environment_matches
(self, query, toolkit_registry=<openforcefield.utils.toolkits.ToolkitRegistry object at 0x7f0a8dcfa208>)[source]¶Retrieve all matches for a given chemical environment query.
SMARTS string (with one or more tagged atoms) or ChemicalEnvironment
query
Query will internally be resolved to SMIRKS using query.asSMIRKS()
if it has an .asSMIRKS
method.
ToolkitRegistry
or ToolkitWrapper
to use for chemical environment matches
A list of tuples, containing the indices of the matching atoms.
Examples
Retrieve all the carbon-carbon bond matches in a molecule
>>> molecule = Molecule.from_iupac('imatinib')
>>> matches = molecule.chemical_environment_matches('[#6X3:1]~[#6X3:2]')
from_iupac
(iupac_name, **kwargs)[source]¶Generate a molecule from IUPAC or common name
IUPAC name of molecule to be generated
If false, raises an exception if molecule contains undefined stereochemistry.
The resulting molecule with position
Note
This method requires the OpenEye toolkit to be installed. ..
Examples
Create a molecule from a common name
>>> molecule = Molecule.from_iupac('4-[(4-methylpiperazin-1-yl)methyl]-N-(4-methyl-3-{[4-(pyridin-3-yl)pyrimidin-2-yl]amino}phenyl)benzamide')
Create a molecule from a common name
>>> molecule = Molecule.from_iupac('imatinib')
to_iupac
(self)[source]¶Generate IUPAC name from Molecule
IUPAC name of the molecule
Note
This method requires the OpenEye toolkit to be installed. ..
Examples
>>> from openforcefield.utils import get_data_file_path
>>> sdf_filepath = get_data_file_path('molecules/ethanol.sdf')
>>> molecule = Molecule(sdf_filepath)
>>> iupac_name = molecule.to_iupac()
from_topology
(topology)[source]¶Return a Molecule representation of an openforcefield Topology containing a single Molecule object.
The Molecule object in the topology
If the topology does not contain exactly one molecule.
Examples
Create a molecule from a Topology object that contains exactly one molecule
>>> molecule = Molecule.from_topology(topology) # doctest: +SKIP
to_topology
(self)[source]¶Return an openforcefield Topology representation containing one copy of this molecule
A Topology representation of this molecule
Examples
>>> molecule = Molecule.from_iupac('imatinib')
>>> topology = molecule.to_topology()
from_file
(file_path, file_format=None, toolkit_registry=<openforcefield.utils.toolkits.ToolkitRegistry object at 0x7f0a8dcfa208>, allow_undefined_stereo=False)[source]¶Create one or more molecules from a file
The path to the file or file-like object to stream one or more molecules from.
Format specifier, usually file suffix (eg. ‘MOL2’, ‘SMI’) Note that not all toolkits support all formats. Check ToolkitWrapper.toolkit_file_read_formats for your loaded toolkits for details.
ToolkitRegistry
or ToolkitWrapper
to use for file loading. If a Toolkit is passed, only
the highest-precedence toolkit is used
If false, raises an exception if oemol contains undefined stereochemistry.
If there is a single molecule in the file, a Molecule is returned; otherwise, a list of Molecule objects is returned.
Examples
>>> from openforcefield.tests.utils import get_monomer_mol2_file_path
>>> mol2_file_path = get_monomer_mol2_file_path('cyclohexane')
>>> molecule = Molecule.from_file(mol2_file_path)
to_file
(self, file_path, file_format, toolkit_registry=<openforcefield.utils.toolkits.ToolkitRegistry object at 0x7f0a8dcfa208>)[source]¶Write the current molecule to a file or file-like object
A file-like object or the path to the file to be written.
Format specifier, one of [‘MOL2’, ‘MOL2H’, ‘SDF’, ‘PDB’, ‘SMI’, ‘CAN’, ‘TDT’] Note that not all toolkits support all formats
ToolkitRegistry
or ToolkitWrapper
to use for file writing. If a Toolkit is passed, only
the highest-precedence toolkit is used
If the requested file_format is not supported by one of the installed cheminformatics toolkits
Examples
>>> molecule = Molecule.from_iupac('imatinib')
>>> molecule.to_file('imatinib.mol2', file_format='mol2') # doctest: +SKIP
>>> molecule.to_file('imatinib.sdf', file_format='sdf') # doctest: +SKIP
>>> molecule.to_file('imatinib.pdb', file_format='pdb') # doctest: +SKIP
from_rdkit
(rdmol, allow_undefined_stereo=False)[source]¶Create a Molecule from an RDKit molecule.
Requires the RDKit to be installed.
An RDKit molecule
If false, raises an exception if oemol contains undefined stereochemistry.
An openforcefield molecule
Examples
Create a molecule from an RDKit molecule
>>> from rdkit import Chem
>>> from openforcefield.tests.utils import get_data_file_path
>>> rdmol = Chem.MolFromMolFile(get_data_file_path('systems/monomers/ethanol.sdf'))
>>> molecule = Molecule.from_rdkit(rdmol)
to_rdkit
(self, aromaticity_model='OEAroModel_MDL')[source]¶Create an RDKit molecule
Requires the RDKit to be installed.
The aromaticity model to use
An RDKit molecule
Examples
Convert a molecule to RDKit
>>> from openforcefield.utils import get_data_file_path
>>> sdf_filepath = get_data_file_path('molecules/ethanol.sdf')
>>> molecule = Molecule(sdf_filepath)
>>> rdmol = molecule.to_rdkit()
from_openeye
(oemol, allow_undefined_stereo=False)[source]¶Create a Molecule from an OpenEye molecule.
Requires the OpenEye toolkit to be installed.
An OpenEye molecule
If false, raises an exception if oemol contains undefined stereochemistry.
An openforcefield molecule
Examples
Create a Molecule from an OpenEye OEMol
>>> from openeye import oechem
>>> from openforcefield.tests.utils import get_data_file_path
>>> ifs = oechem.oemolistream(get_data_file_path('systems/monomers/ethanol.mol2'))
>>> oemols = list(ifs.GetOEGraphMols())
>>> molecule = Molecule.from_openeye(oemols[0])
to_openeye
(self, aromaticity_model='OEAroModel_MDL')[source]¶Create an OpenEye molecule
Requires the OpenEye toolkit to be installed.
The aromaticity model to use
An OpenEye molecule
Examples
Create an OpenEye molecule from a Molecule
>>> molecule = Molecule.from_smiles('CC')
>>> oemol = molecule.to_openeye()
get_fractional_bond_orders
(self, method='Wiberg', toolkit_registry=<openforcefield.utils.toolkits.ToolkitRegistry object at 0x7f0a8dcfa208>)[source]¶Get fractional bond orders.
The name of the charge method to use. Options are: * ‘Wiberg’ : Wiberg bond order
The toolkit registry to use for molecule operations
Examples
Get fractional Wiberg bond orders
>>> molecule = Molecule.from_iupac('imatinib')
>>> molecule.generate_conformers()
>>> fractional_bond_orders = molecule.get_fractional_bond_orders(method='Wiberg')
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