def __init__(self, dcdfile, pdbfile, selection=None, verbose=False): self.file = dcdfile self.verbose = verbose self.selectDict = { None: None, "all": None, "bb": ['N', 'CA', 'C', 'O'], "backbone": ['N', 'CA', 'C', 'O'], "ca": ['CA'], "trace": ['CA'] } self.sel = selection if hasattr(selection, "pop") else self.selectDict[selection] if hasattr(pdbfile, "pdbfile"): self.pdbfile = pdbfile else: self.pdbfile = pdbReader.PdbReader( pdbfile if hasattr(pdbfile, "read") else open(pdbfile, 'r')) self.array = None self.mean = None self.covariance = None self.correlation = None self.indices = self.pdbfile.getIndices(self.sel) self.natom = len(self.indices) self.nframe = 0 self.header = {} self.load()
def move(self, eigenvalue, eigenvector, pdbFileName, clusterVarComparison=None, outPdbFile='move.pdb', append=False, modelNumber=0, continuousScale=False, ca = True, bb = False): pdbFile = open(pdbFileName) pdbR = pdbReader.PdbReader(pdbFile) if clusterVarComparison is None: p = abs(eigenvalue*eigenvector) else: cl1,cl2,var=clusterVarComparison # print var.shape,eigenvector.shape c = (1.*(eigenvector == cl1)+1.*(eigenvector == cl2)) p = var* (numpy.array([c,c,c]).transpose()) pdbFile = open(pdbFileName) pdbW = pdbWriter.PdbWriter(pdbFile) pdbW.alterCoordinates(p, outPdbFile, append=append, modelNumber=modelNumber, ca = ca, bb = bb)
def projection(self, eigenvalue, eigenvector, pdbFileName, clusterVarComparison=None, outPdbFile='projection.pdb', append=False, modelNumber=0, continuousScale=False, ca=True, bb=False): pdbFile = open(pdbFileName) pdbR = pdbReader.PdbReader(pdbFile) if clusterVarComparison is None: p = abs(eigenvalue * eigenvector) else: cl1, cl2, var = clusterVarComparison # print var.shape,eigenvector.shape p = var * ((1. * (eigenvector == cl1) - 1. * (eigenvector == cl2))) pdbFile = open(pdbFileName) pdbW = pdbWriter.PdbWriter(pdbFile) pdbW.addBFactor(p, outPdbFile, append=append, modelNumber=modelNumber, ca=ca, bb=bb) pymolScript = open(outPdbFile.replace('.pdb', '.pml'), 'w') max = numpy.max(eigenvector) if not continuousScale: pymolScript.write(""" load %s hide everything show cartoon spectrum b, minimum=0, maximum=%s """ % (outPdbFile, max)) else: pymolScript.write(""" load %s hide everything show cartoon spectrum b, blue_white_red, minimum=-1, maximum=1 alter all, b=str(abs(b)) cartoon putty unset cartoon_smooth_loops unset cartoon_flat_sheets """ % (outPdbFile)) pymolScript.close()
def write3Dcorr(self, matrix, pdbFileName, outFileName='corrCoords.txt', threshold=0.0, anticorr=True): mm = matriceManipulation.matrix(matrix) matrix = mm.symmetryZeros() def sorter(matrix, anticorr): l = numpy.ravel(matrix) sl = numpy.sort(l) lsl = list(sl) if not anticorr: lsl.reverse() return lsl def replace(pn, matrix): """ pn = +1|-1 """ for i in range(numpy.shape(matrix)[0]): for j in range(numpy.shape(matrix)[1]): e = matrix[i, j] if pn * e > 0: matrix[i, j] = 0 return matrix pdbFile = open(pdbFileName) pdbR = pdbReader.PdbReader(pdbFile) caCoords = pdbR.getCAcoord() resSeqs = pdbR.getResSeqs() if anticorr == True: matrix = replace(1, matrix) else: matrix = replace(-1, matrix) lCorrSorted = sorter(matrix, anticorr) outFile = open(outFileName, 'w') outFile.write('Sorted Ca coordinates from the most correlated\n') outFile.write('resSeq1'.rjust(10) + 'resSeq2'.rjust(10) + 'Pearson'.rjust(10) + 'x1'.rjust(10) + 'y1'.rjust(10) + 'z1'.rjust(10) + 'x2'.rjust(10) + 'y2'.rjust(10) + 'z2'.rjust(10) + '\n') for e in lCorrSorted: if abs(e) > abs(threshold): ij = numpy.where(matrix == e) jValues = itertools.chain(ij[1]) for i in ij[0]: j = jValues.next() iCoord = caCoords[i] jCoord = caCoords[j] outFile.write(('%s' % resSeqs[i]).rjust(10) + ('%s' % resSeqs[j]).rjust(10) + ('%.3f' % e).rjust(10) + ('%.3f' % iCoord[0]).rjust(10) + ('%.3f' % iCoord[1]).rjust(10) + ('%.3f' % iCoord[2]).rjust(10) + ('%.3f' % jCoord[0]).rjust(10) + ('%.3f' % jCoord[1]).rjust(10) + ('%.3f' % jCoord[2]).rjust(10) + '\n') else: break