ó
 xTc           @   sl   d  d l  m Z d  d l m Z d Z d   Z d   Z d d  Z d   Z d	   Z	 d
   Z
 d   Z d S(   i˙˙˙˙(   t   division(   t   cdl_databasei
   c         C   s(   t  |  d  d } | d k r$ d S| S(   Ni
   i´   iL˙˙˙(   t   int(   t   dt   t(    (    sX   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/conformation_dependent_library/utils.pyt   round_to_ten   s     c         C   s   | |  k r |  | | St  |  } xZ t d  D]L } | | d k  rZ | | c d 7<n  | | d k r1 | | c d 8<q1 q1 W|  t |  | S(   Ni   iL˙˙˙ih  iŞ   (   t   listt   ranget   tuple(   t   dbt   keyt   columnt   i(    (    sX   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/conformation_dependent_library/utils.pyt   get_db_result   s      i   c   
      C   sĚ   t  |  t  |  f } g  } g  } xĄ t d d  D] } | j g   | j g   xm t d d  D]\ } | d | t | d | t f }	 | d j t t |  |	 |   | d j |	  qd Wq4 W| S(   Ni˙˙˙˙i   i    i   (   R   R   t   appendt   stepR   R   (
   t   residue_typet   phit   psiR   t   key0t   gridt   indicest   jR   R
   (    (    sX   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/conformation_dependent_library/utils.pyt   get_grid_values   s    $!c         C   sr   t  |   t  |  f } |  d k r1 |  d 8}  n  | d k rJ | d 8} n  |  | d t | | d t f } | S(   Ni´   ih  i    i   (   R   R   (   R   R   R   t   index(    (    sX   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/conformation_dependent_library/utils.pyt	   get_index%   s      c         C   s   d d } | d 7} xK t  d  D]= } x* t  d  D] } | d |  | | 7} q4 W| d 7} q! W| d d 7} | d 7} | GHd  S(   Nt   -i   s   
i   s    %6.2f(   R   (   R   R   R   t   outlR   R   (    (    sX   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/conformation_dependent_library/utils.pyt
   print_grid.   s    


c         C   sp   | | } | | } d d | |  | | d |  d | d | | | |  d | d | | | } | S(   sf   
  http://en.wikipedia.org/wiki/Cubic_Hermite_spline
  http://www.mvps.org/directx/articles/catmull
  g      ŕ?g       @g      @g      @g      @(    (   t   p0t   p1t   p2t   p3R   t   t2t   t3t   result(    (    sX   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/conformation_dependent_library/utils.pyt   interpolate_at_point:   s    

4!c         C   sÍ   | \ } } d | k o# d k n rD d | k o? d k n sJ t   g  } xL t d d  D]; } |  | \ } } } }	 | j t | | | |	 |   q` W| \ } } } }	 t | | | |	 |  }
 |
 S(   s÷   
  Given a 2-dimensional (4x4) grid of values and fractional coordinates,
  compute the value at these coordinates.  Assumes that the grid covers the
  points from -1 to 2 in both dimensions, and the fracional coordinates are
  between 0 and 1.
  i    i   i   (   t   AssertionErrorR   R   R$   (   t   valuest   coordst   xt   yt   pR   R   R   R   R    R#   (    (    sX   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/conformation_dependent_library/utils.pyt   interpolate_2dF   s    >#N(   t
   __future__R    t1   mmtbx.conformation_dependent_library.cdl_databaseR   R   R   R   R   R   R   R$   R+   (    (    (    sX   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/conformation_dependent_library/utils.pyt   <module>   s   							