ó
Ó™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  d l m Z d  d l Z d  d l Z d  d l Z d  d l Z e j Z d	 „  Z d
 e f d „  ƒ  YZ d d& d' d f f d d( f d d) f d d+ f d e e f f g Z e d d, f d d- f g Z d  „  Z d! „  Z d" „  Z d# „  Z  e! d$ k rye  d% e j" d ƒ n  d S(.   iÿÿÿÿ(   t   division(   t   tst_tardy_pdbN(   t   flex(   t   show_times_at_exit(   t   chunk_manager(   t   Auto(   t   StringIOc         C   sV   d GHd G|  GHt  j j ƒ  t  j j ƒ  t j ƒ  d GHt  j j ƒ  t  j j ƒ  Hd  S(   Ns   >Begin exceptions
   Exception:s   >End exception(   t   syst   stdoutt   flusht   stderrt	   tracebackt	   print_exc(   t   context_info(    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/tst_tardy_comprehensive.pyt   report_exception   s    	
t	   collectorc           B   s    e  Z d  „  Z d d d „ Z RS(   c         C   s%   d  |  _ d  |  _ t j ƒ  |  _ d  S(   N(   t   Nonet   tardy_modelt   rmsd_calculatorR   t   doublet   rmsd(   t   O(    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/tst_tardy_comprehensive.pyt   __init__   s    		c         C   s�   | d  k	 rH | d  k	 s t ‚ |  j d  k s3 t ‚ | |  _ | |  _ n |  j d  k	 s] t ‚ |  j j |  j |  j j j |  j j ƒ  ƒ ƒ d  S(   N(	   R   t   AssertionErrorR   R   R   t   appendt   potential_objt   ideal_sites_cartt   sites_moved(   R   R   R   (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/tst_tardy_comprehensive.pyt   __call__    s    	N(   t   __name__t
   __module__R   R   R   (    (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/tst_tardy_comprehensive.pyR      s   	s7   tardy_displacements_auto.rmsd_vs_high_resolution_factori   i   i   t!   structure_factors_high_resolutiong      ô?g      @g      @i   t   real_space_target_weighti
   id   iô  t,   real_space_gradients_delta_resolution_factort   emulate_cartesiant   start_temperature_kelviniÄ	  iˆ  t   number_of_cooling_stepsiú   c         C   s1   d } x$ |  D] \ } } | t  | ƒ 9} q W| S(   Ni   (   t   len(   t   tablet   resultt   namet   values(    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/tst_tardy_comprehensive.pyt   number_of_trials8   s    c         C   sØ   | } x¹ t  t t | ƒ ƒ ƒ D]Ÿ } | | \ } } t | ƒ } | | } | | } | j d ƒ }	 t |	 ƒ d k s| t ‚ |  }
 x! |	 d  D] } t |
 | ƒ }
 q� Wt |
 |	 d | | ƒ q W| d k sÔ t ‚ d  S(   Nt   .i    iÿÿÿÿ(   t   reversedt   rangeR%   t   splitR   t   getattrt   setattr(   t   paramst   trial_tablet
   cp_i_trialt   restt   iR(   R)   t   nt   jt	   phil_patht   scopet
   scope_name(    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/tst_tardy_comprehensive.pyt   set_parameters>   s    

c           C   s   t  j j d d t j j ƒ S(   Nt   input_stringsÐ  pdb_file = None
  .type = path
algorithm = *minimization annealing
  .type = choice
  .optional = False
orca_experiments = False
  .type = bool
random_displacements_parameterization = *constrained cartesian
  .type = choice
  .optional = False
%(dihedral_function_type_params_str)s
number_of_random_trials = 2
  .type = int
hot = False
  .type = bool
verbose = False
  .type = bool
keep_going = False
  .type = bool
chunk = 1 0
  .type = ints(size=2, value_min=0)
(   t   iotbxt   philt   parseR   t   pdb_interpretationt   __dict__(    (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/tst_tardy_comprehensive.pyt   get_master_philM   s    c         C   sH  t  ƒ  } | j ƒ  } g  } x' |  D] } | j | j d | ƒ ƒ q" W| j d | ƒ j ƒ  } t d | j d d | j d ƒ j ƒ  } | j	 | ƒ j
 ƒ  H| j d  k	 s¯ t ‚ t j | j ƒ sÇ t ‚ t j  ƒ  } | j ƒ  } t | _ | j | j _ | j d k rt }	 n | j d k r't }	 n t ‚ t d	 |	 ƒ }
 d
 G|
 GHd GHt j |	 ƒ Ht ƒ  t } t } xÖt |
 ƒ D]È} | j d | ƒ r–qxn  d | |
 d | d |
 f GH| j rÁHn  t  j! j" ƒ  t# d | d |	 d | ƒ | j d k r>| j$ r)t% | _& | j' rt | _$ q)t% | _$ n  d | _( d  | _) n3 | j d k rkd | _* d | _+ d | _) n t ‚ x¿t | j, ƒ D]®} | | _- | j. | _. | j s¬| rÖt% } | j	 | ƒ j
 ƒ  Ht  j! j" ƒ  n  | j/ r)| j rôt  j! } n	 t0 ƒ  } t1 ƒ  } y2 t j2 d | d | j g d g  d | d | ƒ Wn” t3 k
 rN‚  q)t4 k
 rÎHd GHH| j	 | ƒ j
 ƒ  H| j s˜t  j! j5 | j6 ƒ  ƒ n  t  j! j" ƒ  | j7 s´‚  n  t8 d d | | f ƒ q)X| j rÿ| rÿt% } t  j! j5 | j6 ƒ  ƒ n  d G| G| Gt9 | j: ƒ GHt  j! j" ƒ  n  t } q�W| j/ rxHqxqxWd  S(   Nt   argt   sourcesR6   i    R5   i   t   minimizationt	   annealingR&   s   Number of parameter trials:s   parameter_trial_table:s   cp_i_trial: %d / %d = %.2f %%id   R1   R2   R3   gü©ñÒMbP?t	   pdb_filest   other_filest   callbackt   logs*   tst_tardy_pdb_params leading to exception:R   s   cp_i_trial=%d, random_seed=%ds#   RESULT_cp_i_trial_random_seed_rmsd:(;   RB   t!   command_line_argument_interpreterR   t   processt   fetcht   extractR   t   chunkt   easy_allt   formatt   showt   pdb_fileR   R   t   opt   isfileR   R   t   tardy_displacementst%   random_displacements_parameterizationt   tardy_displacements_autot   parameterizationt	   algorithmt   common_parameter_trial_tablet   annealing_parameter_trial_tableR*   t   pprintR   t   Falset   xranget   skip_iterationt   verboseR   R   R	   R;   t   orca_experimentst   Truet   keep_all_restraintsR"   R$   t   minimization_max_iterationst   number_of_time_stepst   time_step_pico_secondst   number_of_random_trialst   random_seedt   dihedral_function_typet   hotR   R   t   run_testt   KeyboardInterruptt	   Exceptiont   writet   getvaluet
   keep_goingR   t   listR   (   t   argst   local_master_philt   argument_interpretert   phil_objectsRC   t   local_paramsRO   t   tst_tardy_pdb_master_philt   tst_tardy_pdb_paramst   parameter_trial_tablet   cp_n_trialst   params_shown_once_alreadyt$   tst_tardy_pdb_log_shown_once_alreadyR3   Ri   t   tst_tardy_pdb_logt   collt
   first_pass(    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/tst_tardy_comprehensive.pyt   rung   sÊ    					 													 		

	t   __main__Rs   gUUUUUUÕ?gUUUUUUå?(   g      ô?g      @g      @i   (   i
   id   iô  gUUUUUUÕ?(   gUUUUUUÕ?(   iÄ	  iˆ  (   iú   iô  (#   t
   __future__R    t   mmtbx.refinementR   t
   iotbx.philR=   t   scitbx.array_familyR   t   libtbx.utilsR   t   libtbx.queuing_system_utilsR   t   libtbxR   t	   cStringIOR   R]   R   R   t   ost   pathRT   R   t   objectR   R^   Rc   R[   R\   R*   R;   RB   R�   R   t   argv(    (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/tst_tardy_comprehensive.pyt   <module>   s6   										p