예제 #1
0
파일: Karplus.py 프로젝트: KristapsE/DP4-AI
def Karplus(f, inputformat):

    obconversion = OBConversion()
    obconversion.SetInFormat(inputformat)
    obmol = OBMol()

    obconversion.ReadFile(obmol, f)

    obmol.ConnectTheDots()
    obmol.Kekulize()

    DihedralHs = []
    for atom in OBMolAtomIter(obmol):
        if atom.GetAtomicNum() == 1:
            DihedNeighbours = GetDihedralHs(atom)
            if DihedNeighbours != 0:
                DihedralHs.append([atom.GetIdx()] + DihedNeighbours)

    if len(DihedralHs) == 0:
        print("No dihedral protons found, Karplus J value prediction " + \
            "impossible, quitting.")
        quit()

    Jmatrix, Jlabels = CalcJMatrix(obmol, DihedralHs)
    Jlabels = [str(x) for x in Jlabels]
    return Jmatrix, Jlabels
예제 #2
0
파일: InchiGen.py 프로젝트: fcwa2005/DP4-AI
def RestoreNumsSDF(f, fold, AuxInfo):

    #Read molecule from file
    obconversion = OBConversion()
    obconversion.SetInFormat("sdf")
    obmol = OBMol()
    obconversion.ReadFile(obmol, f)
    #Get the atoms Hs are connected to
    oldHcons = GetHcons(fold)
    #translate the H connected atoms to the new numbering system
    amap = GetInchiRenumMap(AuxInfo)
    for i in range(0, len(oldHcons)):
        oldHcons[i][1] = amap.index(oldHcons[i][1]) + 1

    newHcons = []
    temp = []
    i = 0
    for atom in OBMolAtomIter(obmol):
        idx = atom.GetIdx()
        anum = atom.GetAtomicNum()
        #If atom is hydrogen, check what it is connected to
        if anum == 1:
            for NbrAtom in OBAtomAtomIter(atom):
                newHcons.append([idx, NbrAtom.GetIdx()])
        #Pick the temporary atom
        temp.append(atom)

    for i in range(0, len(newHcons)):
        conatom = newHcons[i][1]
        for b in range(0, len(oldHcons)):
            if conatom == oldHcons[b][1]:
                amap.append(oldHcons[b][0])
                #remove the number, so that it doesn't get added twice
                oldHcons[b][1] = 0

    newmol = OBMol()
    added = []

    for i in range(1, len(amap) + 1):
        newn = amap.index(i)
        newmol.AddAtom(temp[newn])
        added.append(newn)

    #Final runthrough to check that all atoms have been added,
    #tautomeric protons can be missed. If tautomeric proton tracking
    #is implemented this can be removed
    for i in range(0, len(temp)):
        if not i in added:
            newmol.AddAtom(temp[i])

    #Restore the bonds
    newmol.ConnectTheDots()
    newmol.PerceiveBondOrders()
    #Write renumbered molecule to file
    obconversion.SetOutFormat("sdf")
    obconversion.WriteFile(newmol, f)
예제 #3
0
def main(f, settings):
    """
    Find the axis atoms
    Find all the atoms to be rotated

    Rotate it and the substituents to the other side of the plane
    """
    obconversion = OBConversion()
    obconversion.SetInFormat("sdf")
    obmol = OBMol()

    obconversion.ReadFile(obmol, f)

    obmol.ConnectTheDots()

    #Find the atoms composing furan ring
    Rings = obmol.GetSSSR()
    furan = []
    for ring in Rings:
        if len(settings.RingAtoms) == 5:
            if all(x in ring._path for x in settings.RingAtoms):
                furan = ring
                break
        else:
            if ring.Size() == 5 and not ring.IsAromatic():
                furan = ring
                break

    if furan == []:
        "No five membered rings to rotate. Quitting..."
        quit()
    #Find the plane of the 5-membered ring and the outlying atom
    norm, d, outAtom = FindFuranPlane(obmol, furan)

    #Find the atoms connected to the outlying atom and sort them
    #as either part of the ring(axis atoms) or as atoms to be rotated
    AxisAtoms = []
    RotAtoms = []

    for NbrAtom in OBAtomAtomIter(outAtom):
        #if NbrAtom.IsInRingSize(5):
        if furan.IsInRing(NbrAtom.GetIdx()):
            AxisAtoms.append(NbrAtom)
        else:
            RotAtoms.append(NbrAtom)
            FindSubstAtoms(NbrAtom, outAtom, RotAtoms)

    #Simple switch to help detect if the atoms are rotated the right way
    WasAbove90 = False
    angle = FindRotAngle(AxisAtoms[0], AxisAtoms[1], outAtom, norm)
    if angle > 0.5 * pi:
        WasAbove90 = True
        rotangle = 2 * (angle - 0.5 * pi)
    else:
        WasAbove90 = False
        rotangle = 2 * (0.5 * pi - angle)
    OldAtomCoords = outAtom.GetVector()
    print("Atom " + str(outAtom.GetAtomicNum()) + " will be rotated by " +\
        str(rotangle*57.3) + ' degrees')
    RotateAtom(outAtom, AxisAtoms[0], AxisAtoms[1], rotangle)
    angle2 = FindRotAngle(AxisAtoms[0], AxisAtoms[1], outAtom, norm)

    #if the atom is on the same side of the plane as it was,
    # it has been rotated in the wrong direction
    if ((angle2 > 0.5 * pi) and WasAbove90) or ((angle2 < 0.5 * pi)
                                                and not WasAbove90):
        #Flip the sign of the rotation angle, restore the coords
        #and rotate the atom in the opposite direction
        print("Atom was rotated the wrong way, switching the direction")
        rotangle = -rotangle
        outAtom.SetVector(OldAtomCoords)
        RotateAtom(outAtom, AxisAtoms[0], AxisAtoms[1], rotangle)

    RotatedAtoms = []  # Index to make sure that atoms are not rotated twice
    for atom in RotAtoms:
        if atom not in RotatedAtoms:
            RotateAtom(atom, AxisAtoms[0], AxisAtoms[1], rotangle)
            RotatedAtoms.append(atom)
        else:
            print("Atom already rotated, skipping")

    obconversion.SetOutFormat("sdf")
    obconversion.WriteFile(obmol, f[:-4] + 'rot.sdf')