ó
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 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 e d „ Z d e f d „  ƒ  YZ 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   flex(   t   miller(   t   make_cns_input(   t   random_structure(   t   generate_random_hl(   t   reflection_reader(   t   abs_arg(   t   approx_equal(   t   easy_runNc      	   C   s�  t  j d t  j d |  d | j d |  j ƒ  ƒ d | j ƒ j ƒ  } xb t | j | j j	 | j	 ƒ  ƒ D]? \ } } } t
 | | ƒ d k rd d G| G| G| GHt ‚ qd qd Wt  j d t  j d |  j ƒ  d | j d |  j ƒ  ƒ d | j ƒ j ƒ  } xb t | j | j j	 | j	 ƒ  ƒ D]? \ } } } t
 | | ƒ d k rd G| G| G| GHt ‚ qqW|  j ƒ  }	 |  j ƒ  j ƒ  }
 t  j |  j ƒ  ƒ } xt | j ƒ D]ñ \ } } t  j |	 |
 | ƒ } | j |  j ƒ  ƒ } | j | j j	 | ƒ } | j | j | ƒ } | | j ƒ  } t
 |  j	 ƒ  | | ƒ d k  s2t ‚ t | | | d d ƒs—d G|  j ƒ  GH|  j ƒ  | GHd	 G| | GHd
 G| GHt ‚ q—q—Wd  S(   Nt
   miller_sett   crystal_symmetryt   indicest   anomalous_flagt   datag{®Gáz„?s   Error:t   epss   i:s   o:(   R   t   arrayt   sett   miller_indicesR   t   hlt   phase_integralst   zipt   piR   t   abst   AssertionErrort   cell_equivalent_p1t   space_groupt   space_group_infot   reciprocal_space_asut   make_lookup_dictR   t	   enumeratet
   asym_indext
   one_columnt
   complex_eqt   fcalct   hendrickson_lattman_eqt   hR   (   t   sg_fcalct   sg_hlt   sg_cnst   p1_cnst   sg_phase_integralsR$   t   cns_pit	   miller_pit   p1_phase_integralsR   t   asut   lookup_dictt   p1_it   h_asut   h_eqt	   fcalc_asut   hl_asut   sg_i(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/tst_cns_hl.pyt   verify   sP    								&	c         C   s   |  j  ƒ  j ƒ  | j ƒ  k s$ t ‚ t j |  j ƒ  ƒ } | t j |  j ƒ  ƒ 7} | t j |  j	 ƒ  ƒ 7} | j
 } | d ƒ | d ƒ | d ƒ | d ƒ | d ƒ | d ƒ | d ƒ | d ƒ | d	 ƒ | d
 ƒ | d ƒ | d ƒ | d ƒ xX t |  j ƒ  ƒ D]D \ } } | d | d t |  j  ƒ  | d t ƒd | | ƒ q	W| d ƒ | s | d ƒ | d ƒ | d ƒ | d ƒ | d ƒ | d ƒ n | d ƒ | d ƒ | d ƒ | d ƒ t d d ƒ } x | D] } | | IJqÞW| j ƒ  d  S(   Nt   xrays7     declare name=fcalc domain=reciprocal type=complex ends1     declare name=pa domain=reciprocal type=real ends1     declare name=pb domain=reciprocal type=real ends1     declare name=pc domain=reciprocal type=real ends1     declare name=pd domain=reciprocal type=real ends     group type hls       object pas       object pbs       object pcs       object pds     ends     reflections       index %d %d %ds    fcalc=%.6g %.6g
t   degs#       pa=%.6g pb=%.6g pc=%.6g pd=%.6gs4     declare name=pi domain=reciprocal type=complex ends<     do (pi=get_fom[phistep=5,CEN360=false](pa,pb,pc,pd)) (all)s+     write reflections output="tmp_sg.hkl" ends     expands+     write reflections output="tmp_p1.hkl" ends     anomalous=falses/     write reflections output="tmp_merged.hkl" endt   endt   stops   tmp.cnst   w(   R   t   sizeR   R   t   xray_unit_cellt	   unit_cellt   xray_symmetryR   t   xray_anomalousR   t   appendR   R   R   t   Truet   opent   close(   t   fcalc_arrayR   t
   test_merget	   cns_inputt   lt   iR$   t   f(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/tst_cns_hl.pyt   write_cns_input<   sJ    $	












9









t   read_reflection_arraysc           B   s   e  Z d  „  Z RS(   c         C   sÓ   t  j t | ƒ ƒ } d s! | r/ | j ƒ  GHn  | j | k sD t ‚ | j ƒ  \ } |  _ |  _ | j	 d |  _
 | j	 d |  _ t j |  j |  j
 j ƒ j ƒ  s§ t ‚ t j |  j |  j j ƒ j ƒ  sÏ t ‚ d  S(   Ni    t   FCALCt   PI(   R   t   cns_reflection_fileRB   t   show_summaryt	   anomalousR   t   join_hl_groupR   R   t   reciprocal_space_objectsR"   R   R   t   match_indicesR   t   have_singles(   t   selft	   file_nameR   t   verboset   reflection_filet   names(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/tst_cns_hl.pyt   __init__g   s    "(   t   __name__t
   __module__RZ   (    (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/tst_cns_hl.pyRK   e   s   g       @i    c      
   C   sp  t  j |  d d  d | d t d t ƒj d | d	 | d
 d ƒ j ƒ  } t | ƒ } t | | j ƒ  ƒ y t j	 d ƒ Wn t
 k
 rˆ n Xy t j	 d ƒ Wn t
 k
 r­ n Xt j d d ƒ j ƒ  t d | | ƒ } t d | | ƒ } t | | j ƒ  | | ƒ | rl| j ƒ  } | j ƒ  }	 t | | j ƒ  d t ƒy t j	 d ƒ Wn t
 k
 r\n Xt j d d ƒ j ƒ  t j t d ƒ ƒ }
 | j ƒ  j ƒ  s�|
 j d } |	 j d | j d | j ƒ j ƒ  j |	 ƒ } | j ƒ  j |	 j ƒ  ƒ sõt ‚ |	 j ƒ  } | j ƒ  } xq t j t j  g D]Z } t j! | | j ƒ  ƒ | | j ƒ  ƒ ƒ j" ƒ  } | d! k  r d G| j# ƒ  GHt ‚ q q Wn  |
 j$ ƒ  \ } } } | d d d d g k s´t ‚ | j d | d | ƒ j ƒ  j | ƒ } | j ƒ  j | j ƒ  ƒ süt ‚ xm t% | j ƒ  | j ƒ  | j ƒ  ƒ D]D \ } } } t& | | d d ƒs!| GHd G| GHd G| GHt ‚ q!q!Wn  d  S("   Nt   elementst   Nt   Ct   Ot   random_f_double_primet   random_u_isot   random_occupancyR   t   d_mint	   algorithmt   directs
   tmp_sg.hkls
   tmp_p1.hklt   commands   cns < tmp.cns > tmp.outRE   s   tmp_merged.hklRL   R   R   i   g�íµ ÷Æ°>s   FAILURE acentricst   PAt   PBt   PCt   PDR   g{®Gázt?s   cctbx:s     cns:(   R^   R_   R_   R`   gé!çýÿï?('   R   t   xray_structureRA   t   structure_factorst   f_calcR   RJ   R   t   ost   unlinkt   OSErrorR	   t   fully_bufferedt   raise_if_errors_or_outputRK   R5   t   average_bijvoet_matesR   RN   RB   R   t
   is_centricRR   t   customized_copyR   t
   map_to_asut
   common_sett   all_eqR   t   select_acentricR   t   realt   imagt   linear_correlationt   coefficientR   RQ   R   R   (   R   R   Rd   RW   R%   R&   R'   R(   t	   hl_mergedt	   fc_mergedRX   t   fc_merged_cnst   fc_merged_at   fc_merged_cns_at   partt   ccRY   R   R   t   hl_merged_cnsR$   t   at   b(    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/tst_cns_hl.pyt   exerciset   sx          		!	!			c         C   s1   x* t  t f D] } t | | d |  j ƒq Wd  S(   NRW   (   t   FalseRA   R‰   t   Verbose(   t   flagsR   R   (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/tst_cns_hl.pyt   run_call_back±   s    t   __main__t   argsi   t	   call_back(   t
   __future__R    t   cctbx.array_familyR   t   cctbxR   t   cctbx.developmentR   R   t   cctbx.regression.tst_millerR   t	   iotbx.cnsR   t   libtbx.complex_mathR   t   libtbx.test_utilsR   t   libtbxR	   t   sysRo   R5   RŠ   RJ   t   objectRK   R‰   R�   R[   t   tst_run_requiring_cnst   argv(    (    (    sJ   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/tst_cns_hl.pyt   <module>   s$   	/)=		