ó
Ñ%�Tc           @   s�   d  Z  d d l m Z m Z m Z d d l m Z m Z m Z m	 Z	 m
 Z
 m Z m Z d Z d Z d Z d „  Z d	 d „ Z d	 S(
   s6   Functions for building non-bridging phosphoryl oxygensiÿÿÿÿ(   t   radianst   cost   sin(   t   minust   plust   dotProdt	   crossProdt
   scalarProdt	   magnitudet	   normalizegÃõ(\�Â÷?gfffffæ]@il   c         C   s  y" |  d } |  d } | d } Wn t  k
 r6 d	 SXt | | ƒ } t | t | | ƒ ƒ t | t | | ƒ ƒ } t | t | t | | ƒ ƒ ƒ } t | | ƒ } t | t ƒ }	 t t	 d ƒ }
 |	 \ } } } t | ƒ } | \ } } } | | | | | | } i  } xô d |
 f d |
 f f D]Ù \ } } t
 | ƒ } t | ƒ } | | | | | | | | | | | | d } | | | | | | | | | | | | d } | | | | | | | | | | | | d } | | | g | | <q'W| S(
   sX  Calculate non-bridging phosphoryl oxygen coordinates using the coordinates of the current and previous nucleotides
    
    ARGUMENTS:
        curResAtoms - a dictionary of the current nucleotide coordinates (i.e. the nucleotide to build the phosphoryl oxygens on) in the format atomName: [x, y, z]
        prevResAtoms - a dictionary of the previous nucleotide coordinates in the format atomName: [x, y, z]
    RETURNS:
        phosOxyCoords - a dictionary of the phosphoryl oxygen coordinates in the format atomName: [x, y, z]
        or None if the residue is missing the P, O5', or O3' atoms
    t   Ps   O5's   O3'i   t   OP1t   OP2i    i   N(   t   KeyErrort   NoneR   R   R   R   R	   t   PHOSBONDLENGTHR    t   PHOSBONDANGLER   R   (   t   curResAtomst   prevResAtomsR
   t   O5t   O3t   normt   it
   interPointt   PIlinet   scaledPointt   anglet   xt   yt   zt   unitnormt   ut   vt   wt   at   phosOxyCoordst   atomNamet   thetat   cosThetat   sinThetat   newXt   newYt   newZ(    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/buildPhosOxy.pyt   buildPhosOxy   s2    

.!&666c         C   sâ  yE |  d } | d k	 r0 | d } | d } n |  d } |  d } Wn t k
 rY d SXt | | ƒ } t | t ƒ } t t | | ƒ t | | ƒ ƒ } t | ƒ } | \ } } }	 | \ }
 } } t t ƒ } t | ƒ } t	 | ƒ } |
 | | | | |	 } | |
 | | |
 | | |	 | | | | d <| | | | | | | | |
 |	 | | d <| | |	 | | | |
 | | | | | d <t | | ƒ } t | ƒ } | \ } } }	 | \ }
 } } t t
 d ƒ } i  } xô d	 | f d
 | f f D]Ù \ } } t | ƒ } t	 | ƒ } | |
 | | |
 | | |	 | | | | d } | | | | | | | | |
 |	 | | d } | | |	 | | | |
 | | | | | d } | | | g | | <qW| S(   sŠ  build phosphoryl oxygens using only the O3' or O5'atom (intended for the first or last nucleotide of a chain/segment)
    
    ARGUMENTS:
        curResAtoms - a dictionary of the current nucleotide coordinates (i.e. the nucleotide to build the phosphoryl oxygens on) in the format atomName: [x, y, z]
                      this dictionary must contain at least the phosphate
    OPTIONAL ARGUMENTS:
        prevResAtoms - a dictionary of the previous nucleotide coordinates in the format atomName: [x, y, z]
                       if provided, the curResAtoms["P"] and prevResAtoms["O3'"] will be used to place the phosphoryl oxygens
                       if not provided, the curResAtoms["P"] and curResAtoms["O5'"]
    RETURNS:
        phosOxyCoords - a dictionary of the phosphoryl oxygen coordinates in the format atomName: [x, y, z]
        or None if the residue is missing the necessary atoms
    R
   s   O3's   C3's   O5's   C5'i    i   i   R   R   N(   R   R   R   R	   R   R   R    t   INITPHOSANGLER   R   R   (   R   R   R
   t   Ot   Ct   phosOxyR   R   R   R   R   R    R!   R%   R&   R'   R"   R   R#   R$   R(   R)   R*   (    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/buildPhosOxy.pyt   buildInitOrTerminalPhosOxy\   sH    


!222&666N(   t   __doc__t   mathR    R   R   t	   strucCalcR   R   R   R   R   R   R	   R   R   R,   R+   R   R0   (    (    (    sZ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/buildPhosOxy.pyt   <module>   s   4	A