ó
Â™xTc           @   sØ   d  Z  d d l m Z d d l Z d d l Z d d l Z d d l Z d d l Z	 d d l
 Z	 d d l j Z e j d ƒ d „  Z d „  Z d e f d „  ƒ  YZ d	 e j f d
 „  ƒ  YZ e d k rÔ e j ƒ  n  d S(   s   Tests for superpose.pyiÿÿÿÿ(   t   divisionNi    c         C   s#   t  j j d d |  d t j j ƒ S(   Nt   relative_paths   phenix_regression/pdb/%st   test(   t   libtbxt   envt   find_in_repositoriest   ost   patht   isfile(   t   filename(    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/regression/tst_superpose.pyt   get_filename   s    c         C   sa   |  | k  s t  ‚ t j |  | ƒ } t j |  | ƒ } | | k  rW | } | } | } n  | | f S(   N(   t   AssertionErrort   randomt	   randrange(   t   leftt   rightt   xt   yt   tmp(    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/regression/tst_superpose.pyt   random_pair   s    	t   SuperposeExamplesc           B   s5   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   sÁ   t  j d d d d d d ƒ } t  j d d d d d d ƒ } | j  | ƒ \ } } | j d d	 ƒ | j  | ƒ \ } } | j d
 d ƒ | j  | ƒ \ } } | j | ƒ | j  | ƒ \ } } d  S(   NR	   s   1CBS.pdbt   desct   fixedt   presett   cas   1HMT.pdbt   movingt   allt	   selections   pepnames and (name ca) chain A(   t	   superposet   SuperposePDBt   select_updatet   selectomatic(   t   selfR   R   t   rmsdt   lsq(    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/regression/tst_superpose.pyt   test_example_presets!   s    c         C   sI   t  j d d d d ƒ } t  j d d d d ƒ } | j  | ƒ \ } } d  S(   NR	   s   na1.pdbR   R   s   na2.pdbR   (   R   R   (   R    R   R   R!   R"   (    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/regression/tst_superpose.pyt   test_example_na6   s    c         C   si   t  j d d d d d d ƒ } t  j j d d d d d d ƒ } x# | D] } | j  | ƒ \ } } qF Wd  S(	   NR	   s   1OAN.pdbR   R   R   R   s   1S6N.pdbR   (   R   R   t   open_models(   R    R   t   modelst   modelR!   R"   (    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/regression/tst_superpose.pyt   test_example_multiple=   s    !c         C   sm  i  } t  j d d ƒ } t  j d d ƒ } x– t | j j ƒ  ƒ d  D]{ } xr t | j j ƒ  ƒ d  D]W } | j d d d | j ƒ | j d d d | j ƒ | j  | ƒ | | j | j f <qd WqD Wt g  t | j	 ƒ  ƒ D] } | d ^ qÙ ƒ } d d j
 | ƒ GHxb | D]Z } g  | D] }	 | | |	 f d ^ q}
 d	 | Gd j
 g  |
 D] } d
 | ^ qMƒ GHqWd  S(   NR	   s   1AON.pdbi   R   R   t   chaini    s   	s   %s:	s   %0.2f(   R   R   t   listt   pdbt   chainsR   t   idt   sett   sortedt   keyst   join(   R    t   resultR   R   t   moving_chaint   fixed_chaint   iR0   t   key1t   key2t   rmsds(    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/regression/tst_superpose.pyt   test_example_pairwiseD   s      '/'c         C   s   d  S(   N(    (   R    (    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/regression/tst_superpose.pyt   test_example_sieveT   s    (   t   __name__t
   __module__R#   R$   R(   R9   R:   (    (    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/regression/tst_superpose.pyR       s
   				t   SuperposeTestc           B   s’   e  Z d  d d d „ Z d d d d „ Z d d d	 „ Z d
 d d „ Z d d „ Z d d d „ Z d d d „ Z d d d „ Z	 d d d „ Z
 RS(   s   fab_a_cut_1.pdbt   test_alignment_used_1gú~j¼t“h?c   
      C   sŸ   t  | ƒ } d | } d i | d 6| d 6d d 6d d 6} t j j d	 | d
 | g ƒ t j | ƒ } t j | ƒ } | j | ƒ \ } }	 |  j | | ƒ d  S(   Ns   %s.shifted.pdbsg   phenix.pdbtools %(filename)s output.file_name=%(filename_shifted)s remove="%(gap_selection)s" %(shift)sR	   t   filename_shifteds'   chain A and (resid 5:30 or resid 32:50)t   gap_selections2   sites.rotate="10 20 30" sites.translate="10 20 30"t   shiftt   commandt   result_file_names(   R
   R   t
   test_utilst   run_commandR   R   t
   assertLess(
   R    R	   R   t	   toleranceR?   t   cmdR   t   targetR!   R"   (    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/regression/tst_superpose.pyR>   ^   s    
s   fab_a_cut.pdbt   test_alignment_used_2c         C   sï   t  | ƒ } xÜ t d ƒ D]Î } d | | f } d t t d d ƒ t d d ƒ t d d	 ƒ ƒ } d
 i | d 6| d 6| d 6d d 6} t j j d | d | g ƒ t j | ƒ } t j | ƒ }	 | j |	 ƒ \ }
 } |  j	 |
 | ƒ q Wd  S(   Ni   s   %s.%s.shifted.pdbs7   chain A and (resid %s:%s or resid %s:%s or resid %s:%s)i    i   i   i#   i$   i2   sg   phenix.pdbtools %(filename)s output.file_name=%(filename_shifted)s remove="%(gap_selection)s" %(shift)sR	   R?   R@   s2   sites.rotate="10 20 30" sites.translate="10 20 30"RA   RB   RC   (
   R
   t   xranget   tupleR   R   RD   RE   R   R   RF   (   R    R	   R   RG   t   attemptR?   R@   RH   R   RI   R!   R"   (    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/regression/tst_superpose.pyRJ   n   s"    s
   enk_gm.pdbt   test_comprehensivec         C   s±  t  | ƒ } d d d g d d d g d d d g d d d g d d d	 g g } d
 } xV| D]N\ } } } d | | | f GHd | | f } d | | f }	 d i | d 6| d 6| d 6| d 6| d 6}
 t j j d |
 ƒ t j | d | ƒ} t j | d | ƒ} | j | ƒ \ } } | j | d |	 ƒt j j	 d | ƒ j
 ƒ  } t j j	 d |	 ƒ j
 ƒ  } | j d | ƒ } | r�|  j | d ƒ n |  j | d
 ƒ | d 7} q[ Wd  S(   Nt    t   Nones-   sites.rotate="1 2 3" sites.translate="4 5 6" s   chain A or resname HOHs   not (chain A or resname HOH)s   chain A or chain Cs   not (chain A or chain C)s   name CAs   not (name CA)i    sB   ========= shift: %s -- shift_selection: %s -- remove_selection: %ss   %s.%s.shifted.pdbs   %s.%s.fitted.pdbsŠ   phenix.pdbtools %(filename)s output.file_name=%(filename_shifted)s selection="%(shift_selection)s" remove="%(remove_selection)s" %(shift)sR	   R?   RA   t   shift_selectiont   remove_selectionRB   R   t	   file_namet   otherg      @i   (   R
   R   RD   RE   R   R   t   outputt   iotbxR+   t   inputt   xray_structure_simplet   mean_distancet   assertGreatert   assertAlmostEqual(   R    R	   R   t   testst   countRA   RQ   RR   R?   t   filename_fittedRH   R   RI   R!   R"   t
   xs_shiftedt	   xs_fittedt   check(    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/regression/tst_superpose.pyRN   „   s<    s	   phe_a.pdbt"   test_assert_anisou_warning_messagec         C   sÂ   t  | ƒ } d | } t j | ƒ } t j | ƒ } | j | ƒ \ } } | j | d | ƒt j j d | ƒ } | j ƒ  }	 |	 j ƒ  }
 |
 j	 ƒ  j
 ƒ  } | j d ƒ GH| j d ƒ s¾ t ‚ d  S(   Ns   %s.noaniso.pdbR	   RS   g      ð¿(   R
   R   R   RU   RV   R+   RW   t   construct_hierarchyt   atomst   extract_uijt	   as_doublet   all_eqR   (   R    R	   R   t   filename_outputR   RI   R!   R"   t   pit   pht   pat   uij(    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/regression/tst_superpose.pyRb   ¬   s    
t   test_erik_vogan_casec   	      C   s|   t  d ƒ } t  d ƒ } d | } t j | ƒ } t j | ƒ } | j | ƒ \ } } | j | d | ƒ|  j | d ƒ d  S(   Ns   rebuild03_ckpt04.pdbs   2C30.pdbs   %s.fitted.pdbR	   g      ð?(   R
   R   R   RU   RF   (	   R    R   t	   filename1t	   filename2Rh   R   RI   R!   R"   (    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/regression/tst_superpose.pyRm   »   s    
t   test_altlocs_1gü©ñÒMbP?c   
      C   s|   t  d ƒ } t  d ƒ } d | } t j | ƒ } t j | ƒ } | j | ƒ \ } }	 | j |	 d | ƒ|  j | | ƒ d  S(   Ns	   fab_1.pdbs	   fab_2.pdbs   %s.fitted.pdbR	   (   R
   R   R   RU   RF   (
   R    R   RG   Rn   Ro   Rh   R   RI   R!   R"   (    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/regression/tst_superpose.pyRp   Ë   s    
t2   test_same_models_many_differently_ordered_chains_1g¸…ëQ¸ž?c         C   s~   t  d ƒ } t  d ƒ } d | } t j | ƒ } t j | ƒ } | j | ƒ \ } }	 | j |	 d | ƒ}
 |  j | | ƒ d  S(   Ns   a1.pdbs   b1.pdbs   %s.fitted.pdbR	   (   R
   R   R   RU   RF   (   R    R   RG   Rn   Ro   Rh   R   RI   R!   R"   t   rmsd_output(    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/regression/tst_superpose.pyRq   Ý   s    
t2   test_same_models_many_differently_ordered_chains_2g¤p=
×£À?c         C   s~   t  d ƒ } t  d ƒ } d | } t j | ƒ } t j | ƒ } | j | ƒ \ } }	 | j |	 d | ƒ}
 |  j | | ƒ d  S(   Ns   a2.pdbs   b2.pdbs   %s.fitted.pdbR	   (   R
   R   R   RU   RF   (   R    R   RG   Rn   Ro   Rh   R   RI   R!   R"   Rr   (    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/regression/tst_superpose.pyRs   í   s    
t   test_rna_dnagffffffæ?c         C   s~   t  d ƒ } t  d ƒ } d | } t j | ƒ } t j | ƒ } | j | ƒ \ } }	 | j |	 d | ƒ}
 |  j | | ƒ d  S(   Ns   superpose_pdbs_a.pdbs   superpose_pdbs_b.pdbs   %s.fitted.pdbR	   (   R
   R   R   RU   RF   (   R    R   RG   Rn   Ro   Rh   R   RI   R!   R"   Rr   (    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/regression/tst_superpose.pyRt   ý   s    
(   R;   R<   R>   RJ   RN   Rb   Rm   Rp   Rq   Rs   Rt   (    (    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/regression/tst_superpose.pyR=   \   s   (t   __main__(   t   __doc__t
   __future__R    R   R   t   unittestt	   iotbx.pdbRV   t   libtbx.load_envR   t   libtbx.test_utilst   mmtbx.superposeR   t   seedR
   R   t   objectR   t   TestCaseR=   R;   t   main(    (    (    sL   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/regression/tst_superpose.pyt   <module>   s   		<°