Package Bio :: Package PDB :: Module Superimposer'
[hide private]
[frames] | no frames]

Source Code for Module Bio.PDB.Superimposer'

 1  # Copyright (C) 2002, Thomas Hamelryck (thamelry@binf.ku.dk) 
 2  # This code is part of the Biopython distribution and governed by its 
 3  # license.  Please see the LICENSE file that should have been included 
 4  # as part of this package. 
 5   
 6  """Superimpose two structures.""" 
 7   
 8  from __future__ import print_function 
 9   
10  import numpy 
11   
12  from Bio.SVDSuperimposer import SVDSuperimposer 
13  from Bio.PDB.PDBExceptions import PDBException 
14   
15   
16 -class Superimposer(object):
17 """Rotate/translate one set of atoms on top of another, 18 thereby minimizing the RMSD. 19 """ 20
21 - def __init__(self):
22 self.rotran = None 23 self.rms = None
24
25 - def set_atoms(self, fixed, moving):
26 """Put (translate/rotate) the atoms in fixed on the atoms in 27 moving, in such a way that the RMSD is minimized. 28 29 @param fixed: list of (fixed) atoms 30 @param moving: list of (moving) atoms 31 @type fixed,moving: [L{Atom}, L{Atom},...] 32 """ 33 if not (len(fixed) == len(moving)): 34 raise PDBException("Fixed and moving atom lists differ in size") 35 l = len(fixed) 36 fixed_coord = numpy.zeros((l, 3)) 37 moving_coord = numpy.zeros((l, 3)) 38 for i in range(0, len(fixed)): 39 fixed_coord[i] = fixed[i].get_coord() 40 moving_coord[i] = moving[i].get_coord() 41 sup = SVDSuperimposer() 42 sup.set(fixed_coord, moving_coord) 43 sup.run() 44 self.rms = sup.get_rms() 45 self.rotran = sup.get_rotran()
46
47 - def apply(self, atom_list):
48 """Rotate/translate a list of atoms.""" 49 if self.rotran is None: 50 raise PDBException("No transformation has been calculated yet") 51 rot, tran = self.rotran 52 rot = rot.astype('f') 53 tran = tran.astype('f') 54 for atom in atom_list: 55 atom.transform(rot, tran)
56