ó
º™xTc           @   s  d  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 m Z m Z m Z m Z m Z d d l 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 m Z d d l Z d d l  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* Z* d d l+ Z+ d d l, m- Z- d d l. m/ Z/ d d l0 m1 Z1 d d l m Z d d l2 j3 j4 Z5 d d l6 Z d d l7 Z d d l8 Z d d l m9 Z9 d d l: Z d d l m; Z; d d l< Z< d d l= Z$ d d l> m? Z? m@ Z@ d d l mA ZA d d l mB ZB d d  l mC ZC d d! lD mE ZE d d lF ZG eG jH jI d" ƒ ZJ d d# lK Td d lF ZG d d$ l m3 Z3 eG jH jI d% ƒ ZL d& „  ZM d' „  ZN d( ZO d) ZP d* eO eP e jQ f ZR d+ eR ZS d, eR ZT eU d- „ ZV d. eW f d/ „  ƒ  YZX d0 ZY d1 ZZ e j[ j\ d2 eZ ƒ Z] e^ d3 „ Z_ e j[ j\ d4 ƒ Z` d5 „  Za eU e^ eb eb eb eb eU d6 „ Zc eb d7 „ Zd eU e^ eU e^ eU eb d8 „ Ze d9 „  Zf e* jg e^ d: „ Zh eU d; „ Zi eb d< „ Zj e j[ j\ d= ƒ Zk d> eW f d? „  ƒ  YZl d@ „  Zm dA „  Zn eU e^ e^ e^ e^ e^ dB dC „ Zo dD „  Zp dE „  Zq dF „  Zr dG eW f dH „  ƒ  YZs eU eU dI „ Zt eU eU eU eU eb dJ eU eU eU eb eU eU eU eU e ju jv jw ƒ  eU eU eU dK „ Zx eU dJ e^ eU eU eU eb dL e^ e^ e^ eU dM „ Zy dN eW f dO „  ƒ  YZz dP eW f dQ „  ƒ  YZ{ eU e^ g  eU dR eU eU eU dS „ Z| dT „  Z} dU eW f dV „  ƒ  YZ~ dW eW f dX „  ƒ  YZ eU dY „ Z€ eU dZ „ Z� d[ „  Z‚ d\ „  Zƒ d] „  Z„ d^ „  Z… d_ „  Z† d` „  Z‡ da db e^ dc „ Zˆ eU eU eU e^ dd „ Z‰ de eW f df „  ƒ  YZŠ dg eW f dh „  ƒ  YZ‹ di eW f dj „  ƒ  YZŒ dk eW f dl „  ƒ  YZ� dm eW f dn „  ƒ  YZŽ do dp „ Z� db dq dr „ Z� ds eW f dt „  ƒ  YZ‘ du eW f dv „  ƒ  YZ’ d S(w   s%  
Library of convenience functions for working with models and reflection data.
This contains a number of routines used in phenix.refine and related programs,
mainly concerned with the repetitive process of loading model and data files
and initializing the appropriate objects.  Note that if you are writing a
program that uses similar inputs, it may be significantly easier to use the
unified input handling encapsulated in :py:mod:`mmtbx.command_line`, which
wraps much of the functionality in :py:mod:`mmtbx.utils` while hiding the
messy details.
iÿÿÿÿ(   t   division(   t   twin_analyses(   t   miller(   t   crystal(   t   sgtbxN(   t   flex(   t   Sorryt   date_and_timet   host_and_usert	   multi_outt   null_out(   t   reflection_file_reader(   t   reflection_file_utils(   t   crystal_symmetry_from_any(   t   xray_structure(   t   pdb(   t   StringIO(   t   adptbx(   t   monomer_library(   t   combine_unique_pdb_files(   t   mtz(   t   cif(   t	   str_utils(   t   show_string(   t   adopt_init_args(   t   approx_equal(   t   print_statistics(   t   twin_f_model(   t   outlier_rejection(   t   french_wilson(   t   ifloort   iceil(   t   maptbx(   t   uctbx(   t   xray(   t    crystal_symmetry_as_cns_commentst   mmtbx_utils_ext(   t   *(   t   bulk_solventt   mmtbx_f_model_extc         C   s|   |  j  d | ƒ j d | ƒ } | d  k	 rx | d k re | d d IJ| d I| IJ| d d IJqx t | d ƒ ‚ n  d  S(   Nt   working_point_groupt   data_descriptiont   warningR%   iO   s   WARNING:så  
  The program inspects all inputs to determine the working crystal
  symmetry (unit cell & space group).
  Please check the working crystal symmetry shown above. If it is
  not correct, use the --unit_cell, --space_group, or --symmetry
  option to specify the correct unit cell parameters and space group
  symbol.
  If the working crystal symmetry is in fact correct, disable this
  error by adding
    refinement.input.symmetry_safety_check=warning
  to the command line arguments.
(   t6   crystal_symmetry_is_compatible_with_symmetry_from_filet   format_error_messaget   NoneR   (   t   miller_arrayR)   R(   t   symmetry_safety_checkt   logt   msg(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt"   miller_array_symmetry_safety_checkC   s    		c         C   s&   d } d } |  | | d | IJd  S(   Ns+  If previously used R-free flags are available run this command again
with the name of the file containing the original flags as an
additional input. If the structure was never refined before, or if the
original R-free flags are unrecoverable, run this command again with
the additional definition:

s›   

If the structure was refined previously using different R-free flags,
the values for R-free will become meaningful only after many cycles of
refinement.
s   .generate=True(    (   R0   t   flags_parameter_scopet   part1t   part3(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt-   explain_how_to_generate_array_of_r_free_flags^   s    sü    file_name = None
    .type=path
    .short_caption=Reflections file
    .style = bold input_file file_type:hkl noauto process_hkl       child:fobs:labels child:d_min:high_resolution       child:d_max:low_resolution child:rfree_file:r_free_flags.file_name
    .expert_level = 0
  labels = None
    .type=strings
    .input_size = 160
    .short_caption = Data labels
    .style = bold renderer:draw_fobs_label_widget noauto       OnChange:auto_update_label_choice child:d_min:high_resolution       child:d_max:low_resolution parent:file_name:file_name
    .expert_level = 0
  high_resolution = None
    .type=float
    .input_size = 80
    .style = bold renderer:draw_resolution_widget noauto
    .expert_level = 0
  low_resolution = None
    .type=float
    .input_size = 80
    .style = bold renderer:draw_resolution_widget noauto
    .expert_level = 0
  outliers_rejection = True
    .type=bool
    .short_caption = Reject outliers
    .help = Remove "basic wilson outliers", "extreme wilson outliers", and               "beamstop shadow outliers"
    .expert_level = 0
  french_wilson_scale = True
    .type=bool
    .short_caption = use French-Wilson method to handle negative intensities
  french_wilson
  {
     include scope cctbx.french_wilson.master_phil
  }
  sigma_fobs_rejection_criterion = None
    .type=float
    .short_caption = Sigma(Fobs) rejection criterion
    .expert_level = 0
  sigma_iobs_rejection_criterion = None
    .type=float
    .short_caption = Sigma(Iobs) rejection criterion
    .expert_level = 0
sx    file_name = None
    .type=path
    .short_caption=File with R(free) flags
    .help = This is normally the same as the file containing Fobs and is       usually selected automatically.
    .input_size = 200
    .style = noauto input_file file_type:hkl process_hkl child:rfree:label
    .expert_level = 0
  label = None
    .type=str
    .short_caption = R-free label
    .input_size = 160
    .style = bold renderer:draw_rfree_label_widget noauto              OnChange:update_rfree_flag_value
    .expert_level = 0
  test_flag_value = None
    .type=int
    .help = This value is usually selected automatically - do not change       unless you really know what you're doing!
    .style = noauto
    .expert_level = 0
  ignore_r_free_flags = False
    .type=bool
    .short_caption = Ignore R-free flags
    .help = Use all reflections in refinement (work and test)
    .expert_level=0
sÉ    %s
  ignore_all_zeros = True
    .type=bool
    .short_caption = Ignore all-zero arrays
    .expert_level = 1
  force_anomalous_flag_to_be_equal_to = None
    .type=bool
    .short_caption = Use anomalous data
    .style = tribool
    .expert_level = 1
  convert_to_non_anomalous_if_ratio_pairs_lone_less_than_threshold=0.5
    .type = float
    .expert_level = 2
  r_free_flags
    .expert_level=0
    .style = box auto_align
    .caption = This information will be extracted automatically if possible.       If no test set is present in the reflections file, one can be generated       automatically, or you can use the reflection file editor to combine an       existing set with your X-ray or neutron data.
  {
    %s
    disable_suitability_test = False
      .type=bool
      .expert_level = 2
    ignore_pdb_hexdigest = False
      .type=bool
      .short_caption = Ignore PDB hexdigest sanity check
      .help=If True, disables safety check based on MD5 hexdigests stored in             PDB files produced by previous runs.
      .expert_level=2
    generate = False
      .type=bool
      .short_caption = Generate new R-free flags
      .help = Generate R-free flags (if not available in input files)
    %s
  }
s_   xray_data
  .help=Scope of X-ray data and free-R flags
  .style = scrolled auto_align
{
  %s
}
sù   neutron_data
  .help=Scope of neutron data and neutron free-R flags
  .style = scrolled auto_align
{
  ignore_xn_free_r_mismatch = False
    .type = bool
    .expert_level=2
    .short_caption = Ignore Xray/neutron R-free flags set mismatch
  %s
}

c         C   sL   |  d  k	 r2 d } t j j | |  t f d t ƒSt j j t d t ƒSd  S(   Ns
   %s
{
%s
}
t   process_includes(   R-   t   iotbxt   philt   parset   data_and_flags_strt   True(   t   master_scope_namet   p(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt   data_and_flags_master_paramsþ   s     t   determine_data_and_flagsc           B   s€   e  Z d  Z d d d d d d d e e d d e d „ Z d „  Z d „  Z d d „ Z	 d „  Z
 d „  Z d	 d
 „ Z d „  Z RS(   s}  
  Encapsulates logic for extracting experimental amplitudes and R-free flags
  from the given input file(s).  This expects that the standard parameter block
  is being used.  Determination of appropriate data labels will be as automatic
  as possible, or will give clear feedback when ambiguity exists.  If not
  found in the inputs, the R-free flags can be created if desired.
  t    c         C   sA  t  |  t ƒ  ƒ |  j d  k r4 t ƒ  j ƒ  |  _ n  t |  _ d  |  _ d  |  _	 d  |  _
 d  |  _ | d  k	 rƒ t j | d | ƒn  |  j ƒ  |  _ |  j j ƒ  } |  j d |  j ƒ |  _ |  j j | ƒ |	 r|  j d |  j ƒ |  _ |  j d  k	 r|  j j ƒ  } qn  |	 r=|  j d  k	 r=|  j ƒ  |  j	 j | ƒ n  d  S(   Nt   outt   f_obst   data(   R   t   localst
   parametersR-   R?   t   extractt   Falset   intensity_flagRC   t   r_free_flagst   test_flag_valuet   r_free_flags_md5_hexdigestR   t   make_headert   extract_datat   raw_datat   infot   data_as_f_obst   set_infot   extract_flagst	   raw_flagst   get_r_free_flags(   t   selft   reflection_file_serverRF   t   data_parameter_scopeR3   R)   R(   R/   t!   remark_r_free_flags_md5_hexdigestt   extract_r_free_flagst
   keep_goingR0   t   prefer_anomaloust   force_non_anomaloust	   data_infot
   flags_info(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt   __init__  s*    					
c         C   sM   |  j  d |  j d |  j ƒ \ |  _ |  _ |  _ |  j j |  j j ƒ  ƒ d  S(   NRC   RJ   (   t   flags_as_r_free_flagsRC   RT   RJ   RK   RL   RR   RP   (   RV   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyRU   5  s    c         C   s  |  j  j d |  j j d |  j j d |  j j d |  j d |  j ƒ } | j ƒ  j	 |  j _ | j ƒ  j
 ƒ  g |  j _ | j ƒ  rš |  j d IJt |  _ n |  j d IJ|  j d I| j ƒ  IJ|  j |  j |  j g j d  ƒ d	 k r"t d
 | d |  j d |  j d |  j d |  j ƒ |  j Jn  | j ƒ  } | j d |  j ƒ } | | k	 rd| j d t ƒ } n  | j ƒ  sæ| j ƒ  rŒ|  j d IJn |  j d IJ| j ƒ  } | j d |  j d d ƒ |  j J| j ƒ  } | j d t ƒ } n  |  j rþ| j ƒ  } n  | j | ƒ S(   Nt	   file_namet   labelst   ignore_all_zerost   parameter_scopeR\   s   I-obs:s   F-obs:t    i    R.   R)   R(   R/   R0   t   systematic_absences_eliminateds(   Merging symmetry-equivalent intensities:s'   Merging symmetry-equivalent amplitudes:RB   t   prefixs     t   merged(   RW   t   get_xray_dataRF   Rb   Rc   Rd   RX   R\   RP   t   sourcet   label_stringt   is_xray_intensity_arrayR0   R<   RI   R)   R(   R/   t   countR-   R2   t   eliminate_sys_absentt   customized_copyt   is_unique_set_under_symmetryt   merge_equivalentst   show_summaryt   arrayR]   t   average_bijvoet_matesRR   (   RV   RD   RP   t	   processedRi   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyRN   ;  sL    				

	s   R-free flagsc         C   sâ  d+ \ } } |  j j } |  j j j sºyF |  j j d | j d | j d | j d | j	 d |  j
 ƒ \ } } Wnl t j k
 rÛ } |  j j j d  k	 rÌ t d |  j d |  j
 ƒ |  j r½ d  St d ƒ ‚ n  d, \ } } qºX| j ƒ  j | _ | j ƒ  j ƒ  | _ | | _ |  j | d	 IJ|  j d
 I| j ƒ  IJ|  j |  j g j d  ƒ d k r�t d | d | d |  j d |  j d |  j ƒ |  j Jn  | j ƒ  } | j d |  j ƒ } | | k	 rÑ| j d t ƒ } n  | j ƒ  s�|  j d Iy | j ƒ  }	 Wn[ t k
 rW} |  j Jt | ƒ }
 d } |
 j | ƒ s:t  ‚ t d |
 t! | ƒ ƒ ‚ n X|  j d IJ|  j J|	 j" ƒ  } | j d t ƒ } ~	 n  |  j# r¨| j$ ƒ  } n  | j% | ƒ } n  | d  k r¿| j& d  k só| j' d  k só| j( d  k rt d d ƒ ‚ n  |  j d IJ|  j Jt) j* d d d d d d d d  d! ƒ | j+ d" | j& d# | j, d$ | j' d% | j( d& | j- d' | j. ƒ j% t/ j0 d( d) g ƒ ƒ } | j ƒ  j ƒ  | _ d* | _ n  | d  k	 rÞ| j1 ƒ  j2 ƒ  n  | S(-   NRb   t   labelRK   t   disable_suitability_testRe   R0   R3   s   Please try again.t   :Rf   i    R.   R)   R(   R/   Rg   s:   Checking symmetry-equivalent R-free flags for consistency:s&   cctbx Error: merge_equivalents_exact: s1   Incompatible symmetry-equivalent R-free flags: %st   OKRi   s/   No R-free flags are available, but one or more s7   parameters required to generate new flags is undefined.s'   Generating a new array of R-free flags.t   messaget   warnRD   s:   PHENIX will generate a new array of R-free flags.  Please s>   check to make sure that the input data do not already contain sA   an R-free set; if one is present, you should cancel this job and sA   disable generation of new flags.  If the program you are running s@   outputs an MTZ file, you should be sure to use that file in all s   future refinements.t   fractiont   max_freet   lattice_symmetry_max_deltat   use_lattice_symmetryt   use_dataman_shellst   n_shellsRc   s   R-free-flagsi   (   NN(   NN(3   R-   RF   RJ   t   generateRW   RU   Rb   Rw   RK   Rx   R3   R   t#   Sorry_No_array_of_the_required_typeR6   R0   R[   R   RP   Rk   Rl   R(   R/   Rn   R2   Ro   Rp   R<   Rq   Rr   t   RuntimeErrort   strt
   startswitht   AssertionErrort   lenRt   R]   Ru   RR   R}   R   R€   t   libtbxt	   call_backt   generate_r_free_flagsR~   R�   R‚   R   t
   array_infot	   deep_copyt   as_non_anomalous_array(   RV   RD   R)   RJ   RK   t   paramst   eRP   Rv   Ri   t   error_messaget   expected_error_message(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyRS   e  s     				
	 			

							c      	   C   s�  | j  ƒ  sB | j d | j ƒ  d | j ƒ  d d$ ƒ j | ƒ } n  | j ƒ  d% k } | j t ƒ d k r‰ |  j d IJ| j	 | ƒ } n  | j
 ƒ  } | d k  r´ t d | ƒ ‚ n  | j d |  j ƒ | j ƒ  j ƒ  } |  j J| j ƒ  rû t | ƒ } n  d$ } | j ƒ  rå|  j j rdt j d	 | d
 |  j j d |  j j d |  j ƒ } | d$ k	 rd| } qdn  |  j j s}| d$ k rÎ|  j d | d |  j j d d ƒ } | d$ k	 r¿| j	 | ƒ } n  | j ƒ  } n  |  j d IJ|  j Jn  | j ƒ  } | d$ k	 r`| d k } | | j ƒ  d k M} | j t ƒ }	 |	 d k r`|  j d |	 IJ| j	 | ƒ } q`n  | j ƒ  | j ƒ  } | j ƒ  } |  j j d$ k	 r¹| | j ƒ  j ƒ  |  j j k M} n  |  j j d$ k	 rð| | j ƒ  j ƒ  |  j j k M} n  | j ƒ  d k }
 |  j d I| j t ƒ IJ|  j d I|
 j t ƒ IJ| j ƒ  d k } |  j d I| j t ƒ IJ| |
 M} |  j d | d |  j j d d ƒ } | d$ k	 r¯| | M} n  | | j  ƒ  j ƒ  d k M} | j	 | ƒ } | j! ƒ  } |  j d | d IJ|  j d | d IJ|  j J| j ƒ  j ƒ  d k r>t d ƒ ‚ n  |  j j" d$ k	 r*|  j j" sÒ|  j d IJ| j# ƒ  r'|  j d IJ| j$ ƒ  j% ƒ  } | j& d |  j d d ƒ | j' ƒ  j | ƒ } ~ |  j Jq'qB| j# ƒ  sB|  j d  IJ|  j d! IJ| j( ƒ  } | j) ƒ  } | j | ƒ |  j JqBn | j* d" |  j j+ ƒ } | | j ƒ  j ƒ  k r}|  j d# IJ| j d |  j ƒ n  | S(&   s  
    Convert input data array to amplitudes, adjusting the data type and
    applying additional filters if necessary.

    :param f_obs: selected input data
    :returns: :py:class:`cctbx.miller.array` of real numbers with observation
      type set to amplitudes
    t   indicesRD   t   sigmasi    s   F(0,0,0) will be removed.g      Ð?s(   Resolution of data is too high: %-6.4f At   fR.   R�   t   sigma_iobs_rejection_criterionR0   RC   t   nR{   s9   Number of reflections with |Iobs|/sigma(Iobs) < %5.2f: %ds:   Intensities converted to amplitudes for use in refinement.s>   Number of pairs (Fobs,sigma)=(0,0) is %s. They will be removeds6   Number of F-obs in resolution range:                  s7   Number of F-obs<0 (these reflections will be rejected):sA   Number of F-obs=0 (these reflections will be used in refinement):s9   Number of reflections with |Fobs|/sigma(Fobs) < %5.2f: %ds*   Refinement resolution range: d_max = %8.4fs*                                d_min = %8.4fi   s?   No data left after applying resolution limits and sigma cutoff.s)   force_anomalous_flag_to_be_equal_to=Falses%   Reducing data to non-anomalous array.RB   Rh   s     s(   force_anomalous_flag_to_be_equal_to=Trues'   Generating Bijvoet mates of X-ray data.t	   thresholds,   
Fobs statistics after all cutoffs applied:
N(   i    i    i    (,   t   sigmas_are_sensibleRp   R”   RD   R-   t   set_observation_typeRn   R<   R0   t   selectt   d_minR   t   show_comprehensive_summaryt   sizet   is_complex_arrayt   absRm   RF   t   french_wilson_scaleR   R—   t   _apply_sigma_cutofft	   f_sq_as_fR•   RH   t#   set_observation_type_xray_amplitudet
   map_to_asut   all_selectiont   low_resolutiont
   d_spacingst   high_resolutiont   sigma_fobs_rejection_criteriont	   d_star_sqt   resolution_ranget#   force_anomalous_flag_to_be_equal_tot   anomalous_flagR�   Rr   Rs   Rt   t   observation_typet   generate_bijvoet_matest6   convert_to_non_anomalous_if_ratio_pairs_lone_less_thant@   convert_to_non_anomalous_if_ratio_pairs_lone_less_than_threshold(   RV   RC   t   selR�   t   f_obs_data_sizet   f_obs_fwt   selection_by_isigmaR•   t	   selectiont   n_both_zerot   selection_positivet   selection_zerot   selection_by_fsigmat   rrRi   R°   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyRQ   ¾  sÒ    		 			

%%
		 	c         C   s‚   d  } | j ƒ  d  k	 r~ | } | d  k	 r~ | d k r~ | j ƒ  | j ƒ  | k } |  j | | | j t ƒ f IJ| } q~ n  | S(   Ni    (   R-   R•   RD   R0   Rn   RH   (   RV   RC   R˜   R{   R¸   t   sigma_cutofft   selection_by_sigma(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyR£   6  s    i
   c         C   s¹  |  j  j j } | d  k rC t d d d d |  j  j j ƒ ‚ n  | j d |  j ƒ |  j J|  j d I| IJ|  j Jt | j	 ƒ  t
 j ƒ r¶ | j d | j	 ƒ  t | ƒ k ƒ } n | j d | j	 ƒ  | k ƒ } | j ƒ  j d d	 ƒ j	 ƒ  j ƒ  j ƒ  } |  j d  k	 r8|  j d
 |  j  j j d | d |  j ƒ n  | j ƒ  sv| j ƒ  r¥|  j d IJ| j ƒ  } |  j Jq¥n/ | j ƒ  s¥|  j d IJ| j ƒ  } |  j Jn  | j ƒ  j | ƒ } | j ƒ  j ƒ  | j ƒ  j ƒ  } | d k r“d | g } | d  k	 r | d k r | d c d 7<n[| d c d 7<| j d | ƒ } | d  k rWd }	 n9 | j ƒ  j ƒ  | }	 |	 | d k rŠ| |  } n d }	 | j ƒ  d  k r÷| j d ƒ x© t | j ƒ  | j	 ƒ  ƒ D]% \ }
 } | j d |
 d | ƒ qËWnd | j d ƒ xT t | j ƒ  | j	 ƒ  | j ƒ  ƒ D]. \ }
 } } | j d |
 d | | f ƒ q)W|	 d k r{| j d |	 ƒ n  t d j | ƒ ƒ ‚ n  | j d |  j d d ƒ | | | f S(   Ns4   PHENIX could not determine an appropriate test flag sB   for the data with label(s) '%s'.  This may happen if they are all sA   a single value; please check the file to make sure the flags are s   suitable for use.R–   s   Test (R-free flags) flag value:RD   t   by_valuet   packed_indicest   ignore_pdb_hexdigestt   currentt   recordss-   Reducing R-free flags to non-anomalous array.s)   Generating Bijvoet mates of R-free flags.i    s_   R-free flags not compatible with F-obs array: missing flag for %d F-obs selected for refinementt   .Ry   t   otherg      à?s       h   k   l   datas     %3d %3d %3ds      %.6gs       h   k   l   data  sigmass      %.6g  %.6gs        ... (remaining %d not shown)s   
RB   Rh   RA   (    RF   RJ   RK   R-   R   Rw   Rž   R0   t
   isinstanceRD   R   t   boolRt   R¦   t   sortt   md5t	   hexdigestRY   t!   verify_r_free_flags_md5_hexdigestRÂ   R¯   Ru   R±   t
   common_setR”   RŸ   t   lone_setR•   t   appendt   zipt   joint   show_r_free_flags_info(   RV   RC   RJ   t   missing_show_max_linesRK   RL   t   n_missing_r_free_flagsR1   t   lonet   n_not_shownt   hklR–   t   s(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyRa   A  sr    		*	

	( 4#c   	      C   s¿  t  ƒ  } x@ | D]8 } | j ƒ  } t | ƒ d k r | j | d ƒ q q Wt | ƒ d k rm t d ƒ ‚ n  t | ƒ d k r»| | k r»|  j } x" t d ƒ D] } | d d IJq¡ W| rà | J| d j d g d	 ƒ IJn  | d
 | t | ƒ d f I| s| d t | ƒ d In  | d IJ| s<| d IJn
 | d IJx" t d ƒ D] } | d d IJqSW| J| s»d t	 j
 k r©| j ƒ  t d d d d ƒ ‚ q¸t d ƒ ‚ q»n  d  S(   Ni   i   i   s[   Multiple conflicting REMARK r_free_flags.md5.hexdigest records found in the input PDB file.R%   iO   Rf   t   WARNINGi	   sY  
The MD5 checksum for the R-free flags array summarized above is:
  %s

The corresponding MD5 checksum in the PDB file summarized above is:
  %s

These checksums should be identical but are in fact different. This is
because the R-free flags used at previous stages of refinement are
different from the R-free flags summarized above. As a consequence,
the values for R-free could be biased and misleading.

However, there is no problem if the R-free flags were just extended to
a higher resolution, or if some reflections with no data or that are
not part of the R-free set have been added or removed.i    s‡   In this case,
simply remove the

  REMARK r_free_flags.md5.hexdigest %s

record from the input PDB file to proceed with the refinement.sì   

Otherwise it is best to recover the previously used R-free flags
and use them consistently throughout the refinement of the model.
Run this command again with the name of the file containing the
original flags as an additional input.
s½   If the original R-free flags are unrecoverable, remove the REMARK
record as indicated above. In this case the values for R-free will
become meaningful only after many cycles of refinement.
sƒ   If the original R-free flags are unrecoverable, the values for R-free
will become meaningful only after many cycles of refinement.
t   PHENIX_GUI_ENVIRONMENTs3   This model appears to have previously been refined s=   against a different set of R-free flags.  Please resolve the s@   mismatch; additional information and instructions are available s   at the end of the log output.s)   Please resolve the R-free flags mismatch.(   t   sett   splitR‰   t   addR   R0   t   xrangeRÑ   t   sortedt   ost   environt   flush(	   RV   RÂ   RÃ   RÄ   t	   from_filet   recordt   fldsR0   t   i(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyRÌ   ‰  sN    		 	 
N(   t   __name__t
   __module__t   __doc__R-   R<   RH   R`   RU   RN   RS   RQ   R£   Ra   RÌ   (    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyR@   
  s(   		*Y	x	Esi     file_name=None
    .type=path
    .short_caption=Map coefficients file
  labels=None
    .type=strings
s!    file_name=None
    .type=path
    .short_caption=Experimental phase file
    .style = bold input_file file_type:hkl process_hkl child:hl_coeffs:labels
  labels=None
    .type=strings
    .input_size = 160
    .short_caption = Phase labels
    .style = renderer:draw_hl_label_widget bold
t   input_stringc         C   sk  y. |  j  d | j d | j d | d | ƒ } Wn t j k
 rJ d } nX| j ƒ  j | _ | j ƒ  j ƒ  g | _ | d IJ| d I| j ƒ  IJt	 d | d d	 d
 | d | d | ƒ | J| j ƒ  } | j
 d | ƒ }	 |	 | k	 rý | j d t ƒ } n  |	 j ƒ  sZ| d IJ|	 j ƒ  }
 |
 j d | d d ƒ | J|
 j ƒ  }	 | j d t ƒ } n  |	 j | ƒ Sd S(   sb   
  Extract experimental phases from the given inputs if possible.  Returns None
  if not found.
  Rb   Rc   Rd   Re   s   Experimental phases:Rf   R.   R)   s   Experimental phasesR(   R/   R0   Rg   s=   Merging symmetry-equivalent Hendrickson-Lattman coefficients:RB   Rh   s     Ri   N(   t   get_experimental_phasesRb   Rc   R   R„   R-   RP   Rk   Rl   R2   Ro   Rp   R<   Rq   Rr   Rs   Rt   RR   (   RW   RF   R0   Re   R(   R/   Rd   t   experimental_phasesRP   Rv   Ri   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt   determine_experimental_phasesê  s@    			

sû     file_name=None
    .optional=True
    .type=path
    .help=Model file(s) name (PDB)
    .short_caption=Input model
    .multiple=True
    .input_size=400
    .style = bold input_file file_type:pdb OnChange:extract_pdb_params       file_type_default
c         C   sô   t  |  ƒ t  | ƒ k s t ‚ xÏ t t  |  ƒ d ƒ D]· } |  | } x¤ t | d t  |  ƒ ƒ D]‰ } |  | } t | t j ƒ rµ | | @} | j t ƒ d k rè | | | | f Sq_ | j | ƒ } t  | ƒ d k r_ | | | | f Sq_ Wq5 Wd S(   s7  
  Given a list of atom selections (:py:class:`scitbx.array_family.flex.bool`
  arrays) and corresponding selection strings, inspect the selections to
  determine whether any two arrays overlap.  Returns a tuple of the first pair
  of selection strings found to overlap, or None if all selections are unique.
  i   i    N(
   R‰   Rˆ   t   rangeRÇ   R   RÈ   Rn   R<   t   intersectionR-   (   t
   selectionst   selection_stringst   i_selt
   selection1t   j_selt
   selection2t	   joint_selRï   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt   find_overlapping_selections$  s    
 

c	   &   	      s¥  |  j  }	 | j ƒ  }
 |	 j ƒ  |
 j ƒ  k s3 t ‚ xˆ t |	 |
 ƒ D]w \ } } t | j j ƒ  ƒ d k rC | j ƒ  \ } } t | ƒ d k rº d | j	 ƒ  | _ d | j	 ƒ  | _
 qº qC qC W| rÙ | d  k	 sÙ t ‚ n  ˆ d  k sô t ˆ t ƒ r ˆ g ‰ n t ˆ ƒ d k rd  g ‰ n  ˆ j d  ƒ } t ˆ ƒ } | rK| d k sc| d k rr| d k rrt d ƒ ‚ n  g  } | d k r¼| d k r¼| r¼| j t j |  j  j ƒ  t ƒ ƒ nÉ| r$| d k r$| d k r$| sæt ‚ g  } d  } | rG| j ƒ  j ƒ  } | d k | d k B} | j t ƒ d k rGt d ƒ ‚ qGn  x;|  j j ƒ  D]Æ } x½ | j ƒ  D]¯ } x¦ | j ƒ  D]˜ } g  } x^ | j ƒ  D]P } xG | j ƒ  D]9 } | j } | sÏ| | d k r©| j | j ƒ q©q©Wq–Wt | ƒ d k r}| j t j | ƒ ƒ q}q}WqjWqWWna | d k sC| d k ry| ryx? ˆ D]( } | j t d	 |  d
 | d | ƒ ƒ qJWn t d ƒ ‚ ‡  ‡ f d †  } t | ƒ d k ræt | d t j ƒ sêt j | j ƒ  j ƒ  | d ƒ j ƒ  } n | d j ƒ  j ƒ  } xu t  | d ƒ D]c \ } } | d }  t | t j ƒ sd| t j | j ƒ  j ƒ  | ƒ j ƒ  } q| | j ƒ  } qWt j! | ƒ d k ræt" | ˆ ƒ \ }! }" ˆ  d  k	 rÊt d ˆ  |! |" f ƒ ‚ qãt d |! |" f ƒ ‚ qæn  | r2xC t  | ƒ D]2 \ } }# t# |# d ƒ rù| | j$ ƒ  | | <qùqùWn  | r¡| d }$ x2 | d D]& }% | sf|$ |% B}$ qM|$ j% |% ƒ qMW|$ } | r¡| j& t j' | ƒ ƒ } q¡n  | S(   Ni    s   %2ss   %-2si   s   Ambiguous selection.t   Ht   Ds   No hydrogens to select.t   all_chain_proxiest   stringt   allow_empty_selectionc            s6   t  ˆ |  ƒ } ˆ  d  k	 r* d ˆ  | f Sd | Sd  S(   Ns   for parameter %s (%s)s   (%s)(   R†   R-   (   t   idxt   sele_str(   t   parameter_nameRñ   (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt   selection_infow  s    s0   One or more overlapping selections for %s:
%s
%ss)   One or more overlapping selections:
%s
%st
   iselection(   Rø   Rù   ((   t	   pdb_atomst
   scatterersRŸ   Rˆ   RÐ   R‰   t   elementt   stript   element_and_charge_symbolst   uppert   chargeR-   RÇ   R†   Rn   R   RÏ   R   RÈ   R<   t   extract_scattering_typest   pdb_hierarchyt   modelst   chainst   residue_groupst   atom_groupst   atomst   i_seqt   size_tt   atom_selectiont   as_intRŽ   t	   enumeratet   maxR÷   t   hasattrR  t   extendRœ   t   sort_permutation(&   Rú   R   Rñ   R  t   one_group_per_residueRü   t   hydrogens_onlyt   one_selection_arrayRÿ   R  R  t   atomt   scR‘   t   ct   n_nonet   ss_sizeRð   t   residuest   hd_selectiont
   scat_typest   modelt   chaint   rgt	   rg_i_seqst   agR  t   selection_stringR   t   tmpt   k_t   tmp_st   kt   sel1t   sel2R¸   t   s0RØ   (    (   Rÿ   Rñ   sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt   get_atom_selections:  sž    		*%	(+
+
c         C   sp   |  j  d | d | d  k	 ƒ } | d  k r. d  S| d  k	 rl | rl | j t ƒ rl t d t | ƒ ƒ ‚ ql n  | S(   NRû   t   optionalsB   Selection string results in empty selection (selects no atoms): %s(   R¸   R-   t   all_eqRH   R   R   (   Rú   Rû   Rü   t   result(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyR     s    	c         C   s  | rS | d k	 rS |  j ƒ  } | t j d | ƒ IJ| t j d | j ƒ  ƒ IJn  |  }	 |	 j ƒ  }
 |	 j ƒ  } |	 j ƒ  } | d k	 rÎ | j	 | ƒ } d } |
 j	 | ƒ }
 | j	 | ƒ } | j	 | ƒ } n  |
 j
 ƒ  } |
 j |	 j ƒ  ƒ } |
 j ƒ  } | d k r| j ƒ  } n  x‹ t | ƒ D]} \ } } | | | _ | | | _ t j | | ƒ | _ |
 | j j ƒ  r‚| | | _ n
 | j ƒ  | j d | | ƒ q#W| r³d } n d } | sá| j | j d t d | ƒ ƒ n" | j d t d |  j ƒ  d | ƒ Sd S(   s`   
  Write the specified model to a PDB-format file, incorporating refined atomic
  parameters.
  t   crystal_symmetryt	   unit_cellt   scattering_typei   t
   append_endt   atoms_reset_serial_first_valueN(   R-   R5  R   t   format_cryst1_recordt   format_scale_recordsR6  R  t
   sites_cartt   extract_u_iso_or_u_equivRœ   t   extract_occupanciest   extract_u_cart_plus_u_isoR	  R  R  t   xyzt   occR   t   u_as_bt   bt   flagst   use_u_anisot   uijt	   uij_eraset8   set_element_and_charge_from_scattering_type_if_necessaryt   writet   as_pdb_stringR<   (   R   R
  R  t   write_cryst1_recordR¸   t   atoms_reset_serialRB   t   return_pdb_stringR5  t   xrsR  R<  t   u_isost   occupanciest   u_cartsR#  t   j_seqR  R9  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt   write_pdb_file­  sP    
			c         C   sV   |  Jt  ƒ  j d |  ƒ |  t ƒ  IJ|  J|  d d IJ|  | IJ|  d d IJ|  Jd  S(   NRB   t   -iO   (   R   t   showR   (   R0   t   text(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt   print_programs_start_headerè  s    
c         C   sl   t  ƒ  } d |  k r. | j d d d | ƒ n  t ƒ  } t ƒ  } | j d d d | ƒ | rh | t _ n  | S(   Ns   --quietRw   t   stdoutt   file_objectt
   log_buffer(   R	   t   registerR   t   syst   stderr(   t   argsRB   t   replace_stderrR0   t   string_buffert   string_buffer_plots(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt   set_logò  s    			c         C   s   t  j |  d | ƒd  S(   NRB   (   R   RM   (   t   lineRB   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt   print_headerý  s    c      	   C   s’   t  j j d t  j j ƒ  d t  j j ƒ  d |  d d  ƒ } | j d t ƒ } t d | j	 d | d | g d	 | ƒ } t
 | ƒ d
 k sŠ t ‚ | d S(   Nt   mon_lib_srvt   ener_libRb   R0   Rs   Rú   R   Rñ   R  i   i    (   R   t   pdb_interpretationt   processt   serverRf  R-   R   RH   R1  Rú   R‰   Rˆ   (   t   pdb_file_nameR)  R  t   processed_pdb_fileR   R4  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt   get_atom_selection   s    				sÐ     file_name=None
    .optional=True
    .type=path
    .help=Monomer file(s) name (CIF)
    .multiple=True
    .short_caption=Restraints (CIF)
    .input_size = 400
    .style = bold input_file file_type:cif
t   process_pdb_file_srvc           B   sb   e  Z d d d d d d d d d e e d  „ Z d d e e e d „ Z e e d „ Z d „  Z RS(   c         C   sè   d  |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ |
 |  _	 | d  k rr t
 j j ƒ  |  _ n	 | |  _ |	 d  k r¢ t
 j j d |
 ƒ |  _ n	 |	 |  _ |  j d  k rÉ t j |  _ n  |  j t k rä d  |  _ n  d  S(   Nt   use_neutron_distances(   R-   t   raw_recordsR5  t   pdb_parameterst   pdb_interpretation_paramst   stop_for_unknownst   cif_objectst   cif_parametersR0   Rn  R   Ri  Re  Rf  R\  RX  RH   (   RV   R5  Rp  Rq  Rr  R0   Rs  Rt  Re  Rf  Rn  t   for_dihedral_reference(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyR`     s(    									 		  c         C   se   | | g j  d  ƒ d k s! t ‚ |  j d  k	 r= |  j ƒ  n  |  j d | d | d | d | d | ƒ S(   Ni   t   pdb_file_namesRo  t   stop_if_duplicate_labelsRu  t   allow_missing_symmetry(   Rn   R-   Rˆ   Rs  t   _process_monomer_cif_filest   _process_pdb_file(   RV   Rv  Ro  Rw  Ru  Rx  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt   process_pdb_files9  s    !	c         C   sµ  | d  k rž t d | ƒ } | j d |  j ƒ t | j ƒ d k rR t d ƒ ‚ n  |  j d  k	 r’ g  | j D] } t j	 j
 | ƒ ^ qk |  j _ n  | j } n  | |  _ y( t j j d d  d t j | ƒ ƒ } Wn) t k
 rú }	 t d t |	 ƒ ƒ ‚ n X| j ƒ  j ƒ  d k rkd g }
 | d  k	 rSx( | D] } |
 j d	 t | ƒ ƒ q/Wn  t d
 j |
 ƒ ƒ ‚ n  | rŠ| j ƒ  j ƒ  j ƒ  n  t j j |  j ƒ } |  j  r¸|  j  | d <n  t j j! d |  j" d |  j# d |  j d | d t$ d |  j% d t& d |  j d | d | d | ƒ } | j' d t& ƒ |  j( t$ k r@t& } n t$ } | j) j* d t$ d | ƒ }
 |
 d  k	 r˜|  j( d  k	 r‰|
 d 7}
 n  t |
 ƒ ‚ n  |  j r«|  j Jn  | | f S(   Nt
   file_namesRB   i    s   No coordinate file given.t   source_infot   liness   PDB format error:
%ss)   No atomic coordinates found in PDB files:s     %ss   
Rn  Re  Rf  R�   Ro  t   strict_conflict_handlingR5  t   force_symmetryR0   t   restraints_loading_flagsRu  t6   substitute_non_crystallographic_unit_cell_if_necessaryRs   t   ignore_unknown_scattering_typest%   ignore_unknown_nonbonded_energy_typessS   
  Alternatively, to continue despite this problem use:
    stop_for_unknowns=False(+   R-   R   t   report_non_uniqueR0   R‰   t   unique_file_namesR   Rp  Rà   t   patht   abspathRb   Ro  R8   R   t   inputR   t
   std_stringt
   ValueErrorR†   R  RŸ   RÏ   R   RÑ   t   construct_hierarchyt   overall_countst(   raise_duplicate_atom_labels_if_necessaryR   Rg  t   get_restraints_loading_flagsRq  Rn  Rh  Re  Rf  RH   R5  R<   R   Rr  Rú   t   fatal_problems_message(   RV   Rv  Ro  Rw  Ru  Rx  t   pdb_combinedRb   t   pdb_inpR‘   R1   R�  Rk  R„  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyRz  G  sl    .												
	
c         C   s°  g  } i  } |  j  d  k	 rm xO |  j  j D]> } t j j d | ƒ } t | ƒ | | <| j | d  f ƒ q( Wn  xO |  j D]D \ } } t j j d | ƒ } t | ƒ | | <| j | | f ƒ qw W| j	 ƒ  } | j
 ƒ  t j d | d | ƒ } |  j  d  k	 r	|  j  j 2n  x  | D]˜ \ } } | d  k rQ|  j j d | ƒ |  j j d | ƒ n2 |  j j d | d | ƒ |  j j d | d | ƒ |  j  d  k	 r|  j  j j | ƒ qqWd  S(   NRb   t   sequencet   permutationt
   cif_object(   Rt  R-   Rb   RŠ   R‡  t   canonical_pathR‰   RÏ   Rs  t   valuesRÉ   R   Rœ   Re  t   process_cifRf  t   process_cif_object(   RV   t   allt
   index_dictRb   R•  t   unique_indicest   unique(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyRy  ‹  s4    
 N(	   Rç   Rè   R-   RH   R`   R<   R{  Rz  Ry  (    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyRm    s$   Ac         C   sR  t  j ƒ  } t | t  j ƒ r' | } nS xP | D]H } x? | D]7 } t | t  j ƒ se t  j | ƒ } n  | j | ƒ q; Wq. Wt | ƒ d k r� |  St  j | t  j | ƒ ƒ } g  } xš |  D]’ } g  }	 xa | D]Y }
 g  } x( |
 D]  } | | sÞ | j | ƒ qÞ qÞ Wt | ƒ d k rË |	 j | ƒ qË qË Wt |	 ƒ d k r¸ | j |	 ƒ q¸ q¸ W| S(   Ni    (   R   R  RÇ   R  R‰   RÈ   RÏ   (   R¸   RÆ   RŸ   t   other_as_1dt   o_t   o__t   other_as_1d_as_boolR4  t   s_t	   new_groupt   s__t   new_group_membert   s___(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt   remove_selections§  s0    	 
c         C   s†  g  } xy|  j  ƒ  D]k} xb| j ƒ  D]T} xK| j ƒ  D]=} x4t | j ƒ  ƒ D] \ } } xt | j ƒ  ƒ D]ý \ } } | j | j k rq | | k rq xÐ | j ƒ  D]¿ }	 |	 j j ƒ  }
 |	 j	 j ƒ  d } x” | j ƒ  D]† } | j j ƒ  } | j	 j ƒ  d } |
 d k rÝ | d k rÝ |
 | k rÝ | | k rÝ | j
 t |	 j ƒ g t | j ƒ g g ƒ qÝ qÝ Wq¨ Wqq qq WqR Wq9 Wq& Wq W| S(   Ni   Rø   Rù   (   Rø   Rù   (   Rø   Rù   (   R  R  R  R  R  t   altlocR  R  R  t   nameRÏ   t   intR  (   t	   hierarchyR4  R$  R%  t   residue_groupt   i_gr1t   atom_group_1t   i_gr2t   atom_group_2t   atom1t   e1t   n1t   atom2t   e2t   n2(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt   combine_hd_exchangableÁ  s"    $Mg�íµ ÷Æ°>c	         C   s  |  j  ƒ  j ƒ  | j  ƒ  j ƒ  k s* t ‚ |  j ƒ  }	 | j ƒ  }
 |	 |
 g j d  ƒ d k sc t ‚ |	 j |
 ƒ sx t ‚ | d  k	 r¥ |  j | ƒ }  | j | ƒ } n  | rÒ t |  j	 ƒ  | j	 ƒ  | ƒ sÒ t ‚ n  | rÿ t |  j
 ƒ  | j
 ƒ  | ƒ sÿ t ‚ n  | r8t |  j  ƒ  j ƒ  | j  ƒ  j ƒ  | ƒ s8t ‚ n  | r—|  j  ƒ  j ƒ  } | j  ƒ  j ƒ  } x2 t | | ƒ D] \ } } | | k srt ‚ qrWn  | r|  j ƒ  j ƒ  } | j ƒ  j ƒ  } xD t | | ƒ D]0 \ } } t | j ƒ  | j ƒ  | ƒ sÑt ‚ qÑWn  d  S(   Ni    i   (   i    i   (   R  RŸ   Rˆ   R5  Rn   R-   t   is_similar_symmetryRœ   R   t
   sites_fracR=  R>  R	  RÐ   t   scattering_type_registryt   unique_gaussians_as_listRF   (   t   x1t   x2R¸   t   sitest   adpRP  t   elementst   scattering_typest   epst   cs1t   cs2t   sct1t   sct2t   sct1_t   sct2_t   sr1t   sr2t   s1t   s2(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt   assert_xray_structures_equalÔ  s4    
*!'!c         C   sŽ  d d l  m } |  j ƒ  } | j ƒ  } | | k sJ t d | | f ƒ ‚ t j ƒ  } | j | t ƒ | j ƒ  | k s~ t ‚ | d k r½ | d t k s  t ‚ | | d t k s½ t ‚ n  xv|  j	 ƒ  D]h} x_| j
 ƒ  D]Q} xH| j ƒ  D]:}	 x1|	 j ƒ  D]#}
 x|
 j ƒ  D]} | j | k  s1t ‚ | | j t k sJt ‚ | | j } t | | j <| j j ƒ  j ƒ  | j ƒ  j ƒ  j ƒ  g } | d | d k s±t | ƒ ‚ t | j j ƒ  ƒ d k  rût d | j | j |	 j |
 j f d ƒ ‚ n  | | j | j ƒ | j d ƒ st ‚ qWqWqð WqÝ WqÊ W| j t ƒ sKt ‚ | d k rŠ| d t k smt ‚ | | d t k sŠt ‚ n  d  S(	   Niÿÿÿÿ(   R   s    size mismatch %d != %di    i   s6   
Atom serial='%s' chain='%s' resseq='%s' resname='%s' s1   has no atom name. 
Please check your input model.gü©ñÒMbP?(   t   libtbx.test_utilsR   t
   atoms_sizeRŸ   Rˆ   R   RÈ   t   resizeRH   R  R  R  R  R  R  R<   R  R  R  t   element_symbolR‰   R©  R…   t   serialt   idt   resseqt   resnamet   orthogonalizet   siteR@  R3  (   R«  R  t   cellR   R˜   R¶  t   matchR$  R%  R¬  t
   atom_groupR  RØ   t   aes(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt   compare_hierarchyù  sD    "- 
;c         C   sA   |  j  } | j ƒ  } | j ƒ  } |  j ƒ  } t | | | ƒ d  S(   N(   R   R6  R  R
  RÜ  (   R$  t   xsR6  R  t   hier(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt   assert_model_is_consistent,  s
    	c         C   s]  |  j  } | j ƒ  } | j ƒ  } |  j ƒ  } |  j ƒ  } x| D]} | j ƒ  d k rg t d ƒ ‚ n  | j ƒ  } | j ƒ  } g  }	 d  }
 | j
 ƒ  d k rÜ xH | D]1 } | j j ƒ  d k rÈ | }
 q¤ |	 j | ƒ q¤ Wn t sè t ‚ |
 j } | | j } xT |	 D]L } | | j j } | j | | ƒ } | d k rE| d k  st | ƒ ‚ qWq@ Wd  S(   Ni   s4   Not implemented: cannot handle water with alt. conf.i    t   OgffffffÖ?g333333÷?(   R   R6  R  R
  t   extract_water_residue_groupst   atom_groups_sizeR…   t   only_atom_groupR  R-   RŸ   R  R  RÏ   RH   Rˆ   R  R×  t   distance(   R$  RÝ  R6  R  RÞ  t	   water_rgsR&  R(  R  t   h_atomst   o_atomR  t   o_it   o_sitet   hatomt   hsitet   doh(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt   assert_water_is_consistent3  s2    			t'   xray_structures_from_processed_pdb_filec           B   s   e  Z d d  „ Z RS(   c         C   sf  g  |  _  g  |  _ d  |  _ d  |  _ | j d t ƒ |  _ xd |  j j ƒ  D]S } | j	 j
 ƒ  } d | k rI | j d k rI | d j d ƒ rI | d | _ qI qI W|  j d  k r¾ t d ƒ ‚ n  |  j j ƒ  j ƒ  d k rè t d ƒ ‚ n  | j } t d	 | d
 | d |  j d | d | ƒ \ |  _ |  _ | j j ƒ  } t | ƒ d k r!t j d g ƒ }	 |	 j | ƒ g  }
 xQ t |	 ƒ D]C \ } } y# |
 j |	 | |	 | d g ƒ Wqzt k
 r¼qzXqzWxž |
 D]R } t j t | d | d ƒ ƒ } |  j j | ƒ |  j  j |  j j | ƒ ƒ qÈWnA |  j j t j t |  j j ƒ  j ƒ  ƒ ƒ ƒ |  j  j |  j ƒ d  S(   NRs   t   IASt   ?i   t   ISs   Cannot extract xray_structure.i    s   Empty xray_structure.t   scattering_tableRú   R   R�   R0   (   t   xray_structurest   model_selectionsR-   t   neutron_scattering_dictt   xray_scattering_dictR   RH   t   xray_structure_allR  Rw   RÜ   R7  R‡   R   RŸ   Rú   t   setup_scattering_dictionariesR’  t   model_indicesR‰   R   R  R  R  RÏ   t
   IndexErrorRî   Rœ   RÞ   (   RV   Rk  Rò  R�   R0   R  t   lblRú   Rù  t   model_indices_paddedt   rangesRæ   t   vt   ranR´   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyR`   S  sL    				.		   #	%N(   Rç   Rè   R-   R`   (    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyRî  Q  s   c      	   C   s&  d  g d \ } } | d  k	 r5 t j d d | ƒn  d d d d d g } |  | k r‚ t d	 t |  ƒ d
 d j | ƒ f ƒ ‚ n  |  d k r| j d |  d | d d g ƒ d d  l } | j d | j j	 ƒ | j ƒ  j
 ƒ  } | d  k	 rt j d d | ƒ| j ƒ  j d | ƒ qn  |  d k r«y | j ƒ  } Wn) t k
 rc}	 t d t |	 ƒ ƒ ‚ n X| d  k	 rœt j d d | ƒ| j ƒ  j d | ƒ n  d | j _ n  | d  k	 r| j }
 |
 j ƒ  d k r|
 j d | j d | d d d d  ƒ t d ƒ ‚ n  | d  k	 r| Jqn  | | f S(   Ni   s   Scattering factorsRB   t
   n_gaussiant   wk1995t   it1992t   electront   neutrons   Unknown scattering_table: %s
%ss   Possible choices are: %sRf   t   tableR�   t'   types_without_a_scattering_contributionRð  iÿÿÿÿt   custom_dicts   X-ray scattering dictionarys2   Error setting up neutron scattering dictionary: %ss   Neutron scattering dictionaryi    R  R0   Rh   RA   t	   max_linessÕ   Unknown scattering type symbols.
  Possible ways of resolving this error:
    - Edit columns 77-78 in the PDB file to define the scattering type.
    - Provide custom monomer definitions for the affected residues.(   R   R  R  R  (   R-   R   RM   R   R   RÑ   Rº  t	   mmtbx.iast   iast   ias_scattering_dictt   as_type_gaussian_dictR   t   make_sub_headerRU  t'   switch_to_neutron_scattering_dictionaryR‹  R†   t   scattering_type_registry_paramsR  t   n_unknown_type_symbolst   reportR  (   Rò  R   R�   R0   Rú   Rö  Rõ  t   known_scattering_tablest   mmtbxR‘   Rº  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyRø  ~  sT    		
				
t   mlc         C   s4  | d  k s | r? |  j d t j |  j ƒ  j ƒ  t ƒ ƒ } n  | d  k r« t j j	 d | d | d | d |
 d | d | d | d	 |  d
 | d | d |	 d | d | ƒ } n… d d l
 m } | j d | d d d d ƒ } t j d	 |  d
 | d | d | d | d | d | d | d | d | d | ƒ } | | _ | S(   NRD   t   alpha_beta_paramsR   t   sf_and_grads_accuracy_paramst   use_f_model_scaledRJ   t   mask_paramst   target_nameRC   t   f_maskt   f_calct   abcdt   max_number_of_binst   n_resolution_bins_outputiÿÿÿÿ(   R   t   symbolt   r_deni   t   t_deni�   t   twin_lawt   twin_law_strt   detwin_modet	   map_types(   R-   Rt   R   RÈ   RD   RŸ   RH   R  t   f_modelt   managert   cctbxR   t   rt_mxR   t   twin_model_managert   twin(   RC   R   RJ   R  R  t   ignore_r_free_flagsR  t   k_maskt   k_anisotropict   hl_coeffR  R"  R$  t   detwin_map_typesR  R  R  t   max_number_of_resolution_binsR  t   fmodelR   t   twin_law_xyz(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt   fmodel_managerµ  sB    -			g       @c   "         s¹  | d  k r9 |  j d t j |  j ƒ  j ƒ  t ƒ ƒ } n  |  j ƒ  sK t ‚ | j ƒ  s] t ‚ |  j	 ƒ  j
 | j	 ƒ  ƒ s~ t ‚ |  j ƒ  j ƒ  j t ƒ d k s¥ t ‚ | d  k rÃ t j j ƒ  } n  | | _ | | _ ‡  ‡ f d †  } | d  k s| d  g k r|	 rt j d |  ƒ } n  t } t | ƒ d k r„| d  k rNd  g } n  | j d  ƒ d k rs| j d  ƒ n  | d |  d | d d | d	 | d
 d  d | d | d | d | ƒ 	} | j ƒ  } xÍ| D]´ } | d  k	 rÉ| d |  d | d d | d	 | d
 | d | d | d | d | ƒ 	} | j ƒ  } t | | ƒ d |
 k oM| | k  } | r}| } | j ƒ  } | | _ d }
 q}qÉqÉWnd  } | d j ƒ  } g  } x9t | ƒ D]+\ } } t d | d ˆ d |  j ƒ  d | j ƒ  d | d d  ƒ } | d k r| j | ƒ } n  | d k ra| j ƒ  j ƒ  } g  } x¡ | j  ƒ  D] } | j | j ƒ  ƒ qAWq­| | j ƒ  j ƒ  7} | j  ƒ  } t | ƒ t | ƒ k s¡t ‚ x4 t! t | ƒ ƒ D]  } | | c | | j ƒ  7<q´Wq­W| j" ƒ  j# d | ƒ } g  }  x7 | D]/ } |  j | j" ƒ  j# d | t | ƒ ƒ ƒ qWt d |  j ƒ  d | j ƒ  d | d ˆ d | d |  d d  ƒ }! | rŒ|! j$ d | ƒ n  |! } | rµ| j rµ| j$ d | ƒ n  | S(   NRD   i    c	   
         sh   t  d | j ƒ  d |  j ƒ  d | j ƒ  d ˆ d | d | ƒ }	 | rd |	 j d | d ˆ  d	 | ƒ n  |	 S(
   NR   RC   RJ   R  R  R"  R�   R0   t   optimize_mask(   R4  t   deep_copy_scatterersRŽ   t   update_all_scales(
   RC   RN  RD  t   mpt   tlt   bssft   bsspt   rot   omR2  (   R0   R  (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt
   get_fmodel  s    	R.   i   RC   RN  RD  R8  R9  R:  R;  R<  R=  id   R   R  RJ   R  R"  R  R  t   remove_outliers(%   R-   Rp   R   RÈ   RD   RŸ   RH   t	   is_in_asuRˆ   R”   R3  t   sys_absent_flagsRn   R<   t   bsst   master_paramsRG   R&   t   anisotropic_scalingR   t   get_twin_lawsR‰   RÏ   t   r_workR¡   RŽ   R+  R6  R  R4  t   concatenateR  t   f_masksRî   RC   Rt   R7  ("   RC   Ró  Rò  RJ   R  t   bulk_solvent_and_scalingt
   bss_paramsR  t	   twin_lawst   skip_twin_detectiont   twin_switch_tolerancet   outliers_rejectiont   bulk_solvent_correctionRD  R0   R>  R5  R2  RF  R"  t   fmodel_t   r_work_t   flt   f_model_datat   xrs_as_one_structuret   f_masks_dataR  R   R–   t   fmskst   ifmdt   fmodel_averaget   f_masks_data_averaget   fmodel_result(    (   R0   R  sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt   fmodel_simpleì  sœ    	$!'		"  	&		"-		t   process_command_line_argsc           B   s)   e  Z d d d d e d  „ Z d „  Z RS(   c         C   sE  | |  _  g  |  _ g  |  _ g  |  _ g  |  _ g  |  _ g  |  _ d  |  _ d  |  _	 | |  _
 d  |  _ d  |  _ d  |  _ g  } | d  k	 r® | d  k s™ t ‚ | j d | ƒ } n  g  }	 g  }
 x±| D]©} t } | } t } | j d ƒ d k r| | j d ƒ d } t } n  y) | s6| j | t j | ƒ g ƒ n  Wn$ t k
 rM‚  n t k
 r]n Xt j j | ƒ rsd  } y t j j d | ƒ } Wn$ t k
 r¥‚  n/ t k
 rµn Xt | j  ƒ d k rÔd  } n  | d  k	 r|	 j | ƒ t } |  j j | ƒ qst! j" d | ƒ s*t! j# d | ƒ rC|  j j | ƒ t } qs| j$ d ƒ | j$ d ƒ | j$ d ƒ g j t ƒ d k r`|  j |  j g j d  ƒ d	 k s£t ‚ d
 d l m } t j j% d | ƒ |  _ | |  _ |  j j& } | d k rõd } n  yA | s5t' j( |  j j) ƒ  j* ƒ  | ƒ } | j | | g ƒ n  Wqpt k
 rL‚  qpt k
 r\qpXqsyœ g  } | j$ d ƒ s‡| j$ d ƒ rût+ j, d | d t ƒ } | j- ƒ  d  k	 rÚ|  j j | ƒ |  j j | ƒ t } qût. j/ d | d t ƒ j0 ƒ  } n  Wn$ t k
 r‚  qst1 k
 r"qsXt | ƒ d k rs|  j j | | f ƒ |  j j t j j2 | ƒ ƒ t } qsn  | sÏt+ j, d | d t ƒ } | j- ƒ  d  k	 rÏ|  j j | ƒ |  j j | ƒ t } qÏn  | d  k	 rÁ | rÁ y | j3 d | ƒ } Wn` t4 k
 rY} t j j | ƒ sFd | k r-‚  n  t4 d t5 | ƒ ƒ ‚ n  t4 d | ƒ ‚ qjX|
 j | ƒ qÁ qÁ W| d  k	 r| j6 d |	 |
 d t ƒ \ |  _ } t | ƒ r$|  j  d IJx' | D] } |  j  d It7 | ƒ IJq¿W|  j  d d IJ|  j  Jt4 d ƒ ‚ q$n t |
 ƒ d k s$t ‚ t | ƒ d k ršd  } xB | D]: } | d d  k	 rC| d j) ƒ  d  k	 rC| d } PqCqCW| d  k	 rÀ| j) ƒ  d  k	 rÀxé | D]á } | d d  k	 r¦| d j) ƒ  d  k	 r¦| j8 | d ƒ s‡xR | D]J } | d d  k	 rì|  j  | d I| d j) ƒ  I| d j9 ƒ  IJqìqìW|  j
 d  k s^|  j
 j) ƒ  d  k rwd } t4 d | ƒ ‚ q„|  j
 } Pq‡q¦q¦W| |  _	 qÀn& t | ƒ d k rÀ| d d |  _	 n  |  j
 d  k	 ró|  j
 j) ƒ  d  k	 ró|  j
 |  _	 n  |  j	 d  k	 rA|  j	 j) ƒ  |  j	 j: ƒ  g j d  ƒ d k rAt4 d ƒ ‚ qAn  d  S(   Nt
   home_scopet   =i   Rb   i    s   .mrcs   .ccp4s   .mapi   iÿÿÿÿ(   t   ccp4_maps   .cifs   .cif.gzt   ensure_read_accesst	   file_patht   strictt   args   File not found: %ss   Unknown file format: %st   sourcest   track_unused_definitionss   Unused parameter definitions:Rf   R%   iO   s   Unused parameter definitions.s2   Crystal symmetry mismatch between different files.s   %s
s   Corrupt crystal symmetry.(;   R0   Rv  Rs  t   cif_file_namest   reflection_filest   reflection_file_namest   phil_file_namesR-   R�   R5  t   cmd_csRW   R_  t   ccp4_map_file_nameRˆ   t!   command_line_argument_interpreterRH   Rn   t   indexR<   RÏ   R   t   extract_fromt   KeyboardInterruptR…   Rà   R‡  t   isfileR8   R9   R:   R‰   t   objectsR   t   is_pdb_filet   is_pdb_mmcif_filet   endswitht
   map_readert   space_group_numberR   t   symmetryR6  RF   R   t   any_reflection_filet	   file_typeR   t   readerR$  t	   ExceptionRˆ  Rh  R   R   t   fetchR†   R¸  t   space_group_infot   space_group(   RV   R^  Rj  RC  R0   R]  t    suppress_symmetry_related_errorst   crystal_symmetriest   parameter_interpretert   parsed_paramst   command_line_paramsRc  t   arg_is_processedt   arg_filet   is_parameterR�   R_  Rv  t   csR•  t   reflection_fileR‘   t   unused_definitionst   obj_loct   cs0R1   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyR`   _  s$   															     		!'	 		  		%  	 	
&
&8$	$!c      	   C   sO   |  j  d  k rH t j  d |  j d t d |  j d t j ƒ } | |  _  n  |  j  S(   NR5  R€  Rg  t   err(   RW   R-   R   R5  R<   Rg  R\  R]  (   RV   RW   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt   get_reflection_file_serverõ  s    			N(   Rç   Rè   R-   RH   R`   R�  (    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyR\  ^  s   �t   pdb_filec           B   s/   e  Z d g  d e e d  „ Z e d d „ Z RS(   c         C   s  | d  k r t j } n  d  |  _ d  |  _ | |  _ | |  _ | |  _ | |  _ | |  _	 t
 d | ƒ } | j d | ƒ t | j ƒ d k rš t d ƒ ‚ n  | j |  _ t j j d d  d t j |  j ƒ d t ƒ |  _ | d  k	 r
| j ƒ  d  k	 r
|  j j d | ƒ n  d  S(	   NR|  RB   i    s   No coordinate file given.R}  R~  t   raise_sorry_if_format_errorR5  (   R-   R\  RX  t   processed_pdb_files_srvRk  Rs  R5  Rv  Rn  R„  R   R…  R‰   R†  R   Ro  t   pdb_raw_recordsR8   R   R‰  R   RŠ  R<   R’  R6  (   RV   Rv  R5  Rs  R0   R„  Rn  R‘  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyR`     s&     							c         C   sý   | d  k r t ƒ  } n  t j j j j ƒ  } d | j _ d | j _	 d | j _
 t | _ t d |  j d | d |  j d |  j d t d	 | ƒ |  _ |  j j d
 |  j d | ƒ \ |  _ |  _ |  j j j d t d |  j ƒ } | d  k	 rù t | ƒ ‚ n  d  S(   Ng      ð¿i áõg      ð?Rs  Rq  R5  Rn  Rr  R0   Ro  Rw  Rƒ  R„  (   R-   R   R  R   Rg  RC  RG   t   clash_guardt   nonbonded_distance_thresholdt'   max_number_of_distances_below_thresholdt)   max_fraction_of_distances_below_thresholdR<   t#   proceed_with_excessive_length_bondsRm  Rs  R5  Rn  RH   R�  R{  R‘  Rk  R’  Rú   R�  R„  R   (   RV   Rw  R0   t   pdb_ipR1   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt   set_ppf  s*     				 N(   Rç   Rè   R-   RH   R`   R<   R˜  (    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyRŽ  ÿ  s   i   c	         C   s†  d  }	 t d |  d | d | d | ƒ }
 |
 j ƒ  t j j d |
 j d | d | ƒ } t | j ƒ d k ry t	 d	 ƒ ‚ n  | j d
 } d d d „  ƒ  Y} | d  k rÃ | d | j
 ƒ  j ƒ  ƒ } n  | j ƒ  j ƒ  j ƒ  } d | k pð d | k } |
 j j d t d | d | ƒ } t j j d | d | ƒ } |
 j j j } d d l m } | j d |
 j d | d | d | d | d | ƒ } | S(   NRv  Rs  R5  R0   Rk  Rò  R�   i   s   Multiple models not supported.i    t   rfc           B   s   e  Z d  „  Z RS(   c         S   s4   t  |  _ t |  _ t j | t  ƒ |  _ d  |  _ d  S(   N(	   R<   t   individual_sitesRH   t   individual_adpR   RÈ   t   sites_individualR-   t   sites_torsion_angles(   RV   RŸ   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyR`   K  s    		(   Rç   Rè   R`   (    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyR™  J  s   RŸ   Rø   Rù   t   show_energiest   plain_pairs_radiust   assume_hydrogens_all_missingt   geometryt   normalizationiÿÿÿÿ(   R$  R�  t   restraints_managerR   t   refinement_flagsR
  (    (   R-   RŽ  R˜  R  t   utilsRî  Rk  R‰   Ró  R   R  RŸ   Rº  t   type_count_dictt   keyst   geometry_restraints_managerRH   t
   restraintsR'  Rú   R
  R$  R�  (   Rv  R0   R¢  Rs  R5  RŸ  R¤  Rò  R�   t   cryst1t   mmtbx_pdb_filet   xsfppfR   R™  t	   sctr_keyst   has_hdR¡  R£  R
  R$  R4  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt   model_simple2  sH    		
		
				c      
   C   se  | j  ƒ  } | j  ƒ  } t j j j d | d | d | ƒ t j d |  j ƒ  j ƒ  d d |  j ƒ  j ƒ  ƒ } |  j	 | ƒ }  | j	 | ƒ } t
 j j ƒ  } t | _ d | _ d }	 d  }
 xŠ t | | g ƒ D]v \ } } t j j d | d	 |  d
 | d d ƒ } | j d | d d d t ƒ | j ƒ  } | |	 k  rÌ | }	 | }
 qÌ qÌ W|
 d k r[| } n | } | S(   NR   t   tls_selectionst
   tls_groupsRŸ   R™   g     @@i   g     8�@RC   RJ   R  t   ls_wunit_k1R�   t   verboseiÿÿÿÿR5  i    (   R6  R  t   tlst   toolst   combine_tls_and_u_localR   t   random_boolRD   RŸ   Rœ   RB  RC  RG   RH   t   k_sol_b_sol_grid_searcht   number_of_macro_cyclesR-   R  R&  R'  t   update_solvent_and_scaleRF  (   RC   RJ   R   R°  R±  t   xrs_1t   xrs_2R¸   RJ  RF  t   i_bestRæ   RN  R2  RQ  R4  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt    extract_tls_and_u_total_from_pdbh  s8    			 	t   guess_observation_typec           B   s5   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z RS(   iô  c         C   sÎ  | j  ƒ  |  _ | |  _ d  |  _ | d  k	 rQ | j  ƒ  |  _ | j ƒ  j ƒ  } n  | j ƒ  j ƒ  } | j d d  ƒ } | j ƒ  } | d  k	 r?t	 t
 j | ƒ t
 j | ƒ ƒ d k r?| j ƒ  |  j k r?xK d d d d g D]7 } | j d | ƒ } | j ƒ  j ƒ  |  j k rÝ PqÝ qÝ W| j ƒ  |  j k r?| j  ƒ  } q?n  | j ƒ  \ } }	 |	 d k r“| j d	 d ƒ } | d  k	 r“| j d	 d ƒ } q“n  |	 d
 k  r¨d
 }	 n  | d k rÍ| |	 d k rÍd } n  | j d	 |	 d | ƒ } | j ƒ  |  j k r| } n  g  }
 x¼d d g D]®} | j ƒ  } d  } | d k rmy | j ƒ  Wqmt k
 ri} t | ƒ } qmXn  | d  k ry| j d | ƒ j ƒ  } x0d d d g D]Ñ } | j  ƒ  } | d k rÎ| j ƒ  } n | d k ré| j ƒ  } n  | j ƒ  d } | d k rd } n  |  j d | j  ƒ  d | j  ƒ  d | d | j ƒ  d d d t ƒ } |
 j | | | j | j  ƒ  g ƒ q¡Wq|
 j | | t! d g ƒ |
 j | | t! d g ƒ |
 j | | t! d g ƒ qWd GHx? |
 D]7 } d j" g  | D] } d t | ƒ ^ qçƒ } | GHqÔWg  } g  } xT |
 D]L } | d d k rH| j | ƒ q"| d d k rh| j | ƒ q"t# ‚ q"W|  j$ d  | ƒ \ } } |  j$ d  | ƒ \ } } | | k rût	 | | ƒ d! d" k rû| d  k	 rà| |  _% q+d |  j d  d  g |  _% n0 | d  k	 r| |  _% n d |  j d  d  g |  _% t& |  j% ƒ d k rOd# |  j GHn{ |  j% d$ |  j% d% g j' d  ƒ d$ k r˜d& |  j% d' |  j% d f GHn2 d# d j" g  |  j% D] } d t | ƒ ^ q«ƒ GHd  S((   NR°   gü©ñÒMbP?g      @g       @g      ð?g        t   cutoff_factorg      Ð?R�   g      ø?g      @t   d_maxt   Xt   NR   t   Ft   FFORCEt   IFORCER  R  RC   R  Rò  RM  g      @RL  g    eÍÍAs   All scores (stage 1):Rf   s   %6si    t   resultsg      Y@g       @s
   Answer: %si   i   s   Answer: %s_%si   ((   RŽ   t   f_obs_originalRw   R-   t   r_free_flags_originalR¦   t   remove_systematic_absencesR›   R•   R¡   R   R  t   minRŸ   t	   data_sizet   sigma_filterRD   t	   d_max_mint   resolution_filterR6  R  R{  R†   t!   structure_factors_from_scatterersR  R¤   t	   f_as_f_sqR¥   t   get_r_factorR<   RÏ   R+  RF  RH   RÑ   R…   t	   find_bestR4  R‰   Rn   (   RV   RC   Rw   R   RJ   R•   t   sig_cutt   f_obs_RÁ  R�   RÇ  t   dtypeRN  RŒ  R‘   R  t   ftypeR–   Rò  R2  t   rt   r_t   st_rt	   results_xt	   results_nt   result_best_xt   rbxt   result_best_nt   rbn(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyR`   �  s°    		4   	 	 		
 			),	  
& ) c   	      C   sè   d } d  } xD | D]< } t | d ƒ t | ƒ k  r t | d ƒ } | } q q Wt | d d ƒ } t | d d ƒ } t | d d ƒ } t t t | | ƒ t | | ƒ ƒ t | | ƒ ƒ d } | d k  rÞ d  } n  | | f S(   Ng    eÍÍAi   i    i   i   g      Y@g      @(   R-   R¡   RË  (	   RV   RÇ  t   r_bestt   answerRØ  t   d0t   d1t   d2t   diff(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyRÓ  ì  s    : 	c         C   sV  t  |  j ƒ d k r! |  j } në |  j d |  j d g j d  ƒ d k re |  j d |  j d } n§ |  j } d | d } | d d k r¦ |  j j ƒ  d | } nf | d d k rÐ |  j j ƒ  d	 | } n< | d d
 k r|  j j ƒ  |  _ |  j j ƒ  d | } n  |  j j	 d | ƒ } |  j
 d  k	 rL| j d |  j
 d d ƒ n  | j ƒ  S(   Ni    i   i   t   _s   OBS_%si   RÄ  RÅ  t   IRÆ  t   column_root_labelR.   s   R-free-flags(   R‰   R4  Rw   Rn   R-   RÈ  R¥   t#   set_observation_type_xray_intensityRÑ  t   as_mtz_datasetRÉ  t   add_miller_arrayt
   mtz_object(   RV   Rw   RØ  t   mtz_dataset(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyRí  ü  s,    )			
c         C   s´  | j  d t j | j ƒ  j ƒ  t ƒ ƒ } x¿ t d ƒ D]± } t j d | d | d d ƒ }	 |	 j	 ƒ  j ƒ  }
 |	 j
 ƒ  j ƒ  } |	 j ƒ  j ƒ  } |	 j d | ƒ j ƒ  } |
 | @| @| @} | j | ƒ } | j | ƒ } | j | ƒ } q7 Wd  } | st j d | ƒ } | j d  ƒ n  t j j ƒ  } d	 | _ d
 | _ d
 | _ d	 | _ d | _ d | _ d | _ t d | d | d | g d | d d d t d | d | d | d | ƒ 
} | S(   NRD   i   t
   miller_obsRJ   RB   t   silentR&  R.   g        gffffffÖ?g     ÀV@g     €F@R²  RC   Rò  Ró  R  RI  RJ  RM  RL  RK  (   Rt   R   RÈ   RD   RŸ   RH   RÞ   R   t   outlier_managert   basic_wilson_outlierst   extreme_wilson_outlierst   beamstop_shadow_outlierst   model_based_outliersRœ   R-   R   RE  RÏ   RB  RC  RG   t   k_sol_grid_search_mint   k_sol_grid_search_maxt
   k_sol_stept   b_sol_grid_search_mint   b_sol_grid_search_maxt
   b_sol_stept   targetR[  R<   (   RV   RC   R  Rò  R   RM  RL  RJ   t   trialR4  RË  RÌ  t   s3t   s4t   sel_outRK  R�   R2  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyRÒ    sL    *											N(   Rç   Rè   RÌ  R-   R`   RÓ  Rí  RÒ  (    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyR¿  Œ  s
   \		t   fmodel_from_xray_structurec        
   B   sA   e  Z d d d e d d d  d d d „	 Z d „  Z d d „ Z RS(   R  c         C   s:  |	 d  k r t j }	 n  | |  _ | d  k rE t j j j j ƒ  } n  | d  k ru | j	 d  k	 rl | j	 } qu d } n  | d  k rÙd  } y | j
 } Wn t k
 r± |  j ƒ  n X| j d k rÎ | j ƒ  n | j d | j d | ƒ | d  k r |  j ƒ  n  | j d | ƒ j ƒ  } | j } | j d | d | j d | j d | j d	 | j d
 | j d | j d | j d | j ƒ 	j ƒ  } d  } y | j } Wn t k
 r±t d ƒ n X| j d  k	 r¼| j d | ƒ } q¼nã | j ƒ  d  k	 sñt  ‚ | j! ƒ  d  k	 r| j" ƒ  d  k	 st  ‚ y | j
 } Wn t k
 rAd  } n Xy | j } Wn t k
 rhd  } n X| j d | d | ƒ } | j d k r�| j ƒ  n | j d | j d | j# ƒ  ƒ | j$ d | d t% ƒ } t j& j' d | d | j d | d | j( d | d | d | d t) | ƒ d | j j* d | j j+ d | j j, ƒ } | j& ƒ  } | j- d | j. ƒ  | j j/ ƒ } yó | j0 j1 d k rct) | ƒ } | j2 ƒ  | j3 d  k	 rc| j3 d k r`| j. ƒ  } | j. ƒ  | j3 d } t4 j5 ƒ  } xN t6 | j7 ƒ  ƒ D]: } t8 j9 d d  ƒ } | d k r)d! } n  | j: | ƒ qüW| | | } | j- d | ƒ } q`qcn  Wn' t; k
 rwn t k
 r�t ‚ n X| |  _& | |  _< | |  _ d  |  _= |  j rët4 j5 |  j& j. ƒ  j7 ƒ  d  ƒ } | |  j& _> n  | j	 d  k	 r6| j= ƒ  |  _= |
 r6|  j= j? ƒ  r6|  j= j@ ƒ  |  _= q6n  d  S("   Ngš™™™™™¹?R  R  R�   R   t	   algorithmt   cos_sin_tablet   grid_resolution_factort   quality_factort   u_baset   b_baset   wing_cutofft   exp_table_one_over_step_sizes/   Parameter scope does not have 'low_resolution'.RÁ  R}   R€   R  RJ   R  R  R"  t   twin_fractionRC   t   b_cartt   k_solt   b_solRD   t   reali    g      Y@i   iÿÿÿÿ(A   R-   R\  RX  t
   add_sigmasR  t   command_lineR2  t(   fmodel_from_xray_structure_master_paramsRG   t   r_free_flags_fractionRª   R{  t$   Sorry_high_resolution_is_not_definedRò  R  Rº  t   structure_factorsR  t   structure_factors_accuracyRÐ  R  R  R  R  R  R  R  R	  R¨   R…   RÏ  R5  Rˆ   R6  R~  R�   RŒ   RH   R&  R'  t   maskR¡   R  R  R  Rt   RD   t   scalet   outputt   typeR¥   t&   add_random_error_to_amplitudes_percentR   t   doubleRÞ   RŸ   t   randomt   randintRÏ   t   AttributeErrorR�   RJ   t   _sigmasR¯   Ru   (   RV   R   RC   R�   R  R  R"  R
  Rü  RB   t   merge_r_free_flagst   hrt   sfgat   lrRJ   R2  R&  RD   t   frt   riRý  RØ  R•   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyR`   @  sÌ    
 		  	 									  *  
  
				"
 	  
					!c         C   s   t  d ƒ ‚ d  S(   NsQ   High resolution limit is not defined. Use 'high_resolution' keyword to define it.(   R   (   RV   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyR  ª  s    t
   amplitudesc      	   C   s   |  j  j j d k s t ‚ | d  k	 s- t ‚ |  j  j } |  j  j j d k rt | d ƒ } t d |  j d | ƒ | d |  j j ƒ  j	 ƒ  IJ| d i d d	 6j
 t |  j j ƒ  ƒ d
 ƒ IJx9 d | j d | j j ƒ  f g D] } | d | IJqä W|  j  j d  k	 r| d IJn  | j d k r2|  j j ƒ  t j |  j j ƒ  ƒ |  j j d t ƒ j ƒ  g } |  j  j d  k	 r”| j |  j j ƒ  ƒ n  xqt | Œ  D]Š } |  j  j d  k rð| d | d	 I| d | j | d | d f IJq¡| d | d	 I| d | j | d | d | d f IJq¡Wqœ|  j j ƒ  |  j j ƒ  g } |  j  j d  k	 r{| j |  j j ƒ  ƒ n  xt | Œ  D]| } |  j  j d  k rÐ| d | d	 I| d | j | d f IJqˆ| d | d	 I| d | j | d | d f IJqˆWn‘ |  j } | d k r9| j ƒ  } | j ƒ  n  | j d d | j ƒ }	 |  j  j d  k	 r€|	 j d |  j d d ƒ n  |	 j ƒ  }
 |
 j d | ƒ d  S(   NR   t   cnst   wR5  RB   s   NREFlections=%ds   ANOMalous=%st   FALSEi    t   TRUEs   %ss-   DECLare NAME=%s DOMAin=RECIprocal TYPE=%s ENDs4   DECLare NAME=TEST DOMAin=RECIprocal TYPE=INTeger ENDt   complext   degs   INDE %d %d %ds    %s= %.6g %.6gi   i   s    %s= %.6g %.6g TEST=%di   s	    %s= %.6gs    %s= %.6g TEST=%dt   intensitiesRé  R.   s   R-free-flagsRb   (   s   mtzR'  (   R�   R  t   formatRˆ   R-   t   openR#   R&  R”   RŸ   t   getRª  R¯   Rw   R  R  R  R   R¡   RD   t   phasesR<   RÏ   RJ   RÐ   RÑ  Rê  Rë  Rì  Rí  RI  (   RV   Rb   t   obs_typet   opt   ofot   n_tt   arraysR—  t   output_arrayRî  Rí  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt   write_to_file®  s\    *!%)			
N(   Rç   Rè   R-   RH   R`   R  R8  (    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyR  >  s   a	c         C   sT  d  } |  d  k	 rP| } | d  k	 r: | j d | ƒ } n  |  j j d | j ƒ  ƒ j j } | j ƒ  } | j ƒ  } t	 j
 ƒ  } x“ | D]‹ }	 |	 j \ }
 } | |
 j ƒ  d k r† | | j ƒ  d k r† t j | |
 ƒ } t j | | ƒ } t | | ƒ d } | j | ƒ q† q† W| j ƒ  d k r+d St j t	 j | ƒ | j ƒ  ƒ } n  | S(	   NR¸   R<  Rø   Rù   i   i    (   Rø   Rù   (   Rø   Rù   (   R-   Rœ   R¡  t   pair_proxiesR<  t   bond_proxiest   simpleR=  R  R   R  t   i_seqsRÑ  R   RB  R¡   RÏ   RŸ   t   matht   sqrtt   sum(   R£  R   t   ias_selectionR4  t   xrs_selt   bond_proxies_simpleRO  R  R—  t   proxyR  RR  t   b_iso_it   b_iso_jt   abs_diff_sq(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt   rms_b_iso_or_b_equiv_bondedä  s,     %c         C   sä  | d  k r |  S|  j ƒ  | d k s2 t | ƒ ‚ d d l m } t j j j ƒ  } |  j ƒ  j	 ƒ  } | j
 ƒ  } | d k rš d d l m } | ƒ  } n  x0|  j ƒ  D]"}	 x|	 j ƒ  D]}
 x|
 j ƒ  D]ô} | j ƒ  } t | ƒ d k r÷ qÍ n  xÇ| j ƒ  D]¹} | j ƒ  } t j ƒ  } x$ | j ƒ  D] } | j | j ƒ q/Wt } | d  k	 rƒx% | D] } | | sbt } PqbqbWn  | d k r­| j | ƒ d	 k r­t } n  | s| j d
 | d | d d  ƒ } | d  k	 r½| j | ƒ } t j ƒ  } g  } xV | D]N \ } } t j t j | | j ƒ  ƒ ƒ } | j | ƒ | j | j
 ƒ  ƒ qWd } | d k rrd } n  d  } x¶ t  | | ƒ D]¥ \ } } | d k rÐ| | k  r-| d k r-| } | j
 ƒ  } q-qˆ| d k sè| d k r| | k  r-| } | j
 ƒ  } q-qˆ| | k rˆ| j
 ƒ  } | } qˆqˆW| d  k r“| d k r“d } xA t  | | ƒ D]- \ } } | | k  r_| } | j
 ƒ  } q_q_Wn  | d  k	 s¥t ‚ | j! | | ƒ } q½qqWqÍ Wqº Wq§ W|  j ƒ  j" | ƒ |  S(   Nt   max_distantt   min_distantt   exact_matcht   fix_outliersiÿÿÿÿ(   t   lockit(   t   RotamerEvali   t   OUTLIERRe  t   residuet   atom_selection_boolg      ð¿g    €„.Ag      à?(   RH  RI  RJ  RK  (   RI  RJ  RK  (#   R-   t   reset_i_seq_if_necessaryRˆ   t   mmtbx.command_lineRL  R  R   Ri  R  t   extract_xyzRŽ   t   mmtbx.rotamer.rotamer_evalRM  R  R  R  t
   conformersR‰   t   only_residueR   R  RÏ   R  RH   R<   t   evaluate_residuet   get_rotamer_iteratorRœ   R  R  R>  t   dotRÐ   t   set_selectedt   set_xyz(   R
  t   modeR¸   RL  Re  t   sites_cart_startt   sites_cart_resultRM  t   rotamer_managerR$  R%  R¬  RU  t	   conformerRO  t   residue_iselectionR  t   excludet   r_i_seqt   rotamer_iteratort   sites_cart_start_t	   distancesR¾  t   rotamert   rotamer_sites_cartt   distt
   dist_startt   rest   dRØ   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt   switch_rotamersü  s�     
 
				"c   
      C   s¨   d d  l  } g  } g  } i  } x6 |  j ƒ  D]( } | j | k r+ | j | j ƒ q+ q+ W| j } | j } t ƒ  } x/ | D]' } | d }	 |	 | | <| j |	 ƒ qy W| S(   Niÿÿÿÿi    (   Rû   R  t   segidRÏ   t	   lowercaset	   uppercaset   generate_two_character_idst   remove(
   R
  Rû   t   two_character_chain_idst
   segid_listt   seg_dictR  t   lower_letterst   upper_lettersRÓ  t   chainID(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt   seg_id_to_chain_idE	  s    			

c         C   s¨   t  } x› |  j ƒ  D]� } | j d k r d  } xK | j ƒ  D]= } | d  k rY | j } q; | d  k r; | | j k r; t  Sq; W| d  k r  | d k r  t } q  q q W| S(   NRA   Rf   s     s      s       (   RA   Rf   s     (   RA   Rf   s     s      s       (   RH   R  RÓ  R-   R  Rn  R<   (   R
  t   bare_chainsR%  Rn  R  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt   find_bare_chains_with_segidsV	  s    c         C   s¹   d } x¬ |  j  ƒ  D]ž } | j d k r d  } xV | j ƒ  D]H } | d  k rY | j } q; | | j k r; | G| j GHt d ƒ ‚ q; q; W| | } | | _ | d | | f } q q W| S(   NRA   Rf   s     s'   multiple segid values defined for chains4   segID %s renamed chain %s for Reduce N/Q/H analysis
(   RA   Rf   s     (   R  RÓ  R-   R  Rn  R   (   R
  Ru  t
   rename_txtR%  Rn  R  t   new_id(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt   assign_chain_idse	  s    
	c         C   s°   g  } x£ |  j  ƒ  D]• } xŒ | j ƒ  D]~ } t } x: | j ƒ  D], } | j ƒ  re | j ƒ  re q? q? t } q? W| s{ q& n  | j } | | k r  | j | ƒ q& t Sq& Wq Wt S(   N(	   R  R  RH   RU  t
   is_proteint   is_naR<   RÓ  RÏ   (   R
  t   used_chain_idsR$  R%  t   found_conformerR`  t   cur_id(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt   check_for_duplicate_chain_idsv	  s    
	c         C   sÙ   g  } t  ƒ  } xP |  j ƒ  D]B } x9 | j ƒ  D]+ } | j } | | k r/ | j | ƒ q/ q/ Wq Wxp |  j ƒ  D]b } xY | j ƒ  D]K } | j } | | k r­ | j | ƒ q‚ | d } | | _ | j | ƒ q‚ Wqo Wd  S(   Ni    (   Rq  R  R  RÓ  Rr  RÏ   (   R
  R�  t   two_charR$  R%  Rƒ  R}  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt   force_unique_chain_ids‰	  s    			
	c          C   s  d d  l  }  g  } g  } x |  j D] } | j | ƒ q" Wx t d ƒ D] } d | } qF Wx+ |  j D]  } | j | ƒ | j | ƒ qd Wx1 t t | ƒ ƒ D] } | | } | j | ƒ q› WxV t t | ƒ ƒ D]B } x9 t t | ƒ ƒ D]% } | | | | } | j | ƒ qè WqÏ W| S(   Niÿÿÿÿi
   s   %d(   Rû   Rp  RÏ   Rî   Ro  R‰   (   Rû   t   singlesRs  t   cht   numRæ   t   j(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyRq  �	  s$    
i   i   c         C   s.  |  j  ƒ  } | j  ƒ  } | | k s* t ‚ d } | rT t j |  ƒ Gt j | ƒ GHn  t | d t t t j |  ƒ t j | ƒ ƒ ƒ d ƒ }	 t | d | t t t j |  ƒ t j | ƒ ƒ ƒ d ƒ }
 t j ƒ  } t j ƒ  } t j ƒ  } x­ g  t |	 |
 | ƒ D] } | d ^ qD]‚ } |  | k j t	 ƒ d | } | | k j t	 ƒ d | } | rr| | | | f GHn  | j
 | ƒ | j
 | ƒ | j
 | ƒ qW| r§Hn  t j t j | | ƒ ƒ } | j | ƒ d } t j t j | | ƒ ƒ } | j | ƒ d } | j | ƒ d } | r*| G| GHn  | S(   Ns   %5.2f %6.2f %6.2fid   g      Y@i    (   RŸ   Rˆ   R   RË  R  Rª  R  Rî   Rn   R<   RÏ   R  R¡   Rœ   (   t   map_1t   map_2t   sigma_1t   tail_cutofft   stepR³  t   size_1t   size_2t   fmtt   startt   endR•   t   c_1t   c_2Ræ   t   sigt   s_at   s_oRØ   t   tmp1t   tmp2(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt0   equivalent_sigma_from_cumulative_histogram_match±	  s:     9<0   c         C   sü  | | g j  d  ƒ d k s! t ‚ | d  k r9 t j } n  |  j j ƒ  j  t ƒ d k r[ d  S| r’ | J| d IJ| d |  j ƒ  |  j	 ƒ  f IJn  | d  k	 rÄ t
 d |  j d | j ƒ | j ƒ  n  | d  k	 rß | j ƒ  } n  d d  l } | j j d | d	 | d
 | j ƒ } t j ƒ  } x0 | D]( }	 x |	 d D] }
 | j |
 ƒ q3Wq"W|  j j d d d | ƒ |  j d | ƒ | d  k	 r’|  j | _ n  |  j j d d d |  j j ƒ  ƒ | d  k	 rÏ|  j | _ n  | rø| d |  j ƒ  |  j	 ƒ  f IJn  d  S(   Ni   i    s   Optimizing scattering from H...s0     before optimization: r_work=%6.4f r_free=%6.4fR¼  R½  iÿÿÿÿR
  Re  R£  t   valueR¸   R0   s0     after optimization:  r_work=%6.4f r_free=%6.4f(   Rn   R-   Rˆ   R\  RX  R   R"  R<   RF  t   r_freeRÍ  t   reset_occupancies_for_hydrogensR
  t   mmtbx.hydrogenst	   hydrogenst	   rotatableR£  R   R  RÏ   t   set_occupanciest   update_f_hydrogens(   R2  Re  R
  R$  R0   R³  R  t   rmh_selt   rmh_sel_i_seqsRæ   t   ii(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt
   optimize_hÓ	  sF    !  
	
 t   set_map_to_valuec           B   s   e  Z d  „  Z d „  Z RS(   c         C   sÏ   t  |  t ƒ  ƒ |  j j ƒ  } t j d |  j j ƒ  d |  j j ƒ  d |  j j	 ƒ  d | d t
 j | j ƒ  |  j ƒ ƒ } t
 j d |  j j ƒ  d | ƒ } | j |  j j ƒ  ƒ |  j j | |  j ƒ |  _ d  S(   NR6  t
   fft_n_realt
   fft_m_realR<  t
   site_radiiRŸ   R  (   R   RE   R   R<  R    t   grid_indices_around_sitesR6  t   map_datat   focusRš  R   R  RŸ   t   atom_radiusRÈ   t   reshapet   accessorRZ  R�  (   RV   R®  R   R°  R�  R<  R¸   t   sel_(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyR`   ù	  s    	!c         C   sJ  |  j  j ƒ  } |  j  j ƒ  } | j ƒ  } | j ƒ  } t t j | ƒ ƒ } t t j | ƒ ƒ } |  j j	 ƒ  } g  t
 | | ƒ D] \ } } t | | ƒ ^ q }	 g  t
 | | ƒ D] \ } } t | | ƒ ^ q± }
 t j j j d |  j j ƒ  d |	 d |
 ƒ } t j j j d | d t d d g d | d	 | d
 |  j d d d d ƒ d  S(   NR˜   t   firstt   lastRb   t
   is_p1_cellt   title_liness    NoneR6  t   griddingRD   t   averageiÿÿÿÿt   standard_deviation(   R   R6  R¹  R  RË  t   listR   R  R®  Rš  RÐ   R   R   R8   t   xplort   mapR¸  R¯  t   writerR<   (   RV   Rb   R6  R¹  t   frac_maxt   frac_mint   n_realR–   R˜   t   gridding_firstt   gridding_lastR¸  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt   write_xplor_map
  s(    22		(   Rç   Rè   R`   RÄ  (    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyR©  ø	  s   	t   shift_originc           B   s   e  Z d  „  Z d „  Z RS(   c         C   sn  | |  _  | |  _ | |  _ t |  _ | j ƒ  d k oQ | j ƒ  d k oQ | j ƒ  } | rj| j ƒ  j	 ƒ  j
 ƒ  d	 k rˆ t d ƒ ‚ n  t |  _ | j ƒ  j ƒ  d  \ } } } | j ƒ  } | j ƒ  }	 |  j  j ƒ  j ƒ  }
 | j ƒ  j ƒ  } |  j j ƒ  |  _ d } d  } x2d g D]'} xd g D]} | d | | d | | d | f } |	 d | |	 d | |	 d | f } | | d | d | | d | d | | d | d } } } |
 t j |
 j ƒ  | | | g ƒ } | |
 } t j d |  j d | ƒ } | G| G| GH| | k r'| } | j ƒ  } q'q'WqW| d  k	 rj|  j  j ƒ  j | ƒ qjn  d  S(
   Ni    i   i   s   Not implementedg    €‡ÃÀi   R®  R¹  (   i    i   (   R
  R5  R®  RH   t   shiftedt   focus_size_1dt   ndt
   is_0_basedR~  R  t   numberR…   R<   R6  RF   Rš  t   originR  RS  t   fractionalization_matrixRÅ  R-   R   t   vec3_doubleRŸ   R    t   map_sum_at_sites_fracRŽ   R[  (   RV   R®  R
  R5  t   shift_neededt   aRC  R  RÃ  Rà  R<  t   fmt   t_bestt   sites_cart_bestt   inc1t   inc2t   N_t   O_t   sxt   syt   szt   sites_cart_shiftedt   sites_frac_shiftedt   t(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyR`   
  sD    				$	''D%
	c         C   sy   |  j  j d d d |  j ƒ d d l m } | j d d d |  j j ƒ  d |  j j ƒ  d	 |  j d
 t	 j
 d g ƒ ƒ d  S(   NRb   s   origin_shifted.pdbR5  iÿÿÿÿ(   R_  s   origin_shifted.ccp4R6  R~  R®  Rc   RA   (   R
  RS  R5  R8   R_  t   write_ccp4_mapR6  R~  R®  R   RŠ  (   RV   R_  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt   show_shiftedB
  s    
		(   Rç   Rè   R`   Rß  (    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyRÅ  
  s   	%t    extract_box_around_model_and_mapc           B   sb   e  Z d
 d
 d
 d
 d
 e d  „ Z d „  Z d d „ Z d d „ Z d „  Z d „  Z	 d d	 „ Z
 RS(   c
   %   	   C   s]  t  |  t ƒ  ƒ | j ƒ  }
 | d  k	 rV |	 rV | j d |
 ƒ } t d | d | ƒ n  | j ƒ  d k oƒ | j ƒ  d k oƒ | j ƒ  } | r| d  k	 r|
 j	 ƒ  j
 ƒ  j ƒ  d k rÆ t d ƒ ‚ n  t d | d	 | d |
 ƒ } | j ƒ  | j } | j } | j d |
 ƒ } | |  _ n  | | g j d  ƒ d k s<t ‚ | d  k	 r�| d  k	 sZt ‚ | j ƒ  j d | ƒ } | j d | d | ƒ |  _ n* | |  _ | | g j d  ƒ d
 k sºt ‚ | j d |  j ƒ } | j ƒ  j ƒ  } | j ƒ  j ƒ  } t j | j ƒ  j | f d ƒ ƒ } t t j | ƒ | ƒ } t t j | ƒ | ƒ } | |  _ | j  ƒ  } g  t! | | ƒ D] \ } } t" | | ƒ ^ qo} g  t! | | ƒ D] \ } } t# | | ƒ ^ q¡} | j  ƒ  } t$ j% | | | ƒ |  _& |  j& j' ƒ  } | d | d | d | d | d
 | d
 f } |  j& j( t j) |  j& j  ƒ  ƒ ƒ d  |  _* | d  k	 rÐt+ | ƒ t+ | ƒ k r�| j  ƒ  | k s“t ‚ t$ j% | | | ƒ |  _* |  j* j( t j) |  j* j  ƒ  ƒ ƒ n  | j ƒ  j, ƒ  } g  } x> t- d ƒ D]0 } | j. | | |  j& j  ƒ  | | | ƒ qõWt/ j d | d | d | d
 | d | d | d f ƒ } | j ƒ  | } | j0 | ƒ } t1 j2 d | d d ƒ }
 | j3 ƒ  }  | j |  ƒ }! t1 j4 |
 ƒ }" | j0 |! ƒ } t5 j6 |" | j7 ƒ  ƒ |  _8 |  j d  k	 r-|  j j |  j ƒ |  _9 |  j9 j: |  j8 ƒ n  | j3 ƒ  }# |  j8 j3 ƒ  }$ |# |$ d |  _; d  S(   NR5  R¼  R½  i    i   i   s   Not implementedR®  R
  i   Rû   t   radiusR¸   RF   i   i   R6  R~  t   P1(   i    i   (   i    i   (<   R   RE   R5  R-   t   extract_xray_structureRÍ  RÇ  RÈ  RÉ  R~  R  RÊ  R…   RÅ  Rß  R
  R®  Rn   Rˆ   t   atom_selection_cacheR¸   t   selection_withinRœ   R¹  R  RË  R   R  R6  t   fractionalizeR»  RÀ  Rš  RÐ   R   R   R    t   copyt   map_boxRË  R±  t   gridt	   map_box_2R‰   RF   Rî   RÏ   R!   t   replace_sites_fracR   Rw  R<  t   special_position_settingsR"   t	   structureR  t   xray_structure_boxt   pdb_hierarchy_boxt   adopt_xray_structuret   shift_to_map_boxed_sites_back(%   RV   R   R®  t   box_cushionR
  t   selection_radiusR)  R¸   t
   map_data_2t-   assert_pdb_hierarchy_and_xray_structure_equalR‡  RN  RÏ  t   osht   xray_structure_selectedR¿  RÀ  t   cushiont   naR–   R˜   RÂ  RÃ  RÐ  t   ot   fsR>   t   abcRæ   t   new_unit_cell_boxt   sites_frac_newRî  R<  R¹  t   spt   sc1t   sc2(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyR`   P
  s”    

$	
		!			!		226"	0%.	3c         C   s;   |  j  d  k	 s t ‚ |  j j d | d |  j j ƒ  ƒ d  S(   NRb   R5  (   R
  R-   Rˆ   Rï  RS  Rî  R5  (   RV   Rb   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyRS  ±
  s    s	   box.xplorc         C   s�   t  j j j d |  j j ƒ  d d d |  j j ƒ  ƒ } t  j j j d | d t d d g d	 |  j j	 ƒ  d
 | d |  j j
 ƒ  d d d d ƒ d  S(   NR˜   R´  i    Rµ  Rb   R¶  R·  s
   Map in boxR6  R¸  RD   R¹  iÿÿÿÿRº  (   i    i    i    (   R8   R¼  R½  R¸  Rè  R¯  R¾  R<   Rî  R6  t	   as_double(   RV   Rb   R¸  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyRÄ  ¶
  s    	s   box.ccp4c         C   sc   d d l  m } | j d | d |  j j ƒ  d |  j j ƒ  d |  j j ƒ  d t j	 d g ƒ ƒ d  S(	   Niÿÿÿÿ(   R_  Rb   R6  R~  R®  Rc   Rf   (
   R8   R_  RÞ  Rî  R6  R~  Rè  R  R   RŠ  (   RV   Rb   R_  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyRÞ  Å
  s    	c         C   s8   |  j  d | d | ƒ } | j d | ƒ } | j ƒ  | S(   NR�   t   resolution_factor(   t   box_map_coefficientst   fft_mapt   apply_sigma_scaling(   RV   R�   R  t   box_map_coeffsR  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt   box_map_coefficients_as_fft_mapÎ
  s
    	
c   
      C   s?  d d l  m } | j g  |  j j ƒ  D] } | ^ q& ƒ } t j |  j t j | j	 ƒ  ƒ j
 |  j j ƒ  ƒ ƒ } | j t j | j	 ƒ  ƒ j
 | j ƒ  ƒ ƒ | j | ƒ } |  j j ƒ  } t j j d | j ƒ  d | j ƒ  j ƒ  d t d | d | d t d	 t ƒ } t j d
 | d t d | j ƒ  ƒ j d | j ƒ  ƒ }	 |	 S(   Niÿÿÿÿ(   t   fftpackR6  t   space_group_typeR¯   R�   t   complex_mapt   conjugate_flagt$   discard_indices_affected_by_aliasingR5  R”   RD   (   t   scitbxR	  t   real_to_complex_3dRè  Rš  R    Rç  R   Ré  t   m_realt	   set_focusR¯  R±  RÁ  t   forwardRî  R5  R  t   from_mapR6  R~  R  RH   R<   R   RÛ   t   miller_indicesRt   RD   (
   RV   R�   R  R	  Ræ   t   fftRè  R‡  t   box_structure_factorsR  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyR  Õ
  s*    +0+		s   box.mtzc         C   sY   |  j  d | d | ƒ } | d  k	 rU | j d d ƒ } | j ƒ  } | j d | ƒ n  | S(   NR�   R  Ré  t   BoxMapRb   (   R  R-   Rë  Rí  RI  (   RV   R�   R  Rb   R  Rî  Rí  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt   map_coefficientsì
  s    	N(   Rç   Rè   R-   R<   R`   RS  RÄ  RÞ  R  R  R  (    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyRà  O
  s   X				t&   experimental_data_target_and_gradientsc           B   sY   e  Z d d  „ Z d d „ Z d „  Z d „  Z d „  Z d d „ Z d d d d „ Z	 RS(   c         C   sa   | |  _  |  j  j j ƒ  j ƒ  } t j | t ƒ j ƒ  |  _ |  j  j	 d | ƒ d t ƒ |  _	 d  S(   Nt
   alpha_betat   compute_gradients(
   R2  R   R  RŸ   R   RÈ   R<   R  R´   t   target_functor(   RV   R2  R  RŸ   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyR`   ö
  s
    	c         C   s>   |  j  j d | d t ƒ |  j  j d | ƒ d t ƒ |  _ d  S(   NR   t   update_f_calcR  R  (   R2  t   update_xray_structureR<   R  (   RV   R   R  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyR  ý
  s    c         C   sN   |  j  j j ƒ  j d t ƒ |  j  j j ƒ  j d |  j ƒ |  j j d t	 ƒ S(   Nt   stateR  t	   occupancy(
   R2  R   R  t   flags_set_gradsRH   t   flags_set_grad_occupancyR´   R  t   gradients_wrt_atomic_parametersR<   (   RV   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt   grad_occ  s    
c         C   s)   |  j  j j ƒ  j d t ƒ |  j j ƒ  S(   NR  (   R2  R   R  R!  RH   R  t   d_target_d_site_cart(   RV   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt   grad_sites_cart	  s    c         C   s   |  j  j ƒ  S(   N(   R  t   target_work(   RV   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyRü    s    c         C   s;  | d  k r t j } n  | d |  j j |  j ƒ  f IJ| d |  j j ƒ  |  j j ƒ  f IJ|  j ƒ  } |  j	 ƒ  } |  j j
 j ƒ  } | d IJ| d IJd } x’ t |  j j
 j ƒ  ƒ D]x \ } } | | | | d | | d | | d | j t j | j ƒ | | | | d | | d | | d f	 IJq» Wd  S(	   Ns!   Target type and value: %s %-15.6fs   r_work=%6.4f r_free=%6.4fs3                                             GradientssL                   sites_cart   occ   b_iso      occ                 sites_carts5   %8.3f %8.3f %8.3f %5.2f %7.2f %8.4f %8.4f %8.4f %8.4fi    i   i   (   R-   R\  RX  R2  R  Rü  RF  Rž  R$  R&  R   R<  R  R  R   R   RB  t   u_iso(   RV   R0   t   got   gsR<  R’  Ræ   R  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyRU    s     

%(c         C   sY  | | g } | j  d  ƒ d k s' t ‚ | d  k rQ | j  d  ƒ d k sl t ‚ n | j  d  ƒ d k sl t ‚ | j  d  ƒ d k r– | d  k s– t ‚ n  g  } |  j ƒ  } | d  k rt d |  j j d | j d |  j j j ƒ  ƒ d t	 d t	 d t	 d	 t
 d
 t	 ƒ | j d | ƒ } x=| D]ö } | j | ƒ } t | j ƒ  ƒ }	 t |	 ƒ d k s[t ‚ |	 d }
 |	 t |	 ƒ d } t | j ƒ  ƒ } t | ƒ d k s£t ‚ | d j } d j g  | |
 j | j g D] } | j ƒ  ^ qÌƒ } t j | j | ƒ ƒ } | j | | g ƒ qWn< x9 | D]1 } t j | j | ƒ ƒ } | j d  | g ƒ q W| S(   Ni    i   R¼  R½  R5  R¾  R¿  RP  RÀ  RÁ  t   residues_per_chunki   Rç  (   i    i   (   Rn   R-   Rˆ   R$  RÍ  R2  R   Rã  R5  RH   R<   t   chunk_selectionsRœ   R»  R  R‰   R  RÓ  RÑ   RÔ  R  R   R?  RÏ   (   RV   R
  t   residues_per_windowRð   t   pairR4  t	   occ_gradsR´   t   ht   rgst   rg1t   rg2R  t   chain_idRæ   t   info_strt   group_occ_grad(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt   group_occupancy_grads   sJ      			
7N(
   Rç   Rè   R-   R`   R  R$  R&  Rü  RU  R7  (    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyR  õ
  s   			t   statesc           B   s#   e  Z d  „  Z d „  Z d „  Z RS(   c         C   s;   t  |  t ƒ  ƒ d |  _ t j j j ƒ  |  _ g  |  _ d  S(   Ni    (   R   RE   t   counterR8   R   R«  t   roott   sites_carts(   RV   R   R
  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyR`   K  s    	c         C   s’   |  j  j | ƒ |  j j ƒ  } |  j j d | ƒ } | j | ƒ | j ƒ  } | d j ƒ  } t	 |  j
 ƒ | _ |  j j | ƒ |  j
 d 7_
 d  S(   Nt	   new_sitesi    i   (   R;  RÏ   R
  RŽ   R   t   replace_sites_cartRð  R  t   detached_copyR†   R9  RÓ  R:  t   append_model(   RV   R<  t   phRN  R  t   md(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyRÝ   Q  s    c         C   s   |  j  j d | ƒ d  S(   NRb   (   R:  RS  (   RV   Rb   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyRI  \  s    (   Rç   Rè   R`   RÝ   RI  (    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyR8  J  s   		g      Ð?c         C   sj   | j  ƒ  d  \ } } } |  j ƒ  \ } } } | | | | | | | | | }	 }
 } t |	 |
 | ƒ S(   Ni   (   RF   Rš  RË  (   R®  R6  R  RÐ  RC  R  t   nxt   nyt   nzRä  Rå  t   d3(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt   d_min_from_map_  s    g      @c      	   C   sa   t  d |  d | j ƒ  d | ƒ } t j d | d t d | ƒ } | j d |  d t d t d	 t ƒ S(
   NR®  R6  R  R5  R¯   R�   R½  t	   use_scalet   use_sg(   RF  R6  R   t	   build_setRH   t   structure_factors_from_mapR<   (   R®  t   unit_cell_lengthsRÁ  R5  R  t   d_min_guess_from_mapt   complete_set(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyRJ  h  s    			t   f_000c           B   s   e  Z d d d d  d „ Z RS(   gffffffÖ?c         C   sð   | d  k	 r- | d k r$ | d k s- t ‚ n  d } | d  k	 r  | j ƒ  j ƒ  } | | j ƒ  7} | d  k r  d d  l } | j j d | d d ƒ j j } q  n  | d  k	 rÁ | | | | 7} n  | d k rÚ | | } n  | |  _ | |  _	 d  S(   Ni    i   iÿÿÿÿR   R�   (
   R-   Rˆ   R6  t   volumeRN  t   mmtbx.maskst   maskst   asu_maskt   contact_surface_fractiont   solvent_fraction(   RV   R   t   unit_cell_volumeRT  t   mean_solvent_densityRN  R  (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyR`   w  s     !	N(   Rç   Rè   R-   R`   (    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyRN  v  s   t$   detect_hydrogen_nomenclature_problemc           B   s   e  Z d  Z d d „ Z RS(   s  
  This allows us to avoid the following problems:
  1) a bug in automatic linking which deletes the monomer library definition
     for HD22 for an N-linked Asn, even though it may not actually be replaced
     by a sugar link.
  2) general issues with hydrogen nomenclature

  Attributes
  ----------
  bad_hydrogens: a list of problematic atom ID strings
  n_asn_hd22: number of inappropriate ASN HD22 atoms
  n_hydrogen: number of hydrogens missing geometry restraints
  n_other: number of non-hydrogen atoms missing geometry restraints
  c         C   s¸  | g t  | ƒ } d d  l } | j j j ƒ  } | j j j ƒ  } | j j j j ƒ  } t | j	 _
 | j j j d | d | d t d t d t ƒ  ƒ } | j }	 |	 j }
 |	 j } g  |  _ d |  _ d |  _ d |  _ | j ƒ  d k r´| j |
 ƒ } xº | D]¯ } | j ƒ  GH| j ƒ  } | j d k ra| j d	 k ra|  j d
 7_ |  j j | j ƒ  ƒ qþ | j j ƒ  d k rž|  j d
 7_ |  j j | j ƒ  ƒ qþ |  j d
 7_ qþ Wn  d  S(   NiÿÿÿÿR^  R�   R  R‚  R0   i    t   HD22t   ASNi   Rø   (   R»  t   mmtbx.monomer_library.serverR   Ri  Rf  Rg  RC  RG   R<   t   automatic_linkingt   link_allt   runRH   R
   Rú   R  t   nonbonded_energy_type_registryt   bad_hydrogenst
   n_asn_hd22t
   n_hydrogent   n_otherR  t   get_unknown_atomst   quotet   fetch_labelsR©  RÕ  RÏ   t   id_strR  R  (   RV   RŽ  t	   cif_filesR^  R  Re  Rf  R�   Rk  Rú   R  t   nb_regt   unknown_atomsR  Rc   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyR`   ™  s>    							(    (   Rç   Rè   Ré   R`   (    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyRW  Š  s   (“   Ré   t
   __future__R    t   mmtbx.scalingR   R(  R   R   R   t   cctbx.xray.structure_factorst   cctbx.array_familyR   t   libtbx.utilsR   R   R   R	   R
   t
   iotbx.philR8   R   R   R   t	   iotbx.pdbR   R   t	   cStringIOR   R   R  R   t(   mmtbx.monomer_library.pdb_interpretationRZ  R   R   R   RŠ   R   t   libtbx.str_utilsR   R   R  R\  Rà   RÎ  R   t   mmtbx.refinementR   t   mmtbx.twinningR   t+   mmtbx.bulk_solvent.bulk_solvent_and_scalingR&   RI  RB  t   mmtbx.f_modelt   mmtbx.restraintst   mmtbx.tls.toolsR   t   mmtbx.command_line.fmodelR   R=  t   libtbx.callbackst   libtbx.math_utilsR   R   R    R!   R"   t   iotbx.cns.miller_arrayR#   t   boost.pythont   boostt   pythont
   import_extt	   utils_extR$   t   extR2   R6   t   data_and_flags_str_part1t   data_and_flags_str_part2t   generate_r_free_params_strR;   t   xray_data_strt   neutron_data_strR-   R?   t   objectR@   t   map_coefficents_params_strt   experimental_phases_params_strR9   R:   t   experimental_phases_paramsR<   Rí   t
   pdb_paramsR÷   RH   R1  R  RS  RW  RX  Rb  Rd  Rl  t
   cif_paramsRm  R§  R·  RÍ  RÜ  Rß  Rí  Rî  Rø  R&  t#   sf_and_grads_accuracy_master_paramsRG   R4  R[  R\  RŽ  R¯  R¾  R¿  R  RG  Rm  Ry  R{  R~  R„  R†  Rq  Rœ  R¨  R©  RÅ  Rà  R  R8  RF  RJ  RN  RW  (    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/utils/__init__.pyt   <module>   sR  ($
		@(	

ÿ Ð	(	
		^3	
			�			3		05'd¡4.	$²§I						!	$$3¦U
