ó
¾÷Ic           @   sQ  d  d l  m Z m Z m Z m Z d  d l m Z m Z d d! d „  ƒ  YZ e	 d k rMe d d d g d	 d
 d g d d d g d d d g g d ƒ Z
 e d d d g d d d g d d d g d d d g g d ƒ Z e ƒ  Z e j e
 e ƒ e j ƒ  e j ƒ  Z e j ƒ  \ Z Z e e e ƒ e Z e j ƒ  Z e GHHe GHHd e GHn  d  S("   iÿÿÿÿ(   t   dott	   transposet   sqrtt   array(   t   svdt   dett   SVDSuperimposerc           B   s_   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z RS(
   s®  
    SVDSuperimposer finds the best rotation and translation to put
    two point sets on top of each other (minimizing the RMSD). This is 
    eg. useful to superimpose crystal structures.  

    SVD stands for Singular Value Decomposition, which is used to calculate
    the superposition.

    Reference:

    Matrix computations, 2nd ed. Golub, G. & Van Loan, CF., The Johns 
    Hopkins University Press, Baltimore, 1989
    c         C   s   |  j  ƒ  d  S(   N(   t   _clear(   t   self(    (    s–   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SVDSuperimposer/SVDSuperimposer.pyt   __init__   s    c         C   sC   d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  S(   N(   t   Nonet   reference_coordst   coordst   transformed_coordst   rott   trant   rmst   init_rms(   R   (    (    s–   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SVDSuperimposer/SVDSuperimposer.pyR      s    						c         C   s5   | | } | j  d } t t t | | ƒ ƒ | ƒ S(   s2   Return rms deviations between coords1 and coords2.i    (   t   shapeR   t   sum(   R   t   coords1t   coords2t   difft   l(    (    s–   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SVDSuperimposer/SVDSuperimposer.pyt   _rms%   s    
c         C   s   |  j  ƒ  | |  _ | |  _ | j } | j } | | k s_ | d | d k oY d k n rn t d ƒ ‚ n  | d |  _ d S(   s   
        Set the coordinates to be superimposed.
        coords will be put on top of reference_coords.

        o reference_coords: an NxDIM array
        o coords: an NxDIM array

        DIM is the dimension of the points, N is the number
        of points to be superimposed.
        i   i   s%   Coordinate number/dimension mismatch.i    N(   R   R   R   R   t	   Exceptiont   n(   R   R   R   R   t   m(    (    s–   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SVDSuperimposer/SVDSuperimposer.pyt   set-   s    
				1c   	      C   s/  |  j  d k s |  j d k r- t d ƒ ‚ n  |  j  } |  j } t | ƒ |  j } t | ƒ |  j } | | } | | } t t | ƒ | ƒ } t | ƒ \ } } } t t t | ƒ t | ƒ ƒ ƒ |  _	 t
 |  j	 ƒ d k  r| d | d <t t t | ƒ t | ƒ ƒ ƒ |  _	 n  | t | |  j	 ƒ |  _ d S(   s    Superimpose the coordinate sets.s   No coordinates set.i    i   N(   R   R
   R   R   R   R   R    R   R   R   R   R   (	   R   R   R   t   av1t   av2t   at   ut   dt   vt(    (    s–   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SVDSuperimposer/SVDSuperimposer.pyt   runC   s    		

$'c         C   sƒ   |  j  d k s |  j d k r- t d ƒ ‚ n  |  j d k rK t d ƒ ‚ n  |  j d k r| t |  j  |  j ƒ |  j |  _ n  |  j S(   s#   Get the transformed coordinate set.s   No coordinates set.s   Nothing superimposed yet.N(   R   R
   R   R   R   R   R    R   (   R   (    (    s–   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SVDSuperimposer/SVDSuperimposer.pyt   get_transformedX   s    "c         C   s.   |  j  d k r t d ƒ ‚ n  |  j  |  j f S(   s2   Right multiplying rotation matrix and translation.s   Nothing superimposed yet.N(   R   R
   R   R   (   R   (    (    s–   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SVDSuperimposer/SVDSuperimposer.pyt
   get_rotranb   s    c         C   sR   |  j  d k r t d ƒ ‚ n  |  j d k rK |  j |  j  |  j ƒ |  _ n  |  j S(   s8   Root mean square deviation of untransformed coordinates.s   No coordinates set yet.N(   R   R
   R   R   R   R   (   R   (    (    s–   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SVDSuperimposer/SVDSuperimposer.pyt   get_init_rmsh   s
    c         C   s=   |  j  d k r6 |  j ƒ  } |  j | |  j ƒ |  _  n  |  j  S(   s7   Root mean square deviation of superimposed coordinates.N(   R   R
   R$   R   R   (   R   R   (    (    s–   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SVDSuperimposer/SVDSuperimposer.pyt   get_rmsp   s    (   t   __name__t
   __module__t   __doc__R	   R   R   R   R#   R$   R%   R&   R'   (    (    (    s–   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SVDSuperimposer/SVDSuperimposer.pyR   	   s   							
		t   __main__g33333ÓI@gffffffþ¿g)\ÂõI@g333333I@g®Gáz®ó¿g33333SI@g×£p=
WI@g{®Gáz¤¿g…ëQ¸ÅI@g\Âõ(I@g{®Gáz”¿gÍÌÌÌÌlJ@t   fgfffff¦I@gìQ¸…ëÀg…ëQ¸EG@gìQ¸…‹I@g®Gázþ¿g
×£p=ÊG@g®Gáz.J@g333333ó¿g¤p=
×H@g{®GáZJ@gáz®Gáò¿gq=
×£°H@s   %.2fN(    (   t   numpyR    R   R   R   t   numpy.linalgR   R   R   R(   t   xt   yt   supR   R#   R'   R   R%   R   R   t   y_on_x1R$   t   y_on_x2(    (    (    s–   /oak/stanford/groups/akundaje/marinovg/programs/biopython-1.50.tar.gz/biopython-1.50/build/lib.linux-x86_64-2.7/Bio/SVDSuperimposer/SVDSuperimposer.pyt   <module>   s.   "o	
