ó
š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 m	 Z	 m
 Z
 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 m Z d  d l m Z d  d l Z d  d l m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l  Z  d  d l! m! 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' e" f d( „  ƒ  YZ. d) e" f d* „  ƒ  YZ/ d+ e/ f d, „  ƒ  YZ0 d- e/ f d. „  ƒ  YZ1 d/ e/ f d0 „  ƒ  YZ2 d1 e/ f d2 „  ƒ  YZ3 d3 e/ f d4 „  ƒ  YZ4 d5 e/ f d6 „  ƒ  YZ5 d7 e/ f d8 „  ƒ  YZ6 d9 e/ f d: „  ƒ  YZ7 d; e/ f d< „  ƒ  YZ8 d= e/ f d> „  ƒ  YZ9 d? e" f d@ „  ƒ  YZ: dA e: f dB „  ƒ  YZ; dC e; f dD „  ƒ  YZ< dE e; f dF „  ƒ  YZ= dG e; f dH „  ƒ  YZ> dI e: f dJ „  ƒ  YZ? dK e" f dL „  ƒ  YZ@ d S(M   iÿÿÿÿ(   t   bba(   t   mr_object_new(   t   process_model_new(   t   mr_calculation(   t   OCAHTTPt   DbfetchHTTPt   ClustalWSynchronoust   SuperposePdbs(   t
   chisel_new(   t   sculptor(   t	   tbx_utils(   t   rsam(   t   ncs(   t   bioinformaticsN(   t   Sorry(   t   StringIOt
   Controllerc           B   s>   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z d „  Z RS(   s'   
    Coordinates knowledge sources
    i   c         C   s+   | d | ƒ |  _  | |  _ t ƒ  |  _ d  S(   Nt	   processes(   t   poolt   max_jobst   sett   jobs(   t   selft
   pool_classR   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyt   __init__(   s    	c      
   C   s  xüt  rþt } t |  j ƒ |  j k  r| j d |  d d ƒ x× | D]¶ } | j d | d d ƒ | j d | ƒ } | j d | d d ƒ | rD | j d | d d ƒ | j d | d d | ƒ | j d	 |  d
 | d | ƒ | j d | d d ƒ t  } PqD qD W| j d |  d d ƒ n  |  j	 d | ƒ } xx | D]p } | j d |  d d ƒ | j
 j d | j d | j d | j d | ƒ | j d |  d d ƒ |  j j | ƒ q0W| r | r |  j rá| j d |  d d ƒ t j d ƒ qû| j d |  d d ƒ Pq q Wd  S(   Nt   srct   msgs+   available cpus - querying knowledge sourcess   evaluation phaset
   blackboards   evaluation finisheds   action phases   candidate %st   contextt	   candidates   action completes   no knowledge sources can acts   processing finished jobt   calculationt   initialt   resultss   job processing finisheds(   suspending to wait for jobs to finish...i   s%   exiting as no further action possible(   t   Truet   Falset   lenR   R   t   debugt   inspectt   infot
   manipulatet   finished_jobst   ownert   processR   R   R    t   removet   timet   sleep(   R   R   t   expertst   actiont   ksR   R(   t   job(    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyt   run/   sZ    					
						c      
   C   sD   t  d | d | d | d |  j j | j ƒ ƒ } |  j j | ƒ d  S(   NR)   R   R   R    (   t   JobR   t   apply_asyncR2   R   t   add(   R   R)   R   R   R1   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyt   submitq   s    c         C   s)   g  |  j  D] } | j j ƒ  r
 | ^ q
 S(   N(   R   R    t   ready(   R   t   j(    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR(   |   s    c         C   s   d S(   NR   (    (   R   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyt   __str__�   s    (   t   __name__t
   __module__t   __doc__R   R2   R6   R(   R9   (    (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR   #   s   	B		t   PhaserAIc           B   s_   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 e
 d	 d „ ƒ Z RS(
   s    
    Coordinates MR process
    c         C   s=   d |  _  | |  _ d |  _ t ƒ  |  _ d |  _ | |  _ d  S(   Ng      è?(   t   initial_thresholdt   solverst   refinement_thresholdt   RefinementExpertt   refinet   commit_thresholdt
   controller(   R   R?   RD   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR   ‹   s    				c            s@  | j  j d ƒ x3 t rE |  j d | ƒ | j d t j ƒ s Pq q W| j d |  d d ƒ | j d |  d d ƒ | j j j	 } | j d |  d d | ƒ t
 | j d t j ƒ d	 d
 „  d t ƒ} t ƒ  } t } t } | j d t | ƒ ƒ xi t | ƒ D][ \ } } | j d |  d d | ƒ | j ƒ  }	 | j d |  d d |	 ƒ | j j ƒ  }
 qþ Wt g  | j d t j ƒ D] } | j ƒ  | j f ^ qvƒ ‰  g  | D] } | | j ƒ  k r¡| ^ q¡} | j d |  d d | ƒ ˆ  | j ƒ  r| j d |  d d ƒ n | j d |  d d ˆ  | ƒ t | d	 ‡  f d †  ƒ} | | k rf| j d |  d d ƒ n | j d |  d d | ƒ xè | D]à } | j d |  d d | ƒ | j ƒ  }	 | j d |  d d |	 ƒ | |	 k ræ| j ƒ  n  g  | j d t j ƒ D] } | j ƒ  t k rü| ^ qü} t | ƒ d k s8t ‚ | d j j ƒ  r‡| j d |  d d ƒ q‡q‡q‡W|  j j d t |  j ƒ ƒ |  j j d t |  j ƒ ƒ |  j j d |  j ƒ } x| |  j D]q } |  j j t | ƒ ƒ |  j j  d | d | ƒ } |  j j d t | ƒ ƒ |  j j d | j! ƒ  j" ƒ  ƒ qÇWd  S(   Ns    AI: starting solution process...R   t   typeR   R   s   solution process finisheds   evaluating resultss   best score %.3ft   keyc         S   s
   |  j  ƒ  S(   N(   t   score(   t   i(    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyt   <lambda>¦   s    t   reverses   %s peaks above thresholds   peak %ss
   score %.3fs   best scorer is %ss!   corresponds to target compositions
   missing %sc            s   ˆ  |  j  ƒ  S(   N(   t   mw(   RH   (   t   missing_composition_for(    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRI   Ê   s    s'   this is also the most complete solutions   most complete is %si   i    s$   corresponds to specified compositions!   %s were outperformed and rejecteds!   %s has yielded complete solutionst   casest   caset	   thresholds*   	There are %s partials above the thresholds   	Best score: %s(#   t   loggerR&   R!   t   mr_roundt   readt   staget   Refinedt   problemRG   t   valuet   sortedt   InitialR   R"   R#   t	   enumeratet   partialt	   ancestorst   dictt   CompositionR   t   missingt   is_emptyt   mint   AssertionErrort   _loggert
   _bad_casest   _solved_casest
   _ps_selectt   threshold_scoret   _finished_casest   strt   promising_partial_structurest
   statisticst
   best_score(   R   R   t   bestt   initialst	   processedt   potentially_smallert   potentially_largert   indext   currentRG   R[   t   cRH   t   best_scorert   most_completet   compositionsRO   t   partials(    (   RL   sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyt   solve•   sŽ    				7+	
		
		
				c         C   sÂ  | j  d |  d d ƒ | j  d |  d d ƒ xG | j d t j ƒ D]0 } | j d |  d d | ƒ | j j | ƒ qB W|  j d | ƒ |  j j	 d | d |  j
 ƒ |  j d | ƒ |  j j	 d | d |  j g ƒ |  j d | ƒ g  | j d t j ƒ D] } | ^ q÷ } | j  d |  d d	 t | ƒ ƒ x’ | D]Š } | j j d
 | j ƒ } | sv| j j d
 | j d | j ƒ q0| j  d |  d d | ƒ x' | D] } | j j | j ƒ  j ƒ q—Wq0Wd  S(   NR   R   s   starting MR round...s   clearing blackboard...RE   s   deleting %sR   R.   s   %s peaks have been refinedt	   structureRG   s   %s: not unique(   R&   RR   RS   t   StageR$   t   dataR+   t   initial_selectRD   R2   R?   t   refinement_selectRB   t   record_search_coverageRT   R#   RN   t   equivalents_forRy   t   insertt   llgt   predecessorsR5   R   RZ   (   R   R   t   objt   stt   refst   rt   equivt   e(    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRQ     s*    (	"c         C   sè  | j  d t j ƒ } | s5 | j d |  d d ƒ d  S| j d |  d d t | ƒ ƒ | j j j } | d |  j t	 | ƒ } | j d |  d d | ƒ xH| D]@} | j d |  d d ƒ g  | j
 D]$ } | | j d	 | ƒ k rÆ | ^ qÆ } | s	| j d
 ƒ q  n  | j d |  d d t | ƒ ƒ | d g } | d j ƒ  }	 x> | d D]2 }
 |
 |	 k rQ| j |
 ƒ |	 j |
 j ƒ qQqQW| j d |  d d t | ƒ ƒ x6 | D]. }
 t j d | d	 |
 ƒ } | j j | ƒ q®Wq  Wd  S(   NRE   R   R   s   no active cases availables   %s cases activeg      ð?s   threshold: %.3fs   case %sRZ   s   No above threshold peaks founds   %d foundi    i   s,   %d after removing ancestors with lower scoreRN   (   RR   t	   mr_objectt   CaseR&   R#   RU   RG   RV   R>   t   absRw   t	   score_forR[   t   appendt   updateRS   RX   R{   R5   (   R   R   RM   Rl   RO   RN   t   pt	   promisingt   selectedR[   Ry   R„   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR|   1  s6     4 	c         C   s  | j  d t j ƒ } t s5 | j d |  d d ƒ d  S| j d |  d d t | ƒ ƒ t g  t D] } | j ƒ  ^ q_ ƒ } | d |  j t	 | ƒ } | j d |  d d | ƒ x_ t D]W } | | j ƒ  k r¶ | j d |  d d | ƒ t j
 d	 | ƒ } | j j | ƒ q¶ q¶ Wd  S(
   NRE   R   R   s   no refinement candidatess   %s refinement candidatesg      ð?s   threshold: %.3fs   Selected %st   parent(   RR   RS   t   Packingt   stagesR&   R#   t   maxRG   R@   R‹   t   SignificantR{   R5   (   R   R   t
   candidatesR�   Rl   RO   R„   t   ref(    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR}   \  s    	%c   
      C   sÙ  | j  d t j ƒ rD | j d |  d d ƒ | j d |  d d ƒ n  xh | j  d t j ƒ D]Q } | j rZ | j d |  d d | ƒ t j d | j ƒ } | j	 j
 | ƒ qZ qZ Wi  } xB | j  d t j ƒ D]+ } t j | j j t ƒ  ƒ j
 | j ƒ qË Wx¹ | j ƒ  D]« \ } } t | j ƒ | k r| j d |  d d | ƒ t j d | j j ƒ } | j	 j
 | ƒ xE | j  d t j ƒ D]+ } | j j | k r€| j	 j | ƒ q€q€WqqWi  } xB | j  d t j ƒ D]+ } t j | j j t ƒ  ƒ j
 | j ƒ qÒWxÑ | j ƒ  D]Ã \ }	 } t |	 j ƒ | k r| j d |  d d |	 ƒ t j d	 |	 j j d
 |	 j j d |	 j j ƒ } | j	 j
 | ƒ xE | j  d t j ƒ D]+ } | j j |	 k rŸ| j	 j | ƒ qŸqŸWqqWd  S(   NRE   R   R   s   Calculations have faileds'   Coverage calculations will be incorrects   %s has been processedt   peaks"   All peaks in %s has been processedRN   RZ   t   ensemble(   RR   RS   t   FailureR&   t   TranslationRn   t   recordt   TranslationPeakR™   R{   R5   t   processed_int
   setdefaultt   functionR   t   itemst   peakst   RotationPeakR   t   rpeakR+   t   EnsembleRN   RZ   Rš   (
   R   R   t   tt   rect   processed_in_trafunt   trafunRn   R†   t   processed_in_rotfunt   rotfun(    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR~   t  sN    	
	)	)		c         C   s   d S(   NR=   (    (   R   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR9   ¸  s    c         C   sg   t  ƒ  t ƒ  t ƒ  t ƒ  t ƒ  t ƒ  t ƒ  t ƒ  g } |  d | d | d | d | d g  d | ƒ } | S(   NRU   t   compositiont
   symmetriesR?   t	   modellerst	   outstream(   t   ScoringExpertt   TemplateSolveSuperposeExpertt   TemplateSolveInitiateExpertt   EvaluationExpertt   PackingExpertt   TranslationSearchExpertt   RotationSearchExpertt   EnsembleApplicabilityExpert(   t   clsRU   R­   R®   R°   R?   t   ai(    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyt   MRMode½  s     	N(   R:   R;   R<   R   Rx   RQ   R|   R}   R~   R9   t   classmethodt   NoneR»   (    (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR=   †   s   	
	r	*	+		D	t   CalculateMissingc           B   s    e  Z d  Z d „  Z d „  Z RS(   s(   
    Calculate missing composition 
    c         C   s©   g  | j  d t j ƒ D] } | j s | ^ q } | sV | j d |  d d ƒ d  } nO | j d |  d d t | ƒ ƒ t | d d „  ƒ} | j d |  d d | ƒ | S(	   NRE   R   R   s   no candidates founds   %s candidates foundRF   c         S   s
   |  j  ƒ  S(   N(   RG   (   RS   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRI   ë  s    s   selected %s(   RR   RS   RX   Rn   R$   R½   R#   R•   (   R   R   Rs   R—   R‘   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR%   Û  s    		c         C   s‡   t  | _ | j j j ƒ  } x' | j j ƒ  D] } | j | j ƒ q+ W| j	 d |  d d ƒ t
 j d | d | ƒ } | j j | ƒ d  S(   NR   R   s   calculated missing partR’   R^   (   R!   Rn   RN   R­   t   copyRZ   t	   ensemblest   subtractt	   componentR$   RS   R]   R{   R5   (   R   R   R   R   R^   Rˆ   R„   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR'   ò  s    	(   R:   R;   R<   R%   R'   (    (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR¾   Ö  s   	t   FindEnsemblec           B   s    e  Z d  Z d „  Z d „  Z RS(   s*   
    Find ensembles for missing part 
    c         C   s©   g  | j  d t j ƒ D] } | j s | ^ q } | sV | j d |  d d ƒ d  } nO | j d |  d d t | ƒ ƒ t | d d „  ƒ} | j d |  d d | ƒ | S(	   NRE   R   R   s   no candidates founds   %s candidates foundRF   c         S   s
   |  j  ƒ  S(   N(   RG   (   RS   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRI     s    s   selected %s(   RR   RS   R]   Rn   R$   R½   R#   R•   (   R   R   Rs   R—   R‘   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR%     s    		c   	      C   s9  t  | _ t g  | j d t j ƒ D] } | j | j | j f ^ q" ƒ } | j	 ƒ  } xÝ | j d t
 j ƒ D]Æ } | j d |  d d | ƒ | j | j | f | k rÂ | j d |  d d ƒ qk n  t j d | j ƒ só | j d |  d d ƒ qk n  | j d |  d d ƒ t j d	 | d
 | ƒ } t j d | ƒ qk Wd  S(   NRE   R   R   s
   Testing %ss   previously exploredt   others   not in compositions   applicable for extensionR’   Rš   R   (   R!   Rn   R   RR   R�   R¦   RN   RZ   Rš   R   t   process_modelR&   R^   t   containsRÂ   RS   t	   attach_to(	   R   R   R   R   R†   t   recordsR   Rš   R„   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR'     s     	1(   R:   R;   R<   R%   R'   (    (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRÃ   ÿ  s   	t   RotationSearchc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s6   
    Performs rotation search for ensemble stages
    c         C   s©   g  | j  d t j ƒ D] } | j s | ^ q } | sV | j d |  d d ƒ d  } nO | j d |  d d t | ƒ ƒ t | d d „  ƒ} | j d |  d d | ƒ | S(	   NRE   R   R   s   no candidates founds   %s candidates foundRF   c         S   s
   |  j  ƒ  S(   N(   RG   (   RS   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRI   J  s    s   selected %s(   RR   RS   R¦   Rn   R$   R½   R#   R•   (   R   R   Rs   R—   R‘   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR%   :  s    		c         C   sv   t  | _ | j d |  d d ƒ t j d | j d | j d | j ƒ } | j j	 | ƒ | j
 d |  d | d	 | ƒ d  S(
   NR   R   s   Starting rotation searchRN   RZ   Rš   R)   R   R   (   R!   Rn   R&   R   RÉ   RN   RZ   Rš   R{   R5   R6   (   R   R   R   R   t   calc(    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR'   Q  s    				c         C   sL   | j  d t ƒ } | j j | ƒ | j j | ƒ | j d | d | ƒ d  S(   NR    R   R   (   R*   t   resultR{   R+   R5   t   announce(   R   R   R   R    R   R„   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR*   ^  s    (   R:   R;   R<   R%   R'   R*   (    (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRÉ   5  s   		t   TranslationSearchc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s9   
    Performs translation search for rotation stages
    c         C   s©   g  | j  d t j ƒ D] } | j s | ^ q } | sV | j d |  d d ƒ d  } nO | j d |  d d t | ƒ ƒ t | d d „  ƒ} | j d |  d d | ƒ | S(	   NRE   R   R   s   no candidates founds   %s candidates foundRF   c         S   s
   |  j  ƒ  S(   N(   RG   (   RS   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRI   {  s    s   selected %s(   RR   RS   t   RotationRn   R$   R½   R#   R•   (   R   R   Rs   R—   R‘   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR%   k  s    		c         C   sv   t  | _ | j d |  d d ƒ t j d | j d | j d | j ƒ } | j j	 | ƒ | j
 d |  d | d	 | ƒ d  S(
   NR   R   s   Starting translation searchRN   RZ   R¥   R)   R   R   (   R!   Rn   R&   R   RÍ   RN   RZ   R™   R{   R5   R6   (   R   R   R   R   RÊ   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR'   ‚  s    				c         C   sL   | j  d t ƒ } | j j | ƒ | j j | ƒ | j d | d | ƒ d  S(   NR    R   R   (   R*   RË   R{   R+   R5   RÌ   (   R   R   R   R    R   R„   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR*   �  s    (   R:   R;   R<   R%   R'   R*   (    (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRÍ   f  s   		t   PackingCheckc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s7   
    Performs packing check for translation stages
    c         C   s©   g  | j  d t j ƒ D] } | j s | ^ q } | sV | j d |  d d ƒ d  } nO | j d |  d d t | ƒ ƒ t | d d „  ƒ} | j d |  d d | ƒ | S(	   NRE   R   R   s   no candidates founds   %s candidates foundRF   c         S   s
   |  j  ƒ  S(   N(   RG   (   RS   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRI   ¬  s    s   selected %s(   RR   RS   Rœ   Rn   R$   R½   R#   R•   (   R   R   Rs   R—   R‘   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR%   œ  s    		c         C   s[   t  | _ | j d |  d d ƒ t j d | ƒ } | j j | ƒ | j d |  d | ƒ d  S(   NR   R   s   Starting packing checkR’   R)   R   (   R!   Rn   R&   RS   t   PackingCalculationR{   R5   R6   (   R   R   R   R   RÊ   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR'   ³  s
    	c         C   sL   | j  d t ƒ } | j j | ƒ | j j | ƒ | j d t d | ƒ d  S(   NR    R   R   (   R*   RË   R{   R+   R5   RÌ   R   (   R   R   R    R   R„   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR*   ¼  s    (   R:   R;   R<   R%   R'   R*   (    (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRÏ   —  s   			t
   Refinementc           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s   
    Refines peaks
    c         C   s©   g  | j  d t j ƒ D] } | j s | ^ q } | sV | j d |  d d ƒ d  } nO | j d |  d d t | ƒ ƒ t | d d „  ƒ} | j d |  d d | ƒ | S(	   NRE   R   R   s   no candidates founds   %s candidates foundRF   c         S   s
   |  j  ƒ  S(   N(   RG   (   RS   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRI   Ù  s    s   selected %s(   RR   RS   R–   Rn   R$   R½   R#   R•   (   R   R   Rs   R—   R‘   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR%   É  s    		c         C   s[   t  | _ | j d |  d d ƒ t j d | ƒ } | j j | ƒ | j d |  d | ƒ d  S(   NR   R   s   Starting refinementR’   R)   R   (   R!   Rn   R&   RS   t   RefinementCalculationR{   R5   R6   (   R   R   R   R   RÊ   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR'   à  s
    	c         C   s6   | j  d t ƒ } | j j | ƒ | j j | ƒ d  S(   NR    (   R*   RË   R{   R+   R5   (   R   R   R    R   R„   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR*   é  s    (   R:   R;   R<   R%   R'   R*   (    (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRÑ   Ä  s   			t   AIc           B   s;   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s    
    MR solution controller
    c         C   s4   d |  _  g  |  _ g  |  _ t ƒ  |  _ t |  _ d  S(   Ni   (   t   cpusR.   t   _queueR   t   _runningt
   Sequentialt   _engine(   R   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR   ö  s
    			c         C   sé   xâ t  rä t  } d |  j k  r² x‘ |  j D]v } | j d | ƒ } | r( | j j d | ƒ | j j d | ƒ | j d | d | ƒ | j j d ƒ t } Pq( q( W|  j s² Pq² n  |  j	 d | ƒ } | r | r t
 j d ƒ q q Wd  S(   Ni    R   s   %s - action phases   Candidate: %sR   s   Action complete
i   (   R!   RÔ   R.   R%   RP   R&   R'   R"   RÖ   t   pollR,   R-   (   R   R   t   suspendR0   R   t   new_results(    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRx   ÿ  s"    		c      	   C   sB   |  j  d | d | d | d | ƒ } |  j j | ƒ |  j ƒ  d  S(   NR)   t   protocolt	   executiont
   processing(   RØ   RÕ   R�   t   spool(   R   R)   RÜ   RÝ   RÞ   R1   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR6     s    		c         C   sý   t  } xð t |  j ƒ D]ß } | j ƒ  s. q n  t j d ƒ t } t j | j ƒ | j	 r™ |  j j d | j
 ƒ | j
 j d | j d | d | j ƒ n0 t j d | j
 ƒ | j
 j d | d | j ƒ |  j j | ƒ |  j d 7_ t j d ƒ q W| S(	   Ns   Poll - job finisheds&   %s - processing successful job resultsR    R   t   extras"   %s - processing failed job resultsi   s   Processing complete
(   R"   t   listt   _jobst   finishedRP   R&   R!   R$   t   logfilet   successR)   t   process_successR    RÞ   t   process_failureR+   RÔ   (   R   R   RÛ   R1   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRÙ   &  s*    		
c         C   s^   xW d |  j  k  rY |  j rY |  j j d ƒ } | j ƒ  |  j  d 8_  |  j j | ƒ q Wd  S(   Ni    i   (   RÔ   RÕ   t   popR2   RÖ   R5   (   R   R1   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRß   H  s
    
(   R:   R;   R<   R   Rx   R6   RÙ   Rß   (    (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRÓ   ñ  s   					"R×   c           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s=   
    Simple engine that executes jobs on the main thread
    c         C   sL   | |  _  | |  _ | |  _ | |  _ t |  _ d  |  _ d |  _ d  |  _ d  S(   Nt    (	   R)   RÞ   RÜ   R"   t	   _finishedR½   Rå   Rä   R    (   R   R)   RÜ   RÝ   RÞ   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR   V  s    							c         C   s4   |  j  d |  j ƒ \ |  _ |  _ |  _ t |  _ d  S(   NR{   (   RÜ   RÝ   Rå   Rä   R    R!   Rê   (   R   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR2   b  s    	c         C   s   d  S(   N(    (   R   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRÙ   j  s    c         C   s   |  j  S(   N(   Rê   (   R   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRã   o  s    (   R:   R;   R<   R   R2   RÙ   Rã   (    (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR×   Q  s
   			c           B   s‰   e  Z d  Z i d d 6d d 6d d 6d d 6d	 d
 6d d 6Z d d „ Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 e d d „ ƒ Z RS(   s   
    AI object for MR
    sB   All MRCases have been explored and decisively evaluated. Finishings   ALL DONEs+   There were altogether %s MRCases considereds   REPORT - CAPTIONsG   		This partial structure is complete wrt current composition and modelss   EVAL - FULL SOLUTIONsB   	All current models have been explored with this partial structures   EVAL - EXHAUSTEDsQ   	All selected partial structures are complete. This case can be considered solveds   EVAL - CASE SOLVEDsá   	All possible extensions have been tried, but either not applicable or yield
	worse results than intermediate solutions. This may indicate that the solvent
	content is higher than expected and there are less molecules to finds   EVAL - CASE EXHAUSTEDc   
      C   s‰  t  j j d ƒ s" t  j d ƒ n  t j d t  j j d ƒ ƒ |  _ | |  _ x? | D]7 } t	 j
 d | d | d | ƒ } | j d |  j ƒ qS Wt d d ƒ |  _ | |  _ | |  _ t d d ƒ |  _ t ƒ  |  _ t ƒ  |  _ t j d	 d
 t |  ƒ ƒ |  _ |  j j t j ƒ | r&t j | ƒ }	 n t j ƒ  }	 |	 j t j  d ƒ ƒ |  j j! |	 ƒ t" ƒ  |  _# t" ƒ  |  _$ t" ƒ  |  _% t& |  _' d  S(   Nt   pipelinet	   directoryR­   RU   t   space_groupR   t   fractiong      è?t   names   PhaserAI.%ss   %(message)s((   t   ost   patht   existst   mkdirR    t
   Blackboardt   abspatht   _bbt   _problemRÅ   RŠ   RÇ   t   PSSelectRe   t   _solverst
   _modellerst   TPSelectt
   _tp_selectRA   t   _refineR   t   _controllert   loggingt	   getLoggert   idRb   t   setLevelt   INFOt   StreamHandlerR
   t   NullHandlert   setFormattert	   Formattert
   addHandlerR   Rd   Rc   Rg   R"   t   _all_models_present(
   R   RU   R­   R®   R?   R¯   R°   t   symmRN   t   handler(    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR   Ž  s6    
!					c         C   s   | j  d |  j ƒ d  S(   NR   (   RÇ   Rö   (   R   t   bbobj(    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR5   ¿  s    c         C   s   |  j  S(   N(   Rb   (   R   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRP   Ä  s    c         C   sp  |  j  j d ƒ xG t rY |  j ƒ  |  j j d t j ƒ s |  j  j |  j d ƒ Pq q W|  j  j d ƒ |  j  j |  j d t	 |  j
 ƒ t	 |  j ƒ ƒ |  j  j d t	 |  j
 ƒ ƒ |  j  j d t	 |  j ƒ ƒ |  j j d |  j ƒ } x| |  j D]q } |  j  j t | ƒ ƒ |  j j d	 | d
 | ƒ } |  j  j d t	 | ƒ ƒ |  j  j d | j ƒ  j ƒ  ƒ q÷ Wd  S(   Ns   Starting solution process...RE   s   ALL DONEs   Solution process finisheds   REPORT - CAPTIONs!   %s were outperformed and rejecteds!   %s has yielded complete solutionsRM   RN   RO   s*   	There are %s partials above the thresholds   	Best score: %s(   Rb   R&   R!   RQ   Rö   t   read_instances_ofRÅ   RŠ   t   MESSAGESR#   Rc   Rg   Rd   Re   Rf   Rh   Ri   Rj   Rk   (   R   RO   Rs   Rw   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRx   É  s.    	
	
				c         C   sŸ  |  j  j d ƒ |  j  j d ƒ x* |  j j d t j ƒ D] } | j ƒ  q9 W|  j  j d |  j ƒ |  j j	 d |  j d |  j  ƒ |  j  j d ƒ |  j
 j d |  j d |  j d |  j  ƒ |  j  j d |  j ƒ |  j j	 d |  j d |  j  ƒ |  j  j d ƒ |  j  j d	 ƒ |  j s^|  j
 j d |  j d |  j ƒ |  _ |  j r^|  j  j d
 ƒ q^n  |  j j d t j ƒ } |  j  j d t | ƒ ƒ t g  |  j j d t j ƒ D] } | j ƒ  ^ q¬ƒ } x| D]} |  j  j d | ƒ g  |  j j d t j ƒ D] } | j ƒ  | k r| ^ q} g  |  j j d t j ƒ D] } | j ƒ  | k r>| ^ q>} g  |  j j d t j ƒ D] } | j ƒ  | k r{| ^ q{}	 | rÈ|  j  j d ƒ |  j  j d ƒ n  | s7|  j  j d ƒ | r|  j  j d ƒ |  j j | ƒ n  |  j  j d ƒ |  j j | ƒ | j ƒ  qÎn  |  j  j d t | ƒ ƒ g  }
 x9t | ƒ D]+\ } } |  j  j d | d ƒ |  j  j d t | j ƒ  ƒ ƒ |  j  j d t | j ƒ  ƒ t | j ƒ  ƒ f ƒ |  j  j d t | j ƒ  ƒ ƒ t g  |	 D]0 } | j  ƒ  | k rt! | t j" ƒ r| ^ qƒ } g  |	 D] } | j  ƒ  | k rE| ^ qE} g  |	 D]' } | j# d t j" ƒ | k rp| ^ qp} |  j  j d t | ƒ t | ƒ f ƒ |  j  j d t | ƒ ƒ | j ƒ  rd| rdt g  | j ƒ  D]3 } t j j$ d | j ƒ  d | j% ƒ  d | ƒ ^ qƒ } |  j r�| j& | ƒ r�|  j  j |  j' d ƒ |  j( j | ƒ |
 j) | ƒ q�qdqdWt |
 ƒ t | ƒ k rÎ|  j  j |  j' d ƒ |  j j | ƒ | j ƒ  qÎqÎqÎW|  j
 j d |  j d |  j* g d |  j  ƒ g  |  j j d t j+ ƒ D] } | ^ q*} |  j  j d t | ƒ ƒ xB | D]: } | j ƒ  j, d | j- ƒ  j% ƒ  d  | j- ƒ  j. ƒ  ƒ q]Wd  S(!   Ns   Starting MR round...s   Clearing blackboard...RE   s   %s - analysis startsR   RP   s   Analysis finished
R.   s   Evaluating results...s    All basic models are now presents!   There are still %s MRCases actives   Trial case: %ssC   	Partial structures have been selected that had already been testeds#   	These were not pursued any furthers)   	This case cannot be advanced any furthers1   	All selected partial structures have been testeds)   	No partial structure was above thresholds1   	%s initial partial structure has been identifieds"   	Partial structure %s - Statisticsi   s   		%s ensembles considereds   		%s tested for suitabilitys   		%s remain untesteds9   		%s calculations have been done from %s tested ensembless   		%s calculations altogetherRN   RZ   Rš   s   EVAL - FULL SOLUTIONs   EVAL - CASE SOLVEDs!   	%s refined peaks have been foundRG   (/   Rb   R&   R$   Rö   R  RÅ   t   RoundObjectt   detach_from_blackboardRe   t   analyseRþ   R2   Rù   Rü   R	  t
   any_activeRú   RŠ   R#   R   t   ExhaustionRecordt
   identifiert   InitialStageRN   t   RejectedStaget   DescendantNodeRg   R5   Rc   RY   RÀ   t   untestedR’   t
   isinstancet   EnsembleStaget   predecessort
   descriptorRZ   t
   issupersetR  Rd   R�   Rý   t   RefinedStageR€   t   finalR�   (   R   Rƒ   RM   R¨   t   exhaustionsRN   RS   t   initial_stagest   rejected_stagest   descendant_stagest   terminal_stagesRq   t   iniR„   t   ensemble_stagest   immediate_successor_stagest   all_successor_stagesRˆ   t   identsR…   R†   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRQ   î  sÌ    		
				%			
				'	!			F

	
(c         C   s5  x.| j  d t j ƒ D]} g  | j D] } | j r& | ^ q& } | sM q n  t t t j g  | D] } | j	 ^ q` ƒ ƒ } g  | j
 D] } | j | k r… | ^ q… } | s² t ‚ xx| D]9} g  | j D] } | j rÉ | ^ qÉ } | sî Pn  t t t j g  | D] } | j ^ qƒ ƒ }	 g  | j
 D] }
 |
 j |	 k r&|
 ^ q&} | sSt ‚ g  | D]. }
 g  |
 j ƒ  D] } | j
 sm| ^ qm^ qZ} t g  | D] } t | ƒ d k ^ q˜ƒ s¿t ‚ t g  | D] } t | d |  j ƒ ^ qÉƒ s¹ Pq¹ q¹ Wt j d | j d | j d | j ƒ } | j d | ƒ q Wd  S(   NRE   i   i    RN   RZ   Rš   R   (   R  RÅ   R  t   searchest
   exhaustiveR   t   reducet   operatorR5   t	   rotationst   childrent   rotationRa   t   translationst   translationt   descendantst   allR#   R  t   LEAVESt   ExtensionRecordRN   RZ   Rš   RÇ   (   R   R   RS   t   st   rot_search_exht
   rot_st_allt   rst
   rot_st_actt   tra_search_exht
   tra_st_allt   tst
   tra_st_actt   nt   leavest   lR¨   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyt   record_extensions�  s6    %++%++81,			c         C   sg   t  ƒ  t ƒ  t ƒ  t ƒ  t ƒ  t ƒ  t ƒ  t ƒ  g } |  d | d | d | d | d g  d | ƒ } | S(   NRU   R­   R®   R?   R¯   R°   (   R±   R²   R³   R´   Rµ   R¶   R·   R¸   (   R¹   RU   R­   R®   R°   R?   Rº   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR»   ¿  s     	N(   R:   R;   R<   R  R½   R   R5   RP   Rx   RQ   RC  R¼   R»   (    (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR=   t  s    
*			%	¡	0c           B   s_   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 e
 d	 „  ƒ Z RS(
   s'   
    Coordinates knowledge sources
    i   c         C   sN   t  ƒ  |  _ d |  _ t j d d t |  ƒ ƒ |  _ |  j j t j	 ƒ  ƒ d  S(   Ni   Rï   s   Controller.%s(
   R   Râ   t	   _max_jobsRÿ   R   R  Rb   R  R
   R  (   R   R   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR   Ü  s    	c      
   C   sõ   xî t  rð t  } |  j ƒ  r¸ xš | D] } | j d | d | ƒ } | r" | j d | ƒ | j d | ƒ | j d |  d | d | d | ƒ | j d ƒ t } Pq" q" W|  j ƒ  s¸ Pq¸ n  |  j d | d | ƒ } | r | r t j	 d ƒ q q Wd  S(	   NR   RP   s   %s - action phases   Candidate: %sR   R   s   Action complete
i   (
   R!   t   available_cpusR%   R&   R'   R"   t   running_calculationsRÙ   R,   R-   (   R   R   R.   RP   RÚ   R0   R   RÛ   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR2   ä  s*    		c         C   s   t  |  j ƒ |  j k  S(   N(   R#   Râ   RD  (   R   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRE    s    c      	   C   sh   t  |  j ƒ |  j k  s t ‚ t d | d | d | d | ƒ } | |  j k sT t ‚ |  j j | ƒ d  S(   NR)   RÜ   RÝ   RÞ   (   R#   Râ   RD  Ra   t   EngineR5   (   R   R)   RÜ   RÝ   RÞ   R1   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR6   	  s    	c         C   s   |  j  S(   N(   Râ   (   R   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRF    s    c      	   C   sñ   t  } xä t |  j ƒ D]Ó } | j ƒ  s. q n  | j d ƒ t } | j | j ƒ | j r™ | j d | j	 ƒ | j	 j
 d | j d | d | | j � n3 | j d | j	 ƒ | j	 j d | d | | j � |  j j | ƒ | j d ƒ q W| S(   Ns   Poll - job finisheds&   %s - processing successful job resultsR    R   RP   s"   %s - processing failed job resultss   Processing complete
(   R"   Rá   Râ   Rã   R&   R!   R$   Rä   Rå   R)   Ræ   R    RÞ   Rç   R+   (   R   R   RP   RÛ   R1   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRÙ     s,    		
c            s   t  ‡  ‡ f d †  | Dƒ ƒ S(   Nc         3   s*   |  ]  } | j  d  ˆ  d ˆ j ƒ Vq d S(   R   RP   N(   R%   Rb   (   t   .0R0   (   R   R   (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pys	   <genexpr>A  s   (   t   any(   R   R.   R   (    (   R   R   sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR  >  s    c      
   C   s=   |  d t  ƒ  t ƒ  t ƒ  t ƒ  t ƒ  t ƒ  t ƒ  t ƒ  g ƒ S(   Nt   knowledge_sources(   t   SolutionIdentifyR¶   R·   R¸   t   SculptorExpertt   AlignmentExpertt   StructureFetchExpertt   SequenceFetchExpert(   R¹   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyt	   AutofetchF  s    (   R:   R;   R<   R   R2   RE  R6   RF  RÙ   R  R¼   RP  (    (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR   ×  s   	 				#	Rø   c           B   s;   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   sw   
    Initiates the MR process:
    1. Thresholds peaks
    2. Identifies ensembles that have not been tried before
    c         C   s   | |  _  d  S(   N(   t	   _fraction(   R   Rî   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR   a  s    c      	   C   sÇ  | j  d t j ƒ } | s, | j d ƒ d  S| j d t | ƒ ƒ |  j d | ƒ } | j d | ƒ | j  d t j ƒ } | j d t | ƒ ƒ t g  | j  d t j ƒ D] } | j	 ƒ  ^ q« ƒ } xú | D]ò } | j d | ƒ |  j
 d | d	 | ƒ }	 | j d
 t |	 ƒ ƒ x© |	 D]¡ }
 | j d |
 ƒ t j j d | d |
 ƒ } | | k r€| j d ƒ t j d | d |
 ƒ } n+ | j d ƒ t j d | d |
 d | ƒ } | j d | ƒ qWqÍ Wd  S(   NRE   s   No active cases availables   There are %s cases activeRM   s.   Selection threshold for partial structures: %ss    There are %s ensembles availables   Processing %sRN   RO   s/   There are %s partial structures above thresholdRZ   s$   This partial has already been testeds&   Identified as potential starting pointRÀ   R   (   R  RÅ   RŠ   R&   R#   Rf   R¦   R   t   SelectionRecordR  Ri   R  R  R  RÇ   (   R   R   RP   RM   RO   RÀ   R¨   t   past_selectionsRN   R�   R�   RS   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR  f  sB    %					c         C   sD   t  g  | D] } | j ƒ  j ƒ  ^ q
 ƒ } | d |  j t | ƒ S(   Ng      ð?(   R•   Rj   Rk   RQ  R‹   (   R   RM   Rs   Rl   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRf   š  s    +c         C   s5   g  | j  ƒ  D]$ } | | j d | ƒ k r | ^ q S(   NRZ   (   Rw   RŒ   (   R   RN   RO   R�   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRi      s    c         C   s   d S(   Nt   PartialStructureSelect(    (   R   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR9   ¦  s    (   R:   R;   R<   R   R  Rf   Ri   R9   (    (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRø   Z  s   		4		Rû   c           B   s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   s'   
    Selects above threshold peaks
    c         C   s   | |  _  d  S(   N(   RQ  (   R   Rî   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR   °  s    c   	      C   s	  | j  d t j ƒ } | s, | j d ƒ d  S| j d t | ƒ ƒ t g  | D] } | j ƒ  j ƒ  ^ qM ƒ } | d |  j t	 | ƒ } | j d | ƒ xh | D]` } | j
 ƒ  sË | | j ƒ  j ƒ  k r¡ | j d | ƒ t j d | ƒ } | j d | ƒ q¡ q¡ Wd  S(	   NRE   s   No EvaluationStages availables$   There are %s EvaluationStages activeg      ð?s&   Selection threshold for refinement: %ss   Selected %sR’   R   (   R  RÅ   t   EvaluationStageR&   R#   R•   R™   t   tfRQ  R‹   t   is_solutiont   RefinementStageRÇ   (	   R   R   RP   R”   R�   Rl   RO   R„   t	   ref_stage(    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR  µ  s    	+$c         C   s   d S(   Nt   MRPeakEvaluate(    (   R   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR9   Ì  s    (   R:   R;   R<   R   R  R9   (    (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRû   «  s   		t   KnowledgeSourcec           B   s;   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   sX   
    Knowledge source:
    1. functionality to disable if solutions have been found
    c         C   s   | |  _  | |  _ d  S(   N(   t   _exhaustivet	   _selector(   R   t   selectorR+  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR   Ø  s    	c         C   s  | j  d |  ƒ |  j r/ |  j d | ƒ } n t g  |  j d | ƒ D] } | j ƒ  ^ qE ƒ } | j  d t | ƒ ƒ g  |  j d | ƒ D] } | j ƒ  | k rŠ | ^ qŠ } | sÊ | j  d ƒ d  } n: | j  d t | ƒ ƒ |  j d | ƒ } | j  d | ƒ | j  d ƒ | S(	   Ns   %s - evaluation phaset   bbs,   Omitting stages belonging to %s solved casess   No candidates have been founds   %s candidates has been foundt   choicess   Selected %ss   Evaluation finished
(	   R$   R\  t   fetchR   t	   solutionsRN   R#   R½   R]  (   R   R   RP   R—   t   est   solved_casesR„   R‘   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR%   Þ  s"    	.	c         C   s8   g  | j  d |  j ƒ D] } |  j d | ƒ r | ^ q S(   NRE   R  (   R  t   BBOBJt
   acceptable(   R   R_  Rƒ   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRa  ý  s    c         C   s2   g  | j  d t j ƒ D] } | j ƒ  r | ^ q S(   NRE   (   R  RÅ   RU  RW  (   R   R_  R„   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRb    s    c         C   s
   |  j  j S(   N(   t	   __class__R:   (   R   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR9     s    (   R:   R;   R<   R   R%   Ra  Rb  R9   (    (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR[  Ò  s   				R¸   c           B   s2   e  Z d  Z e j Z d „  Z d „  Z d „  Z RS(   s>   
    Analyse available ensembles for each trial structure
    c         C   s/   t  t |  ƒ j d t d d „  ƒ d t ƒ d  S(   NR^  RF   c         S   s
   |  j  ƒ  S(   N(   t   partial_solution_score(   R7  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRI     s    R+  (   t   superR¸   R   t
   SelectBestR"   (   R   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR     s    c   
      C   s&  | j  ƒ  } xÒ t | j ƒ  ƒ D]¾ } | j d | ƒ | j d | j ƒ  ƒ r† | j d ƒ t j d | d | ƒ } | j d | ƒ nG | j d ƒ t j	 d | j
 ƒ  d	 | j ƒ  d
 | ƒ } | j d | ƒ | j d
 | ƒ q W| j d ƒ t j d | j
 ƒ  d	 | j ƒ  ƒ }	 |	 j d | ƒ d  S(   Ns
   Testing %sRÄ   s   It is applicable for extensionR’   t   searchR   s    It does not fit into compositionRN   RZ   Rš   s*   Adding processing record for the candidate(   R^   Rá   R  R&   RÆ   R­   RÅ   R  RÇ   R  RN   RZ   R+   RR  (
   R   R   R   R   RP   R^   Rš   RS   R�   R¨   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR'      s*    					c         C   s   t  | j ƒ  ƒ S(   N(   t   boolR  (   R   R  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRf  B  s    (	   R:   R;   R<   RÅ   R  Re  R   R'   Rf  (    (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR¸     s
   			"R·   c           B   sM   e  Z d  Z e j Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z RS(   s6   
    Performs rotation search for ensemble stages
    c         C   s8   t  t |  ƒ j d t d d „  ƒ d t ƒ d |  _ d  S(   NR^  RF   c         S   s   |  j  ƒ  j ƒ  S(   N(   Rk  RG   (   R7  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRI   Q  s    R+  g        (   Ri  R·   R   Rj  R"   RQ  (   R   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR   N  s    c         C   s»  | j  j |  ƒ t g  | j d t j ƒ D]' } | j ƒ  r) | j d t j ƒ ^ q) ƒ } | | k rv | j	 d ƒ d  St
 g  | j d t j ƒ D]' } | j |  k r� | j ƒ  | f ^ q� ƒ } t j j d | ƒ }	 |	 | k rW| j	 d ƒ | j	 d ƒ t j d |  d | d | |	 j d	 t ƒ }
 | j	 d
 ƒ |  j d |
 d | d | d | ƒ n` | j	 d ƒ | j d |  d t j d i | j ƒ  d 6| j ƒ  d 6| j ƒ  d 6d i | d 6ƒ d  S(   NRE   s<   Skipping search as a significant peak has already been foundR  s=   An equivalent search has been performed with a different cases   Copying resultst   expertRS   R£   R+  s&   Selecting peaks from rotation functionRk  R’   R   RP   s   Starting rotation searchR)   RÜ   RÝ   RN   RZ   RÞ   (   t   processed_byR5   R   R  RÅ   RU  RW  R  R  R&   R\   RÉ   Rm  R  R  R£   R!   t   evaluate_search_resultsR6   R   t   rotation_functionRN   RZ   Rk  (   R   R   R   R   RP   R„   t   solved_ensemble_stagesR7  t
   search_fort	   search_idRk  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR'   W  sN    	**			
		c      	   C   sa   t  j j d |  d | d | d t ƒ } | j d t | j ƒ ƒ |  j d | d | d | ƒ d  S(	   NRm  RS   t   definitionsR+  s+   There are %s peaks in the rotation functionRk  R’   R   (   RÅ   RÉ   t   from_definitionsR!   R&   R#   R£   Ro  (   R   R’   R    R   RP   Rk  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRæ   “  s    		c         C   s   d  S(   N(    (   R   R’   R   RP   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRç   ¥  s    c         C   sc   | j  d | ƒ g  | j D] } t j d | d | ƒ ^ q } x | D] } | j  d | ƒ qE Wd  S(   NR   R’   R™   (   RÇ   R£   RÅ   t   RotationStage(   R   Rk  R’   R   R�   R”   R7  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRo  ª  s
    +c         C   s   |  | j  k S(   N(   Rn  (   R   R  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRf  ·  s    (   R:   R;   R<   RÅ   R  Re  R   R'   Ræ   Rç   Ro  Rf  (    (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR·   G  s   				<			R¶   c           B   sM   e  Z d  Z e j 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  |  j |  ƒ j d t d d „  ƒ d t ƒ d |  _ d  S(   NR^  RF   c         S   s   |  j  ƒ  j ƒ  S(   N(   R™   t   rf(   R7  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRI   Æ  s    R+  g      è?(   Ri  Rg  R   Rj  R"   RQ  (   R   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR   Ã  s    c         C   sÚ   | j  j |  ƒ t g  | j d t j ƒ D]' } | j ƒ  r) | j d t j ƒ ^ q) ƒ } | | k rv | j	 d ƒ d  S| j	 d ƒ | j
 d |  d t j d i | j ƒ  d 6| j ƒ  d 6| j ƒ  d	 6d
 i | d 6ƒ d  S(   NRE   s<   Skipping search as a significant peak has already been founds   Starting translation searchR)   RÜ   RÝ   RN   RZ   R™   RÞ   R’   (   Rn  R5   R   R  RÅ   RU  RW  R  Rv  R&   R6   R   t   translation_functionRN   RZ   R™   (   R   R   R   R   RP   R„   Rq  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR'   Ì  s&    	*		c      	   C   sa   t  j j d |  d | d | d t ƒ } | j d t | j ƒ ƒ |  j d | d | d | ƒ d  S(   NRm  R’   Rt  R+  s.   There are %s peaks in the translation functionRk  R   (   RÅ   RÍ   Ru  R!   R&   R#   R£   Ro  (   R   R’   R    R   RP   Rk  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRæ   ë  s    		c         C   s   d  S(   N(    (   R   R’   R   RP   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRç   ý  s    c         C   sc   | j  d | ƒ g  | j D] } t j d | d | ƒ ^ q } x | D] } | j  d | ƒ qE Wd  S(   NR   R’   R™   (   RÇ   R£   RÅ   t   TranslationStage(   R   Rk  R’   R   R�   R”   R7  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRo    s
    +c         C   s   |  | j  k S(   N(   Rn  (   R   R  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRf    s    (   R:   R;   R<   RÅ   Rv  Re  R   R'   Ræ   Rç   Ro  Rf  (    (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR¶   ¼  s   							Rµ   c           B   sD   e  Z d  Z e j Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(   s9   
    Performs packing analysis for translation peaks
    c         C   s2   t  |  j |  ƒ j d t d d „  ƒ d t ƒ d  S(   NR^  RF   c         S   s   |  j  ƒ  j ƒ  S(   N(   R™   RV  (   R7  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRI     s    R+  (   Ri  Rg  R   Rj  R!   (   R   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR     s    c         C   st   | j  j |  ƒ | j d ƒ | j d |  d t j d i | j ƒ  d 6| j ƒ  d 6| j ƒ  d 6d i | d	 6ƒ d  S(
   Ns   Starting packing testR)   RÜ   RÝ   RN   RZ   R™   RÞ   R’   (	   Rn  R5   R&   R6   R   t   packing_functionRN   RZ   R™   (   R   R   R   R   RP   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR'   #  s    		c   	      C   s±   | \ } } | r  | j  d ƒ t j d | j ƒ  j ƒ  d | d d | d d | j ƒ  j ƒ  d | j ƒ  j ƒ  ƒ } t j d	 | d
 | ƒ } | j	 d | ƒ n | j  d ƒ d  S(   Ns   Packing test passedRš   R0  i    R2  i   RV  t   tfzR’   R™   R   s   Packing test fail(
   R&   R‰   Rž   R™   Rš   RV  R{  RÅ   t   PackingStageRÇ   (	   R   R’   R    R   RP   t   packsR{   t   tpeakt   pstage(    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRæ   4  s    	

c         C   s   d  S(   N(    (   R   R’   R   RP   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRç   H  s    c         C   s   |  | j  k S(   N(   Rn  (   R   R  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRf  M  s    (   R:   R;   R<   RÅ   Ry  Re  R   R'   Ræ   Rç   Rf  (    (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRµ     s   					RA   c           B   sD   e  Z d  Z e j Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(   s   
    Refines structures
    c         C   s2   t  |  j |  ƒ j d t d d „  ƒ d t ƒ d  S(   NR^  RF   c         S   s   |  j  ƒ  j ƒ  S(   N(   R™   RV  (   R7  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRI   \  s    R+  (   Ri  Rg  R   Rj  R!   (   R   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR   Y  s    c         C   st   | j  j |  ƒ | j d ƒ | j d |  d t j d i | j ƒ  d 6| j ƒ  d 6| j ƒ  d 6d i | d	 6ƒ d  S(
   Ns   Starting refinementR)   RÜ   RÝ   RN   RZ   R™   RÞ   R’   (	   Rn  R5   R&   R6   R   t   refinement_functionRN   RZ   R™   (   R   R   R   R   RP   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR'   a  s    		c         C   s‰  | \ } } | j  d | ƒ | j ƒ  j ƒ  | j ƒ  j ƒ  g } | j d t j ƒ } | rÀ t j	 d | j
 ƒ  d | j ƒ  j ƒ  d | j ƒ  j ƒ  d | j ƒ  j ƒ  d | j ƒ  j ƒ  ƒ }	 n< t j	 d | j
 ƒ  d | j ƒ  j ƒ  d | j ƒ  j ƒ  ƒ }	 t j d g  t | | ƒ D]! \ }
 \ } } |
 | | f ^ qd	 |	 ƒ } t j d
 | d | ƒ } t j d | d | ƒ } | j d | ƒ d  S(   Ns   Refined LLG: %.2fRE   RW  Rw  t   rfzRV  R{  Rt  Rj   RZ   R�   R’   R  R   (   R&   RZ   RÀ   R™   Rš   R  RÅ   Rv  R‰   t   SearchStatisticsRW  Rw  R�  RV  R{  t   PartialStructuret   zipt   RefinedStructureR  RÇ   (   R   R’   R    R   RP   R�   t   defst   ensest	   rot_staget   statsRˆ   R†   R§   RZ   t   refinedRY  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRæ   r  s.    %			7			c         C   s   d  S(   N(    (   R   R’   R   RP   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRç   ˜  s    c         C   s   |  | j  k S(   N(   Rn  (   R   R  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRf  �  s    (   R:   R;   R<   RÅ   RX  Re  R   R'   Ræ   Rç   Rf  (    (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRA   R  s   				&	R±   c           B   sD   e  Z d  Z e j Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(   s   
    Scores structures
    c         C   s)   t  |  j |  ƒ j d d „  d t ƒ d  S(   NR^  c         S   s   |  d S(   Ni    (    (   R`  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRI   ¬  s    R+  (   Ri  Rg  R   R!   (   R   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR   ©  s    	c         C   st   | j  j |  ƒ | j d ƒ | j d |  d t j d i | j ƒ  d 6| j ƒ  d 6| j ƒ  d 6d i | d	 6ƒ d  S(
   Ns   Starting LLG scoringR)   RÜ   RÝ   RN   RZ   R™   RÞ   R’   (	   Rn  R5   R&   R6   R   t   scoring_functionRN   RZ   R™   (   R   R   R   R   RP   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR'   ±  s    		c   	      C   sÀ   | } | j  d | ƒ | j d | ƒ r¯ | j  d ƒ | j ƒ  } t j d | j ƒ  d | j ƒ  d | j ƒ  d | d | j ƒ  ƒ } t	 j
 d	 | d
 | ƒ } | j d | ƒ n | j  d ƒ d  S(   Ns   LLG score: %.2fRG   s,   This peak conforms to expectations, acceptedRš   R0  R2  RV  R{  R’   R™   R   s+   Peak score is worse than expected, rejected(   R&   t   acceptR™   R‰   Rž   Rš   R0  R2  R{  RÅ   t   SpeculatedStageRÇ   (	   R   R’   R    R   RP   R�   t   oldR™   RS   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRæ   Â  s    	c         C   s   d  S(   N(    (   R   R’   R   RP   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRç   Ø  s    c         C   s   |  | j  k S(   N(   Rn  (   R   R  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRf  Ý  s    (   R:   R;   R<   RÅ   t   ScoringStageRe  R   R'   Ræ   Rç   Rf  (    (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR±   ¢  s   					R´   c           B   s5   e  Z d  Z e j Z d d „ Z d „  Z d „  Z RS(   s/   
    Identifies solutions based on Z-score
    g      @c         C   s2   t  |  j |  ƒ j d d „  d t ƒ | |  _ d  S(   NR^  c         S   s   |  d S(   Ni    (    (   R`  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRI   ì  s    R+  (   Ri  Rg  R   R!   t   _z_threshold(   R   t   z_threshold(    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR   é  s    	c         C   s†   | j  j |  ƒ | j ƒ  } |  j | j ƒ  k  rG t } | j d ƒ n t } | j d ƒ t j	 d | d | ƒ } | j
 d | ƒ d  S(   Ns   This is an outstanding peaks   This is an ordinary peakR’   RW  R   (   Rn  R5   R™   R�  R{  R!   R&   R"   RÅ   t   IdentifiedStageRÇ   (   R   R   R   R   RP   R2  RW  RS   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR'   ò  s    		c         C   s   |  | j  k S(   N(   Rn  (   R   R  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRf    s    (	   R:   R;   R<   RÅ   R|  Re  R   R'   Rf  (    (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR´   â  s
   			R³   c           B   s2   e  Z d  Z e j Z d „  Z d „  Z d „  Z RS(   sE   
    Superposes ensembles on solutions and creates new solutions
    c         C   s2   t  |  j |  ƒ j d t d d „  ƒ d t ƒ d  S(   NR^  RF   c         S   s   |  j  ƒ  j ƒ  S(   N(   R™   RV  (   R7  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRI     s    R+  (   Ri  Rg  R   Rj  R!   (   R   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR     s    c         C   s·   | j  j |  ƒ t | t j ƒ r3 | j d ƒ d  St | j d t j ƒ ƒ } | sZ t	 ‚ | j
 ƒ  j ƒ  } | | k s~ t	 ‚ | j | ƒ t j d | d | ƒ } | j d | ƒ d  S(   Ns/   This candidate is not applicable (speculative) RE   t   templateRÀ   R   (   Rn  R5   R  RÅ   R�  R&   R   R  R¦   Ra   R™   Rš   R+   t   TemplateSolveRepositoryRÇ   (   R   R   R   R   RP   RÀ   t   usedt   repo(    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR'     s    		c         C   s   | j  ƒ  o |  | j k S(   N(   RW  Rn  (   R   R  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRf  2  s    (	   R:   R;   R<   RÅ   RU  Re  R   R'   Rf  (    (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR³     s
   			R²   c           B   sD   e  Z d  Z e j Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(   sE   
    Superposes ensembles on solutions and creates new solutions
    c         C   s5   t  |  j |  ƒ j d d „  d t ƒ t ƒ  |  _ d  S(   NR^  c         S   s   |  d S(   Ni    (    (   R`  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRI   A  s    R+  (   Ri  Rg  R   R!   R   t   _proxy(   R   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR   >  s    	c         C   sò  t  | j ƒ  ƒ } | s t ‚ | j d d „  d t ƒ | d } | j d | ƒ | j d | ƒ | j ƒ  } | j ƒ  } | j	 ƒ  }	 |	 j
 ƒ  j | j
 ƒ  ƒ s² | j d ƒ d  St g  | j d t j ƒ D] }
 |
 j ƒ  |
 f ^ qË ƒ } t j j d	 |	 d
 | ƒ } t j j d	 | d
 |	 ƒ } | | k rN| j d ƒ | | j ƒ  } n| | k r€| j d ƒ | | j ƒ  j ƒ  } nÖ | j d ƒ y1 |  j j d	 |	 j ƒ  d
 | j ƒ  ƒ \ } } Wn> t k
 rþ} | j d | ƒ | j d ƒ | j d ƒ n Xt j d	 |	 d
 | d | j ƒ  d | ƒ } | j d | ƒ | j d | ƒ | j ƒ  } | j ƒ  } | j ƒ  j ƒ  } t j j | j ƒ  j ƒ  | j  | j! ƒ  j" ƒ  ƒ f ƒ } | | } t# j$ d | d t# j% d | j& j' ƒ d t# j( d | j) | j* j' ƒ ƒ d d d | j+ ƒ  ƒ } g  | j d t j, ƒ D]0 } | j ƒ  | k r*| j- ƒ  | k r*| ^ q*} t. | ƒ d k sxt ‚ | j d ƒ | j d ƒ | j/ d |  d  t0 j1 d! i | d" 6| j2 ƒ  d# 6| d$ 6d% i | d d& 6| d$ 6d' „  d( 6ƒ d  S()   NRF   c         S   s
   |  j  ƒ  S(   N(   RG   (   R7  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRI   K  s    RJ   i    Rš   s   Trial ensemble: %ss/   Template ensemble does not match trial ensembleRE   t   fixedt   movings#   Using pre-determined transformations,   Using inverted pre-determined transformations   Superposing ensembless   Superposition error: %ss   Discarding this trials   Action completet   transformationt   rmsds   RMSD between ensembles: %.3fR   R0  t   elementsR2  t   coordinatesRV  g        R{  i   s   Superposed solution generateds   Starting packing testR)   RÜ   RÝ   RN   RZ   R™   RÞ   R’   c         S   s
   d |  k S(   Ni    (    (   RG   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRI   ±  s    RŒ  (3   Rá   R  Ra   t   sortR!   R+   R&   R“  R™   Rš   R­   RÆ   R\   R  RÅ   t   SuperpositionR  R  Rš  t   inverseR—  R2   t   pdb_fileR   t   rtRÇ   RN   RU   t	   unit_cellt   scitbxt   matrixR0  t   orthogonalizeR2  t
   fractionalR‰   Rž   t   MatrixR†   t   elemst
   Fractionalt   fractionalizeR§   R{  R  Rk  R#   R6   R   Rz  RZ   (   R   R   R   R   RP   R  R‘   R“  R™   Rš   t   spt   superposition_fort   forw_idt   rev_idRš  t   transfR›  Rˆ   t   supRN   t   cellt   solutiont
   superposedt   transformedR„   t   ense_stages(    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR'   G  s”    
+					!
		0		
c         C   s¿   | \ } } | r¡ | j  d ƒ t j d | j ƒ  d | d d | d d | j ƒ  d | j ƒ  ƒ }	 t j d	 | d
 |	 d | ƒ }
 |
 j d | ƒ | j  d ƒ n | j  d ƒ | j  d ƒ d  S(   Ns   Packing test passedRš   R0  i    R2  i   RV  R{  R’   R™   RŒ  R   s   Sending peak for scorings   Packing test fails"   Not pursuing this peak any further(	   R&   R‰   Rž   Rš   RV  R{  RÅ   R�  RÇ   (   R   R’   R™   RŒ  R    R   RP   R}  R{   R~  RS   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRæ   ¶  s"    	

		c         C   s   d  S(   N(    (   R   R’   R™   RŒ  R   RP   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRç   Ð  s    c         C   s   t  | j ƒ  ƒ S(   N(   Rl  R  (   R   R  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRf  Õ  s    (   R:   R;   R<   RÅ   R”  Re  R   R'   Ræ   Rç   Rf  (    (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR²   7  s   				o		t%   RegularObjectCompletionInitiateExpertc           B   s–   e  Z d  Z e j Z d e j Z d Z	 d „  Z
 d „  Z d „  Z d „  Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z RS(   sI   
    Finds incomplete regular assemblies in solutions completes them
    g       @gñhãˆµøä>c         C   s_   t  |  j |  ƒ j d t d d „  ƒ d t ƒ d |  _ d |  _ d |  _ d |  _ d |  _ d  S(	   NR^  RF   c         S   s   |  j  ƒ  j ƒ  S(   N(   R™   RV  (   R7  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRI   æ  s    R+  i   g      @g333333Ã?g+‡ÙÎ÷ï?(	   Ri  Rg  R   Rj  R!   t	   _max_foldt   _spatial_sqt   _angulart   _axial(   R   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR   ã  s    				c         C   s–  | j  j |  ƒ t | t j ƒ r3 | j d ƒ d  St | j ƒ  j ƒ  ƒ d k rb | j d ƒ d  S| j d ƒ i  } | j ƒ  } | j	 ƒ  j
 ƒ  j ƒ  } xx t | j ƒ  | j ƒ  | j ƒ  ƒ D]R \ } }	 }
 | j | g  ƒ j t j j d |	 j ƒ  d | j |
 j ƒ  ƒ ƒ ƒ q¾ W| j ƒ  } | j | j ƒ  g  ƒ j t j j d | j ƒ  j ƒ  d | j | j ƒ  j ƒ  ƒ ƒ ƒ g  } xÖ | j ƒ  D]È \ } } t | ƒ d k  r½| j d | ƒ qˆn  g  |  j d	 | ƒ D]c } t j d
 | d t j d | j  ƒ  ƒ d t j! d | j" | j# ƒ  ƒ ƒ d d d | j$ ƒ  ƒ ^ qÐ} | j d t | ƒ ƒ qˆW| sj| j d ƒ n( t j% d | d | ƒ } | j& d | ƒ d  S(   Ns/   This candidate is not applicable (speculative) i    s0   Cannot identify operators from a single molecules   Sorting candidate on ensemblesR0  R2  i   s    Cannot identify operators for %st   existingRš   Rœ  R�  RV  g        R{  s   %s possible new positions founds   No new positions foundt   baseRà   R   ('   Rn  R5   R  RÅ   R�  R&   R#   RZ   RÀ   RN   RU   R£  R„  R.  R1  R    R�   t   phaserR   t   OperatorR¥  R¦  R§  R™   Rš   R0  R2  R¢   t   possible_further_moleculesR‰   Rž   R¨  t   get_rotationRª  R«  t   get_translationR{  t!   RegularObjectCompletionRepositoryRÇ   (   R   R   R   R   RP   t   description_withR�   R²  Rˆ   R†   R§   R™   t   possibilitiest   enset   copiest   opt
   identifiedR  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR'   ð  sF    4	y		c            sÓ  | } g  | D] } | j  d | ƒ ^ q } g  } | d d ‰  x�t | ƒ D]\ } }	 |	 j ƒ  }
 g  | | d D] } | |
 ^ qs } d t | ƒ GHx0|  j d | ƒ D]\ } } d | | f GHg  |  j d | d	 | ƒ D] } | |	 ^ qß } d
 t | ƒ GHg  | D] } | j  d | ƒ ^ q} g  t | | ƒ D]@ \ } } t ‡  f d †  |  j d | d | ƒ Dƒ ƒ s9| ^ q9} d t | ƒ GH| j	 | ƒ | j	 g  | D] } | j  d | ƒ ^ q¨ƒ q« WqL W| S(   Nt   pointg      @i   i   s   Considering %s operatorst   opss    Processing generator: %s-fold
%sRÈ  t   lengths"   %s trial operators will be checkedc         3   s   |  ] } | ˆ  k  Vq d  S(   N(    (   RH  t   d_sq(   t   clash_distance_square(    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pys	   <genexpr>G	  s    t   otherss   %s non-clashing(
   t	   transformRY   R   R#   t
   generatorst   power_seriesR„  RI  t   distance_squarest   extend(   R   R¼  t   centret   extentt   unusedRÈ  t   centresRb  Rq   Rr   t   invRË  t   foldt   gent   trialst   pointsR�   t   non_clashing_ops(    (   RÎ  sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRÀ  0	  s.    %%,%+.c   	         s?  g  } xl | D]d } ˆ j  d | ƒ ‰  ˆ  s1 q n  x= | D]5 } t ‡  ‡ f d †  | Dƒ ƒ r8 | j ˆ  ƒ q8 q8 Wq Wg  | D] } ˆ j d | ƒ ^ q| St j d d „  d t ƒ g  } g  } x{ t D]s \ } } | j ƒ  ‰ t ‡ ‡ f d †  | Dƒ ƒ rqÄ n  | j | | f ƒ | j ˆ j	 d | d | d	 ƒ ƒ qÄ W| S(
   NRÈ  c         3   s'   |  ] } ˆ j  d  ˆ  d | ƒ Vq d S(   t   leftt   rightN(   t   operation_overlap(   RH  t   m(   t   anR   (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pys	   <genexpr>a	  s    t   groupRF   c         S   s   |  d S(   Ni    (    (   R7  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRI   h	  s    RJ   c         3   s'   |  ] } ˆ j  d  ˆ  d | ƒ Vq d S(   t   op1t   op2N(   t   approx_inverse(   RH  t   a(   RÙ  R   (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pys	   <genexpr>o	  s    RÌ  i   (
   t   operator_analysisRI  R�   t   merge_operatorsRÑ  Rž  R!   R   RÔ  RÒ  (	   R   RË  t   foundRÈ  Rä  t   gt   uniquest	   accountedRÚ  (    (   Rã  RÙ  R   sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyt   find_generatorsU	  s(    #'c   
   	   C   s+  t  j j | j ƒ  ƒ } |  j d | j ƒ  ƒ \ } } | d	 k rF d  Sd | k  sX t ‚ t g  t	 t
 d | ƒ |  j d | d | ƒ ƒ D]  \ } } | | | | f ^ q† d d „  ƒ} | d d d k sÒ t ‚ t  j j | j ƒ  d
 ƒ } t  j j | j d ƒ } | j | ƒ | }	 | | | |	 | f S(   Nt   anglei    i   RÈ  RÌ  RF   c         S   s   |  d S(   Ni    (    (   R�   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRI   ‹	  s    i   (   i    i   (   i   i   (   i   i   (   R¤  t   matht&   r3_rotation_axis_and_angle_from_matrixRÁ  t   get_fold_and_powerRð  R½   Ra   RW   R„  t   ranget   get_power_seriesR¥  R¨   RÂ  t   axist   dot(
   R   RÈ  t   aafRÚ  t   powerRâ  t	   multiplesR2  t
   t_par_unitt   displacement(    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRé  x	  s     	?c         C   s{   d } xn t  d |  j d ƒ D]V } | | 7} | |  j } t | ƒ } t | | ƒ |  j k  r | t | ƒ | f Sq Wd S(   Ni    i   (   i    i    (   Rô  R¸  t   TWO_PIt   roundR‹   Rº  t   int(   R   Rð  R0  RÚ  t   multiplet   rounded(    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRó  –	  s    
c         C   s<   | g } x, t  d | ƒ D] } | j | d | ƒ q W| S(   Ni   iÿÿÿÿ(   Rô  R�   (   R   RÈ  RÌ  t   seriesRq   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRõ  ¥	  s    	c         C   se  | \ } } } } } | \ } }	 }
 } } t  j | | ƒ } | d k rQ d GHt S| j |
 ƒ |  j k  rr d GHt St | ƒ } t | ƒ } | | | | | | | | } d | GH|  j | j ƒ  k  rÓ d GHt S| | | d d } |	 | | d d } t j	 j
 | j ƒ  d ƒ } | GHt j	 j
 | j ƒ  d	 ƒ } | GH|  j | | j ƒ  k  rad GHt St S(
   Ni   s
   Wrong folds
   Wrong axiss   Diff: %ss#   Large difference in parallel transli   s   large difference in perp transl(   i   i   (   i   i   (   t	   fractionst   gcdR"   R÷  R»  t   floatR¹  t	   length_sqR¤  R¥  R¨   RÂ  R!   (   R   Rß  Rà  t   fold1t   mult1t   axis1t   disp1t   p1t   fold2t   mult2t   axis2t   disp2t   p2R  t   f1t   f2t   diffRå  Ræ  t   trans1t   trans2(    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRá  ¯	  s4    "	c   	   	   C   s  t  | ƒ } d | k  s t ‚ t g  | D] } | d ^ q( ƒ } t g  | D] } | | d d k ^ qK ƒ st t ‚ d | t t j g  | D] } | d ^ q‹ ƒ } d | t t j g  | D]- } t j j	 | d d d j
 ƒ  d	 ƒ ^ q¼ ƒ } t t t j g  | D] } | d ^ qƒ ƒ } t t j g  | D] } | d ^ q2ƒ | } t j d t j j | |  j | ƒ d | | ƒ S(
   Ni    g      ð?i   i   i   i   R0  R2  (   i   i   (   R#   Ra   R•   R4  R,  R-  R5   R¤  R¥  R¨   RÂ  R  R   R¿  Rñ  t$   r3_rotation_axis_and_angle_as_matrixRý  (	   R   Rä  t   countRì  RÚ  Rö  t   perpendiculart   pnormt   parallel(    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRê  ×	  s     #31
;/-		c         C   sF   | j  d | d |  j d |  j ƒ pE | j  d | d |  j d |  j ƒ S(   NRÄ   t   angulart   spatial(   Rç  Rº  t   _spatial(   R   Rå  Ræ  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRç  m
  s    				c            s   ‡  f d †  | Dƒ S(   Nc         3   sM   |  ]C } ˆ  d  | d  d ˆ  d | d d ˆ  d | d d Vq d S(   i    i   i   N(    (   RH  t   o(   RÊ  (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pys	   <genexpr>€
  s   (    (   R   RÊ  RÏ  (    (   RÊ  sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRÓ  }
  s    c         C   s   | j  ƒ  o |  | j k S(   N(   RW  Rn  (   R   R  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRf  †
  s    (   R:   R;   R<   RÅ   RU  Re  Rñ  t   piRý  t   EPSILONR   R'   RÀ  Rï  Ré  Ró  Rõ  Rá  Rê  Rç  RÓ  Rf  (    (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR·  Ú  s    			@	%	#			
	(	–			t   Modellerc           B   s2   e  Z d  Z d „  Z d „  Z d „  Z d „  Z RS(   s^   
    Knowledge sources responsible for model generation
    Disabled if a solution exists
    c         C   s   | |  _  d  S(   N(   R]  (   R   R^  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR   ‘
  s    c         C   sœ   | j  r) | j j r) | j j d ƒ d  S|  j d | j ƒ } | sX | j j d ƒ d  S| j j d t | ƒ ƒ |  j	 d | ƒ } | j j d | ƒ | S(   Ns*   Disabled because solutions have been foundR_  s   No candidates have been founds   %s candidates has been foundR`  s   Selected %s(
   t   quickRj   t   solvedRP   R$   R½   R—   R   R#   R]  (   R   R   R—   R‘   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR%   –
  s    	c         C   s8   g  | j  d |  j ƒ D] } |  j d | ƒ r | ^ q S(   NRE   R  (   R  Re  Rf  (   R   R_  Rƒ   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR—   «
  s    c         C   s
   |  j  j S(   N(   Rg  R:   (   R   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR9   ±
  s    (   R:   R;   R<   R   R%   R—   R9   (    (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR!  ‹
  s
   			t   FetchExpertc           B   s    e  Z d  Z d „  Z d „  Z RS(   s   
    Fetches data
    c         C   s)   t  t |  ƒ j d t d d „  ƒ ƒ d  S(   NR^  RF   c         S   s
   |  j  ƒ  S(   N(   RG   (   R7  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRI   ¾
  s    (   Ri  R$  R   Rj  (   R   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR   »
  s    c         C   sü   | j  j |  ƒ | j j d | ƒ y |  j d | d | ƒ } Wn( t k
 rj } | j j d | ƒ d  SX| j j d | ƒ y" |  j d | d | d | ƒ } Wn( t k
 rË } | j j d | ƒ d  SX|  j d | d | d | ƒ | j j d ƒ d  S(	   Ns   Fetching data for %s...R   R   s	   Error: %ss   Parsing data for %s...t   rawR{   s   Data fetch completed(	   Rn  R5   RP   R&   Ra  t
   ValueErrort   warningt   parset   publish(   R   R   R   R%  Rˆ   R{   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR'   Â
  s    "(   R:   R;   R<   R   R'   (    (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR$  ¶
  s   	RO  c           B   sD   e  Z d  Z e j Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(   s   
    Obtain sequence data
    c         C   s#   t  t |  ƒ j ƒ  t ƒ  |  _ d  S(   N(   Ri  RO  R   R   R—  (   R   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR   â
  s    c         C   s   |  j  j d | j ƒ S(   NR  (   R—  Ra  R  (   R   R   R   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRa  è
  s    c         C   sƒ   t  j | ƒ \ } } | r2 | j j d | ƒ n  | sD t d ‚ n  t | ƒ d k ri | j j d ƒ n  | d } | j | _ | S(   Ns$   Uninterpretable text encountered: %ss   No sequence foundi   s-   Multiple reference sequences, keeping top onei    (   R   t   seq_sequence_parseRP   R'  R&  R#   R  Rï   (   R   R   R%  R   t   seqst   badt   seq(    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR(  í
  s    
c         C   s   | | _  d  S(   N(   t   sequence(   R   R   R{   R   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR)  ÿ
  s    c         C   s   | j  o |  | j k S(   N(   R.  Rn  (   R   R  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRf    s    (   R:   R;   R<   RÅ   t   BlastHitRe  R   Ra  R(  R)  Rf  (    (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRO  Û
  s   					RN  c           B   sD   e  Z d  Z e j Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(   s    
    Obtain structural data
    c         C   s#   t  t |  ƒ j ƒ  t ƒ  |  _ d  S(   N(   Ri  RO  R   R   R—  (   R   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR     s    c         C   s   |  j  j d | j d  ƒ S(   NR  i   (   R—  Ra  R  (   R   R   R   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRa    s    c         C   sÔ   | j  } t j j d | d d ƒ } | j ƒ  } d | d } | j ƒ  j | ƒ } | j | t ƒ }	 |	 j	 ƒ  s‡ t
 d t t f ‚ n  t j j | j d | ƒ }
 | j j d |
 ƒ |	 j |
 ƒ t j d	 |
 ƒ S(
   Nt   linest   source_infot   PDBs
   chain '%s'i   s$   No atoms selected for %s, chain '%s's   %s.pdbs#   Writing out selected atoms as %s...t	   file_name(   R  t   iotbxt   pdbt   inputt   construct_hierarchyt   atom_selection_cachet	   selectiont   selectR!   t   atomsR&  t   pdb_idt   chain_idRð   Rñ   t   joint   data_folderRP   R&   t   write_pdb_fileR‰   t	   Structure(   R   R   R%  R   R  R6  t   rootR9  t   asct   new_rootR3  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR(    s    	c         C   s   | | _  d  S(   N(   Ry   (   R   R   R{   R   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR)  .  s    c         C   s    | j  o | j o |  | j k S(   N(   Ry   R.  Rn  (   R   R  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRf  3  s    (   R:   R;   R<   RÅ   R/  Re  R   Ra  R(  R)  Rf  (    (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRN  	  s   					RM  c           B   sP   e  Z d  Z e j Z d Z d Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z RS(   s0   
    Calculates an alignment for a sequence
    t   targett   modelc         C   s,   t  t |  ƒ j ƒ  t ƒ  |  _ d |  _ d  S(   Nt   clustalw(   Ri  RM  R   R   R—  t   _aligner(   R   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR   A  s    c         C   s±   t  j d |  j d | j j j ƒ } t  j d |  j d | j j ƒ } |  j j d d j t | ƒ t | ƒ g ƒ ƒ \ } } } | r› | j	 j
 d | ƒ n  | s­ t d ‚ n  | S(   NRï   R.  t	   sequencess   
s   Warning: %ss   No alignment returned(   R   R.  t   TARGETRÂ   t   MODELR—  R2   R>  Rh   RP   R'  R&  (   R   R   R   t   seq1t   seq2t   alnt   logt   err(    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRa  H  s    				-c         C   sô   t  j | ƒ \ } } | s+ t d | ‚ n  | j ƒ  d k sC t ‚ |  j | j d k rº |  j | j d k su t ‚ | j j	 d ƒ |  j |  j g | _ | j
 d | j
 d g | _
 n  t j |  j k sÒ t ‚ | j j j | j j g | _ | S(   Ns   Unable to interpret: %si   i   i    s   Rearranging alignment...(   R   t   clustal_alignment_parseR&  t   multiplicityRa   RJ  t   namesRK  RP   R&   t
   alignmentsRL  Rï   RÂ   R.  (   R   R   R%  R   RN  R,  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR(  `  s     c         C   s°   g  | j  j d t j ƒ D] } | j | k r | ^ q } x; | D]3 } | j | j j k rA | j j d | ƒ d  SqA Wt j d | d |  j	 d | ƒ } | j
 d | j  ƒ d  S(   NRE   s   Alignment identical to %st	   blast_hitt   alignert	   alignmentR   (   R   R  RÅ   t	   AlignmentRU  RT  RW  RP   R&   RH  RÇ   (   R   R   R{   R   Rè  RT  t   aliR  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR)  x  s    			c         C   s   | j  o | j o |  | j k S(   N(   Ry   R.  Rn  (   R   R  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRf  �  s    (   R:   R;   R<   RÅ   R/  Re  RJ  RK  R   Ra  R(  R)  Rf  (    (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRM  8  s   					RL  c           B   sD   e  Z d  Z e j Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(   s   
    Runs sculptor
    c      	   C   sÝ   t  t |  ƒ j d t d d „  ƒ ƒ t j j f } t j d t j	 ƒ  g d g  d | ƒ t j
 d t j d d	 ƒ g d | ƒ t j j d
 d d | ƒ t j d t j ƒ  g d | ƒ t j d g  d t j j f ƒ g |  _ d  S(   NR^  RF   c         S   s   |  j  j ƒ  S(   N(   RU  RG   (   R7  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRI   ž  s    t   deletiont	   polishingt
   applicablet   pruningt   leveli   t   starti   t
   completiont   known(   Ri  RL  R   Rj  R   t   MacromoleculeSpecificst   PROTEINt   chiselt   MainchainDeletet   MDAGapt   SidechainPrunet   SPASchwarzenbachert   ResidueRenumbert   Targett   ResidueRenamet   AGACBetaUniformt   CleanUnknownt   UNKNOWNt	   _workflow(   R   t   mms(    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR   ›  s"    				c         C   sÅ   | j  j |  ƒ | j j d ƒ | j j d | j ƒ | j j d | j j | j j j ƒ  f ƒ | j	 d |  d |  j
 d | j j j ƒ  | j | j f d | j j | j j ƒ  | j j f ƒ d  S(   Ns   Running sculptor with:s   	Alignment:
%ss   	Structure: %s, %sR)   RÜ   RÝ   RÞ   (   Rn  R5   RP   R&   RW  RU  R  Ry   R3  R6   R2   RV  t   identity_fractionRÂ   (   R   R   R   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR'   ·  s     					c         C   s   t  j j o |  t  j k S(   N(   R  RU  Ry   Rn  (   R   R_  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRf  Ó  s    c      	   C   s§  | \ } } } t  j j | ƒ j ƒ  } t j d d d t j ƒ } t ƒ  } t j | ƒ } | j	 t j
 d ƒ ƒ | j | ƒ t j d | d | g d |  j d | ƒ }	 | j | ƒ | j ƒ  | j ƒ  | j ƒ  }
 t ƒ  } xE |	 j ƒ  D]7 } t | t j t j f ƒ rê | j | j ƒ  ƒ qê qê Wx |	 j ƒ  D] } | j ƒ  q2W|	 j ƒ  t j d	 | d
 d | | t |  ƒ f d d ƒ } |	 j  ƒ  j! | ƒ t" |
 | | f f S(   NRï   Ré   R^  s   %(message)sRB  RT  t   workflowRP   R3  t   labels   %s_%s_sculptor_%st	   extensionR5  (#   R4  R5  R6  R7  Rÿ   t   LoggerR  R   R  R  R  R  R	   R*   Ro  t   removeHandlert   flusht   closet   getvalueR   t   modificationsR  Rd  t   DeleteInstructiont   AttachInstructionR5   t	   blueprintt   executet
   regularizeR
   t   autonameR  RB  R@  R!   (   R   R{   R3  RW  RV  RB  RP   t	   logstreamR  t   vrRä   t   fingerprintt   commandt   outfile(    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR2   Ø  s:    					

	
		c         C   sã   | \ } } | \ } } } g  | j  j d t j ƒ D]0 }	 t j | k r4 t j j | g k r4 t ^ q4 }
 x5 |
 D]- } | j | k rq | j	 j
 d | ƒ d  Sqq Wt j d | d | d | d | d | ƒ } | j d | j  ƒ d  S(	   NRE   s   Ensemble identical to %sR¡  t   identityRÂ   t   originRz  R   (   R   R  RÅ   t   SculptorEnsemblet   seR‡  R­   t
   componentsRz  RP   R&   RÌ   (   R   R    R   Rà   R…  Rz  R‡  R†  RÂ   Rè  RÀ   RÆ  RF  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRæ     s     0		(   R:   R;   R<   RÅ   RX  Re  R   R'   Rf  R2   Ræ   (    (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRL  ”  s   					,Rj  c           B   s    e  Z d  Z d „  Z d „  Z RS(   s   
    Selects best object
    c         C   s   | |  _  d  S(   N(   t   _key(   R   RF   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyR   &  s    c         C   s   t  | d |  j ƒS(   NRF   (   R•   R‹  (   R   R`  (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyt   __call__+  s    (   R:   R;   R<   R   RŒ  (    (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyRj  !  s   	(A   t   phaser.pipelineR    R   R‰   R   RÅ   R   t   phaser.pipeline.proxiesR   R   R   R   R¾  R   Rd  R	   R
   R   R   R4  R   t	   iotbx.pdbt   libtbx.utilsR   t   scitbx.matrixR¤  Rð   t   sysR,   R-  Rñ  R  t   tempfileR   t   objectR   R=   R¾   RÃ   RÉ   RÍ   RÏ   RÑ   RÓ   R×   Rø   Rû   R[  R¸   R·   R¶   Rµ   RA   R±   R´   R³   R²   R·  R!  R$  RO  RN  RM  RL  Rj  (    (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/pipeline/phaser_ai_new.pyt   <module>   sr   "cÿ Q)611--`#ÿ dƒQ'?6uX>P@*+£ÿ ²+%./\�