ó
‚™xTc           @   sî   d  d l  m Z d  d l Z d  d l m Z d  d l m Z m Z d  d l Z d  d l	 Z	 d  d l
 Z
 d  d l Z e j j d ƒ Z e Z d d e j d „ Z d „  Z d „  Z d	 e j f d
 „  ƒ  YZ e d k rê e e j d ƒ n  d S(   iÿÿÿÿ(   t   divisionN(   t   runtime_utils(   t   Sorryt   Usages…  
add_conformations
  .caption = This utility will duplicate any set of atoms (by default, the     entire input model) to create alternate conformations.  If the new     occupancy is not specified, it will be split evently between each     conformation.  Please be aware that if alternate conformations or     reduced-occupancy atoms are already present in the starting model, the     program behavior is not well-defined, and it may fail.
  .style = auto_align caption_img:icons/custom/iotbx.pdb.add_conformations64.png
{
  pdb_file = None
    .type = path
    .short_caption = PDB file
    .style = bold file_type:pdb noauto
  atom_selection = None
    .type = str
    .input_size = 400
    .style = bold noauto
  output = None
    .type = path
    .short_caption = Output file
    .style = bold file_type:pdb new_file noauto
  n_confs = 2
    .type = int
    .short_caption = Total number of conformations
    .style = bold spinner min:2 max:16 noauto
  new_occ = None
    .type = float
    .short_caption = New occupancy
    .style = noauto
  new_altloc = B
    .type = str
    .short_caption = Start at altloc
    .input_size = 64
    .style = noauto
}
c   '   	   C   s.  t  |  ƒ d k r; | d  k r; t d d t j ƒ  ƒ ‚ n  d d l m } d  } | d  k rœg  } t j d d ƒ } x	|  D]} t j	 j
 | ƒ r(| j t j	 j | ƒ ƒ } | j d k rê | j } | j t j j d	 | j ƒ ƒ q}| j d
 k r| j | j ƒ q}t d | j | f ƒ ‚ q| y | j d | ƒ }	 Wn/ t k
 ro}
 t d | t |
 ƒ f ƒ ‚ q| X| j |	 ƒ q| Wt j d | ƒ j ƒ  } n  t | ƒ | j } | d  k ræ| j | j ƒ } | j d ƒ | j } n  | j d  k rd | j | _ | d | j IJn  d d l  m! } | j" ƒ  } | j# ƒ  } | j$ ƒ  | j% ƒ  } | j& d  k	 r±| j' ƒ  } | j( | j& ƒ j) ƒ  } | j* d ƒ d k rÃt d ƒ ‚ qÃn | j+ | d ƒ } x' t, | ƒ D] \ } } | | | _- qÐWxH| j. ƒ  D]:} x1| j/ ƒ  D]#} t  | j0 ƒ  ƒ } x| j1 ƒ  D]ú} d } xë| j2 ƒ  D]Ý} | j# ƒ  } | j3 ƒ  } | j* d ƒ d k r| j4 d k r,| d k rØg  | D] } | j5 ƒ  ^ q } t d d d j6 | ƒ ƒ ‚ q5| j4 | j7 k r5g  | D] } | j5 ƒ  ^ qñ} t d d d j6 | ƒ ƒ ‚ q5n	 d | _4 | j8 ƒ  } | j7 } xÑt9 | j d ƒ D]¹} | j: ƒ  }  | |  _4 | j* d ƒ d k rd }! d }" x)|  j# ƒ  D]e } | j- d k rÌ|  j; |! ƒ n6 | j< | j ƒ | |" j< | |" | j ƒ |! d 7}! |" d 7}" q§Wn³ x° t= | |  j# ƒ  ƒ D]™ \ }# }$ |# j> | j } | d k rn| d IJ| |# j5 ƒ  IJn- | d k  r›t d |# j5 ƒ  d d ƒ ‚ n  |# j< |# j> | j ƒ |$ j< | j ƒ q)W|  j# ƒ  j% ƒ  | j* d ƒ k sít? ‚ | j@ | d |  ƒ | d 7} tA | ƒ } q^Wn  | d 7} qKWq2WqWqúW| j# ƒ  j% ƒ  }% | j# ƒ  j$ ƒ  | jB ƒ  | jC d  k r¨t j	 jD | j ƒ }& t j	 jE |& ƒ d d | _C n  tF | jC d ƒ } | jG d j6 | jH jI ƒ  ƒ d ƒ | jG | jJ ƒ  ƒ | jK ƒ  | d  | IJ| d! |% IJ| d" | jC IJ| jC S(#   Ni    s6   iotbx.pdb.add_conformations model.pdb [selection=...]
s   Full parameters:
iÿÿÿÿ(   t   file_readert
   home_scopet    t   pdbs   add_conformations.pdb_file="%s"t   phils   Unknown file type '%s' (%s)t   args   Error parsing '%s': %st   sourcesg      ð?s   Setting new occupancy to %.2f(   t   flexi   s   Empty selection.s1   Atom group included in selection already has one s   or more alternate conformers:
s   
s/   Atom group included in selection has an altloc s'   identical to the new_altloc parameter:
t   As   WARNING: zero-occupancy atom:s#   Atom occupancy dropped below zero:
s   
new_occ may be set s	   too high.s
   _split.pdbt   ws   Old model: %d atomss   Modified model: %d atomss   Wrote %s(L   t   lent   NoneR   t   master_philt   as_strt   iotbxR   t!   command_line_argument_interpretert   ost   patht   isfilet   any_filet   abspatht	   file_typet   file_objectt   appendt   libtbxR   t   parset	   file_nameR   t   processt   RuntimeErrort   strt   fetcht   extractt   validate_paramst   add_conformationst   pdb_filet   assert_file_typet   new_occt   n_confst   scitbx.array_familyR   t   construct_hierarchyt   atomst   reset_i_seqt   sizet   atom_selectiont   atom_selection_cachet	   selectiont   as_intt   countt   intt	   enumeratet   tmpt   modelst   chainst
   conformerst   residue_groupst   atom_groupst   extract_tmp_as_size_tt   altloct   format_atom_recordt   joint
   new_altloct   extract_occt   ranget   detached_copyt   remove_atomt   set_occt   zipt   occt   AssertionErrort   insert_atom_groupt   increment_altloct   atoms_reset_serialt   outputt   basenamet   splitextt   opent   writet   inputt   crystallographic_sectiont   as_pdb_stringt   close('   t   argst   paramst   outR   t   pdb_int	   user_philt   interpreterR	   t   ft   arg_philt   eR   t	   hierarchyt	   all_atomst   n_atomst   cacheR1   t   i_seqt   atomt   modelt   chainR)   t   residue_groupt   i_agt
   atom_groupt	   old_atomst   flagst   at	   atoms_errt   old_occR@   t   nt	   new_groupt   j_atomt   k_atomt   old_atomt   new_atomt   n_atoms_newt	   base_name(    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/pdb_add_conformations.pyt   run3   sà    			 
	
			
"
'

 #
c         C   s�   |  j  ƒ  r t j } n< |  j ƒ  r0 t j } n$ |  j ƒ  rH t j } n t d ƒ ‚ | j |  ƒ d } | t	 | ƒ k rˆ t
 d ƒ ‚ n  | | S(   Ns!   altloc must be a letter or digit.i   s   Uh-oh, out of altlocs.(   t   isuppert   stringt	   uppercaset   islowert	   lowercaset   isdigitt   digitsR   t   indexR   R    (   R=   t   letterst   i(    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/pdb_add_conformations.pyRJ   ¬   s    c         C   sË   |  j  }  |  j d  k r' t d ƒ ‚ n  |  j d  k sK t |  j ƒ d k rZ t d ƒ ‚ n  |  j d k  rx t d ƒ ‚ n  |  j d  k rš d |  j |  _ n  |  j d k  s¸ |  j d k rÇ t d ƒ ‚ n  t S(	   Ns   Please specify a PDB file!i   s0   new_altloc must be a single character (e.g. 'B')i   s+   Number of conformations must be at least 2!g      ð?i    s!   new_occ must be between 0 and 1.0(	   R%   R&   R   R   R@   R   R)   R(   t   True(   RV   (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/pdb_add_conformations.pyR$   º   s    	$t   launcherc           B   s   e  Z d  „  Z RS(   c         C   s   t  d t |  j ƒ d t j ƒ S(   NRU   RW   (   Rv   t   listRU   t   syst   stdout(   t   self(    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/pdb_add_conformations.pyRv   Ê   s    (   t   __name__t
   __module__Rv   (    (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/pdb_add_conformations.pyR‚   É   s   t   __main__i   (    (   t
   __future__R    t   libtbx.philR   R   t   libtbx.utilsR   R   t   libtbx.load_envRx   R   R„   R   R   R   t   master_paramsR   R…   Rv   RJ   R$   t   target_with_save_resultR‚   R‡   t   argv(    (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/iotbx/command_line/pdb_add_conformations.pyt   <module>   s    	$	y		