ó
Ë™xTc           @   sw   d  Z  d d l m Z d d l m Z d d l m Z m Z d d l m	 Z	 d Z
 d „  Z d d	 „ Z e	 d
 „ Z d S(   sl   
Functions specific to identifying halide ions.  Very preliminary - needs
much more sophisticated analysis.
iÿÿÿÿ(   t   division(   t   server(   t   colt   distance_from_plane(   t   AutosB  
max_distance_to_amide_n = 3.5
  .type = float
  .input_size = 80
  .help = Max distance to amide N atom
max_distance_to_cation = 3.5
  .type = float
  .input_size = 80
min_distance_to_anion = 3.5
  .type = float
  .input_size = 80
min_distance_to_other_sites = 2.1
  .type = float
  .input_size = 80
max_distance_to_hydroxyl = 3.5
  .type = float
delta_amide_h_angle = 20
  .type = float
  .input_size = 80
  .help = Allowed deviation (in degrees) from ideal N-H-X angle
delta_planar_angle = 10
  .type = float
  .input_size = 80
max_deviation_from_plane = 0.8
  .type = float
c         C   s…   |  d k r | d k r t  S|  d	 k r8 | d k r8 t  St |  ƒ d k rq |  d d !d k rq |  d d k rq t  S| d k r� t  St S(   s,  
  Determine whether the oxygen atom of interest is either negatively charged
  (usually a carboxyl group or sulfate/phosphate), or has a lone pair (and
  no hydrogen atom) that would similarly repel anions.

  Parameters
  -----------
  atom_name : str
  resname : str

  Returns
  -------
  bool
  t   OD1t   OD2t   OE1t   OE2t   GLUt   ASPt   GLNt   ASNt   Ot   HOHt   WATi   i    i   t   O1t   O2t   O3t   At   Bt   Gt   SO4t   PO4(   R   R   R   R   (   R	   R
   R   R   (   R   R   (   R   R   R   (   R   R   R   (   R   R   (   t   Truet   lent   False(   t	   atom_namet   resname(    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/halides.pyt   is_negatively_charged_oxygen'   s    %g      è?c         C   sè   g  } | j  } x¤ | j ƒ  D]– } | j j ƒ  } | d k r\ | d k r\ | j | j ƒ q | d k r‡ | d k r‡ | j | j ƒ q | d	 k r | d k r | j | j ƒ q q Wt | ƒ d k rÌ t St |  j | ƒ } | | k S(   s¾  
  Given an isolated atom and an interacting residue with one or more amine
  groups, determine whether the atom is approximately coplanar with the terminus
  of the sidechain (and thus interacting with the amine hydrogen(s) along
  approximately the same axis as the N-H bond).

  Parameters
  ----------
  atom : iotbx.pdb.hierarchy.atom
  residue : iotbx.pdb.hierarchy.residue
  distance_cutoff : float, optional

  Returns
  -------
  bool
  t   ARGt   NH1t   NH2t   NER   R   t   NE2t   CDR   R   t   ND2t   CGi   (   R   R    R!   (   s   OE1R"   R#   (   s   OD1R$   R%   (	   R   t   atomst   namet   stript   appendt   xyzR   R   R   (   t   atomt   residuet   distance_cutofft   sidechain_sitesR   t   otherR'   t   D(    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/halides.pyt   _is_coplanar_with_sidechainC   s    	c   (         sÏ  | d( t g k r: | j ƒ  } d | k p3 d | k } n  | |  }	 t }
 t } t } t } t |	 j ƒ } t ˆ j ƒ  d d !ƒ } | } x¶| D]®‰  ‡  ‡ ‡ f d †  } ˆ  j } ˆ  j	 ƒ  } ˆ  j
 ƒ  } ˆ  j } t ˆ  ƒ } | j } | | j k  rþ t S| d) k rtt j | ƒ } | d k  r8| | j k r8t S| d k r?| | j k r?t } | | k  rq| } qqq?q‘ | d* k r¹| d+ k r¹| | j k r¹t } | | k  r?| } q?q‘ | d, k r=| d- k r=| sã| d k r=| | j k r=t |	 | j ƒ  d | j ƒr?t }
 | d k r:| | k  r:| } q:q?q‘ | d. k r‚| d/ k r‚| | j k r‚t } | | k  r?| } q?q‘ | d0 k r)t ˆ  j ƒ } | | } t | ƒ d k r¿q‘ n  t | | d ƒ ƒ } | | } | | } t | j | d t ƒƒ } t | d ƒ | j k r?t }
 q?q‘ | d1 k rt| rtt ˆ  j ƒ } | | } d( } }  xx | D]p }! | |! }" |" j j ƒ  j ƒ  d2 k r¥t | |! ƒ ƒ } qe|" j j ƒ  j ƒ  d3 k ret | |! ƒ ƒ }  qeqeW| d( k	 r?|  d( k	 r?| |  d }# | |# }$ | |$ j ƒ  d } | | }% | | }& t |% j |& d t ƒƒ } t | d ƒ | j k rqt }
 qqq?q‘ | d4 k rŒ| d5 k s¤| d6 k r‘ | d7 k r‘ | | } t | ƒ d k sÆt  ‚ t | | d ƒ ƒ } t ˆ  j ƒ } | | }% | | }' t |% j |' d t ƒƒ } t | d ƒ | j k r?t }
 q?q‘ q‘ Wxy | D]q ‰  ˆ  j! ƒ  d8 k rhqJn  ˆ  j	 ƒ  } ˆ  j
 ƒ  } t ˆ  ƒ } | d& k  rJ| | d' k  rJt" | | ƒ rJt SqJW|
 pÎ| pÎ| S(9   sl  
  Detects if an atom's site exists in a favorable environment for a halide
  ion. This includes coordinating by a positively charged sidechain or backbone
  as well as an absense of negatively charged coordinating groups.

  Parameters
  ----------
  i_seq : int
  contacts : list of mmtbx.ions.environment.atom_contact
  pdb_atoms : iotbx.pdb.hierarchy.af_shared_atom
  sites_frac : tuple of float, float, float
  connectivity : scitbx.array_family.shared.stl_set_unsigned
  unit_cell : uctbx.unit_cell
  params : libtbx.phil.scope_extract
  assume_hydrogens_all_missing : bool, optional

  Returns
  -------
  bool
  t   HR0   i    i   c            s   ˆ j  d ˆ  j ˆ |  ƒ S(   Nt	   site_frac(   t   orthogonalizet   rt_mx(   t   k_seq(   t   contactt
   sites_fract	   unit_cell(    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/halides.pyt   get_site�   s    	t   Ct   NR   t   St   NZt   LYSR   R    R$   R"   R   R   R   R-   t   OG1t   OG2t   OH1t   SERt   THRt   TYRi   t   degi´   t   CAi   g…ëQ¸…ë?t   HD1t   HD2t   HE1t   HE2t    R   gš™™™™™	@gš™™™™™É?N(   R;   R<   R2   R   R=   (   R>   (   R?   (   R>   s   NH1s   NH2s   ND2s   NE2(   s   ARGs   ASNs   GLN(   R@   RA   RB   (   RC   RD   RE   (   R2   (   R<   (   RG   (   R;   (   RH   RI   (   s   ASN(   RJ   RK   (   s   GLN(   RL   R   (#   t   NoneR   t   extract_elementR   R   R*   t   maxt
   parametersR+   R   R   t   elementt   abst   i_seqt   min_distance_to_other_sitesR   t
   get_charget   min_distance_to_aniont   max_distance_to_cationR   R1   t   parentt   max_deviation_from_planet   max_distance_to_hydroxylt	   site_cartR   t   anglet   delta_amide_h_angleR'   R(   t   uppert	   normalizet   AssertionErrort   altlocR   ((   RS   t   contactst	   pdb_atomsR8   t   connectivityR9   t   paramst   assume_hydrogens_all_missingt   elementsR+   t   binds_amide_hydrogent   near_cationt   near_lyst   near_hydroxylR*   t   min_distance_to_cationt   min_distance_to_hydroxylR:   R/   R   R   RQ   t   distancet   j_seqt   charget   xyz_ht   bonded_atomst   xyz_nt   vec_hnt   vec_hxR\   t   ca_samet   c_prevR6   t   other2t   xyz_ccat   vec_nccat   vec_nht   vec_nxt   vec_xh(    (   R7   R8   R9   s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/halides.pyt   is_favorable_halide_environmentd   sÐ    
			


	








	N(   t   __doc__t
   __future__R    t
   mmtbx.ionsR   t   scitbx.matrixR   R   t   libtbxR   t   chloride_params_strR   R1   R~   (    (    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/halides.pyt   <module>   s   	)