ligands

Ligand

Small molecule object based on the OpenForceField toolkit.

Todo

Everything in this class

__init__(self, _provenance=None, name='', *args, **kwargs)

Show source code in core/ligands.py
19
20
21
    def __init__(self, _provenance=None, name="", *args, **kwargs):
        Molecule.__init__(self, *args, **kwargs)
        BaseLigand.__init__(self, name=name, _provenance=_provenance)

Create a new Molecule object

Parameters

other : optional, default=None If specified, attempt to construct a copy of the Molecule from the specified object. This can be any one of the following:

* a :class:`Molecule` object
* a file that can be used to construct a :class:`Molecule` object
* an ``openeye.oechem.OEMol``
* an ``rdkit.Chem.rdchem.Mol``
* a serialized :class:`Molecule` object

Examples

Create an empty molecule:

empty_molecule = Molecule()

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 = Molecule(sdf_filepath) molecule = Molecule(open(sdf_filepath, 'r'), file_format='sdf')

import gzip mol2_gz_filepath = get_data_file_path('molecules/toluene.mol2.gz') molecule = Molecule(gzip.GzipFile(mol2_gz_filepath, 'r'), file_format='mol2')

Create a molecule from another molecule:

molecule_copy = Molecule(molecule)

Convert to OpenEye OEMol object

oemol = molecule.to_openeye()

Create a molecule from an OpenEye molecule:

molecule = Molecule(oemol)

Convert to RDKit Mol object

rdmol = molecule.to_rdkit()

Create a molecule from an RDKit molecule:

molecule = Molecule(rdmol)

Create a molecule from a serialized molecule object:

serialized_molecule = molecule.getstate() molecule_copy = Molecule(serialized_molecule)

.. todo ::

  • If a filename or file-like object is specified but the file contains more than one molecule, what is the proper behavior? Read just the first molecule, or raise an exception if more than one molecule is found?

  • Should we also support SMILES strings or IUPAC names for other?

from_smiles(smiles, name=None, **kwargs) (classmethod)

Show source code in core/ligands.py
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
    @classmethod
    def from_smiles(cls, smiles, name=None, **kwargs):  # pylint: disable=arguments-differ
        """
        Same as `openforcefield.topology.Molecule`, but adding
        information about the original SMILES to `._provenance` dict.

        !!! todo
            Inheritance from these methods in OFF is broken because they
            delegate directly to the underlying toolkits, and type is
            lost on the way, so we will always obtain an
            openforcefield.topology.Molecule, no matter what.

            PR #583 has been submitted to patch upstream
        """
        self = super().from_smiles(smiles, **kwargs)
        if name is None:
            name = smiles
        super().__init__(self, name=name, _provenance={"smiles": smiles})
        return self

Same as openforcefield.topology.Molecule, but adding information about the original SMILES to ._provenance dict.

Todo

Inheritance from these methods in OFF is broken because they delegate directly to the underlying toolkits, and type is lost on the way, so we will always obtain an openforcefield.topology.Molecule, no matter what.

PR #583 has been submitted to patch upstream

to_dict(self)

Show source code in core/ligands.py
43
44
45
46
    def to_dict(self):
        d = super().to_dict()
        d["_provenance"] = self._provenance.copy()
        return d

Return a dictionary representation of the molecule.

.. todo ::

  • Document the representation standard.
  • How do we do version control with this standard?

Returns

molecule_dict : OrderedDict A dictionary representation of the molecule.


Last update: April 24, 2020