コード例 #1
0
ファイル: pca.py プロジェクト: ryancoleman/mol2db2
def pca3d(pointList):
  '''sets up the pca for a list of points in 3d. solves eig problem'''
  matrixList = [[0,0,0],[0,0,0],[0,0,0]] #init to 0
  avgPt = geometry_basic.getAverage(pointList)
  diffs = [0,0,0]
  for point in pointList:
    for index in range(3):
      diffs[index] = point[index] - avgPt[index]
    #matrix is old plus a2 ab ac
    #                   ba b2 bc
    #                   ca cb c2 only compute upper diagonal now
    matrixList[0][0] += diffs[0]*diffs[0] #just hardcode it
    matrixList[0][1] += diffs[0]*diffs[1]
    matrixList[0][2] += diffs[0]*diffs[2]
    matrixList[1][1] += diffs[1]*diffs[1]
    matrixList[1][2] += diffs[1]*diffs[2]
    matrixList[2][2] += diffs[2]*diffs[2]
  #make symmetric
  matrixList[1][0] = matrixList[0][1]
  matrixList[2][0] = matrixList[0][2]
  matrixList[2][1] = matrixList[1][2]
  actualMatrix = Matrix(matrixList)
  val,vec = eigenvectors(actualMatrix)
  return val, vec
コード例 #2
0
ファイル: hierarchy.py プロジェクト: ryancoleman/mol2db2
 def _findAdditionalMatchSpheres(self, numSpheres=5, cutoff=2.5):
   '''for each cluster, find a couple matching spheres for distant atoms
   that are relatively localized in space.
   data ends up in dict self.clusterSpheres.
   numSpheres is the max# of spheres to add for each cluster. will not always
    find as many as requested.
   cutoff is used as a cutoff to decide 
    whether or not to add a sphere for that atom, mean pairwise dist?'''
   atomDists = self.mol2data.distFromAtoms(self.rigidComponent) #useful
   possibleAtoms = set(self.heavyAtomNums) #only heavy can be matching
   possibleAtoms.difference_update(self.rigidComponent) #no need to repeat
   possAtomDist = [] #useful for sorting by distance
   for possibleAtom in possibleAtoms:
     possAtomDist.append((possibleAtom, atomDists[possibleAtom]))
   possAtomDist.sort(key=operator.itemgetter(1), reverse=True)
   #use possAtomDist for each cluster now to find the best candidates
   self.clusterSpheres = {} #indexed by clusterIndex just like self.clusters
   for clusterIndex in self.clusters.keys():
     cluster = self.clusters[clusterIndex] #cluster is a tuple of conformations
     #print "cluster", cluster #debugging
     self.clusterSpheres[clusterIndex] = []
     for possibleAtom, atomDist in possAtomDist:
       xyzPositions = self.mol2data.getXyzManyConfs(cluster, possibleAtom)
       okayToAdd = False
       if 1 == len(xyzPositions): #singleton cluster, definitely okay
         okayToAdd = True
       else:
         longDist, meanDist = geometry_basic.longestAndMeanDist(xyzPositions)
         if meanDist <= cutoff: #passes cutoff
           okayToAdd = True
       if okayToAdd: #either singleton or passes cutoff
         avgPoint = geometry_basic.getAverage(xyzPositions)
         self.clusterSpheres[clusterIndex].append((possibleAtom, avgPoint))
         #print possibleAtom #debugging 
         if len(self.clusterSpheres[clusterIndex]) == numSpheres: #done
           break #out of for loop, no need to go on