ó
Ú™xTc           @   s?  d  d l  m Z d  d l m Z d  d l m Z m Z d  d l m Z m	 Z	 m
 Z
 m Z d  d l Z d  d l m Z d  d l Z d „  Z d d	 „ Z d
 „  Z d „  Z d8 d9 d: d; d< d= g Z e e g  e D] \ Z Z e e f ^ qÌ ƒ Z d „  Z d „  Z d „  Z d d „ Z d d „ Z d Z d Z d Z  d Z! d  Z" d! Z# d" Z$ d# Z% d e' d e' d d$ „ Z( d e' d d% d> d( „ Z) d) d* „ Z* d+ Z+ d, „  Z, d d e- e j. d- „ Z/ e j0 j1 d. ƒ Z2 d/ e
 f d0 „  ƒ  YZ3 d d e	 e' e j. d1 „ Z4 d2 Z5 d d d d3 „ Z6 d4 e f d5 „  ƒ  YZ7 d6 e8 f d7 „  ƒ  YZ9 d S(?   iÿÿÿÿ(   t   division(   t   make_sub_header(   t   Sorryt   null_out(   t
   group_argst   Autot   slots_getstate_setstatet+   slots_getstate_setstate_default_initializerN(   t   sqrtc         C   sÏ   d d l  m } |  j ƒ  } | j ƒ  } | j ƒ  j d ƒ sD t ‚ x„ |  j ƒ  j ƒ  D]p } xg | j	 ƒ  D]Y } | j
 ƒ  } t | ƒ d k s§ | d j j ƒ  d k rj | j | j ƒ  j ƒ  ƒ qj qj WqW W| S(   Niÿÿÿÿ(   t   flexi    i   t    (   t   scitbx.array_familyR	   t   atomst   size_tt   extract_i_seqt   all_eqt   AssertionErrort
   only_modelt   chainst   residue_groupst   atom_groupst   lent   altloct   stript   extend(   t   pdb_hierarchyR	   R   t	   selectiont   chaint   residue_groupR   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/building/alternate_conformations/__init__.pyt   multi_conformer_selection   s    +$g      @c         C   sÈ  d d l  m } d } g  } | g } xœ| t |  ƒ k  rÃ|  | } | j ƒ  } d } }	 | d k rw |  | d }	 n  | t |  ƒ d k  rž |  | d } n  | d 7} |	 d k	 r³|	 j ƒ  }
 d } } xF |	 j ƒ  d j ƒ  D]. } | j j ƒ  d k rá | | j	 ƒ } Pqá qá WxF | j ƒ  d j ƒ  D]. } | j j ƒ  d k r*| | j	 ƒ } Pq*q*W| |
 d k s”d | | g k s”t
 | | ƒ | k r³| g } | j | ƒ q( q³n  | j | ƒ q( W| S(   sd   
  Split a protein chain into continuous peptide fragments (as lists of
  residue_group objects).
  iÿÿÿÿ(   t   coli    i   t   Ct   NN(   t   scitbx.matrixR   R   t   resseq_as_intt   NoneR   R   t   nameR   t   xyzt   abst   append(   t   residuest   chain_break_distanceR   t   kt   current_fragmentt	   fragmentst   rest   resseqt   next_rest   prev_rest   prev_resseqt   c_atomt   n_atomt   atom(    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/building/alternate_conformations/__init__.pyt   fragment_single_conformer_chain   s@    	



		c         C   s%  t  |  ƒ j d k r$ |  j ƒ  }  n  t  | ƒ j d k rH | j ƒ  } n  |  d | d d k sx | d |  d d k r| d S| d |  d k oŸ | d k n r¸ |  d | d d S|  d | d k oÛ |  d k n rô | d |  d d St | d |  d d |  d | d d ƒ Sd S(   sï   
  Compute the gap or overlap between two selections (order-independent).
  Returns 0 if the selections are directly adjacent, or the number of
  residues overlapped (as a negative number) or missing between the
  selections (positive).
  t   booliÿÿÿÿi    i   N(   t   typet   __name__t
   iselectiont   max(   t   sel1t   sel2(    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/building/alternate_conformations/__init__.pyt   get_selection_gap@   s    0((c         C   s†   d d l  m } | j ƒ  } d } |  j | ƒ } xN | j ƒ  j ƒ  j ƒ  D]4 } | j | j ƒ  ƒ } | d k rJ | d 7} qJ qJ W| S(   s]   
  Count the number of rotamer outliers from a selection of residues in a
  PDB hierarchy.
  iÿÿÿÿ(   t   rotamer_evali    t   OUTLIERi   (	   t   mmtbx.rotamerR>   t   RotamerEvalt   selectR   t
   only_chainR   t   evaluate_residuet   only_atom_group(   t	   hierarchyR   R>   t   rt
   n_outlierst   sub_hierarchyt   rgt   rotamer_flag(    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/building/alternate_conformations/__init__.pyt   score_rotamersT   s    t   OD1t   OD2t   OE1t   OE2t   ND2t   NE2t   CD1t   CD2t   CE1t   CE2c         C   s  d d l  m } t |  ƒ t | ƒ k oD t | ƒ k oD d k n sO t ‚ d } } d } } d } x‡ t |  | | ƒ D]s \ }	 }
 } | j j ƒ  d k r¦ q| n  t | |	 ƒ | |
 ƒ ƒ } | | d 7} | | k rå | } n  | d 7} q| W| d k st ‚ t	 | | ƒ } | d j
 ƒ  j d k rAt d | d | ƒ Sd } } xŒt |  | | ƒ D]x\ }	 }
 } | j j ƒ  d k rˆq^n  | j j ƒ  } | j ƒ  } t j | d ƒ } | d k	 r—xt |  | | ƒ D]� \ } } } | j ƒ  } | j ƒ  | j ƒ  k rÔ| j | j k rÔ| j j ƒ  | k rÔt | |	 ƒ | | ƒ ƒ } | | d 7} | | k rm| } n  PqÔqÔWt t j ƒ } t t j ƒ } Pq^t | |	 ƒ | |
 ƒ ƒ } | | d 7} | | k r^| } q^q^Wt	 | | ƒ } t d t | | ƒ d t | | ƒ ƒ S(   sŸ   
  Calculate RMSD and maximum distance for a pair of coordinate arrays,
  taking into account the symmetric or pseudo-symmetric nature of many
  sidechains.
  iÿÿÿÿ(   R   i    t   Hi   i   t   ASPt   GLUt   ASNt   GLNt   PHEt   TYRt   rmsdt   max_devN(   RX   RY   RZ   R[   R\   R]   (   R!   R   R   R   R#   t   zipt   elementR   R&   R   t   parentt   resnameR   R$   t   fetch_labelst   symmetric_atom_names_dictt   gett   residt   chain_idt   floatt   syst   maxintt   min(   t   sites1t   sites2R   R   t   rmsd_no_flipt	   rmsd_flipt   mean_sqt   max_deviation_no_flipt   n_sitest   site1t   site2R4   t   distancet   max_deviation_flipt	   atom_namet   labelst   symmetric_namet
   site1_flipt
   site2_flipt	   atom_flipt   labels_flip(    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/building/alternate_conformations/__init__.pyt   coord_stats_with_flipsn   s\    ?

" 	
" "	c   	      C   sâ   d d l  m } | j ƒ  } | j ƒ  } g  } x¡ |  j ƒ  D]“ } | j j ƒ  d k r\ q; n  t } xi | j ƒ  D][ } | j | j k ro | s” t ‚ t	 } | j
 | ƒ | j
 | j ƒ | j
 | j ƒ qo qo Wq; Wt | | | ƒ S(   Niÿÿÿÿ(   R	   RW   t   D(   RW   R€   (   R   R	   t   vec3_doubleR   Ra   R   t   FalseR$   R   t   TrueR'   R%   R   (	   t   residue1t   residue2R	   Rm   Rn   R   t   atom1t   foundt   atom2(    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/building/alternate_conformations/__init__.pyt   coord_stats_for_atom_groups¤   s      c         C   sÞ   g  } xP |  D]H } x? | j  ƒ  D]1 } | j j ƒ  | j ƒ  k r  | j | ƒ q  q  Wq Wd } t | ƒ d k rÚ xf t | ƒ D]U \ } } xF t | | d ƒ D]0 \ } }	 | j |	 ƒ }
 |
 | k rŸ |
 } qŸ qŸ Wq~ Wn  | S(   Ni    i   (   R   R$   R   R'   R   t	   enumerateRv   (   R   Rx   R   t
   atom_groupR4   t   dxyz_maxt   i_atmR†   t   j_atomRˆ   t   dxyz(    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/building/alternate_conformations/__init__.pyt$   max_distance_between_atom_conformersµ   s    !gš™™™™™¹?c         C   s   t  |  d ƒ } | | k S(   NR    (   R�   (   R   t   max_acceptable_distanceRv   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/building/alternate_conformations/__init__.pyt   requires_nterm_splitÄ   s    c         C   s   t  |  d ƒ } | | k S(   NR   (   R�   (   R   R‘   Rv   (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/building/alternate_conformations/__init__.pyt   requires_cterm_splitÈ   s    t   NEW1t   NEW2t   OLDs	   segid OLDs
   segid NEW1s
   segid NEW2s   segid NEW1 or segid NEW2s%   segid NEW1 or segid NEW2 or segid OLDc            sd  ˆ  d k r t ƒ  ‰  n  ˆ  d IJˆ  d IJ|  j ƒ  } | j ƒ  | j d ƒ | d k rs |  j ƒ  j t ƒ } n' t | t	 ƒ rš |  j ƒ  j | ƒ } n  ‡  ‡ ‡ f d †  } d } x¨|  j
 ƒ  j ƒ  D]”}	 |	 j ƒ  }
 xt |
 ƒ D]q\ } } | j ƒ  } | j ƒ  } t | ƒ d k rç | d j ƒ  j ƒ  } | j | ƒ j t ƒ sQqç n  | d k rÎ|
 | d } | j ƒ  } | | d k rÎt | j ƒ  ƒ d k rÎ| s±t | ƒ rË| | ƒ | d 7} qËqÎn  | t |
 ƒ d k  rX|
 | d } | j ƒ  } | | d k rUt | j ƒ  ƒ d k rU| s8t | ƒ rR| | ƒ | d 7} qRqUqXqç qç WqÈ W| S(   s€   
  Given a model with some residues in alternate conformations, split the
  adjacent residues to allow for backbone movement.
  R
   s      Splitting adjacent residues...i    c            sä   ˆ r ˆ  d |  j  ƒ  IJn  d } ˆ d  k	 rJ t d t d ˆ ƒ ƒ } n  |  j ƒ  } d | _ x* | j ƒ  D] } d | | _ t | _	 ql W| j
 ƒ  } d | _ x/ | j ƒ  D]! } | | _ t | _	 d | _ q® W|  j | ƒ d  S(	   Ns     %sg      à?gš™™™™™É?gš™™™™™é?t   Ag      ð?t   Bi   (   t   id_strR#   R:   Rl   RE   R   R   t   occt
   SEGID_MAINt   segidt   detached_copyt   SEGID_NEW_SPLITt   tmpt   append_atom_group(   R   t   new_occt	   main_confR4   t   alt_conf(   t   logt   new_occupancyt   verbose(    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/building/alternate_conformations/__init__.pyt   split_residueë   s"    				i   iÿÿÿÿN(   R#   R   R   t   reset_i_seqt	   reset_tmpt   atom_selection_cacheR   t   SELECTION_NEW_REBUILTt
   isinstancet   strR   R   R   RŠ   R   R"   R   R   RB   R   Rƒ   R’   R“   (   R   R¥   t   split_all_adjacentR   R¦   R¤   t	   pdb_atomsR§   t   n_splitR   R   t   i_resR   R   R.   t   last_group_i_seqst
   prev_groupR1   t
   next_groupt   next_resseq(    (   R¤   R¥   R¦   s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/building/alternate_conformations/__init__.pyt   spread_alternatesÕ   sL     


(
(
g      à?i   g      @c         C   s�  d | k o d k n s" t  ‚ |  j } | j ƒ  j ƒ  } | j | | ƒ | j | ƒ | j ƒ  }	 | d
 k	 r… |	 j | ƒ }	 n  |  j	 |	 d t
 ƒ|  j d d d t
 ƒ }
 |
 j d | ƒ } | j ƒ  j ƒ  } |  j d d d t
 ƒ } | j d | ƒ } | j ƒ  j ƒ  } | d
 k	 rAd	 d
 l } | j j | |
 | ƒ n  | r€t d | d |	 d | ƒ } t d | d |	 d | ƒ } n  |  j	 | d t
 ƒ| | f S(   sì   
  Generate an mFo-DFc map with a selection of atoms at reduced occupancy.
  Will write the map coefficients (along with 2mFo-DFc map) to an MTZ file
  if desired.  Reflections flagged for calculating R-free will always be
  omitted.
  i    g      ð?t   update_f_calct   map_types   mFo-DFct   exclude_free_r_reflectionst   resolution_factors   2mFo-DFciÿÿÿÿNt   map_datat   xray_structureR9   (   R   R¼   t
   scattererst   extract_occupanciest   set_selectedt   set_occupanciest   deep_copy_scatterersR#   RB   t   update_xray_structureRƒ   t   map_coefficientst   fft_mapt   apply_sigma_scalingt   real_map_unpaddedt   iotbx.map_toolst	   map_toolst   write_map_coeffst   negate_surrounding_sites(   t   fmodelR   t   selection_deletet   negate_surroundingt   map_file_namet   partial_occupancyRº   t   xrsRš   t   xrs_tmpt   fofc_coeffst   fofc_fftt   fofc_mapt   two_fofc_coeffst   two_fofc_fftt   two_fofc_mapt   iotbx(    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/building/alternate_conformations/__init__.pyt   get_partial_omit_map  s@    "			
	g      ø?c      	   C   s^   d d l  } | j j j d | d d d | ƒ } | j j j d | d |  d | d	 | ƒ } | S(
   s=   
  Makes the target map negative around an atom selection.
  iÿÿÿÿNR¼   t   selection_within_radiusi   R9   R»   t   negate_selectiont   atom_radius(   t   mmtbx.refinement.real_spacet
   refinementt
   real_spacet   selection_around_to_negatet6   negate_map_around_selected_atoms_except_selected_atoms(   R»   R¼   R9   t   radiust   mmtbxRÛ   t
   target_map(    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/building/alternate_conformations/__init__.pyRÊ   J  s    		s  
  discard_outliers = *rama *rota *cbeta *geo *map
    .type = choice(multi=True)
  min_model_map_cc = 0.85
    .type = float
  use_difference_map = True
    .type = bool
  sampling_radius = 2.5
    .type = float
  ignore_stub_residues = False
    .type = bool
c         C   sâ   | j  } t } |  j ƒ  r0 d | k r0 t } n  |  j ƒ  rQ d | k rQ t } n  |  j ƒ  rr d | k rr t } n  |  j ƒ  r“ d | k r“ t } n  |  j ƒ  r´ d | k r´ t } n  |  j d | j	 ƒ rÞ d | k rÞ t } n  | S(   Nt   rotat   ramat   cbetat   geot   clasht   cc_mint   map(
   t   discard_outliersR‚   t   is_rotamer_outlierRƒ   t   is_ramachandran_outliert   is_cbeta_outliert   is_geometry_outliert   is_clash_outliert   is_map_outliert   min_model_map_cc(   t
   validationt   paramst   filterst   outlier(    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/building/alternate_conformations/__init__.pyt   is_validation_outlieri  s     							c   !      C   s÷  d d l  m } d d l m } d d l }	 d d l m }
 d d l m } d d l	 m
 } | d k rŒ | j | j j ƒ  j ƒ  t ƒ } n  |  j ƒ  j ƒ  | j d |  d	 | d
 | d t ƒ } | rÙ | j d | ƒ n  | j ƒ  } | d k rt j j t ƒ j ƒ  } n  |	 j j j ƒ  } |
 j d	 | ƒ \ } } g  } | j } t d d | ƒx9|  j  ƒ  j! ƒ  D]%} | j" ƒ  s€qhn  x
| j# ƒ  D]ü} | j$ ƒ  } | j% ƒ  } | j ƒ  j& ƒ  } | j' | ƒ } | j( t ƒ sáq�n  t) | ƒ d k r| d | IJq�n  | d } | | j* ƒ } | d k r@| d | IJq�n  | j+ d | d | d t ƒ } t) | ƒ d k r¬|
 j, | ƒ rŒ| j- rŒq¬| d | t) | ƒ f IJq�n  | j. | ƒ } t/ | | ƒ } | rê| d t0 | ƒ IJq�n  | j1 rv|
 j2 | ƒ } |
 j3 d | d | d | d | j d | j4 ƒ }  |  j5 ƒ  d k rv|  j6 ƒ  d k rv| r�| d | IJq�q�qvn  | j7 | j8 ƒ  ƒ q�WqhWt) | ƒ d k r²t9 d ƒ ‚ n  | d IJ| d  t) | ƒ IJ|
 j: | d | d! d" ƒ| d IJ| S(#   sô   
  Pick residues suitable for building alternate conformations - by default,
  this means no MolProbity/geometry outliers, good fit to map, no missing
  atoms, and no pre-existing alternates, but with significant difference
  density nearby.
  iÿÿÿÿ(   t
   molprobity(   R>   N(   t   building(   t   common_residue_names_get_class(   R	   R   RË   t   geometry_restraints_managert   outliers_onlyt   outs#   Identifying candidates for buildingi   s     %s is already multi-conformeri    t   common_amino_acids     %s: non-standard residuet   residuet   mon_lib_srvt   ignore_hydrogenss%     %s: missing or incomplete sidechains     %sRÔ   R×   t   atom_selectionR¼   Râ   s     no difference density for %ss*   No residues passed the filtering criteria.R
   s8   Alternate conformations will be tried for %d residue(s):t   prefixs     (;   t   mmtbx.validationRù   R@   R>   t   mmtbx.monomer_library.serverRã   Rú   t	   iotbx.pdbRû   R   R	   R#   R6   R¼   R½   t   sizeRƒ   R   R¨   R‚   t   showt   as_multi_criterion_viewt   libtbxt   philt   parset   filter_params_strt   extractt   monomer_libraryt   servert   get_difference_mapsRì   R   R   R   t
   is_proteinR   R   R™   R   RB   R   R   Rc   t   eval_residue_completenesst   is_stub_residuet   ignore_stub_residuest   get_residue_group_dataRø   R­   t   use_difference_mapt   get_non_hydrogen_atom_indicest   local_density_qualityt   sampling_radiust$   number_of_atoms_below_fofc_map_levelt+   fraction_of_nearby_grid_points_above_cutoffR'   RE   R   t   show_chain_resseq_ranges(!   R   RË   Rü   R   Rõ   R¦   R¤   Rù   R>   Rã   Rú   Rû   R	   t   full_validationt   multi_criterionR  R×   RÔ   R(   Rö   R   R   R   R™   t   i_seqst   residue_selR‹   t	   res_classt   missing_atomsRô   t
   is_outliert   i_seqs_no_hdt	   map_stats(    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/building/alternate_conformations/__init__.pyt   filter_before_build{  s     $			
		
				

sO   
min_occupancy = 0.1
  .type = float
min_distance_over_u = 1.0
  .type = float
t   disorder_infoc           B   sP   e  Z d  d d d d d d d d d	 d
 g Z e d „ Z e j d d d „ Z RS(   t   n_confst   sitest
   atom_namesR™   t   u_isost   u_starst   max_rmsdt   max_distance_over_ut	   dxyz_savet
   u_iso_savet   atom_name_savec         C   sæ  d d l  m } d d l m } d d l m } g  |  _ g  |  _ g  |  _ g  |  _	 | j
 ƒ  |  _
 | j ƒ  } i  } xÏ | j ƒ  D]Á }	 |	 j ƒ  j ƒ  }
 t |
 ƒ d k rØ |
 j |
 d ƒ rØ t d |	 j
 ƒ  ƒ ‚ n  xh |	 j ƒ  D]Z } | j j ƒ  d k r| rqå n  | j | k r+g  | | j <n  | | j j | ƒ qå Wq‚ Wd |  _ xÜt | j ƒ  ƒ D]È} t | | ƒ } | d k rc|  j d k rÏ|  j | k r+t d
 d |  j
 | | |  j f ƒ ‚ q+n\ | |  _ xP t | ƒ D]B } |  j j | j ƒ  ƒ |  j j | j ƒ  ƒ |  j j g  ƒ qåW|  j	 j | ƒ xí t | ƒ D]Ü } | | | } | j ƒ  | j } | j | j
 ƒ  k sŠt ‚ |  j | j | j  ƒ | j! j" ƒ  rê|  j | j | j# | j$ ƒ ƒ |  j | j | j% ƒ qH|  j | j | j& ƒ |  j | j | j' | | j& ƒ ƒ qHWqcqcWd |  _( d |  _) d  |  _+ |  _, |  _- x‡t. |  j ƒ D]v\ } } | |  j d k  rhxTt | d |  j ƒ D]9} |  j | } | j/ | ƒ } | |  j( k rÛ| |  _( n  xù t. t0 | | ƒ ƒ D]â \ } \ } } t1 | | ƒ | | ƒ ƒ } | j2 d |  j | | d |  j | | d | d | d | ƒ } t3 | j4 ƒ  | j5 ƒ  ƒ } | d k rŒqñn  | | } | |  j) k rñ| |  _) | |  _+ | |  _, |  j	 | |  _- qñqñWqžWqhqhWd  S(   Niÿÿÿÿ(   t   adptbx(   R	   (   R   i   i    s+   B-factors for atom_group '%s' are identicalRW   R€   s*   Inconsistent conformers for '%s': atom %s s6   has %d confs but previously %d conformations were seent   ustar1t   ustar2Rt   Ru   t	   unit_cell(   RW   R€   (6   t   cctbxR4  R   R	   R!   R   R+  R-  R.  R,  R™   R7  R   R   t	   extract_bR   R   t   RuntimeErrorRa   R   R$   R'   R*  t   sortedt   keyst   rangeR�   t   doubleR½   t   i_seqt   labelR   R%   t   flagst   use_u_anisot   b_as_ut   bt   u_start   u_isot   u_iso_as_u_starR/  R0  R#   R1  R2  R3  RŠ   t   rms_differenceR`   R&   t   projection_sumR:   t   z_12t   z_21(   t   selfR   R¼   R  R4  R	   R   R7  t   atom_name_dictR‹   t   b_isosR4   Rx   t   n_atom_confst   nt   i_conft	   scattererR+  t   j_conft
   sites_nextR^   t   k_siteRt   Ru   Rv   t   proj_sumt   u_projt   ratio(    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/building/alternate_conformations/__init__.pyt   __init__ë  s”    				%	"	 !		(		
			R
   c      
   C   s†   | d k r d | } n  |  j  d  k	 rd | | d |  j |  j |  j  |  j t |  j ƒ | f IJn | | d |  j |  j f IJd  S(   NR
   t    s2   %s: rmsd=%-5.3f  atom '%s': dxyz=%-6.3f u=%-6.3f%ss   %s: rmsd=%-5.3f(   R3  R#   R™   R/  R1  R   R2  (   RL  Rþ   R  t   suffix(    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/building/alternate_conformations/__init__.pyt   show_distance_info:  s     (   R8   t
   __module__t	   __slots__Rƒ   RY  Rj   t   stdoutR\  (    (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/building/alternate_conformations/__init__.pyR)  å  s
   	Oc   $   
   C   s�  d d l  m } d d l m } d d l m }	 |  j ƒ  |  j ƒ  j ƒ  |  j	 d | ƒ }
 | d k rq d } n  d } x­|  j ƒ  j ƒ  D]™} | j ƒ  } t | ƒ } d } g  } xÖt | ƒ D]È\ } } | j ƒ  } | j ƒ  } t | ƒ } | d k rÁ t d | d	 |
 ƒ } t g  ƒ } x¼ t | ƒ D]® \ } } g  } x< | j ƒ  D]. } | j j ƒ  d k rJ| j | j ƒ qJqJWt | ƒ d k r”q+n  t | ƒ | j k  r+| d | | j t | ƒ f IJ| j | ƒ q+q+W| j | k  sþ| j | j k  r9| j d | d d d d ƒ | j  t t! d | ƒ ƒ ƒ n | rX| j d | d d ƒ n  t" } t | ƒ d k r‰| j | | f ƒ q‰qÁ qÁ Wx“t | ƒ D]…\ } \ } } | | } | j ƒ  } t | ƒ } t | ƒ | d k  rS| d } | } x\ | t | ƒ k  rO| | \ }  }! |  | d k rAt |! ƒ j# | ƒ } n P| d 7} q÷Wn  t | ƒ d k r±| d 7} x? t | ƒ D]. \ } } | | k r|| j$ | ƒ t% } q|q|Wn  | rš| j ƒ  } xY | D]N } x' | j ƒ  D] } d t | ƒ | _ qÝWt | ƒ d k rÊd | _ qÊqÊWqšqšWqŠ W| d k r9| sE| t% k r‰|  j ƒ  }" |" j& ƒ  } | d k  }# | j' |# d ƒ |" j( | ƒ n  | S(   sô  
  Identifies residues which have been erroneously given alternate confomations
  which are actually identical - this is an expected side effect of the
  assembly process, but we want to keep the number of new atoms as limited as
  possible.  The filtering criteria are 1) the overall RMSD of all conformers
  of each residue to each other, and 2) the maximum ratio (over all non-H
  atoms) of the distance between conformations over u_iso (which in theory
  represents displacement in Angstroms).
  iÿÿÿÿ(   R4  (   R	   (   R   t   crystal_symmetryi    i   R   R¼   RW   R€   s#     %s: altloc '%s' occupancy = %4.2fRþ   R  s     R[  s   !!!g      ð?R
   g      à?N(   RW   R€   ()   R8  R4  R   R	   R!   R   t	   remove_hdR   R¨   t   extract_xray_structureR#   R   R   R   R   RŠ   R™   R   R)  t   setRa   R   R'   Rš   R:   t   min_occupancyR   t   addR/  R0  t   min_distance_over_uR\  t   updateR=  R‚   t   intersectiont   remove_atom_groupRƒ   t   extract_occR¿   t   set_occ($   R   Rõ   R`  t   model_error_mlt   reset_occupanciesR¦   R¤   R4  R	   R   R¼   t
   n_modifiedR   R   t   n_rest   last_nconfst   pending_deletionst   i_rgR   t
   residue_idR   R*  t   infot   delete_groupst   i_groupR‹   Rš   R4   t   reset_residueR*   t   kkt	   i_rg_lastt   j_rgt   delete_othersR   t   partial_occupancy_selection(    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/building/alternate_conformations/__init__.pyt   rejoin_split_single_conformersD  s˜    
				



sM   
set_b_iso = Auto
  .type = float
convert_to_isotropic = True
  .type = bool
c         C   s‡  d d l  m } d d l m } |  j ƒ  } | d k rS | j | j ƒ  t ƒ } n- t	 | t
 ƒ r€ |  j ƒ  } | j | ƒ } n  xZ t | ƒ D]L \ }	 }
 |
 j ƒ  d k	 s± t ‚ d |
 _ | j ƒ  |	 } |
 j ƒ  | _ q� W| rü | j d | j ƒ  ƒ n  | d k	 rX| t k r?| j ƒ  } | j | j | ƒ ƒ d } n  | j d | d | ƒ n  |  j | ƒ | j ƒ  | j ƒ  | j ƒ  d S(	   sR   
  Prepare a rebuilt model for refinement, optionally including B-factor reset.
  iÿÿÿÿ(   R4  (   R	   R
   R   i   t   valueN(   R8  R4  R   R	   R   R#   R6   R  Rƒ   R¬   R­   Rª   R   RŠ   Rb   R   Rœ   R½   R™   R@  t   convert_to_isotropicR9   R   t   extract_u_iso_or_u_equivt   u_as_bt   meant	   set_b_isot   adopt_xray_structuret   reset_serialR¨   R©   (   R   R¼   Rƒ  R  R   R4  R	   R¯   t	   sel_cacheR?  R4   t   scRF  (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/building/alternate_conformations/__init__.pyt   finalize_model±  s0    	

t   refined_fragmentc           B   s,   e  Z d  d d d g Z e j d d „ Z RS(   R@  R   t
   sites_cartR^   R
   c         C   s.   | | d |  j  t |  j ƒ |  j f IJd  S(   Ns    refined %s (%d atoms): rmsd=%.3f(   R@  R   R   R^   (   RL  Rþ   R  (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/building/alternate_conformations/__init__.pyR	  Ô  s    (   R8   R]  R^  Rj   R_  R	  (    (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/building/alternate_conformations/__init__.pyR‰  Ò  s   t   rsr_fragments_basec           B   s    e  Z d  Z d „  Z d „  Z RS(   sz   
  Template for refinement of a collection of non-overlapping model fragments,
  intended to be used in parallel loops.
  c         K   s>   | |  _  | |  _ | |  _ |  j j | ƒ | j ƒ  |  _ d  S(   N(   R   RË   t   processed_pdb_filet   __dict__Rg  R   R¯   (   RL  R   RË   RŒ  t   kwds(    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/building/alternate_conformations/__init__.pyRY  Ý  s
    			c         C   sh   d d l  m } | j d |  j d |  j j d |  j d | d | d |  j j ƒ  j ƒ  d	 t	 ƒ  ƒ } | S(
   Niÿÿÿÿ(   Rú   R   R¼   RŒ  Rä   R   t   d_minRþ   (
   Rã   Rú   t   box_build_refine_baseR   RË   R¼   RŒ  t   f_obsR�  R   (   RL  R   Rä   Rú   t   box(    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/building/alternate_conformations/__init__.pyt   make_boxä  s    			(   R8   R]  t   __doc__RY  R“  (    (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/building/alternate_conformations/__init__.pyR‹  Ø  s   	(   RM   RN   (   RO   RP   (   RM   RQ   (   RO   RR   (   RS   RT   (   RU   RV   g      Ð?(:   t
   __future__R    t   libtbx.str_utilsR   t   libtbx.utilsR   R   R  R   R   R   R   t   libtbx.philt   mathR   Rj   R   R5   R=   RL   t   symmetric_atom_namest   dictt   n1t   n2Re   R   R‰   R�   R’   R“   t   SEGID_NEW_REBUILTRž   R›   t   SELECTION_OLDR«   t   SELECTION_NEW_SPLITt   SELECTION_NEWt   SELECTION_MODIFIEDR#   R‚   R¶   RÙ   RÊ   R  Rø   Rƒ   R_  R(  R  R  t   rejoin_philR)  R}  t   finalize_phil_strRˆ  R‰  t   objectR‹  (    (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/building/alternate_conformations/__init__.pyt   <module>   s|   "	&			)	6		B*	\		bd