ó

šxTc           @   s  d  d l  Z d  d l m Z d  d l Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d	 e f d
 „  ƒ  YZ	 d e f d „  ƒ  YZ
 d e f d „  ƒ  YZ d „  Z d „  Z d e ƒ  d „ Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d S(   iÿÿÿÿN(   t   flext   EnsembleInfoc           B   s   e  Z d  Z d „  Z RS(   s=   
    Information about ensemble extent, centre, symmetry
    c      	   C   s¹  d d  l  } | j ƒ  } | j ƒ  } g  | D] } | j ƒ  ^ q+ } | j ƒ  t j g  | D]0 } | j j j	 | rw | n d t
 ƒ j ƒ  ^ qY ƒ } t d | d | ƒ |  _ |  j j |  _ |  j j | |  j j j ƒ  \ }	 }
 } d d t j d t j t |	 ƒ t |	 ƒ t |
 ƒ t |
 ƒ t | ƒ t | ƒ g ƒ ƒ |  _ d d l m } | j ƒ  } | j d	 | ƒ g  | j ƒ  j ƒ  D]* } t j j | j ƒ  | j  ƒ  f ƒ ^ q‚|  _! d  S(
   Niÿÿÿÿs    Ct   coordst   weightsg      ð?g      @g      à?(   t   ncst   root("   t   cctbx.eltbx.tiny_pset   atomst   extract_xyzt!   determine_chemical_element_simplet   extract_occR    t   doublet   eltbxt   tiny_pset   tablet   Truet   weightt   PrincipalComponentst	   principalt   centret   rt   tt   partst   sumt   maxt   mint   extentt   phaserR   t   EnsembleSymmetryt   set_roott   get_point_groupt   get_operatorst   scitbxt   matrixt   rtt   get_rotationt   get_translationt   pgops(   t   selfR   t   cctbxR   R   t   at   elemst   eR   t   txst   tyst   tzsR   t   ensymt   op(    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/template_new.pyt   __init__   s$    >)	J(   t   __name__t
   __module__t   __doc__R0   (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/template_new.pyR      s   t   MapEnsembleInfoc           B   s   e  Z d  Z d „  Z RS(   sB   
    Information about ensemble defined with electron density
    c         C   sl   | |  _  t | ƒ t | ƒ |  _ d d l m } t j j | j	 j
 j ƒ  | j	 j
 j ƒ  f ƒ g |  _ d  S(   Niÿÿÿÿ(   R   (   R   R   t   lenR   R   R   R    R!   R"   t   Operatort   unityR#   R$   R%   (   R&   R   R   R   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/template_new.pyR0   )   s
    		(   R1   R2   R3   R0   (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/template_new.pyR4   $   s   R   c           B   s   e  Z d  Z d „  Z RS(   s)   
    Principal components of inertia
    c         C   s¦  t  j | ƒ } d | t j j | | j ƒ  ƒ |  _ | |  j j ƒ  \ } } } t  j | | | ƒ } t  j | | | ƒ } t  j | | | ƒ }	 t  j | | | ƒ }
 t  j | | | ƒ } t  j | | | ƒ } d d l m } | j	 |
 | | | | |
 | |	 | f ƒ } | j
 ƒ  } t j j t | d d !ƒ t | d d !ƒ t | d d !ƒ ƒ } | j ƒ  d k  r…| } n  | j |  _ | |  j |  _ d  S(   Ng      ð?iÿÿÿÿ(   t   eigensystemi   i	   i   i    (   R    R   R    R!   t   colR   R   t   scitbx.linalgR8   t   real_symmetrict   vectorst   sqrt   tuplet   determinantR)   R   R   (   R&   R   R   t   totalt   xst   yst   zst   xxt   xyt   xzt   yyt   yzt   zzR8   t   eigt   eivt   inertia(    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/template_new.pyR0   ;   s&    '*	8
(   R1   R2   R3   R0   (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/template_new.pyR   6   s   t   CrystalInfoc           B   s   e  Z d  Z d „  Z RS(   s   
    Symmetry information
    c         C   s4  | |  _  | |  _ t j j | j ƒ  ƒ |  _ t j j | j ƒ  ƒ |  _ | j	 ƒ  |  _
 g  |  j
 D]$ } t j j | j ƒ  j ƒ  ƒ ^ qa |  _ g  |  j D] } |  j | |  j ^ q˜ |  _ | |  _ |  j j ƒ  j ƒ  |  _ t j j |  j j ƒ  j ƒ  j ƒ  ƒ |  _ t j j |  j j ƒ  j ƒ  j ƒ  ƒ |  _ d  S(   N(   t   cellt   space_groupR    R!   R=   t   fractionalization_matrixt   to_fract   orthogonalization_matrixt   to_ortht   all_opst   sgopsR   t	   as_doublet   frac_rotationst   orth_rotationst   dmint   typet   cb_opt   ct   to_reference_settingt   c_invt   from_reference_setting(   R&   RO   RN   RY   R/   t   m(    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/template_new.pyR0   \   s    		7-		!	(   R1   R2   R3   R0   (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/template_new.pyRM   W   s   t   PeakInfoc           B   s/   e  Z d  Z d „  Z d „  Z e d „  ƒ Z RS(   s.   
    Information about a placed ensemble 
    c         C   sG   | |  _  | |  _ | | j |  _ t j j | j |  j ƒ ƒ |  _ d  S(   N(	   t   transformationt   ensembleR   t   centre_orthR    R!   R9   t   fractionalizet   centre_frac(   R&   Rb   Rc   RN   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/template_new.pyR0   x   s
    			c      
   C   sG   t  j j d | j | ƒ f ƒ } |  j d | |  j d |  j d | ƒ S(   Ni   i    Rb   Rc   RN   (	   i   i    i    i    i   i    i    i    i   (   R    R!   R"   t   orthogonalizet	   __class__Rb   Rc   (   R&   t   shiftRN   t   shiftop(    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/template_new.pyt
   translated‚   s    			c         C   s4   |  d t  j j | | j | ƒ f ƒ d | d | ƒ S(   NRb   Rc   RN   (   R    R!   R"   Rg   (   t   clst   rotationt   translationRc   RN   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/template_new.pyt   from_phaser_solution�   s
    	(   R1   R2   R3   R0   Rk   t   classmethodRo   (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/template_new.pyRa   s   s   	
	t   MatchTolerancec           B   s>   e  Z d  Z i  Z d „  Z d „  Z d „  Z e d „  ƒ Z RS(   s$   
    Tolerances for equivalence
    c         C   s   | |  _  | |  _ d  S(   N(   Rm   Rn   (   R&   Rm   Rn   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/template_new.pyR0   ¢   s    	c         C   sB   t  | t t f ƒ s t ‚ n  |  j d |  j | d |  j | ƒ S(   NRm   Rn   (   t
   isinstancet   intt   floatt   NotImplementedRh   Rm   Rn   (   R&   t   other(    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/template_new.pyt   __mul__¨   s
    		c         C   s   |  j  d | ƒ S(   NRv   (   Rw   (   R&   Rv   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/template_new.pyt   __rmul__³   s    c         C   sg   | | f } | |  j  k r\ |  d d t j | j d | j ƒ d | j d ƒ |  j  | <n  |  j  | S(   NRm   g       @g      @Rn   g      @(   t   MT_FORt   matht   atanRY   R   (   Rl   t   crystalRc   t   key(    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/template_new.pyt   from_ensemble¸   s    !(	   R1   R2   R3   Ry   R0   Rw   Rx   Rp   R~   (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/template_new.pyRq   ›   s   			c           c   s	   d Vd S(   s5   
    No origin shifts between the two structures
    i    N(   i    i    i    (    (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/template_new.pyt   no_origin_shiftÆ   s    c         c   sr  d d l  m } | j | j ƒ } | j t d t ƒ } | j | | j j ƒ  | ƒ } t d | j	 ƒ  d | j
 d | j ƒ } | j | j j | j ƒ ƒ }	 | j | |	 j ƒ  | j |	 ƒ ƒ }
 |
 j ƒ  sÐ t ‚ |
 j ƒ  } t j ƒ  } xƒ |  D]{ } xr | D]j } t d | d | d	 | d
 | d | ƒ } | s5qü n  | \ } } } t j j | d ƒ } | | j Vqü Wqï Wd S(   so   
    Origin shifts consistent with space group symmetry that link at least one
    molecule to another one
    iÿÿÿÿ(   t   sgtbxi    RO   RN   RY   t   leftt   rightt   shift_flagsR|   t
   multiplierN(   i    i    i    (   R'   R€   t   structure_seminvariantsRO   t   search_symmetry_flagsR   t   search_symmetryRZ   RM   t   subgroupRN   RY   t   change_basisR[   t   continuous_shifts_are_principalt   AssertionErrort   continuous_shift_flagsR    t   vec3_doublet   symmetry_operators_betweenR    R!   R9   R)   (   R�   R‚   R|   R„   R€   t   semist   flagst   ssymt	   euclidiant   reference_space_groupt   reference_ssymRƒ   t   originst   lR   t   matcht   sgopt   pgopRi   t   transformed(    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/template_new.pyt   plausible_origin_shiftsÎ   s<    			g      ð?c         C   s¨   t  d „  |  Dƒ ƒ t  d „  | Dƒ ƒ k r0 t Sxq | D]i } t d |  d g  | D]! } | j d | d | j ƒ ^ qP d | d | ƒ } t d	 „  | Dƒ ƒ r7 t Sq7 Wt S(
   sJ   
    Determines whether all peaks in left have an equivalent in right
    c         s   s   |  ] } | j  Vq d  S(   N(   Rc   (   t   .0R–   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/template_new.pys	   <genexpr>	  s    c         s   s   |  ] } | j  Vq d  S(   N(   Rc   (   Rœ   R   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/template_new.pys	   <genexpr>	  s    R�   R‚   Ri   RN   R|   R„   c         s   s-   |  ]# \ } } | d  k	 o$ | d  k	 Vq d  S(   N(   t   None(   Rœ   R–   R   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/template_new.pys	   <genexpr>  s    (   t   sortedt   Falset   overlap_iteratorRk   RN   t   allR   (   R�   R‚   R|   R„   R•   t   oriR   t   pairs(    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/template_new.pyt   is_symmetry_equivalentý   s    ,.	c      	   C   s\   t  d |  d | d | d | ƒ } g  | D]0 \ } } | d k	 r( | d k	 r( | | f ^ q( S(   s?   
    Pairs peaks from left with their equivalents in right
    R�   R‚   R|   R„   N(   R    R�   (   R�   R‚   R|   R„   R£   R–   R   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/template_new.pyt   overlap  s    	c         c   s¯   t  | ƒ } x€ |  D]x } d  } xH | D]@ } t d | d | d t t t f d | d | ƒ r& | } Pq& q& W| r€ | j | ƒ n  | | f Vq Wx | D] } d  | f Vq– Wd  S(   NR�   R‚   Rƒ   R|   R„   (   t   setR�   RŽ   RŸ   t   remove(   R�   R‚   R|   R„   t   copyR–   t   matchedR   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/template_new.pyR    +  s"    	c         C   sv  |  j  | j  k rr|  j  } | t j d | d | ƒ } x8t d |  j d | j d | ƒ D]\ } } }	 | j |	 }
 t j j g  t	 | |
 j
 ƒ D] \ } } | rª | n d ^ q‘ ƒ } |
 | 7}
 | j | } t j j | j j | j |
 ƒ ƒ } | j | j ƒ  k  rqY n  xX t d |  j j d | | j j d | ƒ D]+ \ } } | j | k  r]q<n  | | | f SWqY Wn  d S(   s…   
    Calculates whether left is a symmetry equivalent of right
    (considering crystal symmetry and model point group symmetry)
    R|   Rc   R�   R‚   i    N(   Rc   Rq   R~   t   orthogonal_distances_betweenRf   R]   R    R!   R9   t   zipR)   R_   RN   Rg   Rn   t   lengtht   rotation_differences_betweenRb   R   Rm   R�   (   R�   R‚   Rƒ   R|   R„   Rc   t	   toleranceR˜   t   orth_rotationt   deltat	   delta_reft   ft   dt	   shift_refRi   t   diffR™   t
   difference(    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/template_new.pyRŽ   F  s4    	
				;
		c         c   sƒ   x| t  | j | j ƒ D]e \ } } t j j | | ƒ } g  | |  j D] } t d | ƒ ^ qF } | | t j j | ƒ f Vq Wd S(   sg   
    Iterator returning orthogonal distance between left and all symmetry
    equivalents of right
    R²   N(   R«   RU   RX   R    R!   R9   R)   t   fractional_modulus(   R�   R‚   R|   R˜   R¯   Rš   t   vR°   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/template_new.pyRª   r  s    ")c         C   s"   |  d } d | k  r | d S| S(   Ng      ð?g      à?(    (   R²   R   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/template_new.pyR·   ~  s    
c         c   sC   |  j  ƒ  } x0 | j D]% } | t d | j | | ƒ f Vq Wd S(   s~   
    Iterator returning rotation angle differences between left and all
    point group equivalent orientations for right
    t   rotmatN(   t	   transposeR%   t   rotation_matrix_angleR   (   R�   R‚   Rc   Rº   R™   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/template_new.pyR­   „  s    c         C   sA   |  d |  d |  d d d } t  j t t | d ƒ d ƒ ƒ S(   s-   
    Rotation angle of a rotation matrix
    i    i   i   g      ð?g       @g      ð¿(   Rz   t   acosR   R   (   R¹   t   cosdel(    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/template_new.pyR»   “  s    "(   t   scitbx.matrixR    t   scitbx.array_familyR    Rz   t   objectR   R4   R   RM   Ra   Rq   R   R›   R¤   R¥   R    RŽ   Rª   R·   R­   R»   (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/template_new.pyt   <module>   s&   !(+		3		,			