ó
>™xTc           @   sá   d  d l  m Z d  d l Z d  d l m Z d  d l m Z d  d l m Z d  d l m Z d  d l	 Z d  d l m
 Z
 d  d l m Z d  d	 l m Z d
 d „ Z d „  Z d „  Z d d „ Z d „  Z d „  Z d „  Z d S(   iÿÿÿÿ(   t   divisionN(   t   xray(   t   crystal(   t   sgtbx(   t   uctbx(   t   eltbx(   t   adptbx(   t	   cgi_utilst   Inputc         C   sf   |  d k rb | Gd G|  GHd G| d k r1 d GHn- | d k rE d GHn | d k rY d	 GHn d
 GHHn  d  S(   Nt    s   space group symbol:s   Convention:t   A1983s7   International Tables for Crystallography, Volume A 1983t   I1952s7   International Tables for Crystallography, Volume I 1952t   Halls   Hall symbolt   Default(    (   t   sgsymbolt
   conventiont   label(    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/web/io_utils.pyt   show_input_symbol   s    c         C   s(   t  |  ƒ } | d k  r$ t d ‚ n  | S(   Ni    s$   Negative number for columns to skip.(   t   intt
   ValueError(   t   skip_columnst   result(    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/web/io_utils.pyt   interpret_skip_columns   s    c         C   s¤   |  j  ƒ  } t | ƒ | d k  r. t |  ‚ n  d d d g } xM t d ƒ D]? } y t | | | ƒ | | <WqJ t k
 rˆ t |  ‚ qJ XqJ Wd j | |  ƒ | f S(   Ni   i    t    (   t   splitt   lent   FormatErrort   xranget   floatt	   Exceptiont   join(   t   lineR   t   fldst   coordinatest   i(    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/web/io_utils.pyt   interpret_coordinate_line    s       g      @c         C   s¬  t  j d d ƒ } yv|  d | _ y t |  d ƒ Wn9 t k
 ro d } t j j d |  d d t ƒ | _	 n) Xd } t j j d |  d d t
 ƒ | _	 |  | | d !} x( t d ƒ D] } t | | ƒ | | <q¶ W| | _ d	 | _ | j ƒ  t j | ƒ | _ t |  ƒ | d
 k r‡t |  | d ƒ | _ t |  ƒ | d k rht j t |  | d
 ƒ ƒ | _ q‡t |  ƒ | d k  s‡t ‚ n  Wn t k
 r§t j |  ‚ n X| S(   Nt   scattering_typet   consti    i   i   R   t   exacti   g      ð?i   i   (   R   t	   scattererR   R   R   R   t   xray_scatteringt   get_standard_labelt   TrueR$   t   FalseR   t   sitet	   occupancyt   set_use_u_iso_onlyR   t   b_as_ut   u_isoR   t   AssertionErrorR   R   (   R    t   default_b_isoR'   t   offsR,   R"   (    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/web/io_utils.pyt   read_scatterer)   s6    		
##c      
   C   sR   t  j t  j d t j |  j ƒ d t j d |  j d |  j	 ƒ ƒ d t
 |  j ƒ ƒS(   Nt	   unit_cellt   space_group_infot   symbolt   table_idt   min_distance_sym_equiv(   R   t   special_position_settingst   symmetryR   R5   t   ucparamsR   R6   R   R   R   R9   (   t   inp(    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/web/io_utils.pyt"   special_position_settings_from_inpI   s    			c   
      C   sg  | j  ƒ  j ƒ  } d GHt | _ d GHd GHd GHd GHd GHd GHd GHd	 GHd
 GHd GHt j | ƒ } Hxï |  j D]ä } t | j ƒ  ƒ } |  j	 d k r± | j
 ƒ  j | j ƒ | _ n  | j | ƒ | j | j ƒ } | j | ƒ } | j ƒ  }	 d GHd d d d d | j | j |	 j ƒ  |	 j ƒ  | j ƒ  f | j | j t j | j ƒ f GHql Wd GHt | _ H| S(   Ns$   </pre><table border=2 cellpadding=2>s   <tr>s	   <th>Labels!   <th>Scattering<br>factor<br>labels   <th>Multiplictys   <th>Wyckoff<br>positions   <th>Site<br>symmetrys$   <th colspan=3>Fractional coordinatess   <th>Occupancy<br>factors   <th>Bisot
   Fractionals   <td>%s<td>%ss9   <td align=center>%d<td align=center>%s<td align=center>%ss3   <td><tt>%.6g</tt><td><tt>%.6g</tt><td><tt>%.6g</tt>s   <td align=center><tt>%.6g</tt>s   </table><pre>(   R6   t   wyckoff_tableR*   t   in_tableR   t	   structureR!   R4   R   t	   coor_typeR5   t   fractionalizeR,   t   add_scatterert   site_symmetryt   mappingt   positionR   R$   t   multiplicityt   lettert   point_group_typeR-   R   t   u_as_bR0   R+   (
   R=   t   statusR:   R@   RB   R   R'   RF   t   wyckoff_mappingt   wyckoff_position(    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/web/io_utils.pyt   structure_from_inpR   s<    	Q	c         C   s&  |  j  } d GHx | D] } | GHq WHt j j d d  d | ƒ } | j d t ƒ } | j ƒ  j | j	 ƒ  ƒ } t
 } x¢ t | | j ƒ  ƒ D]‹ \ } }	 |	 j }
 g  |
 | g D] } d d | ^ q« \ } } | | k r‰ | sð d GHd GHt } n  d	 G|	 j ƒ  GHd
 | GHd | GHq‰ q‰ W| r"Hn  | S(   Ns   Input PDB file content:
t   source_infot   linest   enable_scattering_type_unknowns    %7.4fi   s=   Anisotropic displacement parameters (ANISOU) of the followings   atoms were modified:R   s       Ucart(input) =s       Ucart(tidy)  =(   R!   t   iotbxt   pdbt   inputt   Nonet   xray_structure_simpleR*   t
   scattererst   extract_u_cartR5   R+   t   zipt   atoms_with_labelst   uijt   quote(   R=   RM   t   pdb_fileR   t   pdb_inpt   xray_structuret   u_tidyt   have_headert   utt   atomt   uit   ut   suit   sut(    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/web/io_utils.pyt   structure_from_inp_pdbz   s2    				"	-		(   t
   __future__R    t	   iotbx.pdbRT   t   cctbxR   R   R   R   t   cctbx.eltbx.xray_scatteringR   R   t	   cctbx.webR   R   R   R#   R4   R>   RP   Rj   (    (    (    s@   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/web/io_utils.pyt   <module>   s    			 			(