ó
Ò™xTc           @   sA  d  d l  m Z d  d l j j Z d  d l m Z d  d l m Z d  d l	 j
 j Z d  d l 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 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 Z d  d l  m! Z! m" Z" m# Z# m$ Z$ d  d l% m& Z& m' Z' d  d l( m) Z) m* Z* d  d l% m+ Z+ d  d l% m, Z, d  d l- Z% d  d l. m/ Z/ d  d l0 Z0 d  d l1 Z1 d  d l2 Z2 d  d l3 Z3 d  d l4 Z4 d  d l5 Z5 d  d l6 Z6 e j7 j8 d ƒ Z9 e j: j; d d d e< d e< ƒ Z= e j7 j8 e= d d e< ƒj> d e9 ƒ Z? d e@ f d „  ƒ  YZA d e@ f d „  ƒ  YZB d e@ f d „  ƒ  YZC d  e@ f d! „  ƒ  YZD d" „  ZE d# „  ZF d$ „  ZG d% eH eI e< d& „ ZJ d' e@ f d( „  ƒ  YZK d) e' f d* „  ƒ  YZL d+ e' f d, „  ƒ  YZM d- e+ jN f d. „  ƒ  YZO d/ „  ZP d S(0   iÿÿÿÿ(   t   divisionN(   t   ensemble_utils(   t   ensemble_cd(   t   iotbx_option_parser(   t   pdb(   t   geometry_restraints(   t   flex(   t   miller(   t   adptbx(   t   xray(   t   Sorryt   user_plus_sys_timet	   multi_outt   show_total_time(   t   adopt_init_argst   slots_getstate_setstate(   t   format_valuet   make_header(   t   runtime_utils(   t   easy_mp(   t   StringIOs  
ensemble_refinement.mask.ignore_hydrogens = False
ensemble_refinement.mask.n_radial_shells = 1
ensemble_refinement.mask.radial_shell_width = 1.5
ensemble_refinement.cartesian_dynamics.number_of_steps = 10
ensemble_refinement.ensemble_ordered_solvent.b_iso_min = 0.0
ensemble_refinement.ensemble_ordered_solvent.b_iso_max = 100.0
ensemble_refinement.ensemble_ordered_solvent.find_peaks.map_next_to_model.max_model_peak_dist = 3.0
ensemble_refinement.ensemble_ordered_solvent.find_peaks.map_next_to_model.use_hydrogens = False
t   phil_stringt    t   enable_experimental_phasest   as_phil_strings/  
ensemble_refinement {
  cartesian_dynamics
    .style = menu_item auto_align box
  {
    include scope mmtbx.dynamics.cartesian_dynamics.master_params
    protein_thermostat = True
      .type = bool
      .help = Use protein atoms thermostat
  }
  update_sigmaa_rfree = 0.001
    .type = float
    .help = test function
  ensemble_reduction = True
    .type = bool
    .help = 'Find miminium number of structures to reproduce simulation R-values'
  verbose = -1
    .type = int
  output_file_prefix = None
    .type = str
    .help = 'Prefix for all output files'
# TODO
#  write_mmcif_file = False
#    .type = bool
  gzip_final_model = True
    .type = bool
    .style = hidden
  random_seed = 2679941
    .type = int
    .help = 'Random seed'
  nproc = 1
    .type = int
    .short_caption = Number of processors
    .style = renderer:draw_nproc_widget
  tx = None
    .type = float
    .help = 'Relaxation time (ps)'
    .short_caption = Relaxation time (ps)
  equilibrium_n_tx = 10
    .type = int
    .help = 'Length of equilibration period, n times tx'
    .short_caption = Length of equilibration period
  acquisition_block_n_tx = 2
    .type = int
    .help = 'Length of acquisition block, n times tx'
    .short_caption = Length of acquisition block
  number_of_acquisition_periods = 10
    .type = int
    .help = 'Number of acquisition periods'
  pdb_stored_per_block = 50
    .type = int
    .help = 'Number of model coordinates stored per acquisition block'
    .short_caption = Models stored per acquisition block
  wxray_coupled_tbath = True
    .type = bool
    .help = 'Use temperature control wxray'
    .short_caption = Use temperature control X-ray weight
  wxray_coupled_tbath_offset = 5.0
    .type = float
    .help = 'Temperature offset, increasing offset increases wxray'
    .short_caption = Temperature ofset
  wxray = 1.0
    .type = float
    .help = 'Multiplier for xray weighting; used if wxray_coupled_tbath = Flase'
    .short_caption = X-ray weight
  tls_group_selections = None
    .type = atom_selection
    .multiple = True
    .help = 'TLS groups to use for TLS fitting (TLS details in PDB header not used)'
    .style = use_list
  ptls = 0.80
    .type = floats
    .optional = False
    .help = 'The fraction of atoms to include in TLS fitting'
    .short_caption = Fraction of atoms to include in TLS fitting
    .style = bold
  max_ptls_cycles = 25
    .type = int
    .help = 'Maximum cycles to use in TLS fitting; TLS will stop prior to this if convergence is reached'
    .short_caption = Max. number of cycles of TLS fitting
  isotropic_b_factor_model = False
    .type = bool
    .help = 'Use isotropic B-factor model instead of TLS'
    .short_caption = Use isotropic B-factor model
  pwilson = 0.8
    .type = float
    .help = 'Scale factor for isotropic b-factor model: all atoms = Bwilson * pwilson'
    .short_caption = Scale factor for isotropic b-factor model
  set_occupancies = False
    .type = bool
    .help = 'Set all atoms aoccupancy to 1.0'
    .short_caption = Reset occupancies to 1.0
  target_name = *ml mlhl ls_wunit_k1_fixed ls_wunit_k1
    .type = choice
    .short_caption = Refinement target
    .help = 'Choices for refinement target'
  remove_alt_conf_from_input_pdb = True
    .type = bool
    .help = 'Removes any alternative conformations if present in input PDB model'
  scale_wrt_n_calc_start = False
    .type = bool
    .help = 'Scale <Ncalc> to starting Ncalc'
    .short_caption = Scale <Ncalc> to starting Ncalc
  show_wilson_plot = False
    .type = bool
    .help = 'Print Wilson plot during simulation'
  output_running_kinetic_energy_in_occupancy_column = False
    .type = bool
    .help = 'Output PDB file contains running kinetic energy in place of occupancy'
  ordered_solvent_update = True
    .type = bool
    .help = 'Ordered water molecules automatically updated every nth macro cycle'
  ordered_solvent_update_cycle = 25
    .type = int
    .help = 'Number of macro-cycles per ordered solvent update'
    .short_caption = Solvent update cycles
  harmonic_restraints
    .style = menu_item auto_align box
  {
    selections = None
      .type = atom_selection
      .help = 'Atoms selections to apply harmonic restraints'
    weight = 0.001
      .type = float
      .help = 'Harmonic restraints weight'
    slack = 1.0
      .type = float
      .help = 'Harmonic restraints slack distance'
  }
  electron_density_maps
    .style = menu_item
  {
    apply_default_maps = True
      .type = bool
    include scope mmtbx.maps.map_coeff_params_str
  }
  mask
    .short_caption = Bulk solvent mask
    .style = menu_item auto_align box
  {
    include scope mmtbx.masks.mask_master_params
  }
  ensemble_ordered_solvent
    .style = menu_item auto_align box
  {
    diff_map_cutoff = 2.5
      .type = float
    e_map_cutoff_keep = 0.5
      .type = float
    e_map_cutoff_find = 0.5
      .type = float
    tolerance = 0.9
      .type = float
    ordered_solvent_map_to_model = True
      .type = bool
    include scope mmtbx.solvent.ordered_solvent.output_params_str
    primary_map_type = mFo-DFmodel
      .type=str
    primary_map_cutoff = 3.0
      .type=float
    secondary_map_type = 2mFo-DFmodel
      .type=str
    secondary_map_cutoff_keep = 1.0
      .type=float
    secondary_map_cutoff_find = 1.0
      .type=float
    include scope mmtbx.solvent.ordered_solvent.h_bond_params_str
    include scope mmtbx.solvent.ordered_solvent.adp_occ_params_str
    refine_occupancies = False
      .type = bool
      .help = Refine solvent occupancies.
      .expert_level = 1
    add_hydrogens = False
      .type = bool
      .help = Adds hydrogens to water molecules (except those on special positions)
    refilter = True
      .type = bool
    temperature = 300
      .type = float
      .help = Target temperature for random velocity assignment
    seed = 343534534
      .type = int
      .help = Fixes the random seed for velocity assignment
    preserved_solvent_minimum_distance = 7.0
      .type = float
    find_peaks {
      include scope mmtbx.find_peaks.master_params
    }
  }
  include scope mmtbx.geometry_restraints.external.external_energy_params_str
}
refinement.geometry_restraints.edits
  .short_caption = Edit geometry restraints
  .style = menu_item box auto_align
{
  include scope mmtbx.monomer_library.pdb_interpretation.geometry_restraints_edits_str
}
gui
  .help = Phenix GUI parameters, not used in command-line program
{
  include scope libtbx.phil.interface.tracking_params
  output_dir = None
    .type = path
    .short_caption = Output directory
    .style = output_dir
}
extra_restraints_file = None
  .type = path
  .short_caption = Custom geometry restraints
  .help = File containing custom geometry restraints, using the same format     as phenix.refine.  On the command line this can be specified directly     as a command-line argument, but this parameter is used by the Phenix GUI.
  .style = input_file file_type:phil
t   process_includest   sourcet	   er_picklec           B   s   e  Z d  „  Z RS(   c         C   s    t  j | t j | d ƒ ƒ d  S(   Nt   wb(   t   cPicklet   dumpt   gzipt   open(   t   selft   pickle_objectt   pickle_filename(    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyt   __init__  s    (   t   __name__t
   __module__R$   (    (    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyR     s   t   ensemble_refinement_datac           B   sb   e  Z d d d d d d d  d  d d d d g  g  g  d d d g  d d d d d d d d d „ Z RS(   i    gü©ñÒMbP?g      ð?c         C   s   t  |  t ƒ  ƒ d  S(   N(   R   t   locals(   R!   t   f_calc_runningt   f_calc_data_totalt   f_calc_data_currentt   f_mask_runningt   f_mask_currentt   f_mask_totalt   total_SF_cntrt   total_SF_cntr_maskt   fix_scale_factort   non_solvent_tempt   solvent_tempt   system_tempt   xray_structurest   pdb_hierarchyst   xray_structures_diff_mapt   seedt
   velocitiest   ke_protein_runningt   ke_pdbt   geo_grad_rmst   xray_grad_rmst   solvent_selt   all_selt   er_harmonic_restraints_infot   er_harmonic_restraints_weightt   er_harmonic_restraints_slackt   macro_cycle(    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyR$     s    N(   R%   R&   t   NoneR$   (    (    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyR'     s6   t   er_tls_managerc           B   s#   e  Z d d d d d d d  „ Z RS(   c         C   s   t  |  t ƒ  ƒ d  S(   N(   R   R(   (   R!   t   tls_selection_strings_no_solt"   tls_selection_strings_no_sol_no_hdt   tls_selections_with_solt   tls_selections_no_solt   tls_selections_no_sol_no_hdt   tls_operators(    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyR$   3  s    N(   R%   R&   RD   R$   (    (    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyRE   2  s   t   run_ensemble_refinementc           B   sþ   e  Z e d  „ Z e d „ Z d e d „ Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z e d
 „ Z e d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d d „ Z RS(   c	      )   C   s[  t  |  t ƒ  ƒ |  j j d} k r. t |  _ n	 t |  _ |  j j sR d |  j _ n  |  j j	 |  _	 |  j j
 j |  j j _ t j d |  ƒ |  _ d  |  _ d  |  _ d |  _ d  |  _ g  |  _ t |  _ t |  _ |  j j
 |  _ t j j j j ƒ  |  _ |  j j d k rd |  j _ n |  j j |  j _ |  j j d  k rµ| d IJ| d IJt  d d	 |  j! j" ƒ  j# ƒ  d
 d ƒ |  j _ | d I|  j! j" ƒ  j# ƒ  IJ| d I|  j j IJn  |  j j |  j j$ |  j j% |  _& t' d d |  j( ƒ| d I|  j j% IJ| d I|  j j IJ| d I|  j& IJt) |  j& |  j j* ƒ |  _+ t) |  j& |  j j, ƒ |  _- t) |  j+ |  j- |  j j. ƒ |  _/ | d IJ| d I|  j j* IJ| d I|  j+ IJ| d I|  j+ |  j j% |  j j$ IJ| d IJ| d I|  j j, IJ| d I|  j- IJ| d I|  j- |  j j% |  j j$ IJ| d IJ| d I|  j j* |  j j. |  j j, IJ| d I|  j/ IJ|  j/ |  j j% |  j j$ |  _0 | d I|  j0 IJ| d IJd |  _1 t2 |  j- |  j+ |  j- |  j/ |  j- ƒ |  _3 t4 t) |  j- |  j j5 ƒ d ƒ |  _6 t7 ƒ  |  _8 |  j! |  _9 d  |  _: d  |  _; d  |  _< |  j j= |  j8 _> i  |  _? |  j9 j@ ƒ  d jA d |  j9 j@ ƒ  d jB ƒ  d ƒ jC ƒ  |  _D |  jE jF |  j9 _F |  j9 jF |  jE jF k sÔtG ‚ |  jE jH |  _H |  jI ƒ  |  jE jJ d d d t d |  j( ƒ |  jK ƒ  |  j jL r¼|  jM d |  j9 j" ƒ  jB ƒ  d d  ƒ |  jM d |  j9 jN ƒ  jB ƒ  d d! ƒ |  jM d |  j9 jO ƒ  jB ƒ  d d" ƒ |  jM d |  j9 jP ƒ  jB ƒ  d d# ƒ n  |  j9 jQ d$ d% d& d' ƒ jR d |  j( ƒ |  j j d~ k r³|  j jS r
t' d( d |  j( ƒ|  j9 jT d) t ƒ |  j9 jU }	 |  j9 jV }
 |  jW d* |
 d+ |	 ƒ |  _X |  jX |  _Y |  jX |  _Z |  j9 jV jC ƒ  |  _[ t4 d t) |  j& d, ƒ ƒ |  _\ |  j( d- j] |  j& ƒ IJ|  j( d. j] |  j\ ƒ IJ|  j9 j^ ƒ  |  __ |  j9 j^ ƒ  |  _` |  ja ƒ  nU t' d/ d |  j( ƒ|  j9 jT d) t ƒ |  j( d0 IJ|  j( d1 j] tb |  j9 jV ƒ ƒ IJ|  jM d |  j9 jU d d2 ƒ |  jM d |  j9 jV d d3 ƒ |  j( d4 d5 d6 d7 IJn  tc ƒ  |  _< |  jd d8 |  j je ƒ |  jf d9 |  jE ƒ |  jg ƒ  |  j jh r@t' d: d |  j( ƒ|  jE jF jh d; d	 ƒ |  jE ji d |  j( ƒ n  |  j jL rã|  jM d |  j9 j" ƒ  jB ƒ  d d< ƒ |  jM d |  j9 jN ƒ  jB ƒ  d d= ƒ |  jM d |  j9 jO ƒ  jB ƒ  d d> ƒ |  jM d |  j9 jP ƒ  jB ƒ  d d? ƒ n  |  j9 jN ƒ  jB ƒ  jC ƒ  |  j8 _j |  j9 jN ƒ  jC ƒ  |  _ |  j j d k rp	|  j9 jk ƒ  jk ƒ  jB ƒ  |  _l |  j9 jm ƒ  |  _n |  jl |  j9 _o n  |  j jp jq d  k	 r’	|  jr ƒ  n  t' d@ d |  j( ƒxb|  j |  j/ k r	|  j |  j8 _ |  j j$ |  j j% |  j |  _s t rf
|  j d, d k rf
|  j( dA I|  j8 jt IJ|  j( dB I|  j8 ju IJ|  j( dC I|  j8 jv IJ|  j( dD I|  j	 IJn  |  j9 j d€ k rè
|  j |  j+ k  rè
|  j jS r¹
|  j |  j\ d k r¹
|  ja ƒ  qå
|  j t) |  j& ƒ d k rå
|  ja ƒ  qå
qè
n  |  j jw r)|  j d k s|  j |  j jx d k r)|  jw ƒ  n  |  jE jF jy ƒ  } |  j9 jF |  jE jF k sYtG ‚ |  j jz d k rŸ|  j d k s�|  j d% d k r–d } q¥dE } n dE } t{ j
 dF |  jE jF dG |  jE j| dH |  j j |  j j dI |  j j} dJ |  j j% dK |  j j~ dL |  j j$ dM |  j j dN |  j9 dO |  j	 dP d	 dQ d  dR d dS |  j dT |  j dU |  j dV t dW |  j8 dX | dY |  j( ƒ } t |  _ t |  _ |  j€ ƒ  |  j jz d k rÉ|  j dZ d k rÉ|  j j� ƒ  n  |  j9 j‚ d[ |  jE jF dV t d\ t d] t ƒ |  j9 j@ ƒ  d jB ƒ  jC ƒ  |  j8 _ƒ |  j9 jN ƒ  jB ƒ  jC ƒ  |  j8 _„ |  j8 j… d  k r€|  j9 j@ ƒ  d jB ƒ  jC ƒ  |  j8 _… d |  j8 _† n= |  j8 j… |  j9 j@ ƒ  d jB ƒ  jC ƒ  7_… |  j8 j† d 7_† |  j8 j‡ d  k rÿ|  j9 jN ƒ  jB ƒ  jC ƒ  |  j8 _‡ d |  j8 _ˆ n9 |  j8 j‡ |  j9 jN ƒ  jB ƒ  jC ƒ  7_‡ |  j8 jˆ d 7_ˆ |  j j d k rzt‰ jŠ |  j j$ |  j j% |  j j ƒ |  _‹ n	 d |  _‹ |  j‹ |  j8 jj d |  j‹ |  j9 jN ƒ  jB ƒ  jC ƒ  |  j8 _j |  j jA d |  j8 jj ƒ |  _ |  j d k r|  j9 j@ ƒ  d jB ƒ  jC ƒ  |  j8 _Œ n; |  j‹ |  j8 jŒ d |  j‹ |  j9 j@ ƒ  d jB ƒ  |  j8 _Œ |  jD jA d |  j8 jŒ ƒ jC ƒ  |  _� |  j9 jŽ d^ |  j d_ |  j� ƒ |  jD jA d |  j8 j… |  j8 j† ƒ jC ƒ  } |  j: d  k rA|  j9 jC ƒ  |  _: |  j: jŽ d^ |  jD jA d |  j8 j‡ |  j8 jˆ ƒ d_ | ƒ |  j8 j� d  k	 ry|  j8 j� |  j: _� qyn8 |  j: jŽ d^ |  jD jA d |  j8 j‡ |  j8 jˆ ƒ d_ | ƒ |  jD jA d |  j8 jƒ ƒ } |  j; d  k r|  j9 jC ƒ  |  _; |  j; jŽ d^ |  jD jA d |  j8 j„ ƒ d_ | ƒ |  j8 j� d  k	 r;|  j8 j� |  j; _� q;n. |  j; jŽ d^ |  jD jA d |  j8 j„ ƒ d_ | ƒ |  j j d� k r”|  j |  j+ k  r”|  j9 jm ƒ  |  jn |  j j‘ k  r‘|  j’ ƒ  q‘q”n  |  j jL rS|  j t) |  j& ƒ d k rS|  jM d |  j9 j" ƒ  jB ƒ  d d` ƒ |  jM d |  j9 jN ƒ  jB ƒ  d da ƒ |  jM d |  j9 jO ƒ  jB ƒ  d db ƒ |  jM d |  j9 jP ƒ  jB ƒ  d dc ƒ n  |  j j r+|  j dd k  rzde |  _	 q+|  j |  j+ k  r+|  j j d k r§d } n< t“ |  js |  j j ƒ } t‰ jŠ |  j j$ |  j j% | ƒ } |  j	 t4 df |  j j |  j8 j” ƒ } | |  j	 d | | |  _	 q+n  |  j |  j6 d k r4|  j |  j+ k r4|  j8 j• j– |  jE jF jy ƒ  ƒ |  j8 j— j– |  jE jH ƒ  jC ƒ  ƒ |  j8 j˜ d  k rÚ|  j8 j™ j– tš j› |  jE jF jœ ƒ  j� ƒ  d ƒ ƒ q4tš j› |  jE jF jœ ƒ  j� ƒ  d ƒ } | jž |  jE jŸ ƒ  |  j8 j˜ ƒ |  j8 j™ j– | ƒ n  | j  dg |  jE jF ƒ j¡ ƒ  j¢ d	 k rÃ|  j( dh IJ|  j( di IJ|  j( dj IJ|  j( dk IJ|  j( dl j] | j  dg |  jE jF ƒ j¡ ƒ  j¢ ƒ IJn  |  j9 j£ ƒ  dm k rçt¤ dn ƒ ‚ n  |  j d k s	|  j do d k r3|  j( dp IJ|  j( dq IJ|  j( dr IJn  |  j( ds j] |  j |  js d% |  js |  j0 d% |  j; j£ ƒ  d% |  j; jm ƒ  d% |  j9 j£ ƒ  d% |  j9 jm ƒ  d% |  j: j£ ƒ  d% |  j: jm ƒ  |  j8 j” |  j8 ju |  j8 jv |  j	 ƒ IJ|  j jz d k r;|  j d k s+|  j d% d k s+|  j |  j/ k r;|  j¥ ƒ  q;n  |  j j. d k ro|  j |  j3 k ro|  j¦ ƒ  qon  |  j |  j+ k rŽ|  j§ ƒ  n  |  jE jF | j¨ k s©tG ‚ |  j9 jF | j¨ k sÄtG ‚ |  j t k r÷|  j9 j^ ƒ  |  j8 j� k s÷tG ‚ n  |  j d 7_ q¨	W|  j/ |  _ |  j j. d k r5|  j© ƒ  n= d |  j: _� |  j: jª dX |  j jz d |  j( dt |  j du t ƒ |  j j« rŽ|  j j« ƒ  n  d |  j: _� |  j¥ ƒ  |  j: jª dX |  j jz d |  j( dt |  j du t ƒ |  j¥ ƒ  |  j( dv |  j: j£ ƒ  |  j: jm ƒ  |  j: jm ƒ  |  j: j£ ƒ  f IJ|  j( dw |  j: j¬ ƒ  |  j: j­ ƒ  |  j: j­ ƒ  |  j: j¬ ƒ  f IJ|  j: jQ d$ d% d& d' ƒ } | j® d |  j( ƒ | jR d |  j( ƒ |  j jL rG|  jM d |  j: j" ƒ  jB ƒ  d dx ƒ |  jM d |  j: jN ƒ  jB ƒ  d dy ƒ |  jM d |  j: jO ƒ  jB ƒ  d dz ƒ |  jM d |  j: jP ƒ  jB ƒ  d d{ ƒ n  |  j¯ d| | ƒ d  S(‚   Nt   mlt   mlhlg        t   ensemble_obji   s-   
Automatically set Tx (parameter not defined)s   Tx          :  2(1/dmin)**2g       @g      ð?i   s   Dmin        : s   Set Tx      : s   Simulation length:t   outs*   Number of time steps per macro cycle    : s*   Tx                                      : s*   Number macro cycles per Tx period       : s   
Equilibrations       Number Tx periods    : s       Number macro cycles  : s       Time (ps)            : s   
Acquisition blocks   
Simulation totals(       Total = Equilibration + nAcquisitioni    t   datat   messages   Starting modelt	   ignore_hdt   miller_datat   headers
   Fobs inputs   Fcalc inputs   Fmodel inputt	   Fmodel_k1t   free_reflections_per_binid   t   max_number_of_binsiç  s(   Calculate Ncalc and restrain to scale knt   update_nobs_ncalct   targett	   referencei
   s)   Number macro cycles per tx     : {0:5.0f}s)   Number macro cycles per update : {0:5.0f}s    Calculate and fix scale of Ncalcs   Fix Ncalc scale          : Trues#   Sum current Ncalc        : {0:5.3f}s   Nobs references   Ncalc referencet   |t   -iM   s   |
t   tls_group_selection_stringst   input_models   Set occupancies to 1.0t   values
   Fobs starts   Fcalc starts   Fmodel starts   Fmodel_k1 starts   Start simulations   Sys temp  : s   Xray grad : s   Geo grad  : s   Wx        : iÿÿÿÿt	   structuret   restraints_managert   temperaturet   protein_thermostatt   n_stepst   n_printt	   time_stept    initial_velocities_zero_fractiont   fmodelt   xray_target_weightt   chem_target_weightt   xray_structure_last_updatedt   shift_updatet   xray_gradientt   reset_velocitiest   stop_cm_motiont   update_f_calct   er_datat   verboset   logiô  t   xray_structuret   update_f_maskt   force_update_f_maskt   f_calct   f_masks   Fobs runnings   Fcalc runnings   Fmodel runnings   Fmodel_k1 runningi   g      @g{®Gáz„?t   others
   

WARNING:s@   Macro cycle too long, max atomic deviation w.r.t. previous cycles   greater than 1.0As0   Reduce params.cartesian_dynamics.number_of_stepss   Max deviation : {0:1.3f}g      è?s'   Simulation aborted, running Rfree > 75%i2   sQ   
________________________________________________________________________________sP       MC        Time     |  Current  |  Rolling  |   Total   | Temp |  Grad Wxray sP             (ps)     (%) |   Rw   Rf |   Rw   Rf |   Rw   Rf |  (K) |   X/G       sv   ~{0:5d} {1:7.2f} {2:7.2f} | {3:4.1f} {4:4.1f} | {5:4.1f} {6:4.1f} | {7:4.1f} {8:4.1f} | {9:4.0f} | {10:5.2f} {11:5.2f}t   paramst   optimize_masks/   FINAL Rwork = %6.4f Rfree = %6.4f Rf/Rw = %6.4fs/   Final Twork = %6.4f Tfree = %6.4f Tf/Tw = %6.4fs
   Fobs finals   Fcalc finals   Fmodel finals   Fmodel_k1 finalt
   run_number(   RM   RN   (   RM   RN   (   RM   RN   (   RM   RN   (   RM   RN   (°   R   R(   R{   t   target_namet   Falset	   fix_scalet   Truet   wxray_coupled_tbatht   wxray_coupled_tbath_offsett   wxrayt   cartesian_dynamicsRc   t   ensemble_ordered_solventR   t   managerRD   Rn   t   fc_running_aveRC   t   sf_model_avet   fmodel_total_block_listRo   t   cmremovet   cdpt   mmtbxt   bulk_solventt   bulk_solvent_and_scalingt   master_paramst   extractt   bspRZ   t   txt   roundRi   t   f_obst   d_minRg   t   number_of_stepst   n_mc_per_txR   Rt   t   intt   equilibrium_n_txt   equilibrium_macro_cyclest   acquisition_block_n_txt   acquisition_block_macro_cyclest   number_of_acquisition_periodst   total_macro_cyclest
   total_timet   block_store_cycle_cntrt   ranget   block_store_cyclet   maxt   pdb_stored_per_blockt   pdb_store_cycleR'   Rr   t   fmodel_runningt   fmodel_totalt   fmodel_currentt   tls_managert   random_seedR8   t   run_time_stats_dictt   f_maskst   arrayRQ   t	   deep_copyt   copy_mat   modelRu   t   AssertionErrort   pdb_hierarchyt   atom_selectionst   show_geometry_statisticst   setup_bulk_solvent_and_scalet   show_wilson_plott   wilson_plotRx   t   f_modelt   f_model_scaled_with_k1t   infot   show_rfactors_targets_in_binst   scale_wrt_n_calc_startt   n_obs_n_calct   n_obst   n_calct   scale_helpert   scale_n1_referencet   scale_n1_targett   scale_n1_currentt   n_calc_referencet   n_mc_per_ncalc_updatet   formatt   scale_k1t   fixed_k1_from_startt	   target_k1t   update_normalisation_factorst   sumRE   t   setup_tls_selectionst   tls_group_selectionst   fit_tlst   assign_solvent_tls_groupst   set_occupanciest   show_occupancy_statisticsR)   t   sigmaat   sigmaa_arrayt   r_freet   best_r_freet
   set_sigmaat   harmonic_restraintst
   selectionst   add_harmonic_restraintst   timeR4   R=   R<   t   ordered_solvent_updatet   ordered_solvent_update_cyclet   deep_copy_scatterersRs   R   Rb   Rd   Rf   Rh   t   kinetic_energy_running_averaget   kinetic_energy_statst   update_xray_structureR-   R+   R.   R0   R*   R/   t   matht   expt   a_primeR,   t   running_f_mask_updatet   updateR1   t   set_scale_switcht   update_sigmaa_rfreet   update_sigmaat   minR2   R5   t   appendR6   R:   R;   R   t   doublet
   sites_cartt   sizet   set_selectedt   solvent_selectiont	   distancest   min_max_meant   meant   r_workR
   t%   print_fmodels_scale_and_solvent_statst   save_multiple_fmodelt   reset_totalsRa   t   optimise_multiple_fmodelt   update_solvent_and_scalet   ensemble_reductiont   target_wt   target_tt   show_remark_3t   write_output_files(   R!   Ri   R±   Rt   t   raw_datat	   raw_flagsR{   t   ptlsR}   R¿   RÀ   t   xrs_previoust   cdp_verboset
   cd_managert   total_f_mask_updatet   current_f_mask_updatet
   a_prime_wxt   wx_txt   wxray_tt   ke_expandedR»   (    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyR$   <  s¨   								

0#	




	 
					?


%%%("
%%%(! ""											
%%!%+!'0	=(;$
+%%"(%%%(	$&""4$''"	$		
		

 
 	%%%(c         C   s*  |  j  j } | d  k	 r) | d | 7} n  | d } | d } |  j  j r— | d 7} |  j d t j | d ƒ ƒ t rÒ |  j d t j | d ƒ ƒ qÒ n; |  j d t | d ƒ ƒ t rÒ |  j d t | d ƒ ƒ n  | |  _	 |  j
 d  k	 sð t ‚ t d |  j
 d |  j d	 |  j d
 | d |  j  ƒ |  _ d  S(   Ns   _%gs   .pdbs   .cifs   .gzRP   R   R¨   Rÿ   R   t   prefixR{   (   R{   t   output_file_prefixRD   t   gzip_final_modelt   write_ensemble_pdbR   R    R   t   write_ensemble_mmcift   pdb_fileR¨   R²   t   write_mtz_fileRÿ   R   t   mtz_file(   R!   R}   R  t   pdb_outt   cif_out(    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyRþ   $  s*    


"				R   c         C   se   | r5 d | } |  j  j ƒ  j d | d |  j ƒ n, d | } |  j j ƒ  j d | d |  j ƒ d  S(   Ns	   Running: RU   RP   s   Total: (   R§   R»   t$   show_rfactors_targets_scales_overallRt   R¨   (   R!   RR   R§   (    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyt   show_overall@  s
    
%
c      	   C   sN  t  d d |  j ƒ|  j ƒ  |  j d |  j ƒ } t j j d | d |  j j	 j
 d |  j j ƒ } |  j ƒ  j ƒ  } |  j d IJg  } xq | d D]e } | | j ƒ  } |  j d	 j | j | j d
 | j | j | j ƒ IJ| j | | | j f ƒ q’ W| |  j _ |  j j	 j |  j _ |  j j	 j |  j _ |  j d d d d IJd  S(   Ns    Add specific harmonic restraintsRP   R±   t   all_chain_proxiest   selection_stringsRu   s    
Add atomic harmonic restraints:i    s       {0} {1} {2} {3} {4}     i   s   
|R]   iM   s   |
(   R   Rt   RÜ   t   generate_all_chain_proxiesR±   R�   t   utilst   get_atom_selectionsR{   RØ   RÙ   Ru   R³   t   atomst   fetch_labelsRÇ   t   namet   i_seqt   resseqt   resnamet   chain_idRë   t   xyzRr   R@   t   weightRA   t   slackRB   (   R!   R  t   hr_selectionst	   pdb_atomst   restraint_infoR  t	   atom_info(    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyRÚ   H  s.    

c      	   C   s¡   t  d d |  j ƒ|  j d d ƒ |  j j d |  j d |  j j d |  j d t ƒ |  j	 t k r� |  j j
 ƒ  |  j _ |  j j |  j _ n  |  j d d ƒ d  S(	   Ns   Setup bulk solvent and scaleRP   RR   s   pre solvent and scaleR{   Rs   R|   s   post solvent and scale(   R   Rt   R  R§   Rù   R’   R{   Rs   R�   R€   RÈ   Rr   R1   Rç   (   R!   (    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyR¶   c  s    		c         C   s'   t  j | | ƒ t  j t  j | ƒ ƒ S(   N(   R   RÌ   t   pow2(   R!   R[   RZ   (    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyRÁ   s  s    c         C   sî  |  j  j r¤ t d d |  j ƒ|  j j d t ƒ \ } } |  j | } d t j	 |  j
 |  j ƒ } | | } |  j j d | |  j j | | } | |  j _ n-t d d |  j ƒ|  j j d t ƒ \ } } |  j d | d | ƒ |  _ |  j d j |  j ƒ IJt |  j j ƒ t | ƒ }	 t j |  j j | ƒ t j t j | ƒ ƒ }
 |  j d	 j t |  j j ƒ ƒ IJ|  j d
 j t | ƒ ƒ IJ|  j d j |	 ƒ IJ|  j d j |
 ƒ IJ|	 | } | |  j _ |  j d d d d IJd  S(   Ns&   Update Ncalc and restrain to Ncalc refRP   RY   g      ð?s"   Update and renormalise Ncalc arrayRZ   R[   s#   Kn current               : {0:5.3f}s#   Sum current Ncalc        : {0:5.3f}s#   Sum updated Ncalc        : {0:5.3f}s#   Rescaling factor         : {0:5.3f}s#   Rescaling factor alt     : {0:5.3f}R\   R]   iM   s   |
(   R{   R½   R   Rt   R§   R¾   R   RÅ   Râ   Rã   RÆ   R˜   RÀ   RÁ   RÄ   RÇ   RÌ   R   R*  (   R!   R¿   RÀ   t   ref_div_currentt   n_calc_coefft   n_calc_scaledt   n_calc_updatet   eobs_norm_factort   ecalc_norm_factort   ecalc_kt   ecalc_k_alt(    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyRË   v  s,    
&/"
c         C   sì   t  d d |  j ƒ|  j j d k rq |  j d I|  j IJ|  j d I|  j j ƒ  IJ|  j ƒ  |  j d IJn  |  j j ƒ  j ƒ  j	 ƒ  |  _
 |  j
 |  j _ |  j j d k r½ |  j ƒ  n  |  j j ƒ  |  _ |  j d d d	 d
 IJd  S(   Ns   Update sigmaaRP   i    s   Previous best Rfree      : s   Current       Rfree      : s     Update sigmaaR\   R]   iM   s   |
(   R   Rt   R{   Rs   RÖ   R§   RÕ   t   print_ml_statsRÓ   RQ   RÔ   R×   (   R!   (    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyRé   š  s    
c         C   s•  t  d d |  j ƒ|  j j ƒ  } | j ƒ  } |  j d | ƒ } t | ƒ d k  ro|  j d IJg  } xv | j ƒ  j ƒ  D]b } d } x- | j	 ƒ  D] } | j
 ƒ  r‘ | d 7} q‘ q‘ W| j | j ƒ  | f } | j | ƒ qx Wt j t | Œ  d ƒ }	 t j |	 d k ƒ }
 t |	 ƒ d k  r;|  j d IJ|  j d	 IJqo|
 j t ƒ d k r®|  j d
 IJ|  j d IJxÿ | D]6 } | j d | d ƒ |  j | d I| d IJqqWqo|  j d IJ| j d ƒ xT | D]L } | d c | d d 7<| d d k  rÏ|  j | d I| d IJqÏqÏW|  j d IJ|  j d IJ|  j d IJ| d d d !| d <|  j | d IJn  t j j d | d | d | j ƒ } g  } x) | D]! } d | d } | j | ƒ q Wt j j d | d | d | j ƒ } |  j d  k	 sþt ‚ | |  j _ | |  j _ | |  j _ | |  j _ t j  j! j" d |  j j d | j d d ƒ |  j _# t j  j! j$ d |  j j d |  j j# ƒ |  j _$ d  S(   NsG   Generating TLS selections from input parameters (not including solvent)RP   R±   i   s)   
No TLS groups supplied - automatic setupi    i?   s=   
Structure contains less than 63 atoms (non H/D, non solvent)sA   
Unable to perform TLS fitting, will use isotropic B-factor models   
TLS selections:s   Chain, number atoms (non H/D)s   chain s7   
Following chains contain less than 63 atoms (non H/D):s
    or chain s(   Combining all chains to single TLS groups9   WARNING: this may not be the optimum tls groupings to uses   TLS selections:iöÿÿÿR  R  Ru   t   (s"   ) and not (element H or element D)RÙ   R`   g        t   tlsos(%   R   Rt   R±   R¯   t   remove_solventR  t   lenR³   t   chainsR  t   element_is_hydrogent   idt
   atoms_sizeRë   R   R™   t   zipt   boolRÌ   t   countR   R�   R  R  Ru   Rª   RD   R²   RF   RG   RI   RJ   t   tlst   toolst   generate_tlsosRK   t
   tls_groups(   R!   R^   t   model_no_solventR  t   chains_infot   chaint   count_ht   atomt   chain_id_non_ht   chains_sizet   chains_size_okt   tls_no_sol_selectionst   tls_no_hd_selection_stringst   selection_stringt   no_hd_stringt   tls_no_sol_no_hd_selections(    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyRÍ   ¨  sx     ""	c         C   sË   | d  k r |  j } n  t j d |  j j j ƒ  ƒ g } | j } | j | ƒ  j ƒ  j	 ƒ  ƒ | j
 j } d | j _ d | j _ d | j _ t | _ d  | j
 j j _ | j
 j d | ƒ \ } } | j S(   Nt   crystal_symmetryg      ð¿i áõg      ð?t   raw_records(   RD   R±   R   t   format_cryst1_recordRu   RP  R³   t   extendt   as_pdb_stringt
   splitlinest   processed_pdb_files_srvt   pdb_interpretation_paramst   clash_guardt   nonbonded_distance_thresholdt'   max_number_of_distances_below_thresholdt)   max_fraction_of_distances_below_thresholdR�   t#   proceed_with_excessive_length_bondst   process_pdb_filesR  (   R!   R±   RQ  R³   t   pipt   processed_pdb_filet   pdb_inp(    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyR  ï  s    !		c   /      C   sŽ  t  d d |  j ƒ| j ƒ  } | j ƒ  } |  j d IJ| j d t d |  j ƒ | j j ƒ  } | j ƒ  | j	 ƒ  j
 ƒ  t j d ƒ } | j j ƒ  |  j j } |  j j } d } t }	 x} |  j j D]o }
 |
 j ƒ  d k  rî t |  j _ qÇ |  j |
 j ƒ  d k  rÇ d |
 j ƒ  |  _ |  j d	 j |  j ƒ IJqÇ qÇ W|  j j r�|  j d
 IJ|  j d IJ|  j j ƒ  |  j j } d t j d } |  j d j | ƒ IJ|  j d IJ| | } |  j d j | ƒ IJg  } xf |  j j D]X } | | | d d d f } d6 } d7 } | j t j d | d | d | d | j ƒ ƒ qàW| |  j _ x¡|  j j D]% } t  j! j" j# d | d |  j ƒ qUWnkxht$ |  j j% ƒ D]T} t  j! j" j& d | d | j d d ƒ } |  j d I| d IJxÕ d d d g d d d g d d d g d d d g d d d g d d d g d d d g d d d g g d D]i \ } } } t  j! j" j' d | j d | d | d d d d  d! | d" | d# | d$ t d% d& d |  j ƒ } qCW| j j ƒ  } t  j! j" j( d' | j) ƒ  d |  j j* d( | ƒ } | j+ | ƒ | j ƒ  | j	 ƒ  j
 ƒ  t j d ƒ } t  j! j" j, d( | d |  j ƒ | r#| j- } | ƒ  j. ƒ  } | ƒ  j/ ƒ  j0 d) ƒ } | ƒ  j/ ƒ  j0 d* ƒ } |  j d+ IJx� t1 | ƒ D]p \ } } | r¬| | j2 ƒ  }  |  j |  j3 I|  j4 I|  j5 I|  j6 Id, I| I| | I| | IJq¬q¬Wn  | | }! | j j7 ƒ  }" |! j8 |" ƒ }# t9 j j: |# ƒ }$ | j8 |" ƒ }% | j8 |" ƒ }& | r�|  j d- I|  j IJn  t; |# ƒ }' |' t< t= |' ƒ |  j ƒ d }( | ræ|  j d. I|( IJn  |  j d/ I|# j ƒ  IJt> j? |# |( k  ƒ }) |  j d0 I|) j@ t ƒ IJ|  j d1 j |) j@ t ƒ |# j ƒ  ƒ IJ|& jA ƒ  jB | k rrPn |& jA ƒ  jB } t> j? |! |( k  ƒ }* g  }+ |! j ƒ  | j j) ƒ  j ƒ  k sÃtC ‚ |* j ƒ  | j j) ƒ  j ƒ  k sêtC ‚ x; t1 |* ƒ D]- \ } }, |, r÷|" | r÷|+ j | ƒ q÷q÷Wg  } x· t$ t= | ƒ ƒ D]£ }
 t> jD ƒ  }- x. | |
 D]" }. |. |+ k r^|- j |. ƒ q^q^Wt= |- ƒ d k  r¥tE d2 ƒ ‚ n  | r×|  j d3 I|
 d Id4 It= |- ƒ IJn  | j |- ƒ qAWq”W|  j d5 IJ| j j ƒ  t  j! j" j( d' | j j) ƒ  d |  j j d( | ƒ } | j j+ | ƒ | j d t d |  j ƒ ~ | |  jF jG _H | |  j _ |  jI ƒ  d  S(8   Ns   Fit TLS from reference modelRP   s   Reference model :t   paddedi   g®Gáú„.Ai?   g      P@s,   
Automatically increasing pTLS to : {0:5.3f}s7   
Model contains less than 63 non-solvent, non-H/D atomss4   Insufficient to fit TLS model, using isotropic modelg       @i   s$   Isotropic translation (B) : {0:5.3f}s     = Wilson b-factor * pwilsons$   Isotropic translation (U) : {0:5.3f}g        t   tt   lt   st   origint   tlsoRÙ   Ru   R`   s   
Fitting cycle : i    i
   t   tlsos_initialt   number_of_macro_cyclest   max_iterationsid   t   refine_Tt   refine_Lt   refine_St   enforce_positive_definite_TLRs   iÿÿÿÿRí   R5  s   not element Hs   name casH   
CA atoms (Name/res number/res name/chain/atom number/ref biso/fit biso:s    | s*   pTLS                                    : s*   Cutoff (<)                              : s*   Number of atoms (non HD)                : s*   Number of atoms (non HD) used in fit    : s2   Percentage (non HD) used in fit         : {0:5.3f}sG   Number atoms in TLS too small; increase size of group or reduce cut-offs
   TLS group s    number atoms s!   
Final non-solvent b-factor model(   g        g        g        g        g        g        (	   g        g        g        g        g        g        g        g        g        (J   R   Rt   R¯   R6  t   show_adp_statisticsR�   Ru   RÞ   t   convert_to_isotropict
   scattererst   extract_u_isoR   t   b_as_ut   convert_to_anisotropicRª   RJ   R   Rî   R{   t   isotropic_b_factor_modelR  RÇ   R§   t   wilson_bt   pwilsonRâ   t   piRK   Rë   t	   tls_toolsRf  Re  R�   R?  R@  t   show_tls_one_groupt   xranget   max_ptls_cyclesRA  t   tls_from_uanisost   u_cart_from_tlsRí   RI   t
   set_u_cartt   show_tlsR³   R  t   atom_selection_cachet	   selectiont	   enumerateR  R  R   R!  R"  t   hd_selectiont   selectt   scitbxt   basic_statisticst   sortedR™   R7  R   R=  R>  Rò   Ró   R²   t   size_tR
   R±   RB  R5  RÐ   (/   R!   R_   Rs   t
   model_copyt	   start_xrst
   start_bisot   tls_selection_no_sol_hdt"   tls_selection_no_sol_hd_exclusionst   pre_fitted_meant   use_isotropict   groupt   iso_bt   episqt   iso_ut	   fit_tlsost	   tls_groupt	   tls_t_newt	   tls_l_newt	   tls_s_newt	   fit_cyclet   rtt   rlt   rst   fitted_tls_xrst   us_tlst   fitted_bisoR³   R'  t   not_h_selectiont   ca_selectionR  t   caR)  t   delta_ref_fitRƒ  t   delta_ref_fit_no_ht   delta_ref_fit_no_h_basic_statst   start_biso_no_hdt   fitted_biso_no_hdt   sorted_delta_ref_fit_no_ht   percentile_cutofft   delta_ref_fit_no_h_includet   include_arrayt   include_i_seqt   include_flagt	   new_groupt   x(    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyRÏ      s   
 
			'0#		
	U
!)'',	c         C   s¥   |  j  j j ƒ  |  j j } t j j j d |  j  j j	 ƒ  d | d |  j j
 ƒ } x' | D] } |  j  j j | d | ƒqY W|  j j d |  j  j d t d t ƒ d  S(   NRí   RÙ   R5  R�  Ru   Rq   Rv   (   R±   Ru   Rs  Rª   RH   R�   R?  R@  R}  Rí   RK   R~  R§   Rá   R   (   R!   RÙ   Rž  R�  (    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyt   tls_parameters_update›  s    c         C   s	  |  j  j j d |  j  j ƒ  ƒ |  j j d |  j  j d t d t ƒ g  |  j _ x- |  j j	 D] } |  j j j
 | j ƒ  ƒ q] Wt |  j j ƒ d k rý |  j ƒ  j ƒ  } |  j  j ƒ  } x?t | ƒ D]0 \ } } | | rÆ |  j j d j
 | ƒ qÆ qÆ Wnþ |  j  j ƒ  } | j ƒ  } | j j | ƒ } | j ƒ  } | j j d | j ƒ  d | j j ƒ  d	 d
 ƒ }	 t | j ƒ  ƒ t |	 j ƒ k sŽt ‚ | j j ƒ  j ƒ  }
 xU t |	 j ƒ D]D \ } } x5 |  j j D]' } | | k rÌ| j
 | |
 ƒ PqÌqÌWq³W|  j ƒ  d  S(   NR�  Ru   Rq   Rv   i   i    t
   sites_fract   use_selectiont   distance_cutoffg      $@(   R±   Ru   Rs  Rð   R§   Rá   R   Rª   RH   RI   Rë   R¯   R7  R³   R  R‚  R„  R6  t   closest_distancesR±  Rƒ  Rí   t   i_seqsR²   Rî   R°  (   R!   t   grpR'  t   hoh_selectiont   nRG  R±   Rð   t   solvent_xrsR´  t   number_non_solvent_atomsR  (    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyRÐ   ª  s<    
!	'c         C   s’   |  j  j j ƒ  } d | |  j j j ƒ  } | j |  j  j ƒ  ƒ } |  j j d  k rf | |  j _ n( |  j
 |  j j d |  j
 | |  j _ d  S(   Ng      à?i   (   R±   Ru   t   atomic_weightsRr   R9   t   dotR„  Rð   R:   RD   Rä   (   R!   R»  t   ke(    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyRß   Î  s    c         C   së   t  j d |  j d |  j d |  j j d |  j j  d |  j j d |  j ƒ } | j |  _ | j |  j _ |  j j	 d |  j j
 d t d	 t ƒ |  j j
 |  j j
 k s© t ‚ d  |  _ |  j j |  _ |  j ƒ  |  j d  k	 rç |  j ƒ  n  d  S(
   NR±   Ri   Rs   R{   R9   Rt   Ru   Rq   Rv   (   R†   R‡   R±   R§   R{   Rs   Rr   R9   Rt   Rá   Ru   R   R²   RD   Rn   R³   R´   Rª   RÐ   (   R!   t    ensemble_ordered_solvent_manager(    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyRÜ   Ú  s&    				
c         C   sw   t  d d |  j ƒg  |  j _ g  |  j _ g  |  j _ g  |  j _ d  |  j _ d |  j _	 d  |  j _
 d |  j _ d  S(   Ns,   Reseting structure ensemble and total FmodelRP   i    (   R   Rt   Rr   R5   R7   R6   R;   RD   R*   R/   R.   R0   (   R!   (    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyR÷   ñ  s    c         C   sC   t  j |  j j j ƒ  j ƒ  t ƒ |  j _ |  j j	 ƒ  |  j _
 d  S(   N(   R   R=  R±   Ru   Rí   Rî   R�   Rr   R?   Rð   R>   (   R!   (    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyR´   ý  s    *c   
   	   C   s¼  t  d d |  j ƒ|  j d j d d d d d ƒ IJ|  j d	 j d
 |  j |  j d d |  j j ƒ  d |  j j ƒ  ƒ IJ|  j j	 |  j j
 } |  j j |  j j } |  j j } |  j j } |  j j } |  j j } | | | | | | f } |  j d |  j d d k rg  |  _ n  |  j j } |  j d  k	 rH| d |  j 7} n  t |  j d ƒ d | d }	 |  j j |	 ƒ t d | d |	 ƒ |  j d 7_ |  j |  j k r¸|  j ƒ  n  d  S(   Ns   Saving fmodel blockRP   s$   {0:<23}: {1:>8} {2:>8} {3:>8} {4:>8}R   t   MCt   Blockt   Rworkt   Rfrees(   {0:<23}: {1:8d} {2:8d} {3:8.3f} {4:8.3f}s   Fmodel block infoi   id   s   _%gt   _block_s   _TEMP.pZR"   R#   (   R   Rt   RÇ   RC   R¡   R¨   Rô   RÕ   Rr   R*   R/   R.   R0   R5   R7   R6   R;   t   block_temp_file_listR{   R  R}   RD   t   strRë   R   RŸ   R÷   (
   R!   t   fcalc_blockt   fmask_blockt	   xrs_blockt   xrs_dm_blockt   pdb_h_blockt   ke_pdb_blockt
   block_infoR  t   filename(    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyRö     s@    "
	c      
   C   sY  t  d d |  j ƒd  } g  |  _ xI |  j D]> } t j t j | d ƒ ƒ } |  j j	 | ƒ t
 j | ƒ q, Wd |  j _ |  j d j d d d d	 ƒ IJx(t t |  j ƒ ƒ D]} | d
 } t |  j ƒ } xï| | k r¿|  j | d j ƒ  } |  j | d
 j ƒ  } d
 }	 xZ | | k  rm| |  j | d j ƒ  7} | |  j | d
 j ƒ  7} | d
 7} |	 d
 7}	 qW|  j j d |  j j d | |	 ƒ d |  j j d | |	 ƒ ƒ |  j j d |  j j d |  j d |  j d t ƒ |  j d j | d
 | |  j j ƒ  |  j j ƒ  |  j j ƒ  ƒ IJ| d  k r]|  j j ƒ  } | | g }
 | |	 } | |	 } nK |  j j ƒ  | d k  r¨|  j j ƒ  } | | g }
 | |	 } | |	 } n  | d
 } | d
 8} qÑ Wq¯ W|  j j d |  j j d | ƒ d |  j j d | ƒ ƒ |  j j d |  j j d |  j d |  j d t ƒ |  j d IJ|  j d j |
 d d
 |
 d
 |  j j ƒ  |  j j ƒ  |  j j ƒ  |  j j ƒ  j ƒ  d |  j j ƒ  j ƒ  ƒ IJg  |  j  _! g  |  j  _" g  |  j  _# g  |  j  _$ xì t t |  j ƒ ƒ D]Õ } | |
 d k rð| |
 d
 k  rð|  j d I| d
 Id It |  j | d ƒ IJ|  j  j! j% |  j | d ƒ |  j  j" j% |  j | d ƒ |  j  j# j% |  j | d ƒ |  j  j$ j% |  j | d ƒ qðqðWt |  j  j! ƒ t |  j  j# ƒ k sót& ‚ t |  j  j! ƒ t |  j  j$ ƒ k st& ‚ |  j d It |  j  j! ƒ IJ|  j d d d d IJd  S(    Ns   Block selection by RworkRP   t   rbi    s     {0:>17} {1:>8} {2:>8}s   Block rangeRÁ  RÂ  t   k1i   Rx   RQ   Ry   Rs   R{   R|   s!     {0:8d} {1:8d} {2:8.3f} {3:8.3f}g{®Gáz„?s   
Optimium block :s3     {0:8d} {1:8d} {2:8.3f} {3:8.3f} {4:8.3f} {5:8.3f}s$   Block | Number of models in block : s    | i   i   i   i   s$   Number of models for PBD          : R\   R]   iM   s   |
('   R   Rt   RD   RŠ   RÄ  R   t   loadR   R    Rë   t   ost   removeR¨   Rç   RÇ   Rz  R7  R¯   Ræ   R°   R®   Rù   R{   Rs   R’   R   Rô   RÕ   RÈ   t
   fmodel_kbut   k_solst   b_solRr   R5   R7   R6   R;   RS  R²   (   R!   t   best_r_workRÍ  RÌ  R¯  t   x2t   yt	   fcalc_tott	   fmask_tott   cntrt   best_r_work_blockt   best_r_work_fcalct   best_r_work_fmask(    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyRø   &  s     	

		


		 4%**c      	   C   s*  t  d t |  j ƒ d |  j ƒ|  j d j d d d d d ƒ IJ|  j d  k	 r¤ |  j d	 j d
 |  j |  j j ƒ  |  j j ƒ  j	 ƒ  |  j j ƒ  j
 ƒ  d ƒ IJn  |  j d  k	 r|  j d	 j d |  j |  j j ƒ  |  j j ƒ  j	 ƒ  |  j j ƒ  j
 ƒ  d ƒ IJn  |  j d  k	 rh|  j d	 j d |  j |  j j ƒ  |  j j ƒ  j	 ƒ  |  j j ƒ  j
 ƒ  d ƒ IJn  |  j d  k	 rŸ|  j d j |  j j ƒ  j ƒ  Œ  IJn  |  j d  k	 rÖ|  j d j |  j j ƒ  j ƒ  Œ  IJn  |  j d  k	 r|  j d j |  j j ƒ  j ƒ  Œ  IJn  |  j d d d d IJd  S(   Ns    Fmodel statistics | macrocycle: RP   s$   {0:<23}: {1:>8} {2:>8} {3:>8} {4:>8}R   R¿  RÏ  t   Bsolt   ksols*   {0:<23}: {1:8d} {2:8.3f} {3:8.3f} {4:8.3f}s   Fmodel currenti    s   Fmodel runningt   Fmodel_TotalsO   Fmodel current bcart   : {0:14.2f} {1:5.2f} {2:5.2f} {3:5.2f} {4:5.2f} {5:5.2f}sO   Fmodel running bcart   : {0:14.2f} {1:5.2f} {2:5.2f} {3:5.2f} {4:5.2f} {5:5.2f}sO   Fmodel total bcart     : {0:14.2f} {1:5.2f} {2:5.2f} {3:5.2f} {4:5.2f} {5:5.2f}R\   R]   iM   s   |
(   R   RÅ  RC   Rt   RÇ   R©   RD   RÈ   RÓ  RÕ  RÔ  R§   R¨   t   b_cart(   R!   (    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyRõ   ~  s@    
(((c         C   s¥   |  j  j d j ƒ  } | t j d | ƒ IJ| t j d | j ƒ  ƒ IJxL t |  j  j ƒ D]8 \ } } | d | d IJ| | j ƒ  IJ| d IJq[ W| d IJd  S(   Ni    RP  t	   unit_cells	   MODEL %8di   t   ENDMDLt   END(	   Rr   R7   RP  R   RR  t   format_scale_recordsRã  R‚  t   as_pdb_file(   R!   RP   RP  R¸  t   xrs(    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyt   write_diff_map_ensemble¡  s    c         C   s  |  j  j | } | j ƒ  } | j ƒ  } | j ƒ  } | j ƒ  } | j | j ƒ  ƒ } | j ƒ  } |  j  j	 | }	 |	 j
 ƒ  }
 |  j  j | } xst |
 ƒ D]e\ } } | t | ƒ k  rš | | | _ |  j j rå d | | | _ n d t |  j  j ƒ | _ t j | | ƒ | _ | | } t | ƒ d k rnd j | d ƒ d k rnd | d  | _ d | d | _ nM t | ƒ d k r¥d | d  | _ d | d | _ n d | | _ d	 | _ | | j j ƒ  rÞ| | | _ qÿt ró|  j | _ qÿd | _ qš qš W|	 S(   Ngš™™™™™¹?g      ð?i   s   +-0123456789i    s   %2ss   %-2si   s     iÿÿÿÿ(   iÿÿÿÿiÿÿÿÿiÿÿÿÿiÿÿÿÿiÿÿÿÿiÿÿÿÿ(   Rr   R5   Rp  Rí   t   extract_u_iso_or_u_equivt   extract_occupanciest   extract_u_cart_plus_u_isoRã  t   extract_scattering_typesR6   R  R;   R‚  R7  R#  R{   t1   output_running_kinetic_energy_in_occupancy_columnt   occR   t   u_as_bt   bt   findt   elementt   charget   flagst   use_u_anisot   uijR   t   u_cart(   R!   t   i_modelRè  Rp  Rí   t   u_isost   occupanciest   u_cartst
   scat_typest   i_model_pdb_hierarchyR'  t
   i_model_ket   j_seqRG  t   e(    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyt   update_single_hierarchy«  s@    
+	c         C   s=  |  j  j d j ƒ  } d } | | IJ| d IJd d l m } | j d | ƒ \ } } | d  k rm d } n' | d  k	 rŠ | d | } n  d	 | } | | | IJ| j } | d
 }	 d }
 |
 } t |	 ƒ d } x• |
 t | ƒ k rht | |
 ƒ d } | | d k rQ| |	 Id j	 | | |
 !ƒ d IJ| d }	 |
 } t |	 ƒ d } n  | | 7} |
 d 7}
 qÔ W| |
 k r˜| |	 Id j	 | | |
 !ƒ IJn  |  j
 j ƒ  } | j d | ƒ |  j j d |  j j d |  j j d |  j  j d t d t d |  j d t ƒ |  _ | |  j IJ| t j d | ƒ IJ| t j d | j ƒ  ƒ IJt } d } t |  j  j ƒ t |  j  j ƒ k s}t ‚ t |  j  j ƒ t |  j  j ƒ k s§t ‚ x… t |  j  j ƒ D]q \ } } | d 7} | d | IJ|  j | ƒ } | rüd } n d  } | j | j  d t d | ƒ ƒ | d IJqºW| d IJd  S(   Ni    s
   REMARK   3s-   REMARK   3 TIME-AVERAGED ENSEMBLE REFINEMENT.iÿÿÿÿ(   t   phenix_infot   fs4      PROGRAM     : PHENIX (phenix.ensemble_refinement)t   _s8      PROGRAM     : PHENIX (phenix.ensemble_refinement: %s)s      AUTHORS     :i   iO   t   ,s                  :RP   Rb   Ru   t   ensemble_xray_structuresRS   Rs   t   return_pdb_stringRP  Rã  s	   MODEL %8dt
   append_endt   atoms_reset_serial_first_valueRä  Rå  (!   Rr   R5   RP  t   phenixR  t   version_and_release_tagRD   t   phenix_developers_lastR7  t   joinR¨   R»   Rý   R   t   ensemble_mean_geometry_statsR±   Rb   Ru   R�   R   Rt   t   final_geometry_pdb_stringR   RR  Ræ  Rã  R;   R²   R6   R‚  R  t   writeRT  (   R!   RP   RP  t   prR  t   vert   tagt   progt   authorsRc  t   jt   iR¸  t   at   fmodel_infot   atoms_reset_serialRÛ  Rù  Rè  Rþ  R
  (    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyR  Ñ  sr    

	
	
$

#	**
	
c         C   s©  |  j  j d  k	 r2 |  j j i |  j  j d 6ƒ n  |  j j d k r› |  j j i |  j  j ƒ  d j ƒ  d 6ƒ |  j j i |  j  j ƒ  d j ƒ  d 6ƒ n  |  j  j	 d  k	 rÍ |  j j i |  j  j	 d 6ƒ n  |  j  j
 d  k	 rÿ |  j j i |  j  j
 d	 6ƒ n  t d
 d |  j ƒ|  j d j d d d d ƒ IJxX t |  j j ƒ  ƒ D]A } |  j | j ƒ  } |  j d j | | j | j | j ƒ IJqGW|  j d d d d IJd  S(   Nt   Sigma_aRM   RN   i    t   Alphai   t   Betas   Eobs(fixed)s   Ecalc(fixed)s   ML statisticsRP   s"     {0:<23}: {1:>12} {2:>12} {3:>12}R   Rê   R¤   Ró   s(     {0:<23}: {1:12.3f} {2:12.3f} {3:12.3f}R\   R]   iM   s   |
(   s   mls   mlhl(   R§   R×   RD   R¬   Ræ   R{   R~   t
   alpha_betaRQ   R¿   RÀ   R   Rt   RÇ   R‡  t   keysRò   Rê   R¤   Ró   (   R!   t   keyR»   (    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyR3    s&     *-  c         C   s•   t  d | d |  j ƒ|  j j d t j | ƒ ƒ |  _ t d |  j j ƒ  j ƒ  ƒ } |  j j	 d | ƒ |  j j
 d t ƒ } | j d |  j ƒ d  S(   Ns   Wilson Plot RP   RQ   iú   t   reflections_per_bint   use_binningR  (   R   Rt   R°   R®   R   t   absRê   RQ   Rî   t   setup_binnerR¸   R�   t   show(   R!   RT   RU   R"  R¸   (    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyR¸   ,  s    !(   R%   R&   RD   R$   Rþ   R�   R  RÚ   R¶   RÁ   RË   Ré   RÍ   R  R   RÏ   R°  RÐ   Rß   RÜ   R÷   R´   Rö   Rø   Rõ   Ré  R  R  R3  R¸   (    (    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyRL   ;  s4   ÿ â				$		G›		$					%	X	#	
	&	E	c         C   st  |  j  ƒ  } |  j ƒ  j ƒ  j t ƒ d |  j ƒ  j ƒ  j ƒ  } | d IJy | | j d ƒ  } Wn t k
 ru n Xd j d | d t	 d | j
 ƒ d t	 d	 | j ƒ d
 t	 d	 | j ƒ d t	 d	 | j ƒ d t	 d	 | j ƒ d t	 d |  j ƒ  ƒ d t	 d | j ƒ d t	 d | ƒ d t	 d | ƒ d t	 d | ƒ d t	 d |  j ƒ  j ƒ  ƒ g ƒ } | d I| IJd  S(   Ng      ð?s   Data statisticsR  s    
    s(   data_label                          : %ss&   high_resolution                     : s   %-5.2fs&   low_resolution                      : s   %-6.2fs&   completeness_in_range               : s&   completeness(d_min-inf)             : s&   completeness(6A-inf)                : s&   wilson_b                            : s   %-6.1fs&   number_of_reflections               : s   %-8ds&   test_set_size                       : s   %-8.4fs&   test_flag_value                     : s   %-ds&   number_of_Fobs_outliers             : s&   anomalous_flag                      : s   %-6ss      (   R»   t   r_free_flagsRQ   R>  R�   Rî   t   indext
   ValueErrorR  R   R–   t   d_maxt   completeness_in_ranget   completeness_d_min_inft   completeness_6_infRu  t   number_of_reflectionsR•   t   anomalous_flag(   Ri   t   n_outlt   test_flag_valuet   f_obs_labelsRt   R»   t   flags_pct   result(    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyt	   show_data6  s:    5
  "c      	   C   sf  |  j  ƒ  j ƒ  \ } } |  j ƒ  j ƒ  j t ƒ d |  j ƒ  j ƒ  j ƒ  } | d k rb d  } n |  j ƒ  } t	 d |  j
 ƒ  j ƒ  d ƒ } t	 d |  j
 ƒ  j ƒ  ƒ } d j g  |  j
 ƒ  j ƒ  D] } d | j ƒ  ^ qÁ ƒ }	 | d IJd j d	 t	 d
 |  j ƒ  ƒ d t	 d
 | ƒ d t	 d
 |  j ƒ  ƒ d | | f d t	 d |	 ƒ g ƒ }
 | d I|
 IJd  S(   Ng      Y@i    s   %-5.2fs   %-7.2ft    s   %8.2fs   Model vs data statisticss    
    s&   r_work(re-computed)                 : s   %-6.4fs&   r_free(re-computed)                 : s&   scale_k1                            : s*   bulk_solvent_(k_sol,b_sol)          : %s%ss&   overall_anisotropic_scale_(b_cart)  : s   %-ss      (   R•   t	   d_max_minR'  RQ   R>  R�   Rî   RD   RÕ   R   RÓ  RÔ  RÕ  R  Râ  t   stripRô   RÈ   (   Ri   Rt   R*  R–   R3  RÕ   t   k_solRÕ  t   vRâ  R4  (    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyt   show_model_vs_dataT  s&     	8
c         C   sÖ  |  d  k	 s t ‚ d d d „  ƒ  Y} d } d } d } d }	 | j ƒ  rR | }
 n | }
 | j d |
 ƒ } | j d | d |	 ƒ | j d	 ƒ | j ƒ  j d
 d d d ƒ } | j d |  j ƒ  d d | ƒ | j ƒ  j d
 d d d ƒ } | j d |  j	 ƒ  d d | ƒ | j ƒ  j d
 d d d ƒ } t
 j j d |  d | j j ƒ } xi | j j ƒ  j ƒ  D]R } | j ƒ  j } | d | d d | d ƒ } | j d | d | d d | ƒ q^W| j ƒ  j d | d ƒ | d S(   Nt   labels_decoratorc           B   s&   e  Z d  „  Z d „  Z d d „ Z RS(   c         S   s   | |  _  | |  _ d  S(   N(   t   _amplitudest   _phases(   R!   t   amplitudes_labelt   phases_label(    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyR$   k  s    	c         S   s   |  j  S(   N(   R=  (   R!   (    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyt
   amplitudesn  s    c         S   s    | d  k s | s t ‚ |  j S(   N(   RD   R²   R>  (   R!   t
   root_labelt   anomalous_sign(    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyt   phasesp  s    N(   R%   R&   R$   RA  RD   RD  (    (    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyR<  j  s   		t   _xrays   F-obss   I-obss   R-free-flagst   column_root_labelt   miller_arrays   Original-experimental-dataR  s$   Experimental-data-used-in-refinementt
   wavelengthi   s   F-obs-filtereds>   Model-structure-factors-(bulk-solvent-and-all-scales-included)s   F-models   Fourier-map-coefficientsRi   R{   R?  i    R@  t   label_decoratort	   file_names   .mtz(    (   RD   R²   t   is_xray_intensity_arrayt   as_mtz_datasett   add_miller_arrayt   set_namet   mtz_crystalt   add_datasetR•   t*   f_model_scaled_with_k1_composite_work_freeR�   t   mapst   compute_map_coefficientst   electron_density_mapst   map_coefficientst   mtz_datasett
   mtz_objectt   as_miller_arraysR»   t   labelsR  (   R¨   Rÿ   R   R  R{   R<  t   xray_suffixt   f_obs_labelt   i_obs_labelt
   flag_labelRF  t   mtz_dataset_originalt   new_datasett   another_datasett   yet_another_datasett   cmot   maRY  t   ld(    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyR  h  sR    									
s   phenix.ensemble_refinementc   A      C   sì  t  |  ƒ d k r d g }  n  t d d | d d | ƒ j ƒ  j ƒ  j d |  ƒ } | d  k rk t j } n  | j d  k	 r  t	 j
 d | j d	 | j d
 | ƒ d  St j j d | j d t	 d
 | d t d t ƒ } | j } | j ƒ  } | j d  k	 rc| d IJ| d | j IJt j j d | j ƒ }	 t j j d ƒ }
 t	 j d | |	 |
 g ƒ } | j ƒ  } n  | j } | j j t k s–t  | j j ƒ d k rt j j d d d t j  j! ƒ } t j j d | ƒ } t j" j j	 j d | g | g ƒ } | j ƒ  j } n  | j# d  k rEt j  j$ t j  j% | j& d ƒ ƒ d d | _# n  t' ƒ  } | j( d d d | ƒ | j( d d d t) ƒ  d d  ƒ | r•| t _* n  t+ | j# d d ƒ } | j, d d d d  d! | ƒ t- ƒ  } t j. j/ d  | d" | ƒ t0 d# d
 | ƒ| j
 d
 | ƒ t0 d$ d
 | ƒ| d% t1 d& t j  j% | j2 j3 j4 ƒ ƒ IJ| d' t1 d& t j  j% | j& d ƒ ƒ IJ| d( IJ| j5 } | j6 ƒ  j7 ƒ  } | j8 } | j9 } | j: } | d) I| j& d IJ| j; } | j& d } t j< j= j	 j ƒ  } d* | j> _? d+ | j> _@ d, | j> _A tB | _C t j. jD d- | d. | d/ | jE d  | ƒ } | jF d0 | g ƒ \ } } | jG jH } | jI rL| jJ ƒ  j7 ƒ  } xø | jK ƒ  D]ê } xá | jL ƒ  D]Ó }  xŸ |  jM ƒ  D]‘ }! |! jN ƒ  }" t  |" ƒ d k sçtO ‚ x9 |" D]1 }# |# jP d— k r|! jQ d3 |# ƒ qîd1 |# _P qîWt  |! jN ƒ  ƒ d k r½|  jR d4 |! ƒ q½q½Wt  |  jM ƒ  ƒ d k rª| jS d5 |  ƒ qªqªWq—W| jJ ƒ  }$ tT jU |$ j7 ƒ  d, ƒ }% |$ jV |% ƒ | jJ ƒ  j7 ƒ  }& | |& k rL| d d6 !d7 }' | d8 IJ| d9 IJ| d: I|' Id; IJ| jW d |' d/ | jX ƒ  ƒ | jF d0 |' g ƒ \ } } qLn  | jY ƒ  }( t j. jZ d< | d= d> d? |( d  | ƒ }) t  |) j[ ƒ d@ k r£t\ dA ƒ ‚ n  |) j[ d j] ƒ  }* d  }+ }, t^ | j dB ƒ rk| j j_ j` }, |, rk| j j_ }- dC d  la }. t0 dD d
 | ƒ| dE |- jb IJ|. jc dF |- jb dG |- jd ƒ }+ | je jf jg ƒ  dH k rhtB | je _h qhqkn  |* ji ƒ  jj ƒ  jk ƒ  }/ dI |/ k p˜dJ |/ k }0 | jl dK t dL dM dN | j" jm jn dO d  dP d  dQ d  dR d  dS d  dT |0 ƒ 	}1 t jo jp dU |1 dV tB dW |, dX |+ ƒ }2 dY d˜ dZ „  ƒ  Y}3 |3 d[ |* jq ƒ  j7 ƒ  ƒ }4 t jr jp d\ | d] |4 d^ |2 d_ |* d` | da d  db d  d  | ƒ } | jE }* |* js ƒ  }5 |* jq ƒ  jt ƒ  }6 | ju jv jw dc |5 dd |6 de t+ | j# df d ƒ ƒ | dg I| jx ƒ  IJ| dh I| jX ƒ  jy ƒ  jz ƒ  IJ| di I| jX ƒ  jy ƒ  j{ ƒ  j| ƒ  j} ƒ  IJ| dj | jx ƒ  j~ ƒ  IJ| j ƒ  j€ ƒ  }7 | j� j‚ rv	d  St j. jƒ dk | dl | jE g d= d> dm | dn | j„ do t dp d  dq d  dr d  ds tB dt du dv tB dw tB dx tB d  | ƒ }8 | j… }9 |9 d  k	 r7
| j2 j† r7
| dy IJdz | _„ |9 j‡ d{ |8 j5 ƒ  ƒ }9 n d  }9 t jˆ jp dq | j‰ d_ | jE dk |8 j5 ƒ  dm |8 j8 ƒ  dn | j„ d| |9 ƒ }8 | jE jŠ ƒ  }: | jE j‹ d} d, d~ |: ƒ | jŒ d
 | ƒ |8 j� d_ | jE d tB d€ t d� t ƒ | jŽ ƒ  j7 ƒ  |8 j5 ƒ  jŽ ƒ  j7 ƒ  }; t� d‚ |8 dƒ |; d„ | j� d… |7 d  | ƒ t‘ d‚ |8 d  | ƒ d  }< t  | j’ ƒ d@ k r¯t“ d‚ |8 d† | d‡ | dˆ | d‰ | d  | ƒ j” dŠ | j’ d d‹ t dŒ t ƒ }< nt“ d‚ |8 d† | d‡ | dˆ | d‰ | d  | ƒ }= g  }> | j• d™ k s t j– d� k rbxƒ | j’ D]Q }? t0 dŽ |? d
 | ƒ|= |? d‹ t d� t ƒ}@ |@ d  k	 sNtO ‚ |> j— |@ ƒ q
Wn$ t˜ j™ d� |= d | j’ d‘ | j• ƒ }> d  |> k s˜tO ‚ tš |> d’ d“ „  ƒ}< |< j› | j# ƒ tœ d
 | ƒ t� d” |< d• | j# d– | d  | ƒ S(š   Ni    s   --helpt   usages%   %s reflection_file pdb_file [options]t   descriptions   Example: %s data.mtz model.pdbt   argst   expert_levelt   attributes_levelRP   t   master_philt   create_fmodelt   process_pdb_files.   Processing custom geometry restraints in file:s     %sRJ  s   extra_restraints_file=Nonet   sourcest   relative_paths>   cctbx_project/mmtbx/refinement/ensemble_refinement/maps.paramst   testt	   _ensemblet   labelt   stdoutt   file_objectt
   log_buffert   atexit_send_tos   .logt   wt	   old_labelt	   new_labelRt   t   new_file_objectt   texts   Ensemble refinement parameterss   Model and data statisticss,   Data file                               : %ss   %5ss.   Model file                              : %s 
s*   
TLS MUST BE IN ATOM RECORDS OF INPUT PDB
s   
PDB file name : g      ð¿i áõg      ð?t   cif_objectsRW  RP  t   pdb_file_namesR   t   At
   atom_groupt   residue_groupRE  iüÿÿÿs   _removed_alt_confs.pdbs#   
Removing alternative conformationss   All occupancies reset to 1.0s
   New PDB : s   
R_  t   scattering_tablet
   n_gaussianR–   i   s   Multiple models not supported.t   amberiÿÿÿÿs   Initializing AMBERs     topology: %st   prmtopt   ambcrdt   autot   Ht   Dt   show_energiest   plain_pairs_radiusi   t   params_editst   params_removet   hydrogen_bond_proxiest   hydrogen_bond_paramst   custom_nonbonded_exclusionst   external_energy_functiont   assume_hydrogens_all_missingt   geometryt   normalizationt	   use_ambert   amber_structst   rfc           B   s   e  Z d  „  Z d „  Z RS(   c         S   sO   t  |  _ t |  _ t j | t  ƒ |  _ d  |  _ d  |  _	 d  |  _
 d  |  _ d  S(   N(   R�   t   individual_sitesR   t   individual_adpR   R=  t   sites_individualRD   t   sites_torsion_anglest   torsion_anglest   adp_individual_isot   adp_individual_aniso(   R!   Rî   (    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyR$   Q  s    					c         [   s   d  S(   N(    (   R!   t   keywords(    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyt   inflateY  s    (   R%   R&   R$   Rž  (    (    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyR•  P  s   	Rî   RV  t   refinement_flagsRb   Ru   R³   RB  t   anomalous_scatterer_groupsRí   t   site_labelsR  s   .geos)   Unit cell                               :s)   Space group                             :s)   Number of symmetry operators            :s1   Unit cell volume                        : %-15.4fR•   R5   R'  R~   R�   t
   bss_paramst   mask_paramst	   twin_lawst   skip_twin_detectiont   twin_switch_toleranceg       @t   outliers_rejectiont   bulk_solvent_correctiont   anisotropic_scalings*   Using MLHL target with experimental phasesRN   Rz   t   abcdR`   R�  Rq   Rv   Rw   Ri   R0  R1  R2  R±   t	   er_paramsRÿ   R   R  t   buffer_outputt   append_ptlst   win32s   Running with pTLS = %gt	   write_logt
   fixed_funct	   processesR!  c         S   s   |  j  S(   N(   RÕ   (   Rb  (    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyt   <lambda>Ò  s    t
   best_trialR  t   validate(   R   R}  (    (   i   N(ž   R7  R   t   enable_dry_runt   enable_show_defaultst   processRD   t   sysRr  Rh  R�   R&  Ri  R�   t   command_linet   load_model_and_dataRg  R   t   working_philR‘   t   extra_restraints_filet   iotbxt   philt   parset   fetcht   ensemble_refinementRT  t   apply_default_mapsRU  t   libtbxt   envt   find_in_repositoriesRÑ  t   patht   isfilet
   refinementR  t   splitextt   basenameR|  R   t   registerR   t   stderrR    t   replace_stringioR   R  t   print_programs_start_headerR   R   t   inputt	   xray_dataRJ  R•   t   indicesRî   R'  R   Rÿ   R{  t   monomer_libraryt   pdb_interpretationRX  RY  RZ  R[  R�   R\  t   process_pdb_file_srvRu   R]  R  R³   t   remove_alt_conf_from_input_pdbR  t   modelsR8  t   residue_groupst   atom_groupsR²   t   altloct   remove_atom_groupt   remove_residue_groupt   remove_chainR   Rì   t   set_occt   write_pdb_fileRP  R–   t'   xray_structures_from_processed_pdb_fileR5   R
   RÞ   t   hasattrR‚  R“  t   amber_adaptbxt   topology_file_namet   get_amber_structst   coordinate_file_namet	   hydrogenst   refinet   lowert   force_riding_adpt   scattering_type_registryt   type_count_dictR   t   geometry_restraints_managerR   t   editst
   restraintsR‡   Rp  R±   Rí   t   extract_labelsRb   R‘  t   show_sortedRã  t   space_group_infot   symbol_and_numbert   typeR�  t   order_zt   volumeR»   t   label_stringt   optionst   dry_runt   fmodel_simpleR~   t	   hl_coeffst   use_experimental_phasest
   common_setR¹   t   maskRƒ  RÑ   RÒ   Rá   RQ   R5  R1  R;  R  t   run_wrappert   __call__t   nproct   platformRë   R   t   pool_mapRê   t
   save_finalR   R4  (A   Rg  t   command_nameRP   R´  t   replace_stderrR¹  t   inputsR»  R{   t   restraints_philt   cleanup_philR«  t   maps_part   maps_par_philt   working_paramsRt   t   log_filet   timerR•   R.  R'  R   Rÿ   R{  R  t   pdb_ipRV  R_  R`  t	   hierarchyt   atoms_size_preR±   RE  R  RØ  R~  R  t   new_occt   atoms_size_postt   pdb_file_removed_alt_confsR–   t   xsfppfRu   R”  R“  t   amber_paramsRá  t	   sctr_keyst   has_hdR‘  Rb   R•  RŸ  Rí   R¡  R2  Ri   Rù  t   hd_selR0  R³  t   drivert   trialsR  t   trial_result(    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyt   run�  s    
							
			*					%#
									

		
			
			

$			
							(					Rý  c           B   s#   e  Z d  „  Z e e e d „ Z RS(   c         C   s   t  |  t ƒ  ƒ d  S(   N(   R   R(   (   R!   R±   Ri   Rÿ   R   R«  Rt   (    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyR$   Ý  s    c         C   s7  |  j  } d  } | r! t ƒ  } n  d  } | r6 | } n  t d |  j j ƒ  d |  j j ƒ  d |  j d |  j d |  j	 d | d | d | ƒ } | râ | j
 ƒ  } | râ |  j j d	 t | ƒ d
 }	 t |	 d ƒ }
 |
 j | ƒ qâ n  t d | d | j j ƒ  d | j j ƒ  d | j d | j d | d t | j j ƒ ƒ S(   NRi   R±   R{   Rÿ   R   R}   R  Rt   s   _ptls-s   .logRv  Rô   RÕ   R  R  t   log_outt   number_of_models(   Rt   RD   R   RL   Ri   R¯   R±   R«  Rÿ   R   t   getvalueR  RÅ  R    R  t   trialR¨   Rô   RÕ   R  R  R7  Rr   R5   (   R!   R  R¬  R¯  R­  RP   R  R}   RÁ  t   log_file_nameR  (    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyRþ  à  s<    								(   R%   R&   R$   R�   Rþ  (    (    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyRý  Ü  s   	R  c           B   s5   e  Z d  d d d d d d g Z d „  Z d „  Z RS(	   Rô   RÕ   R  R  R  R  R  c         K   s8   t  | ƒ } x% |  j D] } t |  | | | ƒ q Wd  S(   N(   t   dictt	   __slots__t   setattr(   R!   t   kwdsR  (    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyR$     s    c         C   sm   | d } |  j  j d ƒ r) | d 7} n  t j |  j  | ƒ t j |  j | d ƒ | |  _  | d |  _ d  S(   Ns   .pdbs   .gzs   .mtz(   R  t   endswithRÑ  t   renameR  (   R!   R  R  (    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyR  
  s    
	(   R%   R&   R"  R$   R  (    (    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyR    s   	R4  c           B   sD   e  Z d  d d d d d d g Z e d „ Z d
 d „ Z d	 „  Z RS(   t	   directoryRô   RÕ   R  R  R  t
   validationc         C   s­   x6 d d d d d g D] } t  |  | t | | ƒ ƒ q Wt j ƒ  |  _ d  |  _ | r© d d l m } | j	 d |  j
 g d	 | ƒ |  _ t |  j ƒ j d
 k s© t ‚ n  d  S(   NRô   RÕ   R  R  R  iÿÿÿÿ(   t   validation_summaryRg  RP   t   ensemble(   R#  t   getattrRÑ  t   getcwdR'  RD   R(  t   mmtbx.command_lineR)  R  R  Rò  R%   R²   (   R!   R³  R  Rt   R´  t   attrR)  (    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyR$     s    		c         C   sL   | d  k r |  j } n  t j j |  j |  j ƒ t j j |  j |  j ƒ f S(   N(   RD   R'  RÑ  RÆ  R  R  R  (   R!   t
   output_dir(    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyt   get_result_files+  s    c         C   s`   |  j  ƒ  \ } } | d f | d f g d d |  j f d d |  j f d t |  j ƒ f g f S(   Ns   Final ensembles   Map coefficientss   R-works   %.4fs   R-freet   Models(   R0  Rô   RÕ   RÅ  R  (   R!   R  R  (    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyt
   finish_job1  s    	N(   R%   R&   R"  R   R$   RD   R0  R2  (    (    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyR4    s
   	t   launcherc           B   s   e  Z d  „  Z RS(   c         C   sE   t  j |  j ƒ t  j |  j ƒ t d t |  j ƒ d t j d t	 ƒ S(   NRg  RP   R´  (
   RÑ  t   mkdirR/  t   chdirR  t   listRg  R¸  Rr  R�   (   R!   (    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyR  <  s
    	(   R%   R&   R  (    (    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyR3  ;  s   c         C   sh   |  j  j d  k r! t d ƒ ‚ n7 t |  j j j d j d ƒ ƒ d k rX t d ƒ ‚ n  t	 j
 j |  ƒ S(   Ns<   You must specify a fraction of atoms to use for TLS fitting.i    R  i   s/   Anomalous data are not allowed in this program.(   RÁ  R  RD   R
   R7  RÏ  RÐ  RY  t   splitR�   R¹  t   validate_input_params(   R{   (    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyt   validate_paramsC  s
    ((Q   t
   __future__R    t&   mmtbx.solvent.ensemble_ordered_solventt   solventR†   t$   mmtbx.refinement.ensemble_refinementR   t   mmtbx.dynamicsR   t   mmtbx.tls.toolsR?  R@  Rx  R-  R�   t   mmtbx.utilst   mmtbx.modelt
   mmtbx.mapst   iotbx.option_parserR   R½  R   t
   iotbx.philt   cctbxR   t   cctbx.array_familyR   R   R   R	   t   scitbx.mathR…  t   libtbx.utilsR
   R   R   R   RÃ  R   R   t   libtbx.str_utilsR   R   R   R   t   libtbx.load_envt	   cStringIOR   R   t   randomR   Râ   RÛ   RÑ  R¸  R¾  R¿  t   customization_paramsR¹  t    generate_master_phil_with_inputsR�   t
   input_philRÀ  R�   t   objectR   R'   RE   RL   R5  R;  R  RD   R   R  Rý  R  R4  t   target_with_save_resultR3  R9  (    (    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/ensemble_refinement/__init__.pyt   <module>   sx   "				Õ	ÿ ÿ ÿ ÿ ÿ  			5ÿ ?&&