ó
Ü™xTc           @   sœ  d  d l  m Z d  d l m Z d  d l Z d  d l m Z d  d l m Z d  d l	 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 Z	 d  d	 l m Z d  d
 l 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 l Z d  d l Z d Z  d „  Z! d e" f d „  ƒ  YZ# d d d „ Z% d e j& f d „  ƒ  YZ' d d „ Z( d „  Z) d S(   iÿÿÿÿ(   t   division(   t   utilsN(   t   iotbx_option_parser(   t   combine_unique_pdb_files(   t   reflection_file_reader(   t   reflection_file_utils(   t   flex(   t   miller(   t   format_value(   t   Sorryt   null_out(   t   adopt_init_args(   t   runtime_utils(   t   StringIOs»  f_obs_1_file_name = None
  .type = path
  .help = File with Fobs data
  .short_caption = Reflections file 1
  .style = bold file_type:hkl process_hkl child:fobs:f_obs_1_label force_data
f_obs_1_label = None
  .type = str
  .short_caption = Labels 1
  .input_size = 160
  .style = bold renderer:draw_fobs_label_widget
f_obs_2_file_name = None
  .type = path
  .help = File with Fobs data
  .short_caption = Reflections file 2
  .style = bold file_type:hkl process_hkl child:fobs:f_obs_2_label force_data
f_obs_2_label = None
  .type = str
  .short_caption = Labels 2
  .input_size = 160
  .style = bold renderer:draw_fobs_label_widget
high_resolution = None
  .type = float
  .help = High resolution data cutoff
  .style = bold resolution
low_resolution = None
  .type = float
  .help = Low resolution data cutoff
  .style = bold resolution
sigma_cutoff = None
  .type = float
  .help = Fobs sigma cutoff
  .short_caption = F(obs) sigma cutoff
phase_source = None
  .type = path
  .help = PDB file with a model or reflection file with the phases
  .short_caption = PDB file for phasing
  .style = bold OnChange:validate_phase_source file_type:pdb
scattering_table = *xray neutron
  .type = choice(multi=False)
  .help = Choices of scattering table for structure factors calculations
output_file = None
  .type = path
  .style = hidden
output_dir = None
  .type = path
  .short_caption = Output folder
  .style = output_dir
  .expert_level = 4
file_name_prefix = None
  .type = str
  .input_size = 400
  .help = Base file name for output (GUI parameter only)
  .expert_level = 4
job_id = None
  .type = int
  .style = hidden
  .help = GUI parameter only
  .expert_level = 4
ignore_non_isomorphous_unit_cells = False
  .type = bool
  .short_caption = Ignore non-isomorphous unit cells
include scope libtbx.phil.interface.tracking_params
advanced
  .expert_level = 3
  .short_caption = Advanced options
  .style = auto_align menu_item
{
  multiscale = False
    .type = bool
    .expert_level = 2
    .short_caption = Use multiscaling method
  omit_selection = None
    .type = atom_selection
    .short_caption = Omit atom selection
    .help = The selected atoms will be left out of the phasing model.
    .expert_level = 1
  anomalous = False
    .type = bool
    .short_caption = Use anomalous differences instead of amplitdues
    .help = Experimental feature: generate a difference map using the       anomalous differences of each dataset instead of the amplitudes,       similar to the log-likelihood gradient difference map in Phaser       SAD phasing (or simple anomaloues residual map), only using two       experimental datasets instead of F-obs and F-calc.
    .expert_level = 3
}
find_peaks_holes = False
  .type = bool
  .short_caption = Find peaks and holes in map
map_cutoff = 3.0
  .type = float
  .short_caption = Sigma-level cutoff for peak search
peak_search
  .short_caption = Peak search parameters
  .style = auto_align box menu_item
{
include scope mmtbx.find_peaks.master_params
}
c           C   s   t  j j t d t ƒS(   Nt   process_includes(   t   iotbxt   philt   parset   fo_minus_fo_master_params_strt   True(    (    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/maps/fobs_minus_fobs_map.pyt   fo_minus_fo_master_params|   s    t   compute_fo_minus_fo_mapc           B   s8   e  Z d e d e d d d e e e d  „
 Z d „  Z RS(   c   -      C   sû  | d  k r t j } n  t |  t ƒ  ƒ g  } x:t | ƒ D],\ } } | s^ | d | IJn  | j ƒ  r€ | r€ | j ƒ  } n | r› | j ƒ  s› t ‚ n  |	 d  k	 rÆ | t	 |	 ƒ k  rÆ |	 | } n* | j
 d t j | j ƒ  j ƒ  t ƒ ƒ } t j j d | d | d d d | ƒ } | j d | ƒ | j d	 | ƒ | sZ| j ƒ  j d	 | ƒ | Jn  | j | ƒ q; W| d
 |  _ g  } xi | D]a } | j ƒ  } d | j ƒ  | j ƒ  } t j
 d | j ƒ  d | j ƒ  | ƒ } | j | ƒ q…W| d
 j d | d j ƒ  ƒ \ } } | j d | d ƒ \ } } | j d | ƒ \ } } | |  _ | j ƒ  j | j ƒ  ƒ snt ‚ | j ƒ  j | j ƒ  ƒ s�t ‚ d } t j  t j! | j ƒ  ƒ t j! | j ƒ  ƒ ƒ } | d
 k r
t j  t j! | j ƒ  ƒ t j! | j ƒ  ƒ ƒ | } n  | j
 d | j ƒ  | ƒ } | rG| j" d | d d ƒ } n  | s| d IJ| d IJ| d IJ| j# d t$ d | j ƒ  j ƒ  ƒ ƒ | j% | ƒ xs| j& ƒ  j' ƒ  D]\} | j& ƒ  j( | ƒ } | j) | ƒ } | j) | ƒ } | j* ƒ  \ } } | j+ d | ƒ }  | j, t- ƒ }! t j  t j! | j ƒ  | j ƒ  ƒ ƒ }" t j  t j! | j ƒ  | j ƒ  ƒ d ƒ } d  }# | d
 k r�|" | }# n  t j. d | j ƒ  d | j ƒ  ƒ j/ ƒ  }$ | j& ƒ  j0 d | d t d t ƒ }% d }& | |& | |% |  |! |$ t1 d |# ƒ f IJq°Wn  t j. d | j ƒ  d | j ƒ  ƒ j/ ƒ  |  _2 t j  t j! | j ƒ  | j ƒ  ƒ ƒ }" t j  t j! | j ƒ  | j ƒ  ƒ d ƒ } d  |  _3 | d
 k r¹|" | |  _3 n  d „  }' | st j
 d | d | j ƒ  | j ƒ  ƒ }( |' d |( d  | ƒ |  _4 nª | j5 ƒ  }) | j5 ƒ  }* |) j ƒ  j |* j ƒ  ƒ sDt ‚ t j
 d |) d |) j ƒ  |* j ƒ  ƒ }( | j ƒ  j6 |( ƒ }+ |' d |( d  |+ ƒ }, |, j7 d |, j ƒ  d! ƒ |  _4 |  j4 j ƒ  rÖt4 j ƒ  |  _4 n  g  |  _8 |
 r÷|  j9 ƒ  |  _8 n  d  S("   Ns   Data set: %dt   datat   xray_structuret   r_free_flagst   target_namet   ls_wunit_k1t   f_obst   logt   outi    g      ð?t
   miller_sett   otheri   t   reflections_per_biniú   t    s   Fobs1_vs_Fobs2 statistics:s8   Bin# Resolution range  Compl.  No.of refl. CC   R-factoriô  t   d_maxi   t   xt   yt   i_bint   show_bin_numbert   show_countss)   %3d: %-17s   %4.2f %6d         %5.3f  %6ss   %6.4fc         S   sb   t  j d |  d t j |  j ƒ  j ƒ  d ƒ ƒ j d | ƒ } t  j d |  d |  j ƒ  | j ƒ  ƒ S(   NR   R   i   t   phase_source(   R   t   arrayR   t   doublet   indicest   sizet   phase_transferR   (   t   miller_arrayR(   t   tmp(    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/maps/fobs_minus_fobs_map.pyR-   â   s
    $	R.   R(   y               @(:   t   Nonet   syst   stdoutR   t   localst	   enumeratet   anomalous_flagt   average_bijvoet_matest   AssertionErrort   lenR)   R   t   boolR   R,   t   Falset   mmtbxt   f_modelt   managert   remove_outlierst   update_solvent_and_scalet   infot$   show_rfactors_targets_scales_overallt   appendt   fmodelR   t   k_anisotropict   k_isotropicR   t   common_setsR+   t   all_eqt   sumt   abst
   multiscalet   setup_binnert   mint   use_binning_oft   binnert
   range_usedt	   selectiont   selectt	   d_max_mint   completenesst   countR   t   linear_correlationt   coefficientt
   bin_legendR   t   cct   r_factort	   map_coefft   anomalous_differencest
   common_sett   customized_copyt
   file_namest   write_map_file(-   t   selft   data_arraysR   R   t   silentt   output_filet   peak_searcht
   map_cutofft   peak_search_paramst   r_free_arrayst	   write_mapRJ   t	   anomaloust   fmodelst   i_seqt   dR   RC   t   f_obsst   obst   f_obs_scalet   fobs_1R<   t   fobs_2t   scale_k1t   denR%   t   selt   f1t   f2R"   t   d_mint   complt   n_reft   numt   rRX   t   d_ranget   fmtR-   t   difft   dano_1t   dano_2t   f_model_phasest
   map_coeffs(    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/maps/fobs_minus_fobs_map.pyt   __init__€   sÌ     *	&	!!18


%(,*	(,			!			c         C   s[  d d d „  ƒ  Y} t  j ƒ  } | d d d d ƒ } |  j j d | j ƒ  d | ƒ } | j d	 | j ƒ  d
 f ƒ |  j d  k	 r� |  j } n d } | j d | ƒ | j ƒ  } | j	 | ƒ | j
 d | ƒ | g |  _ |  j rTd d l m } d d l m } |  j }	 |  j r t ƒ  }	 n  |  j }
 | j d |
 d d  d |  j d |  j d |  j d |	 ƒ j ƒ  } |
 j j ƒ  j | j ƒ | _ | j d |
 d d  d |  j d |  j d |  j d |	 ƒ j ƒ  } |
 j j ƒ  j | j ƒ | _ | j d | d | d |  j ƒ } t j j  | ƒ d d } | j! d | d t" d t" d |	 ƒ |  j j | ƒ n  |  j S(   Nt   map_coeffs_mtz_label_managerc           B   s&   e  Z d  „  Z d „  Z d d „ Z RS(   c         S   s   | |  _  | |  _ d  S(   N(   t   _amplitudest   _phases(   R`   t
   amplitudest   phases(    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/maps/fobs_minus_fobs_map.pyRƒ     s    	c         S   s   |  j  S(   N(   R…   (   R`   (    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/maps/fobs_minus_fobs_map.pyR‡     s    c         S   s    | d  k s | s t ‚ |  j S(   N(   R0   R7   R†   (   R`   t
   root_labelt   anomalous_sign(    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/maps/fobs_minus_fobs_map.pyRˆ   	  s    N(   t   __name__t
   __module__Rƒ   R‡   R0   Rˆ   (    (    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/maps/fobs_minus_fobs_map.pyR„     s   		R‡   t   FoFoRˆ   t   PHFct   column_root_labelt   label_decorators   > column label %s = phenix %st   FoFoPHFcs   FoFoPHFc.mtzs   file name %st	   file_nameiÿÿÿÿ(   t   find_peaks_holes(   t
   find_peaksRC   t   map_typeR‚   Re   t   paramsR   t   peakst   holesi    s
   _peaks.pdbt   include_anomt   include_water(    (#   R   t
   std_stringRZ   t   as_mtz_datasetR‡   RB   Rc   R0   t
   mtz_objectt   add_historyt   writeR^   Rd   t   mmtbx.command_lineR“   R;   R”   R   Rb   R
   RC   R=   Re   Rf   t   peaks_mappedR   t	   unit_cellt   orthogonalizet   sitest   peaks_holes_containert   ost   patht   splitextt   save_pdb_fileR:   (   R`   R„   t   mtz_history_buffert   lbl_mgrt   mtz_datasetR’   R�   R“   R”   t   peak_search_logRC   R—   R˜   t   resultt   pdb_out(    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/maps/fobs_minus_fobs_map.pyR_     sf    						 							
			N(   R‹   RŒ   R0   R:   R   Rƒ   R_   (    (    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/maps/fobs_minus_fobs_map.pyR      s   us   phenix.fobs_minus_fobs_mapc   +      C   s×  t  |  ƒ d k r d g }  n  d } t d d | d | ƒ j d d d	 d
 d ƒj ƒ  j d |  ƒ } | d  k r| t j } n  | j j	 s¶ t
 j d d | ƒ| d IJ| |  IJ| Jn  t
 j d | j d | j d t ƒ  d | d t ƒ } | j } | j j	 s| d IJ| j d | ƒ | Jn  | j ƒ  } d  } | j ršd  | j | j | j g k rot d d d ƒ ‚ n  t j j ƒ  }	 t j j | j d d ƒ}
 |	 j |
 ƒ t j j | j d d ƒ} |	 j | ƒ \ } } t j j | j d d ƒ} |	 j | ƒ \ } } t ƒ  } |	 j d | ƒ | s+| rPt d d d d | j  ƒ  ƒ ‚ n; | s\| r‹t! j" d d  d! d" d# d$ d% | j  ƒ  ƒ n  |	 j# ƒ  } n9 t
 j d | j d | j d t ƒ  d t ƒ  ƒ } | j$ } | j% } t  | j% ƒ d k r| j d  k	 r| j g } qt d& ƒ ‚ n  g  } t  | j& ƒ d' k r«x}| j& D]a } t' j( d( | d) t d* | g d+ t) ƒ  ƒ } t
 j* d, | d- t d t) ƒ  ƒ } | j+ | j, ƒ qCWn| j | j g j- d  ƒ d' k rÛt d. ƒ ‚ n  xÛ t. | j | j g | j/ | j0 g ƒ D]² \ } } t1 j2 d/ | d0 t3 ƒ } t' j( d( | d) t d* | g d+ t) ƒ  ƒ } t
 j4 ƒ  j ƒ  } | d  k	 r~| g | _5 n  t
 j* d, | d1 | d- t d t) ƒ  ƒ } | j+ | j, ƒ qWt  | ƒ d' k rãt d2 j6 t7 ƒ ƒ ‚ n  | j j	 s1x? t8 | ƒ D]. \ } } | d3 | IJ| j9 d4 | ƒ | JqüWn  t: d5 | ƒ } | j; d | ƒ t  | j< ƒ d k rtt d6 ƒ ‚ n  t= j> ƒ  } x< | j? D]1 } | j@ ƒ  j- d7 ƒ d k rŠ| j+ | ƒ qŠqŠW| j+ t jA jB d( | ƒ ƒ t jA jC d8 d  d9 | ƒ }
 |
 jD ƒ  }  t= jE |  jF ƒ  jG ƒ  t3 ƒ }! | jH jI d  k	 r…| d: IJ| d; | jH jI IJ|  jJ ƒ  jK | jH jI ƒ }! | d< |! j- t ƒ IJn  |
 jL ƒ  }" |" jM |! ƒ }" | j j	 sÎ| d= IJ|" jN d4 | ƒ | Jn  | d jO ƒ  }# | d> jO ƒ  }$ | d jP d? | jQ d@ | jR ƒ jS |# ƒ | d <| d> jP d? | jQ d@ | jR ƒ jS |$ ƒ | d> <| jT d  k	 rÕxw d d> g D]f }% | |% jU ƒ  d  k	 rh| |% jV ƒ  | |% jU ƒ  | jT k }& | |% jM |& ƒ jS |# ƒ | |% <qhqhWn  x[ t8 | ƒ D]M \ }' }( |( jW ƒ  jG ƒ  d k rât dA |' d> |( jO ƒ  jX ƒ  f ƒ ‚ qâqâW| jY }) |) d  k rp| jZ d  k	 rpdB | jZ | j[ f }) n  t\ dC | dD |" d | dE | j j	 dF |) dG | j] dH | j^ dI | j_ dJ | jH j` dK | jH ja ƒ 
jb }* |* S(L   Ni    s   --helpsA  Examples:

phenix.fobs_minus_fobs_map f_obs_1_file=data1.mtz f_obs_2_file=data2.sca f_obs_1_label=FOBS1 f_obs_2_label=FOBS2 model.pdb

phenix.fobs_minus_fobs_map f_obs_1_file=data.mtz f_obs_2_file=data.mtz f_obs_1_label=FOBS1 f_obs_2_label=FOBS2 phase_source=model.pdb high_res=2.0 sigma_cutoff=2 scattering_table=neutront   usages   %s [options]t   descriptions   --silentt   actiont
   store_truet   helps   Suppress output to the screen.t   argss   phenix.fobs_minus_fobs_mapR   s   Command line arguments: t   cmd_cst   master_paramsR   t    suppress_symmetry_related_errorss   *** Parameters:s;   The file parameters (f_obs_1_file_name, f_obs_2_file_name, s0   phase_source) must be specified explicitly when s'   ignore_non_isomorphous_unit_cells=True.t
   force_typet   pdbt   hkls7   Incompatible space groups in input files:
%s
All files sC   must have the same point group (and ideally the same space group). sB   Please note that any symmetry information in the PDB file will be s   used first.t   messaget   warnR   s9   Crystal symmetry mismatch:
%s
Calculations will continue s=   using the symmetry in the PDB file (or if not available, the s<   first reflection file), but the maps should be treated with s   extreme suspicion.s   No PDB file found.i   t   crystal_symmetryt   force_symmetryt   reflection_filest   errt   reflection_file_servert
   keep_goings   No reflection data file found.R’   t   ensure_read_accesst
   parameterst    s   *** Summary for data set %d:t   fR^   s   No coordinate file given.t   CRYST1t   source_infot   liness'   Will omit selection from phasing model:s     s   %d atoms selected for removals   *** Model summary:i   Rw   R"   s5   No data left in array %d (labels=%s) after filtering!s	   %s_%s.mtzRa   R   Rb   Rc   Rd   Re   Rf   RJ   Ri   (c   R8   R   t   optiont   enable_symmetry_comprehensivet   processR0   R1   R2   t   optionsRb   R   t   print_headert   process_command_line_argsRµ   t   symmetryR   R   R–   t   showt   extractt!   ignore_non_isomorphous_unit_cellst   f_obs_1_file_namet   f_obs_2_file_nameR(   R	   R   R=   t   file_readert   any_filet   process_pdb_filet   process_reflections_fileR   t   getvaluet   libtbxt	   call_backt   as_symmetry_objectR¾   t   pdb_file_namesRÀ   R   RÂ   R
   t   determine_data_and_flagsRB   R   RT   t   zipt   f_obs_1_labelt   f_obs_2_labelR   t   any_reflection_fileR:   t   data_and_flags_master_paramst   labelst   joint   errorsR4   t   show_comprehensive_summaryR   t   report_non_uniquet   unique_file_namesR   R›   t   raw_recordst   upperRº   t   format_cryst1_recordt   inputt   construct_hierarchyR9   t   atomsR,   t   advancedt   omit_selectiont   atom_selection_cacheRP   t   xray_structure_simpleRQ   t   show_summaryR@   t   resolution_filtert   high_resolutiont   low_resolutiont   set_infot   sigma_cutofft   sigmasR   R+   t   label_stringRc   t   file_name_prefixt   job_idR   R“   Re   Rd   RJ   Ri   R^   (+   Rµ   t   command_nameR   t   examplest   command_linet   processed_argst   working_philR–   t   consensus_symmetryt   symm_managert   pdb_int   hkl_in_1t   sg_err_1t   uc_err_1t   hkl_in_2t   sg_err_2t   uc_err_2R   R¾   Rß   Rm   t   reflection_fileRÂ   t   determine_data_and_flags_resultR’   t   labelRÅ   t   ifobst   fobst   pdb_combinedt   raw_recst   rect	   hierarchyt   omit_selR   t   info0t   info1t   iRt   t   kR   t   output_file_namet   output_files(    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/maps/fobs_minus_fobs_map.pyt   run?  sD    
		

						
													!				


'* 				t   launcherc           B   s   e  Z d  „  Z RS(   c         C   s6   t  j |  j ƒ t  j |  j ƒ t d t |  j ƒ ƒ S(   NRµ   (   R¦   t   makedirst
   output_dirt   chdirR  t   listRµ   (   R`   (    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/maps/fobs_minus_fobs_map.pyR  ø  s    (   R‹   RŒ   R  (    (    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/maps/fobs_minus_fobs_map.pyR  ÷  s   c         C   s”   d  |  j |  j g k r' t d ƒ ‚ n  d  |  j |  j g k rN t d ƒ ‚ n  |  j d  k rl t d ƒ ‚ n  t j j	 |  j
 ƒ s� t d ƒ ‚ n  d  S(   Ns,   You must supply two files containing F(obs).s5   You must define the labels for both reflection files.s(   You must specify a PDB file for phasing.s    Output directory does not exist.(   R0   RÕ   RÖ   R	   Râ   Rã   R(   R¦   R§   t   isdirR!  (   R–   t   callback(    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/maps/fobs_minus_fobs_map.pyt   validate_paramsý  s    c         C   s‰   g  } |  d  k	 r t |  t ƒ r3 t |  ƒ d k s9 t ‚ | j |  d d f ƒ t |  ƒ d k r | j |  d d f ƒ q n  | g  f S(   Ni    s   Map coefficientsi   s   Map peaks and holes(   R0   t
   isinstanceR#  R8   R7   RB   (   R®   R  (    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/maps/fobs_minus_fobs_map.pyt
   finish_job  s    '(*   t
   __future__R    R;   R   t   mmtbx.f_modelt   iotbx.option_parserR   t	   iotbx.pdbR   R   R   R   t   iotbx.file_readert   iotbx.symmetryt
   iotbx.philt   cctbx.array_familyR   t   cctbxR   t   libtbx.str_utilsR   t   libtbx.utilsR	   R
   RÜ   R   R   t   libtbx.callbackst	   cStringIOR   R¦   R1   R   R   t   objectR   R0   R  t   target_with_save_resultR  R&  R(  (    (    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/maps/fobs_minus_fobs_map.pyt   <module>   s6   e	À¸
