ó
@™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 „  Z d	 e f d
 „  ƒ  YZ d e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   division(   t   flexN(   t   miller(   t   maptbx(   t   adopt_init_args(   t   real_space_refinement_simplec         C   su   |  } |  j  ƒ  } t |  j ƒ  ƒ } xJ | D]B \ } } | j  ƒ  | j ƒ  | d } d | | | f GH| } q+ Wd  S(   Ni   s   %8.3f - %8.3f: %5d(   t   data_mint	   enumeratet   slotst
   slot_width(   t	   histogramt   h_1t   lc_1t   s_1t   i_1t   n_1t   hc_1(    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/maptbx/real_space_target_and_gradients.pyt   show
   s    t   target_and_gradientsc           B   s>   e  Z d d d d d d  d „ Z d „  Z d „  Z d „  Z RS(   t   diff_mapc         C   s
  t  |  t ƒ  ƒ |
 d k s" t ‚ | d  k	 rp | | |	 g j d  ƒ d k sR t ‚ | j d |	 d t ƒ |  _ n  |
 d k r¾ | d  k	 sŽ t ‚ t j	 d | d | d | d	 | d
 | ƒ |  _
 n  |
 d k r|	 d  k	 sÜ t ‚ t j	 d | d | d |	 d | ƒ |  _
 n  d  S(   Nt   simpleR   i    t
   sites_cartt   compute_gradientst	   unit_cellt
   map_targett   map_currentt   stept
   sites_fract   density_mapt   real_space_gradients_delta(   R   R   (   R   t   localst   AssertionErrort   Nonet   countt   energies_sitest   Truet   geom_tg_objR   R   t
   rsr_tg_objR   (   t   selfR   R   R   R   R   t   geometry_restraints_managert   real_space_target_weightt   restraints_target_weightR   t   target_type(    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/maptbx/real_space_target_and_gradients.pyt   __init__   s,    			c         C   sC   |  j  j ƒ  } |  j r9 |  j | |  j |  j j } n | } | S(   N(   R%   t   targetR'   R(   R)   R$   (   R&   t   rs_ft   result(    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/maptbx/real_space_target_and_gradients.pyR,   7   s    	
c         C   sI   |  j  j ƒ  } |  j r9 |  j | |  j |  j j } n | } | j ƒ  S(   N(   R%   t	   gradientsR'   R(   R)   R$   t	   as_double(   R&   t   rs_gt   g(    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/maptbx/real_space_target_and_gradients.pyR/   @   s    	
c         C   sr   |  j  j ƒ  } |  j j } t j | j ƒ  ƒ } | d t j | ƒ k  } | j | ƒ } | j ƒ  | j ƒ  } | S(   Ni   (	   R%   R/   R$   R   t   sqrtt   dott   meant   selectt   norm(   R&   t   gxt   gct   tmpt   selR.   (    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/maptbx/real_space_target_and_gradients.pyt   weightI   s    	N(   t   __name__t
   __module__R    R+   R,   R/   R<   (    (    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/maptbx/real_space_target_and_gradients.pyR      s   				t   minimizationc           B   s5   e  Z d  d d d d d d „ Z d „  Z d „  Z RS(   i   i   i   R   c         C   s  | |  _  | |  _ |	 |  _ | j ƒ  |  _ |  j j ƒ  |  _ | |  _ | |  _ | |  _ | |  _	 |
 |  _
 | |  _ t j j d |  d t j j d | d | ƒ d t j j d t d t d t ƒ ƒ |  _ |  j j ƒ  |  j j t j |  j ƒ ƒ |  j j |  j ƒ |  _ d  S(	   Nt   target_evaluatort   termination_paramst   max_iterationst   min_iterationst   exception_handling_paramst)   ignore_line_search_failed_rounding_errorst-   ignore_line_search_failed_step_at_lower_boundt    ignore_line_search_failed_maxfev(   R   R'   R(   R   R0   t   xt   xray_structureR   t   miller_arrayt   crystal_griddingR)   R*   t   scitbxt   lbfgst   runt   termination_parameterst   exception_handling_parametersR#   t	   minimizert   cleart   extendR   t   vec3_doublet   replace_sites_cart(   R&   RI   RJ   RK   R   R   RB   RC   R'   R(   R)   R*   (    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/maptbx/real_space_target_and_gradients.pyR+   `   s0    											c         C   sÜ   t  j |  j ƒ |  _ |  j j |  j ƒ |  _ d  |  _ |  j d k rW |  j	 ƒ  |  _ n  t
 d |  j j ƒ  d |  j d |  j d |  j d |  j j ƒ  d |  j d |  j d	 |  j d
 |  j d |  j ƒ 
} | j ƒ  | j ƒ  f S(   NR   R   R   R   R   R   R'   R(   R)   R   R*   (   R   RT   RH   R   RI   RU   R    R   R*   t   compute_mapR   R   R   R   R   R'   R(   R)   R,   R/   (   R&   t   tg_obj(    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/maptbx/real_space_target_and_gradients.pyt    compute_functional_and_gradients…   s"    								c         C   sS   |  j  j d |  j ƒ j ƒ  } t j d |  j d | ƒ } | j ƒ  | j ƒ  } | S(   NRI   RK   t   fourier_coefficients(	   RJ   t!   structure_factors_from_scatterersRI   t   f_calcR   t   fft_mapRK   t   apply_sigma_scalingt   real_map_unpadded(   R&   t   map_coefficientsR\   R.   (    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/maptbx/real_space_target_and_gradients.pyRV   ˜   s    	
N(   R=   R>   R    R+   RX   RV   (    (    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/maptbx/real_space_target_and_gradients.pyR?   _   s   	(   t
   __future__R    t   cctbx.array_familyR   t   scitbx.lbfgsRL   t   cctbxR   R   t   libtbxR   t   cctbx.maptbxR   R   t   objectR   R?   (    (    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/maptbx/real_space_target_and_gradients.pyt   <module>   s   		L