ó
¢™xTc           @   sP   d  d l  m Z d  d l m Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   division(   t   Sorryt   fmodelsc        	   B   sø   e  Z d  Z d d d d d d d d „ Z d „  Z d „  Z d d „ Z d d „ Z d d d e	 d „ Z
 d d „ Z d d	 „ Z e d e	 e	 d
 d e	 d d „ Z d d „ Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d e	 d „ Z RS(   sØ   
  Container object for F_model values used during refinement.

  Attributes
  ----------
  fmodel_xray :
  fmodel_neutron :
  xray_scattering_dict :
  neutron_scattering_dict :
  neutron_refinement :
  twin_law :
  c         C   sÕ   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ |  j d  k	 rÇ | d  k rÇ |  j  j ƒ  } |  j j ƒ  }	 | |	 }
 |  j j ƒ  j	 d |  j j ƒ  j
 ƒ  |
 ƒ } | j ƒ  |  j j d | ƒ n  |  j ƒ  d  S(   Nt   datat   f_obs(   t   fmodel_xt   fmodel_nt   xray_scattering_dictt   neutron_scattering_dictt   neutron_refinementt   logt   Nonet   scale_k1R   t   arrayR   t#   set_observation_type_xray_amplitudet   updatet   create_target_functors(   t   selft   fmodel_xrayt   fmodel_neutronR   R   R	   t   twin_lawR
   t
   scale_k1_xt
   scale_k1_nt   xn_scalet   f_obs_n_new(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/__init__.pyt   __init__   s    						

c         C   s‰   d } |  j d k	 r' |  j j ƒ  } n  t d |  j j ƒ  d | d |  j d |  j d |  j d |  j ƒ } | j	 d |  j j
 j ƒ  ƒ | S(	   sO   
    Makes a deep copy of self.

    Returns
    -------
    mmtbx.fmodels
    R   R   R   R   R	   R
   t   xray_structureN(   R   R   t	   deep_copyR   R   R   R   R	   R
   t   update_xray_structureR   t   deep_copy_scatterers(   R   t   fmodel_n_dct   result(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/__init__.pyt   pseudo_deep_copy+   s    				c         C   sy   d } |  j d k	 r- |  j j d | ƒ } n  t d |  j j d | ƒ d | d |  j d |  j d |  j d |  j ƒ } | S(	   s[  
    Returns a copy of self with a resolution filter applied to the x-ray and
    neutron maps above a given resolution.

    Parameters
    ----------
    d_min : float
        Reflections with resolutions <= d_min are removed.

    Returns
    -------
    mmtbx.fmodels

    See Also
    --------
    mmtbx.f_model.manager.resolution_filter
    t   d_minR   R   R   R   R	   R
   N(	   R   R   t   resolution_filterR   R   R   R   R	   R
   (   R   R!   R   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/__init__.pyR"   @   s    			c         C   sy   |  j  d k	 rr |  j d k	 rr | d k	 r9 | |  j  _ n  d |  j  j _ |  j  j j d |  j ƒ j ƒ  |  _ qr n  |  j  S(   s   
    ...
    t   custom_dictN(   R   R   R   R   t   _scattering_type_registryt   scattering_type_registryR   t   as_type_gaussian_dict(   R   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/__init__.pyR   ^   s    c         C   s…   |  j  d k	 r~ | d k	 r* | |  j  _ n  d |  j  j _ |  j  j j d |  j d d ƒ j ƒ  |  _ |  j  j j ƒ  s~ t ‚ n  |  j  S(   s   
    ...
    R#   t   tablet   neutronN(	   R   R   R   R$   R%   R   R&   t   guess_scattering_type_neutront   AssertionError(   R   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/__init__.pyR   p   s    c      	   C   s„   |  j  d k	 r@ |  j d | ƒ j d | d | d | d | ƒ n  |  j d k	 r€ |  j d | ƒ j d | d | d | d | ƒ n  d S(   s   
    ...
    R   t   update_f_calct   update_f_maskt   force_update_f_maskN(   R   R   R   R   R   R   (   R   R   R+   R,   R-   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/__init__.pyR   €   s    
c         C   s©   | d k r |  j } n  |  j d k	 rj d } |  j d k	 rE d } n  |  j ƒ  j ƒ  j d | d | ƒ n  |  j d k	 r¥ |  j J|  j ƒ  j ƒ  j d d d | ƒ n  d S(   s   
    ...
    t    s
   x-ray datat   headert   outs   neutron dataN(   R   R
   R   R   R   t   infot$   show_rfactors_targets_scales_overallR   (   R   R
   t   prefix(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/__init__.pyt
   show_short”   s      	R.   c         C   s®   d d l  m } | j d d |  j ƒ|  j d k	 r] |  j ƒ  j ƒ  j d | d |  j ƒ n  |  j	 d k	 rª | j d d |  j ƒ|  j
 ƒ  j ƒ  j d | d |  j ƒ n  d S(   s   
    ...
    iÿÿÿÿ(   t   print_statisticss
   X-ray dataR0   R/   s   Neutron dataN(   t   mmtbx.refinementR5   t   make_sub_headerR
   R   R   R   R1   t   show_allR   R   (   R   t   messageR5   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/__init__.pyt   show_comprehensive£   s    (i   c
         C   sÉ  | d k r |  j } n  t }
 | j d k r6 t }
 n  d d l m } | j d d | ƒ|  j d t d t d | ƒ |  j	 |  j
 g j d ƒ d	 k rŸ t } n  |  j	 d k	 r>d } |  j
 d k	 rÖ d
 } | | IJn  |  j ƒ  j d | d | d | d |
 d | d t d | d | d | d |	 ƒ 
|  j	 j d | d | ƒ n  |  j
 d k	 rÅd } | | IJ|  j ƒ  j d | d | d | d |
 d | d t d | d | d | d |	 ƒ 
|  j
 j d | d | ƒ n  d S(   s   
    ...
    t   slowiÿÿÿÿ(   R5   s   updating all scalesR0   R+   R,   R-   i    s   X-ray:t   update_f_part1t   remove_outlierst   paramst   fastR
   t   showt   optimize_maskt   nproct   apply_back_tracet   refine_hd_scatteringt   suffixs   Neutron:N(   R   R
   t   Truet   modet   FalseR6   R5   t   make_headerR   R   R   t   countR   t   update_all_scalesR@   R   (   R   R<   R=   R>   RA   R-   RB   R
   RC   RD   R?   R5   t   msg(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/__init__.pyRK   ¯   sV      	! 	
c         C   s„   d } |  j  d k	 r d } n  |  j ƒ  j ƒ  j d | d | d | ƒ |  j  d k	 r€ |  j ƒ  j ƒ  j d | d d | ƒ n  d S(   s   
    ...
    R.   t   xrayR0   t   textt    s   neutron N(   R   R   R   R1   t   show_targetsR   (   R   R
   RN   t   prefix_x(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/__init__.pyRP   æ   s    	*c         C   sN   |  j  d k	 r% |  j  j d | ƒ n  |  j d k	 rJ |  j j d | ƒ n  d S(   s   
    ...
    t   target_nameN(   R   R   R   R   (   R   RR   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/__init__.pyR   ñ   s    c         C   sI   |  j  ƒ  j ƒ  |  _ d |  _ |  j d k	 rE |  j ƒ  j ƒ  |  _ n  d S(   s   
    ...
    N(   R   t   target_functort   target_functor_xrayR   t   target_functor_neutronR   R   (   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/__init__.pyR   ú   s    	c         C   s0   |  j  j ƒ  |  j d k	 r, |  j j ƒ  n  d S(   s   
    ...
    N(   RT   t   prepare_for_minimizationRU   R   (   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/__init__.pyt(   prepare_target_functors_for_minimization  s    c         C   sC   x< |  j  |  j g D]( } | d k r+ q n  | j ƒ  s t Sq Wt S(   s   
    ...
    N(   RT   RU   R   t8   target_function_is_invariant_under_allowed_origin_shiftsRH   RF   (   R   t   f(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/__init__.pyt:   target_functions_are_invariant_under_allowed_origin_shifts  s     c         C   s   |  j  ƒ  } |  j d | ƒ S(   s   
    ...
    t   compute_gradients(   R   RT   (   R   R[   t   fmx(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/__init__.pyt   target_functor_result_xray  s    c         C   s:   d } |  j d k	 r6 |  j ƒ  } |  j d | ƒ } n  | S(   s   
    ...
    R[   N(   R   R   R   RU   (   R   R[   R   t   fmn(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/__init__.pyt   target_functor_result_neutron  s
    c            sP   |  j  ‰ |  j ‰ d t f ‡  ‡ ‡ ‡ ‡ ‡ f d †  ƒ  Y} | d |  ƒ } | S(   s   
    ...
    t   tgc              sG   e  Z ‡  ‡ ‡ ‡ ‡ ‡ f d  †  Z ‡ f d †  Z ‡  ‡ f d †  Z RS(   c            sK  | |  _  ˆ d ˆ  ƒ } ˆ j ˆ j } | j ƒ  |  _ |  j | |  _ d  |  _ ˆ  r¢ ˆ rq | j d ˆ ƒ } n | j d ˆ ƒ j	 ƒ  } | |  _ | | |  _
 n  | j ƒ  d  k	 rGˆ j ˆ j } ˆ d ˆ  ƒ } | j ƒ  |  _ |  j | |  _ ˆ  rGˆ r| j d ˆ ƒ } n | j d ˆ ƒ j	 ƒ  } | |  _ | | |  _ qGn  d  S(   NR[   t	   occupancyt   u_iso_refinable_params(   R   t   wxt   wx_scalet   target_workt   target_work_xrayt   target_work_xray_weightedR   t   gradient_xrayt   gradients_wrt_atomic_parameterst   packedt   gradient_xray_weightedR   t   wnt   wn_scalet   target_work_neutront   target_work_neutron_weightedt   gradient_neutront   gradient_neutron_weighted(   R   R   t   tfx_rRc   t   sfRl   t   tfn_r(   R[   Ra   t   tfnt   tfxRb   t   weights(    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/__init__.pyR   0  s2    						c            sJ   |  j  j ƒ  d  k	 r= |  j ˆ  j |  j ˆ  j ˆ  j } n	 |  j } | S(   N(	   R   R   R   Rf   Rd   Rn   Rm   t   wxnRg   (   R   R   (   Rw   (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/__init__.pyt   targetL  s
    	c            sY   d  } ˆ  rU |  j j ƒ  d  k	 rI |  j ˆ j |  j ˆ j ˆ j } qU |  j } n  | S(   N(	   R   R   R   Rh   Rd   Rp   Rm   Rx   Rk   (   R   R   (   R[   Rw   (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/__init__.pyt	   gradientsR  s    (   t   __name__t
   __module__R   Ry   Rz   (    (   R[   Ra   Ru   Rv   Rb   Rw   (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/__init__.pyR`   /  s   R   (   R]   R_   t   object(   R   Rw   R[   Rb   Ra   R`   R   (    (   R[   Ra   Ru   Rv   Rb   Rw   s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/__init__.pyt   target_and_gradients(  s
    		++N(   R{   R|   t   __doc__R   R   R    R"   R   R   RH   R   R4   R:   RF   RK   RP   R   R   RW   RZ   R]   R_   R~   (    (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/__init__.pyR      sD   		-							t	   map_namesc           B   s§   e  Z d  Z d d d d d d g Z d d d	 d
 d d g Z d d d g Z d d d g Z d d d d d d g Z d d d d d d g Z d „  Z	 d  „  Z
 d! „  Z RS("   s  
  Class used for parsing and external display of map's name.

  Attributes
  ----------
  k : float
     Scale for F_obs.
  n : float
      Scale for F_model.
  ml_map : bool
  anomalous : bool
  anomalous_residual : bool
  phaser_sad_llg : bool
  kicked : bool
  f_obs_filled : bool
  t   fcalct   fcalt   fct   fmodelt   fmodt   fmt   dfcalct   dfcalt   dfct   dfmodelt   dfmodt   dfmt   fobst   fobt   fot   mfobst   mfobt   mfos   -kickeds   +kickedt   kickeds   -kicks   +kickt   kicks   +filleds   -filledt   filleds   +fills   -fillt   fillc   
      C   s  | j  ƒ  } d  |  _ d  |  _ d  |  _ t |  _ t |  _ t |  _ t |  _	 t |  _
 xn d d d d d d d d d	 d
 d d d d d d d d d d d d d d d d g D] } | j | d ƒ } q© Wx; |  j D]0 } | | k rÏ | j | d ƒ } t |  _	 qÏ qÏ Wx; |  j D]0 } | | k r| j | d ƒ } t |  _
 qqW| j d ƒ rw| j d ƒ rkt |  _ q×t |  _ n`| j d ƒ s•| j d ƒ r¡t |  _ n6| |  j k rÎd  |  _ d! |  _ t |  _ n	| |  j k rûd  |  _ d! |  _ t |  _ nÜ| |  j k r(d! |  _ d  |  _ t |  _ n¯| |  j k rUd! |  _ d  |  _ t |  _ n‚t } x8 |  j D]- } | | k ret } | j | d" ƒ } qeqeWt } x8 |  j D]- } | | k r¦t } | j | d# ƒ } q¦q¦W| | g j t ƒ d+ k r|  j | ƒ n  | | g j t ƒ d$ k r)t |  _ n4 | | g j t ƒ d  k rPt |  _ n |  j | ƒ |  j sÓx2 |  j D]' } | | k rp| j | d" ƒ } qpqpWx5 |  j D]' } | | k r¥| j | d# ƒ } q¥q¥Wn  | j d# ƒ | j d" ƒ d$ k r|  j | ƒ n  x9 | D]1 } | d, k r| j ƒ  r=|  j | ƒ q=qqW| j d# ƒ | j d" ƒ k  r| | j d# ƒ d! | j d" ƒ !} d  } | j d% ƒ d! k r¦d% } n+ | j d& ƒ d! k rÄd& } n |  j | ƒ | | j d# ƒ | j | ƒ d!  } | | j d# ƒ | j | ƒ d! }	 | j d# d ƒ } |	 j d" d ƒ }	 t | ƒ d  k r[d' |  _ nC t | ƒ d! k r�| d- k r�t d( | ƒ |  _ n t | ƒ |  _ t |	 ƒ d  k r¼d' |  _ q×t |	 ƒ d! k rð|	 d. k rðt d( |	 ƒ |  _ q×t |	 ƒ |  _ nÕ| j d# ƒ | j d" ƒ k rÃ| | j d" ƒ d! | j d# ƒ !} d  } | j d% ƒ d! k rgd% } n+ | j d& ƒ d! k r…d& } n |  j | ƒ | | j d" ƒ | j | ƒ d!  } | | j d" ƒ | j | ƒ d! }	 | j d" d ƒ } |	 j d# d ƒ }	 t | ƒ d  k rd' |  _ nC t | ƒ d! k rP| d/ k rPt d( | ƒ |  _ n t | ƒ |  _ t |	 ƒ d  k r}d' |  _ q×t |	 ƒ d! k r±|	 d0 k r±t d( |	 ƒ |  _ q×t |	 ƒ |  _ n t d) d* | ƒ ‚ |  j d  k	 rt |  j ƒ |  _ t |  j ƒ |  _ n  d  S(1   Nt   ~t   !t   @t   #t   $t   %t   ^t   &t   *t   (t   )t   =t   <t   >t   ?t   /t   :t   ;t   |t   [t   ]t   {t   }t   ,t   _RO   R.   t   anot   residt   sadt   llgi    i   t   Ct   Oi   t   +t   -g      ð?s   %s1s+   Error attempting to decode map name string s   '%s'(   i    i   (   R´   Rµ   (   R¶   R·   (   R¶   R·   (   R¶   R·   (   R¶   R·   (   t   lowerR   t   kt   nt   ml_mapRH   t	   anomaloust   anomalous_residualt   phaser_sad_llgR“   t   f_obs_filledt   replacet   KICKRF   t   FILLEDRJ   t   FCt   DFCt   FOt   MFOt   errort   isalphat   indext   lent   floatt   RuntimeError(
   R   t   map_name_stringt   st   symt   tmpt   found_Dt   found_Mt   signt   pot   pc(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/__init__.pyR   v  sò    								3(								  	  " # 	 	$$    # 	 	$$    c         C   s&   d } d } t  | | | f ƒ ‚ d S(   s0   
    Raises an exception for bad map names.
    sâ  

Wrong map type requested: %s
  Allowed format is: %s
    where [p] and [q] are any numbers (optional),
          [m] and [D] indicate if the requested map is sigmaa (optional),
          Fo and Fc are Fobs and Fcalc,
          [kick] is for Average Kick Map (optional),
          [filled] is for missing Fobs filled map.
  Examples: 2mFo-DFc, 3.2Fo-2.3Fc, mFobs-DFcalc_kick, 2mFobs-DFcalc_filled, Fc,
            2mFobs-DFcalc_kick_fill, anom, anom_diff, anomalous_difference, Fo
s   [p][m]Fo+[q][D]Fc[kick][filled]N(   R   (   R   RÎ   RL   t   format(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/__init__.pyRÇ   æ  s    c         C   s  |  j  r¬|  j r¬t t |  j ƒ |  j ƒ d k  rN t t |  j ƒ ƒ } n t |  j ƒ } t t |  j ƒ |  j ƒ d k  rÑ d } |  j d k r� d } n  |  j d k rµ d } n  | t t |  j ƒ ƒ } n t |  j ƒ } | d k sø | d k rd } n  | d k s| d k r"d } n  | d k r7d } n  | d k rLd } n  |  j rj| d	 | d
 } n | d | d } |  j r’| d 7} n  |  j	 r¨| d 7} n  | S|  j |  j |  j g j
 d ƒ d k sÙt ‚ |  j |  j	 g j
 t ƒ d k s t ‚ |  j rd Sd Sd S(   s°   
    Formats a map name for external display.

    Examples
    --------
    >>> r = mmtbx.map_names(map_name_string="mFo-DFc ")
    >>> print r.format()
    mFobs-DFmodel
    g�íµ ÷Æ°>R.   i    R¶   R·   t   1s   +1s   -1t   mFobst   DFmodelt   Fobst   Fmodelt   _kickt   _filledi   i   R¾   t   anomalous_differenceN(   R¼   R¾   t   abst   intR¹   t   strRº   R»   R“   R¿   RJ   R   R*   RH   (   R   R¹   RÓ   Rº   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/__init__.pyRÖ   ø  sB    
" " 	 	 	 	 	 			 	 -'	(   R{   R|   R   RÃ   RÄ   RÅ   RÆ   RÁ   RÂ   R   RÇ   RÖ   (    (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/__init__.pyR€   ]  s   	p	N(   t
   __future__R    t   libtbx.utilsR   R}   R   R€   (    (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/__init__.pyt   <module>   s   ÿ Y