ó
xTc           @   s   d  d l  m Z d  d l m Z d  d l m Z d  d l m Z d	 d	 d	 d	 d	 d  Z	 d   Z
 d	 d	 d	 d  Z d	 d	 d	 d	 d	 d	 d  Z d	 S(
   i˙˙˙˙(   t   division(   t   space_group_symbols(   t   adptbx(   t   StringIOc         C   sŕ   | d  k	 s t  | d  k	 r5 |  d t |  IJn  | d  k	 rX |  d t |  IJn  | d  k	 r |  d IJx | D] } |  | IJqu W|  d IJn  |  J|  d IJ|  J| d  k	 rÎ |  d t j |  IJn  |  d | IJd  S(   Ns   {+ file: %s +}s   {+ description: %s +}s   {+ comment:s   +}s.   {- begin block parameter definition -} define(sĂ   {============================ space group ============================}

{* space group *}
{* use International Table conventions with subscripts substituted
   by parenthesis *}
{===>} sg="%s";
s  {==================== derivative/MAD coordinates =====================}

{+ list: for each site define:
         - whether the site is to be refined, fixed or ignored
         - derivative name (must be the same for all sites in a derivative)
         - chemical type (note: wavelength-dependent form factors
                                are specified in mad_refine.inp)
         - coordinates (x, y, z)
         - B-value (b)
         - occupancy (q)
         - group name (g) +}

{+ list: the optional group name (g) is a string of upto 4 characters.
         If a group is left blank, each site is refined individually.
         If a group is specified, all sites with the same group name
         and the same derivative name are treated as a rigid body, and their
         occupancies, B-values, and form factors are refined as a group. +}

{+ table: rows=%d numbered
          cols=9 "action" "derivative name" "chemical type"
                 "x coordinate" "y coordinate" "z coordinate"
                 "B-value" "occupancy" "group" +}
(   t   Nonet   AssertionErrort   strR   t
   cns_format(   t   st   filet   descriptiont   commentt   space_group_infot   n_rowst   line(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/cns/sdb_writer.pyt   write_header   s$    
 
c         C   s   |  d IJd  S(   Nsč  {* to appended new entries or merge this file with other
   site database files use sdb_manipulate.inp *}

{* to delete sites from this file either set the derivative
   name to be blank or use delete_sites.inp *}

{===========================================================================}
{         things below this line do not normally need to be changed         }
{===========================================================================}

) {- end block parameter definition -}(    (   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/cns/sdb_writer.pyt
   write_tail6   s    c         C   sí   | d  k r d } n  | d  k r* d } n  | d  k r? d } n  | d k sQ t  | j j   sf t  | d
 k sx t  | } |  d | | | | | | j | | j d | | j d | | j d	 | t j | j  | | j	 | | f IJd  S(   Nt   refinet   SITEt    i    t   fixt   ignoresŢ   {+ choice: "refine" "fix" "ignore" +}
{===>} site.action_%d="%s";
{===>} site.segid_%d="%s"; site.type_%d="%s";
{===>} site.x_%d=%.6g; site.y_%d=%.6g; site.z_%d=%.6g;
{===>} site.b_%d=%.6g; site.q_%d=%.6g; site.g_%d="%s";
i   i   (   R   R   s   ignore(
   R   R   t   flagst   use_u_iso_onlyt   scattering_typet   siteR   t   u_as_bt   u_isot	   occupancy(   R   t   running_indext	   scatterert   actiont   segidt   groupt   i(    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/cns/sdb_writer.pyt   write_scattererD   s"     	 	 		c   
      C   sŻ   t    } t | | | | |  j   |  j   j    xd t |  j    D]P \ } }	 t | | d |	 j d |  j   j	 |	 j
   d | d | d | qG Wt |  | j   S(   Ni   R   R   R    R!   (   R   R   R   t
   scattererst   sizet	   enumerateR#   t   customized_copyt	   unit_cellt   orthogonalizeR   R   t   getvalue(
   t   selfR	   R
   R   R   R    R!   R   R   R   (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/cns/sdb_writer.pyt   xray_structure_as_cns_sdb_fileZ   s    			
N(   t
   __future__R    t	   iotbx.cnsR   t   cctbxR   t	   cStringIOR   R   R   R   R#   R,   (    (    (    sB   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/cns/sdb_writer.pyt   <module>   s   	/	