ó
±™xTc           @   sx   d  d l  m Z d  d l m Z d  d l m Z d  d l Z d Z e j d „ Z	 e
 d k rt e	 d e j d	 ƒ n  d S(
   iÿÿÿÿ(   t   division(   t   make_sub_header(   t   null_outNs@  
model = None
  .type = path
chain_id = None
  .type = str
sequence = None
  .type = path
search_directory = None
  .type = path
output_file = ensemble.pdb
  .type = path
nproc = Auto
  .type = int
include scope mmtbx.building.make_library.master_phil
exclude_ids = None
  .type = strings
dry_run = False
  .type = bool
c         C   sÖ  d d l  m } d d  l } | j j d |  d t d d d d d	 d
 d d ƒ } | j j ƒ  } d  } | j	 d  k r‚ t
 d ƒ ‚ n  | j d  k	 rè | j | j d d ƒ} t | j ƒ } | d k rÕ | d | IJn  | j d j } n  | j | j	 d d ƒ}	 |	 j j }
 | j j j ƒ  } | j j j	 ƒ  } | j | ƒ xv|
 j ƒ  d j ƒ  D]^} | j d  k s{| j | j k rT| j ƒ  s³| j | j k rT| d | j IJqTqTq²| j j j d | j ƒ } | j | ƒ x’ | j ƒ  D]„ } | j ƒ  d } | j j ƒ  d& k rqèn  | j j j d | j d | j  ƒ } | j! ƒ  } d | _ | j" | ƒ | j# | ƒ qèW| d  k r®| j$ d d ƒ } | d | j t | ƒ f IJn  PqTqTW| d  k rÑt
 d ƒ ‚ n  t% d d | ƒ| j& d  | d
 | j' d | d! | d | ƒ } t( ƒ  } | j) d  k	 r;t* | j) d" ƒ } n  | d# IJ| j+ ƒ  } xa | j, D]V } | j- | j. } | d$ | d | | j- | j f IJ| j/ d% | d | f ƒ q[W| j/ | j0 ƒ  ƒ | j1 ƒ  | S('   Niÿÿÿÿ(   t   make_libraryt   argst   master_phil_stringt   pdb_file_deft   modelt   seq_file_deft   sequencet   directory_deft   search_directoryt   usage_strings5   mmtbx.get_related_ensemble [model.pdb] [seq.fa] [...]s+   No model (PDB or mmCIF file) was specified.t
   force_typet   seqi   s.   %d sequences in file - will only use the firsti    t   pdbs5   warning: matching chain '%s' is not protein, skippingt   idt    t   At   resseqt   icodet   padt   Xs2   Using sequence of chain '%s' (approx. %d residues)s=   No protein sequence could be extracted based on these inputs.s.   Finding related models and generating ensemblet   outt   reference_hierarchyt   paramst   ws   Assembling moved models:s     Model %d: %s:%ss   REMARK model %d is from %s
(   R   R   (2   t   mmtbx.buildingR   t
   iotbx.philt   philt   process_command_line_with_filest   master_phil_strt   workt   extractt   NoneR   t   SorryR	   t   get_filet   lent   file_objectt	   hierarchyR   t   roott   append_modelt   modelst   chainst   chain_idR   t
   is_proteint   chaint   append_chaint   residue_groupst   atom_groupst   altloct   stript   residue_groupR   R   t   detached_copyt   append_atom_groupt   append_residue_groupt   as_padded_sequenceR   t   extract_and_superposeR   R   t   output_filet   opent   as_multi_model_hierarchyt   selection_movedt   related_chainst   source_infot   writet   as_pdb_stringt   close(   R   R   R   t   iotbxt   cmdlineR   R	   t   seq_filet   n_seqst   pdb_fileR'   R   R   R.   t	   new_chainR4   t
   atom_groupt   new_rgt   new_agt   ensemblet   ft   ensemble_hierarchyt   kR?   (    (    sU   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/get_related_ensemble.pyt   run   s�    	!						

t   __main__R   i   (   t
   __future__R    t   libtbx.str_utilsR   t   libtbx.utilsR   t   sysR   t   stdoutRP   t   __name__t   argv(    (    (    sU   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/get_related_ensemble.pyt   <module>   s   M