ó
í™xTc           @   sN  d  d l  m Z d  d l m Z d  d l Z d  d l 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 m Z d  d l Z d  d l Z d  d l Z d	 d d d
 e d d „ Z d d d d
 e d d „ Z d d „ Z d d „ Z d „  Z d d d d „ Z d „  Z e d k rJe e j d ƒ n  d S(   iÿÿÿÿ(   t   division(   t   flexN(   t   shelx(   t   hklf(   t   option_parser(   t   distributions(   t   absolute_structuret   cift   henkei   c         C   sÃ   | d k s t  ‚ xª t j |  ƒ D]™ \ } } }	 d | k rC q" n  t j t j j | d | ƒ ƒ }
 xS |
 D]K } y, t | d | d	 | d
 | d | d | ƒWql t k
 r¶ } ql ql Xql Wq" Wd  S(   Nt   rest   inst   fcft   hklR   s   .olexs   *.%st   logt   atomic_form_factorst   inelastic_form_factorst   chiral_space_groups_onlyt   outlier_cutoff_factor(   s   resR
   R   R   s   cif(   t   AssertionErrort   ost   walkt   globt   patht   joint   run_oncet	   Exception(   t	   directoryt   extR   R   R   R   R   t   roott   dirst   filest   gR   t   e(    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/smtbx/command_line/absolute_structure.pyt   crawl   s     "c         C   sJ  | d  k r t j } n  t j j |  ƒ \ } } | d }	 | d }
 | d k rk t |  ƒ \ } } } } n=| d k rzt j j	 d |  ƒ j
 ƒ  } | j ƒ  d } t | d ƒ } t j j j | ƒ j } | j d | d | ƒ t j j |
 ƒ rt |
 | ƒ \ } } } } q¨t j j |	 ƒ rsy t |	 | ƒ \ } } } } Wqwt k
 rot |	 | ƒ \ } } } } qwXq¨d  Sn. t j j |	 ƒ s�d  St |  ƒ \ } } } } | j ƒ  j ƒ  sÓ| r×| j ƒ  j ƒ  r×d  S| |  IJ| j ƒ  j d	 | ƒ | d
 t | j ƒ  j ƒ  ƒ IJt | | | | d | d | d | ƒ| j ƒ  d  S(   Ns   .hkls   .fcfs   .cift	   file_pathi    t   _diffrn_radiation_wavelengtht   photont   tablet   fs   space_group.is_chiral(): t   nuR   R   (   s   .fcfs   .hkl(   t   Nonet   syst   stdoutR   R   t   splitextt   structure_factors_from_fcft   iotbxR   t   readert   modelt   valuest   floatt   builderst   crystal_structure_buildert	   structuret   set_inelastic_form_factorst   existst   structure_factors_from_hklt   RuntimeErrort   structure_factors_from_ins_rest   space_groupt
   is_centrict	   is_chiralt   space_group_infot   show_summaryt   strt   absolute_structure_analysist   flush(   R"   R'   R   R   R   R   R   t	   file_roott   file_extt   hkl_patht   fcf_patht   xst   fo2t   fct   scaleR   t	   cif_blockt
   wavelength(    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/smtbx/command_line/absolute_structure.pyR   !   sD    

	" 
 c   	      C   sõ   t  j j d |  ƒ j ƒ  } | j ƒ  d } d | k rP | d d k sP t ‚ n  t  j j j | ƒ j ƒ  } | d } | d } | d  k r» | j
 ƒ  j t j | j ƒ  d ƒ ƒ } d } n* | j | d d	 ƒj ƒ  } | j | ƒ } | | | | f S(
   NR"   i    t   _shelx_refln_list_codet   4t   _refln_F_squared_meast   _refln_F_squared_calci   t	   algorithmt   direct(   R-   R   R.   R/   R0   R   R2   t   miller_array_buildert   arraysR(   t	   f_sq_as_ft   phase_transferR   t   doublet   sizet!   structure_factors_from_scattererst   f_calct   scale_factor(	   R"   RF   R   RJ   RS   RG   t   fc2RH   RI   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/smtbx/command_line/absolute_structure.pyR,   G   s    

'	c         C   sñ   t  j d |  ƒ j d | ƒ d } | j ƒ  | j d d ƒ } | j ƒ  } | j d d d | j ƒ  ƒ | j | d d	 ƒj	 ƒ  } | j
 | ƒ } | d  k	 rá | | j ƒ  | j ƒ  | j ƒ  j ƒ  | ƒ } | j
 | d
 | ƒ} n  | | | | f S(   Nt	   file_namet   crystal_symmetryi    RP   R   R%   t   it1992t   d_minRQ   t   weights(   R   R.   t   as_miller_arrayst#   set_observation_type_xray_intensityt   merge_equivalentst   arrayt   scattering_type_registryR_   RX   RY   RZ   R(   t   datat   sigmast   as_intensity_array(   RD   RF   t   weighting_schemeRG   t   mergingRH   RI   R`   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/smtbx/command_line/absolute_structure.pyR7   W   s    
*c         C   s°  d d l  m } t j j |  ƒ d d } t j j | ƒ sG d  g d St j j	 d t j j
 t j j t j j ƒ ƒ  } t j j d |  ƒ } t j j | | ƒ } t j j | j ƒ  | ƒ } t j j | j ƒ  | ƒ } t j j | j ƒ  | ƒ } t j j | j ƒ  | d t ƒ} t j j | j ƒ  | ƒ } | j ƒ  | j } | j } | r�| j ƒ  j ƒ  r�|  GHd	 G| d j j ƒ  GHn  | j d
 | j d d ƒ t | | d | j  ƒS(   Niÿÿÿÿ(   t9   weighted_constrained_restrained_crystal_structure_builderi    s   .hkli   t   buildert   filenamet   strictly_shelxls   twin: R$   R%   t   sasakiRi   (!   t   iotbx.buildersRk   R   R   R+   R6   R(   R-   R2   t   mixin_builder_classt   twinning_buildert   reflection_data_source_builderR   t   command_streamt   instruction_parsert   crystal_symmetry_parsert   filtered_commandst   wavelength_parsert   afix_parsert   atom_parsert   Falset   restraint_parsert   parseR4   t   twin_componentsR:   R;   t   twin_lawt   as_hklR5   t   wavelength_in_angstromR7   Ri   (   R"   Rk   RD   Rl   t   streamRF   R~   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/smtbx/command_line/absolute_structure.pyR9   f   s8     					
			c      
   C   sÀ  | d  k r t j } n  t j | | d | d | ƒ} | d IJ| j d | ƒ t j | ƒ } | d IJ| j d | ƒ | J| d  k rª t j | j d d d d	 ƒ} n  t	 j
 | ƒ }	 | j }
 |	 j |
 j ƒ  ƒ } t j | d
 d !|
 d
 d !ƒ } t j | | | d | d | j ƒ  d | ƒ} t j | d t d | ƒ} | d IJ| d | IJ| j d | ƒ | d IJ| j d | ƒ | J|  d  k	 r¼t j |  | j ƒ  ƒ } | j d | ƒ n  d  S(   NRZ   R   s   Gaussian analysis:t   outs   Probability plot:t   min_nui   t   max_nuiÈ   i   iûÿÿÿt   probability_plot_slopet   use_students_t_distributiont   students_t_nus   Student's t analysis:s   nu: %.2f(   R(   R)   R*   R   t   hooft_analysist   showt$   bijvoet_differences_probability_plott+   maximise_students_t_correlation_coefficientt   yR   t   students_t_distributiont	   quantilesRW   R   t   linear_regressiont   students_t_hooft_analysist   slopet   Truet   flack_analysist   as_xray_observations(   RF   RG   RH   RI   R'   R   R   R‰   t   NPPt   distributiont   observed_deviationst   expected_deviationst   fitt
   t_analysist   tPPt   flack(    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/smtbx/command_line/absolute_structure.pyR@   …   sB    
	
		

c         C   s  t  d d ƒ j ƒ  j d  d d d d d ƒj d  d d d d	 d
 ƒj d  d d d d d ƒj d  d d d d d ƒj d  d d d ƒj d  d d d ƒj d  d d d ƒj d  d d d ƒj d  d d d d	 d
 ƒj d |  ƒ } t | j ƒ d k r| j j ƒ  d  S| j	 j
 d  k	 r1t | j	 j
 d ƒ } n d  } t j j | j d ƒ r¦t | j d d | j	 j d | d | j	 j d | j	 j d | j	 j d | j	 j ƒnh t j j | j d ƒ r	t | j d d | j	 j d | d | j	 j d | j	 j d | j	 j ƒn d  GHd  S(!   Nt   usages@   smtbx.absolute_structure directory|cif|fcf|hkl|ins/res [options]s   --extt   actiont   storet   defaultR   s   --nut   typeR1   s   --atomic_form_factorsR^   s   --inelastic_form_factorsR   s   --debugt
   store_trues	   --verboses   --logs   --chiral_space_groups_onlys   --outlier_cutoff_factort   argsi   t   wbi    R   R   R   R   R   R   R'   s(   Please provide a valid file or directory(   R   t   enable_symmetry_comprehensivet   optionR(   t   processt   lenR¤   t   parsert	   show_helpt   optionsR   t   openR   R   t   isdirR!   R   R   R   R   R   t   isfileR   R'   (   R¤   t   command_lineR   (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/smtbx/command_line/absolute_structure.pyt   run©   sX    																		""t   __main__i   (   t
   __future__R    t   cctbx.array_familyR   Rp   R-   t	   iotbx.cift   iotbx.cif.buildersR   t   iotbx.shelxR   t   iotbx.option_parserR   t   scitbx.mathR   t   smtbxR   R   R   R)   R(   R{   R!   R   R,   R7   R9   R@   R±   t   __name__t   argv(    (    (    sS   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/smtbx/command_line/absolute_structure.pyt   <module>   s0   $		$	#	2