ó
ƒ™xTc           @   s‚   d  d l  m Z d  d l Z d  d l Z d  d l Z e j Z d „  Z d „  Z e	 d k r~ d  d l
 Z
 e d e
 j d ƒ n  d S(   iÿÿÿÿ(   t   divisionNc   
         sÍ   d d  l  } | j j d |  d | ƒ ‰  d d l m } | j d |  d | ƒ } ‡  f d †  } | d | ƒ | j d | ƒ } | d | ƒ x< | j d | d	 | ƒ D]" \ } }	 ˆ  j d
 | d |	 ƒ q£ Wˆ  S(   Niÿÿÿÿt   n_sitest	   threshold(   t   utilst
   n_verticest	   edge_listc            sW   xP t  |  ƒ D]B \ } } x3 | D]+ } | | k  r  ˆ  j d | d | ƒ q  q  Wq Wd  S(   Nt   it   j(   t	   enumeratet   add_exclusion(   t	   edge_setsR   t   edge_setR   (   t   result(    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/examples/pdb_tardy_conf_sampling_simple.pyt   add_exclusions   s    R
   t   bond_bending_edge_setsR   R   (	   t   scitbx.r3_utilst   r3_utilst   clash_detector_simplet   scitbx.graphR   t   construct_edge_setsR   t   potential_implied_edge_listR	   (
   R   t	   bond_listR   t   scitbxR   t	   bond_setsR   t
   angle_setsR   R   (    (   R   s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/examples/pdb_tardy_conf_sampling_simple.pyt   build_clash_detector   s    	c            sS  t  j  ƒ  } d d  l ‰ d d l m ‰  d d  l ‰ d d  l ‰ d d l m ‰ d d l m	 ‰ d t  j  ƒ  | GHd ‡  ‡ ‡ ‡ ‡ f d † } t
 |  ƒ d k rÄ x© |  D] } | d	 | ƒ qª Wn‹ d d  l } | j j d
 ƒ së d GHd  S| j j d d d t j ƒ } | d  k r4d d l m } | d ƒ ‚ n  d G| GH| d	 | ƒ d GHd  S(   Niÿÿÿÿ(   t   build_simple_two_way_bond_sets(   t   extract_edge_list(   t   flexs   Time importing extensions: %.2fg       @c            sï  t  j  ƒ  } ˆ j j d |  ƒ } | j ƒ  } d t  j  ƒ  | GHd G| j ƒ  GH| j ƒ  | j ƒ  } t  j  ƒ  } ˆ d ˆ  d | d | j ƒ  ƒ ƒ } d t  j  ƒ  | GHd Gt | ƒ GHt  j  ƒ  } ˆ j	 j
 j d	 | d
 | ƒ } d t  j  ƒ  | GHt  j  ƒ  } ˆ j j d g  | D] } | j ƒ  ^ qd	 | d d g | j ƒ  d | d d  ƒ }	 |	 j ƒ  }
 |	 j ƒ  |
 d  } |
 d j d ƒ sŒt ‚ |
 j ƒ  d } d t  j  ƒ  | GHd G| GHˆ j ƒ  } d t j } t d | j ƒ  d | d | ƒ } t  j  ƒ  } d } d } xx t | ƒ D]j } | j ƒ  } | j | j d | ƒ | ƒ |	 j d | ƒ |	 j ƒ  } | j d | ƒ r| d 7} qqWt  j  ƒ  | } d | | f GHd | | d GH| d k rÑd | | GHn  d | | d  | | f GHd  S(!   Nt	   file_names   Time reading pdb file: %.2fs   Number of atoms:R
   t
   sites_cartt   elementss   Time building bond list: %.2fs   Number of bonds:t   sitesR   s   Time building tardy tree: %.2ft   labelst   massesi   t
   tardy_treet   potential_obji    s   Time building tardy model: %.2fs   Degrees of freedom:i   R   R   R   i'  t   sizet   q_packeds   time / %d conf: %.2f secondss   time / conf: %.3f milli secondsiè  s   conf / second: %.2fs9   Fraction of conformations with clashes: %d / %d = %.2f %%g      Y@(   t   timet   pdbt   inputt   atomsR%   t(   set_chemical_element_simple_if_necessaryt   extract_xyzt   extract_elementt   lent   graphR#   t	   constructt
   rigid_bodyt   tardy_modelt   id_strt   Nonet   q_size_each_jointt   pack_qt   all_eqt   AssertionErrort   mersenne_twistert   matht   piR   t   xranget	   deep_copyt   extendt   random_doublet   unpack_qt   sites_movedt	   has_clash(   R   t   clash_thresholdt
   time_startt   pdb_inpt	   pdb_atomsR   R   R#   t   atomR2   R5   t   q_fixedt   q_size_movingt   mtt   two_pit   clash_detectort   n_conft   n_clash_conft   i_conft   qt   conf_sites_cartt	   time_diff(   R   R   R   t   iotbxR   (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/examples/pdb_tardy_conf_sampling_simple.pyt   process&   sl    
				i    R   t   phenix_regressions/   skipping test: phenix_regression not available.t   relative_paths   phenix_regression/pdb/atp.pdbt   test(   t   Sorrys,   Missing command-line argument: pdb file names   Using file:t   OK(   R'   t	   iotbx.pdbt)   cctbx.crystal.distance_based_connectivityR   t   scitbx.rigid_bodyt   scitbx.graph.tardy_treet   scitbx.graph.utilsR   t   scitbx.array_familyR   R.   t   libtbx.load_envt   envt
   has_modulet   find_in_repositoriest   opt   isfileR4   t   libtbx.utilsRX   (   t   argsRD   RT   R   t   libtbxRX   (    (   R   R   R   RS   R   s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/examples/pdb_tardy_conf_sampling_simple.pyt   run   s2    <	t   __main__Rg   i   (   t
   __future__R    R:   R'   t   ost   pathRd   R   Ri   t   __name__t   syst   argv(    (    (    s[   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/examples/pdb_tardy_conf_sampling_simple.pyt   <module>   s   			Y