ó
P™xTc           @   s�  d  d l  m 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 „  Z d	 „  Z d
 „  Z e d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ  d d d „ Z" e d d d  „ Z# d! „  Z$ d" „  Z% e& d# k r‰e% ƒ  n  d S($   iÿÿÿÿ(   t   divisionN(   t   adptbx(   t   eltbx(   t   random_structure(   t   debug_utils(   t   adopt_init_argsc         C   sg   d d  l  } | j j d d ƒ d  k r/ d GHn t j d |  d | d t ƒ d d l m } | ƒ  GHd  S(	   Niÿÿÿÿt   commandt   cnss"   Skipping tests: cns not available.t   argvt	   call_backt   show_cpu_times(   t   format_cpu_times(	   t   libtbx.patht   patht   full_command_patht   NoneR   t   parse_options_loop_space_groupst   Falset   libtbx.utilsR   (   t   argsR	   t   libtbxR   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/make_cns_input.pyt   tst_run_requiring_cns
   s    	c         C   s8   t  |  d ƒ } x | D] } | | IJq W| j ƒ  d  S(   Nt   w(   t   opent   close(   t	   file_namet	   cns_inputt   ft   line(    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/make_cns_input.pyt   write   s    c         C   sç   g  } | j  } | d ƒ xS |  D]K } | j j d d ƒ d } | d | ƒ | d | | f ƒ | d ƒ q  W| d ƒ | d ƒ | d	 ƒ | d
 ƒ x5 |  D]- } | j j d d ƒ d } | d | ƒ qž W| d ƒ | d ƒ | S(   Nt   topologyt    t    iüÿÿÿs     residue %ss1       atom %s mass=1 charge=0 {chemical}type=%s ends     endt   endt   segments     name=As$     molecule {res}name=%s number=1 end(   t   appendt   labelt   replace(   t
   scatterersR   t   at	   scatterert   name(    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/make_cns_input.pyR      s$    	






c         C   s  g  } | j  } d } x¢|  D]š} | j } | j } | j j ƒ  sI t ‚ t j | j ƒ } t	 j
 j | j ƒ j ƒ  }	 | j }
 | j } x3 t d ƒ D]% } | d d | | | | f ƒ q• W| s¢| d | | f ƒ | d | | f ƒ | d ƒ | d | j j d	 d
 ƒ d ƒ x< t d ƒ D]. } | d |	 j ƒ  | |	 j ƒ  | f ƒ q$W| d |	 j ƒ  f ƒ | d ƒ | d |
 | f ƒ | d | | f ƒ n  | d
 ƒ | d 7} q W| d ƒ | d ƒ | d ƒ | sõ| d ƒ | d ƒ n  | d
 ƒ | S(   Ni   i   s   do (%s=%.12g) (resid=%d)t   xyzs   do (q=%.12g) (resid=%d)s   do (b=%.12g) (resid=%d)t   xrays     scatter (chemical=%s)R   R    iüÿÿÿi   s       %.6g %.6gs       %.6gR!   s    do (scatter_fp=%.12g) (resid=%d)s!   do (scatter_fdp=%.12g) (resid=%d)s   coordinates orthogonalize ends   show (name) (all)s   show (chemical) (all)s   show (scatter_fp) (all)s   show (scatter_fdp) (all)(   R#   t   sitet	   occupancyt   flagst   use_u_iso_onlyt   AssertionErrorR   t   u_as_bt   u_isoR   t   xray_scatteringt   it1992t   scattering_typet   fetcht   fpt   fdpt   xrangeR$   R%   t
   array_of_at
   array_of_bt   c(   R&   t   xyz_onlyR   R'   t   residR(   t   xt   qt   bt   gaussianR7   R8   t   i(    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/make_cns_input.pyt   coordinates.   sF    					#
!&






c         C   sE   g  } | j  } | d ƒ | d |  j ƒ  ƒ | d ƒ | d ƒ | S(   NR+   s<     a=%.12g b=%.12g c=%.12g alpha=%.12g beta=%.12g gamma=%.12gR!   R    (   R#   t
   parameters(   t	   unit_cellR   R'   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/make_cns_input.pyt   xray_unit_cellS   s    	


c         C   s`   g  } | j  } | d ƒ x, |  D]$ } | d | j ƒ  j ƒ  d ƒ q  W| d ƒ | d ƒ | S(   NR+   s     symm=(t   )R!   R    (   R#   t   mod_positivet   as_xyz(   t   space_groupR   R'   t   s(    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/make_cns_input.pyt   xray_symmetry]   s    	
"

c         C   sa   t  |  j ƒ  ƒ } | j } | t |  j ƒ  ƒ ƒ | t |  j ƒ  ƒ ƒ | t |  j ƒ  ƒ ƒ | S(   N(   RG   RF   t   extendRM   RK   R   R&   RD   (   t	   structureR   t   e(    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/make_cns_input.pyt   xray_structureg   s    	c         C   sN   g  } | j  } | d ƒ |  r, | d ƒ n
 | d ƒ | d ƒ | d ƒ | S(   NR+   s     anomalous=trues     anomalous=falseR!   R    (   R#   (   t   flagR   R'   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/make_cns_input.pyt   xray_anomalouso   s    	



c         C   sÐ   t  |  ƒ d k s t ‚ t  |  ƒ d k rE | j ƒ  d  k	 sE t ‚ n  | j ƒ  rZ d } n d } g  } | j } | d ƒ | d |  d | f ƒ t  |  ƒ d k r¸ | d |  d ƒ n  | d	 ƒ | d
 ƒ | S(   Ni   i   t   complext   realR+   s/     declare name=%s domain=reciprocal type=%s endi    s1     declare name=%s domain=reciprocal type=real endR!   R    (   i   i   (   t   lenR0   t   sigmasR   t   is_complex_arrayR#   (   t   namest   miller_arrayt   typeR   R'   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/make_cns_input.pyt   xray_declare{   s     		


c   	      C   s@  t  |  ƒ d k s t ‚ t  |  ƒ d k rE | j ƒ  d  k	 sE t ‚ n  g  } | j } | d ƒ | d | j ƒ  j ƒ  ƒ | d ƒ | j ƒ  } | j ƒ  } x� t | j ƒ  ƒ D]m \ } } d | d |  d t	 | | ƒ f } | d  k	 r| d |  d t	 | | ƒ f 7} n  | | ƒ q­ W| d	 ƒ | d
 ƒ | d ƒ | S(   Ni   i   R+   s     nreflections %ds     reflections       index %d %d %ds    %s %si    s     endR!   R    (   i   i   (
   RV   R0   RW   R   R#   t   indicest   sizet   datat	   enumeratet   str(	   RY   RZ   R   R'   R_   RW   RC   t   hRL   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/make_cns_input.pyt   xray_reflectionŒ   s&     	

&%


c         C   sQ   g  } | j  } | d ƒ | d t |  ƒ t | ƒ f ƒ | d ƒ | d ƒ | S(   NR+   s     generate %s %sR!   R    (   R#   Ra   (   t   d_maxt   d_minR   R'   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/make_cns_input.pyt   xray_generate    s    	
 

c         C   sE   g  } | j  } | d ƒ | d t |  ƒ ƒ | d ƒ | d ƒ | S(   NR+   s     mapresolution %sR!   R    (   R#   Ra   (   Re   R   R'   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/make_cns_input.pyt   xray_mapresolution©   s    	


c         C   sQ   |  d k s t  ‚ g  } | j } | d ƒ | d |  ƒ | d ƒ | d ƒ | S(   Nt   directt   fftR+   s     method %sR!   R    (   Rh   Ri   (   R0   R#   (   t   methodR   R'   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/make_cns_input.pyt   xray_method²   s    	


c         C   s$   g  } | j  } | d t ƒ  ƒ | S(   NsÈ   xray
  declare name=%(reciprocal_space_array)s domain=reciprocal type=complex end
  predict
    mode=reciprocal
    to=%(reciprocal_space_array)s
    selection=(all)
    atomselection=(all)
  end
end
(   R#   t   vars(   t   reciprocal_space_arrayR   R'   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/make_cns_input.pyt   xray_predict¼   s
    	
c         C   sç   t  | ƒ } | j | j } } | t | j ƒ  ƒ ƒ | t d g | ƒ ƒ | t d g | ƒ ƒ | t |  ƒ ƒ | t d ƒ ƒ | t	 d ƒ ƒ | t d ƒ ƒ | t	 d ƒ ƒ | d ƒ | d ƒ | d ƒ | d	 ƒ | d
 ƒ | S(   Nt   fobsRh   t	   fcalc_dirRi   t	   fcalc_fftR+   s:     write reflections output=tmp.hkl fcalc_dir fcalc_fft endR!   R    t   stop(
   RQ   R#   RN   RS   t   anomalous_flagR\   Rc   Rg   Rk   Rn   (   Re   RO   t   f_obsR   R'   RP   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/make_cns_input.pyt!   script_predict_methods_comparisonÌ   s     




c           C   s   d g S(   Nsæ  xray
  declare name=fcalc domain=reciprocal type=complex end
  declare name=fpart domain=reciprocal type=complex end
  declare name=weight domain=reciprocal type=real end
  do (weight=1) (all)
  do (fpart=0) (all)
  associate reset
  associate fcalc (all)
  target=(resi(amplitude(fobs),(fcalc+fpart), weight))
  dtarget=(dresi(amplitude(fobs),(fcalc+fpart), weight))
  tselection (all)
end

flags exclude * include xref end

energy end

show (dx) (all)
show (dy) (all)
show (dz) (all)
(    (    (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/make_cns_input.pyt   xray_gradientsÞ   s    c         C   sœ   t  | ƒ } | j | j } } | t | j ƒ  ƒ ƒ | t d g | ƒ ƒ | t d g | ƒ ƒ | t |  ƒ ƒ | t | ƒ ƒ | t	 ƒ  ƒ | d ƒ | S(   NRo   Rr   (
   RQ   R#   RN   RS   Rs   R\   Rc   Rg   Rk   Rv   (   Re   Rt   RO   Rj   R   R'   RP   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/make_cns_input.pyt   script_xray_gradientsö   s    
t   parameter_nbondsc           B   s/   e  Z d  d d d d d d d d d d	 „
 Z RS(
   g      @g      @g      !@i   i   id   i    g      à?g      ø?c         C   s   t  |  t ƒ  ƒ d  S(   N(   R   t   locals(   t   selft   ctofnbt   ctonnbt   cutnbt
   irexponentt   nbxmodt   rconstt   repelt	   rexponentt	   tolerancet   wmin(    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/make_cns_input.pyt   __init__  s    
(   t   __name__t
   __module__R…   (    (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/make_cns_input.pyRx     s   t   parameter_nonbc           B   s   e  Z d  d d  d d „ Z RS(   gš™™™™™¹?g      ø?gÍÌÌÌÌÌô?c         C   s   t  |  t ƒ  ƒ d  S(   N(   R   Ry   (   Rz   t   epsilont   sigmat	   epsilon14t   sigma14(    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/make_cns_input.pyR…     s    (   R†   R‡   R…   (    (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/make_cns_input.pyRˆ     s   c         C   sÝ   | d  k r t ƒ  } n  | d  k r0 t ƒ  } n  t |  j ƒ  ƒ } | j | j } } | t |  j ƒ  ƒ ƒ | t	 |  j
 ƒ  ƒ ƒ | t |  j
 ƒ  d t ƒƒ | d t | ƒ ƒ | d t | ƒ ƒ | d t | ƒ ƒ | S(   NR=   s  param
  nbonds
    ctofnb=%(ctofnb).6g
    ctonnb=%(ctonnb).6g
    cutnb=%(cutnb).6g
    irexponent=%(irexponent).6g
    nbxmod=%(nbxmod).6g
    rconst=%(rconst).6g
    repel=%(repel).6g
    rexponent=%(rexponent).6g
    tolerance=%(tolerance).6g
    wmin=%(wmin).6g
  end
sD     nonb (all) %(epsilon).6g %(sigma).6g %(epsilon14).6g %(sigma14).6gsÔ   
  nbonds
    ?
  end
end

flags exclude * include vdw pvdw end

energy end

show (dx) (all)
show (dy) (all)
show (dz) (all)

distance
  from=(all)
  to=(all)
  cuton=0
  cutoff=%(cutnb).6g
  disp=print
end

stop(   R   Rx   Rˆ   RG   RF   R#   RN   RM   RK   R   R&   RD   t   TrueRl   (   RO   t   param_nbondst
   param_nonbR   R'   RP   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/make_cns_input.pyt   script_vdw_energy  s       g       @i    c         C   s¸   t  j |  d d d d d | d t d	 t ƒ} d
 s9 | rF | j ƒ  n  | j d | d d ƒ j ƒ  } x@ | t | ƒ g D], } t | | | ƒ t | | | d d ƒqw Wt	 d | ƒ d  S(   Nt   elementst   Nt   Ct   Ot   random_f_prime_d_ming      ð?t   random_f_double_primet   random_u_isot   random_occupancyi    Re   t	   algorithmRh   Rj   RO   (   R’   R“   R“   R”   (
   R   RQ   R�   t   show_summaryt   structure_factorst   f_calct   absRu   Rw   R�   (   t   space_group_infoRs   Re   t   verboseRO   Rœ   Rt   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/make_cns_input.pyt   exerciseK  s     		c         C   s1   x* t  t f D] } t | | d |  j ƒq Wd  S(   NRŸ   (   R   R�   R    t   Verbose(   R.   Rž   Rs   (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/make_cns_input.pyt   run_call_back`  s    c           C   s   t  j t j d t ƒ d  S(   Ni   (   R   R   t   sysR   R¢   (    (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/make_cns_input.pyt   rune  s    t   __main__('   t
   __future__R    t   cctbx.eltbx.xray_scatteringt   cctbxR   R   t   cctbx.developmentR   R   R   R   R£   R   R   R   R   RD   RG   RM   RQ   RS   R\   Rc   Rf   Rg   Rk   Rn   Ru   Rv   Rw   t   objectRx   Rˆ   R   R�   R    R¢   R¤   R†   (    (    (    sN   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/development/make_cns_input.pyt   <module>   sD   	
		%	
	
									
				4		