ó
P™xTc           @   sÕ   d  d l  m Z d  d l m 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 Z d „  Z d	 „  Z e d
 d d „ Z d „  Z e d k rÑ e j d e j d d e ƒ n  d S(   iÿÿÿÿ(   t   division(   t   miller(   t   crystal(   t   make_cns_input(   t   reflection_reader(   t   easy_runNc         C   s«  | j  | k s t ‚ | j d } | j d } | j d } | j d } | j d } x> | | | | f D]* } | j j ƒ  | j j ƒ  k si t ‚ qi W|  j ƒ  }	 xt | j ƒ D]ð\ }
 } | j |
 } | j |
 } | j |
 } | j |
 } | j |
 } | d k  r%| d k r%| d 7} n  | d k | d k k sCt ‚ | d k r[| d k s‰| d k rs| d k s‰t d	 | | f ƒ ‚ |	 j | | ƒ } |	 j	 | ƒ } |	 j
 | ƒ } |	 j | ƒ j t ƒ } | sÝ| rü| |	 j ƒ  | k st ‚ n  | d
 |	 j ƒ  | k st ‚ yd | | k s7t d ƒ ‚ | | k sOt d ƒ ‚ | | k sgt d ƒ ‚ | | k st d ƒ ‚ Wnd t k
 ræ} |  j ƒ  GHd G| GHd G| G| GHd G| G| GHd G| G| GHd G| G| GHt | ‚ n X|	 j | ƒ sýt ‚ | |	 j ƒ  |	 j | t ƒ k s%t ‚ t j |	 | ƒ } | j | ƒ | k sRt ‚ | j	 ƒ  | k sjt ‚ | j
 ƒ  | k s‚t ‚ | j ƒ  j t ƒ | k s³ t ‚ q³ Wd  S(   Nt   CNS_Mt   CNS_Et   CNS_Ct   CNS_At   CNS_Pi    g      ð¿g     €f@s   c_i = %d, p_i = %gi   s   multiplicity mismatchs   epsilon mismatchs   centric mismatchs   restricted phase mismatchs   index=s   m:s   e:s   c:s   p:(   t	   anomaloust   AssertionErrort   reciprocal_space_objectst   indicest   idt   space_groupt	   enumeratet   datat   multiplicityt   epsilont
   is_centrict   phase_restrictiont   ht_anglet   Truet   order_pt   space_group_infot   is_sys_absentR   t   sym_equiv_indices(   t   crystal_symmetryt   anomalous_flagt   reflection_filet   cns_mt   cns_et   cns_ct   cns_at   cns_pt   cns_xR   t   it   ht   m_it   e_it   c_it   a_it   p_it   mt   et   ct   pt   exct   eq(    (    sO   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/tst_cns_epsilon.pyt   verify	   s^    ( 3 	(c         C   sB  t  j |  j ƒ  ƒ } | t  j |  j ƒ  ƒ 7} | t  j | ƒ 7} | t  j d | ƒ 7} | j } | d ƒ | d ƒ | d ƒ | d ƒ | d ƒ | d ƒ | d ƒ | d	 ƒ | d
 ƒ | d ƒ | d ƒ | d ƒ | d ƒ | d ƒ | d ƒ | d ƒ | d ƒ t d d ƒ } x | D] } | | IJq W| j	 ƒ  d  S(   Ni'  t   xrays7     declare name=cns_m domain=reciprocal type=integer ends7     declare name=cns_e domain=reciprocal type=integer ends7     declare name=cns_c domain=reciprocal type=integer ends7     declare name=cns_a domain=reciprocal type=integer ends7     declare name=cns_p domain=reciprocal type=real    ends     do (cns_m = mult) (all)s     do (cns_e = epsilon) (all)s     do (cns_c = 0) (all)s     do (cns_c = 1) (centric)s     do (cns_a = 0) (all)s     do (cns_a = 1) (acentric)s     do (cns_p = -1) (all)s&     do (cns_p = centric_phase) (centric)s2     write reflections output="tmp_cns_input.hkl" endt   endt   stops   tmp_cns_input.cnst   w(
   R   t   xray_unit_cellt	   unit_cellt   xray_symmetryR   t   xray_anomaloust   xray_generatet   appendt   opent   close(   R   R   t   d_mint	   cns_inputt   lt   f(    (    sO   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/tst_cns_epsilon.pyt   write_cns_input@   s4    	
















g       @i    c         C   sÒ   t  j |  j d ƒ d |  ƒ} t | | | ƒ y t j d ƒ Wn$ t k
 rU ‚  n t k
 re n Xt j	 d d ƒ j
 ƒ  t d d ƒ } t j | ƒ } | j ƒ  d s° | r¾ | j ƒ  GHn  t | | | ƒ d  S(   Niè  R   s   tmp_cns_input.hklt   commands+   cns < tmp_cns_input.cns > tmp_cns_input.outt   ri    (   R   t   symmetryt   any_compatible_unit_cellRD   t   ost   unlinkt   KeyboardInterruptt	   ExceptionR   t   fully_bufferedt   raise_if_errors_or_outputR>   R   t   cns_reflection_fileR?   t   show_summaryR3   (   R   R   R@   t   verboseR   RC   R   (    (    sO   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/tst_cns_epsilon.pyt   exercise\   s$    	   	
c         C   s1   x* t  t f D] } t | | d |  j ƒq Wd  S(   NRQ   (   t   FalseR   RR   t   Verbose(   t   flagsR   R   (    (    sO   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/tst_cns_epsilon.pyt   run_call_backn   s    t   __main__t   argsi   t	   call_back(   t
   __future__R    t   cctbxR   R   t   cctbx.developmentR   t	   iotbx.cnsR   t   libtbxR   t   sysRI   R3   RD   RS   RR   RV   t   __name__t   tst_run_requiring_cnst   argv(    (    (    sO   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/tst_cns_epsilon.pyt   <module>   s   	7			