ó
ƒ™xTc           @   sz   d  d l  m Z d  d l Z d  d l m Z d  d l Z d  d l Z d d d d „ Z e	 d k rv e e j
 d	 ƒ n  d S(
   iÿÿÿÿ(   t   divisionN(   t   flexs   R-free-flagsg      à?i    c            sE  t  |  ƒ d k s t ‚ |  d } d t j j | ƒ } d G| GHt j j d | ƒ } | j d | ƒ } | j	 ƒ  ‰ | j
 ƒ  ‰  ‡  ‡ f d †  } | d ƒ }	 t j d	 | ƒ }
 |	 j |
 j d
 |	 j ƒ  ƒ ƒ } t | j ƒ  | d ƒ } d G| GHˆ  j | |  d ƒ | d ƒ | j d ˆ  d ˆ ƒ d G| GH| j d | ƒ d  S(   Ni   i    t
   less_free_s   Reading file:t	   file_namet   labelc            sŠ   ˆ  d k ˆ @j  ƒ  } ˆ  d k ˆ @j  ƒ  } | j ƒ  | j ƒ  ˆ j t ƒ k r` t d ƒ ‚ n  |  Gd G| j ƒ  GH|  Gd G| j ƒ  GH| S(   Ni    s]   Unexpected array of R-free flags:
  Expected: 0 for work reflections, 1 for test reflections.s   number of free reflections:s   number of work reflections:(   t
   iselectiont   sizet   countt   Truet   RuntimeError(   t   whatt   free_indicest   work_indices(   t   flagst   selection_valid(    sU   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/examples/mtz_convert_free_to_work.pyt   get_and_report   s    	t   Inputt   seedR   g      à?s2   Number of reflections converted from free to work:t   Outputt   valuesR   s   Writing file:(   t   lent   AssertionErrort   ost   patht   basenamet   iotbxt   mtzt   objectt
   get_columnR   t   extract_valuesR   t   mersenne_twistert   selectt   random_permutationR   t   intt   set_selectedt
   set_valuest   write(   t   argsR   t   convert_fractiont   random_seedt   input_file_namet   output_file_namet   mtz_objt   columnR   R   t   mtt   permuted_indicest	   n_convert(    (   R   R   sU   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/examples/mtz_convert_free_to_work.pyt   run   s(    
		
	t   __main__i   (   t
   __future__R    t	   iotbx.mtzR   t   cctbx.array_familyR   t   sysR   R/   t   __name__t   argv(    (    (    sU   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/examples/mtz_convert_free_to_work.pyt   <module>   s    