def test_superimpose(): from mglutil.math.rigidFit import RigidfitBodyAligner rigidfitAligner = RigidfitBodyAligner() refCoords = [[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1]] mobCoords = [[10, 0, 0], [11, 0, 0], [10, 1, 0], [10, 0, 1]] rigidfitAligner.setRefCoords(refCoords) rigidfitAligner.rigidFit(mobCoords) rmsd = rigidfitAligner.rmsdAfterSuperimposition(mobCoords) assert diff(rmsd, 0.0)
def doit(self, refAtoms, mobAtoms, updateGeom=True, showRMSD=True): """ The SuperImposeAtomsCommand takes two set of Atoms of the same length compute the rotation and translation matrices to superimpose the mobAtoms onto the refAtoms using rigidFit module and then transform the corresponding geometry. updateGeom = True : transform the masterGeom of mobAtoms. showRMSD = True : print and return RMSD """ if refAtoms is None or mobAtoms is None: return assert isinstance(refAtoms, TreeNodeSet) assert isinstance(mobAtoms, TreeNodeSet) refAtoms = refAtoms.findType(Atom) mobAtoms = mobAtoms.findType(Atom) # validate the inputs if len(refAtoms) != len(mobAtoms): print "The two atomSet are not of equal length" return if len(refAtoms) < 3: print "At least three atoms are needed for superimposition" return refCoords = refAtoms.coords mobCoords = mobAtoms.coords rigidfitAligner = RigidfitBodyAligner() rigidfitAligner.setRefCoords(refCoords) rigidfitAligner.rigidFit(mobCoords) if updateGeom: rotMat = Numeric.identity(4).astype('d') rotMat[:3, :3] = rigidfitAligner.rotationMatrix transMat = Numeric.array(rigidfitAligner.translationMatrix) rotMat[3, :3] = transMat #print rotMat # the matrix mGeom = mobAtoms[0].top.geomContainer.masterGeom mGeom.SetRotation(Numeric.reshape(rotMat, (16, )).astype('f')) mGeom.viewer.Redraw() if showRMSD: rmsd = rigidfitAligner.rmsdAfterSuperimposition(mobCoords) print "RMSD = ", rmsd return rmsd else: return
ref_ats = AtomSet() ref_indices = list(map(int, ref_ll.split(','))) num_ref_indices = len(ref_indices) if num_ref_indices < 3: print(" At least 3 indices are required! only %d indices found!!!" % (num_ref_indices)) exit() for i in ref_indices: #ref_ats.append(ref_mol.allAtoms[i-1]) ref_ats.append(ref_mol.allAtoms.get(lambda x: x.number == i)[0]) num_ref_ats = len(ref_ats) #setup the tool for the rigid fit from mglutil.math.rigidFit import RigidfitBodyAligner RFA = RigidfitBodyAligner() RFA.setRefCoords(ref_ats.coords) #transform the rest of the molecules for l in lines[1:]: name, ll = l.split() ll.strip() moving_mol = Read(name)[0] indices = list(map(int, ll.split(','))) moving_ats = AtomSet() for i in indices: new_atoms = moving_mol.allAtoms.get(lambda x: x.number == i) if not len(new_atoms): print("There is no atom in %s with number %d" % (name, i)) break else:
lines = fptr.readlines() fptr.close() for l in lines: #handle blank lines gracefully l = l.strip() if len(l): first, second = list(map(int, l.split('-'))) moblist.append((first, second)) if verbose: print("moblist=", moblist) else: moblist = reflist[:] #refMol.chains.residues.atoms # all levels of hierarchical data structure #refMol.allAtoms # short cut to lowest level.... #mobMol.allAtoms #each atom has 'coords' attribute from mglutil.math.rigidFit import RigidfitBodyAligner rigidfitAligner = RigidfitBodyAligner() if string_for_atoms_to_use is None: string_for_atoms_to_use = "N_CA_C" names_to_use = string_for_atoms_to_use.split('_') refAtoms = get_atoms(refMol, reflist, names_to_use, verbose) refCoords = refAtoms.coords #or refMol.chains.residues.atoms.get('backbone').coords #check that there are some if len(refCoords) == 0: print("NO REF COORDS!!!") raise Exception( 'Unable to superimpose because no reference coordinates were specified!!!' ) mobAtoms = get_atoms(mobMol, moblist, names_to_use, verbose) mobCoords = mobAtoms.coords if len(mobCoords) == 0: print("NO MOB COORDS!!!")
def onAddCmdToViewer(self): self.rigidfitAligner = RigidfitBodyAligner()