Esempio n. 1
0
 def buildSugar(self, baseAtoms, pucker):
     """Build a sugar of the specified pucker onto a base
     
     ARGUMENTS:
         baseAtoms - a dictionary of base atoms in the form atomName:[x, y, z]
                     Note that this dictionary MUST contain the C1' atom
         pucker    - the pucker of the sugar to be built (passed as an integer, either 2 or 3)
     RETURNS:
         coordinates for a sugar of the specified pucker in anti configuration with the base
     """
     
     #fetch the appropriate sugar structure
     if pucker == 3:
         sugarAtoms = self.__c3pAtoms
     elif pucker == 2:
         sugarAtoms = self.__c2pAtoms
     else:
         raise "BuildInitSugar called with unrecognized pucker: " + str(pucker)
     #I don't have to worry about accidentally modifying the original atom dictionaries, since
     #rotateAtoms effectively makes a deep copy
     
     #figure out which base atoms to use for alignment
     if baseAtoms.has_key("N9"):
         Natom = "N9"
         Catom = "C4"
     else:
         Natom = "N1"
         Catom = "C2"
     
     
     #rotate the sugar so the glycosidic bond is at the appropriate angle
     #first, calculate an axis for this rotation
     translatedBaseN = minus(baseAtoms[Natom], baseAtoms["C1'"])
     sugarN = sugarAtoms[Natom]
     
     axis = crossProd(sugarN, translatedBaseN)
     angle = torsion(translatedBaseN, axis, (0,0,0), sugarN)
     
     #if either angle or magnitude(axis) is 0, then the glycosidic bond is already oriented appropriately
     if not(angle == 0 or magnitude(axis) == 0):
         sugarAtoms = rotateAtoms(sugarAtoms, axis, angle)
     
     
     #next, rotate the sugar so that chi is appropriate
     translatedBaseC = minus(baseAtoms[Catom], baseAtoms["C1'"])
     curChi = torsion(translatedBaseC, translatedBaseN, [0,0,0], sugarAtoms["O4'"])
     sugarAtoms = rotateAtoms(sugarAtoms, translatedBaseN, curChi - STARTING_CHI)
     
     #remove the unnecessary atoms from the sugarAtoms dict
     del sugarAtoms["N1"]
     del sugarAtoms["N9"]
     
     #translate the sugar to the C1' atom of the base
     sugarAtoms = dict([(atom, plus(coords, baseAtoms["C1'"])) for (atom, coords) in sugarAtoms.iteritems()])
     
     return sugarAtoms
Esempio n. 2
0
 def flipBase(self, curBase):
     """Flip the base anti/syn
     
     ARGUMENTS:
         curBase - the current base object in the form [baseType, baseCoordinates]
     RETURNS:
         the base object with rotated coordinates
     NOTE:
         This function does not necessarily simply rotate about chi.  When flipping a purine, it also adjusts
         the glycosidic bond position so that it the base a chance of staying in the density
     """
     
     (baseType, curBaseCoords) = curBase
     
     curC1coords = curBaseCoords["C1'"]
     
     newBaseCoords = {}
     #translate the base to the origin
     for atomName, curAtomCoords in curBaseCoords.items():
         newBaseCoords[atomName] = minus(curBaseCoords[atomName], curC1coords)
     
     #the rotation axis is the same as the alignment vector for mutating the base
     #for pyrimidines, the axis is C1'-C4
     #for purines, the axis is from C1' to the center of the C4-C5 bond
     axis = None
     if baseType == "C" or baseType == "U":
         axis = newBaseCoords["C4"]
     else:
         axis = plus(newBaseCoords["C4"], newBaseCoords["C5"])
         axis = scalarProd(1.0/2.0, axis)
     
     #rotate the base 180 degrees about the axis
     newBaseCoords = rotateAtoms(newBaseCoords, axis, 180, curC1coords)
     
     return [baseType, newBaseCoords]
Esempio n. 3
0
def rotateSugar(antiSugarCoords, atoms, newChi = "syn"):
    """Given a sugar in anti configuration, rotate it to a new configuration (such as syn or high-anti).
    
    ARGUMENTS:
        antiSugarCoords - a dictionary containing a sugar in anti configuration in the format atomName: [x, y, z]
                          typically, this dictionary is generated by a BuildInitSugar object
        atoms           - a dictionary containing base coordinates in the format atomName: [x, y, z]
    OPTIONAL ARGUMENTS:
        newChi          - the chi value to rotate the sugar to
                          may be "syn", "high-anti", or a number (in degrees)
                          defaults to "syn"
    RETURNS:
        synSugarCoords  - a dictionary containing a sugar in syn configuration in the format atomName: [x, y, z]
    """
    
    if newChi == "syn":
        newChi = SYN_CHI
    elif newChi == "high-anti":
        newChi = HIGH_ANTI_CHI
    
    #translate the sugar coordinates to the origin
    synSugarCoords = dict([(atom, minus(coords, atoms["C1'"])) for (atom, coords) in antiSugarCoords.iteritems()])
    
    #rotate the sugar
    if atoms.has_key("N9"):
        baseN = "N9"
    else:
        baseN = "N1"
    axis = minus(atoms[baseN], atoms["C1'"])
    
    synSugarCoords = rotateAtoms(synSugarCoords, axis, newChi - STARTING_CHI, atoms["C1'"])
    
    return synSugarCoords
Esempio n. 4
0
 def flipBase(self, curBase):
     """Flip the base anti/syn
     
     ARGUMENTS:
         curBase - the current base object in the form [baseType, baseCoordinates]
     RETURNS:
         the base object with rotated coordinates
     NOTE:
         This function does not necessarily simply rotate about chi.  When flipping a purine, it also adjusts
         the glycosidic bond position so that it the base a chance of staying in the density
     """
     
     (baseType, curBaseCoords) = curBase
     
     curC1coords = curBaseCoords["C1'"]
     
     newBaseCoords = {}
     #translate the base to the origin
     for atomName, curAtomCoords in curBaseCoords.items():
         newBaseCoords[atomName] = minus(curBaseCoords[atomName], curC1coords)
     
     #the rotation axis is the same as the alignment vector for mutating the base
     #for pyrimidines, the axis is C1'-C4
     #for purines, the axis is from C1' to the center of the C4-C5 bond
     axis = None
     if baseType == "C" or baseType == "U":
         axis = newBaseCoords["C4"]
     else:
         axis = plus(newBaseCoords["C4"], newBaseCoords["C5"])
         axis = scalarProd(1.0/2.0, axis)
     
     #rotate the base 180 degrees about the axis
     newBaseCoords = rotateAtoms(newBaseCoords, axis, 180, curC1coords)
     
     return [baseType, newBaseCoords]
Esempio n. 5
0
 def mutateBase(self, curBase, newBaseType):
     """Change the base type.
     
     ARGUMENTS:
         curBase - the current base object in the form [baseType, baseCoordinates]
         newBaseType - the base type to mutate to
     RETURNS:
         baseObj  - a list of [baseType, baseCoordinates]
     """
     
     (curBaseType, curBaseCoords) = curBase
     
     #calculate the vectors used to align the old and new bases
     #for pyrimidines, the vector is C1'-C4
     #for purines, the vector is from C1' to the center of the C4-C5 bond
     curAlignmentVector = None
     if curBaseType == "C" or curBaseType == "U":
         curAlignmentVector = minus(curBaseCoords["C4"], curBaseCoords["C1'"])
     else:
         curBaseCenter = plus(curBaseCoords["C4"], curBaseCoords["C5"])
         curBaseCenter = scalarProd(1.0/2.0, curBaseCenter)
         curAlignmentVector = minus(curBaseCenter, curBaseCoords["C1'"])
     
     #calculate the alignment vector for the new base
     newBaseCoords = self.__baseStrucs[newBaseType]
     newAlignmentVector = None
     if newBaseType == "C" or newBaseType == "U":
         newAlignmentVector = newBaseCoords["C4"]
     else:
         newAlignmentVector = plus(newBaseCoords["C4"], newBaseCoords["C5"])
         newAlignmentVector = scalarProd(1.0/2.0, newAlignmentVector)
     
     #calculate the angle between the alignment vectors
     rotationAngle = -angle(curAlignmentVector, [0,0,0], newAlignmentVector)
     axis = crossProd(curAlignmentVector, newAlignmentVector)
     
     #rotate the new base coordinates
     newBaseCoords = rotateAtoms(newBaseCoords, axis, rotationAngle)
     
     #calculate the normals of the base planes
     curNormal = None
     if curBaseType == "C" or curBaseType == "U":
         curNormal = crossProd(minus(curBaseCoords["N3"], curBaseCoords["N1"]), minus(curBaseCoords["C6"], curBaseCoords["N1"]))
     else:
         curNormal = crossProd(minus(curBaseCoords["N3"], curBaseCoords["N9"]), minus(curBaseCoords["N7"], curBaseCoords["N9"]))
     
     newNormal = None
     if newBaseType == "C" or newBaseType == "U":
         newNormal = crossProd(minus(newBaseCoords["N3"], newBaseCoords["N1"]), minus(newBaseCoords["C6"], newBaseCoords["N1"]))
     else:
         newNormal = crossProd(minus(newBaseCoords["N3"], newBaseCoords["N9"]), minus(newBaseCoords["N7"], newBaseCoords["N9"]))
     
     #calculate the angle between the normals
     normalAngle = -angle(curNormal, [0,0,0], newNormal);
     normalAxis = crossProd(curNormal, newNormal)
     
     #rotate the new base coordinates so that it falls in the same plane as the current base
     #and translate the base to the appropriate location
     newBaseCoords = rotateAtoms(newBaseCoords, normalAxis, normalAngle, curBaseCoords["C1'"])
     
     return [newBaseType, newBaseCoords]
Esempio n. 6
0
 def findBase(self, mapNum, sugar, phos5, phos3, baseType, direction = 3):
     """Rotate the sugar center by 360 degrees in ROTATE_SUGAR_INTERVAL increments
     
     ARGUMENTS:
         mapNum   - the molecule number of the Coot map to use
         sugar    - the coordinates of the C1' atom
         phos5    - the coordinates of the 5' phosphate
         phos3    - the coordinates of the 3' phosphate
         baseType - the base type (A, C, G, or U)
     OPTIONAL ARGUMENTS:
         direction - which direction are we tracing the chain
                     if it is 5 (i.e. 3'->5'), then phos5 and phos3 will be flipped
                     all other values will be ignored
                     defaults to 3 (i.e. 5'->3')
     RETURNS:
         baseObj  - a list of [baseType, baseCoordinates]
     """
     
     if direction == 5:
         (phos5, phos3) = (phos3, phos5)
     
     #calculate the bisector of the phos-sugar-phos angle
     #first, calculate a normal to the phos-sugar-phos plane
     sugarPhos5Vec = minus(phos5, sugar)
     sugarPhos3Vec = minus(phos3, sugar)
     normal = crossProd(sugarPhos5Vec, sugarPhos3Vec)
     normal = scalarProd(normal, 1.0/magnitude(normal))
     
     phosSugarPhosAngle = angle(phos5, sugar, phos3)
     
     bisector = rotate(sugarPhos5Vec, normal, phosSugarPhosAngle/2.0)
     
     
     #flip the bisector around (so it points away from the phosphates) and scale its length to 5 A
     startingBasePos = scalarProd(bisector, -1/magnitude(bisector))
     
     #rotate the base baton by 10 degree increments about half of a sphere
     rotations = [startingBasePos] #a list of coordinates for all of the rotations
     for curTheta in range(-90, -1, 10) + range(10, 91, 10):
         curRotation = rotate(startingBasePos, normal, curTheta)
         rotations.append(curRotation) #here's where the phi=0 rotation is accounted for
         
         for curPhi in range(-90, -1, 10) + range(10, 91, 10):
             rotations.append(rotate(curRotation, startingBasePos, curPhi))
             
     #test electron density along all base batons
     for curBaton in rotations:
         curDensityTotal = 0
         densityList = []
         for i in range(1, 9):
             (x, y, z) = plus(sugar, scalarProd(i/2.0, curBaton))
             curPointDensity = density_at_point(mapNum, x, y, z)
             curDensityTotal += curPointDensity
             densityList.append(curPointDensity)
         curBaton.append(curDensityTotal)        #the sum of the density (equivalent to the mean for ordering purposes)
         curBaton.append(median(densityList))    #the median of the density
         curBaton.append(min(densityList))       #the minimum of the density
     
     #find the baton with the max density (as measured using the median)
     #Note that we ignore the sum and minimum of the density.  Those calculations could be commented out,
     #   but they may be useful at some point in the future.  When we look at higher resolutions maybe?
     #   Besides, they're fast calculations.)
     baseDir = max(rotations, key = lambda x: x[4])
     
     #rotate the stock base+sugar structure to align with the base baton
     rotationAngle = angle(self.__baseStrucs["C"]["C4"], [0,0,0], baseDir)
     axis = crossProd(self.__baseStrucs["C"]["C4"], baseDir[0:3])
     
     orientedBase = rotateAtoms(self.__baseStrucs["C"], axis, rotationAngle)
     
     #rotate the base about chi to find the best fit to density
     bestFitBase = None
     maxDensity = -999999
     for curAngle in range(0,360,5):
         rotatedBase = rotateAtoms(orientedBase, orientedBase["C4"], curAngle, sugar)
         curDensity = 0
         for curAtom in ["N1", "C2", "N3", "C4", "C5", "C6"]:
             curDensity += density_at_point(mapNum, rotatedBase[curAtom][0], rotatedBase[curAtom][1], rotatedBase[curAtom][2])
         
         #this is "pseudoChi" because it uses the 5' phosphate in place of the O4' atom
         pseudoChi = torsion(phos5, sugar, rotatedBase["N1"], rotatedBase["N3"])
         curDensity *= self.__pseudoChiInterp.interp(pseudoChi)
         
         if curDensity > maxDensity:
             maxDensity = curDensity
             bestFitBase = rotatedBase
     
     baseObj = ["C", bestFitBase]
     
     #mutate the base to the appropriate type
     if baseType != "C":
         baseObj = self.mutateBase(baseObj, baseType)
     
     return baseObj
Esempio n. 7
0
 def mutateBase(self, curBase, newBaseType):
     """Change the base type.
     
     ARGUMENTS:
         curBase - the current base object in the form [baseType, baseCoordinates]
         newBaseType - the base type to mutate to
     RETURNS:
         baseObj  - a list of [baseType, baseCoordinates]
     """
     
     (curBaseType, curBaseCoords) = curBase
     
     #calculate the vectors used to align the old and new bases
     #for pyrimidines, the vector is C1'-C4
     #for purines, the vector is from C1' to the center of the C4-C5 bond
     curAlignmentVector = None
     if curBaseType == "C" or curBaseType == "U":
         curAlignmentVector = minus(curBaseCoords["C4"], curBaseCoords["C1'"])
     else:
         curBaseCenter = plus(curBaseCoords["C4"], curBaseCoords["C5"])
         curBaseCenter = scalarProd(1.0/2.0, curBaseCenter)
         curAlignmentVector = minus(curBaseCenter, curBaseCoords["C1'"])
     
     #calculate the alignment vector for the new base
     newBaseCoords = self.__baseStrucs[newBaseType]
     newAlignmentVector = None
     if newBaseType == "C" or newBaseType == "U":
         newAlignmentVector = newBaseCoords["C4"]
     else:
         newAlignmentVector = plus(newBaseCoords["C4"], newBaseCoords["C5"])
         newAlignmentVector = scalarProd(1.0/2.0, newAlignmentVector)
     
     #calculate the angle between the alignment vectors
     rotationAngle = -angle(curAlignmentVector, [0,0,0], newAlignmentVector)
     axis = crossProd(curAlignmentVector, newAlignmentVector)
     
     #rotate the new base coordinates
     newBaseCoords = rotateAtoms(newBaseCoords, axis, rotationAngle)
     
     #calculate the normals of the base planes
     curNormal = None
     if curBaseType == "C" or curBaseType == "U":
         curNormal = crossProd(minus(curBaseCoords["N3"], curBaseCoords["N1"]), minus(curBaseCoords["C6"], curBaseCoords["N1"]))
     else:
         curNormal = crossProd(minus(curBaseCoords["N3"], curBaseCoords["N9"]), minus(curBaseCoords["N7"], curBaseCoords["N9"]))
     
     newNormal = None
     if newBaseType == "C" or newBaseType == "U":
         newNormal = crossProd(minus(newBaseCoords["N3"], newBaseCoords["N1"]), minus(newBaseCoords["C6"], newBaseCoords["N1"]))
     else:
         newNormal = crossProd(minus(newBaseCoords["N3"], newBaseCoords["N9"]), minus(newBaseCoords["N7"], newBaseCoords["N9"]))
     
     #calculate the angle between the normals
     normalAngle = -angle(curNormal, [0,0,0], newNormal);
     normalAxis = crossProd(curNormal, newNormal)
     
     #rotate the new base coordinates so that it falls in the same plane as the current base
     #and translate the base to the appropriate location
     newBaseCoords = rotateAtoms(newBaseCoords, normalAxis, normalAngle, curBaseCoords["C1'"])
     
     return [newBaseType, newBaseCoords]
Esempio n. 8
0
 def findBase(self, mapNum, sugar, phos5, phos3, baseType, direction = 3):
     """Rotate the sugar center by 360 degrees in ROTATE_SUGAR_INTERVAL increments
     
     ARGUMENTS:
         mapNum   - the molecule number of the Coot map to use
         sugar    - the coordinates of the C1' atom
         phos5    - the coordinates of the 5' phosphate
         phos3    - the coordinates of the 3' phosphate
         baseType - the base type (A, C, G, or U)
     OPTIONAL ARGUMENTS:
         direction - which direction are we tracing the chain
                     if it is 5 (i.e. 3'->5'), then phos5 and phos3 will be flipped
                     all other values will be ignored
                     defaults to 3 (i.e. 5'->3')
     RETURNS:
         baseObj  - a list of [baseType, baseCoordinates]
     """
     
     if direction == 5:
         (phos5, phos3) = (phos3, phos5)
     
     #calculate the bisector of the phos-sugar-phos angle
     #first, calculate a normal to the phos-sugar-phos plane
     sugarPhos5Vec = minus(phos5, sugar)
     sugarPhos3Vec = minus(phos3, sugar)
     normal = crossProd(sugarPhos5Vec, sugarPhos3Vec)
     normal = scalarProd(normal, 1.0/magnitude(normal))
     
     phosSugarPhosAngle = angle(phos5, sugar, phos3)
     
     bisector = rotate(sugarPhos5Vec, normal, phosSugarPhosAngle/2.0)
     
     
     #flip the bisector around (so it points away from the phosphates) and scale its length to 5 A
     startingBasePos = scalarProd(bisector, -1/magnitude(bisector))
     
     #rotate the base baton by 10 degree increments about half of a sphere
     rotations = [startingBasePos] #a list of coordinates for all of the rotations
     for curTheta in range(-90, -1, 10) + range(10, 91, 10):
         curRotation = rotate(startingBasePos, normal, curTheta)
         rotations.append(curRotation) #here's where the phi=0 rotation is accounted for
         
         for curPhi in range(-90, -1, 10) + range(10, 91, 10):
             rotations.append(rotate(curRotation, startingBasePos, curPhi))
             
     #test electron density along all base batons
     for curBaton in rotations:
         curDensityTotal = 0
         densityList = []
         for i in range(1, 9):
             (x, y, z) = plus(sugar, scalarProd(i/2.0, curBaton))
             curPointDensity = density_at_point(mapNum, x, y, z)
             curDensityTotal += curPointDensity
             densityList.append(curPointDensity)
         curBaton.append(curDensityTotal)        #the sum of the density (equivalent to the mean for ordering purposes)
         curBaton.append(median(densityList))    #the median of the density
         curBaton.append(min(densityList))       #the minimum of the density
     
     #find the baton with the max density (as measured using the median)
     #Note that we ignore the sum and minimum of the density.  Those calculations could be commented out,
     #   but they may be useful at some point in the future.  When we look at higher resolutions maybe?
     #   Besides, they're fast calculations.)
     baseDir = max(rotations, key = lambda x: x[4])
     
     #rotate the stock base+sugar structure to align with the base baton
     rotationAngle = angle(self.__baseStrucs["C"]["C4"], [0,0,0], baseDir)
     axis = crossProd(self.__baseStrucs["C"]["C4"], baseDir[0:3])
     
     orientedBase = rotateAtoms(self.__baseStrucs["C"], axis, rotationAngle)
     
     #rotate the base about chi to find the best fit to density
     bestFitBase = None
     maxDensity = -999999
     for curAngle in range(0,360,5):
         rotatedBase = rotateAtoms(orientedBase, orientedBase["C4"], curAngle, sugar)
         curDensity = 0
         for curAtom in ["N1", "C2", "N3", "C4", "C5", "C6"]:
             curDensity += density_at_point(mapNum, rotatedBase[curAtom][0], rotatedBase[curAtom][1], rotatedBase[curAtom][2])
         
         #this is "pseudoChi" because it uses the 5' phosphate in place of the O4' atom
         pseudoChi = torsion(phos5, sugar, rotatedBase["N1"], rotatedBase["N3"])
         curDensity *= self.__pseudoChiInterp.interp(pseudoChi)
         
         if curDensity > maxDensity:
             maxDensity = curDensity
             bestFitBase = rotatedBase
     
     baseObj = ["C", bestFitBase]
     
     #mutate the base to the appropriate type
     if baseType != "C":
         baseObj = self.mutateBase(baseObj, baseType)
     
     return baseObj