ó
Ñ%�Tc           @   sr   d  Z  d d l m Z m Z m Z m Z m Z m Z d Z d Z	 d Z
 d d d „  ƒ  YZ d d	 „ Z d
 „  Z d S(   sV   The BuildInitSugar class for building sugar coordinates given base and C1' coordinatesiÿÿÿÿ(   t   plust   minust   torsiont   rotateAtomst	   crossProdt	   magnitudeijÿÿÿiF   i«ÿÿÿt   BuildInitSugarc           B   s    e  Z d  Z d „  Z d „  Z RS(   sM   Given base and C1' coordinates, build a ribose sugar in an anti configurationc         C   s’   | |  _  | |  _ t | ƒ |  _ t | ƒ |  _ x[ |  j |  j f D]G } | d } | d =x- | j ƒ  D] \ } } t | | ƒ | | <qg WqC Wd S(   s(  Initialize a BuildInitSugar object.
        
        ARGUMENTS:
            c3pstruc - the filename for a PDB file containing a C3'-endo sugar
            c2pstruc - the filename for a PDB file containing a C2'-endo sugar
        RETURNS:
            an initialized BuildInitSugar object
        s   C1'N(   t   c3pStrucFilenamet   c2pStrucFilenamet   readSugarPDBt   _BuildInitSugar__c3pAtomst   _BuildInitSugar__c2pAtomst	   iteritemsR   (   t   selft   c3pStruct   c2pStruct   curSugart   c1pt   curAtomt	   curCoords(    (    s\   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/buildInitSugar.pyt   __init__   s    
		
c         C   s�  | d k r |  j  } n( | d k r0 |  j } n d t | ƒ ‚ | j d ƒ r^ d } d } n d } d } t | | | d ƒ } | | } t | | ƒ } t | | d | ƒ }	 |	 d	 k pÊ t | ƒ d	 k sâ t | | |	 ƒ } n  t | | | d ƒ }
 t |
 | d	 d	 d	 g | d
 ƒ } t | | | t	 ƒ } | d =| d =t
 g  | j ƒ  D]% \ } } | t | | d ƒ f ^ qOƒ } | S(   sÇ  Build a sugar of the specified pucker onto a base
        
        ARGUMENTS:
            baseAtoms - a dictionary of base atoms in the form atomName:[x, y, z]
                        Note that this dictionary MUST contain the C1' atom
            pucker    - the pucker of the sugar to be built (passed as an integer, either 2 or 3)
        RETURNS:
            coordinates for a sugar of the specified pucker in anti configuration with the base
        i   i   s0   BuildInitSugar called with unrecognized pucker: t   N9t   C4t   N1t   C2s   C1'i    s   O4'(   i    i    i    (   R
   R   t   strt   has_keyR   R   R   R   R   t   STARTING_CHIt   dictR   R    (   R   t	   baseAtomst   puckert
   sugarAtomst   Natomt   Catomt   translatedBaseNt   sugarNt   axist   anglet   translatedBaseCt   curChit   atomt   coords(    (    s\   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/buildInitSugar.pyt
   buildSugar5   s.    	
">(   t   __name__t
   __module__t   __doc__R   R*   (    (    (    s\   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/buildInitSugar.pyR      s   	t   sync         C   s¾   | d k r t  } n | d k r* t } n  t g  |  j ƒ  D]% \ } } | t | | d ƒ f ^ q: ƒ } | j d ƒ r€ d } n d } t | | | d ƒ } t | | | t | d ƒ } | S(   sý  Given a sugar in anti configuration, rotate it to a new configuration (such as syn or high-anti).
    
    ARGUMENTS:
        antiSugarCoords - a dictionary containing a sugar in anti configuration in the format atomName: [x, y, z]
                          typically, this dictionary is generated by a BuildInitSugar object
        atoms           - a dictionary containing base coordinates in the format atomName: [x, y, z]
    OPTIONAL ARGUMENTS:
        newChi          - the chi value to rotate the sugar to
                          may be "syn", "high-anti", or a number (in degrees)
                          defaults to "syn"
    RETURNS:
        synSugarCoords  - a dictionary containing a sugar in syn configuration in the format atomName: [x, y, z]
    R.   s	   high-antis   C1'R   R   (   t   SYN_CHIt   HIGH_ANTI_CHIR   R   R   R   R   R   (   t   antiSugarCoordst   atomst   newChiR(   R)   t   synSugarCoordst   baseNR$   (    (    s\   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/buildInitSugar.pyt   rotateSugaro   s    		>	c         C   s¿   t  |  d ƒ } i  } x™ | D]‘ } | d d !j ƒ  d k r | d d !j ƒ  } t | d d !ƒ } t | d	 d
 !ƒ } t | d d !ƒ } | j d d ƒ | | | f | | <q q W| j ƒ  | S(   s¸   Read in a simple PDB containing the atoms of a sugar ring.
    
    ARGUMENTS:
        filename - the name of the PDB file
    RETURNS:
        a dictionary of atomName: [x, y, z]
    t   ri    i   t   ATOMi   i   i   i'   i&   i/   i.   i7   t   *t   '(   t   opent   stript   floatt   replacet   close(   t   filenamet   inputt   struct   curlinet   atomNamet   xt   yt   z(    (    s\   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/buildInitSugar.pyR	   ’   s    	
N(    (   R-   t	   strucCalcR    R   R   R   R   R   R   R/   R0   R   R6   R	   (    (    (    s\   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/buildInitSugar.pyt   <module>   s   .W#