ó
•™xTc           @   s�  d  d l  m Z d  d l m Z m Z d  d l m Z d  d l Z d Z d Z	 d Z
 d Z d	 Z d
 Z d Z i d d 6d d 6d d 6d d 6Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d d „ Z d d „ Z d „  Z d „  Z d „  Z d  „  Z d! „  Z d" „  Z d# e f d$ „  ƒ  YZ e e d% „ Z d& „  Z  d' d( „ Z! d) e f d* „  ƒ  YZ" e e# d+ „ Z$ d S(,   iÿÿÿÿ(   t   division(   t   ifloort   iceil(   t   adopt_init_argsNi   i   i   i   i   i    i@   s   2mFo-DFct   2FOFCWTs   2mFo-DFc_no_fillt   2FOFCWT_no_fills   mFo-DFct   FOFCWTt	   anomaloust   ANOMt   MapNotFoundc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyR	      s   t   serverc           B   s@  e  Z d  Z d d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z d d d d „ Z e d „ Z d „  Z d „  Z d „  Z d „  Z d d d e d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d d e d e e e d „ Z  e d „ Z! RS(    s9  
  Manager for files containing map coefficients (either as complex arrays or
  separate F, PHI, and optional FOM).  Once an MTZ file or collection of
  Miller arrays is loaded, individual maps can be quickly retrieved, and it
  includes built-in recognition of standard map labels used in PHENIX (and
  CCP4).
  c         C   sŽ  | d  k	 s$ t | ƒ d k s$ t ‚ | |  _ | |  _ t |  j ƒ d k r� d d l m } | j | d d ƒ} | j d ƒ | j	 j |  _ n  t |  j ƒ d k sª t ‚ g  |  _
 g  |  _ g  |  _ g  |  _ g  |  _ g  |  _ g  |  _ i  |  _ d d l m } x…|  j D]z} | j ƒ  j ƒ  } |  j j | ƒ | j ƒ  sL| j ƒ  r�| j d ƒ rn|  j j | ƒ q†|  j j | ƒ q| j ƒ  rà| j d ƒ sº| j d ƒ sº| j d	 ƒ rÍ|  j j | ƒ q†|  j
 j | ƒ q| j ƒ  r3| j d
 ƒ r|  j j | ƒ q†| j d ƒ r†|  j j | ƒ q†q| j ƒ  rR|  j j | ƒ q| j ƒ  r| | j ƒ  ƒ r†|  j j | ƒ q†qqWd  S(   Ni    iÿÿÿÿ(   t   file_readert
   force_typet   hkl(   t   looks_like_r_free_flags_infot   FCt   FMODELs   F-modelt   PHt   FOM(   t   Nonet   lent   AssertionErrort	   file_namet   miller_arrayst   iotbxR   t   any_filet   assert_file_typet   file_servert
   map_coeffst   array_labelst   data_arrayst   phase_arrayst   weight_arrayst   rfree_arrayst   fcalc_arrayst
   _pdb_cachet   iotbx.reflection_file_utilsR   t   infot   label_stringt   appendt   is_xray_amplitude_arrayt   is_xray_intensity_arrayt
   startswitht   is_complex_arrayt   is_real_arrayt   is_bool_arrayt   is_integer_array(   t   selfR   R   R   t   fR   t   arrayt   labels(    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyt   __init__!   sP    $										c         C   s   d |  j  k S(   Ns   2FOFCWT,PH2FOFCWT(   R   (   R1   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyt   is_phenix_refine_mapsM   s    c         C   s   d |  j  k S(   Ns   2mFoDFc,P2mFoDFc(   R   (   R1   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyt   is_cctbx_mapsP   s    c         C   s:   d |  j  k s d |  j  k o9 d |  j  k o9 d |  j  k S(   Nt   FPs   FP,SIGFPt   PHIMt   FOMM(   R   (   R1   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyt   is_resolve_mapS   s    c         C   s   d |  j  k p d |  j  k S(   Ns   FWT,PHWTs
   FWT,PHIFWT(   R   (   R1   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyt   is_ccp4_style_mapW   s    c         C   s   d |  j  k S(   Ns   DELFWT,PHDELWT(   R   (   R1   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyt   is_ccp4_style_difference_map[   s    c         C   s:   d |  j  k s d |  j  k o9 d |  j  k o9 d |  j  k S(   NR8   s   FP,SIGFPt   PHIBR   (   R   (   R1   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyt   is_solve_map^   s    c         C   s7   x0 |  j  D]% } | j ƒ  j ƒ  j d ƒ r
 t Sq
 Wt S(   NR   (   R   R'   R(   R,   t   Truet   False(   R1   R3   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyt   is_anomalous_mapb   s    c         C   s   t  |  j ƒ d k S(   Ni    (   R   R   (   R1   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyt   contains_map_coefficientsh   s    c         C   s(   t  |  j ƒ d k o' t  |  j ƒ d k S(   Ni    (   R   R    R!   (   R1   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyt   contains_amplitude_and_phasek   s    c         C   sP  d \ } } } |  j |  j } | d k r; | |  j 7} n  x¤ | D]œ } | d  k rB | j ƒ  j }	 | j ƒ  j ƒ  }
 | d  k	 r© |
 | k s� |	 d | k rÛ | } qÛ qÞ |	 d d k rÂ | } qÞ |	 d d k rÞ | } qÞ qB qB WxÛ |  j D]Ð } | d  k rì | j ƒ  j ƒ  }	 | d  k	 r7|	 | k r¹| } qì q¹q¼|	 d k rL| } q¼|	 d k rpd |  j k rp| } q¼|	 d	 k r¤d |  j k p—d |  j k r¤| } q¼|	 d
 k r¼| } q¼qì qì Wx€ |  j	 D]u } | d  k rÊ| j ƒ  j ƒ  }	 | d  k	 r|	 | k r<| } q<q?|	 d k r'| } q?|	 d k r?| } q?qÊqÊW| | | f S(   NR   R   s   F-modeli    R8   t   FR9   R>   t   PHICt   PHIR:   R   (   NNN(   s   FCs   FMODELs   F-model(
   R   R    R   R$   R'   R4   R(   R!   R   R"   (   R1   t   f_labelt	   phi_labelt	   fom_labelt   f_arrayt	   phi_arrayt	   fom_arrayt   allowed_arraysR3   R4   R(   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyt   get_amplitudes_and_phasesn   sT    						c      	   C   s¿  g  } g  } d  } g  } g  } g  } x–|  j D]‹} | j ƒ  j ƒ  }	 |	 j d ƒ r^ t } n |	 j d ƒ rv t } n  |	 j d ƒ s” |	 j d ƒ r¤ | j | ƒ q. |	 j d ƒ sÂ |	 j d ƒ rÒ | j | ƒ q. |	 j d ƒ rˆt	 }
 d } d	 |	 k r|
 t
 O}
 | d
 7} n  | r,|	 j d ƒ d } n* | | k rV| d | j | ƒ d 7} n  | j | ƒ | j t d | d |
 d | ƒ ƒ q. |	 j d ƒ s. |	 j d ƒ r¬q. q. | j | ƒ q. Wg  } g  } xÄ | D]¼ } | j ƒ  j ƒ  }	 t }
 d } d	 |	 k r|
 t
 O}
 | d
 7} n  | r3|	 j d ƒ d } n* | | k r]| d | j | ƒ d 7} n  | j | ƒ | j t d | d |
 d | ƒ ƒ qÐWx(| D] } | j ƒ  j ƒ  }	 d } t }
 d	 |	 k rÞ| d
 7} |
 t
 O}
 n  |	 j d ƒ rú| d 7} nH |	 j d ƒ s|	 j d ƒ r%|
 t O}
 n | r8|
 t O}
 n
 | d 7} | r^|	 j d ƒ d } n* | | k rˆ| d | j | ƒ d 7} n  | j | ƒ | j t d | d |
 d | ƒ ƒ q—W| S(   Nt   _no_fillt   _fillR   t   2mFoDFcR   t   mFoDFcR   R   t   neutront   _neutront   ,i    s   _%di   R   t   map_typet   map_names   F-modelR   s   mFo-DFcs   2mFo-DFct   _filled(   R   R   R'   R(   t   endswithR@   RA   R,   R)   t   MAP_TYPE_ANOMALOUSt   MAP_TYPE_NEUTRONt   splitt   countt   map_infot   MAP_TYPE_DIFFt   MAP_TYPE_F_OBSt   MAP_TYPE_FILLED(   R1   t   keep_column_labelst   f_mapst	   diff_mapst   default_is_filledt   all_mapst   unknown_mapst
   have_namesR3   R4   RW   RX   t   unfilled_mapst   filled_maps(    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyt   get_phenix_maps�   s’    		



c      	   C   sw   |  j  ƒ  \ } } | d  k rE |  j d d d d d d d t ƒ } n  d d	 l m } | d
 d d g ƒ } | j | ƒ S(   NRH   R8   RI   R9   RJ   R:   t   weightediÿÿÿÿ(   t
   array_infoR4   t   FWTt   PHWT(   t   get_ccp4_mapsR   t   _convert_amplitudes_and_phasesR@   t   cctbx.millerRn   t   set_info(   R1   R   t
   null_valueRn   R'   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyt   get_resolve_mapê   s    c      	   C   sV   |  j  d d d d d d d t ƒ } d d	 l m } | d
 d d g ƒ } | j | ƒ S(   NRH   R8   RI   R>   RJ   R   Rm   iÿÿÿÿ(   Rn   R4   Ro   Rp   (   Rr   R@   Rs   Rn   Rt   (   R1   R   Rn   R'   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyt   get_solve_mapó   s
    c         C   sj   d  } } xS |  j D]H } | j ƒ  j ƒ  } | j d ƒ rD | } q | j d ƒ r | } q q W| | f S(   Ns   FWT,s   DELFWT,(   R   R   R'   R(   R,   (   R1   t   f_mapt   diff_mapR3   R4   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyRq   ú   s    
	c         C   sC   x< |  j  D]1 } | j ƒ  j ƒ  } | j ƒ  j d ƒ r
 | Sq
 Wd  S(   NR   (   R   R'   R(   t   upperR,   R   (   R1   R3   R4   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyt   get_anomalous_map  s
    c      	   C   s©   |  j  | | | ƒ \ } } } | d  k sC | j ƒ  rŠ | d  k rŠ t d d |  j d j |  j ƒ t | ƒ t | ƒ t | ƒ f ƒ ‚ n  t d | d | d | d | ƒ S(   Ns/   Couldn't find amplitude or phase arrays in %s.
s5   File contents:
%s
Expected labels: F=%s PHI=%s FOM=%ss   
R2   t   phit   fomRm   (	   RO   R   R-   R	   R   t   joinR   t   strt   combine_f_phi_and_fom(   R1   RH   RI   RJ   Rm   R2   R|   R}   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyRr     s    %c         K   s%   |  j  | | | ƒ } |  j | | � S(   N(   Rr   t   _write_ccp4_map(   R1   RH   RI   RJ   t   kwdsR   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyt   convert_any_map  s    	c         K   s"   |  j  d | ƒ } |  j | | � S(   NRH   (   Rr   R�   (   R1   t	   map_labelR‚   R   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyt   convert_complex_map  s    c         K   s-   |  j  ƒ  } | | d <t | d <|  j | �  S(   NR   t   simple_file_name(   Rv   R@   R�   (   R1   R‚   R   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyt   convert_resolve_map  s    

c         K   s-   |  j  ƒ  } | | d <t | d <|  j | �  S(   NR   R†   (   Rw   R@   R�   (   R1   R‚   R   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyt   convert_solve_map$  s    

c         K   sq   t  |  j ƒ  ƒ } g  } xR | D]J } | d  k r7 q n  | | d <|  j | �  } | j t j j | ƒ ƒ q W| S(   NR   (   t   listRq   R   R�   R)   t   ost   patht   abspath(   R1   R‚   t   map_coeffs_listt   filesR   t   output_file(    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyt   convert_ccp4_map*  s     
c         K   s3   |  j  ƒ  } | d  k	 r/ | | d <|  j | �  Sd  S(   NR   (   R{   R   R�   (   R1   R‚   R   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyt   convert_anomalous_map5  s
    
c         K   sp   |  j  ƒ  } g  } xW | D]O } d | | j f } | | d <|  j | j | � | j t j j | ƒ ƒ q W| S(   Ns
   %s_%s.ccp4R�   (   Rl   RX   R�   R   R)   RŠ   R‹   RŒ   (   R1   t	   file_baseR‚   Rg   RŽ   t   mapR   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyt   convert_phenix_maps<  s    
c         k   sG   x@ |  j  D]5 } | j ƒ  j ƒ  } |  j | | � } | | f Vq
 Wd  S(   N(   R   R'   R(   R…   (   R1   R‚   R   R4   t   map_file(    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyt   convert_all_map_coefficientsF  s    c         C   s¦   |  j  j | d ƒ \ } } | d  k s? t j j | ƒ | k r¢ d d l m } | j | d d d t	 ƒ} | j
 d ƒ | j } | t j j | ƒ f |  j  | <n  | S(   Ni    iÿÿÿÿ(   R   R   t   pdbt   raise_sorry_if_errors(   Ni    (   R%   t   getR   RŠ   R‹   t   getmtimeR   R   R   R@   R   t   file_object(   R1   R   t   pdb_int   mtimeR   R2   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyt   get_pdb_fileL  s    $		"g      Ð?c	         C   s¥  d  }	 | d  k	 r9 |  j | ƒ }
 |
 j j ƒ  j ƒ  }	 n  | d  k rñ | rk t j j |  j ƒ d d } qñ | rº | j	 ƒ  j
 d } t j | | ƒ } t j j |  j ƒ d d | } qñ | j	 ƒ  j
 d } t j j |  j ƒ d d | } n  | r5t j j | ƒ r5t j j | ƒ t j j |  j ƒ k  r5| S| j d | ƒ } | rZ| j ƒ  n
 | j ƒ  | j ƒ  } t d |	 d | j ƒ  d | d | j ƒ  d	 | ƒ | S(
   Ni    s   .ccp4s   _%s.ccp4t   resolution_factort
   sites_cartt	   unit_cellt   map_datat   n_realR   (   R   Rž   t	   hierarchyt   atomst   extract_xyzRŠ   R‹   t   splitextR   R'   R4   t   standard_map_namesR™   t   existsRš   t   fft_mapt   apply_sigma_scalingt   apply_volume_scalingt   real_mapt   write_ccp4_mapR¡   R£   (   R1   R   t   pdb_fileR�   R†   RŸ   t   sigma_scalingt   forcet   use_standard_map_namesR    Rœ   t   lab1RX   Rª   R¢   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyR�   W  s:    	 $'
c         C   s>  g  } |  j  ƒ  s |  j ƒ  r- |  j ƒ  } n|  j ƒ  rž |  j ƒ  \ } } | d  k	 rs | j t | t d ƒ ƒ n  | d  k	 r:| j t | t	 d ƒ ƒ q:nœ |  j
 ƒ  rÒ |  j ƒ  } | j t | t d ƒ ƒ nh |  j ƒ  r|  j ƒ  } | j t | t d ƒ ƒ n4 |  j ƒ  r:|  j ƒ  } | j t | t d ƒ ƒ n  | S(   Ns   2mFo-DFcs   mFo-DFcs   FP,PHIB,FOMs   FP,PHIM,FOMMR   (   R6   R7   Rl   R<   Rq   R   R)   R_   Ra   R`   R?   Rw   R;   Rv   RB   R{   R[   (   R1   t
   use_filledt   mapsRx   Ry   t   anom_map(    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyt   auto_open_maps€  s&    N(    ("   R
   R   t   __doc__R   R5   R6   R7   R;   R<   R=   R?   RB   RC   RD   RO   RA   Rl   Rv   Rw   Rq   R{   R@   Rr   Rƒ   R…   R‡   Rˆ   R�   R‘   R”   R–   Rž   R�   R·   (    (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyR      sL   ,									,M				
									
		!R_   c           B   sS   e  Z d d  „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   c         C   s   | |  _  | |  _ | |  _ d  S(   N(   R   RW   RX   (   R1   R   RW   RX   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyR5   –  s    		c         C   s   |  j  t @S(   N(   RW   Ra   (   R1   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyt   is_fobs_map›  s    c         C   s   |  j  t @S(   N(   RW   R`   (   R1   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyt   is_difference_mapž  s    c         C   s   |  j  t @S(   N(   RW   R[   (   R1   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyRB   ¡  s    c         C   s   |  j  t @S(   N(   RW   R\   (   R1   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyt   is_neutron_map¤  s    c         C   s   |  j  t @S(   N(   RW   Rb   (   R1   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyt   is_filled_map§  s    c         C   s/   |  j  j ƒ  } | j d | ƒ } | j ƒ  | S(   NRŸ   (   R   t   unique_under_symmetryRª   R«   (   R1   RŸ   R   R“   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyRª   ª  s    
c         C   s   t  |  j | ƒ S(   N(   t   getattrR   (   R1   t   name(    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyt   __getattr__°  s    N(   R
   R   R   R5   R¹   Rº   RB   R»   R¼   Rª   RÀ   (    (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyR_   •  s   						i
   c         C   s2  d d  l  } d d l m } d d l m } |  d  k	 rY | j d |  d | ƒ \ }	 }
 n d d }	 }
 t g  t |	 | ƒ D] \ } } t	 | | ƒ ^ qy ƒ } t g  t |
 | ƒ D] \ } } t
 | | ƒ ^ q± ƒ } | j d ƒ j ƒ  } | j j d	 | d
 | d | d | d | d | d | j d g ƒ ƒ d  S(   Niÿÿÿÿ(   t   sgtbx(   t   flexR    t   bufferg        g      ð?t   P1R   R¡   t   space_groupt   gridding_firstt   gridding_lastR¢   R4   s'   iotbx.map_conversion.write_ccp4_map_box(   g        g        g        (   g      ð?g      ð?g      ð?(   t   iotbx.ccp4_mapt   cctbxRÁ   t   scitbx.array_familyRÂ   R   t   box_frac_around_sitest   tuplet   zipR   R   t   space_group_infot   groupt   ccp4_mapR®   t
   std_string(   R    R¡   R¢   R£   R   RÃ   R   RÁ   RÂ   t   frac_mint   frac_maxR2   t   nRÆ   RÇ   RÅ   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyR®   ³  s&    	88c         C   s   d d  l  } d d l m } d d l m } |  d  k	 rY | j d |  d | ƒ \ }	 }
 n d d }	 }
 t g  t |	 | ƒ D] \ } } t	 | | ƒ ^ qy ƒ } t g  t |
 | ƒ D] \ } } t
 | | ƒ ^ q± ƒ } d G| GHd	 G| GHd
 G| GH| j j d | d | d | d | d | ƒ d  S(   Niÿÿÿÿ(   RÁ   (   RÂ   R    RÃ   g        g      ð?s   n_real:s   gridding start:s   gridding end:R   R¡   RÆ   RÇ   R¢   (   g        g        g        (   g      ð?g      ð?g      ð?(   t
   iotbx.dsn6RÉ   RÁ   RÊ   RÂ   R   RË   RÌ   RÍ   R   R   t   dsn6t   write_dsn6_map(   R    R¡   R¢   R£   R   RÃ   R   RÁ   RÂ   RÒ   RÓ   R2   RÔ   RÆ   RÇ   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyR×   Ê  s&    	88			c         K   s   t  d |  ƒ } | j | �  S(   NR   (   R   R‡   (   t   mtz_fileR‚   t   server_(    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyR‡   ã  s    c         K   s   t  d |  ƒ } | j | �  S(   NR   (   R   Rˆ   (   RØ   R‚   RÙ   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyRˆ   ç  s    c         K   s   t  d |  ƒ } | j | �  S(   NR   (   R   R�   (   RØ   R‚   RÙ   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyR�   ë  s    c         K   s   t  d |  ƒ } | j | �  S(   NR   (   R   Rƒ   (   RØ   R‚   RÙ   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyt   convert_any_map_coeffsï  s    c         K   s#   t  d |  d ƒ } | j |  | � S(   NR   s   .mtz(   R   R”   (   R’   R‚   RÙ   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyR”   ó  s    c         K   s‡   g  } t  d | ƒ } xk |  D]c } | j d | j } y | j | d d | � } Wn t k
 rh q n X| j | | j f ƒ q W| S(   sî   
  Convert the map coefficients in an MTZ file created by phenix.maps or
  phenix.refine (and related applications).  The parameter block expected in
  map_coefficients is actually in mmtbx/maps/__init__.py, but the I/O belongs
  here.
  R   RV   N(   R   t   mtz_label_amplitudest   mtz_label_phasesRƒ   R   R	   R)   RW   (   t   map_coefficientsRØ   R‚   t   outputsRÙ   R“   t   array_labelR•   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyt   convert_map_coefficients÷  s    	t   write_ccp4_maps_wrapperc           B   s    e  Z d  Z d „  Z d „  Z RS(   sŸ   
  Callable object for running map conversions in parallel (probably overkill,
  but anything we can do to take advantage of multiple CPUs is worth trying).
  c         C   s   t  |  t ƒ  ƒ d  S(   N(   R   t   locals(   R1   t   pdb_hierarchyR   t   output_filesRŸ   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyR5     s    c         C   s�   |  j  j ƒ  j ƒ  } x� t |  j |  j ƒ D]j \ } } | d  k rI q+ n  | j d |  j ƒ } t	 d | d | j
 ƒ  d | j ƒ  d | j ƒ  d | ƒ q+ Wd  S(   NRŸ   R    R¡   R¢   R£   R   (   Rã   R¥   R¦   RÍ   R   Rä   R   Rª   RŸ   R®   R¡   R­   R£   (   R1   R    R   R   Rª   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyt   run  s    "(   R
   R   R¸   R5   Rå   (    (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyRá     s   	c   	      C   sÎ   d d l  } | j j d d ƒ } |  j d d d | ƒ } | j d | d d	 d | ƒ | d k	 r€ | j d | d d
 d | ƒ n  | d k	 r« | j d | d d d | ƒ n  | j ƒ  } | j d | ƒ ~ d S(   sÐ   
  Convenience function for writing out 2mFo-DFc and mFo-DFc (and, optionally,
  anomalous difference) map coefficients with predefined labels, which will
  be recognized by the auto-open function in Coot.
  iÿÿÿÿNt   phases_prefixR   t   column_root_labelR   t   label_decoratort   miller_arrayR   R   s   F-modelR   (   t	   iotbx.mtzt   mtzRè   t   as_mtz_datasett   add_miller_arrayR   t
   mtz_objectt   write(	   t
   fwt_coeffst   delfwt_coeffsR   t   anom_coeffst   fmodel_coeffsR   t	   decoratort   mtz_datasetRî   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyt   write_map_coeffs!  s,    				
	
c         C   s%  d d  l  } d  } xù t | |  ƒ D]è \ } }  |  j ƒ  rI |  j ƒ  }  n  | j j d d ƒ } | d k rs d } nT | d k rˆ d } n? | d k r¬ d	 } | j j ƒ  } n | d k rÁ d } n | } | d  k rî |  j d | d | ƒ } q" | j	 d |  d | d | ƒ q" W| j
 ƒ  j | ƒ d  S(   NiÿÿÿÿRæ   R   s   2mFo-DFcR   s   mFo-DFcR   t   mFoRo   t   anomR   R   Rç   Rè   Ré   (   Rø   s	   anomalous(   Rê   R   RÍ   t   anomalous_flagt   average_bijvoet_matesRë   Rè   t   ccp4_label_decoratorRì   Rí   Rî   Rï   (   R   t	   map_typesR   R   Rõ   RW   t   dect   label(    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyt   write_map_coefficients_genericA  s2    					g      Ð?c   	      C   s^  g  } |  j  ƒ  } | j ƒ  } |  j ƒ  |  j ƒ  } | j d | t | ƒ f ƒ | j d d | j ƒ  f ƒ | j d d | j ƒ  f ƒ | j d d | j ƒ  f ƒ | j d d | j	 ƒ  f ƒ |  j
 ƒ  |  j ƒ  } | j d d | j ƒ  f ƒ | j d d | j ƒ  f ƒ d	 d
 l m } | j |  j t ƒ ƒ } | j d d | j ƒ  f ƒ | S(   Ns'   Grid points (with resolution_factor=%g)s   Min value (volume-scaled)s   %.2fs   Max value (volume-scaled)s   Mean value (volume-scaled)s   Sigma (volume-scaled)s   Min value (sigma-scaled)s   Max value (sigma-scaled)iÿÿÿÿ(   t   maptbxt   Skewness(   t   real_map_unpaddedt   sizeR¬   t
   statisticsR)   R   t   mint   maxt   meant   sigmaR«   RÉ   R   t   more_statisticsR­   RA   t   skewness(	   R“   RŸ   R'   R­   t   n_grid_pointst	   stats_volt   stats_sigmaR   t
   more_stats(    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyt   get_map_summary^  s&    

t   auto_convert_map_coefficientsc           B   s   e  Z d d  d „ Z RS(   g      Ð?c      	   C   sK  d  |  _ d  |  _ d  |  _ d  |  _ t d | ƒ } | j ƒ  r™ | j d d d | d t d | ƒ |  _ d |  _ | j d d d | d t d | ƒ |  _ n~ | j	 ƒ  r| j d d	 d | d t d | ƒ |  _ d
 |  _ | j
 ƒ  rd |  _ | j d d d | d t d | ƒ |  _ qn  | j ƒ  rG| j d | d t d | ƒ |  _ n  d  S(   NR   R„   s   2FOFCWT,PH2FOFCWTR¯   R²   RŸ   s   2mFo-DFcs   FOFCWT,PHFOFCWTs   FWT,PHWTt   fwts   DELFWT,PHDELWT(   R   Rx   Ry   R¶   t
   f_map_typeR   R6   R…   R@   R<   R=   RB   R‘   (   R1   RØ   R¯   RŸ   t
   map_server(    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyR5   t  sH    												N(   R
   R   R   R5   (    (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyR  s  s   c         C   så   |  j  ƒ  } |  j ƒ  r' |  j ƒ  }  n  |  j ƒ  j | ƒ }  |  j ƒ  rL |  S|  j ƒ  s^ t ‚ | r› | d  k	 r› |  j	 d | j ƒ  ƒ \ }  } |  | }  n  |  j	 d | j ƒ  ƒ \ }  } |  j
 | d t ƒj d d  ƒ j | ƒ Sd  S(   Nt   othert   degt   sigmas(   R'   Rù   Rú   t
   map_to_asuRt   R-   R.   R   R   t   common_setst   phase_transferR@   t   customized_copy(   R2   R|   R}   Rm   R'   (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyR€   š  s    (%   t
   __future__R    t   libtbx.math_utilsR   R   t   libtbxR   RŠ   Ra   R`   R[   t   MAP_TYPE_ISO_DIFFR\   t   MAP_TYPE_F_CALCRb   R¨   t   RuntimeErrorR	   t   objectR   R_   R®   R×   R‡   Rˆ   R�   RÚ   R”   Rà   Rá   R   Rö   Rÿ   R  R  R@   R€   (    (    (    s=   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/map_tools.pyt   <module>   sD   
ÿ }							'