예제 #1
0
def iupac_to_oemol(iupac_name: str) -> oechem.OEMol:
    """
    Convert an IUPAC name to an OEMol with openeye

    Parameters
    ----------
    iupac_name : str
        The name of the molecule

    Returns
    -------
    mol : oechem.OEMol
        The OEMol corresponding to the IUPAC name with all hydrogens
    """
    mol = oechem.OEMol()
    oeiupac.OEParseIUPACName(mol, iupac_name)
    oechem.OEAddExplicitHydrogens(mol)

    # generate conformers:
    omega = oeomega.OEOmega()
    omega.SetStrictStereo(False)
    omega.SetMaxConfs(1)
    omega(mol)

    return mol
예제 #2
0
def test_partial_bondorder(verbose=False):
    """Test setup of a molecule which activates partial bond order code."""
    from openeye import oechem
    mol = oechem.OEMol()
    from openeye import oeiupac
    oeiupac.OEParseIUPACName(mol, 'benzene')
    positions = positions_from_oemol(mol)
    oechem.OETriposAtomNames(mol)
    topology = generateTopologyFromOEMol(mol)
    # Load forcefield from above
    ffxml = StringIO(ffxml_contents_noconstraints)
    ff = ForceField(ffxml)

    # Set up once using AM1BCC charges
    system = ff.createSystem(topology, [mol],
                             chargeMethod='OECharges_AM1BCCSym',
                             verbose=verbose)

    # Check that energy is what it ought to be -- the partial bond order
    # for benzene makes the energy a bit higher than it would be without it
    energy = get_energy(system, positions)
    if energy < 7.50 or energy > 7.60:
        raise Exception(
            "Partial bond order code seems to have issues, as energy for benzene is outside of tolerance in tests."
        )

    # Set up once also without asking for charges
    system = ff.createSystem(topology, [mol], verbose=verbose)
    energy = get_energy(system, positions)
    # Energy is lower with user supplied charges (which in this case are zero)
    if energy < 4.00 or energy > 6.0:
        raise Exception(
            "Partial bond order code seems to have issues when run with user-provided charges, as energy for benzene is out of tolerance in tests."
        )
예제 #3
0
파일: utils.py 프로젝트: CHEMPHY/perses
def createOEMolFromIUPAC(iupac_name='bosutinib'):
    from openeye import oechem, oeiupac, oeomega

    # Create molecule.
    mol = oechem.OEMol()
    oeiupac.OEParseIUPACName(mol, iupac_name)
    mol.SetTitle(iupac_name)

    # Assign aromaticity and hydrogens.
    oechem.OEAssignAromaticFlags(mol, oechem.OEAroModelOpenEye)
    oechem.OEAddExplicitHydrogens(mol)

    # Create atom names.
    oechem.OETriposAtomNames(mol)

    # Create bond types
    oechem.OETriposBondTypeNames(mol)

    # Assign geometry
    omega = oeomega.OEOmega()
    omega.SetMaxConfs(1)
    omega.SetIncludeInput(False)
    omega.SetStrictStereo(True)
    omega(mol)

    return mol
예제 #4
0
def create_molecule(name, filename):
    # Open output file.
    ofs = oechem.oemolostream()
    ofs.open(filename)

    # Create molecule.
    mol = oechem.OEMol()

    # Speculatively reorder CAS permuted index names
    str = oeiupac.OEReorderIndexName(name)
    if len(str) == 0:
        str = name

    done = oeiupac.OEParseIUPACName(mol, str)

    # Create conformation.
    omega = oeomega.OEOmega()
    omega.SetIncludeInput(False)  # don't include input
    omega.SetMaxConfs(1)  # set maximum number of conformations to 1
    omega(mol)

    # Set molecule name
    mol.SetTitle(name)

    # Write molecule.
    oechem.OEWriteMolecule(ofs, mol)

    # Close stream.
    ofs.close()

    return
예제 #5
0
        def _createMolecule(self, iupac_name):
            """Create molecule from IUPAC name.

            Best practices for creating initial coordinates can be applied here.

            Parameters
            ----------
            iupac_name : str
                IUPAC name

            Returns
            -------
            molecule : OEMol
                OEMol with 3D coordinates, but no charges

            """
            # Check cache
            if iupac_name in self._cached_molecules:
                return copy.deepcopy(self._cached_molecules[iupac_name])

            # Create molecule from IUPAC name.
            molecule = oechem.OEMol()
            if not oeiupac.OEParseIUPACName(molecule, iupac_name):
                raise ValueError(
                    "The supplied IUPAC name '%s' could not be parsed." %
                    iupac_name)

            # Set molecule name
            molecule.SetTitle(iupac_name)

            # Normalize molecule
            oechem.OEAssignAromaticFlags(molecule, oechem.OEAroModelOpenEye)
            oechem.OEAddExplicitHydrogens(molecule)
            oechem.OETriposAtomNames(molecule)

            # Create configuration
            omega = oeomega.OEOmega()
            omega.SetMaxConfs(1)
            omega.SetIncludeInput(False)
            omega.SetCanonOrder(False)
            omega.SetSampleHydrogens(True)
            omega.SetStrictStereo(True)
            omega.SetStrictAtomTypes(False)
            status = omega(molecule)
            if not status:
                raise (RuntimeError("omega returned error code %d" % status))

            # Cache molecule
            self._cached_molecules[iupac_name] = molecule

            return molecule
예제 #6
0
def generate_initial_molecule(iupac_name):
    """
    Generate an oemol with a geometry
    """
    mol = oechem.OEMol()
    oeiupac.OEParseIUPACName(mol, iupac_name)
    oechem.OEAddExplicitHydrogens(mol)
    oechem.OETriposAtomNames(mol)
    oechem.OETriposBondTypeNames(mol)
    omega = oeomega.OEOmega()
    omega.SetStrictStereo(False)
    omega.SetMaxConfs(1)
    omega(mol)
    return mol
예제 #7
0
def Nam2Mol(itf):
    ifp = sys.stdin
    if itf.GetString("-in") != "-":
        ifp = open(itf.GetString("-in"))

    ofs = oechem.oemolostream()
    if not ofs.open(itf.GetString("-out")):
        oechem.OEThrow.Fatal("Unable to open output file: %s" %
                             itf.GetString("-out"))

    language = oeiupac.OEGetIUPACLanguage(itf.GetString("-language"))
    charset = oeiupac.OEGetIUPACCharSet(itf.GetString("-charset"))

    mol = oechem.OEGraphMol()
    for name in ifp:
        name = name.strip()
        mol.Clear()

        # Speculatively reorder CAS permuted index names
        str = oeiupac.OEReorderIndexName(name)
        if len(str) == 0:
            str = name

        if charset == oeiupac.OECharSet_HTML:
            str = oeiupac.OEFromHTML(str)
        if charset == oeiupac.OECharSet_UTF8:
            str = oeiupac.OEFromUTF8(str)

        str = oeiupac.OELowerCaseName(str)

        if language != oeiupac.OELanguage_AMERICAN:
            str = oeiupac.OEFromLanguage(str, language)

        done = oeiupac.OEParseIUPACName(mol, str)

        if not done and itf.GetBool("-empty"):
            mol.Clear()
            done = True

        if done:
            if itf.HasString("-tag"):
                oechem.OESetSDData(mol, itf.GetString("-tag"), name)

            mol.SetTitle(name)
            oechem.OEWriteMolecule(ofs, mol)
예제 #8
0
파일: openeye.py 프로젝트: LaYeqa/perses
def iupac_to_oemol(iupac, title='MOL', max_confs=1):
    """
    Generate an oemol from an IUPAC name
    Parameters
    ----------
    iupac : str
        iupac name of molecule
    title : str, default 'MOL'
        title of OEMol molecule
    max_confs : int, default 1
        maximum number of conformers to generate
    Returns
    -------
    molecule : openeye.oechem.OEMol
        OEMol object of the molecule
    """
    from openeye import oeiupac, oeomega

    # Create molecule
    molecule = oechem.OEMol()
    oeiupac.OEParseIUPACName(molecule, iupac)

    # Set title.
    molecule.SetTitle(title)

    # Assign aromaticity and hydrogens.
    oechem.OEAssignAromaticFlags(molecule, oechem.OEAroModelOpenEye)
    oechem.OEAssignHybridization(molecule)
    oechem.OEAddExplicitHydrogens(molecule)
    oechem.OEPerceiveChiral(molecule)

    # Create atom names.
    oechem.OETriposAtomNames(molecule)
    oechem.OETriposBondTypeNames(molecule)

    # Assign geometry
    omega = oeomega.OEOmega()
    omega.SetMaxConfs(max_confs)
    omega.SetIncludeInput(False)
    omega.SetStrictStereo(True)
    omega(molecule)
    return molecule
예제 #9
0
molecules = {'BEN': 'benzene', 'TOL': 'toluene'}

from openeye import oechem
from openeye import oeomega
from openeye import oeiupac
from openeye import oequacpac

# Create molecules.
for resname in molecules:
    name = molecules[resname]
    print name

    # Create molecule from IUPAC name.
    molecule = oechem.OEMol()
    oeiupac.OEParseIUPACName(molecule, name)
    molecule.SetTitle(name)

    # Normalize molecule.
    oechem.OEAddExplicitHydrogens(molecule)
    oechem.OETriposAtomNames(molecule)
    oechem.OEAssignAromaticFlags(molecule, oechem.OEAroModelOpenEye)

    # Create configuration.
    omega = oeomega.OEOmega()
    omega.SetStrictStereo(True)
    omega.SetIncludeInput(False)
    omega(molecule)

    # Create charges.
    oequacpac.OEAssignPartialCharges(molecule, oequacpac.OECharges_AM1BCCSym)