ó
Ã™xTc           @   sÉ   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
 m Z d  d l Z d  d l Z d  d l m Z d Z d	 e Z d
 „  Z d d d d „ Z d e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   division(   t   xray(   t   print_statistics(   t   cartesian_dynamicsN(   t   flex(   t   adopt_init_argss<  start_temperature = 5000
  .type = float
final_temperature = 300
  .type = float
cool_rate = 100
  .type = float
number_of_steps = 50
  .type = int
time_step = 0.0005
  .type = float
  .expert_level=2
initial_velocities_zero_fraction = 0
  .type = float
  .expert_level=2
interleave_minimization = False
  .type = bool
verbose = -1
  .type = int
  .short_caption = Verbosity level
n_print = 100
  .type = int
  .short_caption = Steps between log output
  .expert_level=2
update_grads_shift = 0.3
  .type = float
  .short_caption = Update gradient shifts
  .expert_level=2
s„  %s
refine_sites = True
  .caption = "lbfgs refinement of atomic coordinates before sa"
  .short_caption=Refine sites first
  .type = bool
refine_adp = False
  .caption = "lbfgs refinement of adp before sa"
  .short_caption=Refine ADPs first
  .type = bool
max_number_of_iterations = 25
  .type = int
mode = every_macro_cycle *second_and_before_last once first first_half
  .type = choice
c           C   s   t  j j t d t ƒS(   Nt   process_includes(   t   iotbxt   philt   parset   master_params_strt   False(    (    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/dynamics/simulated_annealing.pyt   master_params9   s    c
         C   s¬  | d  k r t j } n  | d  k	 r< t | d ƒ s< t ‚ n  t j d d | ƒ| j ƒ  | j ƒ  }
 | j	 |
 _	 |  j
 d k r t j d d | ƒt } | j j d k r´ t } n  d d  l } t j j j d | j d	 t d
 | d | d | d | j j d |  j
 ƒ d | d | d d ƒ 	} n  |
 j d | j	 d t d t ƒ t j d d | ƒ| j j | j j } t d |  d | j d |
 d | d | j j d | d |	 d | ƒ d  S(   Nt   adds   simulated annealing refinementt   outi    s.   lbfgs minimization: before simulated annealingt   neutroniÿÿÿÿt   restraints_managert
   refine_xyzt   fmodelst   is_neutron_scat_tablet   modelt   lbfgs_termination_paramst   max_iterationst   target_weightst   h_paramst   verboset   xray_structuret   update_f_calct   update_f_masks   simulated annealingt   paramst   fmodelt   wxt   wct   states_collectort   callbackt   log(   t   Nonet   syst   stdoutt   hasattrt   AssertionErrorR   t   make_headert   set_refine_individual_sitest   fmodel_xrayR   t   max_number_of_iterationst   make_sub_headerR   t   maint   scattering_tablet   Truet   scitbx.lbfgst   mmtbxt
   refinementt   minimizationt   lbfgsR   t   termination_parameterst   update_xray_structuret   xyz_weights_resultR   t   wx_scalet   runt   w(   R   R   t
   all_paramst   macro_cycleR   R   R   R   R!   R"   R   R   t   scitbxt	   minimizedR   (    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/dynamics/simulated_annealing.pyt   manager<   sR    
 
				R:   c           B   sA   e  Z d d d d d e d d d e d  „
 Z d „  Z d „  Z RS(   c         C   s×  t  |  t ƒ  ƒ | d  k s1 t | d ƒ s1 t ‚ |  j d  k rU t ƒ  j ƒ  |  _ n  |	 d  k rp t j	 |  _
 n  |  j d  k	 r‘ |  j j |  _ n  |  j j ƒ  |  _ | j |  _ | j } t } d  } t | j j d d  ƒ } t } | d  k	 r$d | j j k r$t | j j j _ t } t } q$n  x‹| j |  j k r±t } t j d |  j d |  j ƒ  d |  j d |  j j d | d	 |  j j d
 |  j j  d |  j j! d | d | d |  j
 d | ƒ } t } | j" } | j |  _ |  j d  k	 r	|  j j# d |  j d t d t ƒ n  |
 d  k	 r4|  j$ j% d | j j ƒ  ƒ n  | d  k	 rS| d |  j ƒ n  |  j& d |  j ƒ |  j | j' 8_ | r'|  j
 d |  j IJ| j( d | j j ƒ  ƒ q'q'W| d  k	 rÓt | j j j _ n  d  S(   Nt   __call__t   den_managert	   cartesianR   t   gradients_calculatort   temperaturet   interleaved_minimizationt   vxyzt   n_stepst	   time_stept   n_printt   stop_cm_motiont   reset_velocitiesR#   R   R   R   t
   sites_cartR   t	   curr_temps$   update DEN eq distances at temp=%.1f()   R   t   localsR$   R'   R(   R   R   t   extractR%   R&   R#   R   R   RM   t   sites_cart_startt   start_temperatureRN   R   R0   t   getattrt   geometryt   generic_restraints_managerR   t   annealing_typet   flagst   dent   final_temperatureR   R:   RD   t   interleave_minimizationt   number_of_stepsRI   RJ   RG   R7   R!   R   t   showt	   cool_ratet   update_eq_distances(   t   selfR   R   R   R   R    R   t
   target_mapt
   real_spaceR#   R!   R"   R   RL   RG   RB   t   cartesian_den_restraintst   cmremovet
   cd_manager(    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/dynamics/simulated_annealing.pyt   __init__p   sp    !  								
	c      	   C   sí   |  j  ré |  j j ƒ  } |  j j j d | ƒ } | j ƒ  d | j ƒ  d } } t j	 t j
 |  j | j ƒ  ƒ ƒ } |  j d  k	 rÃ d } |  j | | |  j j ƒ  |  j j ƒ  | | | f IJqé d } |  j | | | | | f IJn  d  S(   NRM   i   sP     temp=%7.1f r_work=%6.4f r_free=%6.4f dist_moved=%6.2f angles=%6.2f bonds=%6.3fs6     temp=%7.1f dist_moved=%6.2f angles=%6.2f bonds=%6.3f(   R   R   RM   R   RT   t   energies_sitest   bond_deviationst   angle_deviationsR   t   meant   sqrtRQ   t   dotR   R$   R#   t   r_workt   r_free(   R_   RN   RM   t   est   at   bt   distt   fmt(    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/dynamics/simulated_annealing.pyR\   ·   s    	!%c         C   sÜ   |  j  s� |  j d  k	 ri t j d |  j d |  j d |  j j j ƒ  d |  j d |  j	 d |  j
 j ƒ } qØ t j d |  j ƒ } nW t j d |  j j d |  j d |  j j ƒ  d |  j j ƒ  d |  j d |  j	 d d	 ƒ } | S(
   NR   R   RM   R   R    t   update_gradient_thresholdR`   t	   unit_celli    (   Ra   R   R$   R   t%   gradients_calculator_reciprocal_spaceR   R   RM   R   R    R   t   update_grads_shiftt(   gradients_calculator_geometry_restraintst&   gradients_calculator_real_space_simpleRT   R`   Rt   (   R_   t	   grad_calc(    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/dynamics/simulated_annealing.pyRD   Å   s(    												N(   t   __name__t
   __module__R$   R   R0   Re   R\   RD   (    (    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/dynamics/simulated_annealing.pyR:   o   s   ;	(   t
   __future__R    t   cctbxR   t   mmtbx.refinementR   t   mmtbx.dynamicsR   t   mmtbx.refinement.minimizationR2   t   scitbx.array_familyR   t
   iotbx.philR   R%   t   libtbxR   t   main_params_strR
   R   R$   R@   t   objectR:   (    (    (    sP   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/dynamics/simulated_annealing.pyt   <module>   s   
	
*