ó
í™xTc           @   sÐ  d  d l  m Z d  d l Z d  d l m Z d  d l Z d  d l m Z d% Z d e	 f d	 „  ƒ  YZ
 d
 e
 f d „  ƒ  YZ d „  Z d Z d Z e d k rÌd  d l Z d  d l Z e j d e d e ƒ Z e j d d d d d ƒe j d d d d d d d ƒe j d d d d d d d ƒe j d d d  d d! d d" ƒe j ƒ  \ Z Z y e e e ƒ WqÌe k
 rŽe j ƒ  e j d# ƒ qÌe
 k
 rÈZ e j d$ e IJe j ƒ  e j d# ƒ qÌXn  d S(&   iÿÿÿÿ(   t   divisionN(   t   lstbx(   t
   refinements   .inss   .ress   .cift   command_line_errorc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/smtbx/command_line/refine.pyR      s    t   number_of_arguments_errorc           B   s   e  Z RS(    (   R   R   (    (    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/smtbx/command_line/refine.pyR      s    c      	   C   sM  d t  |  ƒ k o d k n s. t ƒ  ‚ n  |  d } d  } d  } t  |  ƒ d k ri |  d \ } } nT t  |  ƒ d k r½ t j j |  d ƒ \ } } | t k r° |  d } q½ |  d } n  t j j | ƒ \ } } | sä d } n  | d  k rý | d } n  | d  k rC| d k r%| d }	 }
 n | d | }	 }
 |	 |
 } n t j j | ƒ \ }	 }
 x3 | |
 f D]% } | t k rht d	 | ƒ ‚ qhqhWx9 | | f D]+ } t j j | ƒ sžt d
 | ƒ ‚ qžqžWt j j | ƒ r| j	 rüt
 j d | IJqt d | ƒ ‚ n  | d k r9t j j d | d | ƒ } n t j j d | d | ƒ } xk | j j ƒ  D]Z } | j j t ƒ | j j ƒ  rœ| j j t ƒ n  | j j ƒ  rd| j j t ƒ qdqdWt j j d | j ƒ  d | j d | j d | j ƒ } | j  ƒ  |
 d k r!t! d |
 ƒ ‚ n  t" | d ƒ � } | j j# | ƒ Wd  QXd  S(   Ni   i   i    i   s   .inss   .hkls   .ress   -outs   unsupported extension: %ss   No such file %ss'   
WARNING: file %s will be overwritten.
s@   refuse to overwrite file %s (use option 'overwrite' to force it)s   .cift   modelt   reflectionst
   ins_or_rest   hklt   non_linear_lst   n_max_iterationst   gradient_thresholdt   step_thresholds"   Write refined structure to %s filet   w($   t   lenR   t   Nonet   ost   patht   splitextt   allowed_input_file_extensionsR   t   isfilet	   overwritet   syst   stderrR   R   t   from_cift
   from_shelxt   xray_structuret
   scattererst   flagst   set_grad_sitet   Truet	   use_u_isot   set_grad_u_isot   use_u_anisot   set_grad_u_anisoR   t   normal_eqns_solvingt   naive_iterationst   least_squarest
   max_cyclest   stop_if_max_derivative_belowt   stop_if_shift_norm_belowt   dot   NotImplementedErrort   opent   as_cif_simple(   t	   filenamest   optionst   input_filenamet   output_filenamet   reflections_filenamet   _t   extt   in_roott   in_extt   out_roott   out_extt   filenamet   xmt   sct   stepst   out(    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/smtbx/command_line/refine.pyt   run   sr    "
 		

	  		
s‚   refine [options] INPUT
refine [options] INPUT REFLECTIONS
refine [options] INPUT OUTPUT
refine [options] INPUT REFLECTIONS OUTPUT
s+  Supported formats for the INPUT and OUTPUT files are CIF and ShelX
whereas REFLECTIONS file format may be any of those supported
by iotbx.reflection_file_reader.

A certain amount of guessing is done by the program:
- if INPUT lacks any extension, a .ins extension is appended;
- if OUTPUT is not specified,
  o if INPUT is a .ins file, then OUTPUT is a .res file with the same root;
  o otherwise OUTPUT has the same extension as INPUT but with "-out"
    appended to INPUT root.
- if REFLECTIONS is not specified, it is INPUT root with a .hkl extension
t   __main__t   usaget   descriptions   --overwritet   actiont
   store_truet   helps   allows OUTPUT to be overwrittens   --stop-if-max-derivative-belowt   typet   floatt   defaultgH¯¼šò×z>sl   Stop refinement as soon as the largest absolute value of objective derivatives is below the given threshold.s   --stop-if-shift-norm-belowsm   Stop refinement as soon as the Euclidean norm of the vector of parameter shifts is below the given threshold.s   --max-cyclest   inti   sI   Stop refinement as soon as the given number of cycles have been performedi   s   
ERROR: %s
(   s   .inss   .ress   .cif(   t
   __future__R    R   t   scitbxR   t    scitbx.lstbx.normal_eqns_solvingt   smtbxR   R   t   RuntimeErrorR   R   R?   t
   here_usaget   here_descriptionR   R   t   optparset   OptionParsert   parsert
   add_optiont
   parse_argsR0   t   argst   print_usaget   exitt   errR   t
   print_help(    (    (    sG   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/smtbx/command_line/refine.pyt   <module>   sX   	O		

