ó
Ñ%�Tc           @   sY   d  Z  d d l m Z d d l m Z m Z d d l m Z m Z d d d „  ƒ  YZ	 d S(	   s0   Predict rotamers from low resolution informationiÿÿÿÿ(   t   ThetaEtaPredictor(   t
   SmoothProbt   SmoothProbError(   t   rotListt   puckerListFullNamet   PseudoPredictorc        
   B   sS   e  Z d  Z d d d d d d „ Z d d d d d d d d d d „	 Z d „  Z RS(   s0   Predict rotamers from low resolution informationc         C   sà   t  ƒ  } | d =| |  _ d |  _ d |  _ d |  _ d |  _ d |  _ | d k	 rd t | ƒ |  _ n  | d k	 r‚ t	 | ƒ |  _ n  | d k	 r  t	 | ƒ |  _ n  | d k	 r¾ t	 | ƒ |  _ n  | d k	 rÜ t	 | ƒ |  _ n  d S(   sÀ  Create and initialize a PseudoPredictor object
        OPTIONAL ARGUMENTS:
            Note that at least one of these arugments must be provided
            thetaEta        - A file contianing training data for theta eta Gaussian clusters
            pucker          - A file contianing training data for P-perp distances
            sugarDist       - A file contianing training data for sugar-sugar (C1'-C1') distances
            startPhosDist   - A file contianing training data for starting phosphate-phosphate distances
            endPhosDist     - A file contianing training data for ending phosphate-phosphate distances
        RETURNS:
            an initialized PseudoPredictor object
        t   selfN(
   t   localst   _PseudoPredictor__inputFilest   Nonet    _PseudoPredictor__thetaEtaPredict   _PseudoPredictor__puckerPredict!   _PseudoPredictor__sugarDistPredict%   _PseudoPredictor__startPhosDistPredict#   _PseudoPredictor__endPhosDistPredicR    R   (   R   t   thetaEtat   puckert	   sugarDistt   startPhosDistt   endPhosDistt
   inputFiles(    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/pseudoPredictor.pyt   __init__   s$    							c
         C   s”  | d k	 r | \ } } n  d g d \ }
 } } } } } |  j d k	 ry | d k	 ry | d k	 ry |  j j | | ƒ }
 n  |  j d k	 rÇ | d k	 rÇ y |  j j | ƒ } WqÇ t k
 rÃ d } qÇ Xn  |  j d k	 r| d k	 ry |  j j | ƒ } Wqt k
 rd } qXn  |  j d k	 rc| d k	 rcy |  j j | ƒ } Wqct k
 r_d } qcXn  |  j d k	 r±| d k	 r±y |  j j | ƒ } Wq±t k
 r­d } q±Xn  |  j d k	 rÿ|	 d k	 rÿy |  j j |	 ƒ } Wqÿt k
 rûd } qÿXn  i  } xÜ t D]Ô } d } |
 d k	 r5| |
 | 9} n  | d k	 rR| | | 9} n  | d k	 ro| | | 9} n  | d k	 rŒ| | | 9} n  | d k	 r±| | t	 | d 9} n  | d k	 rÖ| | t	 | d 9} n  | | | <qWt
 | j ƒ  ƒ } y9 t g  | j ƒ  D] \ } } | | | f ^ q	ƒ } WnF t k
 rwd t t ƒ } t g  t D] } | | f ^ qYƒ } n X| d k rˆ| S| | Sd S(   sÚ  Calculate the probability of each rotamer for a suite from all given information
        
        OPTIONAL ARGUMENTS:
            rot - which rotamer to return the probability for
                if not provided, a hash of all probabilities is returned
            Note that at least one of the following arugments must be provided:
            thetaEta      - a list of the (theta, eta) coordinates of the suite
            theta         - the theta coordinates of the suite (ignored if thetaEta is given)
            eta           - the eta coordinates of the suite (ignored if thetaEta is given)
            startPperp    - the starting base-phosphate perpendicular (P-perp) distance
            endPperp      - the ending base-phosphate perpendicular (P-perp) distance
            sugarDist     - the C1'-C1' distance for the suite
            startPhosDist - the phosphate-phosphate distance for the starting nucleotide of the suite
            endPhosDist   - the phosphate-phosphate distance for the ending nucleotide of the suite
        RETURNS:
            if rot is given, returns the probability that the described suite is of rotamer rot
            if rot is not given, returns a hash in the form rotamer => probability
        i   i   i    g      ð?N(   R	   R
   t   calcProbR   R   R   R   R   R   t
   puckerListt   sumt   valuest   dictt	   iteritemst   ZeroDivisionErrort   len(   R   t   rotR   t   thetat   etat
   startPperpt   endPperpR   R   R   t   thetaEtaProbst   startPuckerProbst   endPuckerProbst   sugarDistProbst   startPhosDistProbst   endPhosDistProbst   probst   currott   curprobt	   totalProbt	   equalProb(    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/pseudoPredictor.pyR   @   sn    '      9)c         C   sE   |  j  d k r d S|  j  j | ƒ } | d | d k r= d Sd Sd S(   s"  Calculate the most likely pucker of a sugar given only the base-phosphate perpendicular distance
        
        ARGUMENTS:
            pperp - the base-phosphate perpendicular (P-perp) distance
        RETURNS:
            3 if a C3'-endo sugar pucker is more likely, 2 otherwise
        s   C3's   C2'i   i   N(   R   R	   R   (   R   t   pperpt   puckerProbs(    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/pseudoPredictor.pyt
   calcPuckerŸ   s    	N(   t   __name__t
   __module__t   __doc__R	   R   R   R0   (    (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/pseudoPredictor.pyR      s   '$_N(    (
   R3   t   thetaEtaPredictorR    t
   smoothProbR   R   R   R   R   R   (    (    (    s]   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/python2.7/site-packages/coot/rcrane/pseudoPredictor.pyt   <module>   s   