openforcefield.topology.FrozenMolecule¶
-
class
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.
- Attributes
angles
Get an iterator over all i-j-k angles.
atoms
Iterate over all Atom objects.
bonds
Iterate over all Bond objects.
conformers
Returns the list of conformers for this molecule.
has_unique_atom_names
True if the molecule has unique atom names, False otherwise.
hill_formula
Get the Hill formula of the 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
Returns the number of conformers for this molecule.
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
are_isomorphic
(mol1, mol2[, …])Determines whether the two molecules are isomorphic by comparing their graph representations and the chosen node/edge attributes.
assign_fractional_bond_orders
([…])Update and store list of bond orders this molecule.
assign_partial_charges
(partial_charge_method)Calculate partial atomic charges for this molecule using an underlying toolkit, and assign the new values to the partial_charges attribute.
canonical_order_atoms
([toolkit_registry])Canonical order the atoms in a copy of the molecule using a toolkit, returns a new copy.
chemical_environment_matches
(query[, …])Retrieve all matches for a given chemical environment query.
compute_partial_charges_am1bcc
([…])Calculate partial atomic charges for this molecule using AM1-BCC run by an underlying toolkit and assign them to this molecule’s partial_charges attribute.
enumerate_protomers
(**kwargs)Enumerate the formal charges of a molecule to generate different protomoers.
enumerate_stereoisomers
([undefined_only, …])Enumerate the stereocenters and bonds of the current molecule.
enumerate_tautomers
([max_states, …])Enumerate the possible tautomers of the current molecule
find_rotatable_bonds
([…])Find all bonds classed as rotatable ignoring any matched to the
ignore_functional_groups
list.from_bson
(serialized)Instantiate an object from a BSON serialized representation.
from_dict
(molecule_dict)Create a new Molecule from a dictionary representation
from_file
(file_path[, file_format, …])Create one or more molecules from a file
from_inchi
(inchi[, allow_undefined_stereo, …])Construct a Molecule from a InChI representation
from_iupac
(*args, **kwargs)Generate a molecule from IUPAC or common name
from_json
(serialized)Instantiate an object from a JSON serialized representation.
from_mapped_smiles
(mapped_smiles[, …])Create an openforcefield.topology.molecule.Molecule from a mapped SMILES made with cmiles.
from_messagepack
(serialized)Instantiate an object from a MessagePack serialized representation.
from_openeye
(*args, **kwargs)Create a Molecule from an OpenEye molecule.
from_pdb_and_smiles
(*args, **kwargs)Create a Molecule from a pdb file and a SMILES string using RDKit.
from_pickle
(serialized)Instantiate an object from a pickle serialized representation.
from_qcschema
(qca_record[, client, …])Create a Molecule from a QCArchive entry based on the cmiles information.
from_rdkit
(*args, **kwargs)Create a Molecule from an RDKit molecule.
from_smiles
(smiles[, …])Construct a Molecule from a SMILES representation
from_toml
(serialized)Instantiate an object from a TOML serialized representation.
from_topology
(topology)Return a Molecule representation of an openforcefield Topology containing a single Molecule object.
from_xml
(serialized)Instantiate an object from an XML serialized representation.
from_yaml
(serialized)Instantiate from a YAML serialized representation.
generate_conformers
([toolkit_registry, …])Generate conformers for this molecule using an underlying toolkit.
generate_unique_atom_names
()Generate unique atom names using element name and number of times that element has occurred e.g.
get_bond_between
(i, j)Returns the bond between two atoms
is_isomorphic_with
(other, **kwargs)Check if the molecule is isomorphic with the other molecule which can be an openforcefield.topology.Molecule, or TopologyMolecule or nx.Graph().
remap
(mapping_dict[, current_to_new])Remap all of the indexes in the molecule to match the given mapping dict
to_bson
()Return a BSON serialized representation.
to_dict
()Return a dictionary representation of the molecule.
to_file
(file_path, file_format[, …])Write the current molecule to a file or file-like object
to_hill_formula
(molecule)Generate the Hill formula from either a FrozenMolecule, TopologyMolecule or nx.Graph() of the molecule
to_inchi
([fixed_hydrogens, toolkit_registry])Create an InChI string for the molecule using the requested toolkit backend.
to_inchikey
([fixed_hydrogens, toolkit_registry])Create an InChIKey for the molecule using the requested toolkit backend.
to_iupac
(**kwargs)Generate IUPAC name from Molecule
to_json
([indent])Return a JSON serialized representation.
to_messagepack
()Return a MessagePack representation.
to_networkx
()Generate a NetworkX undirected graph from the Molecule.
to_openeye
(**kwargs)Create an OpenEye molecule
to_pickle
()Return a pickle serialized representation.
to_qcschema
([multiplicity, conformer, extras])Generate the qschema input format used to submit jobs to archive or run qcengine calculations locally, spec can be found here <https://molssi-qc-schema.readthedocs.io/en/latest/index.html>
to_rdkit
(**kwargs)Create an RDKit molecule
to_smiles
([isomeric, explicit_hydrogens, …])Return a canonical isomeric SMILES representation of the current molecule.
to_toml
()Return a TOML serialized representation.
to_topology
()Return an openforcefield Topology representation containing one copy of this molecule
to_xml
([indent])Return an XML representation.
to_yaml
()Return a YAML serialized representation.
-
__init__
(other=None, file_format=None, toolkit_registry=<openforcefield.utils.toolkits.ToolkitRegistry object>, allow_undefined_stereo=False)[source]¶ Create a new FrozenMolecule object
- Parameters
- otheroptional, default=None
If specified, attempt to construct a copy of the Molecule from the specified object. This can be any one of the following:
- file_formatstr, optional, default=None
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.
- toolkit_registrya
ToolkitRegistry
orToolkitWrapper
object, optional, default=GLOBAL_TOOLKIT_REGISTRY ToolkitRegistry
orToolkitWrapper
to use for I/O operations- allow_undefined_stereobool, default=False
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
__init__
([other, file_format, …])Create a new FrozenMolecule object
are_isomorphic
(mol1, mol2[, …])Determines whether the two molecules are isomorphic by comparing their graph representations and the chosen node/edge attributes.
assign_fractional_bond_orders
([…])Update and store list of bond orders this molecule.
assign_partial_charges
(partial_charge_method)Calculate partial atomic charges for this molecule using an underlying toolkit, and assign the new values to the partial_charges attribute.
canonical_order_atoms
([toolkit_registry])Canonical order the atoms in a copy of the molecule using a toolkit, returns a new copy.
chemical_environment_matches
(query[, …])Retrieve all matches for a given chemical environment query.
compute_partial_charges_am1bcc
([…])Calculate partial atomic charges for this molecule using AM1-BCC run by an underlying toolkit and assign them to this molecule’s partial_charges attribute.
enumerate_protomers
(**kwargs)Enumerate the formal charges of a molecule to generate different protomoers.
enumerate_stereoisomers
([undefined_only, …])Enumerate the stereocenters and bonds of the current molecule.
enumerate_tautomers
([max_states, …])Enumerate the possible tautomers of the current molecule
find_rotatable_bonds
([…])Find all bonds classed as rotatable ignoring any matched to the
ignore_functional_groups
list.from_bson
(serialized)Instantiate an object from a BSON serialized representation.
from_dict
(molecule_dict)Create a new Molecule from a dictionary representation
from_file
(file_path[, file_format, …])Create one or more molecules from a file
from_inchi
(inchi[, allow_undefined_stereo, …])Construct a Molecule from a InChI representation
from_iupac
(*args, **kwargs)Generate a molecule from IUPAC or common name
from_json
(serialized)Instantiate an object from a JSON serialized representation.
from_mapped_smiles
(mapped_smiles[, …])Create an openforcefield.topology.molecule.Molecule from a mapped SMILES made with cmiles.
from_messagepack
(serialized)Instantiate an object from a MessagePack serialized representation.
from_openeye
(*args, **kwargs)Create a Molecule from an OpenEye molecule.
from_pdb_and_smiles
(*args, **kwargs)Create a Molecule from a pdb file and a SMILES string using RDKit.
from_pickle
(serialized)Instantiate an object from a pickle serialized representation.
from_qcschema
(qca_record[, client, …])Create a Molecule from a QCArchive entry based on the cmiles information.
from_rdkit
(*args, **kwargs)Create a Molecule from an RDKit molecule.
from_smiles
(smiles[, …])Construct a Molecule from a SMILES representation
from_toml
(serialized)Instantiate an object from a TOML serialized representation.
from_topology
(topology)Return a Molecule representation of an openforcefield Topology containing a single Molecule object.
from_xml
(serialized)Instantiate an object from an XML serialized representation.
from_yaml
(serialized)Instantiate from a YAML serialized representation.
generate_conformers
([toolkit_registry, …])Generate conformers for this molecule using an underlying toolkit.
generate_unique_atom_names
()Generate unique atom names using element name and number of times that element has occurred e.g.
get_bond_between
(i, j)Returns the bond between two atoms
is_isomorphic_with
(other, **kwargs)Check if the molecule is isomorphic with the other molecule which can be an openforcefield.topology.Molecule, or TopologyMolecule or nx.Graph().
remap
(mapping_dict[, current_to_new])Remap all of the indexes in the molecule to match the given mapping dict
to_bson
()Return a BSON serialized representation.
to_dict
()Return a dictionary representation of the molecule.
to_file
(file_path, file_format[, …])Write the current molecule to a file or file-like object
to_hill_formula
(molecule)Generate the Hill formula from either a FrozenMolecule, TopologyMolecule or nx.Graph() of the molecule
to_inchi
([fixed_hydrogens, toolkit_registry])Create an InChI string for the molecule using the requested toolkit backend.
to_inchikey
([fixed_hydrogens, toolkit_registry])Create an InChIKey for the molecule using the requested toolkit backend.
to_iupac
(**kwargs)Generate IUPAC name from Molecule
to_json
([indent])Return a JSON serialized representation.
to_messagepack
()Return a MessagePack representation.
to_networkx
()Generate a NetworkX undirected graph from the Molecule.
to_openeye
(**kwargs)Create an OpenEye molecule
to_pickle
()Return a pickle serialized representation.
to_qcschema
([multiplicity, conformer, extras])Generate the qschema input format used to submit jobs to archive or run qcengine calculations locally, spec can be found here <https://molssi-qc-schema.readthedocs.io/en/latest/index.html>
to_rdkit
(**kwargs)Create an RDKit molecule
to_smiles
([isomeric, explicit_hydrogens, …])Return a canonical isomeric SMILES representation of the current molecule.
to_toml
()Return a TOML serialized representation.
to_topology
()Return an openforcefield Topology representation containing one copy of this molecule
to_xml
([indent])Return an XML representation.
to_yaml
()Return a YAML serialized representation.
Attributes
angles
Get an iterator over all i-j-k angles.
atoms
Iterate over all Atom objects.
bonds
Iterate over all Bond objects.
conformers
Returns the list of conformers for this molecule.
has_unique_atom_names
True if the molecule has unique atom names, False otherwise.
hill_formula
Get the Hill formula of the 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
Returns the number of conformers for this molecule.
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.