ó
Í™xTc           @   s„  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	 m
 Z
 d  d l	 m Z d  d l m Z d  d l Z d  d l Z d  d	 l m Z d  d
 l m Z d  d l m Z d  d l Z	 d a d e f d „  ƒ  YZ d Z e j j d e ƒ Z d d „ Z d e f d „  ƒ  YZ  d e f d „  ƒ  YZ! d „  Z" d „  Z# d e f d „  ƒ  YZ$ d d d e% d d „ Z& d S(   iÿÿÿÿ(   t   division(   t   flex(   t   adopt_init_argsN(   t   approx_equal(   t   matrix(   t   lbfgs(   t   print_statistics(   t   null_out(   t   user_plus_sys_time(   t   iroundg        t   rigid_body_shift_accumulatorc           B   s&   e  Z d  „  Z d „  Z d d „ Z RS(   c         C   s   | |  _  g  |  _ g  |  _ d  S(   N(   t   euler_angle_conventiont	   rotationst   translations(   t   selfR   (    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/rigid_body.pyt   __init__   s    		c   	      C   sæ   t  | ƒ t  | ƒ k s t ‚ g  } g  } t  |  j ƒ d k r– xŽ t | | |  j |  j ƒ D]4 \ } } } } | j | | ƒ | j | | ƒ q[ Wn: x7 t | | ƒ D]& \ } } | j | ƒ | j | ƒ q¦ W| |  _ | |  _ d  S(   Ni    (   t   lent   AssertionErrorR   t   zipR   t   append(	   R   R   R   t   new_rotationst   new_translationst   rnt   tnt   rt   t(    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/rigid_body.pyt   add   s    	c         C   sw   | d  k r t j } n  | d IJt j d | d d d d d |  j d |  j d	 |  j ƒ | d d
 d d IJ| Jd  S(   NsO   |-rigid body shift (total)----------------------------------------------------|t   outt   prefixt    t   framet   |R   R   R   t   -iM   (   t   Nonet   syst   stdoutR   t*   show_rigid_body_rotations_and_translationsR   R   R   (   R   R   (    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/rigid_body.pyt   show)   s     
			
N(   t   __name__t
   __module__R   R   R!   R%   (    (    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/rigid_body.pyR
      s   		s	    min_number_of_reflections = 200
    .type = int
    .help = Number of reflections that defines the first lowest resolution             zone for the multiple_zones protocol. If very large             displacements are expected, decreasing this parameter to 100             may lead to a larger convergence radius.
  multi_body_factor = 1
    .type = float
  zone_exponent = 3.0
    .type = float
  high_resolution = 3.0
    .type = float
    .help = High resolution cutoff (used for rigid body refinement only)
  max_low_high_res_limit = None
    .type = float
    .expert_level=2
    .help = Maximum value for high resolution cutoff for the first lowest             resolution zone
  number_of_zones = 5
    .type = int
    .help = Number of resolution zones for MZ protocol
sŒ      mode = *first_macro_cycle_only every_macro_cycle
      .type = choice
      .help = Defines how many times the rigid body refinement is performed               during refinement run. first_macro_cycle_only to run only once               at first macrocycle, every_macro_cycle to do rigid body               refinement main.number_of_macro_cycles times
    target = ls_wunit_k1 ml *auto
      .type = choice
      .help = Rigid body refinement target function: least-squares or               maximum-likelihood
    target_auto_switch_resolution = 6.0
      .type = float
      .help = Used if target=auto, use optimal target for given working               resolution.
    disable_final_r_factor_check = False
      .type = bool
      .expert_level = 2
      .help = If True, the R-factor check after refinement will not revert to         the previous model, even if the R-factors have increased.
      .short_caption = Disable R-factor check
    refine_rotation = True
      .type = bool
      .help = Only rotation is refined (translation is fixed).
    refine_translation = True
      .type = bool
      .help = Only translation is refined (rotation is fixed).
    max_iterations = 25
      .type = int
      .help = Number of LBFGS minimization iterations
    bulk_solvent_and_scale = True
      .type = bool
      .help = Bulk-solvent and scaling within rigid body refinement (needed               since large rigid body shifts invalidate the mask).
    euler_angle_convention = *xyz zyz
      .type = choice
      .expert_level=2
      .help = Euler angles convention
    lbfgs_line_search_max_function_evaluations = 10
      .type = int
      .expert_level=2
    %s
c      
   C   s‹  | d k s t  ‚ | d k s$ t  ‚ | d  k sB | d k sB t  ‚ | d  k s` | d k s` t  ‚ | d  k s~ | d k s~ t  ‚ | d  k sœ | d k sœ t  ‚ | d  k	 sº | d  k	 sº t  ‚ | d  k	 rç | d  k	 rç | | k sç t  ‚ n  | d  k s| d k st  ‚ |	 d k st  ‚ |
 d  k r/t j }
 n  |  j ƒ  } |  j t j |  d t ƒƒ }  |  d |  d } } | d  k	 rž| | k  rž|  j |  | k ƒ }  n  |  d } | } | d  k rÒ|  | k j	 t ƒ } n� | d  k	 rý| t
 | | d | ƒ 7} n  | d k st  ‚ | d  k	 rY| |  j ƒ  k rY|  | d | k rY|  | k j	 t ƒ } n | } g  } | d  k	 rK| d k rK| |  j ƒ  k } | r¥| j | ƒ qs|  j ƒ  | | d |	 } | j |  | d ƒ xš t d | ƒ D]^ } t
 | | | |	 ƒ } | | d k r/| |  j ƒ  k s/t  ‚ n  | j |  | d ƒ qæWn( t | |  j ƒ  ƒ } t } | j | ƒ |
 d IJ|
 d | IJt | ƒ d k s£| r-|
 d IJ|
 d I| IJ|
 d	 I| IJ|
 d
 I| IJ|
 d I| IJ|
 d I| I| | k r|
 d In  |
 J|
 d I| IJn  |
 d | | | f IJ|
 d | | |  j ƒ  f IJ| r„|
 d | |  j ƒ  f IJn  g  } xS | D]K } | d k rÏ| | k r¿| j d ƒ qÜ| j d ƒ q‘| j | ƒ q‘Wt | ƒ d k r�|
 d IJ|
 d IJ|
 d IJxT t | ƒ D]F \ } } |  | k j	 t ƒ } |
 d | d | | | | | f IJqW|
 d | | |	 f IJn  | | f S(   Ni    t   reverseiÿÿÿÿi   s   Rigid body refinement:s*     Requested number of resolution zones: %ds(     Calculation for first resolution zone:s-       Requested number of reflections per body:s       Requested factor per body:s       Number of bodies:s$       Resulting number of reflections:s#       Requested low-resolution limit:s   (determines final number)s        Final number of reflections:sF     Data resolution:                      %6.2f - %6.2f (%d reflections)sF     Resolution for rigid body refinement: %6.2f - %6.2f (%d reflections)s¹     WARNING: Final number of reflections for first resolution zone is greater
           than the number of available reflections (%d > %d).
  INFO: Number of resolution zones reset to 1.t   autot   ls_wunit_k1t   mls)     Resolution cutoffs for multiple zones: s#                             number ofs,       zone     resolution  reflections  targets        %3d  %6.2f -%6.2f %11d    %ss;       zone number of reflections = %d + %.6g * (zone-1)**%.6g(   R   R!   R"   R#   t   sizet   selectR   t   sort_permutationt   Truet   countR	   R   t   ranget   mint   FalseR   t	   enumerate(   t
   d_spacingst   n_bodiest   targett   target_auto_switch_resolutiont   n_ref_firstt   multi_body_factor_n_ref_firstt   d_lowt   d_hight   number_of_zonest   zone_exponentt   logt   n_refl_datat   d_maxt   d_mint   m_ref_firstt   final_n_ref_firstt   d_minst
   degeneratet   zone_factort   i_zonet   nt   target_namest   it   d_it   n_ref(    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/rigid_body.pyt   split_resolution_range{   s°      






"t   managerc           B   sP   e  Z d d d d d d d d  „ Z d „  Z d „  Z d „  Z d d d „ Z RS(   c	   %      C   sÝ  | |  _  | j }	 d  }
 | d  k	 r0 | j }
 n  t ƒ  } | j ƒ  } | j ƒ  } | j j ƒ  } | d  k rx t	 j
 } n  | d  k r» g  } | j t j | j j ƒ  j ƒ  t ƒ j ƒ  ƒ n t | ƒ d k sÓ t ‚ | j j ƒ  j d t ƒ | j j ƒ  j d t j | j j ƒ  j ƒ  t ƒ j ƒ  ƒ g  |  _ g  |  _ xF | D]> } |  j j t j d d ƒ ƒ |  j j t j d d ƒ ƒ q?W| d  k rÀg  } x* | D] } | j t j d d ƒ ƒ qšWn  | d  k rÿg  } x* | D] } | j t j d d ƒ ƒ qÙWn  | j ƒ  } | j d  k	 r)d | j _ n  t d | j ƒ  j ƒ  j  ƒ  d t | ƒ d | j! d	 | j" d
 | j# d | j$ d | j% d | j& d | j' d | j( d | ƒ \ } } | J| j | d k rØ| j) d | d ƒ n  |  j* d | d |  j d |  j d d d | ƒ | j' d k s!| d  k r*d  } n7 | j+ } | d  k	 ra| d d  d d  d | d d ƒ n  x�t, | | ƒ D]\ } } | j j ƒ  } | j- d | ƒ } | j | k rÀ| j) d | ƒ n  | j ƒ  j. ƒ  } d t/ d | d ƒ j0 ƒ  d  t/ d! | d ƒ j0 ƒ  d" | j } t1 j2 | d | ƒ| j3 d# | d$ t ƒ t j ƒ  } t | ƒ d k rgd } n t4 t5 | ƒ d% ƒ } xŒt6 | ƒ D]~} | d  k	 r\| j7 r\| j8 ƒ  j9 ƒ  d& k rÈt | _ n  t } | j: d' k ræt } n  | j; d( t d) | d* | d | d+ t d, t d- t ƒ | j8 ƒ  j9 ƒ  d& k r\|
 d  k	 sDt ‚ |
 | _ |
 | _< q\n  t= d | d. | d/ | d0 | d1 | j> d2 | j? d3 | j@ d4 | jA d5 | jB ƒ 	} g  } g  } xÒ t6 t | ƒ ƒ D]¾ }  |  j |  c t j | jC |  ƒ 7<|  j |  c t j | jD |  ƒ 7<tE jF jG d6 | jC |  d d7 | jC |  d d8 | jC |  d9 d: | jA ƒ }! | j |! jH ƒ  ƒ | j | jD |  ƒ qÉWtI d# | jJ j d; | d< | d. | ƒ }" | j3 d# |" d$ t d= t ƒ | jJ j ƒ  }# | jJ j ƒ  }$ tK |# | j ƒ  ƒ s‰t ‚ q‰W| j3 d# | j d$ t d= t ƒ | d  k	 r”| j7 r”t } | j: d' k r]t } n  | j; d( t d) | d* | d | d+ t d, t d- t ƒ n  |  j* d | d |  j d |  j d d> d | ƒ | d  k	 rq| d d  d d  d | d d ƒ qqqqW| d  k	 r^| j7 r^t } | j: d' k r't } n  | j; d( t d) | d* | d | d+ t d, t d- t ƒ n  | J|  j* d | d |  j d |  j d d? d | ƒ | J|  jL | | | | | ƒ | |  _J |  jJ j) d |	 ƒ tM | jN ƒ  7aM d  S(@   Ni    t   statet
   iselectioni   iÿÿÿÿR5   R6   R7   R8   R9   R:   R;   R<   R=   R>   R?   t   target_namet   fmodelt   r_matt   t_vect   headert   StartR   i   t   monitort   modelt   methodt
   rigid_bodyRB   s   Refinement at resolution: s   %7.2fs    - s   %6.2fs    target=t   xray_structuret   update_f_calci   g      @t   slowt   update_f_part1t   paramst   fastt   remove_outlierst   optimize_maskt   refine_hd_scatteringt
   selectionst	   r_initialt	   t_initialt   refine_rt   refine_tt   max_iterationsR   t   lbfgs_maxfevt   phit   psit   thei   t
   conventiont   rotation_matricest   translation_vectorst   update_f_masks   Rigid body refinements   Rigid body end(O   R`   RR   R!   t   anisotropic_scalingR   t   r_workt   r_freeR\   t   deep_copy_scatterersR"   R#   R   R   t   boolt
   scatterersR,   R/   RQ   R   R   t   flags_set_gradsR3   t   flags_set_grad_sitet   total_rotationt   total_translationt   doublet	   deep_copyt   mask_paramst   verboseRN   t
   f_obs_workR5   t   dataR7   R8   t   min_number_of_reflectionst   multi_body_factort   max_low_high_res_limitt   high_resolutionR=   R>   t   updateR%   t   call_back_handlerR   t   resolution_filtert	   d_max_mint   strt   stripR   t   make_sub_headert   update_xray_structureR2   t   intt   xranget   bulk_solvent_and_scalet   f_obsRB   t   modet   update_all_scalest   minimization_b_cartt   rigid_body_minimizert   refine_rotationt   refine_translationRj   R   t*   lbfgs_line_search_max_function_evaluationst   r_mint   t_mint   scitbxR[   t   eulert   rot_matt   apply_transformationRS   R   t   evaluate_after_endt   time_rigid_body_totalt   elapsed(%   R   RS   Re   R`   Rf   Rg   t   bssR?   t   monitorst   save_original_target_namet   save_bss_anisotropic_scalingt   timer_rigid_body_totalt   save_r_workt   save_r_freet   save_xray_structuret   itemt   fmodel_copyRE   RJ   t   monitors_call_back_handlert   resRR   t   xrsRŠ   t   linet   rworkst   n_rigid_body_minimizer_cyclest   i_macro_cycleRa   t	   minimizedRp   Rq   RK   t   rot_objt   new_xrst   rworkt   rfree(    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/rigid_body.pyR   è   s^   				 %(		   												E	 							##			 		
		  		
		
	c         C   sý   | j  ƒ  } | j ƒ  } | | k rù t | | ƒ d k rù | J|  j j rW | d IJn | d IJ| d IJ| d | | f IJ| d | | f IJ|  j j r¬ | d IJnF | d IJ| J| j d	 | d
 t d t ƒ | j ƒ  j d d d | ƒ | Jn  d  S(   Ng{®Gáz„?s/   Warning: R-factors increased during refinement.s@   The model after this rigid-body refinement step is not accepted.s/   Reason: increase in R-factors after refinement.s    Start/final R-work: %6.4f/%-6.4fs    Start/final R-free: %6.4f/%-6.4fs<   (Revert to previous model is disabled, so accepting result.)s"   Return back to the previous model.R\   R]   Rr   RV   s   rigid body after step backR   (	   Rt   Ru   t   absR`   t   disable_final_r_factor_checkRŽ   R/   t   infot$   show_rfactors_targets_scales_overall(   R   RS   R¨   R©   Rª   R?   Rt   Ru   (    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/rigid_body.pyR    £  s(    "


c         C   s   |  j  S(   N(   R{   (   R   (    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/rigid_body.pyt   rotation¼  s    c         C   s   |  j  S(   N(   R|   (   R   (    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/rigid_body.pyt   translation¿  s    R   c         C   sä   | d  k r t j } n  | j ƒ  } | j d | d | ƒ | d d d d IJ| j d | ƒ | d d d d IJ| d |  j j d d	 d IJt j	 d | d
 d d d d |  j j d | d | ƒ | d d d d IJd  S(   NRV   R   s   | s     i&   R   s%   | Rigid body shift (Euler angles %s):t    i(   R   R   R   R   R   R   R    iM   (
   R!   R"   R#   R»   t    _header_resolutions_nreflectionst+   _rfactors_and_bulk_solvent_and_scale_paramsR`   R   R   R$   (   R   RS   RT   RU   RV   R   t   fmodel_info(    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/rigid_body.pyR%   Â  s"     	N(   R&   R'   R!   R   R    R½   R¾   R%   (    (    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/rigid_body.pyRO   ç   s   ´			R–   c           B   s/   e  Z d  „  Z d „  Z d „  Z e d „ Z RS(   c
         C   s   t  |  t ƒ  ƒ |  j j ƒ  |  _ |  j j ƒ  |  _ |  j j ƒ  |  j j j ƒ  |  _ |  j j j	 ƒ  |  _	 |  j j j
 ƒ  |  _
 t |  j ƒ |  _ |  j d k s§ t ‚ d |  _ t |  j ƒ t |  j ƒ k sÔ t ‚ t |  j ƒ t |  j ƒ k sø t ‚ d |  _ d |  _ t j |  j ƒ |  _ t j |  j ƒ |  _ xQ t t |  j ƒ ƒ D]: }
 t |  j |
 ƒ |  j |
 <t |  j |
 ƒ |  j |
 <qJW|  j |  j |  j ƒ |  _ |  j j ƒ  |  _ t j d |  d t j  d |	 ƒ d t j! d | ƒ d t j" d	 t# d
 t# ƒ ƒ |  _$ |  j% d t# ƒ |  ` d  S(   Ni    i   t   target_evaluatort   core_paramst   maxfevt   termination_paramsRj   t   exception_handling_paramst-   ignore_line_search_failed_step_at_lower_boundt-   ignore_line_search_failed_step_at_upper_boundt   suppress_gradients(&   R   t   localsRS   R~   R¬   t   target_functort   prepare_for_minimizationR\   t   atomic_weightst
   sites_cartt
   sites_fracR   Re   t   n_groupsR   t   counterRf   Rg   t   dim_rt   dim_tt   copyt   deepcopyRš   R›   R�   t   tuplet   packt   xR,   RI   R   t   runt   core_parameterst   termination_parameterst   exception_handling_parametersR/   t	   minimizert    compute_functional_and_gradients(   R   RS   Re   Rf   Rg   Rh   Ri   Rj   R   Rk   RK   (    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/rigid_body.pyR   Õ  s@    
	$$								c         C   sq   g  } xU t  | | ƒ D]D \ } } |  j r> | t | ƒ 7} n  |  j r | t | ƒ 7} q q Wt j t | ƒ ƒ S(   N(   R   Rh   t   listRi   R   R}   R×   (   R   R   R   t   vt   rit   ti(    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/rigid_body.pyRØ     s    	 	 c         C   sž   d } x‘ t  |  j ƒ D]€ } |  j rY t |  j ƒ | | |  j !|  j | <| |  j 7} n  |  j r t |  j ƒ | | |  j !|  j	 | <| |  j 7} q q Wd  S(   Ni    (
   R�   RÑ   Rh   R×   RÙ   RÓ   Rš   Ri   RÔ   R›   (   R   RK   t   j(    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/rigid_body.pyt   unpack_x  s    	$	$c         C   sÏ  |  j  ƒ  |  j d 7_ g  } g  } g  } x– t |  j ƒ D]… } t j j d |  j | d d |  j | d d |  j | d d |  j ƒ } | j	 | j
 ƒ  ƒ | j	 |  j | ƒ | j	 | ƒ q; Wt d |  j j d	 |  j d
 |  j d | d | d |  j d |  j ƒ \ } } }	 |  j j j | ƒ |  j j }
 |  j j d |
 d t ƒ t d |	 d	 | d |  j d | d |  j d | ƒ } | j ƒ  |  _ | ržd  |  _ n! |  j | j ƒ  | j ƒ  ƒ |  _ |  j |  j f S(   Ni   Rl   i    Rm   Rn   i   Ro   R\   RÏ   RÐ   Rp   Rq   Re   RÎ   R]   t   centers_of_massRÌ   t   rot_objsRÊ   (    Rå   RÒ   R�   RÑ   Rœ   R[   R�   Rš   R   R   Rž   R›   t   apply_transformation_RS   R\   RÏ   RÐ   Re   RÎ   R¬   t   set_sites_fracRŽ   R/   t   target_and_gradsRÌ   R7   t   fR!   t   gRØ   t   gradients_wrt_rt   gradients_wrt_t(   R   RÊ   Rp   Rq   Rç   RK   Rµ   t   new_sites_fract   new_sites_cartRæ   R¶   t   tg_obj(    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/rigid_body.pyRß     sL    
						!(   R&   R'   R   RØ   Rå   R3   Rß   (    (    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/rigid_body.pyR–   Ô  s   	,		
c         C   sñ   t  | ƒ t  | ƒ k s t ‚ t  | ƒ t  | ƒ k s< t ‚ g  } | j ƒ  } | j ƒ  } x‡ t | | | ƒ D]s \ } }	 }
 |  j d | d | d |	 j ƒ  d |
 d | d |  j ƒ  d | ƒ } | j } | j } | j	 | j
 ƒ qm W| | | f S(   NRÏ   RÐ   t   rott   transRÎ   t	   unit_cellt	   selection(   R   R   R~   R   t   apply_rigid_body_shift_objt   as_mat3Rô   RÏ   RÐ   R   t   center_of_mass(   R\   RÏ   RÐ   Rp   Rq   Re   RÎ   Ræ   t   selRò   Ró   Rö   (    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/rigid_body.pyRè   ;  s$    "				c         C   sÝ   t  | ƒ t  | ƒ k s t ‚ t  | ƒ t  | ƒ k s< t ‚ |  j ƒ  } x| t | | | ƒ D]h \ } } } |  j | ƒ } | j ƒ  }	 | j ƒ  }
 |
 |	 } t | ƒ | | |	 } | j | | ƒ q[ W|  j d | ƒ } | S(   Nt	   new_sites(	   R   R   RÏ   R   R-   Rø   Rà   t   set_selectedt   replace_sites_cart(   R\   Rp   Rq   Re   Rú   Rù   Rò   Ró   R¯   t   cm_cartRÏ   t   sites_cart_cmt   tmpR¶   (    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/rigid_body.pyRŸ   U  s    "
Rê   c           B   s,   e  Z d  „  Z d „  Z d „  Z d „  Z RS(   c         C   s[  | d | ƒ } | j  ƒ  |  _ | r; d  |  _ d  |  _ d  S| j d t ƒ } g  |  _ g  |  _ t j | j	 ƒ  ƒ } xà t
 | | | ƒ D]Ì \ }	 }
 } | j |	 ƒ | } | j |	 ƒ } t j | j | ƒ ƒ } |  j j t j | j ƒ  ƒ ƒ |
 j ƒ  | j ƒ  } |
 j ƒ  | j ƒ  } |
 j ƒ  | j ƒ  } |  j j t j | | | g ƒ ƒ q‡ Wd  S(   Nt   compute_gradientst   site(   t   target_workRë   R!   t   grads_wrt_rt   grads_wrt_tt   gradients_wrt_atomic_parametersR/   R   t   vec3_doublet   packedR   R-   R   t   sqrt   transpose_multiplyR   R}   t   sumt   r_phit   tracet   r_psit   r_the(   R   Ræ   RÏ   RÌ   Rç   Re   RÊ   t   t_rt   target_grads_wrt_xyzRù   Rµ   t   cmRþ   t   target_grads_wrt_xyz_selt   target_grads_wrt_rt   g_phit   g_psit   g_the(    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/rigid_body.pyR   g  s(    				"c         C   s   |  j  S(   N(   Rë   (   R   (    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/rigid_body.pyR7   ‚  s    c         C   s   |  j  S(   N(   R  (   R   (    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/rigid_body.pyRí   …  s    c         C   s   |  j  S(   N(   R  (   R   (    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/rigid_body.pyRî   ˆ  s    (   R&   R'   R   R7   Rí   Rî   (    (    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/rigid_body.pyRê   f  s   			i   c         C   s{  |  j  ƒ  j ƒ  j d ƒ s" t ‚ | d  k r: t ƒ  } n  d } | sO d } n  |  j ƒ  j d | ƒ } |  j | ƒ }  |  j	 ƒ  } t
 | ƒ d k sš t ‚ t |  j ƒ  ƒ }	 g  }
 xí | d j ƒ  D]Û } | j ƒ  pÞ | j ƒ  sç qÃ n  | j  ƒ  } | j ƒ  | k rÃ | j ƒ  } d | j } | sg| d j ƒ  j ƒ  } | d j ƒ  j ƒ  } | d | | f 7} n | d	 | 7} | d
 7} | |
 k rž|
 j | ƒ qžqÃ qÃ W| rw| d  k	 sºt ‚ |  j ƒ  } | j ƒ  } | j ƒ  } x– |
 D]‹ } | j | ƒ j ƒ  } | j | ƒ } t
 | ƒ d k rå| d IJ| d | IJ| d IJx& | D] } | d |	 | j ƒ  IJqJWd  SqåWn  |
 S(   Ni    s    not (resname HOH or resname WAT)s*   not (not pepnames and single_atom_residue)t   stringi   s   (chain '%s'iÿÿÿÿs    and resid %s through %ss    and t   )s8     WARNING: selection includes atoms on special positionss       selection: %ss       bad atoms:s       %s(   t   atomst   extract_i_seqt   all_eqR   R!   R   t   atom_selection_cacheRõ   R-   t   modelsR   Rà   t   atoms_with_labelst   chainst
   is_proteint   is_naR,   t   residue_groupst   idt   residRŒ   R   t   site_symmetry_tablet   special_position_indicesRQ   t   intersectiont   id_str(   t   pdb_hierarchyt   min_chain_sizeR\   t$   check_for_atoms_on_special_positionst   group_all_by_chainR?   t
   sel_stringRõ   R  t   atom_labelsRe   t   chaint   chain_atomst   rgst
   chain_selet   resid_firstt
   resid_lastt	   sel_cacheR%  t   disallowed_i_seqst   sele_strt   iselt   isel_specialt   i_seq(    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/rigid_body.pyt   rigid_groups_from_pdb_chains‹  sV    " 	


('   t
   __future__R    t   cctbx.array_familyR   t   libtbxR   R"   t   libtbx.test_utilsR   Rœ   R   R   t   mmtbx.refinementR   t
   iotbx.philt   iotbxRÕ   t   libtbx.utilsR   R   t   libtbx.math_utilsR	   t   scitbx.rigid_bodyR¡   t   objectR
   t   multiple_zones_params_strt   philt   parset   master_paramsR!   RN   RO   R–   Rè   RŸ   Rê   R3   R;  (    (    (    sI   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/refinement/rigid_body.pyt   <module>   s:   ;	*aíg		'