ó
š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 Z d  d l m	 Z	 d  d l
 m Z d  d l Z d  d l Z d	 Z d
 Z e e j g ƒ Z d Z d Z e j j j ƒ  Z d „  Z d „  Z i e d 6e d 6Z d „  Z d e _ d „  Z d e i e j d e d e d ƒ d 6d d 6e j d e d d ƒ d 6e _ d „  Z d e i e j d e d e d ƒ d 6d d 6e j d e d d ƒ d 6e _ d „  Z  d e  _ i e d  6e d! 6e d" 6e  d# 6Z! d$ „  Z" d% e" _ d& „  Z# d' e# _ i e" d( 6e# d) 6Z$ d* „  Z% d+ e% _ d, „  Z& d- e i e j d e d e d ƒ d 6d d 6e j d e d d ƒ d 6e& _ i e% d. 6e& d/ 6Z' d0 „  Z( d1 e d2 e( _ d3 „  Z) d4 e d5 e i e j d e d e d ƒ d 6d d 6e j d e d d ƒ d 6f e) _ d6 „  Z* d7 e d8 e* _ i e( d9 6e) d/ 6e* d: 6Z+ d; „  Z, d< „  Z- d= „  Z. i e, d> 6e- d? 6e. d9 6Z/ d@ „  Z0 dA „  Z1 dB „  Z2 dC „  Z3 dD „  Z4 i e3 dE 6e4 dF 6Z5 dG „  Z6 e7 dH „ Z8 dI „  Z9 dJ „  Z: dK „  Z; i dL dM 6dN dO 6dP dQ 6dR dS 6dT dU 6dV dW 6dX dY 6dZ d[ 6d\ d] 6d^ d_ 6d` da 6db dc 6dd de 6Z< i e< j= ƒ  df 6dM d[ dc g dg 6Z> i  Z? dh „  Z@ di „  ZA dj „  ZB dk ZC dl i e j d e5 d dE ƒ dm 6ZD dn i e j d e/ d d> ƒ do 6ZE dp i	 e j d e! d d  ƒ dq 6eB dr e! ƒ ds 6e j d e$ d d ƒ dt 6eB dr e$ ƒ du 6e j d e' d d. ƒ dv 6eB dr e' ƒ dw 6e j d e+ d d9 ƒ dx 6eB dr e+ ƒ dy 6e j d eG e jH g  e D]% ZI g  eI jJ D] ZK eK jL ^ qº^ qªƒ d dz ƒ d{ 6ZM d| i eM d} 6eE d~ 6ZN d i e j d eA ƒ  d dM ƒ d€ 6eE d~ 6ZO d� i eM d} 6ZP d‚ ZQ e jR jS dƒ i eC d„ 6eD d… 6eN d
 6eQ d† 6d‡ eT ƒZU eU e; f ZV e jR jS dˆ i eC d„ 6eD d… 6eO d
 6eQ d† 6d‡ eT ƒZW eW e: f ZX eU ZY d‰ „  ZZ dŠ „  Z[ d‹ „  Z\ dŒ „  Z] d� „  Z^ dŽ „  Z_ d� „  Z` d� „  Za d‘ „  Zb d’ „  Zc d“ „  Zd d eV e je jf d” „ Zg d• e	 jh f d– „  ƒ  YZi e jj d— „ Zk d˜ „  Zl d™ „  Zm d S(š   iÿÿÿÿ(   t   chisel(   t   mmt(   t	   tbx_utils(   t   output(   t   bioinformaticsN(   t   runtime_utils(   t   Sorrys   0.3.3t   sculptorsx  
calculation
    .help = "Normalized values (~1: perfect match; ~0: random sequence: ~-1: gap)" 
    .short_caption = Sequence similarity calculation
    .help = "Configure sequence similarity calculation"
    .style = box auto_align
{
    matrix = %(matrix)s
        .help = "Similarity matrix"
        .short_caption = Similarity matrix
        .type = choice
        .optional = False
        
    window = %(window)s
        .help = "Averaging window width"
        .type = int
        .optional = False
        
    weighting = %(weighting)s
        .help = "Weighting scheme"
        .type = choice
        .optional = False
}s³   
factor = %s
    .help = "Transform values by multiplying with a factor" 
    .type = float
    .optional = False
    .short_caption = Scale current B-factors by
    .style = boldc         C   s,   d d l  m } | j d g d |  d ƒ S(   Niÿÿÿÿ(   t   flexi   i   (   t   scitbx.array_familyR   t   double(   t   windowR   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt   get_unit_weights<   s    c         C   sE   d d l  m } | j t d |  d ƒ |  d g t |  d d ƒ ƒ S(   Niÿÿÿÿ(   R   i   i    (   R	   R   R
   t   range(   R   R   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt   get_triangular_weightsB   s    t   uniformt
   triangularc         C   s
   t  j ƒ  S(   N(   R    t   MDAGap(   t   params(    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt   gap_mainchain_algorithmQ   s    s�   
    .short_caption = Filter by residue presence
    .help = "Delete residue if aligned with gap"
    .style = box auto_align
{
}c         C   sb   |  j  j } t |  j  j d | ƒ } t j d t j d |  j  j d d d | d | ƒ d |  j ƒ S(   NR   t   ss_calct   matrixt   unknowni    t   weightst	   threshold(	   t   calculationR   t   WEIGHTING_SCHEME_NAMEDt	   weightingR    t   MDASimilarityt    LinearAveragedSequenceSimilarityR   R   (   R   t   wR   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt   similarity_mainchain_algorithm^   s    			sk  
    .short_caption = Filter by sequence similarity, truncate by specified threshold
    .help = "Delete residue if sequence similarity is low"
    .style = box auto_align
{
    threshold = -0.2
        .help = "Threshold to accept a residue"
        .short_caption = Threshold to accept a residue
        .type = float
        .optional = False
        
    %s
}t   possiblet   defaulti    R   i   R   R   c         C   sb   |  j  j } t |  j  j d | ƒ } t j d t j d |  j  j d d d | d | ƒ d |  j ƒ S(   NR   R   R   R   i    R   t   offset(	   R   R   R   R   R    t   MDAThresholdAdjustSimilarityR   R   R"   (   R   R   R   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt/   threshold_adjust_similarity_mainchain_algorithm‰   s    			s$  
    .short_caption = Filter by sequence similarity, truncate to target completeness
    .help = "Delete residues based on sequence similarity to get same number of gaps             as the Schwarzenbacher algorithm"
    .style = box auto_align
{
    offset = 0.0
        .help = "Completeness in fraction of model length             (0.0 = completeness from Schwarzenbacher algorithm, useful range: +/-0.05)"
        .short_caption = Model completeness wrt Schwarzenbacher-algorithm
        .type = float
        .optional = False
        
    %s
}c         C   s   t  j d |  j ƒ S(   Nt
   min_length(   R    t   MDARemoveLongR%   (   R   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt   remove_long_mainchain_algorithm¶   s    s  
    .short_caption = Filter by residue presence
    .help = "Delete residue if aligned with gap"
    .style = box auto_align
{
    min_length = 3
        .help = "Minimum length for mainchain segment to remove"
        .type = int
        .optional = False 
}t   gapt   threshold_based_similarityt   completeness_based_similarityt   remove_longc         C   s   t  j d |  j ƒ S(   NR%   (   R    t   MPARemoveShortt   minimum_length(   R   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt    remove_short_polishing_algorithmÏ   s    sÐ   
    .help = "Delete short unconnected segments"
{
    minimum_length = 3
        .help = "Minimum length"
        .type = int
        .optional = False
        .short_caption = Minimum chain length to keep
}c         C   s   t  j d |  j ƒ S(   Nt
   max_length(   R    t   MPAKeepRegulart   maximum_length(   R   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt    keep_regular_polishing_algorithmÞ   s    sÓ   
    .help = "Keep residues in secondary structure"
{
    maximum_length = 1
        .help = "Maximum length"
        .type = int
        .optional = False
        .short_caption = Maximum chain length to keep
}t   remove_shortt   keep_regularc         C   s   t  j d |  j ƒ S(   Nt   level(   R    t   SPASchwarzenbachert   pruning_level(   R   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt+   schwarzenbacher_sidechain_pruning_algorithmô   s    s¯   
    .help = "Truncate atoms if target residue != source residue"
{
    pruning_level = 2
        .help = "Level of truncation"
        .type = int
        .optional = False
}c         C   st   |  j  j } t |  j  j d | ƒ } t j d t j d |  j  j d d d | d | ƒ d |  j d |  j	 d	 |  j
 ƒ S(
   NR   R   R   R   i    R   t   lowert   upperR5   (   R   R   R   R   R    t   SPASimilarityR   R   t   full_truncation_limitt   full_length_limitR7   (   R   R   R   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt&   similarity_sidechain_pruning_algorithm  s    					s  
    .help = "Truncate atoms based on sequence similarity"
    .short_caption = Similarity-based truncation
    .style = box auto_align
{
    pruning_level = 2
        .help = "Level of intermediate truncation"
        .type = int
        .optional = False
        
    full_length_limit = 0.2
        .help = "Limit of no truncation"
        .type = float
        .optional = False
        
    full_truncation_limit = -0.2
        .help = "Limit for full truncation"
        .type = float
        .optional = False
        
    %s
}t   schwarzenbachert
   similarityc         C   s   t  j d |  j ƒ S(   Nt   factor(   R    t   BPAOriginalBfactorRA   (   R   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt   original_bfactor_algorithm@  s    s‹   
    .help = "Use original bfactors to predict new B-values"
    .short_caption = Original B-factors
    .style = auto_align box
{
    %s
}i   c         C   sb   |  j  j } t |  j  j d | ƒ } t j d t j d |  j  j d d d | d | ƒ d |  j ƒ S(   NR   R   R   R   i    R   RA   (	   R   R   R   R   R    t   BPASequenceSimilarityR   R   RA   (   R   R   R   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt   similarity_bfactor_algorithmN  s    			s¡   
    .help = "Use sequence similarity to predict new B-values" 
    .short_caption = Sequence similarity-based
    .style = box auto_align
{
    %s
    
    %s
}iœÿÿÿc         C   s[   |  j  d k  r t d ‚ n  |  j d k  r6 t d ‚ n  t j d |  j d |  j  d |  j ƒ S(   Ni   s   Invalid precision: >0 requiredi    s"   Invalid probe_radius: >=0 requiredt   probet	   precisionRA   (   RG   R   t   probe_radiusR    t   BPAAccessibleSurfaceAreaRA   (   R   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt   asa_bfactor_algorithmw  s    			s“  
    .help = "Use accessible surface area to predict new B-values"
    .short_caption = Surface area-based
    .style = box auto_align
{
    %s
        
    precision = 960
        .help = "Number of points per atom"
        .type = int
        .optional = False
        
    probe_radius = 1.4
        .help = "Radius for probing surface accessibility"
        .type = float
        .optional = False
}i   t   originalt   asac         C   s   t  j j d |  j ƒ S(   Nt   start(   R    t   MRASequencet   TargetRM   (   R   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt   target_renumber_step   s    c         C   s   t  j j d |  j ƒ S(   NRM   (   R    RN   t   ModelRM   (   R   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt   model_renumber_step¥  s    c         C   s
   t  j ƒ  S(   N(   R    t   MRAOriginal(   R   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt   no_renumber_stepª  s    t   targett   modelc         C   s   |  r t  j ƒ  St  j ƒ  S(   N(   R    t   SRSingleLetterTargett
   SRSequence(   t   keep_ptm(    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt   target_sequence_rename_step¶  s    c           C   s
   t  j ƒ  S(   N(   R    t
   SROriginal(    (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt   model_sequence_rename_step»  s    c         C   s  x9 |  j  ƒ  D]+ } | j d k  r | j ƒ  j | ƒ q q WxÒ |  j ƒ  D]Ä } | j  ƒ  sn |  j | ƒ qI n  xœ | j ƒ  D]Ž } | j  ƒ  s  | j | ƒ q{ n  xf | j ƒ  D]X } | j  ƒ  s­ | j	 | ƒ q­ x3 | j
 ƒ  D]" } | j  ƒ  sÜ | j | ƒ qÜ qÜ Wq­ q­ Wq{ WqI W|  j ƒ  d  S(   Ng{®Gázt?(   t   atomst   occt   parentt   remove_atomt   modelst   remove_modelt   chainst   remove_chaint   residue_groupst   remove_residue_groupt   atom_groupst   remove_atom_groupt   atoms_reset_serial(   t   roott   aRV   t   chaint   rgt   ag(    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt   regularize_hierarchyÁ  s&    #c         C   s  | j  d d ƒ | j d d ƒ |  j ƒ  } t j d | ƒ } | j d | ƒ } | j  d d ƒ xf | D]^ \ }	 }
 |	 j d |
 ƒ } |
 j ƒ  r± | j | ƒ |	 j d |
 ƒ qg | j d d | ƒ qg W| j  d d	 ƒ t	 d | ƒ | j  d d
 ƒ g  } x“ | D]‹ \ } }	 |	 sqn  t
 | j d | ƒ j ƒ  ƒ } | sEt ‚ | d j ƒ  d k r| j t j d | d j ƒ  j d |	 d ƒ ƒ qqW| j  d d ƒ d | | f } t | d ƒ } x | D] } | j d | ƒ qÈW| j d | j ƒ  ƒ | j ƒ  | S(   Nt   msgs   PDB output requesteds1   Associate modifications with hierarchy objects...Rj   t	   r_indexers   Applying modifications...t   entitys2   %s - execution omitted because entity not attacheds   Regularizing hierarchy...s'   Generating sequence identity records...t   indexeri    t   midi   t   identityg      Y@s   Preparing output file...s	   %s_%s.pdbR   s   %s
(   t   infot   debugt	   deep_copyR    t   ReverseIndexert   instructionst   logt   is_connectedt   apply_toRo   t   listt	   as_entityt	   hierarchyt   AssertionErrorR5   t   appendR   t    get_phaser_model_identity_remarkt   objectt   idt   filet   writet   as_pdb_stringt   close(   Rj   t	   blueprintt
   identitiest	   file_roott   suffixt   loggert	   copy_rootRs   Rz   t   it   et   mt   remarkst   dt   ht	   file_namet   foutt   r(    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt   write_pdb_outputÝ  sF    		
c         C   sŠ  d d  l  } | j d d ƒ | j d d ƒ |  j ƒ  } t j d | ƒ } | j d | ƒ }	 | j d d ƒ g  }
 g  } g  } t j j | j	 j
 j } t j j | j	 j
 j } t j j | j	 j
 j } x0|	 D](\ } } t | t j ƒ rU| j d d | j d	 | ƒ ƒ | j ƒ  | k r0|
 j | ƒ qø| j ƒ  | k rø| j | ƒ qøqÐ t | t j ƒ rÈ| j d d
 | j d	 | ƒ ƒ | j ƒ  | k rµ| j | | j j f ƒ n  | j d	 | ƒ qÐ | j d d | j d	 | ƒ ƒ | j d	 | ƒ qÐ W| j d d ƒ t d | ƒ | j d d ƒ d | | f } t | d ƒ } | j d ƒ | j d t t j d | ƒ ƒ ƒ | j d ƒ x+ |
 D]# } | j d t | j ƒ  ƒ ƒ qŒW| j d ƒ | j d ƒ x+ | D]# } | j d t | j ƒ  ƒ ƒ qÔW| j d ƒ | j d ƒ xJ | D]B \ } } | j d t | j ƒ  | | j ƒ  j j ƒ  f ƒ ƒ qW| j d ƒ | j d ƒ | j  ƒ  | S(   NiÿÿÿÿRp   s   Coot output requesteds1   Associate modifications with hierarchy objects...Rj   Rq   s-   Applying modifications (but not deletions)...s   %s deferredRr   s   %s applied and loggeds
   %s applieds   Regularizing hierarchy...s   Preparing output file...s
   %s_%s.cootR   s   (
s   %s,
s     %s,
s     ),
s   )
(!   t	   iotbx.pdbRv   Rw   Rx   R    Ry   Rz   t   Entityt	   LEVEL_FORt   pdbR€   t   residue_groupt
   atom_groupt   atomt
   isinstancet   DeleteInstructionR{   R5   R‚   t   AttachInstructiont   datat   nameR}   Ro   R†   R‡   t   strt   to_coot_s_expressiont   coot_selectorR„   t   altloct   stripR‰   (   Rj   RŠ   R‹   RŒ   R�   RŽ   t   iotbxR�   Rs   Rz   t   moribund_residuest   moribund_atomst   attached_atomst   level_rgt   level_agt   level_aR�   R‘   R–   R—   t   n(    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt   write_coot_output  sd       #!!4
R�   t   cootc         C   sE   g  | j  D]7 } |  | d t | | ƒ r8 t | | ƒ n d  ƒ ^ q
 S(   NR   (   t   uset   hasattrt   getattrt   None(   t
   collectionR   R²   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt   get_algorithmsf  s    c         C   s§   t  j d t d t d |  ƒ d t d t d | ƒ d t | j d | ƒ d t d t d | ƒ d t | ƒ d | r t	 d	 | ƒ n t
 ƒ  d
 t d t d | ƒ d | j ƒ S(   Nt	   deletionsR¹   R   t
   polishingst   renumbert   pruningst   completionst   renameRY   t   bfactorst	   minimum_b(   R    t   SculptorRº   t   MAINCHAIN_ALGORITHM_NAMEDt   POLISHING_ALGORITHM_NAMEDt   RENUMBER_STEP_BASED_ONRµ   t!   SIDECHAIN_PRUNING_ALGORITHM_NAMEDt   setRZ   R\   t   BFACTOR_ALGORITHM_NAMEDt   minimum(   t   deletiont	   polishingR½   t   pruningt
   completionRÀ   t   bfactorRY   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt   get_sculptor_objectn  s"    					c         C   sf   |  s g  } nG t  t j g  |  D]. } g  | j d ƒ D] } | j ƒ  ^ q5 ^ q ƒ } t j d | ƒ S(   Nt   ,t   keep(   t   reducet   operatort   addt   splitRª   R    t	   Discarder(   R   t   knownt   indR�   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt   get_discarder_objectˆ  s    	>c         C   sk  | j  d d ƒ t j j t ƒ } t ƒ  } xA |  j j D]3 } | t k r^ | j	 t | ƒ q8 | j
 | ƒ q8 Wg  } xï | D]ç } | j  d t j d d | ƒ ƒ | j d t d | ƒ g ƒ } | j  d | j ƒ  ƒ | j ƒ  } | j d | d | t d	 | j j d
 | j j d | j j d | j j d | j j d |  j j d |  j j d |  j j ƒ f ƒ q| W| S(   NRp   s!   Predefined protocols will be usedt   texts   Protocol %s:t   sourcest   keys   protocol %ss   _%sRË   RÌ   RÍ   RÎ   RÏ   R½   RÀ   RY   (   Rv   t   libtbxt   philt   parset   PHIL_PROTOCOL_MPRÈ   t   macromoleculet	   protocolst   PROTOCOL_COMBINATIONSt   updateRÕ   R   t   headingt   fetcht   get_protocol_philt   as_strt   extractR‚   RÐ   RË   RÌ   RÍ   RÎ   RÏ   R½   RÀ   t   keep_ptm_if_base_residues_agree(   R   RŽ   t   protocol_philt   protocol_keysRÝ   Rã   t   mppt   prot(    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt   process_multiprotocol_phil–  s4    	 c         C   sâ   | j  d d ƒ | j  d t j ƒ  ƒ t j j t ƒ } | j d | j d |  ƒ g ƒ } | j  d | j	 ƒ  ƒ d d t
 d |  j j d |  j j d	 |  j j d
 |  j j d |  j j d |  j j d |  j j d |  j j ƒ f g S(   NRp   s$   User-specified protocol will be usedRÜ   t   python_objects   user defined protocolt    RË   RÌ   R½   RÍ   RÎ   RÀ   RÏ   RY   (   Rv   R   t   blankRÞ   Rß   Rà   Rá   Rç   t   formatRé   RÐ   Râ   RË   RÌ   R½   RÍ   RÎ   RÀ   RÏ   Rë   (   R   RŽ   Rì   Rî   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt"   process_user_defined_protocol_phil¿  s"    	s  
        macromolecule {
            deletion {
                use = gap
            }
            
            polishing {
                use = None
            }
            
            pruning {
                use = schwarzenbacher
                
                schwarzenbacher {
                    pruning_level = 2
                }
            }
            
            bfactor {
                use = original
                minimum = 10
            }
            
            completion = cbeta
        }
        t   1sU  
        macromolecule {
            deletion {
                use = completeness_based_similarity
                
                completeness_based_similarity {
                    offset = 0.0
                    calculation {
                        matrix = blosum62
                        window = 5
                        weighting = triangular
                    }
                }
            }
            
            polishing {
                use = None
            }
            
            pruning {
                use = schwarzenbacher
                
                schwarzenbacher {
                    pruning_level = 2
                }
            }
            
            bfactor {
                use = original
                minimum = 10
            }
            
            completion = cbeta
        }
        t   2s  
        macromolecule {   
            deletion {
                use = gap
            }
            
            polishing {
                use = None
            }
            
            pruning {
                use = similarity
                
                similarity {
                    pruning_level = 2
                    full_length_limit = 0.2
                    full_truncation_limit = -0.2
                    calculation {
                        matrix = blosum62
                        window = 1
                        weighting = triangular
                    }
                }
            }
            
            bfactor {
                use = original
                minimum = 10
            }
            
            completion = cbeta
        }
        t   3s_  
        macromolecule {   
            deletion {
                use = completeness_based_similarity
                
                completeness_based_similarity {
                    offset = 0.0
                    calculation {
                        matrix = blosum62
                        window = 5
                        weighting = triangular
                    }
                }
            }
            
            polishing {
                use = None
            }
            
            pruning {
                use = similarity
                
                similarity {
                    pruning_level = 2
                    full_length_limit = 0.2
                    full_truncation_limit = -0.2
                    calculation {
                        matrix = blosum62
                        window = 1
                        weighting = triangular
                    }
                }
            }
            
            bfactor {
                use = original
                minimum = 10
            }
            
            completion = cbeta
        }
        t   4s-  
        macromolecule {   
            deletion {
                use = gap
            }
            
            polishing {
                use = None
            }
            
            pruning {
                use = schwarzenbacher
                
                schwarzenbacher {
                    pruning_level = 2
                }
            }
            
            bfactor {
                use = similarity
                minimum = 10
                
                similarity {
                    factor = -80
                    calculation {
                        matrix = blosum62
                        window = 5
                        weighting = triangular
                    }
                }
            }
            
            completion = cbeta
        }
        t   5so  
        macromolecule {   
            deletion {
                use = completeness_based_similarity
                
                completeness_based_similarity {
                    offset = 0.0
                    calculation {
                        matrix = blosum62
                        window = 5
                        weighting = triangular
                    }
                }
            }
            
            polishing {
                use = None
            }
            
            pruning {
                use = schwarzenbacher
                
                schwarzenbacher {
                    pruning_level = 2
                }
            }
            
            bfactor {
                use = similarity
                minimum = 10
                
                similarity {
                    factor = -80
                    calculation {
                        matrix = blosum62
                        window = 5
                        weighting = triangular
                    }
                }
            }
            
            completion = cbeta
        }
        t   6sµ  
        macromolecule {   
            deletion {
                use = gap
            }
            
            polishing {
                use = None
            }
            
            pruning {
                use = schwarzenbacher
                
                schwarzenbacher {
                    pruning_level = 2
                }
            }
            
            bfactor {
                use = asa
                minimum = 10
                
                asa {
                    factor = 12
                    precision = 960
                    probe_radius = 1.4
                }
            }
            
            completion = cbeta
        }
        t   7s÷  
        macromolecule {   
            deletion {
                use = completeness_based_similarity
                
                completeness_based_similarity {
                    offset = 0.0
                    calculation {
                        matrix = blosum62
                        window = 5
                        weighting = triangular
                    }
                }
            }
            
            polishing {
                use = None
            }
            
            pruning {
                use = schwarzenbacher
                
                schwarzenbacher {
                    pruning_level = 2
                }
            }
            
            bfactor {
                use = asa
                minimum = 10
                
                asa {
                    factor = 12
                    precision = 960
                    probe_radius = 1.4
                }
            }
            
            completion = cbeta
        }
        t   8sÔ  
        macromolecule {   
            deletion {
                use = gap
            }
            
            polishing {
                use = None
            }
            
            pruning {
                use = schwarzenbacher
                
                schwarzenbacher {
                    pruning_level = 2
                }
            }
            
            bfactor {
                use = similarity+asa
                minimum = 10
                
                asa {
                    factor = 8
                    precision = 960
                    probe_radius = 1.4
                }
                
                similarity {
                    factor = -60
                    calculation {
                        matrix = blosum62
                        window = 5
                        weighting = triangular
                    }
                }
            }
            
            completion = cbeta
        }
        t   9s  
        macromolecule {   
            deletion {
                use = completeness_based_similarity
                
                completeness_based_similarity {
                    offset = 0.0
                    calculation {
                        matrix = blosum62
                        window = 5
                        weighting = triangular
                    }
                }
            }
            
            polishing {
                use = None
            }
            
            pruning {
                use = schwarzenbacher
                
                schwarzenbacher {
                    pruning_level = 2
                }
            }
            
            bfactor {
                use = similarity+asa
                minimum = 10
                
                asa {
                    factor = 8
                    precision = 960
                    probe_radius = 1.4
                }
                
                similarity {
                    factor = -60
                    calculation {
                        matrix = blosum62
                        window = 5
                        weighting = triangular
                    }
                }
            }
            
            completion = cbeta
        }
        t   10sÛ  
        macromolecule {   
            deletion {
                use = gap
            }
            
            polishing {
                use = None
            }
            
            pruning {
                use = similarity
                
                similarity {
                    pruning_level = 2
                    full_length_limit = 0.2
                    full_truncation_limit = -0.2
                    calculation {
                        matrix = blosum62
                        window = 1
                        weighting = triangular
                    }
                }
            }
            
            bfactor {
                use = similarity+asa
                minimum = 10
                
                asa {
                    factor = 8
                    precision = 960
                    probe_radius = 1.4
                }
                
                similarity {
                    factor = -60
                    calculation {
                        matrix = blosum62
                        window = 5
                        weighting = triangular
                    }
                }
            }
            
            completion = cbeta
        }
        t   11s  
        macromolecule {   
            deletion {
                use = completeness_based_similarity
                
                completeness_based_similarity {
                    offset = 0.0
                    calculation {
                        matrix = blosum62
                        window = 5
                        weighting = triangular
                    }
                }
            }
            
            polishing {
                use = None
            }
            
            pruning {
                use = similarity
                
                similarity {
                    pruning_level = 2
                    full_length_limit = 0.2
                    full_truncation_limit = -0.2
                    calculation {
                        matrix = blosum62
                        window = 1
                        weighting = triangular
                    }
                }
            }
            
            bfactor {
                use = similarity+asa
                minimum = 10
                
                asa {
                    factor = 8
                    precision = 960
                    probe_radius = 1.4
                }
                
                similarity {
                    factor = -60
                    calculation {
                        matrix = blosum62
                        window = 5
                        weighting = triangular
                    }
                }
            }
            
            completion = cbeta
        }
        t   12sS  
        macromolecule {
            deletion {
                use = threshold_based_similarity
                
                threshold_based_similarity {
                    threshold = -0.2
                    calculation {
                        matrix = blosum62
                        window = 3
                        weighting = triangular
                    }
                }
            }
            
            polishing {
                use = None
            }
            
            pruning {
                use = schwarzenbacher
                
                schwarzenbacher {
                    pruning_level = 2
                }
            }
            
            bfactor {
                use = original
                minimum = 10
            }
            
            completion = cbeta
        }
        t   13t   allt   minimalc         C   sb   |  t  k rZ |  t k r= t d |  d j t t ƒ ƒ f ‚ n  t j j t |  ƒ t  |  <n  t  |  S(   Ns    Unknown protocol '%s': not in %sRÑ   (   t   PROTOCOL_PHILSt	   PROTOCOLSR   t   joint   sortedRÞ   Rß   Rà   (   RÝ   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyRè   í  s    c           C   s   t  j ƒ  t j ƒ  S(   N(   R  t   keysRä   (    (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt   get_known_protocolsû  s    c         C   s9   d j  g  |  j ƒ  D] \ } } d | | j f ^ q ƒ S(   Ns   
s   %s
%s(   R  t   itemst   PHIL(   t   phil_fort   kt   v(    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt   configuration_phil  s    s  
input
    .help = "Input files"
{
    model
        .help = "Input pdb file"
        .optional = True
        .short_caption = PDB file
    {
        file_name = None
            .help = "PDB file name"
            .short_caption = PDB file
            .optional = False
            .type = path
            .style = bold file_type:pdb
            
        selection = all
            .help = "Selection string"
            .optional = False
            .short_caption = Atom selection
            .input_size = 400
            .type = str
            .style = bold
            
        remove_alternate_conformations = False
            .help = "Remove alternate conformations"
            .type = bool
            .optional = False
            .style = bold noauto
            
        sanitize_occupancies = False
            .help = "Sets occupancies > 1.0 to 1.0"
            .type = bool
            .optional = False
            .style = noauto
    }

    alignment
        .help = "Input alignment file"
        .multiple = True
        .optional = True
        .short_caption = Sequence alignment file
        .style = auto_align
    {
        file_name = None
            .optional = False
            .type = path
            
        target_index = 1
            .help = "Index of target sequence in alignment"
            .type = int
            .optional = False
    }
            
    sequence
        .help = "Input sequence file"
        .multiple = True
        .optional = True
        .style = auto_align
    {
        file_name = None
            .help = "Sequence file"
            .short_caption = Sequence file
            .type = path
            
        chain_ids = None
            .optional = False 
            .short_caption = Chain IDs
            .type = strings
    }
}
sŒ  
output
    .help = "Output options"
{
    include scope libtbx.phil.interface.tracking_params
    
    folder = .
        .help = "Output file folder"
        .type = path
        .optional = False
        .short_caption = "Output file folder"
        .input_size = 400
        .style = directory
        
    root = sculpt
        .help = "Output file root"
        .type = str
        .optional = False
        .short_caption = Output file base
        .input_size = 400
        .style = bold
            
    format = %(output_format)s
        .help = "Output file format"
        .type = choice
        .optional = False
        .style = hidden
}
t   output_formatsø  
renumber
    .short_caption = Numbering
{
    use = %(renumber_use)s
        .help = "Mainchain numbering; (* = selected; None: disable)"
        .type = choice
        .optional = False
        .short_caption = Mainchain numbering method
 
    start = 1
        .help = "Number for first residue"
        .type = int
        .optional = False
        .short_caption = First residue number for sequence-based numbering
}
        
rename = True
    .help = "True: enable; False: disable"
    .type = bool
    .optional = False
    .short_caption = Rename residues based on target sequence
    .style = bold
    
keep_ptm_if_base_residues_agree = False
    .help = "Keep post-translational modification if residues agree"
    .type = bool
    .optional = False
t   renumber_usesv  
deletion
    .help = "Configure mainchain deletion"
    .short_caption = Main-chain deletion
    .style = menu_item auto_align box
{
    use = %(mainchain_use)s
        .help = "Available algorithms (* = active)"
        .short_caption = Mainchain deletion method
        .type = choice ( multi = True )
        .optional = True
        .style = bold noauto cols:2
                
    %(mainchain_configure)s
}
            
polishing
    .help = "Configure mainchain polishing"
    .short_caption = Main-chain polishing
    .style = menu_item auto_align box
{
    use = %(polishing_use)s
        .help = "Available algorithms (* = active)"
        .type = choice ( multi = True )
        .short_caption = Mainchain polishing method
        .optional = True
        .style = bold noauto
            
    %(polishing_configure)s
}   
        
pruning
    .help = "Configure sidechain pruning"
    .short_caption = Sidechain pruning
    .style = menu_item auto_align box
{   
    use = %(pruning_use)s
        .help = "Available algorithms (* = active)"
        .short_caption = Sidechain pruning method
        .type = choice ( multi = True )
        .optional = True
        .style = bold noauto
                
    %(pruning_configure)s
}
            
bfactor
    .help = "Configure bfactor prediction"
    .short_caption = B-factor modifications
    .style = menu_item auto_align box
{
    use = %(bfactor_use)s
        .help = "Available algorithms (* = active)"
        .type = choice ( multi = True )
        .optional = True
        .short_caption = B-factor predication algorithm
        .style = bold noauto
            
    minimum = 10
        .help = "Minimum allowed value (a constant is added if any B-factors would fall below this value)"
        .type = float
        .optional = False
        .short_caption = Add constant to current B-factors
        .style = bold
                
    %(bfactor_configure)s
}
                
completion = %(completion_use)s
    .help = "Sidechain completion algorithms (* = active)"
    .type = choice ( multi = True )
    .optional = True
    .short_caption = Sidechain completion method
    .style = menu_item
t   mainchain_useR  t   mainchain_configuret   polishing_uset   polishing_configuret   pruning_uset   pruning_configuret   bfactor_uset   bfactor_configuret   cbetat   completion_uses{   
macromolecule
    .help = "Workflow step configuration"
{   
    %(protocol_operations)s
    
    %(common_operations)s
}
t   protocol_operationst   common_operationssó   
macromolecule
    .help = "Workflow step configuration"
{
    protocols = %(protocols)s
        .help = "Available protocols (* = active)"
        .type = choice ( multi = True )
        .optional = False
        
    %(common_operations)s
}
Rã   s\   
macromolecule
    .help = "Workflow step configuration"
{   
    %(protocol_operations)s
}
s«      
hetero = None
    .help = "Keep named hetero residues"
    .type = strings
    .multiple = False
    
min_hssp_length = 6
    .help = "Length of residue segment that indicates a reliable match"
    .type = int
    .multiple = False
    .optional = False
    
min_matching_fraction = 0.4
    .help = "Minimum matching fraction in residue-to-alignment matching"
    .type = float
    .multiple = False
    .optional = False
sL   
    %(input)s
    
    %(output)s

    %(sculptor)s
    
    %(other)s
    t   inputR   t   othert   process_includessP   
    %(input)s
    
    %(output)s
    
    %(sculptor)s
    
    %(other)s
    c         C   s  d d  l  } t t j j ƒ } xß |  j ƒ  D]Ñ } g  t | j ƒ  ƒ D]+ \ } } | j ƒ  d j	 | k rD | ^ qD } | s+ | d d k r’ q+ n  | j
 j j ƒ  } | j | _ x6 | j ƒ  | d D]  } | j | ƒ | j | ƒ qÅ W| j ƒ  j | ƒ q+ Wd  S(   Niÿÿÿÿi    (   Rš   RÈ   R   t   SOLVENTt   three_letter_codesRc   t	   enumerateRe   Rg   t   resnameR�   R€   Rl   R…   Rf   t   append_residue_groupR_   t   append_chain(   Rj   R«   t   resnamest   cR�   Rm   t
   is_solventt   solvent_chain(    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt#   transfer_solvent_to_separate_chainsf  s    %c         C   sñ   d d l  m } x« |  j ƒ  D]� } | j ƒ  } | s; t ‚ | d j d k r‹ d t | ƒ k r˜ d | d _ | j | d | d ƒ q˜ n d | d _ x | d D] } | j | ƒ q£ Wq W|  j	 ƒ  } | j
 | j d g t | ƒ ƒ ƒ d  S(   Niÿÿÿÿ(   R   i    Rò   i   i   g      ð?(   R	   R   Re   Rg   R�   R©   t   lent   merge_atom_groupsRh   R]   t   set_occR
   (   Rj   R   Rm   t   agsRn   R]   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt   remove_alternate_conformations~  s    c         C   sd   d d l  m } |  j ƒ  } | j ƒ  } g  | D] } t | d ƒ ^ q/ } | j | j | ƒ ƒ d  S(   Niÿÿÿÿ(   R   g      ð?(   R	   R   R]   t   extract_occt   minR/  R
   (   Rj   R   R]   R^   t   ot	   sanitized(    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt   sanitize_occupancies”  s
    "c         C   s`   x% |  j  ƒ  | D] } |  j | ƒ q Wt |  j  ƒ  ƒ d k r\ t d ƒ |  j  ƒ  d _ n  d  S(   Ni   i    (   Ra   Rb   R-  R¦   R…   (   Rj   t	   max_countR’   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt   restrict_model_count�  s    c         C   sÒ  d d l  m } | j ƒ  } xP | D]H }	 x? t |	 j j ƒ  ƒ D]( \ }
 } | j d | d |
 |	 f ƒ q? Wq# Wg  } g  } xJ| D]B} | j d d | ƒ t j	 d | j
 ƒ } | j d | j ƒ | t k rˆyV |  d | j
 d	 | d
 | d | j | j
 j ƒ d | d | d | ƒ } | j | ƒ Wq°t k
 r„} | j d | ƒ | j d d ƒ t j d | j
 d	 | ƒ } | j | ƒ q°Xn( t j d | j
 d	 | ƒ } | j | ƒ | j d | j d <q‚ W| | f S(   Niÿÿÿÿ(   t   rsamt   sequenceR¤   Rp   s   Processing: %sRl   s   Chain type: %sR   R¹   R%   t   min_fractionRŽ   s   Treating as UNKNONW typei   Rv   (   t   phaserR9  t
   SequenceDBR$  R„   t   sequence_stringsRÕ   Rv   R   t	   determineRl   R¥   t   KNOWNt   getR…   R‚   t   RuntimeErrort   warningR    t   ChainSamplet
   identifiert   store(   t   factoryt   chain_infost
   alignmentst   sequence_forR%   R;  RŽ   R9  R¹   t   alit   indext   seqRØ   R   t   cinfot   mm_typet   csR‘   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt   chain_samples¦  s>    "$		c         C   s   t  j d |  d t ƒ S(   NRl   R   (   R    RD  RO  (   Rl   R   R¹   R:  R%   R;  RŽ   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt   unaligned_chain_sampleÔ  s    c            sŸ  d d l  m } d d l  m } | j d d ƒ ˆ j ƒ  ‰ | j d |  j ƒ  d ˆ d ˆ j ƒ }	 | j d d	 |	 ƒ | r,| j d d
 ƒ | j	 d | j
 d |	 d d d d |  j ƒ }
 |
 j ƒ  d k sÓ t ‚ | j d ƒ | j |
 ƒ t j d d d |
 ƒ } d } t j d d g d |	 g ƒ } nr| j d d ƒ | j ƒ  d k rZt d ‚ n  | j d d ƒ | j d d ƒ | j d |	 ƒ } | s˜t ‚ t | ƒ } | | k  rÐ| j d d  | ƒ t d! ‚ n  | j d d" | ƒ g  t | | j ƒ D] \ } } | | k r÷| ^ q÷} d t | ƒ k  rZ| j d d# t | ƒ ƒ | j d d$ ƒ n  | d d \ } } | j d d% | j | f ƒ | j d | j ƒ | j d t j d& d' ƒ ƒ t j d( |  d | j d) | d* ˆ d+ | d, | ƒ ‰  ˆ  j  r˜| j d d- ƒ t! ˆ  j  ƒ } d. j" g  |  j ƒ  D] } | | k r@d/ n d0 ^ q(ƒ } t j d |	 g d d1 g ƒ } | j d | j# d2 d3 d4 d5 d6 | ƒ ƒ n  g  t ˆ  j$ ƒ  ˆ  j% ƒ D]* \ } } | ˆ  j& j' k r±| | f ^ q±} t j d d. j" d7 „  | Dƒ ƒ d. j" ‡  ‡ ‡ f d8 †  | Dƒ ƒ g d d9 d1 g ƒ } | j( ƒ  } | d: k  r›| j d d; ƒ | j d d< | ƒ | j | ƒ | | k  r›t d= ‚ q›n  ˆ  S(>   Niÿÿÿÿ(   R9  (   t   application_utilsRp   s   Chain-sequence matching:t   rgst   one_letter_forR   s   Chain sequence: %ss   Target sequence providedt   seq_at   seq_bt   name_at   MASTERt   name_bs   CHAIN_%si   s   Alignment with target:R¥   s   phenix.alignmentt	   alignmenti   t   namest   CHAINRI  s$   Select alignment from predefined seti    s   No alignments are availables$   Pre-screening alignment sequences...s+   Scoring sequences based on exact overlap...R:  sG   The longest exact overlap is shorter than %s residues (min_hssp_length)s;   No sufficiently similar alignment sequences have been founds   Longest overlap is %d residuess+   There are %d sequences with longest overlaps   The first one will be selecteds$   Best matching: name = %s, index = %sRÛ   s   Residue mappingRl   RL  R   t   min_hssp_lengtht   min_matching_fractions   Unaligned residues:Rò   t   *t    t   PDBt	   aln_widthi<   t   caption_widthi   t   middle_linec         s   s   |  ] } | d  Vq d S(   i    N(    (   t   .0t   p(    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pys	   <genexpr>=  s    c         3   sK   |  ]A } | d  r9 ˆ j  | d  j ƒ  d j ˆ j ƒ n	 ˆ  j j Vq d S(   i   i    N(   RA  Rg   R%  t   unknown_one_letterR[  R(   (   Rf  Rg  (   RP  R   RU  (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pys	   <genexpr>>  s   t   ALIg      ð?s   Sequence mismatchess   Matching fraction: %.2fs:   Unable to align: matching fraction < min_matching_fraction()   R<  R9  RS  Rv   RU  t   one_letter_sequenceRe   Rh  Rw   t   create_alignmentR:  R…   t   multiplicityR�   R   t   AlignmentObjectR   t   clustal_alignmentt   countRB  t   matchingt   maxRC  t   zipRF  R-  R¥   R„   R   Ræ   R    t   AlignedChainSamplet	   unalignedRÈ   R  Rô   t   model_sequencet   alignedR[  R(   t   identity_fraction(   Rl   R   R¹   R:  R%   R;  RŽ   R9  RS  RM  t   ali_objRK  RL  t	   chain_alit	   matchingst   longestt   lR”   t   bestst   unknownsRm   t   midlinet   show_aliR)  t   mappingRw  (    (   RP  R   RU  s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt   aligned_chain_sampleÙ  s¢    								7						4			"%$	c         C   se   t  d „  |  Dƒ ƒ r/ | j d d ƒ t } n2 t  d „  |  Dƒ ƒ sK t ‚ | j d d ƒ t } | S(   Nc         s   s(   |  ] } | d  j  d t j ƒ Vq d S(   iÿÿÿÿt   sample_typeN(   t   processableR    RD  (   Rf  Rg  (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pys	   <genexpr>S  s    Rp   s%   No chain-alignment matching necessaryc         s   s(   |  ] } | d  j  d t j ƒ Vq d S(   iÿÿÿÿRƒ  N(   R„  R    Rs  (   Rf  Rg  (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pys	   <genexpr>X  s   s*   Chain-alignment matching will be performed(   R  Rv   RR  R�   R‚  (   t
   processorsRŽ   RG  (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt   chain_sample_factoryQ  s    		c         C   sÐ   g  } x™ | D]‘ } | j  d d t | j d ƒ ƒ | j d | j ƒ sO t ‚ | j  d d ƒ | j d | d | ƒ } | j  d d t | ƒ ƒ | j | ƒ q Wt	 j
 j d	 t t j | g  ƒ d
 |  ƒ } | S(   NRp   s   Processing '%s'...Rv   Rƒ  s     Finding modifications...t   sampleRŽ   s     (%d modifications found)Rz   Rs   (   Rv   R¦   RF  R„  t	   __class__R�   t   runR-  R‚   R    t	   Blueprintt   from_instructionsRÓ   RÔ   RÕ   (   Rs   t   samplest	   processorRŽ   Rz   RP  t   instrt   bp(    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt   sample_process`  s    !	c         C   sU   g  } xH | D]@ } t  j j | j ƒ j d |  ƒ | j ƒ  f } | j | ƒ q W| S(   NRs   (   R    R›   t   ChainRl   t   as_descriptorRu   R‚   (   Rs   RØ   RŽ   R‹   RP  R�   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt   identity_processs  s    c         C   s
  | j  d t j d d ƒ ƒ t d | d |  j ƒ  d | d | d | d	 | d
 | ƒ \ } } t j d |  j ƒ } | j  d d ƒ | j  d t j ƒ  ƒ t	 d | d | d
 | ƒ } | rÖ | j  d t j d d ƒ ƒ n  t
 d | d | d | d
 | ƒ } | r| j  d t j d d ƒ ƒ n  g  } xá | D]Ù \ } } } | j  d d | ƒ | j  d t j ƒ  ƒ t
 d | d | d | d
 | ƒ } x! | j D] } | j d | ƒ q�W|
 d |  j d | d | d | d d |	 | f d
 | ƒ } | j  d d | ƒ | j | ƒ q)W| S(   NRp   RÛ   s   Find chainsRG  RH  RI  RJ  R%   R;  RŽ   Rj   s   Calculating identity records...Rs   RØ   s   Processing hetero chainsRŒ  R�  s   Processing protein chainss   Running: %st   datumRŠ   R‹   RŒ   R�   s   %s%ss   %s written
(   Rv   R   t
   underlinedRQ  t   get_chain_infosR    t   ForwardIndexerR„   Ró   R“  R�  R¤   RÕ   R‚   (   R�   RG  RI  RJ  t	   sculptorst	   discarderR%   R;  t   prefixR�   t   output_methodRŽ   RØ   R   Rs   R‹   t
   bp_unknownt   outfilesR¥   t   tagt   st   bp_knownR”   t   outfile(    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt   process_single_pdb�  s`    							c   "      C   s§  t  j d | d | ƒ } | j d t  j d d t t f ƒ ƒ | \ } } t j d | ƒ } d d l m	 } | j
 d	 t j d
 | j ƒ  d d ƒ ƒ | j
 d	 t j d
 d d g d d ƒ ƒ x |  D] }	 |	 j d | ƒ qÃ Wy | j ƒ  }
 Wn t k
 r} t | ‚ n X| j d t  j d d ƒ ƒ | j d |
 j ƒ  ƒ y |
 j ƒ  } Wn t k
 rl} t | ‚ n X| j d t  j d d ƒ ƒ | d | d | ƒ } t d | j ƒ } | j j j sËt d ‚ n  | j d t  j d ƒ ƒ | j d d | j j j ƒ t j j d | j j j ƒ } | j j j d k rÞ| j j j sUd | j j _ n  | j d d | j j j ƒ | j j ƒ  j | j j j ƒ } | j j | t ƒ } | j  ƒ  sÀt d ‚ n  t j d | d | j! ƒ } n  | j j j" r| j d d ƒ t" d | j ƒ n  | j j j# rB| j d d  ƒ t# d | j ƒ n  | j d d! ƒ t$ d | j ƒ g  } | j j% r“| j d t  j d d" ƒ ƒ n  x t& | j j% d# d$ ƒD]\ } } | j d d% | | j f ƒ t j' j d | j ƒ } | j( d$ k r`| j d d& | j( ƒ y | j j) d' | j( d$ ƒ Wq`t* k
 r\} t d( | | j( f ‚ q`Xn  | j+ | ƒ | j, d t  j- d d) ƒ ƒ | j, d | j ƒ | j d t  j. ƒ  ƒ q¬Wi  } | j j/ rç| j d t  j d d* ƒ ƒ n  x‰t& | j j/ ƒ D]u\ } } | j d d% | | j f ƒ t j0 j d | j ƒ } | j1 d d+ ƒ x' | j D] } | j1 d t2 | ƒ ƒ qUWd$ t3 | j ƒ k  r�| j4 d d, ƒ n  | j5 d  k r¿t d- | j ‚ n  t7 t8 j9 g  | j5 D] } | j: d. ƒ ^ qÒg  ƒ } | j d/ d0 j; g  | D] } t2 | ƒ ^ q	ƒ ƒ | j< t= g  | D] } | | j d1 f ^ q6ƒ ƒ | j d t  j. ƒ  ƒ qúWd d  l> } t? d2 | d | ƒ } t@ | j  jA } | j d t  jB d d3 ƒ ƒ | j d d | j! ƒ | jC j: | j! ƒ \ } }  y’ tD d4 | d5 | d6 | d7 | d8 | d9 | d: | jE d; | jF d< | jC j; | j  jG | jC jH | j  jI ƒ ƒ d= | jC jJ |  ƒ d1 d> | d | ƒ }! Wn t k
 r¢} t | ‚ n X|! S(?   Nt   streamR5   Rp   RÛ   s   %s version %st   master_philiÿÿÿÿ(   R   t   handlert
   extensionst   templates   input.alignment.file_name=%ss   .pdbs   .ents   input.model.file_name=%st   accumulators   All configuration options:s   Requested protocolsR   RŽ   s   No pdb files specifieds   Reading PDB files   File name: %sR–   R  t   nones   Atom selection: %ss"   No atoms left after atom selectionRj   R¥   s#   Removing alternate conformations...s   Removing occupancies > 1.0...s)   Separating solvent from macromolecules...s   Reading alignment filesRM   i   s   %d. %ss#   Assigning sequence #%d as target...RL  s   %s: %ds   Alignment reads   Reading sequence filess   Sequences read:s=   File contains multiple sequences, only the first will be useds   Empty chain_id for %sRÑ   s   Applicable chains: %ss   , i    R…  s   Processing PDB fileR�   RG  RI  RJ  R˜  R™  R%   R;  Rš  R�   R›  (K   R   t   SingleStreamRv   t   bannert   PROGRAMt   VERSIONR   t   PhilAccumulatorR«   R   t   register_file_handlert   ExtensionFileHandlert   known_alignment_formatst   processt   mergeRB  R   R•  Ré   Rê   RÚ   t   heteroR  RV   R–   t	   PDBObjectt	   from_filet	   selectionR„   t   atom_selection_cachet   selectt   TrueR]   R¥   R1  R6  R,  R[  R$  Rm  t   target_indext   assign_as_targett
   IndexErrorR‚   t   verboseRæ   Ró   R:  t   SequenceObjectRw   R¦   R-  RC  t	   chain_idsR¸   RÓ   RÔ   RÕ   RÖ   R  Rå   t   dictt   os.pathR†  t   OUTPUT_METHOD_FORRô   t   subtitlet   pathR¢  R^  R_  t   foldert   basenameRj   t   splitext("   t   argst   outt   setupt	   verbosityRŽ   t   phil_mastert   phil_processorR¨  R   t   argumentt   merged_philR‘   R   R˜  R™  R�   t   ascRj   RI  RL  t   inpRg  RJ  R4  RŸ  t
   applicableR�   R  t   osRG  R›  t   headt   tailR�  (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyR‰  Ó  sæ    			
		
!%		
"	-3				t   launcherc           B   s   e  Z d  „  Z RS(   c         C   s   t  d |  j d t j ƒ S(   NRÉ  RÊ  (   t   run_philRÉ  t   syst   stdout(   t   self(    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyR‰  �  s    (   t   __name__t
   __module__R‰  (    (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyR×  €  s   c         C   sA   t  j d t ƒ } t d g  |  D] } | d | ƒ ^ q d | ƒ S(   NR¤  RÉ  RÏ  RÊ  (   R   t   PhilArgumentFactoryt   PHIL_MASTERR‰  (   RÉ  RÊ  RG  t   arg(    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyRØ  „  s    "c         C   sg   d d  l  } g  } xH |  D]@ } | j j | ƒ r | j j | ƒ } | j | d f ƒ q q W| g  f S(   Niÿÿÿÿs   Final model(   RÂ  RÅ  t   isfilet   abspathR‚   (   t   resultRÔ  t   filesR–   t   pdb_out(    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt
   finish_jobŠ  s    c         C   s1   d  |  j j |  j j g k r- t d ƒ ‚ n  t S(   Ns'   Missing the PDB file or alignment file.(   R¸   R  RV   R[  R   Rº  (   R   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt   validate_params“  s    (n   R<  R    R   R   R   R«   R   t   libtbx.philRÞ   R   t   libtbx.utilsR   RÔ   RÙ  R­  R¬  RÈ   t   PROTEINR@  t   SIMILARITY_PHILt   TRANSFORMATION_PHILt   similarity_matrix_suiteR\  t   SS_MATRICESR   R   R   R   R  R   t   choice_stringR$   R'   RÄ   R.   R2   RÅ   R8   R>   RÇ   RC   RE   RJ   RÉ   RP   RR   RT   RÆ   RZ   R\   Ro   R™   R³   RÃ  Rº   t   FalseRÐ   RÚ   Rð   Rõ   R  R	  Rä   R  Rè   R
  R  t
   PHIL_INPUTt   PHIL_OUTPUTt   PHIL_COMMON_OPERATIONSR¸   RÓ   RÕ   RO  t   sidechain_completionRk   t   NAMEt   PHIL_PROTOCOL_OPERATIONSt   PHIL_SCULPTORt   PHIL_SCULPTOR_MPRá   t
   PHIL_OTHERRß   Rà   Rº  Rß  t   SETUP_DEFAULTt   PHIL_MULTIPROTOCOL_MASTERt   SETUP_MULTIPROTOCOLt   master_paramsR,  R1  R6  R8  RQ  RR  R‚  R†  R�  R“  R¢  Rª  t   INFOR‰  t   target_with_save_resultR×  RÚ  RØ  Ræ  Rç  (    (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/phaser/sculptor.pyt   <module>   sœ  		
	
									
				
			'		
					
			
				7	I
			)	#!*#, ))209#
			N	 	N	
	
	
	
	5		
														.		x				R­		