ó
±™xTc           @   sá   d  d l  m Z d  d l m Z d  d l m Z d  d l m Z m Z d  d l m	 Z	 d  d l
 Z d  d l Z d  d l Z d  d l Z d „  Z e j d „ Z d	 e f d
 „  ƒ  YZ d „  Z e d k rÝ e e j d ƒ n  d S(   iÿÿÿÿ(   t   division(   t   Sorry(   t   make_header(   t   Autot   adopt_init_args(   t   easy_mpNc          C   s;   d d l  m }  |  d t d t d t d t d t d d	 ƒ S(
   Niÿÿÿÿ(   t    generate_master_phil_with_inputst   enable_twin_lawt   enable_experimental_phasest    enable_pdb_interpretation_paramst   enable_stop_for_unknownst   enable_full_geometry_paramst   phil_strings  
selection = None
  .type = atom_selection
whole_residues = False
  .type = bool
  .help = If the initial selection includes partial residues, expand it to     include each residue in its entirety.
selection_delete = None
  .type = atom_selection
  .help = Designates atoms to be removed from the structure before     calculating the target map.
target_map = *mFo-DFc 2mFo-DFc
  .type = choice
occ = 0.5
  .type = float
  .help = Partial occupancy for selected atoms for map calculation.
rsr_after_anneal = False
  .type = bool
resolution_factor = 0.25
  .type = float
negate_surrounding_sites = False
  .type = bool
  .help = Set map values to negative around atoms outside of the target     selection.
reference_sigma = 0.5
  .type = float
  .help = Sigma for harmonic restraints for neighboring atoms not included     in the selection of interest.
wc = 1
  .type = float
  .help = Geometry restraints weight
n_confs = 1
  .type = int
nproc = Auto
  .type = int
random_seed = None
  .type = int
output {
  file_name = disordered.pdb
    .type = path
  include_starting_model = True
    .type = bool
  map_file_name = None
    .type = path
  verbose = False
    .type = bool
  debug = False
    .type = bool
}
simulated_annealing {
  include scope mmtbx.dynamics.simulated_annealing.master_params
}
(   t   mmtbx.command_lineR   t   Truet   False(   R   (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/generate_disorder.pyt   get_master_phil   s    5c         C   s¡  d d l  m } d d  l } d d  l  } d d  l } | j j d |  d t ƒ  d t d t d | d d	 ƒ } | j } | j	 } t
 | ƒ | j } t d
 d | ƒ| j j }	 |	 j | j ƒ }
 | j rí | j j j d |
 d | j ƒ  ƒ }
 n  |
 j t ƒ } | d k st ‚ | d | IJd  } | j d  k	 rF|	 j | j ƒ } n  | j d | j ƒ  d |
 d | d | j d | j j d | j d | j ƒ \ } } | } | j  d k rµ| } n  t! d | j" d | d | j d | d | d | j# ƒ  j$ ƒ  d | d |
 d | j d | d | j j% ƒ } | j ƒ  j& ƒ  j ƒ  } t' j( d | d t) | j* ƒ d  | j+ ƒ } | j j, j- ƒ  } | j j. rŽ| j/ d | ƒ n  g  } x· t0 | ƒ D]© \ } } | d  k	 s¿t ‚ | j1 ƒ  j2 ƒ  } | j ƒ  j3 | ƒ t4 | d! ƒ | _5 | j6 |
 ƒ j7 | j6 |
 ƒ ƒ } | d" | d! | f IJ| j8 | ƒ | j9 | ƒ q¡Wt: | j j; d# ƒ } | j< | j= d$ | j" ƒ ƒ | j> ƒ  | d% | j j; IJ| S(&   Niÿÿÿÿ(   t   alternate_conformationst   argst   master_philt   process_pdb_filet   create_fmodelt   outt   usage_stringsý   mmtbx.generate_disorder model.pdb data.mtz selection="resname ATP" [occ=0.6]

Perform simulatead annealing against an mFo-DFc map to generate possible
alternate conformations for a selection of atoms.  For development purposes
and experimentation only.
s   Generating disordert	   selectiont	   pdb_atomsi    s   %d atoms selectedt   fmodelt   selection_deletet   negate_surroundingt   map_file_namet   partial_occupancyt   resolution_factors   2mFo-DFct   xray_structuret   pdb_hierarchyt   processed_pdb_filet
   target_mapt   two_fofc_mapt   d_mint   paramst   debugt
   fixed_funct   iterablet	   processesi   s   Model %d: rmsd=%.3ft   wt   crystal_symmetrys   Wrote ensemble model to %s(?   t   mmtbx.buildingR   R   t   iotbx.pdb.hierarchyt   command_linet   load_model_and_dataR   R   R&   R   t   validate_paramsR!   R   R"   t   all_chain_proxiesR   t   whole_residuest   pdbt   atom_selectiont&   expand_selection_to_entire_atom_groupst   atomst   countt   AssertionErrort   NoneR   t   get_partial_omit_mapt	   deep_copyt   negate_surrounding_sitest   outputR   t   occR   R#   t   annealing_managerR    t   f_obsR%   R'   t   extract_xyzR   t   pool_mapt   ranget   n_confst   nproct	   hierarchyt   roott   include_starting_modelt   insertt	   enumeratet
   only_modelt   detached_copyt   set_xyzt   strt   idt   selectt   rms_differencet   appendt   append_modelt   opent	   file_namet   writet   as_pdb_stringt   close(   R   R   R   t   mmtbxt   iotbxt   cmdlineR&   R   R!   t   a_c_pR   t   n_selR   R$   t   fofc_mapR#   t   annealert	   sites_reft	   sites_allt   ensemblet   rmsdst   i_conft	   sites_newt   modelt   rmsdt   f(    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/generate_disorder.pyt   runJ   s˜    				
										
R@   c           B   s    e  Z e d d  „ Z d „  Z RS(   c         C   s   t  |  t ƒ  ƒ d  S(   N(   R   t   locals(   t   selfR    R!   R"   R#   R$   R%   R   R&   R   R'   R   (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/generate_disorder.pyt   __init__Ÿ   s    c         C   s  d d  l  } d d l m } |  j j } | d  k rS t t j ƒ  t j	 ƒ  ƒ } n  t
 j | ƒ | j | ƒ | j j d |  j j ƒ  d |  j j ƒ  d |  j d |  j d |  j d |  j d	 |  j d
 |  j j d |  j d |  j j d |  j j d |  j j d |  j d |  j ƒ } | S(   Niÿÿÿÿ(   t   flexR    R!   R"   R   R#   R%   R   R&   t   target_map_rsrt   rsr_after_annealt   reference_sigmat   wcR   R'   (   R-   t   scitbx.array_familyRn   R&   t   random_seedR:   t   intt   timet   ost   getpidt   randomt   seedt   set_random_seedt   buildingt   run_real_space_annealingR    t   deep_copy_scatterersR!   R<   R"   R   R#   R%   R   t   simulated_annealingR$   Rp   Rq   Rr   R   R'   (   Rl   t   i_procRZ   Rn   Rz   Rf   (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/generate_disorder.pyt   __call__­   s.    							N(   t   __name__t
   __module__R   R:   Rm   R�   (    (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/generate_disorder.pyR@   ž   s   c         C   s"   |  j  d  k r t d ƒ ‚ n  d  S(   Ns/   You must specificy an atom selection to anneal.(   R   R:   R   (   R&   (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/generate_disorder.pyR1   Æ   s    t   __main__i   (   t
   __future__R    t   libtbx.utilsR   t   libtbx.str_utilsR   t   libtbxR   R   R   t   os.pathRw   Ry   Rv   t   sysR   t   stdoutRj   t   objectR@   R1   R‚   t   argv(    (    (    sR   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/generate_disorder.pyt   <module>   s   	>T(	