ó
ƒ™xTc           @   s›   d  d l  m Z d  d l Z d  d l m Z m Z d  d l Z d  d l Z e j	 j
 d ƒ Z d	 d d d „ Z d „  Z e d k r— e e j d ƒ n  d S(
   iÿÿÿÿ(   t   divisionN(   t   Sorryt   Usages~  
split_chains
{
  pdb_file = None
    .type = path
    .short_caption = PDB file
    .style = file_type:pdb input_file
  output_dir = None
    .type = path
    .short_caption = Output directory
    .style = directory
  output_base = None
    .type = str
    .short_caption = Base file name
  exclude_heteroatoms = True
    .type = bool
  preserve_symmetry = True
    .type = bool
}
c         C   s<  | d  k r t j } n  | d  k r„ t |  ƒ d k rE t d ƒ ‚ n  d d  l } | j j d |  d t d d ƒ } | j	 j
 ƒ  } n  t | ƒ | j } | j d  k r¸ t j ƒ  | _ n  | j d  k rò t j j t j j | j ƒ d ƒ | _ n  d d l m } d d	 l m } | j | j d
 d ƒ} | j d ƒ | j j ƒ  } | j j }	 t |	 j ƒ  ƒ d k r�t d d d ƒ ‚ n  i  }
 g  } x¨|	 j ƒ  d j  ƒ  D]�} | j! ƒ  d } | j" r| j# ƒ  rã| j$ ƒ  rãq¤qt | j% ƒ  ƒ d k rq¤qn  | j& } | d k r"d } n  |
 j' | d ƒ d k rUd | |
 | d f } n | } | |
 k rtd |
 | <n  |
 | c d 7<t j j( | j d | j | f ƒ } t) | d ƒ } | j* rç| j+ d j( | ƒ ƒ | j+ d ƒ n  | | ƒ } | j+ | j, ƒ  ƒ | j- ƒ  | j. | ƒ | d | j& | f IJq¤W| S(   Ni    s   pdb_split_chains.py model.pdbiÿÿÿÿt   argst   master_philt   pdb_file_defs   split_chains.pdb_file(   t   file_reader(   t   new_hierarchy_from_chaint
   force_typet   pdbi   s6   Multi-model PDB files are not supported.  You can use sD   iotbx.pdb.split_models to break the structure into individual model s   files.t    t   _s   %s-%ds	   %s_%s.pdbt   ws   
s   Wrote chain '%s' to %s(/   t   Nonet   syst   stdoutt   lenR   t
   iotbx.philt   philt   process_command_line_with_filesR   t   workt   extractt   validate_paramst   split_chainst
   output_dirt   ost   getcwdt   output_baset   patht   basenamet   splitextt   pdb_filet   iotbxR   t   iotbx.pdb.hierarchyR   t   any_filet   check_file_typet   file_objectt   crystallographic_sectiont	   hierarchyt   modelsR   t   chainst
   conformerst   exclude_heteroatomst
   is_proteint   is_nat   residue_groupst   idt   gett   joint   opent   preserve_symmetryt   writet   as_pdb_stringt   closet   append(   R   t   paramst   outR    t   cmdlineR   R   t   pdb_int   symmR&   t	   id_countst   outputst   chaint	   main_confR.   t   suffixt   output_filet   ft   new_hierarchy(    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/examples/pdb_split_chains.pyt   run   sr     	
	+					
c         C   s%   |  j  j d  k r! t d ƒ ‚ n  d  S(   Ns   PDB file not defined!(   R   R   R   R   (   R7   (    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/examples/pdb_split_chains.pyR   X   s    t   __main__i   (    (   t
   __future__R    t   libtbx.philt   libtbxt   libtbx.utilsR   R   R   R   R   t   parseR   R   RD   R   t   __name__t   argv(    (    (    sM   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/examples/pdb_split_chains.pyt   <module>   s   		;	