Example #1
0
def get_ani_mol(coordinates, species, smiles):
    """ Given smiles string and list of elements as reference,
    get the RDKit mol with xyz.

    """

    mol = oechem.OEGraphMol()

    for symbol in species:
        mol.NewAtom(getattr(oechem, 'OEElemNo_' + symbol))

    mol.SetCoords(coordinates.reshape([-1]))
    mol.SetDimension(3)
    oechem.OEDetermineConnectivity(mol)
    oechem.OEFindRingAtomsAndBonds(mol)
    oechem.OEPerceiveBondOrders(mol)

    smiles_can = oechem.OECreateCanSmiString(mol)

    ims = oechem.oemolistream()
    ims.SetFormat(oechem.OEFormat_SMI)
    ims.openstring(smiles)
    mol_ref = next(ims.GetOEMols())
    smiles_ref = oechem.OECreateCanSmiString(mol_ref)

    assert smiles_can == smiles_ref

    g = hgfp.graph.from_oemol(mol, use_fp=True)

    return g, mol
Example #2
0
    def descriptorToMol(self,
                        descr,
                        descrType,
                        limitPerceptions=False,
                        messageTag=None):
        """Parse the input descriptor string and return a molecule object (OeGraphMol/OeQMol).

        Args:
            descr (str): descriptor
            descrType (str): descriptor type
            limitPerceptions (bool): flag to limit the perceptions/transformations of input descriptor
            messageTag (srt, optional): prefix string for error messages. Defaults to None.

        Returns:
            object: OeGraphMol()/OeQmol() object or None for failure

            ifs.SetFlavor(oechem.OEFormat_PDB, oechem.OEIFlavor_PDB_Default | oechem.OEIFlavor_PDB_DATA | oechem.OEIFlavor_PDB_ALTLOC)  # noq
        """
        try:
            if "SMILES" in descrType.upper() and "ISO" in descrType.upper():
                oeMol = self.smilesToMol(descr,
                                         limitPerceptions=limitPerceptions,
                                         messageTag=messageTag)
                if oeMol:
                    isoSmiles = oechem.OECreateIsoSmiString(oeMol)
                    return self.smilesToMol(isoSmiles,
                                            limitPerceptions=limitPerceptions,
                                            messageTag=messageTag)
                else:
                    return None
            if "SMILES" in descrType.upper():
                oeMol = self.smilesToMol(descr,
                                         limitPerceptions=limitPerceptions,
                                         messageTag=messageTag)
                if oeMol:
                    smiles = oechem.OECreateCanSmiString(oeMol)
                    return self.smilesToMol(smiles,
                                            limitPerceptions=limitPerceptions,
                                            messageTag=messageTag)
                else:
                    return None
            elif "INCHI" in descrType.upper():
                oeMol = self.inchiToMol(descr,
                                        limitPerceptions=limitPerceptions,
                                        messageTag=messageTag)
                if oeMol:
                    isoSmiles = oechem.OECreateIsoSmiString(oeMol)
                    return self.smilesToMol(isoSmiles,
                                            limitPerceptions=limitPerceptions,
                                            messageTag=messageTag)
            elif "SMARTS" in descrType.upper():
                return self.smartsToQmol(descr, messageTag=messageTag)
            else:
                return None
        except Exception as e:
            logger.exception("Failing with %s", str(e))
        return None
Example #3
0
 def __makeChemCompDescriptorCategory(self, ccId, oeMol):
     """
         loop_
         _pdbx_chem_comp_descriptor.comp_id
         _pdbx_chem_comp_descriptor.type
         _pdbx_chem_comp_descriptor.program
         _pdbx_chem_comp_descriptor.program_version
         _pdbx_chem_comp_descriptor.descriptor
         ARG SMILES           ACDLabs              10.04 "O=C(O)C(N)CCCNC(=[NH2+])N"
         ARG SMILES_CANONICAL CACTVS               3.341 "N[C@@H](CCCNC(N)=[NH2+])C(O)=O"
         ARG SMILES           CACTVS               3.341 "N[CH](CCCNC(N)=[NH2+])C(O)=O"
         ARG SMILES_CANONICAL "OpenEye OEToolkits" 1.5.0 "C(C[C@@H](C(=O)O)N)CNC(=[NH2+])N"
         ARG SMILES           "OpenEye OEToolkits" 1.5.0 "C(CC(C(=O)O)N)CNC(=[NH2+])N"
         ARG InChI            InChI                1.03  "InChI=1S/C6H14N4O2/c7-4(5(11)12)2-1-3-1..... "
         ARG InChIKey         InChI                1.03  ODKSFYDXXFIFQN-BYPYZUCNSA-O
     #
     """
     rowL = []
     #
     aRow = {}
     aRow["comp_id"] = ccId
     aRow["type"] = "SMILES_CANONICAL"
     aRow["program"] = "OpenEye OEToolkits"
     aRow["program_version"] = self.__oeVersion
     aRow["descriptor"] = oechem.OECreateIsoSmiString(oeMol)
     rowL.append(aRow)
     #
     aRow = {}
     aRow["comp_id"] = ccId
     aRow["type"] = "SMILES"
     aRow["program"] = "OpenEye OEToolkits"
     aRow["program_version"] = self.__oeVersion
     aRow["descriptor"] = oechem.OECreateCanSmiString(oeMol)
     rowL.append(aRow)
     #
     aRow = {}
     aRow["comp_id"] = ccId
     aRow["type"] = "InChI"
     aRow["program"] = "OpenEye OEToolkits"
     aRow["program_version"] = self.__oeVersion
     aRow["descriptor"] = oechem.OECreateInChI(oeMol)
     rowL.append(aRow)
     #
     aRow = {}
     aRow["comp_id"] = ccId
     aRow["type"] = "InChIKey"
     aRow["program"] = "OpenEye OEToolkits"
     aRow["program_version"] = self.__oeVersion
     aRow["descriptor"] = oechem.OECreateInChIKey(oeMol)
     rowL.append(aRow)
     #
     return rowL
Example #4
0
 def serializeOe(self, oeMol):
     """Create a string representing the content of the current OE molecule.   This
     serialization uses the OE internal binary format.
     """
     try:
         oms = oechem.oemolostream()
         oms.SetFormat(oechem.OEFormat_OEB)
         oms.openstring()
         oechem.OEWriteMolecule(oms, oeMol)
         logger.debug("SMILES %s", oechem.OECreateCanSmiString(oeMol))
         logger.debug("Atoms = %d", oeMol.NumAtoms())
         return oms.GetString()
     except Exception as e:
         logger.exception("Failing with %s", str(e))
Example #5
0
    def test_atom_map(self):
        """Test get atom map"""
        from openeye import oechem
        tagged_smiles = '[H:5][C:1]#[N+:4][C:3]([H:9])([H:10])[C:2]([H:6])([H:7])[H:8]'
        mol_1 = openeye.smiles_to_oemol('CC[N+]#C')
        inf = get_fn('ethylmethylidyneamonium.mol2')
        ifs = oechem.oemolistream(inf)
        mol_2 = oechem.OEMol()
        oechem.OEReadMolecule(ifs, mol_2)

        atom_map = utils.get_atom_map(tagged_smiles, mol_1)

        for i, mapping in enumerate(atom_map):
            atom_1 = mol_1.GetAtom(oechem.OEHasAtomIdx(atom_map[mapping]))
            atom_1.SetAtomicNum(i + 1)
            atom_2 = mol_2.GetAtom(oechem.OEHasAtomIdx(mapping - 1))
            atom_2.SetAtomicNum(i + 1)
            self.assertEqual(oechem.OECreateCanSmiString(mol_1),
                             oechem.OECreateCanSmiString(mol_2))

        # Test aromatic molecule
        tagged_smiles = '[H:10][c:4]1[c:3]([c:2]([c:1]([c:6]([c:5]1[H:11])[H:12])[C:7]([H:13])([H:14])[H:15])[H:8])[H:9]'
        mol_1 = openeye.smiles_to_oemol('Cc1ccccc1')
        inf = get_fn('toluene.mol2')
        ifs = oechem.oemolistream(inf)
        mol_2 = oechem.OEMol()
        oechem.OEReadMolecule(ifs, mol_2)

        atom_map = utils.get_atom_map(tagged_smiles, mol_1)
        for i, mapping in enumerate(atom_map):
            atom_1 = mol_1.GetAtom(oechem.OEHasAtomIdx(atom_map[mapping]))
            atom_1.SetAtomicNum(i + 1)
            atom_2 = mol_2.GetAtom(oechem.OEHasAtomIdx(mapping - 1))
            atom_2.SetAtomicNum(i + 1)
            self.assertEqual(oechem.OECreateCanSmiString(mol_1),
                             oechem.OECreateCanSmiString(mol_2))
Example #6
0
    def get_d3rmolecule(self, source):
        """Gets D3RMolecule from `source`
        """
        openeye_mol = self._get_molecule_from_openeye(source)
        d3ratoms = []
        for atom in openeye_mol.GetAtoms():
            d3ratom = D3RAtom()
            d3ratom.set_atomic_name(atom.GetName())
            d3ratom.set_atomic_number(atom.GetAtomicNum())
            d3ratom.set_is_hydrogen(atom.IsHydrogen())
            d3ratoms.append(d3ratom)

        d3rmol = D3RMolecule()
        d3rmol.set_atoms(d3ratoms)
        smi_str = oechem.OECreateCanSmiString(openeye_mol)
        d3rmol.set_canonical_smiles_str(smi_str)
        return d3rmol
Example #7
0
    def descriptorToSmiles(self,
                           descr,
                           descrType,
                           limitPerceptions=False,
                           messageTag=None):
        """Parse the input descriptor string and return an OE smiles.

        Args:
            descr (str): descriptor
            descrType (str): descriptor type
            limitPerceptions (bool): flag to limit the perceptions/transformations of input descriptor
            messageTag (srt, optional): prefix string for error messages. Defaults to None.

        Returns:
            str: SMILES string
        """
        try:
            if "SMILES" in descrType.upper() and "ISO" in descrType.upper():
                oeMol = self.smilesToMol(descr,
                                         limitPerceptions=limitPerceptions,
                                         messageTag=messageTag)
                if oeMol:
                    return oechem.OECreateIsoSmiString(oeMol)
                else:
                    return None
            if "SMILES" in descrType.upper():
                oeMol = self.smilesToMol(descr,
                                         limitPerceptions=limitPerceptions,
                                         messageTag=messageTag)
                if oeMol:
                    return oechem.OECreateCanSmiString(oeMol)
                else:
                    return None
            elif "INCHI" in descrType.upper():
                oeMol = self.inchiToMol(descr,
                                        limitPerceptions=limitPerceptions,
                                        messageTag=messageTag)
                if oeMol:
                    return oechem.OECreateIsoSmiString(oeMol)
            else:
                return None
        except Exception as e:
            logger.exception("Failing with %s", str(e))
        return None
Example #8
0
    def standardizeSmiles(self, smiles, type="ISOMERIC"):  # pylint: disable=redefined-builtin
        """ Return a standardized SMILES (type) or None
        """
        smilesOut = None
        try:
            mol = oechem.OEGraphMol()
            if (oechem.OEParseSmiles(mol, smiles) == 1):
                oechem.OEAssignAromaticFlags(mol)
                if type == "CANNONICAL":
                    smilesOut = oechem.OECreateCanSmiString(mol)
                elif type == "ISOMERIC":
                    smilesOut = oechem.OECreateIsoSmiString(mol)
            else:
                logger.error("Unable to parse input SMILES '%s'", smiles)

        except Exception as e:
            logger.exception("Error '%s' occured. Arguments %s.", str(e), e.args)

        return smilesOut
Example #9
0
    def deserializeOe(self, oeS):
        """Reconstruct an OE molecule from the input string serialization (OE binary).

        The deserialized molecule is used to initialize the internal OE molecule
        within this object.

        Returns:
            list:  OE GraphMol list
        """
        molList = []
        try:
            ims = oechem.oemolistream()
            ims.SetFormat(oechem.OEFormat_OEB)
            ims.openstring(oeS)
            for mol in ims.GetOEGraphMols():
                logger.debug("SMILES %s", oechem.OECreateCanSmiString(mol))
                logger.debug("title  %s", mol.GetTitle())
                logger.debug("atoms  %d", mol.NumAtoms())
                molList.append(oechem.OEGraphMol(mol))
        except Exception as e:
            logger.exception("Failing with %s", str(e))
        return molList
Example #10
0
def PerceiveAromaticity(mol, modelname, aromodel):
    oechem.OEAssignAromaticFlags(mol, aromodel)
    cansmi = oechem.OECreateCanSmiString(mol)
    print(modelname, ":", cansmi)
Example #11
0
 def smiles(self):                                     
     """                                               
     Returns a SMILES string for this structure.       
     """                                               
     return oechem.OECreateCanSmiString(self._struc)   
    topology.setPeriodicBoxVectors(system.getDefaultPeriodicBoxVectors())

    ifs = oechem.oemolistream()
    ifs.open(ligand_filename)

    # get the list of molecules
    mol_list = [oechem.OEMol(mol) for mol in ifs.GetOEMols()]

    for idx, mol in enumerate(mol_list):
        mol.SetTitle("MOL{}".format(idx))
        oechem.OETriposAtomNames(mol)

    initial_mol = mol_list[initial_ligand]
    proposal_mol = mol_list[proposal_ligand]
    proposal_smiles = SmallMoleculeSetProposalEngine.canonicalize_smiles(
        oechem.OECreateCanSmiString(proposal_mol))
    current_smiles = SmallMoleculeSetProposalEngine.canonicalize_smiles(
        oechem.OECreateCanSmiString(initial_mol))

    barostat = openmm.MonteCarloBarostat(1.0 * unit.atmosphere, temperature,
                                         50)

    system_generator = SystemGenerator(
        [
            'amber14/protein.ff14SB.xml', 'gaff.xml', 'amber14/tip3p.xml',
            'MCL1_ligands.xml'
        ],
        barostat=barostat,
        forcefield_kwargs={
            'nonbondedMethod': app.PME,
            'constraints': app.HBonds,
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of OpenEye products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. OpenEye claims no rights to Customer's
# modifications. Modification of Sample Code is at Customer's sole and
# exclusive risk. Sample Code may require Customer to have a then
# current license or subscription to the applicable OpenEye offering.
# THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall OpenEye be
# liable for any damages or liability in connection with the Sample Code
# or its use.

# @ <SNIPPET>
from __future__ import print_function
from openeye import oechem
import sys

mol = oechem.OEGraphMol()
for smi in sys.stdin:
    mol.Clear()
    smi = smi.strip()
    if oechem.OEParseSmiles(mol, smi):
        oechem.OEAssignAromaticFlags(mol)
        print(oechem.OECreateCanSmiString(mol))
    else:
        oechem.OEThrow.Warning("%s is an invalid SMILES!" % smi)
# @ </SNIPPET>
#!/usr/bin/env python
# (C) 2017 OpenEye Scientific Software Inc. All rights reserved.
#
# TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
# provided to current licensees or subscribers of OpenEye products or
# SaaS offerings (each a "Customer").
# Customer is hereby permitted to use, copy, and modify the Sample Code,
# subject to these terms. OpenEye claims no rights to Customer's
# modifications. Modification of Sample Code is at Customer's sole and
# exclusive risk. Sample Code may require Customer to have a then
# current license or subscription to the applicable OpenEye offering.
# THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED.  OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall OpenEye be
# liable for any damages or liability in connection with the Sample Code
# or its use.

# @ <SNIPPET>
from __future__ import print_function
from openeye import oechem

mol = oechem.OEGraphMol()
oechem.OEParseSmiles(mol, "n1ccncc1")

print("Canonical smiles :", oechem.OECreateCanSmiString(mol))
oechem.OEClearAromaticFlags(mol)
oechem.OEKekulize(mol)
print("Kekule smiles    :", oechem.OECreateCanSmiString(mol))
# @ </SNIPPET>
Example #15
0
def infer_mol_from_coordinates(
    coordinates,
    species,
    smiles_ref=None,
    coordinates_unit="angstrom",
):

    # local import
    from openeye import oechem
    from simtk import unit
    from simtk.unit import Quantity

    if isinstance(coordinates_unit, str):
        coordinates_unit = getattr(unit, coordinates_unit)

    # make sure we have the coordinates
    # in the unit system
    coordinates = Quantity(coordinates, coordinates_unit).value_in_unit(
        unit.angstrom  # to make openeye happy
    )

    # initialize molecule
    mol = oechem.OEGraphMol()

    if all(isinstance(symbol, str) for symbol in species):
        [
            mol.NewAtom(getattr(oechem, "OEElemNo_" + symbol))
            for symbol in species
        ]

    elif all(isinstance(symbol, int) for symbol in species):
        [
            mol.NewAtom(
                getattr(oechem,
                        "OEElemNo_" + oechem.OEGetAtomicSymbol(symbol)))
            for symbol in species
        ]

    else:
        raise RuntimeError(
            "The species can only be all strings or all integers.")

    mol.SetCoords(coordinates.reshape([-1]))
    mol.SetDimension(3)
    oechem.OEDetermineConnectivity(mol)
    oechem.OEFindRingAtomsAndBonds(mol)
    oechem.OEPerceiveBondOrders(mol)

    if smiles_ref is not None:
        smiles_can = oechem.OECreateCanSmiString(mol)
        ims = oechem.oemolistream()
        ims.SetFormat(oechem.OEFormat_SMI)
        ims.openstring(smiles_ref)
        mol_ref = next(ims.GetOEMols())
        smiles_ref = oechem.OECreateCanSmiString(mol_ref)
        assert (smiles_ref == smiles_can
                ), "SMILES different. Input is %s, ref is %s" % (
                    smiles_can,
                    smiles_ref,
                )

    from openff.toolkit.topology import Molecule

    _mol = Molecule.from_openeye(mol, allow_undefined_stereo=True)
    g = esp.Graph(_mol)

    return g
Example #16
0
    topology = topology.to_openmm()
    topology.setPeriodicBoxVectors(system.getDefaultPeriodicBoxVectors())

    ifs = oechem.oemolistream()
    ifs.open(ligand_filename)

    # get the list of molecules
    mol_list = [oechem.OEMol(mol) for mol in ifs.GetOEMols()]

    for idx, mol in enumerate(mol_list):
        mol.SetTitle("MOL{}".format(idx))
        oechem.OETriposAtomNames(mol)

    initial_mol = mol_list[initial_ligand]
    proposal_mol = mol_list[proposal_ligand]
    proposal_smiles = SmallMoleculeSetProposalEngine.canonicalize_smiles(oechem.OECreateCanSmiString(proposal_mol))
    current_smiles = SmallMoleculeSetProposalEngine.canonicalize_smiles(oechem.OECreateCanSmiString(initial_mol))

    barostat = openmm.MonteCarloBarostat(1.0*unit.atmosphere, temperature, 50)

    system_generator = SystemGenerator(['amber14/protein.ff14SB.xml', 'gaff.xml', 'amber14/tip3p.xml', 'MCL1_ligands.xml'], barostat=barostat, forcefield_kwargs={'constraints': app.HBonds,
                                                               'hydrogenMass': 4 * unit.amus}, periodic_forcefield_kwargs={'nonbondedMethod': app.PME} use_antechamber=False)

    atom_mapper_filename = os.path.join(setup_directory, "{}_atom_mapper.json".format(project_prefix))
    with open(atom_mapper_filename, 'r') as infile:
        atom_mapper = SmallMoleculeAtomMapper.from_json(infile.read())

    proposal_engine = PremappedSmallMoleculeSetProposalEngine(atom_mapper, system_generator)

    topology_proposal = proposal_engine.propose(system, topology, current_smiles=current_smiles, proposed_mol=proposal_mol, map_index=map_index)