ó
Ì™xTc           @   s›  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 d „ Z d d	 „ Z d d
 „ Z d d „ Z d d „ Z d d „ Z d d „ Z d d „ Z d d „ Z e d e f d e f d e f d e f d e f d e f d e f d e f d e f g	 ƒ Z d „  Z d „  Z d „  Z d „  Z d „  Z d  „  Z d! „  Z d" „  Z d# „  Z d$ „  Z d% „  Z d& „  Z  d' „  Z! d( „  Z" d) „  Z# d* „  Z$ d+ „  Z% d, „  Z& d- „  Z' d. „  Z( d/ „  Z) d0 „  Z* d1 „  Z+ d2 „  Z, d3 „  Z- d4 „  Z. d5 „  Z/ d6 „  Z0 e d7 d8 e0 d f d9 e d f g f d: d; e d f d< e d f d= e d f d> e/ d f g f d? d@ e d f dA e d f dB e! d f g f dC dD e d f d e  d f dE e" d f dF e$ e% e& g d f g f dG dH e# d f dI e' d f g f dJ dK e( d f dL e) e* e+ g d f g f dM dN e. d f g f g ƒ Z1 g  e1 j2 ƒ  D] Z3 e3 D] Z4 e4 dO ^ qfq\Z5 dP „  Z6 e7 dQ dR „ Z8 dS S(T   s   
This module provides tools for examining a set of vectors and find the geometry
that best fits from a set of built in shapes.
iÿÿÿÿ(   t   division(   t   col(   t   OrderedDictt   Iterable(   t   sqrtc      	   C   sP   g  t  |  ƒ D]? \ } } |  | d D]$ } | | | j | d t ƒf ^ q% q S(   s¼   
  Creates a list of angles (In degrees) between all two-element combinations
  in vectors.

  Parameters
  ----------
  vectors : scitbx.matrix.col

  Returns
  -------
  list of float
  i   t   deg(   t	   enumeratet   anglet   True(   t   vectorst   indext   v1t   v2(    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyt   _bond_angles   s    i   c         C   s~   t  |  ƒ d k s$ t  |  ƒ d k  r( d St |  ƒ } t t d „  | Dƒ ƒ t  |  ƒ ƒ } | | k rz | d t  |  ƒ f Sd S(   sê   
  Tetrahedrons have four vertices, with angles between all pairs of vertices
  uniformly about 104.5 degrees.

  Parameters
  ----------
  vectors : list scitbx.matrix.col
  dev_cutoff : float, optional

  Returns
  -------
  bool
  i   i   Nc         s   s'   |  ] } t  | d  d ƒ d  Vq d S(   i   g      Z@N(   t   abs(   t   .0t   i(    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pys	   <genexpr>2   s    (   t   lenR   R   t   sum(   R	   t
   dev_cutofft   anglest	   deviation(    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyt   _is_tetrahedron   s    $&c         C   s˜   t  |  ƒ d k r d St |  ƒ } g  } x# | D] } | j | d d ƒ q/ Wt t d „  | Dƒ ƒ t  | ƒ ƒ } | | k r” | d t  |  ƒ f Sd S(   s$  
  Triangular planar geometry has three vertices (By definition all on the same
  equatorial plane). The expected angles are 120 degrees between neighboring
  vertices.

  Parameters
  ----------
  vectors : list scitbx.matrix.col
  dev_cutoff : float, optional

  Returns
  -------
  bool
  i   Ni   ix   c         s   s   |  ] } | d  Vq d S(   i   N(    (   R   R   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pys	   <genexpr>O   s    (   R   R   t   appendR   R   (   R	   R   R   t   a_120sR   R   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyt   _is_trigonal_plane7   s    &c         C   s.  t  |  ƒ d k r d St |  ƒ } g  } g  } xc | D][ } t | d d ƒ t | d d ƒ k  r{ | j | d d ƒ q5 | j | d d ƒ q5 Wt  | ƒ d k  sÜ t  | ƒ d k sÜ t  | ƒ d k  sÜ t  | ƒ d k rà d St t d „  | | Dƒ ƒ t  | ƒ ƒ } | | k r*| d t  |  ƒ f Sd S(   sH  
  Square planar geometry has four vertices, all on the same equatorial plane.
  The expected angles are 90 degrees between neighboring vertices and 180
  degrees between vertices across from one another.

  Parameters
  ----------
  vectors : list scitbx.matrix.col
  dev_cutoff : float, optional

  Returns
  -------
  bool
  i   Ni   iZ   i´   i   c         s   s   |  ] } | d  Vq d S(   i   N(    (   R   R   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pys	   <genexpr>x   s    (   R   R   R   R   R   R   (   R	   R   R   t   a_90st   a_180sR   R   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyt   _is_square_planeT   s    (H*c         C   s  t  |  ƒ d k r d St |  ƒ } g  g  } } xc | D][ } t | d d ƒ t | d d ƒ k  r| | j | d d ƒ q6 | j | d d ƒ q6 Wt  | ƒ d k s¹ t  | ƒ d k r½ d St t d „  | | Dƒ ƒ t  | ƒ ƒ } | | k r| d t  |  ƒ f Sd S(   s  
  Square bipyramids have five vertices, four on the same equatorial plane with
  one above. The expected angles are all either 90 degrees or 180 degrees.

  Parameters
  ----------
  vectors : list scitbx.matrix.col
  dev_cutoff : float, optional

  Returns
  -------
  bool
  i   Ni   iZ   i´   i   c         s   s   |  ] } | d  Vq d S(   i   N(    (   R   R   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pys	   <genexpr>š   s    (   R   R   R   R   R   R   (   R	   R   R   R   R   R   R   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyt   _is_square_pyramid}   s    ($*c         C   s/  t  |  ƒ d k r d St |  ƒ } g  g  } } xc | D][ } t | d d ƒ t | d d ƒ k  r| | j | d d ƒ q6 | j | d d ƒ q6 Wt  | ƒ d k sÝ t  | ƒ d k  sÝ t  | ƒ d k  sÝ t  | ƒ d	 k rá d St t d
 „  | | Dƒ ƒ t  | ƒ ƒ } | | k r+| d t  |  ƒ f Sd S(   sn  
  Octahedrons have six vertices (Their name comes from their eight faces).
  The expected angles are all either 90 degrees (Next to each other),
  or 180 degrees (Across from each other).

  Another name for this shape is square bipyramidal.

  Parameters
  ----------
  vectors : list scitbx.matrix.col
  dev_cutoff : float, optional

  Returns
  -------
  bool
  i   NiÿÿÿÿiZ   i´   i   i   i   i   c         s   s   |  ] } | d  Vq d S(   i   N(    (   R   R   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pys	   <genexpr>¿   s    (   R   R   R   R   R   R   (   R	   R   R   R   R   R   R   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyt   _is_octahedronŸ   s    (H*i   c         C   s/  t  |  ƒ d k r d St |  ƒ } g  g  } } xc | D][ } t | d d ƒ t | d d ƒ k  r| | j | d d ƒ q6 | j | d d ƒ q6 Wt  | ƒ d k  sÝ t  | ƒ d k sÝ t  | ƒ d k  sÝ t  | ƒ d k rá d St t d „  | | Dƒ ƒ t  | ƒ ƒ } | | k r+| d t  |  ƒ f Sd S(   sR  
  Trigional pyramids have four vertices. Three vertices form a plane with
  angles of 120 degrees between each pair. The last vertex resides axial
  to the plane, at 90 degrees from all of the equatorial vertices.

  Parameters
  ----------
  vectors : list scitbx.matrix.col
  dev_cutoff : float, optional

  Returns
  -------
  bool
  i   Ni   iZ   ix   c         s   s   |  ] } | d  Vq d S(   i   N(    (   R   R   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pys	   <genexpr>â   s    (   R   R   R   R   R   R   (   R	   R   R   R   R   R   R   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyt   _is_trigonal_pyramidÄ   s    (H*c         C   s‰  t  |  ƒ d k s$ t  |  ƒ d k  r( d St |  ƒ } t | d d „  ƒ\ } } } | d k  rb d Sg  } g  } x | D]w \ } }	 }
 | | | g k |	 | | g k k r¸ | |
 f 7} qu | | | g k ru |	 | | g k ru | |
 f 7} qu qu W| d g } | g  | D] } | d ^ q7} | g  | D] } | d	 ^ q(7} t t d
 „  | Dƒ ƒ t  | ƒ ƒ } | | k r…| d t  |  ƒ f Sd S(   sj  
  Trigonal bipyramids have five vertices. Three vertices form a plane in the
  middle and the angles between all three are 120 degrees. The two other
  vertices reside axial to the plane, at 90 degrees from all the equatorial
  vertices.

  Parameters
  ----------
  vectors : list scitbx.matrix.col
  dev_cutoff : float, optional

  Returns
  -------
  bool
  i   i   Nt   keyc         S   s   t  |  d ƒ S(   Niÿÿÿÿ(   R   (   t   x(    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyt   <lambda>ý   s    i–   i´   iZ   ix   c         s   s   |  ] } | d  Vq d S(   i   N(    (   R   R   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pys	   <genexpr>  s    (   R   R   t   maxR   R   (   R	   R   R   t   ax1t   ax2t   axial_anglet   base_to_axialst   equatorial_anglesR   R   R   t   deviantsR   R   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyt   _is_trigonal_bipyramidç   s&    $$$!!&c         C   s–  t  |  ƒ d k s$ t  |  ƒ d k  r( d St |  ƒ } g  } xâ |  D]Ú } g  } x9 |  D]1 } | | k rT | j | j | d t ƒƒ qT qT Wt  g  | D]" } t | d ƒ d k  r“ | ^ q“ ƒ } t  g  | D]" } t | d ƒ d k  rÈ | ^ qÈ ƒ }	 | d k rA |	 d	 k rA | j | ƒ qA qA Wt  | ƒ d
 k r5d S| \ }
 } |
 j | d t ƒ} g  } g  } x | D]w \ } } } | |
 | g k | |
 | g k k r¬| | f 7} qi| |
 | g k ri| |
 | g k ri| | f 7} qiqiW| d g } | g  | D] } | d ^ qû7} | g  | D]) } t t | d ƒ t | d ƒ ƒ ^ q7} t t d „  | Dƒ ƒ t  | ƒ ƒ } | | k r’| d t  |  ƒ f Sd S(   sh  
  Pentagonal bipyramids have seven vertices. Five vertices form a plane in the
  middle and the angles between all five are 72 degrees. The two other vertices
  reside axial to the plane, at 90 degrees from all the equatorial vertices.

  Parameters
  ----------
  vectors : list scitbx.matrix.col
  dev_cutoff : float, optional

  Returns
  -------
  bool
  i   i   NR   i´   i   iZ   i    i   i   iH   i�   c         s   s   |  ] } | d  Vq d S(   i   N(    (   R   R   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pys	   <genexpr>M  s    (	   R   R   R   R   R   R   t   minR   R   (   R	   R   R   t   axialsR   t   v_anglesR   R   R   R   R$   R%   R&   R'   R(   R   R)   R   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyt   _is_pentagonal_bipyramid  s<    $#55$$!:&c         C   s  t  |  ƒ d k r d St |  ƒ } g  g  } } xc | D][ } t | d d ƒ t | d d ƒ k  r| | j | d d ƒ q6 | j | d d ƒ q6 Wt  | ƒ d k r½ t  | ƒ d k r½ d St t d „  | | Dƒ ƒ t  | ƒ ƒ } | | k  r| d t  |  ƒ f Sd S(   s�  
  Triangular prisms are defined by 3 vertices in a triangular pattern on two
  aligned planes. Unfortunately, the angles are dependent on the length and
  width of the prism. Need more examples to come up with a better way of
  detecting this shape.

  For now, this code is experimental.

  Parameters
  ----------
  vectors : list scitbx.matrix.col
  dev_cutoff : float, optional

  Returns
  -------
  bool
  i   NiÿÿÿÿiU   i‡   i	   c         s   s   |  ] } | d  Vq d S(   i   N(    (   R   R   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pys	   <genexpr>s  s    (   R   R   R   R   R   R   (   R	   R   R   t   a_85st   a_135sR   R   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyt   _is_trigonal_prismR  s    ($*t   tetrahedralt   trigonal_planart   square_planart   square_pyramidalt
   octahedralt   trigonal_pyramidalt   trigonal_bipyramidalt   pentagonal_bipyramidalt   trigonal_prismc          G   sX   g  } xK |  D]C } t  | t ƒ rC x+ | D] } | j | ƒ q) Wq | j | ƒ q W| S(   s²   
  Reduces a list of a mixture of elements and lists down to a single list.

  Parameters
  ----------
  args : tuple of (object or list of object)

  Returns
  -------
  list
  (   t
   isinstancet   listR   (   t   argst   lstt   argt   elem(    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyt   _concatenate„  s    c           C   sL   t  d d d g ƒ t  d d d g ƒ t  d d d g ƒ t  d d d g ƒ g S(   s3   
  Returns
  -------
  list of scitbx.matrix.col
  i   iÿÿÿÿ(   R   (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyt   _tetrahedron™  s    c           C   s   t  t ƒ  ƒ S(   s3   
  Returns
  -------
  list of scitbx.matrix.col
  (   t
   _bipyramidt   _square_plane(    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyt   _octahedron¦  s    c           C   sO   t  d d d g ƒ t  t d ƒ d d d g ƒ t  t d ƒ d d d g ƒ g S(   s3   
  Returns
  -------
  list of scitbx.matrix.col
  i    i   i   i   iÿÿÿÿg      à¿g      à¿(   R   R   (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyt   _trigonal_plane®  s    c           C   sL   t  d d d g ƒ t  d d d g ƒ t  d d d g ƒ t  d d d g ƒ g S(   s3   
  Returns
  -------
  list of scitbx.matrix.col
  i    i   iÿÿÿÿ(   R   (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyRD   º  s    c         C   s   t  |  t d d d g ƒ ƒ S(   s3   
  Returns
  -------
  list of scitbx.matrix.col
  i    i   (   RA   R   (   t   base(    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyt   _pyramidÇ  s    c         C   s.   t  |  t d d d g ƒ t d d d g ƒ ƒ S(   s3   
  Returns
  -------
  list of scitbx.matrix.col
  i    i   iÿÿÿÿ(   RA   R   (   RG   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyRC   Ï  s    c           C   s   t  t ƒ  ƒ S(   s3   
  Returns
  -------
  list of scitbx.matrix.col
  (   RH   RD   (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyt   _square_pyramid×  s    c           C   s   t  t ƒ  ƒ S(   s3   
  Returns
  -------
  list of scitbx.matrix.col
  (   RC   RD   (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyt   _square_bipyramidß  s    c           C   s   t  t ƒ  ƒ S(   s3   
  Returns
  -------
  list of scitbx.matrix.col
  (   RH   RF   (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyt   _trigonal_pyramidç  s    c           C   s   t  t ƒ  ƒ S(   s3   
  Returns
  -------
  list of scitbx.matrix.col
  (   RC   RF   (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyt   _trigonal_bipyramidï  s    c       	   C   s_   t  g  t ƒ  D] }  |  t d d d g ƒ ^ q g  t ƒ  D] }  |  t d d d g ƒ ^ q9 ƒ S(   s3   
  Returns
  -------
  list of scitbx.matrix.col
  i    i   iÿÿÿÿ(   RA   RF   R   (   R   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyt   _trigonal_prism÷  s    ,c          C   sÆ   t  d ƒ d d }  t  d ƒ d d } t  d d t  d ƒ ƒ d } t  d d t  d ƒ ƒ d } t d d d g ƒ t |  | d g ƒ t | | d g ƒ t | | d g ƒ t |  | d g ƒ g S(   s¶   
  Create a list of vectors in the shape of a planar pentagon.

  Returns
  -------
  list of scitbx.matrix.col

  See Also
  --------
  http://mathworld.wolfram.com/Pentagon.html
  i   i   i   i
   i   i    (   R   R   (   t   c_1t   c_2t   s_1t   s_2(    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyt	   _pentagon  s    c           C   s   t  t ƒ  ƒ S(   s3   
  Returns
  -------
  list of scitbx.matrix.col
  (   RH   RR   (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyt   _pentagonal_pyramid  s    c           C   s   t  t ƒ  ƒ S(   sX   
  Creates a square bipyramid shape.

  Returns
  -------
  list of scitbx.matrix.col
  (   RC   RR   (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyt   _pentagonal_bipyramid#  s    c           C   s[   t  t ƒ  t t d ƒ d t d ƒ d d g ƒ t t d ƒ d t d ƒ d d g ƒ ƒ S(   sº   
  Creates a square pyramid shape with one vertex replaced with a bidentate
  coordination group. One vertex is missing in this shape.

  Returns
  -------
  list of scitbx.matrix.col
  i   iÿÿÿÿ(   RA   RD   R   R   (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyt    _square_pyramid_bidentate_miss_1-  s    	&c        	   C   sš   t  d d d g ƒ t  d d d g ƒ t  d d d g ƒ t  d d d g ƒ t  t d ƒ d t d ƒ d d g ƒ t  t d ƒ d t d ƒ d d g ƒ g S(   sº   
  Creates a square pyramid shape with one vertex replaced with a bidentate
  coordination group. One vertex is missing in this shape.

  Returns
  -------
  list of scitbx.matrix.col
  i    i   iÿÿÿÿi   (   R   R   (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyt    _square_pyramid_bidentate_miss_2<  s    
&c        	   C   sš   t  d d d g ƒ t  d d d g ƒ t  d d d g ƒ t  d d d g ƒ t  t d ƒ d t d ƒ d d g ƒ t  t d ƒ d t d ƒ d d g ƒ g S(   sº   
  Creates a square pyramid shape with one vertex replaced with a bidentate
  coordination group. One vertex is missing in this shape.

  Returns
  -------
  list of scitbx.matrix.col
  i    i   iÿÿÿÿi   (   R   R   (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyt    _square_pyramid_bidentate_miss_3N  s    
&c           C   s[   t  t ƒ  t t d ƒ d t d ƒ d d g ƒ t t d ƒ d t d ƒ d d g ƒ ƒ S(   s•   
  Creates a square pyramid shape with one vertex replaced with a bidentate
  coordination group.

  Returns
  -------
  list of scitbx.matrix.col
  i   iÿÿÿÿ(   RA   RI   R   R   (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyt   _square_pyramid_bidentate`  s    	&c           C   s[   t  t ƒ  t t d ƒ d t d ƒ d d g ƒ t t d ƒ d t d ƒ d d g ƒ ƒ S(   s™   
  Creates a pentagonal pyramid shape with one vertex replaced with a bidentate
  coordination group.

  Returns
  -------
  list of scitbx.matrix.col
  i   iÿÿÿÿ(   RA   RS   R   R   (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyt   _pentagonal_pyramid_bidentateo  s    	&c           C   s­   t  t t d ƒ d t d ƒ d d g ƒ t t d ƒ d t d ƒ d d g ƒ t t d ƒ d t d ƒ d d g ƒ t t d ƒ d t d ƒ d d g ƒ t ƒ  d  Œ S(   sº   
  A planar pentagon with bidentate atoms coordinating directly above and
  below. One vertex from the plane is missing in this shape.

  Returns
  -------
  list of scitbx.matrix.col
  i   i   iÿÿÿÿ(   RA   R   R   RR   (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyt   _pentagonal_bibidentate_miss_1~  s    	&(&(c           C   s­   t  t t d ƒ d t d ƒ d d g ƒ t t d ƒ d t d ƒ d d g ƒ t t d ƒ d t d ƒ d d g ƒ t t d ƒ d t d ƒ d d g ƒ t ƒ  d Œ S(   sº   
  A planar pentagon with bidentate atoms coordinating directly above and
  below. One vertex from the plane is missing in this shape.

  Returns
  -------
  list of scitbx.matrix.col
  i   i   iÿÿÿÿ(   RA   R   R   RR   (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyt   _pentagonal_bibidentate_miss_2�  s    	&(&(c       
   C   sÈ   t  ƒ  }  t t t d ƒ d t d ƒ d d g ƒ t t d ƒ d t d ƒ d d g ƒ t t d ƒ d t d ƒ d d g ƒ t t d ƒ d t d ƒ d d g ƒ |  d |  d |  d |  d ƒ S(   sº   
  A planar pentagon with bidentate atoms coordinating directly above and
  below. One vertex from the plane is missing in this shape.

  Returns
  -------
  list of scitbx.matrix.col
  i   i   iÿÿÿÿi    i   i   (   RR   RA   R   R   (   t   pentagon(    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyt   _pentagonal_bibidentate_miss_3   s    		&(&(c           C   sƒ   t  t ƒ  t t d ƒ d t d ƒ d d g ƒ t t d ƒ d t d ƒ d d g ƒ t t d ƒ d t d ƒ d d g ƒ ƒ S(   sÈ   
  A planar pentagon with bidentate atoms coordinating directly above and
  below. One vertex from a bidentate coordinator is missing in this shape.

  Returns
  -------
  list of scitbx.matrix.col
  i   i   iÿÿÿÿ(   RA   RR   R   R   (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyt   _pentagonal_bibidentate_miss_4µ  s
    	&(c           C   s�   t  t ƒ  t t d ƒ d t d ƒ d d g ƒ t t d ƒ d t d ƒ d d g ƒ t t d ƒ d t d ƒ d d g ƒ ƒ S(   sÈ   
  A planar pentagon with bidentate atoms coordinating directly above and
  below. One vertex from a bidentate coordinator is missing in this shape.

  Returns
  -------
  list of scitbx.matrix.col
  i   i   iÿÿÿÿ(   RA   RR   R   R   (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyt   _pentagonal_bibidentate_miss_5Å  s
    	&(c        	   C   s©   t  t ƒ  t t d ƒ d t d ƒ d d g ƒ t t d ƒ d t d ƒ d d g ƒ t t d ƒ d t d ƒ d d g ƒ t t d ƒ d t d ƒ d d g ƒ ƒ S(   s„   
  A planar pentagon with bidentate atoms coordinating directly above and below.

  Returns
  -------
  list of scitbx.matrix.col
  i   i   iÿÿÿÿ(   RA   RR   R   R   (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyt   _pentagonal_bibidentateÕ  s    &(&c           C   sL   t  d d d g ƒ t  d d d g ƒ t  d d d g ƒ t  d d d g ƒ g S(   sa   
  An octahedron missing two adjacent points.

  Returns
  -------
  list of scitbx.matrix.col
  i   i    iÿÿÿÿ(   R   (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyt   _see_sawå  s    	c           C   s:   t  d d d g ƒ t  d d d g ƒ t  d d d g ƒ g S(   s‰   
  Better name? Imagine 3 orthogonal vectors pointed in the x, y, and z
  directions.

  Returns
  -------
  list of scitbx.matrix.col
  i   i    (   R   (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyt   _three_legsô  s    
i   t
   three_legst   trigonal_planei   t   tetrahedront   square_planet   trigonal_pyramidt   see_sawi   t   square_pyramidt   trigonal_bipyramidR\   i   t
   octahedront   pentagonal_pyramidt   square_pyramid_bidentate_missi   t   pentagonal_bipyramidt   square_pyramid_bidentatei   t   pentagonal_pyramid_bidentatet   pentagonal_bibidentate_missi	   t   pentagonal_bibidentatei    c         C   s÷   t  |  ƒ t  | ƒ k s t ‚ g  t |  ƒ D]6 \ } } |  | d D] } | j | d t ƒ^ qC q+ } g  t | ƒ D]6 \ } } | | d D] } | j | d t ƒ^ qŒ qt } | j ƒ  | j ƒ  t t d „  t | | ƒ Dƒ ƒ t  | ƒ ƒ } | S(   sñ   
  Calculates the root mean square of the angle deviation (in degrees) between
  two lists of vectors.

  Parameters
  ----------
  vectors_a : list of scitbx.matrix.col
  vectors_b : list of scitbx.matrix.col

  Returns
  -------
  float
  i   R   c         s   s#   |  ] \ } } | | d  Vq d S(   i   N(    (   R   R   t   j(    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pys	   <genexpr>H  s    (	   R   t   AssertionErrorR   R   R   t   sortR   R   t   zip(   t	   vectors_at	   vectors_bR
   t   vect   vec_ot   angles_at   angles_bt   angle_deviation(    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyt   _angles_deviation-  s    00

g333333@c            sº  g  } xN t  |  ƒ D]@ \ } ‰  t ‡  f d †  |  | d Dƒ ƒ r | j ˆ  ƒ q q Wg  ‰ x3 | D]+ ‰  ˆ  j ƒ  | k  rd ˆ j ˆ  j ƒ qd qd Wg  } | rgt ˆ ƒ } | t k r» | Sx} t | D]q \ } } }	 t | t ƒ rt	 ‡ f d †  | Dƒ ƒ }
 n t
 ˆ | ƒ  ƒ }
 |
 |	 k  rÆ | j | |
 f ƒ qÆ qÆ W| r¶| j d d „  ƒ | d g } q¶nO xL t j ƒ  D]> \ } } | ˆ ƒ } | rt| d } | j | | f ƒ qtqtW| S(   s2  
  Searches through a list of geometries to find those that fit nearby_atom.

  Geometries are recognized by generating a list of all combinations of angles
  between the vectors and comparing them against the angles among the vectors
  of the ideal geometry.

  Parameters
  ----------
  nearby_atoms: list of mmtbx.ions.environment.atom_contact
      A list of atom contacts, indicating the vertices of the shape to be
      recognized.
  minimizer_method: bool, optional
      Optional parameter to use the new, more efficient version of geometry
      recognition. The old method will be depreciated in later versions of
      cctbx.
  cutoff: float, optional
      A cutoff distance, past which vectors are not included in geometry
      calculations.

  Returns
  -------
  list of tuples of str, float
      A list of found geometries. Each tuple contains the name of the geometry
      in string form followed by the deviation from ideal angles.

  See Also
  --------
  mmtbx.ions.geometry.SUPPORTED_GEOMETRY_NAMES,
  mmtbx.ions.geometry.SUPPORTED_GEOMETRIES_OLD
  c         3   s$   |  ] } ˆ  j  | ƒ d  k Vq d S(   g      à?N(   t   distance_from(   R   t   other(   t   contact(    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pys	   <genexpr>s  s   i   c         3   s!   |  ] } t  ˆ  | ƒ  ƒ Vq d  S(   N(   R~   (   R   R   (   t   filtered(    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pys	   <genexpr>†  s    R    c         S   s   |  d S(   Niÿÿÿÿ(    (   R!   (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyR"   Ž  s    i    (   R   t   allR   t   distancet   vectorR   t   SUPPORTED_GEOMETRIESR;   R   R+   R~   Ru   t   SUPPORTED_GEOMETRIES_OLDt   items(   t   nearby_atomst   minimizer_methodt   cutofft   non_overlappingR
   t
   geometriest	   n_vectorst   namet   funct   rmsa_cutofft   rmsat   valR   (    (   R�   R‚   sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyt   find_coordination_geometryM  s:    $
N(9   t   __doc__t
   __future__R    t   scitbx.matrixR   t   collectionsR   R   t   mathR   R   R   R   R   R   R   R   R*   R.   R1   R‡   RA   RB   RE   RF   RD   RH   RC   RI   RJ   RK   RL   RM   RR   RS   RT   RU   RV   RW   RX   RY   RZ   R[   R]   R^   R_   R`   Ra   Rb   R†   t   valuest   valst   lst_it   SUPPORTED_GEOMETRY_NAMESR~   t   FalseR”   (    (    (    sA   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/ions/geometry.pyt   <module>   s¬   	)"%#/<&																							
													0	 