ó
±™xTc           @   sô  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	 Z	 d  d l
 Z d  d l Z d  d l m Z d  d l j j Z d  d l m Z d  d l Z d  d l Z d  d l m Z d  d l Z d  d l Z d  d l m Z d  d l Z d  d l Z d  d	 l m Z e j  d
 ƒ e j! d
 ƒ d Z" d e# f d „  ƒ  YZ$ d „  Z% d „  Z& d d
 d „ Z' d „  Z( d „  Z) d „  Z* d „  Z+ d „  Z, d „  Z- d „  Z. d „  Z/ e j0 d „ Z1 e2 d k rðe1 e j3 d ƒ n  d S(   iÿÿÿÿ(   t   division(   t   adptbx(   t   flexN(   t   easy_run(   t   monomer_library(   t   ladp(   t   approx_equal(   t   Sorryi    sL  f_obs {
  high_resolution = 2.0
    .type = float
  low_resolution = 15.0
    .type = float
  scattering_table = wk1995 it1992 *n_gaussian neutron
  f_calc {
    atomic_model {
      ensemble_size = 20
        .type = int
      add_hydrogens = False
        .type = bool
      tls {
        max_tl = 2
          .type = float
        min_tl = 0
          .type = float
      }
      apply_cartesian_dynamics = True
        .type = bool
      regularize_geometry {
        rmsd_bonds_target = 0.025
          .type = float
        rmsd_angles_target = 2.5
          .type = float
      }
      ladp_angle = 3.0
        .type = float
      switch_rotamers = True
        .type = bool
      shake_sites_rmsd = 0.01
        .type = float
      rigid_body_shift {
        rotation_angle = 1.0
          .type = float
        translation_length = 0.1
          .type = float
      }
      stop_cartesian_dynamics_at_diff = 0.5
        .type = float
      use_ramachandran_plot_restraints = True
        .type = bool
      output_file_name = fake_model.pdb
        .type = str
    }
    accuracy {
      include scope mmtbx.f_model.sf_and_grads_accuracy_master_params
    }
  }
  f_bulk {
    k_sol = 0.35
      .type = float
    b_sol = 50.0
      .type = float
    mask {
      include scope mmtbx.masks.mask_master_params
    }
  }
  overall_scale = 1.0
  overall_anisotropic_scale_matrix_b_cart {
    max = 10
      .type = float
    min = 0
      .type = float
  }
  experimental_noise {
    add_random_error_to_amplitudes_percent = 5
      .type = float
  }
  output_file_name = fake_f_obs.mtz
    .type = str
}

t   showc           B   s   e  Z d  d „ Z RS(   t    c         C   s‡   | j  d | j ƒ  d t ƒ j } | j ƒ  d |  _ | j ƒ  d |  _ t j	 | j
 d | ƒ ƒ |  _ d | |  j |  j |  j f GHd  S(   Nt
   sites_cartt   compute_gradientsi   t   others-     %s err=%8.3f rmsd: bonds=%6.3f angles=%6.3f(   t   energies_sitesR
   t   Falset   geometryt   bond_deviationst	   bond_rmsdt   angle_deviationst
   angle_rmsdR   t   meant	   distancest   error(   t   selft   xrst	   xrs_startt   grmt   prefixt   esg(    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/fake_f_obs.pyt   __init__g   s    	(   t   __name__t
   __module__R   (    (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/fake_f_obs.pyR   f   s   c         C   si   |  j  ƒ  } | j ƒ  } | j ƒ  j ƒ  t j j d | d d ƒ } | j d | j ƒ  j ƒ  ƒ | | f S(   Nt   pdb_hierarchyt   modet   min_distantR
   (	   t   deep_copy_scattererst	   deep_copyt   atomst   reset_i_seqt   mmtbxt   utilst   switch_rotamerst   set_sites_cartt   extract_xyz(   t   xray_structureR    t   xt   p(    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/fake_f_obs.pyR)   t   s    	c         C   sw   t  j d | d t j j ƒ  ƒ } |  j d t j d d ƒ ƒ }  |  j ƒ  t  j d |  d | d | d t	 d	 d
 ƒ }  |  S(   NR    t   mon_lib_srvt   valuei   i
   R,   t   axes_and_atoms_i_seqst   enable_recursiont   depthi    (
   R   t   get_axes_and_atoms_i_seqsR   t   servert	   set_b_isot   randomt	   randranget   convert_to_isotropict   set_ladpt   True(   R,   R    t   angleR1   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/fake_f_obs.pyR:   ~   s    	
		i   c         C   s:   t  j | |  j d t  j | t  j d | d | ƒ ƒ ƒ ƒ S(   Nt   u_start   u_scalet   u_min(   R   t   u_star_as_u_cartt   average_u_start   u_cart_as_u_start   random_u_cart(   t   space_groupt	   unit_cellR>   R?   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/fake_f_obs.pyt   random_aniso_adpŒ   s    c         C   sÂ  |  j  ƒ  } |  j ƒ  } t j |  j ƒ  j ƒ  t ƒ } | j ƒ  g } t d | d | d | j	 d | j
 ƒ } t d | d | d | j	 d | j
 ƒ } d d j g  | D] } d | j ƒ  ^ q£ ƒ GHd d j g  | D] } d | j ƒ  ^ qÒ ƒ GHt j j j d	 | d
 |  d | g d | g d d d d d d d d d d g	 g ƒ }	 t j j j d |  j ƒ  d	 | d |	 ƒ }
 |  j ƒ  |  j ƒ  j | ƒ } |
 | } |  j d | d | j ƒ  ƒ |  j ƒ  |  S(   NRD   RE   R>   R?   s     T: %st   ,s   %7.3fs     L: %st
   selectionsR,   t   Tt   Lt   Si    R
   t   tlsost   u_cartt	   selection(   RE   RD   R   t   boolt
   scattererst   sizeR;   t
   iselectionRF   t   max_tlt   min_tlt   joint   stripR'   t   tlst   toolst   generate_tlsost   u_cart_from_tlsR
   t   convert_to_anisotropict   extract_u_cartt
   set_u_cartt   tidy_us(   R,   t   paramst   uct   sgt   selections_1dRH   RI   RJ   t   iRL   RZ   RM   t   utot(    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/fake_f_obs.pyt	   apply_tls‘   s4    //		'	


c         C   s,  d d  l  } t } | j j | j ƒ  ƒ } | j j d | d | j d t ƒ } d } xr t rÈ | j ƒ  } | j j |  j	 ƒ  j
 d | ƒ ƒ } t | ƒ }	 |	 d k r© Pn  | d 7} | d	 k  sW t ‚ qW W| | j |	 } |  j ƒ  }
 |  j ƒ  } | |
 | | | } |  j d
 | |
 | | | ƒ |  S(   Niÿÿÿÿt   axisR<   t   degi    t   translation_cartgš™™™™™¹?i   id   R
   (   t   scitbx.matrixR   t   matrixt   colt   random_double_point_on_spheret   matht$   r3_rotation_axis_and_angle_as_matrixt   rotation_angleR;   t   crystal_symmetryt)   subtract_continuous_allowed_origin_shiftst   abst   AssertionErrort   translation_lengthR
   t   center_of_massR*   (   R,   R_   t   scitbxt   mtt   rot_axist
   rot_matrixt   run_away_countert   translt   transl_no_cont_sht   lR
   t   cmt   ns(    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/fake_f_obs.pyt   apply_rigid_body_shift­   s,    	
	c         C   s÷  d  } g  } xút |  j ƒ  ƒ D]æ\ } } t j ƒ  } | j t j j d | ƒ ƒ xH | j	 ƒ  D]: } | j
 ƒ  }	 | j ƒ  }
 | j |	 ƒ | j |
 ƒ q` Wt j j d | d d  ƒ j ƒ  } | d k r
t | j d | j j ƒ j ƒ  ƒ } | j d | j j ƒ } n  t j j d | d | d	 | j j j d
 | j j j ƒ } | j ƒ  j ƒ  } | j ƒ  } | d k r | } g  } x‰ | D] } | j | j ƒ  ƒ q€Wq | | 7} | } t | ƒ t | ƒ k sÎt ‚ x4 t t | ƒ ƒ D]  } | | c | | j ƒ  7<qáWq W| j ƒ  j  d | ƒ } g  } x= | D]5 } | j | j ƒ  j  d | t |  j ƒ  ƒ ƒ ƒ q.Wd  } | j j! j" | j j! j# g j$ d  ƒ d k rt% d | j& ƒ  d | j' ƒ  d | j j! j" d | j j! j# ƒ } d d j( g  | D] } d | j) ƒ  ^ qéƒ GHn  t j j d | d | d | d | j j j* d | j j j+ d | ƒ } t | j ƒ  ƒ } | j, ƒ  | j- d d ƒ } | j. ƒ  } | j/ d | d d ƒ | j0 ƒ  } | j1 d | j j2 ƒ t j j d | d | d | ƒ } | j3 d d ƒ d  S(   NRp   t   linest   source_infoi    t   d_mint   d_maxt   f_obsR,   t   mask_paramst   sf_and_grads_accuracy_paramst   dataRD   RE   R>   R?   s,   
overall_anisotropic_scale_matrix_b_cart: %sRG   s   %7.3ft   f_calct   f_maskt   k_solt   b_solt   b_cartt   column_root_labels	   F(ake)obst   miller_arrays   R-free-flagst	   file_namet   verboseiÿÿÿÿ(4   t   Nonet	   enumeratet   modelsR   t
   std_stringt   appendt   iotbxt   pdbt   format_cryst1_recordR%   t   format_atom_recordt   format_anisou_recordt   inputt   xray_structure_simpleRr   t   structure_factorsR…   t   high_resolutionR‰   t   resolution_filtert   low_resolutionR'   t   f_modelt   managert   f_bulkt   maskt   accuracyRˆ   t   f_maskst   lenRs   t   ranget   arrayt'   overall_anisotropic_scale_matrix_b_cartt   maxt   mint   countRF   RD   RE   RU   RV   R‹   RŒ   t#   set_observation_type_xray_amplitudet   as_mtz_datasett   generate_r_free_flagst   add_miller_arrayt
   mtz_objectt   writet   output_file_namet   update_solvent_and_scale(   t   rootRp   R_   t   f_calc_datat   f_masks_datat   i_mt   mt   raw_recordst   atomt   rat   ruR   t   dummyt   fmodelt   fcdt   fmst   ft   fmskst   ifmdt   fcalc_averaget   f_masks_data_averageR�   Rc   R…   t   mtz_datasett   r_free_flagsR³   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/fake_f_obs.pyt   simulate_f_obsÅ   sˆ    
"3!	)	
		c         C   s˜   d d l  m } d d  l } |  j ƒ  } | j d | d | j d | j j j d t ƒ d | j	 d | j
 d	 | j j d
 d ƒ ƒ } |  j d | ƒ }  |  S(   Niÿÿÿÿ(   t   geometry_minimizationR
   t   geometry_restraints_managert   geometry_restraints_flagst   defaultt   rmsd_bonds_termination_cutofft   rmsd_angles_termination_cutofft   lbfgs_termination_paramst   max_iterationsiô  t	   new_sites(   t   mmtbx.refinementRÌ   t   scitbx.lbfgsR
   t   lbfgsR   t   geometry_restraintst   flagsR;   t   rmsd_bonds_targett   rmsd_angles_targett   termination_parameterst   replace_sites_cart(   R,   t   restraints_managerR_   t   gmRv   R
   t	   minimized(    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/fake_f_obs.pyt   regularize_geometry  s    				c         C   sw   t  j d | d |  j ƒ  d d ƒ } t  j d | d |  d d d	 d
 d d d d d d d t d d  d | j d d ƒ d  S(   NRÞ   R
   t   wci   t   gradients_calculatorR,   t   temperaturei¸  t   n_stepsi ¡ t	   time_stepgü©ñÒMb@?t    initial_velocities_zero_fractioni    t   n_printid   t   stop_cm_motiont   logt   stop_at_diffR‘   iÿÿÿÿ(   t   cartesian_dynamicst%   gradients_calculator_reciprocal_spaceR
   t   runR;   R’   t   stop_cartesian_dynamics_at_diff(   R,   RÞ   R_   Rã   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/fake_f_obs.pyt   cd  s     				c      	   C   s³  d GH|  j  j j } | } | j ƒ  } t d | d | d | d d ƒ | j ƒ  } | j d  k	 rv | j d | j ƒ n  | j rº t	 d | d	 | d
 | ƒ t d | d | d | d d ƒ n  | j
 j | j
 j g j d  ƒ d k r!t
 d | d	 | d
 | j
 ƒ } t d | d | d | d d ƒ n  | j d  k	 rQt d | d | d | j ƒ } n  | j j | j j g j d  ƒ d k r“t d | d
 | j ƒ } n  | j j | j j g j d  ƒ d k rôt d | d
 | j ƒ } t d | d | d | d d ƒ n  | j ƒ  }	 |	 j ƒ  j ƒ  |	 j ƒ  j | j ƒ  j ƒ  ƒ |	 j ƒ  j | j ƒ  j | j  ƒ  ƒ ƒ |	 j ƒ  j! | j" ƒ  t# j$ d ƒ ƒ |	 j% ƒ  d j& ƒ  }
 t' d  ƒ |
 _( | j) |
 ƒ d  S(   Ns   model:R   R   R   R   s   start:t   rms_differenceR,   RÞ   R_   s   cd:   i    s   min:  R    R<   s   rb:   g      ð?(*   R…   R‰   t   atomic_modelR#   R   t   shake_sites_rmsdR’   t   shake_sites_in_placet   apply_cartesian_dynamicsRð   Rá   RÚ   RÛ   R®   t
   ladp_angleR:   RW   RS   RT   Re   t   rigid_body_shiftRo   Rt   R€   R$   R%   R&   t   set_xyzR
   t   set_uijRP   R\   RE   t   set_bt   extract_u_iso_or_u_equivR   t   u_as_bR”   t   detached_copyt   strt   idt   append_model(   R_   R,   R    RÞ   R·   t   ampR   R   t   xrs_sht   hR»   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/fake_f_obs.pyt   loop_21  sD    	"	"'	"(&c         C   s;  | | f g } |  j  j j j rL | j t d | j ƒ  d | j ƒ  ƒ ƒ n  d } t t j	 |  j  j j j
 t | ƒ ƒ ƒ } xV | D]N } | \ }	 }
 x9 t | ƒ D]+ } t d |  d |	 d |
 d | d | ƒ q£ Wq„ Wx/ t | j ƒ  ƒ D] \ } } t | ƒ | _ qé W| j ƒ  j | j ƒ  j ƒ  t | j ƒ  ƒ ƒ d  S(   NR,   R    i    R_   RÞ   R·   (   R…   R‰   Rò   R)   R–   R#   R$   t   intRm   t   ceilt   ensemble_sizeR¨   t   xrangeR  R“   R”   Rþ   Rÿ   R%   t   set_occt   extract_occ(   R_   R·   R,   R    RÞ   t   xht   counterRQ   t   xh_t   x_t   h_t   mct   i_modelt   model(    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/fake_f_obs.pyt   loop_1V  s&    +c         C   s*   |  d IJt  j j t d t ƒ} |  J| S(   Ns   Default params::
t   process_includes(   R—   t   philt   parset   master_params_strR;   (   Rê   t   parsed(    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/fake_f_obs.pyt   defaultsk  s    
c         C   sÞ  t  |  ƒ d k r; t d | ƒ } | j d d d | ƒ d  St d | ƒ } t j j d |  d t j d | ƒ } | j j ƒ  | j j	 ƒ  } t  | j
 ƒ d k r® t d ƒ ‚ n  t  | j
 ƒ d	 k rÒ t d
 ƒ ‚ n  | j
 d } | j j j j r't j j | ƒ d } t j d | | f ƒ | } n  t j j d | ƒ } t j j j j	 ƒ  } | j j j j rrt | j _ n  t j j d | d t j  j  ƒ  d t j  j! ƒ  d | ƒ }	 |	 j" j# }
 |
 j$ ƒ  j% ƒ  |	 j& ƒ  } t j j' d | d | j( ƒ  ƒ | j) ƒ  j* ƒ  j+ ƒ  } d | k pd | k } |	 j, d t- d d d | ƒ } t j. j/ d | d t ƒ } t j j0 j1 ƒ  } t2 d | d | d | d |
 d | ƒ | j3 d | j j j j4 d  | j5 ƒ  ƒ t6 d | d  | j5 ƒ  d | ƒ d  S(!   Ni    Rê   R   s     t   outt   argst   master_paramss   No PDB file found.i   s   More than one PDB file found.t   _reduces   phenix.reduce %s > %sR�   t   pdb_inpR/   t   ener_libR_   t   x1t   x2t   Ht   Dt   show_energiest   plain_pairs_radiusi   t   assume_hydrogens_all_missingR   t   normalizationR·   R,   R    RÞ   Rp   (7   R¨   R  R   R'   R(   t   process_command_line_argst   syst   stdoutR_   t   extractt   pdb_file_namesR   R…   R‰   Rò   t   add_hydrogenst   ost   patht   basenameR   t   goR—   R˜   Rœ   R   t   pdb_interpretationR  t    use_ramachandran_plot_restraintsR;   t   peptide_linkt   ramachandran_restraintst   processR5   R  t   all_chain_proxiesR    R%   R&   R,   t   assert_xray_structures_equalR�   t   scattering_type_registryt   type_count_dictt   keysRÍ   R   t
   restraintsR£   t	   hierarchyR·   R  t   write_pdb_fileRµ   Rp   RË   (   R  Rê   R  t   processed_argsR_   t   pdb_file_namet   pdb_file_name_rR  t   pdbi_paramst   processed_pdb_fileR    R,   t	   sctr_keyst   has_hdR   RÞ   R·   (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/fake_f_obs.pyRî   q  sj    			
		t   __main__i   (4   t
   __future__R    t   cctbxR   t   cctbx.array_familyR   R7   Rm   R)  R.  t	   iotbx.pdbR—   t   mmtbx.utilsR'   t   libtbxR   t!   mmtbx.dynamics.cartesian_dynamicst   dynamicsRì   R   t(   mmtbx.monomer_library.pdb_interpretationt   mmtbx.monomer_library.servert	   mmtbx.tlsR   t   mmtbx.tls.toolst   mmtbx.f_modelt   libtbx.test_utilsR   t
   iotbx.philt   mmtbx.maskst   libtbx.utilsR   t   seedt   set_random_seedR  t   objectR   R)   R:   RF   Re   R€   RË   Rá   Rð   R  R  R  R*  Rî   R   t   argv(    (    (    sK   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/fake_f_obs.pyt   <module>   sF   0L	
				K			%		7