ó
‚™xTc           @   s  d  d l  m Z 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 Z d  d l Z d  d l Z d e f d	 „  ƒ  YZ d d d d
 „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d d „ Z e d k re d e j d ƒ n  d S(   iÿÿÿÿ(   t   division(   t   crystal_symmetry_from_anyN(   t
   sdb_reader(   t   strudat(   t   option_parser(   t   euclidean_model_matchingt   MultipleEntriesErrorc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/emma.pyR      s    c         C   s‡  |  | g j  d  ƒ d k s! t ‚ | d  k rE t j j d |  ƒ } n t j j d d  d | ƒ } | j d | d t ƒ } | s‘ | j ƒ  d  k r¤ t	 d |  ƒ ‚ n  | j
 ƒ  d  k rÅ t	 d ƒ ‚ n  g  } xm | j ƒ  D]_ } | j t j d	 j t t | ƒ d ƒ | j | j | j g ƒ | j ƒ  j | j ƒ ƒ ƒ qØ Wt | ƒ d
 k sSt ‚ t j | j ƒ  | ƒ } |  d  k	 rƒ|  | _ n  | S(   Ni   t	   file_namet   source_infot   linest   crystal_symmetryt   weak_symmetrys*   Unit cell parameters unknown for model %s.s   Space group unknown.t   :i    (   t   countt   Nonet   AssertionErrort   iotbxt   pdbt   inputR   t   Truet	   unit_cellt   RuntimeErrort   space_group_infot   atoms_with_labelst   appendt   emmat   positiont   joint   strt   lent   namet   resnamet   chain_idt   fractionalizet   xyzt   modelt   special_position_settingst   label(   R	   t   pdb_recordsR   t   pdb_inpt	   positionst   atomt   result(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/emma.pyt   get_emma_model_from_pdb   s2    !		 		c         C   s]  t  j t |  ƒ ƒ } t | ƒ d k r: t d |  ƒ ‚ n  t | ƒ d k sR t ‚ | d } | j d | j ƒ  d t ƒ } g  } xš t	 | j
 ƒ D]‰ \ } } | j ƒ  d  k r½ t d ƒ ‚ n  | j t j d j t | d ƒ | j | j f ƒ | j ƒ  j | j | j | j f ƒ ƒ ƒ q� Wt | ƒ d k s5t ‚ t j | j ƒ  | ƒ } | j | _ | S(   Ni   s+   SDB file %s may contain only one structure.i    t   other_symmetryt   forces   Unit cell parameters unknown.R   (   R   t   multi_sdb_parsert   openR   R   R   t   join_symmetryR   R   t	   enumeratet   sitesR   R   R   R   R   R   R   R   t   segidt   typeR#   t   xt   yt   zR%   R&   R	   R'   (   R	   R   t	   sdb_filest   sdb_fileR*   t   it   siteR,   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/emma.pyt   get_emma_model_from_sdb-   s,    
		%/		c         C   sç   g  } x¡ t  |  ƒ D]“ } | j ƒ  } t | ƒ d k  s | d j ƒ  d k rS q n  g  | d d !D] } t | ƒ ^ qa } | j t j d t t | ƒ d ƒ | ƒ ƒ q Wt | ƒ d k sÂ t	 ‚ t j
 | j ƒ  | ƒ } |  | _ | S(   Ni   i    R$   i   R=   (   R1   t   splitR   t   lowert   floatR   R   R   R   R   R%   R&   R'   (   R	   R   R*   t   linet   fldsR7   R=   R,   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/emma.pyt   get_emma_model_from_solveE   s    ( &1			c         C   s"   t  j j j d t |  ƒ ƒ j ƒ  S(   Nt   file(   t   cctbxt   xrayt	   structuret
   from_shelxR1   t   as_emma_model(   R	   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/emma.pyt   get_emma_model_from_insS   s    c         C   so   t  j t |  ƒ ƒ } t | j ƒ d k r= t d |  ƒ ‚ n  t | j ƒ d k sX t ‚ | j d j ƒ  j ƒ  S(   Ni   s/   strudat file %s may contain only one structure.i    (	   R   t   read_all_entriesR1   R   t   entriesR   R   t   as_xray_structureRJ   (   R	   t   strudat_entries(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/emma.pyt   get_emma_model_from_strudatV   s    c         C   s¡  t  j j |  ƒ s% t d |  ƒ ‚ n  y t d |  d | ƒ SWn< t k
 rR ‚  n) t k
 rz t j j	 |  ƒ r{ ‚  q{ n Xy t
 d |  d | ƒ SWn7 t k
 r¨ ‚  n$ t k
 r» ‚  n t k
 rË n Xy t d |  d | ƒ SWn$ t k
 rù ‚  n t k
 r	n Xy t d |  ƒ SWn$ t k
 r1‚  n t k
 rAn Xy t d |  ƒ SWn7 t k
 ri‚  n$ t k
 r|‚  n t k
 rŒn Xt d |  ƒ ‚ d  S(   Ns   File not found: %sR	   R   s#   Coordinate file %s: unknown format.(   t   ost   patht   isfileR   R-   t   KeyboardInterruptt	   ExceptionR   R   t   is_pdb_fileR>   R   RD   RK   RP   (   R	   R   (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/emma.pyt   get_emma_model^   sX      
    s   phenix.emmac         C   s5  t  d | d d d d | ƒ j ƒ  j d  d d d d	 d
 d d d d d d ƒj d  d d d d	 d d d d d d d ƒj d  d d d d d ƒj d |  d d ƒ } | j } | j ƒ  d  k sÒ | j ƒ  d  k rx8 | j D]* } | j	 d t
 j d | ƒ d t ƒ } qÜ Wn  | j j } | r+d G| GHn  | j j } d  G| GH| d! k rXt d" ‚ n  H| j j } | rtd# GHHn  g  } x- | j D]" } | j t d | d$ | ƒ ƒ q„W| d% j d& ƒ | d' j d( ƒ xm t | d) d* g ƒ D]V \ }	 }
 |	 j ƒ  d  k rt d+ |
 ƒ ‚ n  |	 j ƒ  d  k rât d, |
 ƒ ‚ qâqâWt j d- | d% d. | d' d/ | d0 | ƒ } | j ƒ  d% k rƒd1 GHHn® d  } t } xŸ | j D]” } | d  k sÄt | j ƒ | d2 k rd3 d4 GHH| j ƒ  | r| r| j d5 | d6 d7 d8 t j  ƒ n  t } n  | d  k r™t | j ƒ } q™q™Wd  S(9   Nt   usages
    [options]s(    reference_coordinates other_coordinatest   descriptions!   Example: %s model1.pdb model2.sdbs   --output_pdbt   actiont   storeR6   R   t   defaultt    t   helps>   Output pdb: second model transformed to best match first modelt   metavart   STRs   --toleranceRA   g      @s   match tolerancet   FLOATs   --diffraction_index_equivalentt
   store_trues4   Use only if models are diffraction-index equivalent.t   argst   nargsi   R.   R	   R/   s   Output pdb:s
   Tolerance:g        s$   Tolerance must be greater than zero.s(   Models are diffraction index equivalent.R   i    s   Reference modeli   s   Other modelt	   referencet   others(   Unit cell parameters unknown (%s model).s   Space group unknown (%s model).t   model1t   model2t	   tolerancet'   models_are_diffraction_index_equivalents   No matches.gš™™™™™É?t   .iO   t
   output_pdbt   scattering_typet   SEt   f(!   R   t   enable_symmetry_comprehensivet   optionR   t   processt   symmetryR   R   Rc   R2   R   t   extract_fromt   Falset   optionsRl   Ri   t
   ValueErrort   diffraction_index_equivalentR   RW   t   showt   zipR   R   t   model_matchest	   n_matchesR   t   refined_matchesR   t   pairst   get_transformed_model2t   syst   stdout(   Rc   t   command_namet   command_lineR   R	   Rl   Ri   Rx   t   emma_modelsR%   R'   R{   t   max_n_pairst   firstt   match(    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/emma.pyt   run†   s�    										"	

	%	
	t   __main__Rc   i   (   t
   __future__R    R   R   t	   iotbx.pdbt	   iotbx.cnsR   t   iotbx.kriberR   t   iotbx.option_parserR   RF   R   R   R€   RQ   t
   cctbx.xrayR   R   R   R-   R>   RD   RK   RP   RW   Rˆ   R   t   argv(    (    (    sE   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/emma.pyt   <module>   s(   					(N