ó
„™xTc           @   sk   d  d l  m Z d  d l m Z d  d l m Z d  d l Z d  d l Z d e f d „  ƒ  YZ	 d „  Z
 d S(   iÿÿÿÿ(   t   division(   t
   group_args(   t   SorryNt   managerc           B   s•   e  Z d  Z e d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z e d „ Z d „  Z d „  Z d d „ Z RS(   só  
  Class for keeping track of symmetry information from multiple files.  This
  is particularly problematic in the phenix.refine GUI, where users may supply
  any number of PDB files as input, plus a PDB file representing a reference
  structure, and up to five reflection files.  Automatically taking the latest
  symmetry provided, without taking into account the symmetry information in
  other files and the current GUI state, may result in errors if files contain
  incompatible information.
  c         C   s:   g  |  _  g  |  _ i  |  _ d  |  _ d  |  _ | |  _ d  S(   N(   t   pdb_file_namest   reflection_file_namest   symmetry_by_filet   Nonet   current_space_groupt   current_unit_cellt   prefer_pdb_space_group(   t   selfR
   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/symmetry.pyt   __init__   s    					c         C   s   | |  _  | |  _ d  S(   N(   R   R	   (   R   t   space_groupt	   unit_cell(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/symmetry.pyt   set_current   s    	c         C   s   |  j  |  j f S(   N(   R   R	   (   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/symmetry.pyt   get_current   s    c         C   s\   |  j  d  k s |  j d  k r1 t d d ƒ ‚ n  d d  l } | j j d |  j  d |  j ƒ S(   Ns5   Either the space group or the unit cell (or both) is s
   undefined.iÿÿÿÿt   space_group_infoR   (   R   R   R	   R   t   cctbx.crystalt   crystalt   symmetry(   R   t   cctbx(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/symmetry.pyt   as_symmetry_object!   s    	c         C   sb   |  j  ƒ  \ } } | d  k r' d } n d | j ƒ  } | d  k rL d } n t | ƒ } | | f S(   Nt    s   %.3g %.3g %.3g %.3g %.3g %.3g(   R   R   t
   parameterst   str(   R   t   sgt   uct   uc_strt   sg_str(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/symmetry.pyt   get_current_as_strings*   s    		c         C   sÖ   | d k s | d k r$ d |  _ nh d d l m } y | j | ƒ |  _ Wn? t k
 r‹ } d t | ƒ k r… t d d | ƒ ‚ qŒ ‚  n X| d k s¤ | d k r° d |  _ n" d d l m	 } | j
 | ƒ |  _ d S(	   s$   Set symmetry from fields in the GUI.R   iÿÿÿÿ(   t   sgtbxs   symbol not recognizeds1   The current value for the space group parameter, s<   '%s', could not be recognized as a valid space group symbol.(   t   uctbxN(   R   R   R   R   R   t   RuntimeErrorR   R   R	   R    R   (   R   R   R   R   t   eR    (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/symmetry.pyt   set_current_as_strings6   s    c         C   s^   | j  j ƒ  } | d k	 r6 | j ƒ  } | j ƒ  } n d \ } } | j } |  j | | | ƒ S(   s=   Extract symmetry info from iotbx.file_reader._any_file objectN(   NN(   t   file_objectt   crystal_symmetryR   R   R   t	   file_namet   add_pdb_file(   R   t
   input_filet   symmR   R   R&   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/symmetry.pyt   process_pdb_fileK   s    	c      	   C   sE   |  j  j | ƒ | | f |  j | <|  j d | d | d | d d ƒ S(   NR&   R   R   t	   file_typet   pdb(   R   t   appendR   t"   check_consistency_and_set_symmetry(   R   R&   R   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/symmetry.pyR'   V   s    	c         C   se   | j  j d j ƒ  } | d k	 r= | j ƒ  } | j ƒ  } n d \ } } | j } |  j | | | ƒ S(   s=   Extract symmetry info from iotbx.file_reader._any_file objecti    N(   NN(   t   file_servert   miller_arraysR%   R   R   R   R&   t   add_reflections_file(   R   R(   R)   R   R   R&   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/symmetry.pyt   process_reflections_file_   s    	c      	   C   sE   |  j  j | ƒ | | f |  j | <|  j d | d | d | d d ƒ S(   NR&   R   R   R+   t   hkl(   R   R-   R   R.   (   R   R&   R   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/symmetry.pyR1   j   s    	c         C   s©   |  j  d  k s |  j d  k r? | r; t d d | ƒ ‚ n  d  Sd d l m } y( | j d |  j j ƒ  d |  j  ƒ } Wn' t k
 r  } t d d d	 ƒ ‚ n Xt	 Sd  S(
   Ns5   Either the unit cell or the space group (or both) is s1   not set; these parameters are required to run %s.iÿÿÿÿ(   R   R   R   s1   Unit cell parameters are not consistent with the s?   currently set space group.  Please make sure that the symmetry s!   information is entered correctly.(
   R	   R   R   R   R   R   R   t   groupt   AssertionErrort   True(   R   t   program_namet   raise_error_if_incompleteR   R)   R"   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/symmetry.pyt   check_cell_compatibilitys   s    c         C   s  t  } t  } t  } t  } | d  k	 rÉ |  j d  k	 r½ t |  j ƒ }	 t | ƒ }
 |	 |
 k rÆ |  j j ƒ  } | j ƒ  } | j ƒ  j ƒ  | k r– t } qº | d k rº |  j rº | |  _ qº qÆ qÉ | |  _ n  | d  k	 r|  j d  k	 r|  j j	 | ƒ st } qq| |  _ n  | | f S(   NR,   (
   t   FalseR   R   R   R4   t   build_derived_point_groupR6   R
   R	   t   is_similar_to(   R   R&   R   R   R+   t   space_group_mismatcht   set_new_space_groupt   unit_cell_mismatcht   incompatible_cellt   current_sgnamet
   new_sgnameR4   t
   derived_sg(    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/symmetry.pyR.   †   s,    	c      	   C   sÁ   g  } g  } |  j  |  j } xq | D]i } |  j | \ } } | d  k	 rd | j | t | ƒ f ƒ n  | d  k	 r# | j | t | ƒ f ƒ q# q# Wt d t |  j ƒ d t |  j ƒ d | d | ƒ S(   NR   R	   t   space_group_filest   unit_cell_files(	   R   R   R   R   R-   R   R   R   R	   (   R   t   sg_filest   uc_filest   all_file_namesR&   R   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/symmetry.pyt   get_symmetry_choices¡   s     c         C   s   | d  k r t j } n  |  j |  j } xP | D]H } |  j | \ } } | d t j j | ƒ t	 | ƒ t	 | ƒ f IJq/ Wd  S(   Ns	   %s: %s %s(
   R   t   syst   stdoutR   R   R   t   ost   patht   basenameR   (   R   t   outRH   R&   R   R   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/symmetry.pyt   show±   s    N(   t   __name__t
   __module__t   __doc__R6   R   R   R   R   R   R#   R*   R'   R2   R1   R:   R9   R.   RI   R   RP   (    (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/symmetry.pyR      s   												
		c         C   sG  d d l  m } d } |  d k	 r| d k	 r|  j ƒ  j | j ƒ  ƒ s~ t d d |  j ƒ  j ƒ  | j ƒ  j ƒ  f ƒ ‚ n  |  j ƒ  } | j ƒ  } | | k rò | j ƒ  } | j	 ƒ  } | j ƒ  j	 ƒ  | k rò t d d | | f ƒ ‚ qò n  | j
 d | j ƒ  d |  j ƒ  ƒ } n* |  d k	 r.|  } n | d k	 rC| } n  | S(	   s¿   
  Given data from a model (PDB) file and a reflections file, attempt to
  reconcile them.  Precedence is given to the space group from the PDB file
  and the unit cell from the data file.
  iÿÿÿÿ(   R   s.   Unit cell mismatch between data and PDB file:
s   PDB file: %s
Data:%ss1   Incompatible space groups in data and PDB files:
R   R   N(   R   R   R   R   R<   R   R   R   R4   R;   R   (   t   model_symmetryt   data_symmetryR   t   use_symmetryt   pdb_sgt   hkl_sgt	   pdb_groupRC   (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/symmetry.pyt   combine_model_and_data_symmetry¼   s0    			(   t
   __future__R    t   libtbxR   t   libtbx.utilsR   RL   RJ   t   objectR   RZ   (    (    (    s<   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/symmetry.pyt   <module>   s   ´