Пример #1
0
def main(args):
    if len(args) != 2:
        oechem.OEThrow.Usage("%s <initial guess>" % args[0])

    x = oechem.OEDoubleArray(1)
    try:
        x[0] = float(args[1])
    except ValueError:
        oechem.OEThrow.Usage("%s <initial guess (expecting a number)>" %
                             args[0])

    func = Function()

    # Calculate function value at given x
    value = func(x)
    oechem.OEThrow.Info("Function value at x = %d is %d" % (x[0], value))

    # Optimize function using BFGS Optimizer and checkpoint
    xOpt = oechem.OEDoubleArray(1)
    optimizer = oeff.OEBFGSOpt()
    value = optimizer(func, ChkPt(), x, xOpt)
    oechem.OEThrow.Info(
        "Function has a minimia at x = %d and the minimum value is %d" %
        (xOpt[0], value))

    return 0
Пример #2
0
    def minimize(self, mol):
        oechem.OEAddExplicitHydrogens(mol)
        if (not self.mmff.PrepMol(mol)) or (not self.mmff.Setup(mol)):
            oechem.OEThrow.Warning("Unable to process molecule: title = '%s'" %
                                   mol.GetTitle())
            return None

        adaptor = oeff.OEQuatAdaptor(self.mmff, False, False)
        if not adaptor.Setup(mol):
            oechem.OEThrow.Warning(
                "Unable to process subset for molecule: title = '%s'" %
                mol.GetTitle())
            return None

        vecCoords = oechem.OEDoubleArray(3 * mol.GetMaxAtomIdx())
        mol.GetCoords(vecCoords)

        vecX = oechem.OEDoubleArray(adaptor.NumVar())
        adaptor.GetVar(vecX, vecCoords)

        initial_energy = adaptor(vecX)

        optimizer = oeff.OEBFGSOpt()
        final_energy = optimizer(adaptor, vecX, vecX)

        adaptor.AdaptVar(vecCoords, vecX)
        mol.SetCoords(vecCoords)

        return initial_energy, final_energy
def main(args):
    if len(args) != 2:
        oechem.OEThrow.Usage("%s <input>" % args[0])

    ifs = oechem.oemolistream()
    if not ifs.open(args[1]):
        oechem.OEThrow.Fatal("Unable to open %s for reading" % args[1])

    mol = oechem.OEGraphMol()
    while oechem.OEReadMolecule(ifs, mol):
        oechem.OEAddExplicitHydrogens(mol)

        mmff = oeff.OEMMFF()
        if not mmff.PrepMol(mol) or not mmff.Setup(mol):
            oechem.OEThrow.Warning("Unable to process molecule: title = '%s'" %
                                   mol.GetTitle())
            continue

        # print out interactions
        vecCoords = oechem.OEDoubleArray(3 * mol.GetMaxAtomIdx())
        mol.GetCoords(vecCoords)
        oechem.OEThrow.Info("Molecule: %s" % mol.GetTitle())
        for intc in mmff.GetInteractions(mol, vecCoords):
            vecGrads = oechem.OEDoubleArray(intc.NumValues())
            oechem.OEThrow.Info("Interaction: %s Value: %d" %
                                (intc.GetName(), intc.GetValues(vecGrads)))

            for atom in intc.GetAtoms():
                oechem.OEThrow.Info("Atom index: %d" % atom.GetIdx())

    return 0
Пример #4
0
 def __call__(self, x, h=None, g=None):
     if isinstance(x, oechem.OEDoubleArray):
         if g is not None:
             g[0] = 2.0 * x[0] - 7.0  # gradient
             h[0] = 2.0  # hessien
             return True
         elif h is not None:
             h[0] = 2.0 * x[0] - 7.0  # gradient
             return x[0] * x[0] - 7 * x[0] + 63
         else:
             return x[0] * x[0] - 7 * x[0] + 63
     else:
         x1 = oechem.OEDoubleArray(x, self.NumVar(), False)
         if g is not None:
             g1 = oechem.OEDoubleArray(g, self.NumVar(), False)
             g1[0] = 2.0 * x1[0] - 7.0
             h1 = oechem.OEDoubleArray(h, self.NumVar(), False)
             h1[0] = 2.0
             return True
         elif h is not None:
             h1 = oechem.OEDoubleArray(h, self.NumVar(), False)
             h1[0] = 2.0 * x1[0] - 7.0
             return x1[0] * x1[0] - 7 * x1[0] + 63
         else:
             return x1[0] * x1[0] - 7 * x1[0] + 63
Пример #5
0
def main(args):
    if len(args) != 3:
        oechem.OEThrow.Usage("%s <input> <output>" % args[0])

    ifs = oechem.oemolistream()
    if not ifs.open(args[1]):
        oechem.OEThrow.Fatal("Unable to open %s for reading" % args[1])

    ofs = oechem.oemolostream()
    if not ofs.open(args[2]):
        oechem.OEThrow.Fatal("Unable to open %s for writing" % args[2])

    mmff = oeff.OEMMFF()

    # Setup adaptor. The first (false) means not to pass ownership of mmff,
    # and the second (false) means not to exclude interactions related
    # to the subset which would be fixed for calculations.
    adaptor = oeff.OETorAdaptor(mmff, False, False)

    # Use a simple predicate for the subset of torsions to optimize
    adaptor.Set(oechem.OEIsRotor())

    mol = oechem.OEMol()
    while oechem.OEReadMolecule(ifs, mol):
        oechem.OEAddExplicitHydrogens(mol)

        # Use a simple atoms predicate for the subset, followed by setup
        if (not mmff.PrepMol(mol)) or (not adaptor.Setup(mol)):
            oechem.OEThrow.Warning("Unable to process molecule: title = '%s'" % mol.GetTitle())
            oechem.OEWriteMolecule(ofs, mol)
            continue

        vecCoords = oechem.OEDoubleArray(3*mol.GetMaxAtomIdx())
        for conf in mol.GetConfs():
            oechem.OEThrow.Info("Molecule: %s Conformer: %d" % (mol.GetTitle(), conf.GetIdx()+1))
            conf.GetCoords(vecCoords)

            # Get adaptor variables set corresponding to the coordinates
            vecX = oechem.OEDoubleArray(adaptor.NumVar())
            adaptor.GetVar(vecX, vecCoords)

            # Calculate energy using adaptor
            energy = adaptor(vecX)
            oechem.OEThrow.Info("Initial energy: %d kcal/mol" % energy)

            # Optimize the adaptor
            optimizer = oeff.OEBFGSOpt()
            energy = optimizer(adaptor, vecX, vecX)
            oechem.OEThrow.Info("Optimized energy: %d kcal/mol" % energy)

            # Get optimized coordinates corresponding to the adaptor optimized variables
            adaptor.AdaptVar(vecCoords, vecX)
            conf.SetCoords(vecCoords)

        oechem.OEWriteMolecule(ofs, mol)

    return 0
Пример #6
0
def main(argv=[__name__]):
    itf = oechem.OEInterface(InterfaceData, argv)

    if not itf.GetBool("-verbose"):
        oechem.OEThrow.SetLevel(oechem.OEErrorLevel_Warning)

    rfname = itf.GetString("-ref")
    ifname = itf.GetString("-in")

    automorph = itf.GetBool("-automorph")
    heavy = itf.GetBool("-heavyonly")
    overlay = itf.GetBool("-overlay")

    ifs = oechem.oemolistream()
    if not ifs.open(rfname):
        oechem.OEThrow.Fatal("Unable to open %s for reading" % rfname)

    rmol = oechem.OEGraphMol()
    if not oechem.OEReadMolecule(ifs, rmol):
        oechem.OEThrow.Fatal("Unable to read reference molecule")

    ifs = oechem.oemolistream()
    if not ifs.open(ifname):
        oechem.OEThrow.Fatal("Unable to open %s for reading" % ifname)

    ofs = oechem.oemolostream()
    if itf.HasString("-out"):
        ofname = itf.GetString("-out")
        if not ofs.open(ofname):
            oechem.OEThrow.Fatal("Unable to open %s for writing" % ofname)
        if not overlay:
            oechem.OEThrow.Warning(
                "Output is the same as input when overlay is false")

    for mol in ifs.GetOEMols():
        oechem.OEThrow.Info(mol.GetTitle())

        rmsds = oechem.OEDoubleArray(mol.GetMaxConfIdx())
        rmtx = oechem.OEDoubleArray(9 * mol.GetMaxConfIdx())
        tmtx = oechem.OEDoubleArray(3 * mol.GetMaxConfIdx())

        # perform RMSD for all confomers
        oechem.OERMSD(rmol, mol, rmsds, automorph, heavy, overlay, rmtx, tmtx)

        for conf in mol.GetConfs():
            cidx = conf.GetIdx()
            oechem.OEThrow.Info("Conformer %i : rmsd = %f" %
                                (cidx, rmsds[cidx]))

            if itf.GetBool("-overlay"):
                oechem.OERotate(conf, rmtx[cidx * 9:cidx * 9 + 9])
                oechem.OETranslate(conf, tmtx[cidx * 3:cidx * 3 + 3])

        if itf.HasString("-out"):
            oechem.OEWriteMolecule(ofs, mol)

    return 0
Пример #7
0
def OERMSD_Array(refcrds, fitcrds, size):
    oechem.OERMSD(refcrds, fitcrds, size)

    overlay = True
    oechem.OERMSD(refcrds, fitcrds, size, overlay)

    rotmat = oechem.OEDoubleArray(9)
    oechem.OERMSD(refcrds, fitcrds, size, overlay, rotmat)

    transvec = oechem.OEDoubleArray(3)
    oechem.OERMSD(refcrds, fitcrds, size, overlay, rotmat, transvec)
Пример #8
0
 def __call__(self, coord, grad=None):
     energy = 0.0
     if isinstance(coord, oechem.OEDoubleArray):
         if grad is not None:
             for i in range(0, self.natoms):
                 grad[3 * i] += 2.0 * coord[3 * i]  # x gradient
                 grad[3 * i + 1] += 2.0 * coord[3 * i + 1]  # y gradient
                 grad[3 * i + 2] += 2.0 * coord[3 * i + 2]  # z gradient
                 energy += coord[3 * i] * coord[3 *
                                                i]  # x distance from zero
                 energy += coord[3 * i +
                                 1] * coord[3 * i +
                                            1]  # y distance from zero
                 energy += coord[3 * i +
                                 2] * coord[3 * i +
                                            2]  # z distance from zero
         else:
             for i in range(0, self.natoms):
                 energy += coord[3 * i] * coord[3 *
                                                i]  # x distance from zero
                 energy += coord[3 * i +
                                 1] * coord[3 * i +
                                            1]  # y distance from zero
                 energy += coord[3 * i +
                                 2] * coord[3 * i +
                                            2]  # z distance from zero
     else:
         coord1 = oechem.OEDoubleArray(coord, self.NumVar(), False)
         if grad is not None:
             grad1 = oechem.OEDoubleArray(grad, self.NumVar(), False)
             for i in range(0, self.natoms):
                 grad1[3 * i] += 2.0 * coord1[3 * i]  # x gradient
                 grad1[3 * i + 1] += 2.0 * coord1[3 * i + 1]  # y gradient
                 grad1[3 * i + 2] += 2.0 * coord1[3 * i + 2]  # z gradient
                 energy += coord1[3 * i] * coord1[3 *
                                                  i]  # x distance from zero
                 energy += coord1[3 * i +
                                  1] * coord1[3 * i +
                                              1]  # y distance from zero
                 energy += coord1[3 * i +
                                  2] * coord1[3 * i +
                                              2]  # z distance from zero
         else:
             for i in range(0, self.natoms):
                 energy += coord1[3 * i] * coord1[3 *
                                                  i]  # x distance from zero
                 energy += coord1[3 * i +
                                  1] * coord1[3 * i +
                                              1]  # y distance from zero
                 energy += coord1[3 * i +
                                  2] * coord1[3 * i +
                                              2]  # z distance from zero
     return energy
Пример #9
0
def CliqueAlign(refmol, fitmol, ofs):
    cs = oechem.OECliqueSearch(refmol, oechem.OEExprOpts_DefaultAtoms,
                               oechem.OEExprOpts_DefaultBonds)
    cs.SetSaveRange(5)
    cs.SetMinAtoms(6)
    for mi in cs.Match(fitmol):
        rmat = oechem.OEDoubleArray(9)
        trans = oechem.OEDoubleArray(3)
        overlay = True
        oechem.OERMSD(cs.GetPattern(), fitmol, mi, overlay, rmat, trans)
        oechem.OERotate(fitmol, rmat)
        oechem.OETranslate(fitmol, trans)
        oechem.OEWriteMolecule(ofs, fitmol)
Пример #10
0
def OERMSD_Part_MolBase(ref, fit):
    match = oechem.OEMatch()
    for aRef, aFit in zip(ref.GetAtoms(), fit.GetAtoms()):
        match.AddPair(aRef, aFit)

    oechem.OERMSD(ref, fit, match)

    overlay = True
    oechem.OERMSD(ref, fit, match, overlay)

    rotmat = oechem.OEDoubleArray(9)
    oechem.OERMSD(ref, fit, match, overlay, rotmat)

    transvec = oechem.OEDoubleArray(3)
    oechem.OERMSD(ref, fit, match, overlay, rotmat, transvec)
Пример #11
0
def SmartsAlign(refmol, fitmol, ss, ofs):
    unique = True
    for match1 in ss.Match(refmol, unique):
        for match2 in ss.Match(fitmol, unique):
            match = oechem.OEMatch()
            for mp1, mp2 in zip(match1.GetAtoms(), match2.GetAtoms()):
                match.AddPair(mp1.target, mp2.target)

            overlay = True
            rmat = oechem.OEDoubleArray(9)
            trans = oechem.OEDoubleArray(3)
            oechem.OERMSD(refmol, fitmol, match, overlay, rmat, trans)
            oechem.OERotate(fitmol, rmat)
            oechem.OETranslate(fitmol, trans)
            oechem.OEWriteConstMolecule(ofs, fitmol)
Пример #12
0
 def __call__(self, x, g=None):
     if isinstance(x, oechem.OEDoubleArray):
         if g is not None:
             g[0] = 2.0 * x[0] - 7.0
             return x[0] * x[0] - 7 * x[0] + 63
         else:
             return x[0] * x[0] - 7 * x[0] + 63
     else:
         x1 = oechem.OEDoubleArray(x, self.NumVar(), False)
         if g is not None:
             g1 = oechem.OEDoubleArray(g, self.NumVar(), False)
             g1[0] = 2.0 * x1[0] - 7.0
             return x1[0] * x1[0] - 7 * x1[0] + 63
         else:
             return x1[0] * x1[0] - 7 * x1[0] + 63
Пример #13
0
def main(args):
    if len(args) != 2:
        oechem.OEThrow.Usage("%s <input>" % args[0])

    ifs = oechem.oemolistream()
    if not ifs.open(args[1]):
        oechem.OEThrow.Fatal("Unable to open %s for reading" % args[1])

    mol = oechem.OEGraphMol()
    while oechem.OEReadMolecule(ifs, mol):
        oechem.OEAddExplicitHydrogens(mol)

        mmff = oeff.OEMMFF()
        if not mmff.PrepMol(mol) or not mmff.Setup(mol):
            oechem.OEThrow.Warning("Unable to process molecule: title = '%s'" %
                                   mol.GetTitle())
            continue

        vecCoords = oechem.OEDoubleArray(3 * mol.GetMaxAtomIdx())
        mol.GetCoords(vecCoords)
        for fcomp in mmff.GetFComponents(vecCoords):
            oechem.OEThrow.Info(
                "Molecule: %s Component: %s Energy: %d kcal/mol" %
                (mol.GetTitle(), fcomp.name, fcomp.value))

    return 0
Пример #14
0
def GetBoundsFromMol(bounds, mol, pad):
    set = False
    c = oechem.OEDoubleArray(3)
    for atom in mol.GetAtoms():
        mol.GetCoords(atom, c)
        if not set:
            bounds[0] = bounds[3] = c[0]
            bounds[1] = bounds[4] = c[1]
            bounds[2] = bounds[5] = c[2]
            set = True
        else:
            if (c[0] < bounds[0]):
                bounds[0] = c[0]
            if (c[1] < bounds[1]):
                bounds[1] = c[1]
            if (c[2] < bounds[2]):
                bounds[2] = c[2]
            if (c[0] > bounds[3]):
                bounds[3] = c[0]
            if (c[1] > bounds[4]):
                bounds[4] = c[1]
            if (c[2] > bounds[5]):
                bounds[5] = c[2]

    bounds[0] -= pad
    bounds[1] -= pad
    bounds[2] -= pad
    bounds[3] += pad
    bounds[4] += pad
    bounds[5] += pad
Пример #15
0
def OERMSD_Full_MolBase(ref, fit):
    oechem.OERMSD(ref, fit)

    automorf = True
    oechem.OERMSD(ref, fit, automorf)

    heavyOnly = True
    oechem.OERMSD(ref, fit, automorf, heavyOnly)

    overlay = False
    oechem.OERMSD(ref, fit, automorf, heavyOnly, overlay)

    rotmat = oechem.OEDoubleArray(9)
    oechem.OERMSD(ref, fit, automorf, heavyOnly, overlay, rotmat)

    transvec = oechem.OEDoubleArray(3)
    oechem.OERMSD(ref, fit, automorf, heavyOnly, overlay, rotmat, transvec)
Пример #16
0
def OERMSD_Part_MCMolBase(ref, fit):
    match = oechem.OEMatch()
    for aRef, aFit in zip(ref.GetAtoms(), fit.GetAtoms()):
        match.AddPair(aRef, aFit)

    nConfs = fit.GetMaxConfIdx()
    vecRmsd = oechem.OEDoubleArray(nConfs)
    oechem.OERMSD(ref, fit, vecRmsd, match)

    overlay = True
    oechem.OERMSD(ref, fit, vecRmsd, match, overlay)

    rotmat = oechem.OEDoubleArray(9*nConfs)
    oechem.OERMSD(ref, fit, vecRmsd, match, overlay, rotmat)

    transvec = oechem.OEDoubleArray(3*nConfs)
    oechem.OERMSD(ref, fit, vecRmsd, match, overlay, rotmat, transvec)
Пример #17
0
def normalize_coordinates(mol, dih):
    """Reset the coordinates of an OEGraphMol object with respect to a dihedral.

    The first three atoms of the dihedral will be set to the following
    coordinates:
    |Atom| Position |
    |----|----------|
    |  0 | (0,0,0)  |
    |  1 | (x1,0,0) |
    |  2 | (x2,y2,0)|

    This defines the coordinate system required to determine the coordinates of
    all the other atoms in the fragment.

    Arguments:
        mol: An OEGraphMol object.
        dih: An OEAtomBondSet with atoms belonging to mol.

    Returns:
        success: A bool indicating whether the transformation was successful.
    """
    dih_atoms = [atom for atom in dih.GetAtoms()]

    # Translate the fragment until the first atom of the dihedral is at the origin
    origin = mol.GetCoords()[dih_atoms[0].GetIdx()]
    shift = oechem.OEDoubleArray([-x for x in origin])
    oechem.OETranslate(mol, shift)

    # Get coordinates of atoms 2 and 3 in the dihedral
    u = np.array(mol.GetCoords()[dih_atoms[1].GetIdx()])
    v = np.array(mol.GetCoords()[dih_atoms[2].GetIdx()])

    # Get three orthogonal unit vectors
    u_hat = u / np.linalg.norm(u)

    v_hat = v - (
        (np.dot(u, v) * u) / np.dot(u, u))  # Gram-Schmidt Orthogonalization
    v_hat = v_hat / np.linalg.norm(v_hat)

    w_hat = np.cross(u_hat, v_hat)

    # Assemble unit vectors into rotation matrix
    R = np.stack((u_hat, v_hat, w_hat), axis=0)
    rotation_matrix = oechem.OEDoubleArray(R.flatten())
    oechem.OERotate(mol, rotation_matrix)
Пример #18
0
def OERMSD_Full_MCMolBase(ref, fit):
    nConfs = fit.GetMaxConfIdx()
    vecRmsd = oechem.OEDoubleArray(nConfs)
    oechem.OERMSD(ref, fit, vecRmsd)

    automorf = True
    oechem.OERMSD(ref, fit, vecRmsd, automorf)

    heavyOnly = True
    oechem.OERMSD(ref, fit, vecRmsd, automorf, heavyOnly)

    overlay = True
    oechem.OERMSD(ref, fit, vecRmsd, automorf, heavyOnly, overlay)

    rotmat = oechem.OEDoubleArray(9*nConfs)
    oechem.OERMSD(ref, fit, vecRmsd, automorf, heavyOnly, overlay, rotmat)

    transvec = oechem.OEDoubleArray(3*nConfs)
    oechem.OERMSD(ref, fit, vecRmsd, automorf, heavyOnly, overlay, rotmat, transvec)
Пример #19
0
def MCSAlign(refmol, fitmol, ofs):
    atomexpr = oechem.OEExprOpts_AtomicNumber | oechem.OEExprOpts_Aromaticity
    bondexpr = 0
    mcss = oechem.OEMCSSearch(oechem.OEMCSType_Exhaustive)
    mcss.Init(refmol, atomexpr, bondexpr)
    mcss.SetMCSFunc(oechem.OEMCSMaxBondsCompleteCycles())

    rmat = oechem.OEDoubleArray(9)
    trans = oechem.OEDoubleArray(3)
    unique = True
    overlay = True
    for match in mcss.Match(fitmol, unique):
        rms = oechem.OERMSD(mcss.GetPattern(), fitmol, match, overlay, rmat, trans)
        if rms < 0.0:
            oechem.OEThrow.Warning("RMS overlay failure")
            continue
        oechem.OERotate(fitmol, rmat)
        oechem.OETranslate(fitmol, trans)
        oechem.OEWriteMolecule(ofs, fitmol)
Пример #20
0
    def __call__(self, iteration, nvar, fval, var, state):
        # Intermediate information during optimization
        var1 = oechem.OEDoubleArray(var, 1, False)
        oechem.OEThrow.Info("iteration: %d x: %d value: %d state: %d" %
                            (iteration, var1[0], fval, state))

        # To demonstrate how to force quitting optimization from checkpoint
        # this returns false when iteration is 5
        if iteration >= 5:
            return False
        else:
            return True
Пример #21
0
def main(args):
    if len(args) != 4:
        oechem.OEThrow.Usage("%s <protein> <ligand> <output>" % args[0])

    ips = oechem.oemolistream()
    if not ips.open(args[1]):
        oechem.OEThrow.Fatal("Unable to open %s for reading protein" % args[1])

    ils = oechem.oemolistream()
    if not ils.open(args[2]):
        oechem.OEThrow.Fatal("Unable to open %s for reading ligand" % args[2])

    ofs = oechem.oemolostream()
    if not ofs.open(args[3]):
        oechem.OEThrow.Fatal("Unable to open %s for writing" % args[3])

    # Load the protein molecule and Prepare with MMFF
    protein = oechem.OEGraphMol()
    oechem.OEReadMolecule(ips, protein)
    oechem.OEAddExplicitHydrogens(protein)
    mmff = oeff.OEMMFFAmber(protein)
    mmff.PrepMol(protein)

    mol = oechem.OEMol()
    while oechem.OEReadMolecule(ils, mol):
        oechem.OEAddExplicitHydrogens(mol)
        if (not mmff.PrepMol(mol)) or (not mmff.Setup(mol)):
            oechem.OEThrow.Warning("Unable to process molecule: title = '%s'" %
                                   mol.GetTitle())
            oechem.OEWriteMolecule(ofs, mol)
            continue

        vecCoords = oechem.OEDoubleArray(3 * mol.GetMaxAtomIdx())
        for conf in mol.GetConfs():
            oechem.OEThrow.Info("Molecule: %s Conformer: %d" %
                                (mol.GetTitle(), conf.GetIdx() + 1))
            conf.GetCoords(vecCoords)

            # Calculate energy
            energy = mmff(vecCoords)
            oechem.OEThrow.Info("Initial energy: %d kcal/mol" % energy)

            # Optimize the ligand
            optimizer = oeff.OEBFGSOpt()
            energy = optimizer(mmff, vecCoords, vecCoords)
            oechem.OEThrow.Info("Optimized energy: %d kcal/mol" % energy)
            conf.SetCoords(vecCoords)

        oechem.OEWriteMolecule(ofs, mol)
    return 0
Пример #22
0
def SeqAlign(ref, fit, ofs):
    sa = oechem.OEGetAlignment(ref, fit)
    print()
    print("Alignment of %s to %s" % (fit.GetTitle(), ref.GetTitle()))
    print()
    print("  Method: %s" % oechem.OEGetAlignmentMethodName(sa.GetMethod()))
    print("  Gap   : %d" % sa.GetGap())
    print("  Extend: %d" % sa.GetExtend())
    print("  Score : %d" % sa.GetScore())
    print()

    oss = oechem.oeosstream()
    oechem.OEWriteAlignment(oss, sa)
    print(oss.str().decode("UTF-8"))

    onlyCAlpha = True
    overlay = True
    rot = oechem.OEDoubleArray(9)
    trans = oechem.OEDoubleArray(3)
    rmsd = oechem.OERMSD(ref, fit, sa, onlyCAlpha, overlay, rot, trans)
    print("  RMSD = %.1f" % rmsd)
    oechem.OERotate(fit, rot)
    oechem.OETranslate(fit, trans)
    oechem.OEWriteMolecule(ofs, fit)
def mmff_energy(mol):
    """
    Compute MMFF energy

    """
    from openeye import oechem, oeff
    mol = oechem.OEGraphMol(mol)
    mmff = oeff.OEMMFF()
    if not mmff.PrepMol(mol) or not mmff.Setup(mol):
        oechem.OEThrow.Warning("Unable to process molecule: title = '%s'" % mol.GetTitle())
        return None

    vecCoords = oechem.OEDoubleArray(3*mol.GetMaxAtomIdx())
    mol.GetCoords(vecCoords)
    energy = mmff(vecCoords)
    return energy
Пример #24
0
    def GetTorsionEnvAtoms(self, elem, bgnAtom, endAtom, envMol):
        elemEnvList = []
        for envAtom in oechem.OEGetSubtree(bgnAtom, endAtom):
            if elem == 'pc' and envAtom.GetFormalCharge() >= 1:
                elemEnvList.append(envAtom)
            elif elem == 'nc' and envAtom.GetFormalCharge() <= -1:
                elemEnvList.append(envAtom)
            elif envAtom.GetAtomicNum() == elem:
                elemEnvList.append(envAtom)

        coordsList = []
        for elemEnvAtom in elemEnvList:
            coords = oechem.OEDoubleArray(3)
            if envMol.GetCoords(elemEnvAtom, coords):
                coordsList.append(coords)

        return elemEnvList, coordsList
Пример #25
0
    def GetEnvAtomCoords(self, elem, refAtom, envMol, envAtoms):
        elemEnvList = []
        for envAtom in envAtoms:
            if envAtom == refAtom:
                continue

            if elem == 'pc' and envAtom.GetFormalCharge() >= 1:
                elemEnvList.append(envAtom)
            elif elem == 'nc' and envAtom.GetFormalCharge() <= -1:
                elemEnvList.append(envAtom)
            elif envAtom.GetAtomicNum() == elem:
                elemEnvList.append(envAtom)

        coordsList = []
        for elemEnvAtom in elemEnvList:
            coords = oechem.OEDoubleArray(3)
            if envMol.GetCoords(elemEnvAtom, coords):
                coordsList.append(coords)

        return coordsList
Пример #26
0
    def GetTorsionCenterAsOEMol(self, mol):
        refCoords = oechem.OEDoubleArray(3)
        try:
            torsion_atoms = get_torsion_oeatom_list(mol)

            bgnCoords = mol.GetCoords(torsion_atoms[1])
            endCoords = mol.GetCoords(torsion_atoms[2])
            refCoords[0] = (bgnCoords[0] + endCoords[0]) / 2.0
            refCoords[1] = (bgnCoords[1] + endCoords[1]) / 2.0
            refCoords[2] = (bgnCoords[2] + endCoords[2]) / 2.0
        except Exception as e:
            print(e)
            return None

        refMol = oechem.OEMol()
        refAtom = refMol.NewAtom(oechem.OEElemNo_C)
        refMol.SetCoords(refAtom, refCoords)
        refMol.Sweep()

        return refMol
Пример #27
0
def main(args):
    if len(args) != 2:
        oechem.OEThrow.Usage("%s <input>" % args[0])

    ifs = oechem.oemolistream()
    if not ifs.open(args[1]):
        oechem.OEThrow.Fatal("Unable to open %s for reading" % args[1])

    mol = oechem.OEGraphMol()
    oechem.OEReadMolecule(ifs, mol)
    vecCoords = oechem.OEDoubleArray(3 * mol.GetMaxAtomIdx())
    mol.GetCoords(vecCoords)

    hermonic = Harmonic()
    hermonic.Setup(mol)
    optimizer = oeff.OEBFGSOpt()
    energy = optimizer(hermonic, vecCoords, vecCoords)
    oechem.OEThrow.Info("Optimized energy: %d" % energy)

    return 0
Пример #28
0
def main(args):
    if len(args) != 3:
        oechem.OEThrow.Usage("%s <input> <output>" % args[0])

    ifs = oechem.oemolistream()
    if not ifs.open(args[1]):
        oechem.OEThrow.Fatal("Unable to open %s for reading" % args[1])

    ofs = oechem.oemolostream()
    if not ofs.open(args[2]):
        oechem.OEThrow.Fatal("Unable to open %s for writing" % args[2])

    mol = oechem.OEMol()
    while oechem.OEReadMolecule(ifs, mol):
        oechem.OEAddExplicitHydrogens(mol)

        mmff = oeff.OEMMFF()
        if not mmff.PrepMol(mol) or not mmff.Setup(mol):
            oechem.OEThrow.Warning("Unable to process molecule: title = '%s'" %
                                   mol.GetTitle())
            oechem.OEWriteMolecule(ofs, mol)
            continue

        vecCoords = oechem.OEDoubleArray(3 * mol.GetMaxAtomIdx())
        for conf in mol.GetConfs():
            oechem.OEThrow.Info("Molecule: %s Conformer: %d" %
                                (mol.GetTitle(), conf.GetIdx() + 1))
            conf.GetCoords(vecCoords)

            energy = mmff(vecCoords)
            oechem.OEThrow.Info("Initial energy: %d kcal/mol" % energy)

            optimizer = oeff.OEBFGSOpt()
            energy = optimizer(mmff, vecCoords, vecCoords)
            oechem.OEThrow.Info("Optimized energy: %d kcal/mol" % energy)
            conf.SetCoords(vecCoords)

        oechem.OEWriteMolecule(ofs, mol)

    return 0
Пример #29
0
def main(args):
    if len(args) != 3:
        oechem.OEThrow.Usage("%s <input> <output>" % args[0])

    ifs = oechem.oemolistream()
    if not ifs.open(args[1]):
        oechem.OEThrow.Fatal("Unable to open %s for reading " % args[1])

    ofs = oechem.oemolostream()
    if not ofs.open(args[2]):
        oechem.OEThrow.Fatal("Unable to open %s for writing" % args[3])

    # Load the protein molecule and Prepare with MMFF
    smir = oeff.OESmirnoff()
    optimizer = oeff.OENewtonOpt()

    mol = oechem.OEMol()
    while oechem.OEReadMolecule(ifs, mol):
        if ((not smir.PrepMol(mol)) or (not smir.Setup(mol))):
            oechem.OEThrow.Warning("Unable to process molecule: title = '%s'" % mol.GetTitle())
            oechem.OEWriteMolecule(ofs, mol)
            continue

        vecCoords = oechem.OEDoubleArray(3*mol.GetMaxAtomIdx())
        for conf in mol.GetConfs():
            oechem.OEThrow.Info("Molecule: %s Conformer: %d" % (mol.GetTitle(), conf.GetIdx()+1))
            conf.GetCoords(vecCoords)

            energy = smir(vecCoords)
            oechem.OEThrow.Info("Initial energy: %d kcal/mol" % energy)

            energy = optimizer(smir, vecCoords, vecCoords)
            oechem.OEThrow.Info("Optimized energy: %d kcal/mol" % energy)
            conf.SetCoords(vecCoords)

        oechem.OEWriteMolecule(ofs, mol)
    return 0
Пример #30
0
def main(args):
    if len(args) != 4:
        oechem.OEThrow.Usage("%s <protein> <ligand> <output>" % args[0])

    ips = oechem.oemolistream()
    if not ips.open(args[1]):
        oechem.OEThrow.Fatal("Unable to open %s for reading protein" % args[1])

    ils = oechem.oemolistream()
    if not ils.open(args[2]):
        oechem.OEThrow.Fatal("Unable to open %s for reading ligand" % args[2])

    ofs = oechem.oemolostream()
    if not ofs.open(args[3]):
        oechem.OEThrow.Fatal("Unable to open %s for writing" % args[3])

    # Load the protein molecule and Prepare with MMFF
    protein = oechem.OEGraphMol()
    oechem.OEReadMolecule(ips, protein)
    oechem.OEAddExplicitHydrogens(protein)
    mmff = oeff.OEMMFFAmber(protein)
    mmff.PrepMol(protein)

    mol = oechem.OEMol()
    while oechem.OEReadMolecule(ils, mol):
        oechem.OEAddExplicitHydrogens(mol)
        if (not mmff.PrepMol(mol)) or (not mmff.Setup(mol)):
            oechem.OEThrow.Warning("Unable to process molecule: title = '%s'" % mol.GetTitle())
            oechem.OEWriteMolecule(ofs, mol)
            continue

        # Setup adaptor. The first (false) means not to pass ownership of mmff,
        # and the second (false) means not to exclude interactions related
        # to the subset which would be fixed for calculations.
        adaptor = oeff.OEQuatAdaptor(mmff, False, False)
        if not adaptor.Setup(mol):
            oechem.OEThrow.Warning("Unable to process subset for molecule: title = '%s'"
                                   % mol.GetTitle())
            oechem.OEWriteMolecule(ofs, mol)
            continue

        vecCoords = oechem.OEDoubleArray(3*mol.GetMaxAtomIdx())
        for conf in mol.GetConfs():
            oechem.OEThrow.Info("Molecule: %s Conformer: %d" % (mol.GetTitle(), conf.GetIdx()+1))
            conf.GetCoords(vecCoords)

            # Get adaptor variables set corresponding to the coordinates
            vecX = oechem.OEDoubleArray(adaptor.NumVar())
            adaptor.GetVar(vecX, vecCoords)

            # Calculate energy using adaptor
            energy = adaptor(vecX)
            oechem.OEThrow.Info("Initial energy: %d kcal/mol" % energy)

            # Optimize the ligand
            optimizer = oeff.OEBFGSOpt()
            energy = optimizer(adaptor, vecX, vecX)
            oechem.OEThrow.Info("Optimized energy: %d kcal/mol" % energy)

            # Get optimized coordinates corresponding to the adaptor optimized variables
            adaptor.AdaptVar(vecCoords, vecX)
            conf.SetCoords(vecCoords)

    oechem.OEWriteMolecule(ofs, mol)
    return 0