ó
“™xTc           @   s÷   d  d l  m Z d  d l m Z d  d l m Z m Z d  d l m Z d  d l m	 Z	 d  d l
 m Z d  d l Z d d d d d d d d d d d „
 Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d S(   iÿÿÿÿ(   t   division(   t   sgtbx(   t   adp_restraintst   geometry_restraints(   t   adp_restraint_params(   t   flex(   t   modelNc         C   s»  | d  k	 r% |  j t | | ƒ ƒ n  | d  k	 rJ |  j t | | ƒ ƒ n  | d  k	 ro |  j t | | ƒ ƒ n  | d  k	 r« t | | ƒ } x | D] } |  j | ƒ q‘ Wn  | d  k	 rÐ |  j t | | ƒ ƒ n  | d  k	 rõ |  j t | | ƒ ƒ n  | d  k	 r|  j t | | ƒ ƒ n  |	 d  k	 rVt	 | |	 ƒ } x | D] } |  j | ƒ q<Wn  |
 d  k	 r’t
 | |
 ƒ } x | D] } |  j | ƒ qxWn  | d  k	 r·|  j t | | ƒ ƒ n  d  S(   N(   t   Nonet   add_loopt   distances_as_cif_loopt   angles_as_cif_loopt   dihedrals_as_cif_loopt   bond_similarity_as_cif_loopst   rigid_bond_as_cif_loopt   adp_similarity_as_cif_loopt   isotropic_adp_as_cif_loopt    adp_u_eq_similarity_as_cif_loopst"   adp_volume_similarity_as_cif_loopst   fixed_u_eq_adp_as_cif_loop(   t	   cif_blockt   xray_structuret   bond_proxiest   angle_proxiest   dihedral_proxiest   bond_similarity_proxiest   rigid_bond_proxiest   adp_similarity_proxiest   isotropic_adp_proxiest   adp_u_eq_similarity_proxiest   adp_volume_similarity_proxiest   fixed_u_eq_adp_proxiest   loopst   loopt   l(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/cif/restraints.pyt   add_to_cif_block   s>     	 	 c      
   C   s  t  j d |  j ƒ  ƒ } |  j ƒ  } |  j ƒ  } |  j ƒ  j ƒ  } d } t j d d ƒ } x³ | D]« } t	 j
 d
 | d | d | ƒ }	 | j }
 | j } | d  k r² t  j ƒ  } n  | j | |
 d | |
 d | j | ƒ | |	 j | t j d |	 j ƒ | |	 j f ƒ qa W| S(   Nt   groups   %.4ft   headert!   _restr_distance_atom_site_label_1t!   _restr_distance_atom_site_label_2t   _restr_distance_site_symmetry_2t   _restr_distance_targett#   _restr_distance_target_weight_paramt   _restr_distance_difft	   unit_cellt
   sites_cartt   proxyi    i   (   R%   R&   R'   R(   R)   R*   (   R   t   space_group_infot   space_groupR+   R,   t
   scattererst   extract_labelsR   R    R   t   bondt   i_seqst   rt_mx_jiR   t   rt_mxt   add_rowt   cif_symmetry_codet   distance_idealt   matht   sqrtt   weightt   delta(   R   t   proxiesR.   R+   R,   t   site_labelst   fmtR    R-   t	   restraintR3   t   sym_op(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/cif/restraints.pyR	   3   s8    	     					 
c         C   sP  t  j d |  j ƒ  ƒ } |  j ƒ  } |  j ƒ  } |  j ƒ  j ƒ  } d } t j d d ƒ } t  j	 ƒ  g d } xÜ | D]Ô }	 t
 j d | d | d |	 ƒ }
 |	 j } | d  k r¶ | } n  |	 j } | j | | d | | d | | d | j | d ƒ | j | d ƒ | j | d ƒ | |
 j | t j d |
 j ƒ | |
 j f	 ƒ qt W| S(   NR#   s   %.4fR$   t   _restr_angle_atom_site_label_1t   _restr_angle_atom_site_label_2t   _restr_angle_atom_site_label_3t   _restr_angle_site_symmetry_1t   _restr_angle_site_symmetry_2t   _restr_angle_site_symmetry_3t   _restr_angle_targett    _restr_angle_target_weight_paramt   _restr_angle_diffi   R+   R,   R-   i    i   i   (	   RB   RC   RD   RE   RF   RG   RH   RI   RJ   (   R   R.   R/   R+   R,   R0   R1   R   R    R5   R   t   anglet   sym_opsR   R3   R6   R7   t   angle_idealR9   R:   R;   R<   (   R   R=   R.   R+   R,   R>   R?   R    t   unit_mxsR-   R@   RL   R3   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/cif/restraints.pyR
   Q   sF    	        				 		
c         C   sk  t  j d |  j ƒ  ƒ } |  j ƒ  } |  j ƒ  } |  j ƒ  j ƒ  } d } t j d d ƒ } t  j	 ƒ  g d } x÷ | D]ï }	 t
 j d | d | d |	 ƒ }
 |	 j } | d  k r¶ | } n  |	 j } | j | | d | | d | | d | | d | j | d ƒ | j | d ƒ | j | d ƒ | j | d ƒ | |
 j | t j d |
 j ƒ | |
 j f ƒ qt W| S(   NR#   s   %.4fR$   t    _restr_torsion_atom_site_label_1t    _restr_torsion_atom_site_label_2t    _restr_torsion_atom_site_label_3t    _restr_torsion_atom_site_label_4t   _restr_torsion_site_symmetry_1t   _restr_torsion_site_symmetry_2t   _restr_torsion_site_symmetry_3t   _restr_torsion_site_symmetry_4t   _restr_torsion_angle_targett   _restr_torsion_weight_paramt   _restr_torsion_diffi   R+   R,   R-   i    i   i   i   (   RO   RP   RQ   RR   RS   RT   RU   RV   RW   RX   RY   (   R   R.   R/   R+   R,   R0   R1   R   R    R5   R   t   dihedralRL   R   R3   R6   R7   RM   R9   R:   R;   R<   (   R   R=   R.   R+   R,   R>   R?   R    RN   R-   R@   RL   R3   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/cif/restraints.pyR   v   sN    	          				 		
c      	   C   sÊ  t  j d |  j ƒ  ƒ } |  j ƒ  } |  j ƒ  } |  j ƒ  j ƒ  } d } t j d d ƒ } t j d d ƒ } d }	 xK| D]C}
 t	 j
 d | d | d |
 ƒ } |	 d 7}	 t j t j t j | j ƒ  ƒ ƒ d |
 j j ƒ  ƒ } | j |	 | t j d |
 j d ƒ | | j ƒ  | | | t j | j ƒ  ƒ f ƒ x… t |
 j j ƒ  ƒ D]n } |
 j | \ } } |
 j d  k r�t  j ƒ  } n |
 j | } | j | | | | | j | ƒ |	 f ƒ qJWqy W| | f S(   NR#   s   %.4fR$   t'   _restr_equal_distance_atom_site_label_1t'   _restr_equal_distance_atom_site_label_2t%   _restr_equal_distance_site_symmetry_2t   _restr_equal_distance_class_idt$   _restr_equal_distance_class_class_idt/   _restr_equal_distance_class_target_weight_paramt#   _restr_equal_distance_class_averaget   _restr_equal_distance_class_esdt$   _restr_equal_distance_class_diff_maxi    R+   R,   R-   i   g      ð?(   R[   R\   R]   R^   (   R_   R`   Ra   Rb   Rc   (   R   R.   R/   R+   R,   R0   R1   R   R    R   t   bond_similarityR9   R:   R   t   sumt   pow2t   deltasR3   t   sizeR6   t   weightst   mean_distancet   max_absolutet   rangeRL   R   R5   R7   (   R   R=   R.   R+   R,   R>   R?   R    t
   class_loopt   class_idR-   R@   t   esdt   it   i_seqt   j_seqRA   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/cif/restraints.pyR   Ÿ   sP    	   		    			
!	c   
   	   C   sø   |  j  ƒ  } |  j ƒ  } |  j ƒ  j | ƒ } |  j ƒ  j ƒ  } d } t j d d ƒ } xš | D]’ } t j t	 d | d	 | ƒ d
 | ƒ}	 | j
 | | j d | | j d | t j d | j ƒ | d |	 j ƒ  |	 j ƒ  | |	 j ƒ  f ƒ q^ W| S(   Ns   %.4fR$   t    _restr_U_rigid_atom_site_label_1t    _restr_U_rigid_atom_site_label_2t"   _restr_U_rigid_target_weight_paramt   _restr_U_rigid_U_parallelt   _restr_U_rigid_diffR,   t   u_cartR-   i    i   g      à?(   Rs   Rt   Ru   Rv   Rw   (   R+   R,   R0   t   extract_u_cartR1   R   R    R   t
   rigid_bondR   R6   R3   R9   R:   R;   t   z_12t   z_21t   delta_z(
   R   R=   R+   R,   Rx   R>   R?   R    R-   R@   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/cif/restraints.pyR   Ì   s*    	    		c         C   s   |  j  ƒ  j ƒ  } d } t j d d ƒ } xN | D]F } | j | | j d | | j d | t j d | j ƒ f ƒ q1 W| S(	   Ns   %.4fR$   t"   _restr_U_similar_atom_site_label_1t"   _restr_U_similar_atom_site_label_2t   _restr_U_similar_weight_parami    i   (   R~   R   R€   (	   R0   R1   R   R    R6   R3   R9   R:   R;   (   R   R=   R>   R?   R    R-   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/cif/restraints.pyR   ä   s    	  	"c         C   sq   |  j  ƒ  j ƒ  } d } t j d d ƒ } x@ | D]8 } | j | | j d | t j d | j ƒ f ƒ q1 W| S(   Ns   %.4fR$   t   _restr_U_iso_atom_site_labelt   _restr_U_iso_weight_parami    i   (   R�   R‚   (	   R0   R1   R   R    R6   R3   R9   R:   R;   (   R   R=   R>   R?   R    R-   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/cif/restraints.pyR   ò   s    	 	6c      	   C   sf  |  j  ƒ  j ƒ  } d } t j d d ƒ } t j d d ƒ } |  j ƒ  } t j d |  j  ƒ  j | ƒ d |  j  ƒ  j ƒ  d |  j	 ƒ  ƒ } d } xÌ | D]Ä }	 t j
 d | d |	 ƒ }
 | d 7} | j | | t j d |	 j ƒ | |
 j | |
 j ƒ  | t j |
 j ƒ  ƒ f ƒ xE t |	 j ƒ D]4 \ } } | j | | | |
 j ƒ  | | f ƒ q Wq” W| | f S(   Ns   %.4fR$   t&   _restr_U_Ueq_similar_atom_site_label_1t   _restr_U_Ueq_similar_difft   _restr_U_Ueq_similar_class_idt#   _restr_U_Ueq_similar_class_class_idt.   _restr_U_Ueq_similar_class_target_weight_paramt"   _restr_U_Ueq_similar_class_averaget   _restr_U_Ueq_similar_class_esdt#   _restr_U_Ueq_similar_class_diff_maxRx   t   u_isot   use_u_anisoi    t   paramsR-   i   (   Rƒ   R„   R…   (   R†   R‡   Rˆ   R‰   RŠ   (   R0   R1   R   R    R+   R   R   Ry   t   extract_u_isoRŒ   t   adp_u_eq_similarityR6   R9   R:   R;   t	   mean_u_eqt
   rms_deltasR   Rk   Rg   t	   enumerateR3   (   R   R=   R>   R?   R    Rm   R+   R�   Rn   R-   R@   Rp   Rq   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/cif/restraints.pyR   ý   sB    	  		    				
	
c         C   s  |  j  ƒ  j ƒ  } d } t j d d ƒ } |  j ƒ  } t j d |  j  ƒ  j | ƒ d |  j  ƒ  j ƒ  d	 |  j	 ƒ  ƒ } xˆ | D]€ } t j
 d
 | d | ƒ } x_ t | j ƒ D]N \ }	 }
 | j | |
 | t j d | j ƒ | | j | | j ƒ  f ƒ qª Wq| W| S(   Ns   %.4fR$   t   _restr_U_Ueq_atom_site_label_1t   _restr_U_Ueq_weight_paramt   _restr_U_Ueq_targett   _restr_U_Ueq_diffRx   R‹   RŒ   R�   R-   i   (   R“   R”   R•   R–   (   R0   R1   R   R    R+   R   R   Ry   RŽ   RŒ   t   fixed_u_eq_adpR’   R3   R6   R9   R:   R;   t
   u_eq_idealR<   (   R   R=   R>   R?   R    R+   R�   R-   R@   Rp   Rq   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/cif/restraints.pyR   #  s,    	   				
c      	   C   sf  |  j  ƒ  j ƒ  } d } t j d d ƒ } t j d d ƒ } |  j ƒ  } t j d |  j  ƒ  j | ƒ d |  j  ƒ  j ƒ  d |  j	 ƒ  ƒ } d } xÌ | D]Ä }	 t j
 d | d |	 ƒ }
 | d 7} | j | | t j d |	 j ƒ | |
 j | |
 j ƒ  | t j |
 j ƒ  ƒ f ƒ xE t |	 j ƒ D]4 \ } } | j | | | |
 j ƒ  | | f ƒ q Wq” W| | f S(   Ns   %.4eR$   t)   _restr_U_volume_similar_atom_site_label_1t   _restr_U_volume_similar_difft    _restr_U_volume_similar_class_idt&   _restr_U_volume_similar_class_class_idt1   _restr_U_volume_similar_class_target_weight_paramt%   _restr_U_volume_similar_class_averaget!   _restr_U_volume_similar_class_esdt&   _restr_U_volume_similar_class_diff_maxRx   R‹   RŒ   i    R�   R-   i   (   R™   Rš   R›   (   Rœ   R�   Rž   RŸ   R    (   R0   R1   R   R    R+   R   R   Ry   RŽ   RŒ   t   adp_volume_similarityR6   R9   R:   R;   t   mean_u_volumeR‘   R   Rk   Rg   R’   R3   (   R   R=   R>   R?   R    Rm   R+   R�   Rn   R-   R@   Rp   Rq   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/cif/restraints.pyR   =  sB    	  		    				
	
(   t
   __future__R    t   cctbxR   R   R   t   cctbx.adp_restraintsR   t   cctbx.array_familyR   t	   iotbx.cifR   R9   R   R"   R	   R
   R   R   R   R   R   R   R   R   (    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/cif/restraints.pyt   <module>   s4   		%	)	-				&	