def glaccel_glr_axis(self, position, axis, radius): """glaccel optimized version of glr_axis. """ if numpy.allclose(AtomMath.length(axis), 0.0): return end = position + axis glaccel.rod(position[0], position[1], position[2], end[0], end[1], end[2], radius)
def SuperimposeAtomsOutlierRejection(alist, rmsd_cutoff = 1.0, max_cycles = 100): """Superimpose two homologus protein chains. The argument alist is a list of 2-tuples. The 2-tuples are the 1:1 atoms to superimpose. The alignment procedure incrementally omits atoms with large deviations until the rmsd of the least squares superposition is less than or equal to rmsd_cutoff, or the number of cycles exceeds max_cycles. """ for cycle in xrange(max_cycles): sresult = SuperimposeAtoms(alist) print "Cycle %d NA: %5d RMSD %6.2f" % (cycle, sresult.num_atoms, sresult.rmsd) if sresult.rmsd <= rmsd_cutoff: return sresult deviation = [] for i in xrange(len(alist)): satm, datm = alist[i] spos = sresult.transform(satm.position) deviation.append((AtomMath.length(spos - datm.position), i)) deviation.sort() outliers = deviation[-10:] outliersr = [(x[1], x[0]) for x in outliers] outliersr.sort() outliersr.reverse() for i, d in outliersr: if d < rmsd_cutoff: continue del alist[i] return None
def SuperimposeAtomsOutlierRejection(alist, rmsd_cutoff=1.0, max_cycles=100): """Superimpose two homologus protein chains. The argument alist is a list of 2-tuples. The 2-tuples are the 1:1 atoms to superimpose. The alignment procedure incrementally omits atoms with large deviations until the rmsd of the least squares superposition is less than or equal to rmsd_cutoff, or the number of cycles exceeds max_cycles. """ for cycle in xrange(max_cycles): sresult = SuperimposeAtoms(alist) print "Cycle %d NA: %5d RMSD %6.2f" % (cycle, sresult.num_atoms, sresult.rmsd) if sresult.rmsd <= rmsd_cutoff: return sresult deviation = [] for i in xrange(len(alist)): satm, datm = alist[i] spos = sresult.transform(satm.position) deviation.append((AtomMath.length(spos - datm.position), i)) deviation.sort() outliers = deviation[-10:] outliersr = [(x[1], x[0]) for x in outliers] outliersr.sort() outliersr.reverse() for i, d in outliersr: if d < rmsd_cutoff: continue del alist[i] return None
def glr_normal(self, n): """ """ ## just rotate the normal R = self.matrix[:3, :3] nr = numpy.dot(R, n) if self.normalize == True: self.normal = AtomMath.normalize(nr) else: self.normal = nr
def glr_normal3(self, x, y, z): """ """ ## just rotate the normal R = self.matrix[:3, :3] n = numpy.array([x, y, z], float) nr = numpy.dot(R, n) if self.normalize == True: self.normal = AtomMath.normalize(nr) else: self.normal = nr
def glr_axis(self, position, axis, radius): """Draw a vector axis using the current set material at position with the given radius. """ ## don't bother redering small axes -- they look like junk if numpy.allclose(AtomMath.length(axis), 0.0): return self.object_list.append( (5, dot43(self.matrix, position), dot43(self.matrix, position + axis), radius, self.material_color_r, self.material_color_g, self.material_color_b))
def test_module(): import random import AtomMath import FileIO import Structure R = AtomMath.rmatrixu(numpy.array((0.0, 0.0, 1.0), float), math.pi / 2.0) struct1 = FileIO.LoadStructure(fil="/home/jpaint/8rxn/8rxn.pdb") struct2 = FileIO.LoadStructure(fil="/home/jpaint/8rxn/8rxn.pdb") chn1 = struct1.get_chain("A") chn2 = struct2.get_chain("A") rc = lambda: 0.1 * (random.random() - 1.0) for atm in chn2.iter_atoms(): atm.position = numpy.matrixmultiply(R, atm.position) + numpy.array( (rc(), rc(), rc()), float) alist = [] for atm1 in chn1.iter_atoms(): if atm1.name != "CA": continue atm2 = chn2.get_equivalent_atom(atm1) if atm2 == None: continue alist.append((atm1, atm2)) sup = SuperimposeAtoms(alist) R = sup.R Q = sup.Q print Q print R so = sup.src_origin do = sup.dst_origin sup1 = Structure.Structure(structure_id="JMP1") for atm in chn1.iter_atoms(): atm.position = numpy.matrixmultiply(R, atm.position - so) sup1.add_atom(atm) FileIO.SaveStructure(fil="super1.pdb", struct=sup1) sup2 = Structure.Structure(structure_id="JMP2") for atm in chn2.iter_atoms(): atm.position = atm.position - do sup2.add_atom(atm) FileIO.SaveStructure(fil="super2.pdb", struct=sup2)
def test_module(): import random import AtomMath import FileIO import Structure R = AtomMath.rmatrixu(numpy.array((0.0, 0.0, 1.0), float), math.pi/2.0) struct1 = FileIO.LoadStructure(fil="/home/jpaint/8rxn/8rxn.pdb") struct2 = FileIO.LoadStructure(fil="/home/jpaint/8rxn/8rxn.pdb") chn1 = struct1.get_chain("A") chn2 = struct2.get_chain("A") rc = lambda: 0.1 * (random.random() - 1.0) for atm in chn2.iter_atoms(): atm.position = numpy.matrixmultiply(R, atm.position) + numpy.array((rc(),rc(),rc()),float) alist = [] for atm1 in chn1.iter_atoms(): if atm1.name != "CA": continue atm2 = chn2.get_equivalent_atom(atm1) if atm2 == None: continue alist.append((atm1, atm2)) sup = SuperimposeAtoms(alist) R = sup.R Q = sup.Q print Q print R so = sup.src_origin do = sup.dst_origin sup1 = Structure.Structure(structure_id = "JMP1") for atm in chn1.iter_atoms(): atm.position = numpy.matrixmultiply(R, atm.position - so) sup1.add_atom(atm) FileIO.SaveStructure(fil="super1.pdb", struct=sup1) sup2 = Structure.Structure(structure_id = "JMP2") for atm in chn2.iter_atoms(): atm.position = atm.position - do sup2.add_atom(atm) FileIO.SaveStructure(fil="super2.pdb", struct=sup2)
def glr_axis(self, position, axis, radius): """Draw a vector axis using the current set material at position with the given radius. """ ## don't bother redering small axes -- they look like junk if numpy.allclose(AtomMath.length(axis), 0.0): return end = position + axis l = AtomMath.length(axis) R = AtomMath.rmatrixz(axis) glPushMatrix() self.glr_mult_matrix_Rt(R, position) glEnable(GL_LIGHTING) quad = gluNewQuadric() gluCylindar(quad, radius, radius, l, 10, 1) glDisable(GL_LIGHTING) glPopMatrix()
def iter_struct_orth_symops(self, struct): """Iterate over the orthogonal-space symmetry operations which will place a symmetry related structure near the argument struct. """ ## compute the centroid of the structure n = 0 cent = numpy.zeros(3, float) for atm in struct.iter_all_atoms(): n += 1 cent += atm.position centroid = cent / n ccell = self.calc_cell(self.calc_orth_to_frac(centroid)) centroid_cell = numpy.array(ccell, float) ## compute the distance from the centroid to the farthest point from ## it in the structure. max_dist = 0.0 for frag in struct.iter_amino_acids(): for atm in frag.iter_atoms(): dist = AtomMath.length(atm.position - centroid) max_dist = max(max_dist, dist) max_dist2 = 2.0 * max_dist + 5.0 for symop in self.space_group.iter_symops(): for i, j, k in self.cell_search_iter(): cell_t = numpy.array([i, j, k], float) symop_t = SpaceGroups.SymOp(symop.R, symop.t+cell_t) xyz = self.calc_orth_to_frac(centroid) xyz_symm = symop_t(xyz) centroid2 = self.calc_frac_to_orth(xyz_symm) if AtomMath.length(centroid - centroid2) <= max_dist2: yield self.calc_orth_symop(symop_t)
def glr_axis(self, position, axis, radius): """Draw a vector axis using the current set material at position with the given radius. """ ## don't bother redering small axes -- they look like junk if numpy.allclose(AtomMath.length(axis), 0.0): return self.object_list.append( ( 5, dot43(self.matrix, position), dot43(self.matrix, position + axis), radius, self.material_color_r, self.material_color_g, self.material_color_b, ) )
def glr_rotate_axis(self, deg, axis): """ """ R = AtomMath.rmatrixu(axis, deg * Constants.DEG2RAD) self.glr_mult_matrix_R(R)