ó
‚™xTc           @   sÞ   d  d l  m Z d  d l m Z m Z m Z d  d l Z d  d l Z d  d l	 Z	 d  d l
 Z
 d Z e j j d e ƒ Z d „  Z e d „ Z d d e
 j d „ Z e
 j d	 „ Z d
 „  Z e d k rÚ e e
 j d ƒ n  d S(   iÿÿÿÿ(   t   division(   t   Sorryt   Usaget   show_development_warningNs<  
scaling = *sigma volume
  .type = choice
resolution_factor = 1/4.
  .type = float
  .optional = False
high_resolution = None
  .type = float
sharpening = False
  .type = bool
min_sigma_ratio = 3.0
  .type = float
  .optional = False
remove_origin_peak = False
  .type = bool
mandatory_factors = None
  .type = ints
s¯   
data = None
  .type = path
labels = None
  .type = str
map_type = *auto anom native
  .type = choice
diff_limit = None
  .type = float
%s
map_file_name = None
  .type = path
c         C   s¤   |  j  ƒ  r |  j ƒ  }  n  |  j ƒ  }  |  j ƒ  sH |  j ƒ  j ƒ  }  n  |  j ƒ  d  k	 r  |  j |  j ƒ  d k ƒ }  |  j |  j	 ƒ  |  j ƒ  | j
 k ƒ }  n  |  S(   Ni    (   t   is_xray_intensity_arrayt	   f_sq_as_ft
   map_to_asut   is_unique_set_under_symmetryt   merge_equivalentst   arrayt   sigmast   Nonet   selectt   datat   min_sigma_ratio(   t   f_obst   params(    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/patterson_map.pyt   prepare_f_obs+   s    +c         C   s—   | r% |  j  d t ƒ |  j ƒ  }  n  |  j d | j d | j d | j d | j d | j ƒ } d G| j	 ƒ  GH| j
 d k r‰ | j ƒ  n
 | j ƒ  | S(	   Nt   auto_binningt   resolution_factort   mandatory_factorst   d_mint
   sharpeningt   origin_peak_removals   Map gridding: t   sigma(   t   setup_binnert   Truet!   quasi_normalize_structure_factorst   patterson_mapR   R   t   high_resolutionR   t   remove_origin_peakt   n_realt   scalingt   apply_sigma_scalingt   apply_volume_scaling(   R   R   t	   normalizet   map(    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/patterson_map.pyt   calculate_patterson_map6   s    					
c         C   sè  d d l  m } | d  k r: | j |  d d d t ƒ} n  | j j } d  } g  } g  } g  }	 g  }
 | d | j IJxµ | D]­ } | j ƒ  j	 ƒ  } | | k rª | } Pq| | d  k r| | j
 ƒ  rî | j ƒ  rÞ | j | ƒ q&| j | ƒ q)| j ƒ  r)| j ƒ  r|
 j | ƒ q&|	 j | ƒ q)q| q| W| d  k räx¨ | |
 | |	 g D]‘ } t | ƒ d k r£t d d	 d
 j g  | D] } | j ƒ  j	 ƒ  ^ q{ƒ ƒ ‚ qLt | ƒ d k rL| d } | d | j ƒ  j	 ƒ  IJPqLqLWn  | S(   Niÿÿÿÿ(   t   file_readert
   force_typet   hklt   raise_sorry_if_errorss   Reading data from %s...i   s.   Multiple equally good candidates for data:
%s
s)   Please specify labels=<your choice here>.s   
i    s   Defaulting to data in %s(   t   iotbxR&   R   t   any_fileR   t   file_servert   miller_arrayst	   file_namet   infot   label_stringt   is_xray_amplitude_arrayt   anomalous_flagt   appendR   t   lenR   t   join(   R.   t   hkl_int   expected_labelst   outR&   R-   t   obst   all_fst   all_fs_anomt   all_ist   all_is_anomR	   t   labelst   choicest   a(    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/patterson_map.pyt   extract_dataM   sJ    5
c         C   sV  t  d | ƒ t |  ƒ d k s+ d |  k rJ t d t j d d ƒ ƒ ‚ n  d d  l } d d l m } d d	 l m	 } d d
 l m
 } d  } g  } | j j d |  d t d d ƒ } | j j ƒ  }	 |	 j d  k rð t d t j d d ƒ ƒ ‚ n  t d |	 j d |	 j d | ƒ }
 |
 d  k r,t d ƒ ‚ n  t |
 d |	 ƒ}
 |
 } t } |
 j ƒ  rÏ|	 j d k rÀ| d IJt } |
 j ƒ  } t | ƒ } |	 j d  k	 rÌ| j | j ƒ  |	 j k  ƒ } qÌqÏ|
 j ƒ  } n  t d | d |	 d | ƒ } |	 j d  k r.t  j! j" t  j! j# |	 j ƒ ƒ d } | d |	 _ n  | j$ d |	 j ƒ | d |	 j IJd  S(   NR8   i    s   --helps‘   cctbx.patterson_map data.mtz [options]

Calculates a simple or anomalous difference Patterson map.  Output is in CCP4
format.

Full options:

%s
t   prefixs     iÿÿÿÿ(   t   flex(   t   miller(   t   xrayt   argst   master_philt   reflection_file_defR   s7   mmtbx.patterson_map data [options]

Full parameters:
%sR.   R7   s   No suitable data found.R   t   autot   anoms&   Output will be anomalous Patterson mapR#   s
   _patt.ccp4s   Wrote %s(   RI   RJ   (%   R   R4   R   RG   t   as_strt
   iotbx.philt   cctbx.array_familyRC   t   cctbxRD   RE   R   t   philt   process_command_line_with_filest   workt   extractR   RA   R>   R   R   t   FalseR2   t   map_typeR   t   anomalous_differencest   abst
   diff_limitR   t   average_bijvoet_matesR%   t   map_file_namet   ost   patht   splitextt   basenamet   as_ccp4_map(   RF   R8   R*   RC   RD   RE   R6   t   sourcest   cmdlineR   R   t   final_arrayt   is_anomR$   t   base(    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/patterson_map.pyt   runv   sX    					
$	%	
c         C   sM   |  j  d  k r t d ƒ ‚ n+ t j j |  j  ƒ sI t d |  j  ƒ ‚ n  t S(   Ns   Data file not specified.s    The path %s is not a valid file.(   R   R   R   RZ   R[   t   isfileR   (   R   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/patterson_map.pyt   validate_params­   s
    t   __main__i   (   t
   __future__R    t   libtbx.utilsR   R   R   t   libtbx.philt   libtbxt   mathRZ   t   syst   patterson_map_phil_strRO   t   parseRG   R   RS   R%   R   t   stdoutRA   Rd   Rf   t   __name__t   argv(    (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/patterson_map.pyt   <module>   s   		)7	