ó
BxTc           @   sK  d  d l  m Z d  d l Z d  d l Z d  d l Z e j j	 d  Z
 d  d l Td  d l m Z d  d l Z d e
 j f d     YZ d e
 j j j _ d	 e
 j j j _ d
 e
 j j j _ d e
 j j j _ d e
 j j j _ d e j j e
 j f d     YZ d d  Z d d d d d d d  Z d e f d     YZ d   Z d S(   i’’’’(   t   divisionNt   cctbx_uctbx_ext(   t   *(   t   matrixt	   unit_cellc           B   s    e  Z d  Z d d d d  Z RS(   s  
  Class for the handling of unit cell information.

  All angles are in degrees.

  The PDB convention for orthogonalization and fractionalization
  of coordinates is used:

  | Crystallographic Basis: D = {a,b,c}
  | Cartesian Basis:        C = {i,j,k}
  | i parallel to a
  | j is in (a,b) plane
  | k = i x j

  :param parameters: A list, tuple or string of unit cell parameters.
  :param metrical_matrix: Metrical matrix. See also
                          :py:meth:`metrical_matrix`.
  :param orthogonalization_matrix: Orthogonalization matrix. See also
                          :py:meth:`orthogonalization_matrix`.

  :returns: None
  :rtype: None
  c         C   sš   | | | g j  d   d k s$ t  | d  k	 r t | t  rs g  | j d d  j   D] } t |  ^ qX } n  t j	 j
 |  d | n` | d  k	 r± t j	 j
 |  d | n; | d  k	 rÖ t j	 j
 |  d | n t j	 j
 |  d g  d  S(   Ni   t   ,t    t
   parameterst   metrical_matrixt   orthogonalization_matrix(   t   countt   Nonet   AssertionErrort
   isinstancet   strt   replacet   splitt   floatt   extR   t   __init__(   t   selfR   R   R	   t   p(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/__init__.pyR   %   s    $4


N(   t   __name__t
   __module__t   __doc__R   R   (    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/__init__.pyR      s   s?  
Access to the metrical matrix:

.. math::
   \begin{pmatrix}
     a^2                & a b \cos(\gamma) & a c \cos(\beta)  \\
     a b \cos(\gamma) & b^2                & b c \cos(\alpha) \\
     a c \cos(\beta)  & b c \cos(\alpha) & c^2                \\
   \end{pmatrix}

:returns: the metrical matrix
:rtype: tuple
sŠ   
Matrix for the conversion of fractional to Cartesian coordinates:

.. math::
  \mathbf{x}_\textrm{Cartesian} = \mathbf{O} \mathbf{x}_\textrm{fractional}

:returns: the orthogonalization matrix
:rtype: tuple
sŠ   
Matrix for the conversion of fractional to Cartesian coordinates:

.. math::
  \mathbf{x}_\textrm{fractional} = \mathbf{F} \mathbf{x}_\textrm{Cartesian}

:returns: the fractionalization matrix
:rtype: tuple
s:  
Conversion of fractional coordinates to Cartesian coordinates.

:param sites_frac: The fractional coordinates.
                   Either coordinates for a single site (3-tuple) or a
                   flex.vec3_double array of coordinates.

:returns: the Cartesian coordinates
:rtype: 3-tuple or flex.vec3_double
s:  
Conversion of Cartesian coordinates to fractional coordinates.

:param sites_cart: The Cartesian coordinates.
                   Either coordinates for a single site (3-tuple) or a
                   flex.vec3_double array of coordinates.

:returns: the fractional coordinates
:rtype: 3-tuple or flex.vec3_double
t   _c           B   s  e  Z d    Z d d d  Z d d d  Z d d d  Z d   Z d d d d  Z d d d d  Z	 d d	  Z
 d d
  Z d d d  Z d d d  Z d d d  Z d e d  Z d d  Z d   Z d d d d  Z d d d d d d d d d e d 
 Z e Z RS(   c         C   s   d |  j    S(   Ns$   (%.6g, %.6g, %.6g, %.6g, %.6g, %.6g)(   R   (   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/__init__.pyt   __str__s   s    s   Unit cell: c         C   s0   | d  k r t j } n  | | t |   IJd  S(   N(   R   t   syst   stdoutR   (   R   t   ft   prefix(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/__init__.pyt   show_parametersv   s     gü©ńŅMbP?c         C   s   |  j    } t | d | d  | k r. t Sd d d g } x= d d d g D], } t | | | | d  | k rM t SqM Wt S(   Ni    i   iZ   ix   i   i   i   (   R   t   abst   Falset   True(   R   t   absolute_length_tolerancet   absolute_angle_toleranceR   t   ideal_anglest   i(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/__init__.pyt   is_conventional_hexagonal_basisz   s    "c         C   s   |  j    } x6 d d g D]( } t | d | |  | k r t Sq Wx6 d d g D]( } t | d | |  | k rR t SqR Wt S(   Ni   i   i    i   i   i   (   R   R    R!   R"   (   R   R#   R$   R   t   j(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/__init__.pyt"   is_conventional_rhombohedral_basis   s    c         C   s   t  d |  d | d |  S(   NR   t   site_frac_1t   site_frac_2(   t   distance_mod_1(   R   R*   R+   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/__init__.pyR,      s    c         C   sR   | d  k r d } n  | d  k r* d } n  | d  k r? d } n  t |  | | |  S(   Nid   i   i   (   R   t   fast_minimum_reduction(   R   t   iteration_limitt"   multiplier_significant_change_testt   min_n_no_significant_change(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/__init__.pyt   minimum_reduction   s    			c         C   s   |  j  | | |  j   S(   N(   R1   t   as_unit_cell(   R   R.   R/   R0   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/__init__.pyt   minimum_cell¤   s    c         C   s#   d d l  m } | |  |  j   S(   Ni’’’’(   t   gruber_parameterization(   t   cctbx.uctbx.reduction_baseR4   t   is_buerger_cell(   R   t   relative_epsilonR4   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/__init__.pyR6   ¬   s    c         C   s#   d d l  m } | |  |  j   S(   Ni’’’’(   R4   (   R5   R4   t   is_niggli_cell(   R   R7   R4   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/__init__.pyR8   °   s    c         C   s#   d d l  m } | j |  | |  S(   Ni’’’’(   t   krivy_gruber_1976(   t   cctbx.uctbxR9   t	   reduction(   R   R7   R.   R9   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/__init__.pyt   niggli_reduction“   s    c         C   s   |  j  | |  j   S(   N(   R<   R2   (   R   R7   R.   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/__init__.pyt   niggli_cellø   s    c         C   s   |  j  | |  j   S(   N(   R<   t   change_of_basis_op(   R   R7   R.   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/__init__.pyt!   change_of_basis_op_to_niggli_cell¾   s    i   c         C   s,   d d l  m } | j d |  d | d |  S(   Ni’’’’(   t   sgtbxt   reduced_cellt	   max_deltat)   enforce_max_delta_for_generated_two_folds(   t   cctbxR@   t   lattice_symmetry_group(   R   RB   RC   R@   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/__init__.pyRE   Ä   s
    	c         C   s   |  j    } |  j |  } | j d |  } d d l m } | j d | d | j    } d d l m }	 |	 j d | d | d	 |  }
 |
 j | j	    S(
   NRB   i’’’’(   t   crystalR   t   space_group_info(   t   millert   crystal_symmetryt   anomalous_flagt   d_min(
   R?   t   change_basisRE   RD   RF   t   symmetryt   infoRH   t	   build_sett   inverse(   R   RJ   RK   t   lattice_symmetry_max_deltat   cb_opR=   t   lattice_groupRF   t   niggli_lattice_symmetryRH   t   niggli_lattice_set(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/__init__.pyt)   complete_miller_set_with_lattice_symmetryĪ   s    					c         C   sr   d d l  m } | j d |  d g  d	 d
 d g D] } | j d | d d  ^ q/  j d t |   j   j   S(   Ni’’’’(   t   direct_space_asuR   t   cutsi    t   nt   ct	   thickness(   i’’’’i    i    (   i    i’’’’i    (   i    i    i’’’’(   t   cctbx.crystalRW   t	   float_asut   float_cut_planet
   add_bufferR   t   shape_verticest   max(   R   t   bufferRW   RY   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/__init__.pyt   buffer_shifts_fracį   s    	7c   	      C   s3  | | g j  d   d k s! t  | d  k rZ | j   d k sE t  |  j d |  } n | j   d k sr t  ~ | d  k s | d k r£ | j   | j   f S| j   | j   } } ~ |  j d |  } t g  t	 | |  D] \ } } | | ^ qä  t g  t	 | |  D] \ } } | | ^ q f S(   Ni   i    t
   sites_cartRb   (
   R
   R   R   t   sizet   fractionalizet   minRa   Rc   t   tuplet   zip(	   R   Rd   t
   sites_fracRb   t   s_mint   s_maxt   shifts_fract   st   b(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/__init__.pyt   box_frac_around_sitesź   s    !/i2   c         C   sJ  | | g j  d   d k s! t  | | | | | | g j  d   d k sN t  d d l m } | } | d  k ry | } n  | d  k	 r | j |  } n  | d  k	 rĀ | j |  j |  | |	 |
  S| d  k	 rą | j |  } n  | d  k	 r| j	 |  |  } n  | d  k	 r"| j
 |  |  } n  | d  k	 s4t  | j | | |	 |
  S(   Ni   i   i’’’’(   t   adptbx(   R
   R   R   RD   Rq   t   u_as_bt   debye_waller_factor_b_isot   stol_sqt   b_as_ut   u_cart_as_u_start   u_cif_as_u_start   debye_waller_factor_u_star(   R   t   miller_indext   miller_indicest   u_isot   b_isot   u_cartt   b_cartt   u_cift   u_start   exp_arg_limitt   truncate_exp_argRq   t   h(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/__init__.pyt   debye_waller_factorsż   s*    !- 	N(   R   R   R   R   R   R'   R)   R,   R1   R3   R6   R8   R<   R=   R?   R"   RE   RV   Rc   Rp   R!   R   t   debye_waller_factor(    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/__init__.pyR   q   sL   	
		
g      ą?c         C   sG   t  j |  t  j |   } t t |   } | d k rC | } n  | S(   Ni    (   R   t   colRa   t   list(   t   sites_cart_mint   sites_cart_maxt   default_buffer_layert
   sites_spant   buffer_layer(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/__init__.pyt!   non_crystallographic_buffer_layer  s
    	i    c         C   sē   |  d  k | d  k k	 s t  | d  k | d  k k s< t  |  d  k	 rc |  j   } |  j   } n  | d  k r t d | d | d |  } n  t j |  t j |  } t g  | t j | g d  d D] } t | |  ^ qĖ  S(   NR   R   R   i   i   (   R   R   Rg   Ra   R   R   R   R   (   Rd   R   R   R   R   t   min_unit_cell_lengthR   t   unit_cell_length(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/__init__.pyt   non_crystallographic_unit_cell)  s    t;   non_crystallographic_unit_cell_with_the_sites_in_its_centerc           B   s#   e  Z d d  d d  Z d   Z RS(   g      ą?i    c   	      C   s«   | j    } | j   } t d d  d | d | d | d | d |  |  _ t j |  j j d g d   } t j | j    t j | j     d	 } | | | |  _ d  S(
   NRd   R   R   R   R   R   g      ą?i   i   (	   Rg   Ra   R   R   R   R   R   t   orthogonalizeRd   (	   R   Rd   R   R   R   R   R   t   unit_cell_centert   model_center(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/__init__.pyR   @  s    "c         C   s?   d d l  m } d d l  m } | j d |  j d | j    S(   Ni’’’’(   RF   (   R@   R   t   space_group(   RD   RF   R@   RM   R   R   (   R   RF   R@   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/__init__.pyRI   S  s
    		N(   R   R   R   R   RI   (    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/__init__.pyR   >  s   c         C   s  d d l  m } d } t | j d | j     j d d  } t |   d k r\ t |   S| j   } | d k rt |   d	 k r |  d
 } nR t |   d k rŁ |  \ } } } | | k oĖ | k n så t	  n t
 |   t | | | d d d f  }	 n| d k rot }
 | d k r<| d k r<t }
 q<n  |
 rt |   d k rct
 |   n  |  d
 } |  d	 } t | | | | | | f  }	 qt |   d k rĮ|  d
 } |  d	 } n t |   d k r÷|  \ } } } | | k sNt	  nW t |   d k rB|  \ } } } } | | k s-t	  | d k sNt	  n t
 |   t | | | d d d f  }	 n | d k r)t |   d k rĀ|  d
 } |  d	 } t | | | d d d f  }	 qt |   d k r|  d  \ } } } | | k słt	  t | | | d d d f  }	 qt
 |   nf| d k rt |   d k rVt
 |   n  |  d
 } |  d	 } |  d } t | | | d d d f  }	 nś | d k rtt |   d k rĀt
 |   n  |  d
 } |  d	 } |  d } |  d } | d k rt | | | d | d f  }	 q| d k rDt | | | d d | f  }	 q| d k rt | | | | d d f  }	 qn | d k rt
 |   n  |	 Sd  S(   Ni’’’’(   R@   s&   Cannot interpret unit cell parameters.t   groupR   t    i   t   Cubici   i    i   iZ   t	   Hexagonalt   Trigonals   R-3m:Rs   R-3:Ri   i   ix   t
   Tetragonalt   Orthorhombict
   Monoclinics   P12/m1s   P112/ms   P2/m11t	   Triclinic(   R   R   (   s   R-3m:Rs   R-3:R(   RD   R@   R   RG   t   build_derived_laue_groupR   t   lenR   t   crystal_systemR   t   RuntimeErrorR!   R"   (   t   paramsR   R@   t	   error_msgt
   laue_groupR”   t   aRo   RZ   t
   unit_cell_t   is_rhombohedralt   angle(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/__init__.pyt   infer_unit_cell_from_symmetryZ  s    
%! 

!
!

!! 


! 



!!$(   t
   __future__R    t   cctbx.array_family.flexRD   t   scitbx.array_family.sharedt   scitbxt   boost.pythont   boostt   pythont
   import_extR   R   R   R   R   R   t   __func__R   R	   t   fractionalization_matrixR   Rf   t   injectorR   R   R   R   t   objectR   RŖ   (    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/uctbx/__init__.pyt   <module>   s.   
8

"±