ó
Ù™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 m	 Z	 d  d l
 Z d Z d „  Z d	 „  Z d
 „  Z d e d d „ Z d S(   iÿÿÿÿ(   t   division(   t   rotatable_bonds(   t   rotate_point_around_axis(   t   flex(   t   maptbxNs  
refine = individual riding *Auto
  .type = choice
  .help = Choice for refinement: riding model or full (H is refined as           other atoms, useful at very high resolutions only)
  .short_caption = Hydrogen refinement model
  .expert_level=1
force_riding_adp = None
  .type = bool
optimize_scattering_contribution = True
  .type = bool
contribute_to_f_calc = True
  .type = bool
  .help = Add H contribution to Xray (Fcalc) calculations
  .short_caption=Include hydrogens in Fcalc
  .expert_level=1
high_resolution_limit_to_include_scattering_from_h = 1.6
  .type = float
  .short_caption = High-resolution limit to include scattering from H
  .expert_level=2
real_space_optimize_x_h_orientation = True
  .type = bool
  .short_caption = Optimize X-H orientation in real-space
  .expert_level = 1
xh_bond_distance_deviation_limit = 0.0
  .type = float
  .help = Idealize XH bond distances if deviation from ideal is greater           than xh_bond_distance_deviation_limit
  .short_caption = X-H bond distance deviation limit
  .expert_level=2
c   '      C   s!  g  } d „  } d „  } | d k	 rZ t j ƒ  } x' | j j D] } | j | j ƒ q= Wn  t j j	 }	 d d l
 }
 x¨|  j ƒ  D]š} x‘| j ƒ  D]ƒ} | j ƒ  } t | ƒ } xbt | ƒ D]T\ } } | d k pâ | d | k } | j ƒ  } x| j ƒ  D]} x| j ƒ  D]ø} | j j ƒ  j ƒ  d k r8qn  | j ƒ  } |	 d | j ƒ d	 k rtt | ƒ d k rtqn  |	 d | j ƒ d
 k r| rt j d | d | d t d | ƒ } | d k	 r	| d | d | ƒ } | d k	 rx | D] } | j | ƒ qëWqq	q| d k	 r| j ƒ  } | j ƒ  } | j ƒ  } | j ƒ  } d g | j ƒ  } t | j ƒ  ƒ } | j  | ƒ } | j j! d | ƒ j" j# }  g  }! x |  D] }" |! j |" j ƒ q£Wg  }# g  }$ x|  D]}" |
 j$ j% j& d | d |! d |" j g ƒ }% |
 j' j( d | d | d | d |% d d ƒ }& t j d | d | d t d d d |& ƒ } | d k	 rÐ| d | d | d |  d | ƒ } | d k	 rät | ƒ d k räx< | D]1 } | |$ k r©| |$ k rÚ|$ j | ƒ qÚq©q©WqäqÐqÐWx |$ D] } | j | ƒ qïWqqWqþ Wq½ Wq’ Wq W| S(   sQ   
  General tool to identify rotatable H, such as C-O-H, C-H3, in any molecule.
  c         S   sµ  g  } x~|  D]v} t  | d ƒ d k s/ t ‚ t  | d ƒ d k sK t ‚ | | d d | | d d } } | j j ƒ  j ƒ  } | j j ƒ  j ƒ  } | | g j d ƒ d k oÍ | | g j d ƒ d k } t }	 g  }
 x; | d D]/ } | | j j ƒ  j ƒ  d k rç t }	 Pqç qç Wg  }
 d  } | r |	 r | j	 | j	 g } x& | d D] } |
 j
 | | j	 ƒ qOW| j
 | |
 g ƒ q q Wt  | ƒ d k o¤d  k	 n r­| Sd  Sd  S(   Ni    i   i   t   Ht   D(   R   R   (   t   lent   AssertionErrort   elementt   stript   uppert   countt   Truet   Falset   Nonet   i_seqt   append(   t   gt   atomst   resultt   git   a1t   a2t   e1t   e2t   condition_1t   condition_2t	   rot_atomst   gi1it   axis(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/hydrogens/__init__.pyt   analyze_group_aa_specific-   s0    %6" c         S   sÅ  g  } xŽ|  D]†} d \ } } } t | d ƒ d k s> t ‚ t | d ƒ d k sZ t ‚ | | d d | | d d }	 }
 |	 j j ƒ  j ƒ  } |
 j j ƒ  j ƒ  } | | g j d ƒ d k oÜ | | g j d ƒ d k } t | d ƒ } | r t } x; | d D]/ } | | j j ƒ  j ƒ  d k rt	 } PqqW| r“t	 } xµ | d D]© } g  } xc | D][ } | | j
 k rcxC | j
 D]5 } | | j j ƒ  j ƒ  d k r‚| j | ƒ q‚q‚WqcqcWt | ƒ } t | | @ƒ } t | ƒ d k rPt } qPqPW| r�| r�| r�|	 j |
 j g } g  } t	 } x> | D]6 } | | j | k rVt } n  | j | | j ƒ q4W| s�| j | | g ƒ q�q�q“q q Wt | ƒ d k o´d  k	 n r½| Sd  Sd  S(	   Ni    i   i   R   R   (   NNN(   R   R   (   R   R   (   R   R   R   R	   R
   R   R   t   setR   R   t   i_seqsR   t   listR   (   R   R   t   bpst   pselR   R   R   R   t   condition_3R   R   R   R   t   s1R   t   giat   bonds_involved_intot   bpR   t   s2t   sR   R   t   in_planet   i(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/hydrogens/__init__.pyt   analyze_group_generalG   sT    %6  	 #" iÿÿÿÿNi    i   t   PROt   namet   common_watert   common_amino_acidt   residuet   mon_lib_srvt   remove_clusters_with_all_ht   logR   R   t
   sites_cartt   sitest	   edge_listt   fixed_vertex_listst   labelst   massest
   tardy_treet   potential_objt   tardy_modelR#   R$   ()   R   R   t   size_tt   geometryt   planarity_proxiest   extendR!   t   iotbxt   pdbt   common_residue_names_get_classt   scitbx.graph.tardy_treet   modelst   chainst   residue_groupsR   t	   enumeratet
   conformerst   residuest   resnameR
   R   R   R   t   axes_and_atoms_aa_specificR   R   t   extract_elementt   extract_namet   extract_i_seqt   extract_xyzt   sizet   ranget   selectt   pair_proxiest   bond_proxiest   simplet   graphR=   t	   constructt
   rigid_bodyR?   ('   t   pdb_hierarchyR4   t   restraints_managerR6   R   R   R.   R$   t   pt	   get_classt   scitbxt   modelt   chainRJ   t
   n_residuest   i_rgt   residue_groupt   first_or_lastRL   t	   conformerR3   R   t   frt   rt   r_t   elementst   namest
   iselectionR7   R<   R;   t   grm_iR#   R9   R)   R:   t   tmp_rR=   R?   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/hydrogens/__init__.pyt	   rotatable(   s”    		, 	  			! !(c         C   s/   d } x" |  D] } | t  | d ƒ 7} q W| S(   Ni    i   (   R   (   t
   selectionsR   R+   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/hydrogens/__init__.pyt   count_rotatableÁ   s    c         C   s•  | j  ƒ  } | j ƒ  } | j ƒ  } x]| D]U} d } d }	 d }
 | d } | d } t j t | ƒ ƒ } xã |	 d k rQt j t | ƒ ƒ } d } xŠ t | ƒ D]| \ } } t d | | d d | | d d | | d	 |	 d
 t ƒ } | j	 | ƒ } | t
 t j | | ƒ ƒ 7} | | | <q£ W| | k rD| } | j ƒ  } n  |	 |
 7}	 qo Wx+ t | ƒ D] \ } } | | | | _ q_Wq+ W|  j | ƒ d  S(   Niÿÿÿÿg        i   i    ih  t   axis_point_1t   axis_point_2t   pointt   anglet   deg(   t	   unit_cellR7   t
   scatterersR   t   vec3_doubleR   RK   R   R   t   fractionalizet   absR   t   eight_point_interpolationt	   deep_copyt   sitet   adopt_xray_structure(   R]   t   xray_structuret   map_datat   rotatable_h_selectionRy   R7   Rz   t   sel_t   ed_valRw   t   angular_stepR   t   points_i_seqst   sites_frac_bestt   sites_frac_tmpt   ed_val_R   t   point_i_seqt   site_cart_newt   site_frac_new(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/hydrogens/__init__.pyt   fit_rotatableÈ   s<    


	s   2mFo-DFcc      	   C   sâ  | j  d t ƒ } |  j } t d | d | j j d | j d | ƒ } g  }	 x | D] }
 |	 j |
 d ƒ qR Wt j	 |	 ƒ }	 t j
 | j ƒ  j ƒ  |	 ƒ } | d  k	 rÓ | d IJ| d |  j ƒ  |  j ƒ  f IJn  | r4|  j j | ƒ } |  j d	 | d
 t ƒ | d  k	 r4| d |  j ƒ  |  j ƒ  f IJq4n  |  j ƒ  j d d d | d t j ƒ } | j ƒ  | j ƒ  } t d | d	 | d | d | ƒ |  j d	 | d
 t ƒ | | _ | d  k	 rÞ| d |  j ƒ  |  j ƒ  f IJn  d  S(   Nt   sync_with_xray_structureR]   R4   R^   R6   i   s*   Real-space grid search fit H (or D) atoms:s#     start:  r_work=%6.4f r_free=%6.4fR‚   t   update_f_calcs#     H omit: r_work=%6.4f r_free=%6.4ft   resolution_factorg      ð?g      @t   map_typet   symmetry_flagsR„   Rƒ   s#     final:  r_work=%6.4f r_free=%6.4fg      Ð?(   R]   R   R‚   Rq   t   processed_pdb_files_srvR4   R^   RC   R   R@   t   boolRz   RT   R   t   r_workt   r_freeRV   t   update_xray_structuret   electron_density_mapt   fft_mapR   t   use_space_group_symmetryt   apply_sigma_scalingt   real_map_unpaddedR�   (   t   fmodelt	   ref_modelR‡   R6   t   use_h_omit_mapR“   R]   t   xrsR„   t   rotatable_h_selection_1dR+   t   rotatable_h_selection_1d_boolt   xrs_omitR›   Rƒ   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/hydrogens/__init__.pyt   run_fit_rotatableì   sN    				

	(   t
   __future__R    t   mmtbx.utilsR   t   scitbx.matrixR   t   cctbx.array_familyR   t   cctbxR   t	   iotbx.pdbRD   t   hydrogens_master_params_strRq   Rs   R�   R   R   R¦   (    (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/hydrogens/__init__.pyt   <module>   s    	™		(