ó
±™xTc           @   sê   d  d l  m Z d  d l 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 Z d  d l m Z d  d l Z d  d l Z e j j d ƒ Z d	 „  Z d
 d „ Z e d k ræ e d e j d ƒ n  d S(   iÿÿÿÿ(   t   divisionN(   t   amino_acid_codes(   t   flex(   t	   superpose(   t   matrix(   t   Sorrys:  super {
  fixed = None
    .type = str
  moving = None
    .type = str
  moved = "moved.pdb"
    .type = str
  alignment_style = *local global
    .type = choice
  gap_opening_penalty = 20
    .type = float
  gap_extension_penalty = 2
    .type = float
  similarity_matrix = *blosum50 dayhoff
    .type = choice
}
c         C   s(  g  } t  j ƒ  } t  j ƒ  } |  j ƒ  j ƒ  d } xÛ | j ƒ  D]Í } xÄ | j ƒ  d j ƒ  D]¬ } t j	 j
 d | j ƒ d k rˆ q^ n  | j } t j | } | j | ƒ t }	 d }
 x6 | j ƒ  D]( } | j d k rÄ | j }
 t }	 PqÄ qÄ W| j |
 ƒ | j |	 ƒ q^ WqA Wd j | ƒ | | f S(   Ni    t   namet   common_amino_acids    CA t    (   i    i    i    (   R   t   vec3_doublet   boolt   construct_hierarchyt   modelst   chainst
   conformerst   residuest   iotbxt   pdbt   common_residue_names_get_classt   resnameR   t   one_letter_given_three_lettert   appendt   Falset   atomsR   t   xyzt   Truet   join(   t	   pdb_inputt   seqt   sitest	   use_sitest   modelt   chaint   resit   resnt   singlet   useR   t   atom(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/super.pyt   extract_sequence_and_sites   s,    			s   mmtbx.superc   "      C   sé  t  |  ƒ d k r d | GHd  Sd GHd G| GHd GHd GHd GHd GHg  } t j d d ƒ } d  } d  } x³ |  D]« } t j j | ƒ r½ | d  k r™ | } q| d  k r® | } qt d ƒ ‚ ql y | j d	 | ƒ } Wn4 t	 k
 ré ‚  ql t
 k
 r	t d
 | ƒ ‚ ql X| j | ƒ ql Wt j d | ƒ } | j ƒ  }	 d „  }
 | d  k rp|	 j j d  k r||
 d ƒ q|n | |	 j _ | d  k rª|	 j j d  k r¶|
 d ƒ q¶n | |	 j _ d GHd GHHt j d |	 ƒ } | j ƒ  Hd GHHd G|	 j j GHt j j d |	 j j ƒ } Hd G|	 j j GHt j j d |	 j j ƒ } Ht d | ƒ \ } } } t d | ƒ \ } } } d GHt j j d | d | d |	 j j d |	 j j d |	 j j d |	 j j ƒ } d GHH| j ƒ  } | j ƒ  } | j  d ƒ } | j  d  ƒ } t  | j! ƒ | j! j  d! ƒ } | j" d" | d# d$ d% d& d' d d( d d) d* d+ | t# d& | ƒ d+ | | t# d& | ƒ f ƒ t$ j% ƒ  } t$ j% ƒ  } xt t& | j' | j( | ƒ D]Z \ } } } | d5 k rÅq¤n  | | r¤| | r¤| j | | ƒ | j | | ƒ q¤q¤Wd, GHd- GHd. G| j) ƒ  GH| j) ƒ  d k r<t d/ ƒ ‚ n  t* j+ d0 | d1 | ƒ } | j, | j- ƒ  ƒ } d2 | GHHd3 |	 j j. GH| j/ ƒ  }  x7 |  j0 ƒ  D]) }! | j1 t2 j3 |! j4 ƒ | j5 |! _4 q›W|  j6 d |	 j j. d4 t7 ƒ Hd  S(6   Ni    s4   usage: %s fixed.pdb moving.pdb [parameter=value ...]t   #s   #                       s<   # A lightweight sequence-based structure superposition tool.t
   home_scopet   supers   Too many file names.t   args   Unknown file or keyword: %st   sourcesc         S   s   t  d t ƒ  ƒ ‚ d  S(   Ns†   Missing file name for %(what)s structure:
  Please add
    %(what)s=file_name
  to the command line to specify the %(what)s structure.(   R   t   vars(   t   what(    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/super.pyt   raise_missingV   s    t   fixedt   movings   #Parameters used:s   #phil __ON__t   python_objects   #phil __OFF__s   Reading fixed structure:t	   file_names   Reading moving structure:R   s   Computing sequence alignment...t   seq_at   seq_bt   gap_opening_penaltyt   gap_extension_penaltyt   similarity_functiont   styles   done.t   |t   *t   -t   matchest
   block_sizei2   t   n_blocki   t   top_namet   bottom_namet   comments   The alignment used in the superposition is shown below.

The sequence identity (fraction of | symbols) is %4.1f%%
of the aligned length of the fixed molecule sequence.

The sequence similarity (fraction of | and * symbols) is %4.1f%%
of the aligned length of the fixed molecule sequence.
g      Y@s=   Performing least-squares superposition of C-alpha atom pairs:s4     Number of C-alpha atoms pairs in matching residuess     indicated by | or * above:s   No matching C-alpha atoms.t   reference_sitest   other_sitess.     RMSD between the aligned C-alpha atoms: %.3fs   Writing moved pdb to file: %st
   append_end(   R9   R:   (8   t   lent   master_paramst!   command_line_argument_interpretert   Nonet   ost   patht   isfileR   t   processt   KeyboardInterruptt	   ExceptionR   t   fetcht   extractR)   R/   R0   t   formatt   showR   R   t   inputR&   t   mmtbxt	   alignmentt   alignR5   R6   t   similarity_matrixt   alignment_stylet   extract_alignmentR<   t   countt   at   pretty_printt   maxR   R	   t   zipt   i_seqs_at   i_seqs_bt   sizeR   t   least_squares_fitt   rms_differencet   other_sites_best_fitt   movedR   R   t   rR   t   colR   t   tt   write_pdb_fileR   ("   t   argst   command_namet   phil_objectst   argument_interpretert   fixed_pdb_file_namet   moving_pdb_file_nameR*   t   command_line_paramst   working_paramst   paramsR.   t	   fixed_pdbt
   moving_pdbt	   fixed_seqt   fixed_sitest   fixed_site_flagst
   moving_seqt   moving_sitest   moving_site_flagst	   align_objRU   R<   t   equalt   similart   totalt   fixed_sites_selt   moving_sites_selt   iat   ibt   mt   lsq_fitt   rmsdt   pdb_hierarchyR%   (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/super.pyt   run7   sÐ    				 	 	   	  
		7( 			't   __main__Rj   i   (   t
   __future__R    t   mmtbx.alignmentRT   t	   iotbx.pdbR   R   t   cctbx.array_familyR   t   scitbx.mathR   R   t   libtbx.philt   libtbxt   libtbx.utilsR   t   sysRI   t   philt   parseRF   R&   R‡   t   __name__t   argv(    (    (    sF   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/super.pyt   <module>   s   			