ó
šxTc           @   s½  d  d l  m Z d  d l m Z d  d l m Z d  d l m Z d  d l m Z d  d l m	 Z	 d  d l
 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 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  e f d! „  ƒ  YZ d" „  Z d# „  Z d$ e f d% „  ƒ  YZ d& e f d' „  ƒ  YZ d( e f d) „  ƒ  YZ d* „  Z d+ e f d, „  ƒ  YZ  d- e f d. „  ƒ  YZ! d/ e f d0 „  ƒ  YZ" d1 e f d2 „  ƒ  YZ# d3 e f d4 „  ƒ  YZ$ d5 e f d6 „  ƒ  YZ% d7 e f d8 „  ƒ  YZ& d9 e f d: „  ƒ  YZ' d; „  Z( d< „  Z) d= „  Z* d> e f d? „  ƒ  YZ+ d@ e f dA „  ƒ  YZ, dB e f dC „  ƒ  YZ- dD e f dE „  ƒ  YZ. dF e f dG „  ƒ  YZ/ dH e f dI „  ƒ  YZ0 dJ e f dK „  ƒ  YZ1 dL e f dM „  ƒ  YZ2 dN e f dO „  ƒ  YZ3 dP e f dQ „  ƒ  YZ4 dR e f dS „  ƒ  YZ5 dT „  Z6 d S(U   iÿÿÿÿ(   t   division(   t   stage(   t   calculation(   t	   mr_object(   t   output(   t   SorryNt
   SelectBestc           B   s    e  Z d  Z d „  Z d „  Z RS(   s,   
    Select best of possible candidates
    c         C   s   | |  _  | |  _ d  S(   N(   t   _expertt   _type(   t   selft   expertt   type(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyt   __init__   s    	c         C   sØ   g  | j  d |  j ƒ D] } |  j | j k r | ^ q } | s\ | j j d d ƒ d  } nx | j j d d t | ƒ ƒ t | d d „  ƒ} | j j d d ƒ | j j	 ƒ  | j j d t
 | ƒ ƒ | j j ƒ  | S(   NR   t   msgs   No candidates founds   %s candidates foundt   keyc         S   s
   |  j  ƒ  S(   N(   t   score(   R   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyt   <lambda>%   s    s	   Selected:(   t   readR   R   t   processed_byR   t   debugt   Nonet   lent   maxt   indentt   strt   dedent(   R	   t   boardt   caset   contextt   ct
   candidatest   selected(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyt   __call__   s    	(   t   __name__t
   __module__t   __doc__R   R    (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR      s   	t   SelectRangec           B   s    e  Z d  Z d „  Z d „  Z RS(   s+   
    Select best N possible candidates
    c         C   s   | |  _  | |  _ | |  _ d  S(   N(   R   R   t   _count(   R	   R
   R   t   count(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR   3   s    		c         C   sù   g  | j  d |  j ƒ D] } |  j | j k r | ^ q } | s\ | j j d d ƒ d  } n™ | j j d d t | ƒ ƒ | j d d „  d t	 ƒ | |  j
  } | j j d d ƒ x@ t | d	 d
 ƒD], \ } } | j j d | | j ƒ  f ƒ qÅ W| S(   NR   R   s   No candidates founds   %s candidates foundR   c         S   s
   |  j  ƒ  S(   N(   R   (   t   s(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR   E   s    t   reverses	   Selected:t   starti   s   %d: %s(   R   R   R   R   R   R   R   R   t   sortt   TrueR%   t	   enumeratet   short(   R	   R   R   R   R   R   R   t   i(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR    :   s    	$(   R!   R"   R#   R   R    (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR$   .   s   	t   Suspendablec           B   s    e  Z d  Z d „  Z d „  Z RS(   s0   
    Suspend if certain objects are present
    c         C   s   | |  _  | |  _ d  S(   N(   t   _markert
   _selection(   R	   t   markert	   selection(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR   T   s    	c         C   se   g  | j  d |  j ƒ D] } | ^ q } | rE | j j d d ƒ d  S|  j d | d | d | ƒ Sd  S(   NR   R   s   Knowledge source suspendedR   R   R   (   R   R0   R   R   R   R1   (   R	   R   R   R   R   R   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR    Z   s
    ((   R!   R"   R#   R   R    (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR/   O   s   	t   FindEnsemblec           B   s€   e  Z d  Z d e j e j f d e j e j f d e j e j f d e j	 e j
 f g Z d „  Z d „  Z d „  Z d „  Z RS(	   s*   
    Find ensembles for missing part 
    s   Models:s   Collections:s
   Templates:s   Homology search hits:c         C   s   t  d |  d t j ƒ |  _ d  S(   NR
   R   (   R   R   t   Initialt   inspect(   R	   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR   r   s    c         C   s>  | j  j |  ƒ | j j d t j d d ƒ ƒ | j j d d d d ƒ | j j d d | j ƒ  ƒ | j j d t j ƒ  ƒ | j j d t | ƒ ƒ x� |  j	 D]v \ } } } | j j d t j
 d | ƒ ƒ | j j ƒ  |  j d | d	 | d
 | d | d | d | ƒ | j j ƒ  q¡ W| j j d t j d d ƒ ƒ d  S(   NR   t   texts   Composition analysist   messaget   statust   datas   Space group %st	   candidateR   R   R   t   intypet   outtypes   Composition analysis finished(   R   t   addR   t   verboset   subtitlet   notifyt   space_group_symbolt   blankR   t   SCANSt   headingR   t   fetch_and_identifyR   t   section_close(   R	   R;   R   R   R   t   captionR<   R=   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyt
   manipulatew   s(    	c         C   sT  | j  j j d | ƒ | j j d | ƒ } | j d d „  d t ƒ | j j d d t | ƒ ƒ | j j d d ƒ g  } x… t | d d	 ƒD]q \ }	 }
 | j	 j
 d
 |
 j ƒ sÔ | j j d d |	 |
 f ƒ q� n  | j j d d |	 |
 f ƒ | j |
 ƒ q� WxK t | d d	 ƒD]7 \ }	 }
 | d | d |
 d |	 ƒ } | j d | ƒ qWd  S(   NR   R   c         S   s
   |  j  ƒ  S(   N(   R   (   t   e(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR   —   s    R(   R   s   Available: %dt    R)   i   t   others#   %d: %s - not in missing compositions!   %d: %s - applicable for extensiont   initialR<   t   indext   obj(   t   problemR:   R   R*   R+   R   R?   R   R,   t   missingt   containst   compositiont   appendt   write(   R	   R;   R   R   R   R<   R=   t	   availablet   acceptedRN   RO   t   st(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRF   ”   s&    +	c         C   s   d S(   Nt   EnsembleFind(    (   R	   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyt   __str__±   s    (   R!   R"   R#   R   t   EnsembleR   t   ModelCollectiont   Templatet   ModelTemplatet   HomologySearchHitt   TemplateHitRD   R   RI   RF   RZ   (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR4   f   s   			t   RotationSearchc           B   sD   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s6   
    Performs rotation search for ensemble stages
    c         C   s+   t  d t j d |  j ƒ |  _ | |  _ d  S(   NR2   R3   (   R/   R   t
   Suspensiont   selectR6   t   cutoff(   R	   Rd   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR   »   s    	c   	      C   sE  t  g  | j j j d t j ƒ D]3 } t | j t j ƒ r | j j | j j	 f ^ q ƒ } g  | j d t
 j ƒ D]6 } |  | j k rq | j ƒ  | j	 f | k rq | ^ qq } | sÏ | j j d d ƒ d  } nr | j j d d t | ƒ ƒ t | d d „  ƒ} | j j d d ƒ | j j ƒ  | j j d | ƒ | j j ƒ  | S(   NR   R   s   No candidates founds   %s candidates foundR   c         S   s
   |  j  ƒ  S(   N(   R   (   R   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR   Ù   s    s	   Selected:(   t   setRP   R:   R   R   t   Progresst
   isinstanceRa   t   partialt   ensembleR   R[   R   R   R   R   R   R   R   R   (	   R	   R   R   R   t   progt
   submittedsR   R   R   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRc   Ä   s"    6'	c      	   C   s+  | j  j |  ƒ | j j d t j d d ƒ ƒ | j j d d d d ƒ | j j d d | j ƒ  ƒ | j j d t j ƒ  ƒ | j j d | ƒ t j	 d | j
 ƒ  d | j ƒ  d	 | j d
 |  j ƒ } | j j d t j d d ƒ ƒ | j j j d t j d | ƒ ƒ | j j d |  d | d | ƒ d  S(   NR   R7   s   Rotation searchR8   R9   R:   s   Space group %sRh   Ri   Rd   s   Rotation job submittedRO   R   t   ownert   extra(   R   R>   R   R?   R@   RA   RB   RC   R   Ra   t   calculation_dataRh   Ri   Rd   RG   RP   R:   RU   Rf   t   queuet   submit(   R	   R;   R   R   R   t   calc(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRI   â   s    		"c         C   sÎ  d d l  m } | j j d t j d d ƒ ƒ | j j d d d d	 ƒ | j j d d
 | j ƒ  ƒ | j j d t j ƒ  ƒ | j j d t | ƒ ƒ | j j d t j ƒ  ƒ g  | j	 j
 j d | j ƒ D] } | j | k rÌ | ^ qÌ }	 t |	 ƒ d k st ‚ | j	 j
 j |	 d ƒ | j d | ƒ }
 | j j d d ƒ | j j d |
 j ƒ | j | j	 j k r¢| j j d d ƒ | j ƒ  | j	 j
 j d |
 ƒ n  |  j d |
 d | d | d | d | ƒ d  S(   Niÿÿÿÿ(   R   R   R7   s   Rotation function processingR8   R9   R:   s   Rotation function evaluations   Space group %sR   i   i    t   resultss   Logfile:s4   Rotation function valid for all space groups: storedRO   t   resultRi   R   R   R   (   t   phaser.pipelineR   R   R?   R@   RA   RB   RC   R   RP   R:   R   Rf   R   t   AssertionErrort   deletet   processR   t   logfileRh   t   roott   cleanupRU   t   place_peaks(   R	   R   Rs   Rm   R   R   R   Rq   t   pt   progresst   res(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRw   ú   s8    "
	c   	      C   sÇ   | j  j d d t | j ƒ ƒ x� t | j d d ƒD]j \ } } | j  j d d ƒ | j  j d d | | f ƒ t j d | d | d	 | ƒ } | j d
 | ƒ q6 W| j  j d t  j d d ƒ ƒ d  S(   NR   s   Peaks above threshold: %dR)   i   RK   s   %d: %sRi   t   peakRN   RO   R7   s%   Rotation function processing finished(	   R   R?   R   R:   R,   R   t   NormalRotationRU   RG   (	   R	   Rs   Ri   R   R   R   R.   R|   RX   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR{   $  s    "		c         C   s   d S(   NRa   (    (   R	   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRZ   9  s    (	   R!   R"   R#   R   Rc   RI   Rw   R{   RZ   (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRa   ¶   s   					*	t   ApplyRotationSearchResultsc           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   sS   
    Reinstates existing rotation searches (only important for first molecule)
    c         C   s   | |  _  d  S(   N(   t   rotation_search_expert(   R	   R‚   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR   C  s    c            s«   |  j  j d | d | d | ƒ ‰  ˆ  s+ d  S‡  f d †  | j j j d t j ƒ Dƒ } y | j ƒ  } Wn% t	 k
 r� | j
 j d d ƒ d  SX| j
 j d d ƒ ˆ  | f S(	   NR   R   R   c         3   sW   |  ]M } t  | j t j ƒ r | j j ˆ  j ƒ  k r | j j ˆ  j k r | Vq d  S(   N(   Rg   R   Ra   Rh   Ri   (   t   .0R~   (   R   (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pys	   <genexpr>T  s    R   R   s*   No search has been performed for this peaks+   Selected rotation search has been performed(   R‚   R6   R   RP   R:   R   R   t   Resultt   nextt   StopIterationR   R   (   R	   R   R   R   t   calcst   search(    (   R   sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR6   H  s    	+c         C   sÏ   | \ } } | j  j |  j ƒ | j j d t j d d ƒ ƒ | j j d d d d ƒ | j j d d | j ƒ  ƒ | j j d t j ƒ  ƒ | j j d | ƒ |  j j	 d	 | d
 | d | d | d | ƒ d  S(   NR   R7   s   Apply rotation search resultsR8   R9   R:   s3   Apply rotation search results for other space groups   Space group %sRs   Ri   R   R   R   (
   R   R>   R‚   R   R?   R@   RA   RB   RC   R{   (   R	   R;   R   R   R   R   Rˆ   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRI   f  s     c         C   s   d S(   NR�   (    (   R	   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRZ   ~  s    (   R!   R"   R#   R   R6   RI   RZ   (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR�   >  s
   			t   TranslationSearchc           B   s;   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s9   
    Performs translation search for rotation stages
    c         C   s   t  d |  d t j ƒ |  _ d  S(   NR
   R   (   R   R   t   RotationR6   (   R	   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR   ˆ  s    c         C   sÞ  | j  j |  ƒ | j j d t j d d ƒ ƒ | j j d d d d ƒ | j j d d | j ƒ  ƒ | j j d t j ƒ  ƒ | j j d t | ƒ ƒ t	 | j
 ƒ  j ƒ d k ro| j ƒ  d	 k ro| j j d d
 ƒ |  j d t j d | j j d | j j d d d | j j d | j j d d ƒ g d | d | d | d | ƒ t | _ | j j d t j d d ƒ ƒ nk t j d | j ƒ  d | j
 ƒ  d | j ƒ } | j j d t j d d ƒ ƒ | j j d |  d | d | ƒ d  S(   NR   R7   s   Translation searchR8   R9   R:   s   Space group %si    i   s?   P1 space group with empty located part: skip translation searcht   peaksRi   t   rotationt   translationg        t   tft   tfzt   bfactorR   R   R   s   Translation function finishedRh   t   rpeaks   Translation job submittedRl   R   Rm   (   g        g        g        (   R   R>   R   R?   R@   RA   RB   RC   R   R   Rh   R‹   t   space_group_numberR{   R   t   TranslationPeakR   Ri   RŒ   t   rft   rfzR+   t   translation_doneRG   R   R‰   Rn   Ro   Rp   (   R	   R;   R   R   R   Rq   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRI   �  s@    -				c         C   sR  | j  j d t  j d d ƒ ƒ | j  j d d d d ƒ | j  j d d | j ƒ  ƒ | j  j d t  j ƒ  ƒ | j  j d t | ƒ ƒ | j  j d t  j ƒ  ƒ | j d	 | ƒ } | j  j d d
 ƒ | j  j d | j	 ƒ | j  j d d t
 | j ƒ ƒ |  j d | j d | d | d | d | ƒ t | _ | j  j d t  j d d ƒ ƒ d  S(   NR   R7   s   Translation function processingR8   R9   R:   s   Translation function evaluations   Space group %sRr   s   Logfile:s   Peaks above threshold: %dR‹   RŒ   R   R   R   s(   Translation function processing finished(   R   R?   R@   RA   RB   RC   R   Rw   R   Rx   R   R:   R{   R+   R–   RG   (   R	   R   Rs   Rm   R   R   R   R~   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRw   ½  s,     			c   	      C   s…   x~ t  | d d ƒD]j \ } } | j j d d ƒ | j j d d | | f ƒ t j d | d | d | ƒ } | j d	 | ƒ q Wd  S(
   NR)   i   R   RK   s   %d: %sRŒ   R   RN   RO   (   R,   R   R?   R   t   TranslationRU   (	   R	   R‹   RŒ   R   R   R   R.   R|   RX   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR{   Ý  s    		c         C   s   d S(   NR‰   (    (   R	   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRZ   ê  s    (   R!   R"   R#   R   RI   Rw   R{   RZ   (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR‰   ƒ  s   		0	 	t   PooledPackingCheckc           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   sI   
    Performs packing check for translation stages pooling all peaks
    c         C   s%   t  d t j d |  d | ƒ |  _ d  S(   NR   R
   R&   (   R$   R   R—   R6   (   R	   t   pool(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR   ô  s    	c      	   C   sš  | j  j d t  j d d ƒ ƒ | j  j d d d d ƒ | j  j d d | j ƒ  ƒ | j  j d t  j ƒ  ƒ | j  j d d t | ƒ ƒ | j  j d d	 ƒ | j  j ƒ  xJ | D]B } | j  j d t | ƒ ƒ | j  j d d	 ƒ | j	 j
 |  ƒ q² Wt j d | j ƒ  d
 g  | D] } | j ƒ  ^ qd g  | D] } | j ^ q3ƒ } | j  j ƒ  | j  j d t  j d d ƒ ƒ | j j d |  d | d | ƒ d  S(   NR   R7   s   Packing checkR8   R9   R:   s   Space group %ss
   Pooled: %dRK   t   partialst   tpeakss   Packing job submittedRl   R   Rm   (   R   R?   R@   RA   RB   RC   R   R   R   R   R>   R   t   SinglePoolPackingCheckRn   Rh   R   R   RG   Ro   Rp   (   R	   R;   R   R   R   R   Rq   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRI   ý  s&    	c         C   sÅ  | j  j d t  j d d ƒ ƒ | j  j d d d d ƒ | j  j d d | j ƒ  ƒ | j  j d t  j ƒ  ƒ | j d	 | ƒ } | j  j d d
 ƒ | j  j d | j ƒ t	 | j
 ƒ t	 | ƒ k sÊ t ‚ xÕ t | j
 | ƒ D]Á \ } }	 | rd }
 t j d |	 d | ƒ } n d }
 t j d |	 ƒ } | j  j d d |
 ƒ | j  j ƒ  | j  j d t |	 ƒ ƒ | j  j ƒ  | j  j d d ƒ | j d | ƒ t |	 _ qÝ W| j  j d t  j d d ƒ ƒ d  S(   NR   R7   s   Packing check processingR8   R9   R:   s   Packing check evaluations   Space group %sRr   s   Logfile:t   PASSR�   R   t   FAILSs   Peak: %sRK   RO   s!   Packing check processing finished(   R   R?   R@   RA   RB   RC   Rw   R   Rx   R   R:   Ru   t   zipR   t   Packedt   ClashR   R   R   RU   R+   t   packing_doneRG   (   R	   R   Rs   Rm   R   R   R   R~   t   dR   t   verdictRX   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRw     s0    !c         C   s   d S(   NR˜   (    (   R	   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRZ   ;  s    (   R!   R"   R#   R   RI   Rw   RZ   (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR˜   ï  s
   				#t   SuperposeSolvec           B   sD   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   sV   
    Finds ensembles that could be superposed on a solutions to get new solutions
    c            s¦   ‡  f d †  | j  d t j ƒ Dƒ } y | j ƒ  } Wn* t k
 ra | j j d d ƒ d  } nA X| j j d d ƒ | j j ƒ  | j j d | ƒ | j j	 ƒ  | S(   Nc         3   s0   |  ]& } | j  ƒ  r ˆ  | j k r | Vq d  S(   N(   t   significantR   (   Rƒ   R   (   R	   (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pys	   <genexpr>G  s    R   R   s   No candidates founds	   Selected:(
   t   readiterR   t   ScoredR…   R†   R   R   R   R   R   (   R	   R   R   R   R   R   (    (   R	   sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR6   E  s    %
c      
   C   s÷  | j  j d t  j d d ƒ ƒ | j  j d d d d ƒ | j  j d d | j ƒ  ƒ | j  j d t  j ƒ  ƒ | j  j d t | ƒ ƒ | j  j d d	 ƒ | j j |  ƒ | j	 ƒ  s¼ t
 ‚ | j  j d d
 ƒ | j  j d d	 ƒ | j ƒ  j } | j ƒ  } g  | j d t j ƒ D]- } | j | k r| j ƒ  | k r| ^ q} g  }	 xf | D]^ } | j j d | j j ƒ szqSn  | j j d | j j ƒ }
 |
 j ƒ  rS|	 j | ƒ qSqSW| j  j d d t |	 ƒ ƒ | j  j d d	 ƒ xì|	 D]ä} | j  j d d | j ƒ | j | k s!t
 ‚ | j  j ƒ  z‡ y@ | j j d | j ƒ  d | j d | j ƒ  d | j  j ƒ } Wn@ t k
 r³} | j  j d d | ƒ | j  j d d ƒ wìn XWd  | j  j ƒ  X| j ƒ  j j ƒ  | j j ƒ  k r<| j  j d d ƒ t j d | j  ƒ  d | j! ƒ  d | d | j" ƒ } |  j# } nF | j  j d d ƒ t j$ d | j  ƒ  d | j! ƒ  d | ƒ } |  j% } | j  j d d ƒ | j  j d d	 ƒ | j& j' d |  d | d | | | f ƒ qìW| j  j d t  j( d d ƒ ƒ d  S(   NR   R7   s   Template structure solutionR8   R9   R:   s   Superpose solutions   Space group %sRK   s*   This peak is significant and could be usedR   RL   s   Applicable: %s casess   Replacement ensemble: %sR   Ri   t   cellt   streams   Superposition error: %ss   Alternative rejecteds1   Different ensembles: do refinement before scoringRh   t   protocols>   Ensembles have the same template: no refinement before scorings   Evaluation job submittedRl   R   Rm   s$   Template structure solution finished()   R   R?   R@   RA   RB   RC   R   R   R>   R¦   Ru   R   Ri   RM   R   R   R[   RS   RR   t   overlapt   superposableRT   R   R   t   superpositiont
   substitutet   uctbx_unit_cellt   RuntimeErrorR   t   superpose_templateR   t   RefinedEvaluationRn   Rh   t   b_factor_refinementt   process_refinedt
   Evaluationt   process_unrefinedRo   Rp   RG   (   R	   R;   R   R   R   Ri   RM   RJ   t   estagest
   applicableR¬   t   esR   Rq   t   method(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRI   Z  s‚    - 	$				c         C   s‰  | j  j d t  j d d ƒ ƒ | j  j d d d d ƒ | j  j d d | j ƒ  ƒ | j  j d t  j ƒ  ƒ | \ } } }	 | j  j d t | ƒ ƒ | j  j d t  j d d	 | j ƒ ƒ | j	 d
 | ƒ }
 |
 j
 d |
 j
 d } } | s| j  j d d ƒ | j  j d d ƒ d  S| j  j d d ƒ |	 d | d |
 j
 d | d | d | ƒ } | j d | ƒ | j  j d t  j d d ƒ ƒ d  S(   NR   R7   s(   Template structure evaluation processingR8   R9   R:   s   Superpose solution evaluations   Space group %ss   Replacement ensemble: %sRr   i    i   s!   Generated peak fails packing tests   Discarding this solutions   Accepting this solutionR   Ri   t   templateR   RO   s1   Template structure evaluation processing finished(   R   R?   R@   RA   RB   RC   R   RE   Ri   Rw   R:   RU   RG   (   R	   R   Rs   Rm   R   R   R   R¼   Rº   R»   R~   t   is_pakR   RX   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRw   ·  s8    			c      	   C   sE   | j  j d d | j | j f ƒ t j d | d | d | d t ƒ S(   NR   s&   Peak statistics: tf = %.3f, tfz = %.2fRi   R¼   R   t   refined(   R   R?   RŽ   R�   R   t	   Templatedt   False(   R	   R   R:   Ri   R¼   R   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR·   ß  s    	c         C   sX   | d } | j  j d d | j | j | f ƒ t j d | d | d | d t d | ƒ S(	   Ni   R   s2   Peak statistics: tf = %.3f, tfz = %.2f, llg = %.2fRi   R¼   R   R¾   t   llg(   R   R?   RŽ   R�   R   R¿   R+   (   R	   R   R:   Ri   R¼   R   RÁ   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRµ   ì  s    
	c         C   s   d S(   NR¥   (    (   R	   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRZ   û  s    (	   R!   R"   R#   R6   RI   Rw   R·   Rµ   RZ   (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR¥   @  s   		]	(		t   RotationPeakSalvagec           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s}   
    Transfer good rotation peaks to the next round (if there is one) in order to
    save rotation function calculation
    c         C   s   t  d |  d t j ƒ |  _ d  S(   NR
   R   (   R   R   R[   R6   (   R	   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR     s    c         C   s&  | j  j d t  j d d ƒ ƒ | j  j d d d d ƒ | j  j d d | j ƒ  ƒ | j  j d t  j ƒ  ƒ | j  j d t | ƒ ƒ | j  j d d	 ƒ | j j |  ƒ g  | j	 j
 d
 t j ƒ D]6 } | j | j ƒ  k rÃ | j j | j k rÃ | ^ qÃ } | s(| j  j d t  j d d ƒ ƒ d  S| j d d „  ƒ g  } xq t | d d ƒD]] \ } } t j d | d | j d | ƒ }	 | j d |	 ƒ | j |	 ƒ | j	 j d | ƒ qTW| j  j d d t | ƒ ƒ t j d t d | d | ƒ ƒ }
 | j d |
 ƒ | j  j d t  j d d ƒ ƒ d  S(   NR   R7   s-   Previously located significant rotation peaksR8   R9   R:   s8   Reinstate significant rotation peaks found in last cycles   Space group %sRK   R   s!   No previously located peaks foundR   c         S   s
   |  j  j S(   N(   R   R”   (   t   r(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR   &  s    R)   i   Ri   R   RN   RO   s   Reinstating: %d peakst	   conditionR   t	   rotationss?   Rotation searches are suspended until these peaks are processed(   R   R?   R@   RA   RB   RC   R   R   R>   R:   R   R   t   HistoricRotationt	   structureRh   R   Ri   RG   R*   R,   R   t   PreviouslyEstablishedRotationRU   RT   Rv   R   Rb   t   RotationsExplored(   R	   R;   R   R   R   t   hrt   relatedRÅ   RN   t   rpt
   suspension(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRI     sD    !					c         C   s§  | j  j d t  j d d ƒ ƒ | j  j d d d d ƒ t g  | j d t j ƒ D] } | j ^ qQ ƒ } g  | j d t j	 ƒ D]* } d	 | j
 j k r | | k r | ^ q }	 | j  j d d
 t |	 ƒ ƒ g  }
 x¯| D]§} | j ƒ  } g  |	 D] } | | j ƒ  k rò | ^ qò } | s"qÙ n  | j  j d t  j d d ƒ ƒ | j  j ƒ  | j  j d t  j d d ƒ ƒ | j  j ƒ  | j  j d t | ƒ ƒ | j  j ƒ  | j  j d t  j d d ƒ ƒ | j  j ƒ  | j d d „  d t ƒ x~ t | d d ƒD]j \ } } | j  j d d | | j
 f ƒ | j  j d d ƒ t j d | j d | j
 ƒ } |
 j | ƒ qøW| j  j ƒ  | j  j ƒ  qÙ W| j  j d t  j d d ƒ ƒ |
 S(   NR   R7   s&   Rotation peak salvage - identificationR8   R9   R:   s.   Search for untested significant rotation peaksR   g      @s)   Unexplored significant rotation peaks: %ds   Associations:s
   Structure:s   Peaks:R   c         S   s
   |  j  ƒ  S(   N(   R   (   R'   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR   e  s    R(   R)   i   s   %d: %sRK   RÇ   R   s   Rotation peak salvage finished(   R   R?   R@   RA   Re   R   R   R—   RŒ   RŠ   R   R•   R   RM   RE   R   R   R   R*   R+   R,   R   t   GenuineRotationRÇ   RT   RG   (   R	   R   R   R   t	   solutionst   postprocessingsR'   t   usedsR   t   unusedsR‹   RM   RÃ   t   foundR.   t   hrot(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR    ?  sL    .*+ 		c         C   s   d S(   NRÂ   (    (   R	   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRZ   {  s    (   R!   R"   R#   R   RI   R    RZ   (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRÂ      s
   		4	<RÉ   c           B   s    e  Z d  Z d „  Z d „  Z RS(   sJ   
    Suspension until packing jobs starting from rotation peak finish
    c         C   s   | |  _  t | ƒ |  _ d  S(   N(   R   Re   RÅ   (   R	   R   RÅ   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR   …  s    	c            sI   t  d „  ˆ  j Dƒ ƒ s t St  ‡  f d †  ˆ  j j d t j ƒ Dƒ ƒ S(   Nc         s   s   |  ] } | j  Vq d  S(   N(   R–   (   Rƒ   RÃ   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pys	   <genexpr>�  s    c         3   s*   |  ]  } | j  ˆ  j k r | j Vq d  S(   N(   RŒ   RÅ   R¢   (   Rƒ   R'   (   R	   (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pys	   <genexpr>�  s    R   (   t   allRÅ   RÀ   R   R   R   R—   (   R	   (    (   R	   sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR    ‹  s    (   R!   R"   R#   R   R    (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRÉ   €  s   	t   PeakEvaluatec           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   sN   
    Evaluate potential peaks that have been associated with a structure 
    c         C   s   t  d |  d t j ƒ |  _ d  S(   NR
   R   (   R   R   R[   R6   (   R	   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR   ™  s    c      
   C   s“  | j  j d t  j d d ƒ ƒ | j  j d d d d ƒ | j  j d d | j ƒ  ƒ | j  j d t  j ƒ  ƒ | j  j d | ƒ | j  j d t  j ƒ  ƒ | j j |  ƒ | j ƒ  } | j	 ƒ  } g  | j
 j d	 t j ƒ D]' } | j d
 | d | j ƒ rÛ | ^ qÛ } | s1| j  j d t  j d d ƒ ƒ d  Sx)t | d d ƒD]\ }	 }
 |
 j d
 | d |	 ƒ } | j  j d | ƒ | j  j ƒ  | j  j d | j ƒ | j  j ƒ  | j d | d | ƒ } | j  j d d | j j ƒ t j d d „  ƒ } | j d | ƒ | j j d |  d | d | | | f ƒ | j
 j d |
 ƒ | j  j d t  j ƒ  ƒ qDW| j  j d d ƒ | j  j d t  j d d ƒ ƒ d  S(   NR   R7   s   Peak evaluationR8   R9   R:   s   Evaluate potential peakss   Space group %sR   Rh   Ri   s!   No previously located peaks foundR)   i   RN   R   s   Evaluation job (%s) submittedRÄ   c           S   s   t  S(   N(   RÀ   (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR   ¿  s    RO   Rl   R   Rm   s;   Rotation searches suspended until these peaks are processeds   Peak evaluation finished(   R   R?   R@   RA   RB   RC   R   R>   Rh   Rn   R:   R   R   t   PotentialPeakt
   is_relatedRi   RG   R,   t   get_handler_forR   R   R   R   t	   __class__R!   R   Rb   RU   Ro   Rp   Rv   (   R	   R;   R   R   R   Rh   R:   t   ppRË   RN   R   t   handlerRq   RÍ   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRI   ž  sH    'c         C   s  | j  j d t  j d d ƒ ƒ | j  j d d d d ƒ | j  j d d | j ƒ  ƒ | j  j d t  j ƒ  ƒ | \ } } }	 | j d	 |	 ƒ | j  j d | ƒ | j  j d t  j ƒ  ƒ | j  j d | ƒ | j  j d d
 | j ƒ | j  j d t  j ƒ  ƒ | j d | j d | ƒ ƒ }
 |
 j	 s€| j  j d d ƒ | j  j d d ƒ t
 j d | j d | j ƒ } | j j d	 | ƒ ni | j  j d d |
 j ƒ | j  j d d |
 j ƒ | j  j d d ƒ | j d	 | j d | d |
 ƒ ƒ | j  j d t  j d d ƒ ƒ d  S(   NR   R7   s   Peak evaluation processingR8   R9   R:   s   Evaluate peak rescoring resultss   Space group %sRO   s
   %s (trial)Rs   Rr   s!   Generated peak fails packing tests   Discarding this solutionRÇ   R   s
   %s (final)s   Peak statistics: %ss   Accepting this solutiont   parents#   Peak evaluation processing finished(   R   R?   R@   RA   RB   RC   Rv   R   Rw   R½   R   t   FillFailureRecordRÇ   R:   RU   t
   statisticsR   RG   (   R	   R   Rs   Rm   R   R   R   Ri   RÜ   RÍ   R~   t   failure(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRw   Ò  s8    			"c         C   s   d S(   NRÖ   (    (   R	   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRZ   ú  s    (   R!   R"   R#   R   RI   Rw   RZ   (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRÖ   ”  s
   		4	(t   Amalgamationc           B   sz   e  Z d  Z d „  Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z	 e d „  ƒ Z
 d „  Z RS(	   s>   
    Mix solutions if coming from the same starting point
    c         C   s�  | j  j d t  j d d ƒ ƒ | j  j d d d d ƒ |  j d | ƒ rä | j  j d d	 ƒ d
 d l m } | j | j ƒ  ƒ } |  j	 d | ƒ r¼ | j  j d d ƒ |  j
 } |  j }	 qÿ | j  j d d ƒ |  j } |  j }	 n d. g } |  j } |  j }	 g  | D] }
 |
 j j r|
 ^ q} g  | D] }
 |
 j j r+|
 ^ q+} | j  j d d t | ƒ ƒ | j  j d t  j d d ƒ ƒ g  } d
 d l m } x | D]˜} | j  j d d ƒ | j  j ƒ  | j  j d t | ƒ ƒ | j  j ƒ  | j ƒ  } g  | | D]$ }
 | j j d |
 j ƒ r|
 ^ q} | j  j d d ƒ | j  j d t | ƒ ƒ g  } | j j d
 } | j d t j d | g ƒ d t ƒ } | j  j ƒ  xà| D]Ø} | j  j d d ƒ | j  j d t | j ƒ ƒ | j j d
 } | j | j k r*| j  j d d ƒ | j | ƒ q­n  | j j  | j j  k rh| j  j d d ƒ | j | ƒ q­n  | j  j d d | j | j f ƒ | j  j ƒ  zj y: | j! j" d | d | j d | j# ƒ  d  | j  j$ ƒ } Wn) t% k
 r } | j  j d d! ƒ w­n XWd  | j  j ƒ  X| j d t j d | g ƒ ƒ } | j& d" | d# | ƒ sr| j  j d d$ ƒ | j | ƒ q­n  | j  j d d% ƒ q­W| j  j ƒ  | j  j d d ƒ | j  j d d& t | ƒ ƒ | sø| j  j d d' ƒ | j  j d d( ƒ q¢n  | j  j d d) t | ƒ ƒ | j' | d | j d* | d+ | ƒ ƒ q¢W| j  j d d ƒ |	 d, | d | d+ | ƒ } | j  j d t  j( d d- ƒ ƒ | S(/   NR   R7   s   Amalgamation - identificationR8   R9   R:   s&   Find solutions that can be amalgamatedRÏ   s*   Initial structure empty - undefined originiÿÿÿÿ(   t   AlterOriginSymmatet   originss4   Floating origin - extracting rotation component onlys/   Discrete origin - adding possible origin shiftsi    s   Significant peaks: %ds   Processing:(   t   matchings
   Structure:RL   RK   s   Potential peaks: %dRÇ   R‹   t   cacheds%   ACCEPTED: unique peak with same models)   ACCEPTED: peak with non-alternative models   Relating %s to %s:R   Ri   R©   Rª   s   REJECTED: no superpositiont   leftt   rights,   ACCEPTED: unique peak with alternative models/   REJECTED: identical peak with alternative models?   After filtering identical solutions with alternative models: %ds   No mixable peaks founds   
s   Accepted peaks: %dt   relatedsR   t
   collections   Amalgamation finished(   i    i    i    ()   R   R?   R@   RA   t   origin_undefinedt   phaserRâ   t   GetAllOriginsR’   t   is_floating_origint   rotation_peaks_collectt   rotation_peaks_collatet   associated_peaks_collectt   associated_peaks_collateRÇ   R¦   R   RE   Rä   R   R   R   RM   t	   evaluatedt   mixable_for_amalgamationR‹   t   create_matching_mr_structureR   t	   StructureR+   Ri   RT   RS   R®   R¯   R°   R   R±   t   is_equivalentt   extendRG   (   R	   R   R   R   RÏ   RÐ   Râ   Rã   t   collectt   collateR'   t   significantsRm   Rr   Rä   RX   RM   t   usablest	   acceptedsR   t   tmft   ut   latestt
   subst_peakRJ   t   equivt   possibilities(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR      sÊ    					%%$		 				c         C   s‡   g  } x6 |  D]. } | j  t | j ƒ  j ƒ  j ƒ d k ƒ q W| t g t |  ƒ k s} | t g t |  ƒ k s} t | ƒ ‚ t | ƒ S(   Ni    (	   RT   R   RM   Rh   R‹   R+   RÀ   Ru   t   any(   RÏ   t   odsR'   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRê   �  s
    ,>c   	   
   C   s¼   g  } x¯ t  | d d ƒD]› \ } } | j j d } t j d | j d | j d d d d ƒ } | j j d	 d
 | | f ƒ | j j d	 d ƒ t j	 d |  d | ƒ } | j
 | ƒ q W| S(   NR)   i   iÿÿÿÿRi   RŒ   R”   g        R•   R   s   %d: %sRK   RÇ   R   (   R,   RÇ   R‹   R   t   RotationPeakRi   RŒ   R   R?   t   ExtractedRotationRT   (	   RÇ   Rè   R   RÅ   R.   RÃ   R   RÌ   t   exrp(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRî   ª  s    						c         C   s!   | j  j d d t |  ƒ ƒ |  S(   NR   s!   Number of extracted rotations: %d(   R   R?   R   (   Ré   Rã   R   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRï   Â  s    c         C   s†   g  } xy t  | d d ƒD]e \ } } | j } | j j d d | | j d f ƒ | j j d d ƒ | j t |  | g ƒ ƒ q W| S(   NR)   i   R   s   %d: %siÿÿÿÿRK   (   R,   RÇ   R   R?   R‹   RT   t	   frozenset(   RÇ   Rè   R   t   associationsR.   RÃ   t   current(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRð   Ë  s    	c         C   sR   t  |  ƒ } | j j d d t | ƒ ƒ g  | D] } t j d | d | ƒ ^ q0 S(   NR   s@   Number of possibilities found (taking symmetry into account): %dt
   structuresRã   (   Re   R   R?   R   R   Rá   (   Ré   Rã   R   t   uniquest   fs(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRñ   Û  s
    c         C   s7   t  t t j |  d ƒ ƒ } t | j d d d g ƒ ƒ S(   Nt   xt   yt   z(    (   Re   t   reducet   operatorR>   t   boolt   intersection(   Rã   t   tokens(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRí   æ  s    c         C   s   d S(   NRá   (    (   R	   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRZ   í  s    (   R!   R"   R#   R    t   staticmethodRê   Rî   Rï   Rð   Rñ   Rí   RZ   (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRá   ÿ  s   	™	c      	   C   sl   |  j  j d | ƒ s! t d ‚ n  y( | j d |  d | d | d | ƒ } Wn t k
 rg } t d ‚ n X| S(   NRL   s   different compositionR   Ri   R©   Rª   s   no superposition(   Ri   t   substituteable_withR±   R¯   (   R   Ri   R©   R®   Rª   t   speakRJ   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyt   substitute_peakò  s    	c         C   sc   |  j  d | ƒ s t d ‚ n  y" | j d |  d | d | ƒ } Wn t k
 r^ } t d ‚ n X| S(   NRL   s   different compositiont	   referencet   movingRª   s   no superposition(   R  R±   t	   superpose(   R  R  R®   Rª   t   supRJ   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyt   get_superposition  s    	t   GeneratorSearchc           B   sM   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   sb   
    Recognizes generators (pure rotations around an axis)
    Only active in post-processing
    c         C   s   | |  _  d  S(   N(   t
   tolerances(   R	   R   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR     s    c         C   sp  | j  j d t  j d d ƒ ƒ | j  j d d d d ƒ g  | j d t j ƒ D] } | ^ qN } | j d	 d
 „  ƒ | j  j d d t | ƒ ƒ xº | D]² } | j  j d d | j	 ƒ |  j
 d | j d | d | ƒ } | j  j d d t | ƒ ƒ | r6| j d t j d | j d | ƒ ƒ | j  j d d ƒ n  | j  j d d ƒ q— W| j  j d t  j d d ƒ ƒ d  S(   NR   R7   s   Generator searchR8   R9   R:   s   Find generatorsR   R   c         S   s   |  j  S(   N(   RN   (   R'   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR   /  s    s   Analysing %s structuress   %d. structureRÇ   R   R   s"   Total %s geometric relations foundRO   t	   relationss$   Saved relations for further analysisRK   s   Generator search finished(   R   R?   t
   underlinedRA   R   R   t   ForSymmetryAnalysisR*   R   RN   t   find_assemblies_inRÇ   RU   t   StructureRelationsRG   (   R	   R   R   R   t   lRú   t   labelR!  (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR    "  s6    (						

c         C   s?  | j  ƒ  } g  } x&t | j d  ƒ D]\ } } | j j d d ƒ | j j d d | d | f ƒ | j j d t j ƒ  ƒ | j j d d ƒ | j j ƒ  | j d | ƒ j	 ƒ  } | j
 j ƒ  }	 xHt | j | d d | d ƒD]%\ }
 } | j j d d |
 d | f ƒ y7 t d	 | d
 | j
 d | d | j d | j j ƒ } WnF t k
 r”} | j j d d | ƒ | j j d t j ƒ  ƒ qè n X| j j d d ƒ |  j d | d | d | ƒ } | j j d d t | ƒ ƒ x't | d d ƒD]\ } } | j j d d | ƒ | j j d d | ƒ | | j d | ƒ } y |  j d | d
 |	 ƒ } Wn- t k
 r‘} | j j d d | ƒ qön X| j j d d ƒ | j j d d ƒ | j j d d | ƒ | j t j d t j d
 | j
 d | ƒ d | | f ƒ ƒ qöWqè W| j j ƒ  | j j d t j ƒ  ƒ q& W| S(   NiÿÿÿÿR   s   Reference peak:s   %s: %si   s   Comparing with other peaks:R©   R)   R   Ri   R®   Rª   s     REJECTED: %ss
     ACCEPTEDR  RL   R   s9     Testing %s symmetry equivalents for assembly memberships     %s. potential mate:s       %st   ops     Generator:t   settingt	   generatort   relating(   R°   R,   R‹   R   R?   RC   R   R   t   as_scitbx_rt_operatort   inverseRi   t   matching_ensemble_infoR  R®   R±   t   potential_assembly_members_forR   t   to_generator_formRT   R   t   ModelRelationt   GeneratorSettingR   (   R	   RÇ   R   R   R©   R!  t   i_refR  R-  t   einfot   i_otherRL   R  RJ   t   membersR.   t   mt   transft   gen(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR$  S  sf     !.!								c         C   sþ  | j  | j  k s t ‚ | j d | ƒ j ƒ  } | j d | ƒ j ƒ  } g  } d d  l } d d  l } | j  j ƒ  j }	 | j ƒ  }
 xs| j	 d | ƒ D]_\ } } | j
 j | j | j ƒ } | j
 j g  | j | D] } t | ƒ ^ qÖ ƒ } t j j d | j | j
 j | j j
 ƒ  ƒ j ƒ } | j
 j | j | j ƒ } x² | j d d d g d d ƒD]’ } | | j
 j | ƒ } | j
 j |
 j | | | j ƒ ƒ } |  j d	 | d
 |	 ƒ r`| j t j d | j  d | d | | j d d ƒ ƒ q`q`Wq— W| S(   NR   iÿÿÿÿRL   t   elementsi    i   t   repeati   t   deltat   extentRi   RŒ   R�   R�   (   Ri   Ru   t   create_matching_mr_peakt
   positionalt   scitbx.matrixt	   itertoolsR.  R=  R°   t   orthogonal_differences_betweent   matrixt   colt   sgopt   centret   roundR   RŠ   t   Matrixt   orth_rotationt   sqrRŒ   t   elemsR�   t   productt   orthogonalizet   sufficiently_closeRT   t   Peak(   R	   R  RL   R   t   tmf_reft	   tmf_othert
   potentialst   scitbxRA  R=  R©   t   symopR<  t   transformedt   nt   shiftRŒ   R�   t	   neighbourt   ishiftt   npos(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR/  ž  s6    	)(%			c      	   C   s¸   y= t  j j d | d |  j j d |  j j d |  j j ƒ } Wn t k
 r[ } t | ‚ n XxU | j	 ƒ  D]G } | | j
 } | j
 | } |  j d | d | j ƒ si t d ‚ qi qi W| S(   NR(  t   max_foldt   angulart   spatialR<  R=  s&   Generated assembly larger than allowed(   R   t	   Generatort   from_scitbx_rt_operatorR   R[  t   max_angular_errort   max_spatial_errort
   ValueErrorR±   t   nontrivial_seriesRF  RN  R=  (   R	   R(  Ri   R*  RJ   t   oR
  R<  (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR0  Ç  s    c         C   s   | j  ƒ  | |  j j k S(   N(   t   lengthR   t   max_relative_assembly_size(   R	   R<  R=  (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRN  Þ  s    c         C   s   d S(   Ns   Generator search(    (   R	   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRZ   ã  s    (
   R!   R"   R#   R   R    R$  R/  R0  RN  RZ   (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR    s   		1	K	)		t   GeneratorClassifyAveragec           B   s;   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   sO   
    Averages near-identical generators
    Only active in post-processing
    c         C   s   | |  _  d  S(   N(   R   (   R	   R   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR   î  s    c      	   C   sÇ  | j  j d t  j d d ƒ ƒ | j  j d d d d ƒ t g  | j d t j ƒ D] } | j | j	 f ^ qQ ƒ } | j  j d d	 t
 | ƒ ƒ t t t j g  | j ƒ  D]+ \ } } g  | D] } | | f ^ q» ^ q¨ g  ƒ ƒ } | j  j d d
 t
 | ƒ ƒ |  j d | j ƒ  d | ƒ }	 | j  j d d t
 |	 ƒ ƒ xg |	 j ƒ  D]Y \ }
 } t j d |
 ƒ } x( | D]  } | j d | | d | ƒ qlW| j d | ƒ qGW| j  j d t  j d d ƒ ƒ d  S(   NR   R7   s&   Generator classification and averagingR8   R9   R:   s   Classify and average generatorsR   s4   Analysing geometric relations data for %s structuress   %s relations foundR!  R   s   %s clusters formedt   averageRÇ   t   relationRO   s!   Generator classification finished(   R   R?   R"  RA   t   dictR   R   R%  RÇ   R!  R   R  R  R>   t   itemst   merge_equivalent_assembliest   keyst   GeneratorClusterRU   RG   (   R	   R   R   R   RÃ   t   analysis_forR'   t   relst	   origin_oft   components_ofRh  R6  t   gclustt   rel(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR    ó  s6    4;		c            s6  t  | ƒ } i  } x| r1| j ƒ  } | j j d d ƒ | j j d | j ƒ | j j d d ƒ | j j ƒ  t j d ‡  f d †  ƒ } | j d | j j	 | f ƒ xt
 | ƒ D]} | j j d d ƒ | j j d | j ƒ y: t d | j j d	 | j j d
 | j d | j j ƒ } WnF t k
 re}	 | j j d d |	 ƒ | j j d t j ƒ  ƒ q´ n X| j j	 j d | j ƒ }
 | j j d d |
 ƒ | j d |
 | f ƒ | j | ƒ q´ W| j j ƒ  x_t | j ƒ  d d ƒD]E\ } } | j j d d | t | ƒ f ƒ d t | ƒ k  s,t ‚ t t j g  | D] \ } } | j ^ q<ƒ j ƒ  } d t | ƒ t t j g  | D] \ } } | j ^ q}ƒ } t  g  | D] \ } } | j ^ q¦ƒ } xc| r)t | ƒ } | j | ƒ i  } g  | D]! \ } } | j | k ró| ^ qó| | <xx t
 | ƒ D]j } | | k  sCt ‚ | | d k r+| j | ƒ g  | D]! \ } } | j | k rg| ^ qg| | <q+q+Wt j  d | j j d t j! j" d ˆ  j# d | ƒ d | d | ƒ ƒ } t t j | j$ ƒ  ƒ } | j j d d | j	 t | ƒ f ƒ | | | <qÇWqåWq W| S(   NR   s
   Reference:s+   Transform other assemblies to same ensembleRi  c            s0   |  d j  d | d d ˆ  j j d ˆ  j j ƒ S(   Ni    RL   t   max_misalignmentRa  (   t   approx_equal_spatiallyR   t   min_axis_alignmentRa  (   Ræ   Rç   (   R	   (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR   1  s    
t   values   Trial:R  R  R®   Rª   s     REJECTED: %st	   operations   Transformed generator: %sR)   i   s   Cluster %s: %s elementsi    g      ð?Ri   R*  t   foldt   generators_witht   axisRF  s)   Averaged operator: %s (from %s operators)(%   Re   t   popR   R?   R)  R   R   t   EquivalenceRelationR>   R*  t   listR  Ri   R®   R   R±   RC   RU  t   transformationt   removeR   R,   t   classesR   Ru   R  R  R|  t	   normalizeRF  Rz  R   R2  R^  t   newt   determine_generator_foldt   values(   R	   R!  R   t	   remainingt
   members_ofR  R  t   trialR  RJ   t   trRN   t   clusterR(  Rt  R|  RF  t   unmerged_foldst   highestR{  t   oft   averR6  (    (   R	   sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRl  #  s~    			%+,(	29			c         C   s…   | s t  ‚ t g  | j ƒ  D] } t | ƒ ^ q ƒ } x> t | d t ƒD]* } |  j j t | | ƒ | k rJ | SqJ Wt d ‚ d  S(   NR(   s$   This statement should not be reached(	   Ru   R   R†  R   t   sortedR+   R   t   min_fold_fractionR±   (   R	   R{  t   vt   highest_countR   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR…  †  s    + c         C   s   d S(   Ns&   Generator classification and averaging(    (   R	   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRZ   ’  s    (   R!   R"   R#   R   R    Rl  R…  RZ   (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRg  è  s   		0	c	t   PointGroupDeterminec           B   sH   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z i e d 6Z RS(   si   
    Analyzes averaged generators and turn them into point groups
    Only active in post-processing
    c         C   s   | |  _  d  S(   N(   R   (   R	   R   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR   �  s    c         C   s�  | j  j d t  j d d ƒ ƒ | j  j d d d d ƒ | j d t j ƒ } | j  j d d	 t | ƒ ƒ g  } x_ |  j j	 ƒ  D]N \ } } | |  d
 | ƒ} | j  j d d t | ƒ | f ƒ | j
 | ƒ q€ W| j  j d d t | ƒ ƒ | j  j d d ƒ |  j d | d | ƒ }	 xA |	 D]9 }
 | j  j d d t |
 j j ƒ ƒ | j d |
 ƒ q!W| j  j d t  j d d ƒ ƒ d  S(   NR   R7   s   Point group determinationR8   R9   R:   s   Determine point group symmetryR   s   %s generators foundt   clusterss   %s %s founds   %s point groups founds"   Merging subgroups into supergroupst   analysesR   s   Symmetry id: %sRO   s"   Point group determination finished(   R   R?   R"  RA   R   R   Rn  R   t
   METHOD_FORRk  R÷   t   find_supergroupst   idR)  t   point_groupRU   RG   (   R	   R   R   R   t	   averagedsR–  t   nameR»   t
   symmetriest   highestsRO   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR    ¢  s*    #c         C   sp   g  } xc | D][ } | j  t j d t j d | j j d t j d | j j ƒ ƒ d | j d | g ƒ ƒ q W| S(   NR)  Ri   Rš  R|  t   relations_fromt	   formed_by(	   RT   R   t   SymmetryAnalysist   SymmetrySettingRh  Ri   t   RotationAxisR*  RŸ  (   R	   R•  R�  t   clust(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyt   find_rotation_axesÆ  s    				c         C   så   t  | ƒ } g  } xÌ | rà t | d d „  ƒ} | j j d d | j ƒ | j | ƒ | j | ƒ xv t | ƒ D]h } | j j d d | j ƒ | j d | ƒ rÆ | j j d d ƒ | j | ƒ qq | j j d d ƒ qq Wq W| S(	   NR   c         S   s   t  |  j j j ƒ  ƒ S(   N(   R   R)  Rš  t   series(   R'   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR   á  s    R   s   Highest symmetry: %ss   Testing: %sRL   s     CONTAINEDs     NOT contained(	   Re   R   R   R?   R)  RT   R�  R  RR   (   R	   R–  R   R‡  t   supergroupsR�  R‰  (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR˜  Û  s    	c         C   s   d S(   Ns   Point group determination(    (   R	   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRZ   ó  s    s   rotation axes(	   R!   R"   R#   R   R    R¥  R˜  RZ   R—  (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR”  —  s   		$			c         C   s7   t  j ƒ  } x! |  D] } | j d | j ƒ q W| j S(   sG   
    Determines which molecules are related by a specific symnetry
    Ri  (   R   t   EquivalenceRelationChainR>   R+  R‚  (   R!  t   ecRÃ   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyt    find_symmetry_related_assembliesý  s    t   SymmetryComparec           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   sC   
    Compares new symmetries with that has been located before
    c         C   s   | |  _  d  S(   N(   R   (   R	   R   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR     s    c      	   C   s  | j  j d t  j d d ƒ ƒ | j  j d d d d ƒ | j j d t j ƒ } | j  j d d	 t | ƒ ƒ | j d t j	 ƒ } xpt
 | d
 d ƒD]\\ } } | j  j d d | ƒ | j  j d d ƒ | j  j ƒ  g  } g  }	 xÏ | D]Ç }
 | j  j d d |
 ƒ y+ |  j d |
 d | j d | ƒ \ } } Wn* t k
 r_} | j  j d d | ƒ n X| r‰| j  j d d ƒ |	 j |
 ƒ n  | rë | j  j d d ƒ | j |
 ƒ që që W| j  j ƒ  t j d | d |	 d | ƒ } | j d | ƒ q• W| j  j d t  j d d ƒ ƒ d  S(   NR   R7   s   Symmetry comparisonR8   R9   R:   s1   Compare found and existing point group symmetriesR   s   %s symmetries knownR)   i   s   %s. symmetrys#   Compare with existing point groups:s   Compare: %st   existingR‰  R   s     REJECTED: %ss     KNOWN CONTAINS NOVELs     NOVEL CONTAINS KNOWNt   analysist   contained_byRR   RO   s   Symmetry comparison finished(   R   R?   R"  RA   R:   R   R   R¢  R   R¡  R,   R   t"   determine_containment_relationshipR)  R±   RT   R   t   SymmetrySetRelationAnalysisRU   RG   (   R	   R   R   R   t   knownR–  RN   R­  t   trial_containst   trial_contained_byR¬  R®  RR   RJ   R!  (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR      sJ    				c      	   C   s¬   t  d | j d | j d | j d | j j ƒ } | j j d | j ƒ } | j j d | d |  j	 j
 d |  j	 j ƒ } | j d | j d |  j	 j
 d |  j	 j ƒ } | | f S(	   NR  R  R®   Rª   Ry  RL   t   min_cos_anglet   max_spatial_disp(   R  Ri   R®   R   R   Rš  RU  R€  t   approx_containsR   Rw  Ra  (   R	   R¬  R‰  R   R  RŠ  R®  RR   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR¯  M  s    					(   R!   R"   R#   R   R    R¯  (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR«  
  s   		9t   SymmetryCreationPolicyc           B   s   e  Z d  Z d „  Z RS(   s$   
    Creates novel point groups
    c   
      C   s_  | j  j d t  j d d ƒ ƒ | j  j d d d d ƒ | j  j d d ƒ g  | j d	 t j ƒ D] } | j sa | ^ qa } | j  j d d
 t | ƒ ƒ x  | D]˜ } | j	 j
 d | j j ƒ t g  | j j j ƒ  D]! \ } } | t d | ƒ f ^ qÕ ƒ }	 | j
 d t j d | d |	 ƒ ƒ | j  j d d | ƒ q  W| j  j d t  j d d ƒ ƒ d  S(   NR   R7   s   Symmetry creationR8   R9   R:   s   Rationalise point groupss   Create novel point groupsR   s    %s novel point groups identifiedRO   R!  R­  t   assemblies_ins	   %s: SAVEDs   Symmetry creation finished(   R   R?   R"  RA   R   R   R°  R®  R   R:   RU   R­  R)  Rj  RŸ  Rk  Rª  t   NewSymmetryRG   (
   R	   R   R   R   t   srR§  t   srat   structRp  R¸  (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR    k  s,    :		
(   R!   R"   R#   R    (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR·  f  s   t   SymmetrySubgroupPolicyc           B   s&   e  Z d  Z d „  Z e d „  ƒ Z RS(   sR   
    Controls what to do with point groups that are not the highest available
    c      
   C   s  | j  j d t  j d d ƒ ƒ | j  j d d d d ƒ | j  j d d ƒ | j d	 t j ƒ } | j  j d d
 t | ƒ ƒ xy t | d d ƒD]e \ } } | j  j d d | | f ƒ | j  j	 ƒ  |  j
 d | d | d | d | ƒ | j  j ƒ  q� W| j  j d t  j d d ƒ ƒ d  S(   NR   R7   s   Symmetry updateR8   R9   R:   s   Rationalise point groupss    Remove subgroups of new symmetryR   s   %s new symmetries createdR)   i   s   %s. %st   symmetryR   R   R   s   Symmetry update finished(   R   R?   R"  RA   R   R   R¹  R   R,   R   R�  R   RG   (   R	   R   R   R   R§  RN   t   ns(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR    —  s     "c         C   sÎ   t  |  j j ƒ } t  g  | j j d t j ƒ D] } | | k r. | ^ q. ƒ } xx |  j j D]j } | | k r„ | j j d | ƒ n  | j d t j	 d | d |  j j j
 ƒ ƒ | j j d d | ƒ q\ Wd  S(   NR   RO   R)  t   supersymmetryR   s   DELETED: %s(   Re   R­  RR   R:   R   R   R¢  Rv   RU   t   ObsoletedBySuperSymmetryR)  R   R?   (   R¾  R   R   R   t	   moribundst   sst   presents(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR�  ³  s    		(   R!   R"   R#   R    R  R�  (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR½  ’  s   	t   SymmetryUnsupportedPolicyc           B   s   e  Z d  Z d „  Z RS(   sl   
    Controls what to do with point groups that are too high,
    i.e. not found in current best models
    c         C   sB  | j  j d t  j d d ƒ ƒ | j  j d d d d ƒ | j  j d d ƒ | j d	 t j ƒ } t t t	 j
 g  | D] } | j ^ qs g  ƒ ƒ } i  } x> | D]6 } x- | j D]" }	 | j |	 t ƒ  ƒ j
 | ƒ q® Wqž Wg  | j j d	 t j ƒ D] }
 |
 | k rñ |
 ^ qñ } | j  j d d
 t | ƒ ƒ xð t | d d ƒD]Ü \ } }
 | j j d |
 ƒ | j  j d d |
 ƒ |
 | k ràt g  | |
 D] } | j j ^ q�d d „  ƒ} | j  j d d | ƒ | j j d | ƒ n d  } | j  j d d ƒ | j d t j d |
 d | ƒ ƒ q?W| j  j d t  j d d ƒ ƒ d  S(   NR   R7   s   Symmetry removal - unsupportedR8   R9   R:   s@   Remove point groups with symmetry not found in current solutionss(   Remove supergroups not supported by dataR   s   %s symmetries not detectedR)   i   RO   s   %s: REMOVEDR   c         S   s   t  |  j j ƒ  ƒ S(   N(   R   Rš  R¦  (   R'   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR   õ  s    s   Highest subgroup symmetry: %ss   No subgroup symmetry detectedR)  R�  s   Symmetry removal finished(   R   R?   R"  RA   R   R   R°  Re   R  R  R>   RR   R®  t
   setdefaultR:   R¢  R   R,   Rv   R   R­  R)  RU   R   t   SymmetryDowngradeRG   (   R	   R   R   R   t   ssrasR'   t	   subgroupst   supergroup_ofRt  t   symmRÃ  R§  RN   t   raR�  (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR    Ñ  sB    .$#	(   R!   R"   R#   R    (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRÅ  Ë  s   t   SymmetryUpdatec           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s0   
    Handles updates to existing symmetries
    c         C   s   | |  _  d |  _ d |  _ d  S(   Ng      ð?g®Gáz®ï?(   R   Ra  Ru  (   R	   R   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR     s    		c      
   C   s¼  | j  j d t  j d d ƒ ƒ | j  j d d d d ƒ i  } xW | j d t j ƒ D]@ } x7 | j | j D]% } | j	 | t
 ƒ  ƒ j | j ƒ qk WqT W| j  j d d	 t | ƒ ƒ xát | j j d t j ƒ d
 d ƒD]»\ } } | j  j d | | f ƒ | | k r%| j  j d d ƒ qÚ n  | j  j ƒ  t t j g  | | D] }	 |	 j ^ qFt
 ƒ  ƒ }
 |  j d | d |
 d | ƒ } | j  j ƒ  | | j k r·| j  j d d ƒ qÚ n  | j  j d d ƒ i  } xK | | D]? } x6 | j j ƒ  D]% \ } } | j	 | g  ƒ j | ƒ qñWqÛWt g  | j ƒ  D]! \ } } | t d | ƒ f ^ q.ƒ } | j } | j d t j d | d | j d | ƒ ƒ | | _ qÚ W| j  j d t  j  d d ƒ ƒ d  S(   NR   R7   s   Symmetry updateR8   R9   R:   s   Update existing symmetriesR   s%   Up to %s symmetries could be affectedR)   i   s   %s. %ss   No updateable elementsR¾  Rè   R   s   Skipping this symmetrys(   Replacing original with updated symmetryR!  RO   R)  t   previousR¸  s   Symmetry update finished(!   R   R?   R"  RA   R   R   R°  R®  RR   RÆ  Re   R>   R­  R   R,   R:   R¢  R   R  R  t   or_R   t   updated_point_groupR   Rš  RŸ  Rk  R÷   Rj  Rª  RU   t   SymmetryUpdateRecordRG   (   R	   R   R   R   t   analyses_fort   ssraRË  RN   RÃ  t   aRè   t   updatedRŸ  R­  RÇ   R!  R¼  Rp  R¸  RÎ  (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR      s^    '1		!4				
c            sú  | j  j d d t | ƒ ƒ | j  j d d ƒ g  } x€ | D]x } y7 t d | j d | j j d | j d | j  j ƒ } Wn t k
 r’ } q= n X| j	 | j j
 j d | j ƒ ƒ q= W| j  j d d	 t | ƒ ƒ | j  j d d
 ƒ g  } x�t | j j ƒ  d d ƒD]€\ }	 }
 | j  j d d |	 ƒ g  } xv | D]n ‰  ‡  ‡ f d †  t |
 j |
 j ƒ Dƒ } y | j ƒ  } Wn t k
 r�q;n X| j	 ˆ  j d | ƒ ƒ q;W| j  j d d t | ƒ ƒ | rb| j  j d d ƒ t j d |
 j j d t t j g  | D] } | j ^ qƒ j ƒ  d d t | ƒ t t j g  | D] } | j ^ qCƒ ƒ } n | j  j d d ƒ |
 j } | j	 | ƒ qW| g  | j j ƒ  D] }
 |
 j ^ q¢k rÔ| j  j d d ƒ | j S| j  j d d ƒ | j j d | ƒ S(   NR   s   %s related generators founds    Transforming to common referenceR  R  R®   Rª   Ry  s   %s generators transformeds+   Matching with point group generator classesR)   i   s	   %s. classc         3   s?   |  ]5 \ } } ˆ  j  d  | d ˆ j d ˆ j ƒ r | Vq d S(   RL   Ru  Ra  N(   Rv  Ru  Ra  (   Rƒ   t   gR(  (   R9  R	   (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pys	   <genexpr>~  s
    			s   %s generators matchs   Averaging spatial componentsRz  R|  RF  g      ð?s   Using original operators2   No generator updated, keeping original point groups   Forming point group from basest
   generators(    R   R?   R   R  Ri   Rh  R®   R   R±   RT   R*  RU  R€  R,   Rš  t   generator_classesRŸ   R×  t
   operationsR…   R†   R   R^  t   standardRz  R  R  R>   R|  Rƒ  RF  t   from_generators(   R	   R¾  Rè   R   t   transformedsRÃ   R  RJ   t   basesRN   t   gcR
  t	   searchgent   stdopR(  Rh  (    (   R9  R	   sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRÐ  ]  s\    		 ((	%,	+(   R!   R"   R#   R   R    RÐ  (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRÍ  	  s   		Ht   SpatiallyEquivalentMatchingPeakc           B   s#   e  Z d  Z e d „ Z d „  Z RS(   sR   
    A matching-compatible class that takes care of superpose transformations
    c         C   sÚ   d d l  m } | |  _ | |  _ | |  _ | |  _ | rO | j }	 | j }
 n | j }	 | j	 }
 | j
 j d |  j j j ƒ  d |  j j d |  j d |  j j j ƒ  d | d | d	 |
 d
 |	 ƒ |  _ | |  _ | |  _ d  S(   Niÿÿÿÿ(   Rä   RŒ   R�   t   crystalRi   t   dmint
   multipliert   detail_positiont   detail_orientation(   Rë   Rä   R   Râ  Rã  Rä  t   cached_rotation_differencest   cached_position_differencest   simple_rotation_differencest   simple_position_differencest   MRPeakPOt   phaser_styleRŒ   RC  R�   Ri   R.  R]  R®   Rª   (   R	   R   R®   Rª   Râ  Rã  Rä  Rå   Rä   Ræ  Rå  (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR   ³  s*    									c         c   s  y7 t  d |  j j d | j j d |  j d |  j ƒ } Wn t k
 rR } t ‚ n Xd d l m } | j j	 d |  j
 j ƒ | j } | j j d | j j d	 |  j
 j j | j j ƒ d
 |  j
 d |  j j j ƒ  d |  j d |  j ƒ } x" |  j j d | ƒ D] } | Vqþ Wd  S(   NR  R  R®   Rª   iÿÿÿÿ(   Rä   R©   RŒ   R�   Râ  Ri   Rã  Rä  RL   (   R  R   Ri   R®   Rª   R±   R†   Rë   Rä   R,  Râ  R©   R€  Rë  Rì  RÃ   RK  t   fractionalizet   tR.  Rã  Rä  R]  t   operations_between(   R	   RL   R  RJ   Rä   t
   superposedRU  R(  (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRï  Û  s(    	

		(   R!   R"   R#   RÀ   R   Rï  (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRá  ®  s   
 t   SymmetryTolerancesc           B   s)   e  Z d  Z d d d d d d d „ Z RS(   s6   
    Small container class to hold all tolerances
    i   g333333Ã?g      ð?g®Gáz®ï?g      @g333333Ó?c         C   s:   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ d  S(   N(   R[  R`  Ra  Rw  Rf  R‘  (   R	   R[  R`  Ra  Rw  Rf  R‘  (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR   þ  s    
					(   R!   R"   R#   R   (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRñ  ù  s   t   LocalSymmetryExpertc           B   s,   e  Z d  Z e e e e d „ Z d „  Z RS(   sP   
    A wrapper class to contain all symmetry-related experts for scheduling
    c         C   sÎ   t  ƒ  |  _ t d |  j ƒ t d |  j ƒ t d |  j ƒ t d |  j ƒ g |  _ | rm |  j j t ƒ  ƒ n  | r’ |  j j t	 d |  j ƒ ƒ n  | r® |  j j t
 ƒ  ƒ n  | rÊ |  j j t ƒ  ƒ n  d  S(   NR   (   Rñ  R   R  Rg  R”  R«  t   actionsRT   RÅ  RÍ  R·  R½  (   R	   t   add_new_symmetryt   remove_subgroup_symmetryt   remove_unsupported_symmetryt   update_known_symmetry(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR   	  s    c         C   sb  | j  j d t  j d d ƒ ƒ | j  j d d d d ƒ | j  j d t  j d d ƒ ƒ g  | | D] } | j j rb | ^ qb } x� t | d	 d
 ƒD]{ \ } }	 | j  j d d | ƒ | j  j ƒ  | j  j d t	 |	 ƒ ƒ | j  j
 ƒ  | j d t j d |	 j d | ƒ ƒ q“ Wx* |  j D] }
 |
 d | d | d | ƒ qW| j  j d t  j d d ƒ ƒ g  S(   NR   R7   s   Local symmetry analysisR8   R9   R:   s.   Analyse solutions to identify local symmetriess   Structure selectionR)   i   s   %d. Structure:RO   RÇ   RN   R   R   R   s    Local symmetry analysis finished(   R   R?   R@   RA   R"  RÇ   R¦   R,   R   R   R   RU   R   R#  Ró  RG   (   R	   R   R   R   RÏ   RÐ   R'   R   RN   t   solt   action(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR    2	  s,    )			(   R!   R"   R#   R+   R   R    (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRò  	  s   c   !      C   s‡  d d l  m } | j ƒ  } | j ƒ  } g  |  j D]K } t d | d | j d | j j d | d | j	 j
 j d | d	 t ƒ ^ q2 }	 t |  j ƒ }
 t t |	 |  j ƒ ƒ } t t |  j |	 ƒ ƒ } g  } x›|
 re|
 j ƒ  } g  g } xýt | j d
 d ƒD]æ\ } } | j j d d | ƒ y4 t d | j d | j d | j d | j j ƒ } Wn- t k
 r‚} | j j d d | ƒ qü n X| j d | ƒ | j } g  } xµ | j D]ª \ } } | | } t j d | d t j j d | j j ƒ d | j | j  ƒ d | j! ƒ } t d | d | j d | j j d | d | j	 j
 j d | ƒ } | j" | ƒ q¬W| j# d g  |
 D] } | | ^ qjd | ƒ } g  | j$ d | ƒ D] \ } } | ^ qœ} | j j d d t% | ƒ d ƒ | j" | ƒ qü Wg  t& | d t% ƒD] } | | ^ qù}  | j j d d t% |  ƒ d ƒ x |  D] } |
 j' | ƒ q7W| j" | g |  ƒ qË W| j j d d t% | ƒ ƒ | S(   Niÿÿÿÿ(   Rä   R   R®   Rª   Râ  Rã  Rä  Rå   R)   i   R   s	   Anchor %sR  R  s     REJECTED: %sR©   Ri   RŒ   R:  R�   R�   Ræ   Rç   t   overlapss     members: %sR   s"   Largest association has %s memberss    Number of associations found: %s((   Rë   Rä   R°   t   matching_crystal_infoR‹   Rá  R®   R   R   RP   t	   xray_datat
   resolutionR+   Re   Rj  RŸ   R}  R,   t   anchorsR?   R  Ri   R±   R,  R€  R   RO  RŠ   RH  RÃ   RK  Rí  Rî  R�   RT   R¬   t   pairsR   R   R�  (!   RÇ   t   assemblyR   R   Rä  Rä   R©   Râ  R   t   tmfsR‡  t   peak_fort   tmf_forR	  t   headt   alternativesRN   t   anchorR  RJ   R€  t   trialst   enseR(  t   finalt   ptmfR|   Rú  R&  RÃ   t   assocRî  t   largest(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyt.   partition_structure_according_to_membership_inZ	  sn    	X		"			
					+!)c         C   s   | j  j d d ƒ t S(   s1   
    Accepts any assembly without any checks
    R   s+   Accepting assembly (no condition specified)(   R   R?   R+   (   R   R  R   R   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyt   AcceptAssemblyStrategy»	  s    c         C   s   | j  j d d ƒ t S(   s1   
    Rejects any assembly without any checks
    R   s+   Rejecting assembly (no condition specified)(   R   R?   RÀ   (   R   R  R   R   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyt   RejectAssemblyStrategyÄ	  s    t   AcceptObservedAssemblyStrategyc           B   s#   e  Z d  Z d d „ Z d „  Z RS(   sF   
    Accepts if the assembly has been observed in any structures 
    g      @c         C   s   | |  _  d  S(   N(   Rä  (   R	   Rä  (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR   Ò	  s    c         C   s  | j  j d d ƒ t | j ƒ } | j  j d d | ƒ | j  j d d t | ƒ ƒ x¯ t | d d ƒD]› \ } } t d | d | d	 | d
 | d |  j ƒ } t g  | D] }	 t |	 ƒ ^ q© ƒ }
 | j  j d d | |
 f ƒ | |
 k ri | j  j d d ƒ t Sqi W| j  j d d ƒ t	 S(   NR   s+   Accepting symmetry if full assembly presents   Full assembly has %s memberss#   Testing membership in %s structuresR)   i   RÇ   R   R   R   Rä  s-   Structure %s: largest assembly has %s memberss   Full assembly founds   Full assembly NOT found(
   R   R?   R   t   descriptionR,   R  Rä  R   R+   RÀ   (   R	   R   R  R   R   t   member_countRN   RÇ   R	  RÔ  R  (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR    ×	  s0    %(   R!   R"   R#   R   R    (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR  Í	  s   t   AssemblyCreatec           B   sM   e  Z d  Z d „  Z d „  Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z RS(   s(   
    Creates models with symmetries
    c         C   s   | |  _  d  S(   N(   t   is_valid(   R	   R  (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR   
  s    c      
   C   s  | j  j d t  j d d ƒ ƒ | j  j d d d d ƒ t g  | j j d t j ƒ D] } | j	 ^ qT ƒ } | j  j d d	 t
 | ƒ ƒ g  | j j d t j ƒ D] } | j | k r¢ | ^ q¢ }	 | j  j d d
 t
 |	 ƒ ƒ g  | | D] } | j j rë | j ^ që }
 xæ t |	 d d ƒD]Ò \ } } | j  j d d | | f ƒ t j j d | j d | j d t j ƒ  ƒ } |  j d | d |
 d | d | ƒ rÞ| j  j d d ƒ | j j d | ƒ | j d t j d | ƒ ƒ q| j  j d d ƒ qW| j  j d t  j d d ƒ ƒ g  S(   NR   R7   s   Assembly creationR8   R9   R:   s,   Create assemblies from identified symmetriesR   s$   Current assemblies use %s symmetriess0   %s symmetries not used in assemblies are presentR)   i   s   %s. %sRi   R¾  t   strategyR   R  R   R   s
     ACCEPTEDRO   s
     REJECTEDs   Assembly creation finished(   R   R?   R@   RA   Re   R:   R   R   t   AssemblyR¾  R   R¢  Rš  RÇ   R¦   R,   t   SimpleRi   t   RefineStrategyR  RU   t   NewAssemblyRecordRG   (   R	   R   R   R   RÏ   RÐ   RÔ  RÑ   R'   RÒ   R  RN   R)  R   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR    
  sB    1,					c         C   s   |  d t  ƒ S(   NR  (   R  (   t   cls(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyt   AlwaysB
  s    c         C   s   |  d t  ƒ  ƒ S(   NR  (   R  (   R  (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyt   ObservedH
  s    c         C   s   |  d t  ƒ S(   NR  (   R  (   R  (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyt   NeverN
  s    (	   R!   R"   R#   R   R    t   classmethodR  R  R  (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR  ü	  s   		<t   AssemblyRemovec           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s2   
    Removes models with obsoleted symmetries
    c         C   sÑ   | j  j d t  j d d ƒ ƒ | j  j d d d d ƒ | j  j d t  j d d ƒ ƒ |  j d	 | d
 | d | ƒ | j  j d t  j d d ƒ ƒ |  j d	 | d
 | d | ƒ | j  j d t  j d d ƒ ƒ g  S(   NR   R7   s   Assembly removalR8   R9   R:   s+   Remove assemblies with obsoleted symmetriess   Subgroup symmetriesR   R   R   s   Supergroup symmetriess   Assembly removal finished(   R   R?   R@   RA   R"  t   remove_subgroup_symmetriest   remove_supergroup_symmetriesRG   (   R	   R   R   R   RÏ   RÐ   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR    Y
  s(    		c         C   sÐ   t  g  | j d t j ƒ D] } | j j ^ q ƒ } | j j d d t | ƒ ƒ xx | j	 j d t j
 ƒ D]^ } | j | k rj | j j d d | ƒ | j	 j d | ƒ | j d t j d | ƒ ƒ qj qj Wd  S(   NR   R   s   %s symmetries obsoleteds   %s: symmetry obsoleted, removeRO   R   (   Re   R   R   RÁ  R)  Rš  R   R?   R   R:   R  R¾  Rv   RU   t   AssemblyRemovalRecord(   R	   R   R   R   RV  t	   obsoletest   assem(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR   z
  s    .	c   	      C   sb  t  g  | j d t j ƒ D] } | j j | j f ^ q ƒ } | j j d d t	 | ƒ ƒ x| j
 j d t j ƒ D]ç } | j | k rs | j j d d | ƒ | j
 j d | ƒ | j d t j d | ƒ ƒ | | j } | d  k	 rZ| j j d d | ƒ t j d | j d	 | j d
 | j ƒ } | j
 j d | ƒ | j d t j d | ƒ ƒ qZqs qs Wd  S(   NR   R   s   %s symmetries downgradeds   %s: symmetry obsoleted, removeRO   R   s   Reinstating subgroup: %st   definitionsR¾  R  (   Rj  R   R   RÇ  R)  Rš  R�  R   R?   R   R:   R  R¾  Rv   RU   R"  R   R%  R  R  (	   R	   R   R   R   t   dgt   downgraded_toR$  t   replacementt   r_assem(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR!  �
  s.    7					(   R!   R"   R#   R    R   R!  (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR  T
  s   	!	t   AssemblyUpdatec           B   s   e  Z d  Z d „  Z RS(   s(   
    Updates models with symmetries
    c   	      C   s$  | j  j d t  j d d ƒ ƒ | j  j d d d d ƒ | j  j d d ƒ t g  | j d	 t j ƒ D] } | j | j	 j
 f ^ qd ƒ } | j  j d d
 t | ƒ ƒ xY | j j d	 t j ƒ D]? } | j | k r¾ | j  j d d | ƒ | | j | _ q¾ q¾ W| j  j d t  j d d ƒ ƒ g  S(   NR   R7   s   Assembly updateR8   R9   R:   s   Update symmetry for assembliess9   Update assemblies according to changes made to symmetriesR   s   %s updates availables   %s: UPDATEDs   Assembly update finished(   R   R?   R@   RA   Rj  R   R   RÑ  RÎ  R)  Rš  R   R:   R  R¾  RG   (	   R	   R   R   R   RÏ   RÐ   Rþ   t
   update_forR$  (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR    ¶
  s$    7(   R!   R"   R#   R    (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR*  ±
  s   t   SearchModelMaintenancec           B   s_   e  Z d  Z d „  Z d „  Z d „  Z d „  Z e d „  ƒ Z e d „  ƒ Z	 e d „  ƒ Z
 RS(   sE   
    Creates/removes AssemblyEnsembles as dictated by Assemblies
    c         C   s   | |  _  d  S(   N(   R  (   R	   R  (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR   Ú
  s    c      	   C   s  | j  j d t  j d d ƒ ƒ | j  j d d d d ƒ | j  j d t  j d d ƒ ƒ g  | | D] } | j j rb | j ^ qb } |  j d	 | d
 | d | d | ƒ | j  j d t  j d d ƒ ƒ |  j d
 | d | d | ƒ | j  j d t  j	 d d ƒ ƒ g  S(   NR   R7   s%   Search model assembly and maintenanceR8   R9   R:   s)   Creates and search models from assembliess   New assembliesR  R   R   R   s   Obsoleted assembliess!   Search model maintenance finished(
   R   R?   R@   RA   R"  RÇ   R¦   t   add_new_assembliest   remove_deleted_assembliesRG   (   R	   R   R   R   RÏ   RÐ   R'   R  (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR    ß
  s,    ,		c      
   C   sU  t  g  | j j d t j ƒ D] } | j ^ q ƒ } | j j d d t | ƒ ƒ g  | j j d t j	 ƒ D] } | | k rj | ^ qj } | j j d d t | ƒ ƒ x© t
 | d d ƒD]• \ }	 }
 | j j d d |	 |
 f ƒ |  j d |
 d	 | d
 | d | ƒ r:| j j d d ƒ | j j d t j d |
 ƒ ƒ q¸ | j j d d ƒ q¸ Wd  S(   NR   R   s    Current models use %s assembliess,   %s assemblies not used as models are presentR)   i   s   %s. %sR   R  R   R   s
     ACCEPTEDRO   s
     REJECTED(   Re   R:   R   R   t   AssemblyEnsembleR   R   R?   R   R  R,   R  RU   (   R	   R  R   R   R   RJ   RÑ   RÔ  RÒ   RN   R   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR-    s&    1		c         C   s¥   t  d „  | j d t j ƒ Dƒ ƒ } | j j d d t | ƒ ƒ x\ | j j d t j ƒ D]B } | j	 | k r[ | j j d d | ƒ | j j
 d | ƒ q[ q[ Wd  S(   Nc         s   s   |  ] } | j  Vq d  S(   N(   R   (   Rƒ   RÃ   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pys	   <genexpr>*  s    R   R   s   %s assemblies deleteds   %s: removed search modelRO   (   Re   R   R   R"  R   R?   R   R:   R/  R   Rv   (   R	   R   R   R   t   deletedsR  (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR.  '  s    "c         C   s   |  d t  ƒ S(   NR  (   R  (   R  (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR  4  s    c         C   s   |  d t  ƒ  ƒ S(   NR  (   R  (   R  (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR  :  s    c         C   s   |  d t  ƒ S(   NR  (   R  (   R  (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR  @  s    (   R!   R"   R#   R   R    R-  R.  R  R  R  R  (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR,  Õ
  s   		%	#	t   AssemblyModelCreatec           B   sh   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z RS(   sU   
    Creates aggregate models from assemblies
    Only active in post-processing
    c         C   s7   | r |  j  |  _ n |  j |  _ d |  _ d |  _ d  S(   Ng®Gáz®ï?g      ð?(   t   accept_if_observedt   acceptt   accept_anywayR´  Rµ  (   R	   t   observe_first(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR   L  s
    	c      	   C   sÃ  | j  j d t  j d d ƒ ƒ | j  j d d d d ƒ | j j d t j ƒ } | j j d t j ƒ } | j  j d d	 t	 | ƒ ƒ x| D]} | j  j d d
 | ƒ | j  j d t  j
 d d ƒ ƒ x¸ | D]p }	 | j  j d d ƒ | j  j d |	 ƒ |  j d | d |	 j d | ƒ s"qÏ n  | j  j d d ƒ | |	 _ PqÏ W|  j d | d | ƒ rƒt j d | ƒ }
 | j j d |
 ƒ n  | j  j d t  j ƒ  ƒ qŒ W| j  j d t  j d d ƒ ƒ g  S(   NR   R7   s   Model assemblyR8   R9   R:   s%   Create models according to assembliesR   s   Assemblies: %ss   Processing: %ss   Comparing with existing modelss   Trial:Ræ   Rç   R   s*   There is a model for this assembly: UPDATER   RO   s   Model assembly finished(   R   R?   R@   RA   R:   R   R   t   RegularEnsembleR  R   R"  R¶  R   R3  RU   RC   RG   (   R	   R   R   R   RÏ   RÐ   R±  t
   assembliesR$  t   regt   reg_ense(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR    X  s8    !	c         C   s   | j  j d d ƒ t S(   NR   s   Novel assembly: CREATE model(   R   R?   R+   (   R	   R   R   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR4  ‡  s    c         C   s;   | j  r  | j j d d ƒ t S| j j d d ƒ t Sd  S(   NR   s'   Novel assembly (observed): CREATE models$   Novel assembly (unobserved): DISCARD(   t   presentR   R?   R+   RÀ   (   R	   R   R   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR2  Ž  s
    	c      
   C   s÷  | j  } | j  } t | ƒ t | ƒ k  rA | j j d d ƒ t S| j j d d ƒ | d \ } } xŒt | d d ƒD]x\ } \ }	 }
 y1 |  j d | d |	 d	 | j d
 | j j ƒ } Wn t	 k
 rÒ } qw n X| j j d d | ƒ | | f |	 |
 f f | d g  | D] } | |	 |
 f k r| ^ q| j
 f } x² |  j d | d | ƒ D]� \ } } } | j j d d | rŠ| j | ƒ d n d | r¦| j | ƒ d n d f ƒ | d  k rS| j j d d ƒ PqSqSW| j j d d ƒ t Sqw Wt S(   NR   s   Containing assembly smallers   Finding seed:i    R)   i   Ræ   Rç   R®   Rª   s   Seed: 1 vs %st   matchR   s   Match: %s vs %ss   n/as5   Unmatched component in larger assembly, dropping seeds   All components match(   R  R   R   R?   RÀ   R,   t   ensemble_relationR®   R   R±   R€  t   assignRN   R   R+   (   R	   Ræ   Rç   R   t	   left_desct
   right_desct   l_enset   l_opt   r_indext   r_enset   r_opR  RJ   t   riR;  R&  RÃ   R'   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR¶  ™  sB    		%		(($c         C   s%   t  j j d | d |  j d |  j ƒ S(   NRy  R´  Rµ  (   R   t
   PointGroupt   approx_identity_operationR´  Rµ  (   R	   R(  (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRG  Ï  s    	c         C   s:   | j  d | ƒ s t d ‚ n  | j d | d | d | ƒ S(   NRL   s   different compositionR  R  Rª   (   R  R±   R  (   R	   Ræ   Rç   R®   Rª   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR<  Ø  s    	c         c   só   | \ \ \ } } \ } } } } }	 | | f | | f |	 f V| | |	 j  ƒ  }
 g  | D] \ } } | |
 | f ^ qY } xq |  j d | d | d | ƒ D]Q \ } } } | d  k	 rÝ | | k sÇ t ‚ | | j | ƒ } n  | | | f Vqš Wd  S(   NRæ   Rç   R   (   R-  R¬   R   Ru   RN   (   R	   R;  R   R@  RA  RC  RD  Ræ   Rç   R  R8  RJ   R(  t   r_transfR&  RÃ   t   s_op(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR=  ä  s    $).c         c   s  t  | ƒ } xæ | D]Þ \ } } | j ƒ  } xÃ | D]§ \ } }	 y1 |  j d | d | d | j d | j j ƒ }
 Wn t k
 r‡ } q2 n X|  j d | |	 |
 j ƒ r2 | j	 | |	 f ƒ | | f | |	 f |
 j f VPq2 q2 W| | f d  d  f Vq Wx | D] } d  | d  f Vqü Wd  S(   NRæ   Rç   R®   Rª   R(  (   Re   R-  R<  R®   R   R   R±   RG  R€  R�  R   (   R	   Ræ   Rç   R   t   copyt   ref_enset   ref_opR-  t
   trial_enset   trial_opR  RJ   RÃ   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR¬   ô  s&    		c         C   s   d S(   Ns   Model assembly(    (   R	   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRZ     s    (   R!   R"   R#   R   R    R4  R2  R¶  RG  R<  R=  R¬   RZ   (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR1  F  s   		/			6					!t   ObjectCompletionc           B   sD   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s1   
    Adds molecules to incomplete assemblies
    c         C   s   d |  _  d  S(   Ng      @(   Rä  (   R	   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR     s    c         C   s²  | j  j d t  j d d ƒ ƒ | j  j d d d d ƒ | j j d t j ƒ | j j j d t j ƒ } g  | D] } | j	 j
 rp | ^ qp } | j  j d d	 t | ƒ ƒ | j  j d t  j d d
 ƒ ƒ g  | j j d t j ƒ D]B }	 |	 j j | j d |	 j d |  j ƒ | j d |	 j	 ƒ f ^ qã }
 g  } x[| D]S} |  j d | j	 d | d | d | ƒ } | j d | j	 d t ƒ } g  } xz | D]r \ } } |  j d | d | d |
 d | d | ƒ sÙ| j | | f ƒ q�| j  j d | ƒ | j  j d d ƒ q�W| j  j d d t | ƒ ƒ xU | D]M \ } } t j d | j	 d | d | ƒ } | j  j d | ƒ | j | ƒ q'W| j  j d d ƒ q8W| j  j d t  j d d ƒ ƒ | S(   NR   R7   s"   Object completion - identificationR8   R9   R:   s%   Find assemblies that can be completedR   s   Significant peaks: %ds   Processing:R   Rä  RÇ   R7  R   R   Rå   t   failuress     REJECT: know failures   %s missing molecules filled inR  RK   s   Object completion finished(   R   R?   R@   RA   R:   R   R   R  RP   RÇ   R¦   R   RE   RÞ   R   Ri   R>  Rä  Rô   t   complete_assemblies_inR+   t   is_known_failureRT   RO  RG   (   R	   R   R   R   RÏ   RÐ   R7  R'   Rú   t   recRP  Rr   Rø  t
   generatedst   trial_structure_tmfRü   R   t   stratR  t   roc(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR    $  s\    %^											c         C   sÿ  g  } xÕ| j  D]Ê} | j j d | ƒ | j j d | j ƒ ss | j j d d ƒ | j j d t j ƒ  ƒ q n  y1 | j j d | j d | j d | j j ƒ } WnB t	 k
 rè } | j j d d ƒ | j j d t j ƒ  ƒ q n X| j j d d ƒ | j
 d	 | ƒ | j }	 g  }
 xy | j D]n \ } } |	 | } |
 j t j d
 | d t j j d | j j ƒ d | j | j ƒ d | j ƒ | j f ƒ q%W| j j d d t |
 ƒ ƒ | j j d t j ƒ  ƒ | j |
 ƒ q W| j j d d t | ƒ ƒ | S(   NR   RL   s!     REJECTED: different compositionR  R  Rª   s     REJECTED: no superpositions2   Generating possible molecules using current anchorR©   Ri   RŒ   R:  R�   R�   s     %s peak generateds+   Total %s peaks generated from this assembly(   Rþ  R   R?   Ri   R  RC   R®   R  R   R±   R,  R€  R‹   RT   R   RO  RŠ   RH  RÃ   RK  Rí  Rî  R�   R  R   R÷   (   R	   R   R   R©   R   RT  R  R  RJ   R€  t   currentsR  R(  R	  (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyt   process_assemblyu  sF    		
		c   )         sø  | j  j d d ƒ | j  j ƒ  | j  j d | ƒ | j  j ƒ  | j  j d t  j ƒ  ƒ t j d d „  ƒ } xÄ| j D]¹} | j  j d d ƒ | j  j ƒ  | j  j d | ƒ | j  j ƒ  | j  j d t  j ƒ  ƒ | j  j d d ƒ | j  j d t  j ƒ  ƒ g  } x¡ t | d d ƒD]� \ } }	 | j  j d d	 | |	 f ƒ | j  j ƒ  | j	 |  j
 d
 | d |	 d | j ƒ  d | ƒ ƒ | j  j d t  j ƒ  ƒ | j  j ƒ  qW| j  j d d t | ƒ ƒ | j  j d t  j ƒ  ƒ xK | D]C \ }
 } | j d
 |
 d |  j ƒ } | j d |
 | f | f ƒ qêWqx W| j  j d d t | j ƒ ƒ | j  j d t  j ƒ  ƒ g  } | j d | d t d |  j ƒ } t g  | j D] }
 |
 j ^ q¢ƒ } d d  l ‰  d d  l ‰  d d l m } | j  j d d ƒ xßt | j ƒ  d d ƒD]Å\ } } | s&t ‚ | j  j d d | t | ƒ f ƒ | j ƒ  \ \ } } } | j ƒ  } | j j } | j j  ƒ  g } ˆ  j  j! | j" ƒ g } | j# g } | g } x'| D]\ \ }
 } } t$ | j% d | j ƒ  ƒ d ‡  f d †  ƒ\ } } t& | j' d | j j ƒ d ‡  f d †  ƒ\ } } | j( | j) ˆ  j  j* |
 j j  ƒ  ƒ | j+ ƒ ˆ  j  j! | j, |
 j" ƒ } | j( | ˆ  j  j! g  | d | D] }  t- |  ƒ ^ q¤ƒ ƒ | j( |
 j# ƒ | j( | ƒ q¿Wˆ  j. j/ | Œ  }! d t | ƒ t0 t1 j | ƒ }" d t | ƒ t2 | ƒ }# t& | d d „  ƒ}$ t j3 d | j d  t j4 j5 d! |! ƒ d" |" j6 d# |# ƒ }% | j  j d d$ ƒ | j  j d |% ƒ x.| D]ç }& |% j j7 d |& ƒ sÊq©n  y7 | j8 j9 d
 |% d |& d | j ƒ  d% | j  j: ƒ }' Wn t; k
 rq©n X| j< d& | d' | j d
 |' d |  j ƒ g ƒ }( t= | j> d( |( ƒ ƒ r©| j  j d d) ƒ | j  j d t  j ƒ  ƒ Pq©q©W| j  j d d* ƒ | j  j d t  j ƒ  ƒ | j( |% |$ f ƒ qW| j  j d d t | ƒ ƒ | S(+   NR   s
   Structure:Ri  c         S   s   t  |  d j d | d ƒ ƒ S(   Ni   RL   (   R  Rï  (   Ræ   Rç   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR   ·  s    s   Trial peak:s   Processing assemblies:R)   i   s   %d: %sR   R   R©   R   s'   Total %s peaks generated for trial peakRä  Rx  s+   Total %s peaks generated for this structureRÇ   Rå   iÿÿÿÿ(   Rä   s   Merging quasi-equivalent peakss   Cluster %d: %d elementsRL   R   c            s   ˆ  j  j |  d ƒ j ƒ  S(   Ni   (   RC  RD  t	   length_sq(   R|   (   RS  (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR     s    c            s   ˆ  j  j |  d ƒ S(   Ni   (   t   matht*   r3_rotation_cos_rotation_angle_from_matrix(   R|   (   RS  (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR     s    i    g      ð?c         S   s
   |  j  ƒ  S(   N(   t   coverage(   R'   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR     s    Ri   RŒ   R:  R�   R�   s   Averaged peak:Rª   Ræ   Rç   Rú  s"   REJECT: present in known structuret   ACCEPT(?   R   R?   R   R   RC   R   R~  R‹   R,   R÷   RY  R°   R   R>  Rä  R>   R†  Rô   R+   Re   Ri   t   scitbx.mathR@  Rë   Rä   R‚  Ru   R}  R?  R]  t   orientationRŒ   RC  RD  R�   R�   t   minRB  R   t   rotation_differences_betweenRT   RI  RJ  RÃ   RE  RG  R[  t1   r3_rotation_average_rotation_matrix_from_matricesR  R  t   sumRO  RŠ   RH  RK  R  R®   R¯   R   R±   R¬   R  Rÿ  ()   R	   RÇ   R7  R   R   R  R   RX  RN   R$  R|   R'   Rý   R›  RÄ  t   structure_ensemblesRä   R‹  t   refRV  t   rtmft   ref_posit   ref_orit   rotst   trast   bfacst   stratsRT  R<  t   pgopt   rotmatRî  RV  t   rott   trat   bfacR  R‰  R  t   sub_peakRú  (    (   RS  sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRQ  ®  sØ    		
$	%%	*8 						c      
   C   s  d d l  m } xÿ | D]÷ \ } } }	 | j j d | ƒ sA q n  y7 | j j d | d | d | j ƒ  d | j j ƒ }
 Wn t	 k
 rŽ q n X| j
 d |
 d |  j ƒ } t | j d | ƒ ƒ sÈ q n  | j d	 | j d
 | d |	 ƒ ƒ } t t | ƒ ƒ t |	 ƒ k r t Sq Wt S(   Niÿÿÿÿ(   Rä   RL   R   Ri   R©   Rª   Rä  Rú  Ræ   Rç   (   Rë   Rä   Ri   R  R®   R¯   R°   R   R   R±   R>  Rä  R  Rï  Rÿ  R¬   R   R  R+   RÀ   (   R	   RÇ   R   RP  R   R   Rä   R  t   p_tmft   s_tmfRs  Rý   R¬   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRR  J  s,    		c         C   s   d S(   Ns   Object completion(    (   R	   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRZ   o  s    (	   R!   R"   R#   R   R    RY  RQ  RR  RZ   (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRO    s   		Q	9	œ	%t   Coordinatorc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s   
    Manages suspensions
    c         C   s2   g  | j  d t j ƒ D] } | j ƒ  r | ^ q S(   NR   (   R   R   Rb   RÄ   (   R	   R   R   R   R'   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR6   y  s    c         C   sý   | j  j d t  j d d ƒ ƒ | j  j d d d d ƒ | j  j d d | j ƒ  ƒ | j  j d t  j ƒ  ƒ | j  j d t  j d d ƒ ƒ xJ t | d	 d
 ƒD]6 \ } } | j  j d | | f ƒ | j d | ƒ q  W| j  j d t  j	 d d ƒ ƒ d  S(   NR   R7   s   Process coordinationR8   R9   R:   s   Space group %ss   Expired suspensions:R)   i   s   %s: %sRO   s   Process coordination finished(
   R   R?   R@   RA   RB   RC   RE   R,   Rv   RG   (   R	   R;   R   R   R   RN   RÍ   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRI   €  s    c         C   s   d S(   NRv  (    (   R	   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRZ   –  s    (   R!   R"   R#   R6   RI   RZ   (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRv  t  s   		t	   Ensemblerc           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s   
    Runs ensembler
    c         C   sA   t  d |  d t j ƒ |  _ d d l m } | j j ƒ  |  _ d  S(   NR
   R   iÿÿÿÿ(   t	   ensembler(	   R   R   R\   R6   Rë   Rx  t   PHIL_MASTERt   extractt   params(   R	   Rx  (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR      s    c   	      C   s•  | j  j |  ƒ | j j d t j d d ƒ ƒ | j j d d d d ƒ | j j d d | j ƒ  ƒ | j j d t j ƒ  ƒ | j j d t | ƒ ƒ | j j d d ƒ |  j	 d	 | j
 d
 | d | ƒ } | | j
 _ | j j d d | j
 j ƒ | j ƒ  } g  | j d t j ƒ D] } | j ƒ  | k r| ^ q} t j d | d | d t | ƒ d ƒ } | j d | ƒ | j j d t j d d ƒ ƒ d  S(   NR   R7   s   Model generation - ensemblerR8   R9   R:   s   Space group %sRK   Ré   R   R   s   Ensemble #%d generatedR   RM   R<   RN   i   RO   s   Ensembler finished(   R   R>   R   R?   R@   RA   RB   RC   R   Rw   Ré   Ri   RN   RM   R   R   R[   R   RU   RG   (	   R	   R;   R   R   R   Ri   RM   Rº   R¬  (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRI   §  s4    				c      	      sÙ  | j  d  k	 r) | j j d d ƒ | j  S| j j j d | ƒ t j d | j j ƒ } | j	 ƒ  } | j
 |  j j _
 d d l m } y+ | j d | d g  d	 |  j d
 | ƒ } Wn7 t k
 ré } | j j d d | ƒ t d | ‚ n Xg  | D] }	 |	 j j ƒ  ^ qñ }
 xS t | |
 ƒ D]B \ }	 } |	 j j | j ƒ  j ƒ  |	 j } | j ƒ  j | ƒ qW|  j j j
 rÒt d „  | Dƒ ƒ s�t ‚ | j d d ƒ | j d t j ƒ  ƒ | j d | d |
 d
 | ƒ n  y/ | j  d d | j! d | d |
 d
 | ƒ } Wn t" k
 r} t | ‚ n Xt# | ƒ t# | ƒ k s>t ‚ t$ t | j% | j& ƒ ƒ ‰  t ‡  f d †  | Dƒ ƒ s{t ‚ g  | D] }	 ˆ  |	 j' j( ^ q‚} t) j* d | d | d | j+ ƒ } | j j j, d | ƒ | S(   NR   s   This entry has been processedRO   Rª   iÿÿÿÿ(   Rx  t   pdbst
   alignmentsR{  t   loggers   Ensembler error: %ss   Ensembler: %sc         s   s   |  ] } t  | d  ƒ Vq d S(   t   ensembler_trimming_maskN(   t   hasattr(   Rƒ   t   info(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pys	   <genexpr>ô  s    s   Trimming chainst   infost   chainsRy   s   ensembler_%dc         3   s!   |  ] } | j  j ˆ  k Vq d  S(   N(   t   pdbRœ  (   Rƒ   R�  (   t   rmsd_for(    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pys	   <genexpr>  s    t   rmsdsRS   (-   Ri   R   R   R?   RP   R:   Rv   t   SingleStreamR   t   pdb_objectst   trimR{  t   configurationRë   Rx  Rw   R±   R   t   chaint   detached_copyRŸ   t   ensembler_rotationRK  t   atomst   extract_xyzt   ensembler_translationt   set_xyzRÕ   Ru   R�  RC   t   trim_chainst)   write_chain_and_model_sorted_output_filesRN   t   IOErrorR   Rj  R|  R†  R„  Rœ  R   t   MultifileEnsembleRS   RU   (   R	   Ré   R   R   R~  R|  Rx  R‚  RJ   R�  Rƒ  R‹  t   sitest
   file_namest   chain_rmsdsRi   (    (   R…  sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRw   Ï  sZ    		"
	"#	c         C   s   d S(   Ns   ModelGeneration (ensembler)(    (   R	   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRZ     s    (   R!   R"   R#   R   RI   Rw   RZ   (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRw  ›  s
   		(	Ft   Sculptorc           B   sA   e  Z d  Z d g d „ Z d „  Z d „  Z d „  Z d „  Z RS(   s   
    Runs sculptor
    RÕ   c         C   s‰   t  d |  d t j ƒ |  _ d d l m } | j j ƒ  |  _ | |  j j	 _
 | j d |  j d t j ƒ  ƒ |  _ | j d d  ƒ |  _ d  S(   NR
   R   iÿÿÿÿ(   t   sculptorR{  R~  (   R   R   R^   R6   Rë   Rš  t   PHIL_MULTIPROTOCOL_MASTERRz  R{  t   macromoleculet	   protocolst   process_multiprotocol_philR   R‡  t	   sculptorst   get_discarder_objectR   t	   discarder(   R	   R�  Rš  (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR     s    		c         C   sû  | j  j |  ƒ | j j d t j d d ƒ ƒ | j j d d d d ƒ | j j d d | j ƒ  ƒ | j j d t j ƒ  ƒ | j j d t | ƒ ƒ | j j d d ƒ | j j d d	 t	 |  j
 ƒ ƒ |  j d
 | j d | d | ƒ } | | j _ | j j d d ƒ | j j ƒ  | j ƒ  } g  | j d t j ƒ D] } | j ƒ  | k r9| ^ q9} xk t | d t	 | ƒ d ƒD]M \ }	 }
 | j j d |
 ƒ t j d | d |
 d |	 ƒ } | j d | ƒ qzW| j j ƒ  | j j d t j d d ƒ ƒ d  S(   NR   R7   s   Model generation - sculptorR8   R9   R:   s   Space group %sRK   s   Number of active protocols: %sR¼   R   R   s   Unique models generated:R   R)   i   RM   R<   RN   RO   s   Sculptor finished(   R   R>   R   R?   R@   RA   RB   RC   R   R   RŸ  t   process_and_uniqueifyR¼   t	   ensemblesR   RM   R   R   R[   R,   RU   R   RG   (   R	   R;   R   R   R   R£  RM   Rº   R¬  R.   Ri   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRI   ,  s@    			)		c         C   s0  | j  d  k	 r) | j j d d ƒ | j  S| j j j d | ƒ t j d | j j ƒ } d d l	 m
 } d d l	 m } | j ƒ  } | j } | j d | ƒ | j d	 | j d
 | j ƒ  d | j g d i  d |  j j d |  j j d | ƒ \ }	 }
 | j d | ƒ } | j d | d |	 d | ƒ } | j d | d |
 d |  j d | ƒ } |  j d | d |	 d | ƒ } g  } d d  l } x¯| D]§\ } } x! | j D] } | j d | ƒ q—W| j d | d | d | d d d d | j ƒ  | f d | ƒ } | j j  | ƒ j! ƒ  } | j" ƒ  s#| j# ƒ  rW| j j d d | ƒ | j j d d | ƒ q�n  | j j d d | ƒ t$ t% | j" ƒ  d j& ƒ  ƒ ƒ } | j' d | j( ƒ  d  | ƒ } | j j d d! | j( ƒ  d" | | f ƒ t) j* d# | g d$ | g d% | j+ d& | ƒ } | j j j, d | ƒ | j- | ƒ q�W| S('   NR   s   This entry has been processedRO   Rª   iÿÿÿÿ(   Rš  (   t   chiselRy   t   factoryt   chain_infosR}  t   sequence_fort
   min_lengtht   min_fractionR~  t   indexerR±  t   samplest	   processort   datumt	   blueprintt
   identitiest	   file_roott   sculptt   suffixs   %s%ss   %s: model emptys   %s: discardeds   %s: model generatedi    t   identityt   num_residuess'   Identity=%.2f%%, length=%d => rmsd=%.3fid   R|  R†  RS   R¼   (.   R£  R   R   R?   RP   R:   Rv   R‡  R   Rë   Rš  R¤  t
   pdb_objectt   objectt   sanitize_occupanciest   chain_samplest   aligned_chain_samplet   get_chain_infost	   alignmentR{  t   min_hssp_lengtht   min_matching_fractiont   ForwardIndexert   identity_processt   sample_processR¡  t    unique_modification_instructionst	   iotbx.pdbR>   t   write_pdb_outputR²  R„  t   inputt   construct_hierarchyt   modelsRŽ  R   R  t   residue_groupst   identity_to_rmsR³  R   t   SculptorEnsembleRS   RU   RT   (   R	   R¼   R   R   R~  Rš  R¤  R„  Ry   R±  t   unknownRª  R¯  t
   bp_unknownt
   unique_mist   outensemblest   iotbxt   tagt   bpR£   t   outfilet   outfile_rootRe  t   rmsdRi   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR¢  [  s†    												"							c      
   C   sÐ   d d l  m } g  } t ƒ  } xª |  j D]Ÿ \ } } }	 | j d | d | d |	 d | ƒ }
 t g  |
 j D]$ \ } } | j ƒ  ri | | f ^ qi ƒ } | | k r¨ q) n  | j | ƒ | j	 | |
 f ƒ q) W| S(   Niÿÿÿÿ(   Rš  Rª  R«  R¬  R~  (
   Rë   Rš  Re   RŸ  RÀ  R  R:   t   is_structural_changeR>   RT   (   R	   Rª  R±  R~  Rš  t
   blueprintsR  Rœ  RÏ  R'   RÐ  R.   R£   t   mods(    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRÁ  ¸  s"    			!c         C   s   d S(   Ns   ModelGeneration (sculptor)(    (   R	   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRZ   Ö  s    (   R!   R"   R#   R   RI   R¢  RÁ  RZ   (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR™    s   	/	]	t	   DataFetchc           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s   
    Fetches models
    c         C   s(   t  d |  d t j ƒ |  _ | |  _ d  S(   NR
   R   (   R   R   R`   R6   t   site(   R	   RØ  (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR   à  s    c   	      C   sÇ  | j  j d t  j d d ƒ ƒ | j  j d d d d ƒ | j  j d d | j ƒ  ƒ | j  j d t  j ƒ  ƒ | j  j d t | ƒ ƒ | j  j d d	 ƒ | j j |  ƒ |  j	 d
 | j
 d | d | ƒ } | | j
 _ t | t j ƒ r&| j  j d d | j ƒ | j  j d t  j d d ƒ ƒ d  S| j ƒ  } g  | j d t j ƒ D] } | j ƒ  | k rH| ^ qH} t j d | d | d t | ƒ d ƒ } | j d | ƒ | j  j d t  j d d ƒ ƒ d  S(   NR   R7   s   Homology search - fetchR8   R9   R:   s
   Data fetchs   Space group %sRK   t   hssR   R   s   This entry cannot be used: %ss   Fetch finishedR   RM   R<   RN   i   RO   (   R   R?   R@   RA   RB   RC   R   R   R>   t   fetchRÙ  t   fetchedRg   R   t   BadHomologySearchEntryt   reasonRG   RM   R   R   R^   R   RU   (	   R	   R;   R   R   R   R¼   RM   t   tsR¬  (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRI   æ  s4    !	c         C   s7  | j  r# | j j d d ƒ | j  S| j j j d | ƒ | j } d d  l } d d  l } yR | j	 j
 j
 d | j d |  j ƒ } | j	 j d | j ƒ  d |  j ƒ j ƒ  } Wn= t k
 rë } | j j d d	 | ƒ t j d
 | d | ƒ SX| j ƒ  s!| j j d d ƒ t j d
 | d d ƒ S| j j d d | j ƒ | j ƒ  j d | j ƒ }	 | j |	 t ƒ }
 |
 j ƒ  s¥| j j d d ƒ t j d
 | d d | j ƒ Sd | j | j f } | j j d d | ƒ |
 j | ƒ t j d | d | j ƒ  d | j ƒ } | j j d d | ƒ | j j j d | ƒ | S(   NR   s   This entry has been fetchedRO   iÿÿÿÿR™  t   mirrort   linest   source_infos	   Error: %sRÙ  RÝ  s   Error: PDB file emptys
   Empty files   Selecting reference chain %ss
   chain '%s's%   Error: No atoms after chain selections   No chain '%s's	   %s_%s.pdbs   Writing out file: %st   pdb_fileR»  RS   s   Saving template: %s(   RÛ  R   R?   RP   R:   Rv   t   hitt   iotbx.pdb.fetchRÂ  R„  RÚ  t
   identifierRØ  RÄ  R   RÅ  R±   R   RÜ  RŽ  R‹  t   atom_selection_cacheR3   Rc   R+   t   write_pdb_fileR]   t   alignment_objectRS   RU   (   R	   RÙ  R   R   Rã  RÎ  Rª   Ry   RJ   t   asct   croott	   file_nameR¼   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRÚ    sF    		$		c         C   s   d |  j  S(   Ns   DataFetch (%s)(   RØ  (   R	   (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyRZ   C  s    (   R!   R"   R#   R   RI   RÚ  RZ   (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyR×  Û  s
   		)	4c         C   sN  | j  d |  j ƒ r5 | j d |  j ƒ t d ‚ n  | j d |  j ƒ r• | j d ƒ | j d |  j ƒ } | sx t ‚ | j d | ƒ | |  _ n  | j d ƒ | j d |  j ƒ } | j ƒ  sÜ | j d ƒ t d ‚ n  | j d	 |  j	 ƒ | j
 ƒ  j d
 |  j	 ƒ } | j | t ƒ } | j ƒ  sJ| j d ƒ t d |  j	 ‚ n  | S(   NRå  s   Entry %s has been retracted
t	   retracteds   This entry has been obsoleted
s   Replacement entry: %s
s   Retrieving file...
s   Error: PDB file empty
t   emptys   Selecting reference chain %s
s
   chain '%s's&   Error: No atoms after chain selection
s   no chain '%s'(   Rì  Rå  RU   R±   t	   obsoletedt   replacement_forRu   t   fetch_entryRŽ  R‹  Ræ  R3   Rc   R+   (   Rã  R„  t   redirectionsRª   t   replRy   Ré  Rê  (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyt   download_homology_hit_modelH  s*    (7   t
   __future__R    Rt   R   R   R   Rë   R   t   libtbx.utilsR   R  R[  R¶  R   R$   R/   R4   Ra   R�   R‰   R˜   R¥   RÂ   RÉ   RÖ   Rá   R  R  R  Rg  R”  Rª  R«  R·  R½  RÅ  RÍ  Rá  Rñ  Rò  R  R  R  R  R  R  R*  R,  R1  RO  Rv  Rw  R™  R×  Ró  (    (    (    sD   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/expert.pyt   <module>   sd   !PˆElQÀ€kó		Ñ¯f	\,9>¥KJ	a				/X]$qÔÿ ['Ám