ó
±™xTc           @   sþ  d  d l  m Z d  d l Z d  d l m Z d  d l Z d  d l m Z d  d l 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 m Z d  d	 l m Z d  d
 l m Z d  d l m Z d Z d e Z d „  Z d „  Z d „  Z  d „  Z! e j" d „ Z# d „  Z$ d „  Z% d e& f d „  ƒ  YZ' d e j( f d „  ƒ  YZ) d „  Z* d „  Z+ e, d k rúe ƒ  Z- e j" Z. e' e j/ d d e. ƒZ0 e- j1 ƒ  Z2 e0 j. d e2 IJe3 e2 e0 j4 ƒ d k  sút5 ‚ n  d S(    iÿÿÿÿ(   t   divisionN(   t   monomer_library(   t   combine_unique_pdb_files(   t   flex(   t   user_plus_sys_timet   Sorry(   t   runtime_utils(   t   StringIO(   t   ramalyze(   t   RotamerEval(   t   substitute_sss¿  silent = False
  .type = bool
write_geo_file = True
  .type = bool
file_name = None
  .type = path
  .short_caption = Model file
  .style = file_type:pdb bold input_file
show_states = False
  .type = bool
restraints = None
  .type = path
  .multiple = True
  .short_caption = Restraints
  .style = file_type:cif bold input_file
restraints_directory = None
  .type = path
  .style = directory
output_file_name_prefix = None
  .type = str
  .input_size = 400
  .style = bold
directory = None
  .type = path
  .short_caption = Output directory
  .style = output_dir
include scope libtbx.phil.interface.tracking_params
fix_rotamer_outliers = True
  .type = bool
  .help = Remove outliers
reference_restraints {
  restrain_starting_coord_selection = None
    .type = str
    .help = Atom selection string: restraint selected to starting position
    .short_caption = Restrain selection
    .input_size = 400
  coordinate_sigma = 0.5
    .type = float
    .help = sigma value for coordinates restrained to starting positions
}
stop_for_unknowns = True
  .type = bool
  .short_caption = Stop for unknown residues
  .style = noauto
include scope mmtbx.monomer_library.pdb_interpretation.grand_master_phil_str
secondary_structure_restraints = False
  .type = bool
  .short_caption = Secondary structure restraints
secondary_structure
  .alias = refinement.secondary_structure
{
  include scope mmtbx.secondary_structure.sec_str_master_phil
}
c_beta_restraints=True
  .type = bool
sv  
%s
selection = all
  .type = str
  .help = Atom selection string: selected atoms are subject to move
  .short_caption = Atom selection
  .input_size = 400
minimization
  .help = Geometry minimization parameters
  .short_caption = Minimization parameters
  .expert_level=1
{
  max_iterations = 500
    .type = int
    .help = Maximun number of minimization iterations
    .short_caption = Max. iterations
    .style = noauto
  macro_cycles = 5
    .type = int
    .help = Number of minimization macro-cycles
  alternate_nonbonded_off_on = False
    .type = bool
    .short_caption = Macro cycles
    .style = noauto
  rmsd_bonds_termination_cutoff = 0
    .type = float
    .help = stop after reaching specified cutoff value
  rmsd_angles_termination_cutoff = 0
    .type = float
    .help = stop after reaching specified cutoff value
  grms_termination_cutoff = 0
    .type = float
    .help = stop after reaching specified cutoff value
  move
    .help = Define what to include into refinement target
    .short_caption = Geometry terms
    .style = box auto_align columns:3 noauto
  {
  bond = True
    .type = bool
    .short_caption = Bond lengths
  nonbonded = True
    .type = bool
    .short_caption = Nonbonded distances
  angle = True
    .type = bool
    .short_caption = Bond angle
  dihedral = True
    .type = bool
    .short_caption = Dihedral angle
  chirality = True
    .type = bool
    .short_caption = Chirality
  planarity = True
    .type = bool
    .short_caption = Planarity
  parallelity = True
    .type = bool
    .short_caption = Parallelity
  }
}
  include scope mmtbx.geometry_restraints.external.external_energy_params_str
c           C   s   t  j j t d t ƒS(   Nt   process_includes(   t   iotbxt   philt   parset   master_params_strt   True(    (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/geometry_minimization.pyt   master_paramsŽ   s    c         C   s0   | d d IJ| |  IJ| d t  |  ƒ IJd  S(   Nt   -iO   t   *(   t   len(   t   mt   log(    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/geometry_minimization.pyt	   broadcast‘   s    
c         C   s0   |  d d IJd } |  | IJ|  d d IJd  S(   NR   iO   s§   phenix.geometry_minimization: regularize model geometry

Usage examples:
  phenix.geometry_minimization model.pdb
  phenix.geometry_minimization model.pdb ligands.cif
(    (   R   t   msg(    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/geometry_minimization.pyt   format_usage_message–   s    
c         C   s'  g  } t  |  j ƒ } | j d  k	 r7 | j | j ƒ n  |  j } t } | d  k rµ t } d d  l } t	 d | ƒ } | j
 j d d  d t j | j ƒ ƒ j ƒ  j d d ƒ j ƒ  } n  t  |  j ƒ } t | j ƒ d k r0d d  l } xH | j D]: }	 | j j d |	 d	 t ƒ j ƒ  }
 | j |	 |
 f ƒ qï Wn  | j d  k	 rÃt j | j ƒ } xo | D]d }	 |	 j d
 ƒ rXt j j | j |	 ƒ } | j j d | d	 t ƒ j ƒ  }
 | j | |
 f ƒ qXqXWn  t j j  d | d | j! d | j" d | d | d | j! j# ƒ } | j$ d | ƒ \ } } | | _% | S(   Niÿÿÿÿt
   file_namest   source_infot   linest   buffer_sizei
   i    t	   file_patht   stricts   .cift   crystal_symmetryt   pdb_interpretation_paramst   stop_for_unknownsR   t   cif_objectst   use_neutron_distancest   pdb_file_names(&   t   listR%   t	   file_namet   Nonet   appendR    t   FalseR   t	   iotbx.pdbR   t   pdbt   inputR   t
   std_stringt   raw_recordst   xray_structure_simplet*   cubic_unit_cell_around_centered_scatterersR#   R   t
   restraintst	   iotbx.cift   cift   readert   modelt   restraints_directoryt   ost   listdirt   endswitht   patht   joint   mmtbxt   utilst   process_pdb_file_srvt   pdb_interpretationR"   R$   t   process_pdb_filest!   is_non_crystallographic_unit_cell(   t   inputst   paramsR   R%   t   csRB   R   t   pdb_combinedR#   R'   t
   cif_objectt   restraint_filest	   full_patht   processed_pdb_files_srvt   processed_pdb_filet   junk(    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/geometry_minimization.pyt   process_input_files¢   sL    	!				c         C   sç  d& } | d& k	 rE | j ƒ  j ƒ  j ƒ  } d | k p? d | k } n  d& } | j j } d& } | j rš| d IJd& }	 t | j j ƒ t | j j	 ƒ d k rË t
 j j j d | j j d | j j	 ƒ }	 n |  j j j ƒ  }	 |	 d& k	 r‰t d |  j j d | d	 |	 d
 | j d | j d | j d | j d | j d | j d | j d | j d | j d | d t ƒ } | j |  j j j ƒ  j ƒ  ƒ qš| d d IJn  | j rt  j j! d | j d |  d t" j# ƒ  d | d | ƒ }
 |
 j$ d | ƒ |
 j% d | d d& ƒ } | j& } n  |  j' d t d t d | j( j) d d  d! | d | ƒ } t  j* j+ d" | d# t, ƒ } | d& k	 rŽ| j- rŽ| j. j/ j0 d$ | ƒ n  | d& k	 r¬| j1 ƒ  | _1 n  | j2 rãt  j3 j4 j5 d" | j6 d% |  j j d | ƒ n  | S('   s¦   This function should be transfered to be a member of processed_pdb_file
     class. It should be used in all places where geometry_restraints_manager
     is needed. t   Ht   Ds:   Substituting secondary structure elements with ideal ones.i    t   helicest   sheetst   real_ht   xray_structuret   ss_annotationt   sigma_on_reference_non_sst   sigma_on_reference_helixt   sigma_on_reference_sheett   sigma_on_torsion_sst   sigma_on_torsion_nonsst   sigma_on_ramachandrant   sigma_on_cbetat   n_macrot   n_iterR   t   verboses/   No secondary structure definition found in phils-   or HELIX/SHEET records. No substitution done.RD   RK   t   tmp_dirt   assume_hydrogens_all_missingt   hbond_paramst   show_energiest   show_nonbonded_clashscoret   params_editst   plain_pairs_radiusi   t   hydrogen_bond_proxiest   geometryt   normalizationt   proxiest   pdb_hierarchyN(7   R(   t   scattering_type_registryt   type_count_dictt   keyst   secondary_structuret   idealizationt   enabledR   t   helixt   sheetR   R,   t
   annotationt   all_chain_proxiest   pdb_inpt   extract_secondary_structureR
   Rj   RU   RV   RW   RX   RY   RZ   R[   R\   R]   R*   t   set_sites_cartt   atomst   extract_xyzt   secondary_structure_restraintsR=   t   process_structureR8   t   getcwdt
   initializet   create_hbond_proxiesRi   t   geometry_restraints_managert   geometry_restraintst   editsR2   t   managerR   t   restrain_torsion_anglest   generic_restraints_managert   reference_managert&   add_existing_reference_torsion_proxiesR    t   c_beta_restraintst   torsion_restraintsR>   t   add_c_beta_restraintsRg   (   RK   RS   RD   R   t   has_hdt	   sctr_keysRa   t	   id_paramst   reference_torsion_proxiest   annott   sec_strt   build_proxiesRg   t   restraints_manager(    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/geometry_minimization.pyt   get_geometry_restraints_managerÌ   sŒ    	
										
		
			
		
		
c	   
   +   C   sÍ   t  j j j d | d | d | j d | j d |  d | j j d | j j d | j j	 d	 | j j
 d
 | j j d | j j d | j j d t d | j d | j d | j d | d | d | d | d | ƒ }	 d  S(   NR‘   Rj   t   max_number_of_iterationst   number_of_macro_cyclest	   selectiont   bondt	   nonbondedt   anglet   dihedralt	   chiralityt	   planarityt   parallelityt   generic_restraintst   rmsd_bonds_termination_cutofft   rmsd_angles_termination_cutofft   alternate_nonbonded_off_ont   cdlt   states_collectort   correct_hydrogenst   fix_rotamer_outliersR   (   R=   t
   refinementt   geometry_minimizationt   run2t   max_iterationst   macro_cyclest   moveR–   R—   R˜   R™   Rš   R›   Rœ   R*   Rž   RŸ   R    (
   R•   R‘   Rj   RD   R¡   R£   R¢   R¤   R   t   o(    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/geometry_minimization.pyt   run_minimization   s,    
					c   
   '   C   sÇ   d d  l  } | j j d | d | d | j d | j d |  d | j j d | j j d	 | j j d
 | j j	 d | j j
 d | j j d | j j d t d | j d | j d | d | d | d | ƒ }	 d  S(   NiÿÿÿÿR‘   Rj   R“   R”   R•   R–   R—   R˜   R™   Rš   R›   Rœ   R�   t   grms_termination_cutoffR    R   t   prmtopt   ambcrdt
   use_sander(   t)   amber_adaptbx.amber_geometry_minimizationt   amber_geometry_minimizationt   runR¨   R©   Rª   R–   R—   R˜   R™   Rš   R›   Rœ   R*   R­   R    (
   R•   R‘   Rj   RD   R   R®   R¯   R°   t   amber_adaptbxR«   (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/geometry_minimization.pyt   run_minimization_amberA  s*    					R³   c           B   sª   e  Z d  Z e d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   t	   minimizedc         C   s§   | |  _  d  |  _ d  |  _ | |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _	 d  |  _
 g  |  _ d |  _ d  |  _ g  |  _ | |  _ d  |  _ d  |  _ |  j ƒ  d  S(   Ni    (   R   R(   RD   RC   t   argsRK   RS   Rj   R•   t   restrain_selectiont   grmt   time_stringst
   total_timet   output_file_nameR%   t   use_directory_prefixt   sites_cart_startR¢   t   _run__execute(   t   selfR·   R   R½   (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/geometry_minimization.pyt   __init__b  s$    																	c         C   s¦   |  j  |  j d ƒ |  j  |  j d ƒ |  j  |  j d ƒ |  j  |  j d ƒ |  j  |  j d ƒ |  j  |  j d ƒ |  j  |  j d ƒ |  j  |  j d ƒ |  j	 ƒ  d  S(	   Ns   Initialization, inputss   Processing inputss   Atom selections   Geometry Restraintss   Add reference restraintst   Minimizations   Write PDB files   Write GEO file(
   t   callerR}   t   process_inputst   atom_selectiont   get_restraintst   reference_restraintst   minimizationt   write_pdb_filet   write_geo_filet
   show_times(   RÀ   (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/geometry_minimization.pyt	   __executev  s    c         C   s   t  ƒ  S(   N(   R   (   RÀ   (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/geometry_minimization.pyR   ƒ  s    c         C   s_   t  ƒ  } | d | ƒ | j ƒ  } |  j | 7_ |  j j d | t d | ƒ j ƒ  f ƒ d  S(   Nt   prefixs     %s: %ss   %8.3f(   R   t   elapsedR»   Rº   R)   t   strt   strip(   RÀ   t   funcRÍ   t   timert   t(    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/geometry_minimization.pyRÃ   †  s
    	c         C   sï   t  d d d |  j ƒ d } x2 |  j D]' } t | ƒ } | | k r& | } q& q& Wd t | ƒ d } x_ |  j D]T } | j ƒ  } d j | t | ƒ d  ƒ } |  j | | I| t | ƒ d IJqo W|  j d	 t d
 |  j ƒ j ƒ  IJd  S(   NR   s   Detailed timingR   i    s     %-t   st    i   s     Sum of individual times: %ss   %8.3f(	   R   R   Rº   R   RÏ   t   splitR<   R»   RÐ   (   RÀ   t   max_lent   tst   ltst   fmtt   stst   l(    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/geometry_minimization.pyRË   �  s     )
c         C   s   t  d |  j ƒ d  S(   NR   (   R   R   (   RÀ   (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/geometry_minimization.pyR   ›  s    c         C   sû   |  j  d  k r t j |  _  n  t |  j ƒ d k r@ |  j ƒ  n  |  j ƒ  } t j	 j
 d |  j d | ƒ |  _ |  j j j ƒ  |  _ |  j j r� t ƒ  |  _  n  t d | d |  j  ƒ |  j j j d d d |  j  ƒ t |  j ƒ d k r÷ t j d ƒ n  d  S(	   Ni    R·   R   R   R   RÍ   s     t   out(   R   R(   t   syst   stdoutR   R·   R   R   R=   R>   t   process_command_line_argsRC   RD   t   extractt   silentR   R   t   showt   exit(   RÀ   RÍ   t   parsed(    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/geometry_minimization.pyR}   ž  s       c         C   s   t  d | d |  j ƒ t |  j j ƒ |  _ |  j j d  k	 rV |  j j |  j j ƒ n  t	 d |  j d |  j d |  j ƒ |  _
 |  j
 j |  _ |  j
 j ƒ  |  _ |  j j ƒ  j ƒ  |  _ |  j
 j j |  _ |  j j rü t j j d |  j d |  j ƒ |  _ n  d  S(   NR   R   RC   RD   RS   Rj   (   R   R   R&   RC   R%   RD   R'   R(   R)   RM   RK   RB   t   output_crystal_symmetryRS   t
   sites_cartt	   deep_copyR¾   Rt   Rj   t   show_statesR=   R>   t   statesR¢   (   RÀ   RÍ   (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/geometry_minimization.pyRÄ   «  s    	c         C   s†   t  d | d |  j ƒ t j j d |  j j d |  j j ƒ |  _ |  j d t	 |  j j
 t ƒ ƒ t	 |  j j ƒ  ƒ f IJ|  j ƒ  d  S(   NR   R   Rt   t   strings#     selected %s atoms out of total %s(   R   R   R=   R>   RÅ   RK   Rt   RD   R•   RÏ   t   countR   t   sizet'   generate_reference_restraints_selection(   RÀ   RÍ   (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/geometry_minimization.pyRÅ   ¼  s    
.c         C   sS   |  j  j j d  k	 rO t j j d |  j j d |  j  j j ƒ |  _	 |  j
 ƒ  n  d  S(   NRt   Rë   (   RD   RÇ   t!   restrain_starting_coord_selectionR(   R=   R>   RÅ   RK   Rt   R¸   t4   exclude_outliers_from_reference_restraints_selection(   RÀ   (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/geometry_minimization.pyRî   Å  s    	c         C   sZ  |  j  d  k	 rVt d |  j d t ƒ j ƒ  } t j |  j  j ƒ  | ƒ } t j	 ƒ  } t
 ƒ  } x½ |  j j ƒ  D]¬ } x£ | j ƒ  D]• } xŒ | j ƒ  D]~ } | j ƒ  } t | ƒ d k r½ q“ n  xQ | j ƒ  D]C } | j ƒ  }	 | j |	 ƒ d k rÊ | j |	 j ƒ  j ƒ  ƒ qÊ qÊ Wq“ Wq€ Wqm Wt j |  j  j ƒ  | ƒ } | | B}
 |  j  |
 @|  _  n  d  S(   NRj   t   outliers_onlyi   t   OUTLIER(   R¸   R(   R   Rj   R*   t   outlier_selectionR   t   boolRí   t   size_tR	   t   modelst   chainst   residue_groupst
   conformersR   t   only_residuet   evaluate_residuet   extendRx   t   extract_i_seq(   RÀ   t   rama_outlier_selectiont   rota_outlier_selectiont   rotamer_managerR6   t   chaint   residue_groupRù   t	   conformert   residueRó   (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/geometry_minimization.pyRð   Î  s*    		 ,	
c      	   C   sJ   t  d | d |  j ƒ t d |  j d |  j d |  j d |  j ƒ |  _ d  S(   NR   R   RK   RS   RD   (   R   R   R’   RK   RS   RD   R¹   (   RÀ   RÍ   (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/geometry_minimization.pyRÆ   æ  s    			c         C   sð   |  j  d  k	 rì t d | d |  j ƒ |  j j ƒ  j ƒ  j |  j  ƒ } |  j j	 j
 j j d | d |  j  d |  j j j ƒ |  j j	 j
 j j t k s› t ‚ |  j j	 j
 j j d  k	 s¼ t ‚ t |  j j	 j
 j j ƒ t | ƒ k sì t ‚ n  d  S(   NR   R   Rç   R•   t   sigma(   R¸   R(   R   R   RS   Rç   Rè   t   selectR¹   Rg   R„   R…   t   add_coordinate_restraintsRD   RÇ   t   coordinate_sigmat   flagst	   referenceR   t   AssertionErrort   reference_coordinate_proxiesR   (   RÀ   RÍ   t   restrain_sites_cart(    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/geometry_minimization.pyRÇ   î  s    	!c         C   sy  t  d | d |  j ƒ t } t |  j d ƒ r@ |  j j j } n  | ré |  j j j sd t d ƒ ‚ n  |  j j j	 s‚ t d ƒ ‚ n  t
 d |  j d |  j d |  j j d	 |  j d |  j d
 |  j j j d |  j j j	 d |  j j j ƒ nj t d |  j d |  j d |  j j d	 |  j d |  j j j d |  j j j d |  j j d |  j d |  j ƒ 	|  j j d |  j j ƒ  j ƒ  ƒ d  S(   NR   R   t   ambersF   Need to supply topology file using amber.topology_file_name=<filename>sH   Need to supply topology file using amber.coordinate_file_name=<filename>R•   R‘   RD   Rj   R®   R¯   R°   R¡   R£   R¤   R¢   Rç   (   R   R   R*   t   hasattrRD   R  t	   use_ambert   topology_file_nameR   t   coordinate_file_nameRµ   R•   R¹   RÈ   Rj   R°   R¬   R@   R¡   R£   R¤   R¢   RS   Rw   Rx   Ry   (   RÀ   RÍ   R  (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/geometry_minimization.pyRÈ      s<    								
c         C   sŸ  t  d | d |  j ƒ |  j j |  j ƒ |  j j } |  j j } d |  j d } | d  k r¶ t
 j j |  j d ƒ } t d | j d ƒ ƒ } | d k r¥ | | n | |  | } n |  j j d } |  j ró | d  k	 ró t
 j j | | ƒ } n  |  j d I| IJ|  j |  j ƒ  IJ|  j rG|  j j d | d	 |  j j ƒ  ƒ n |  j j d | ƒ |  j r†|  j j d | j d d
 ƒ ƒ n  t
 j j | ƒ |  _ d  S(   NR   R   t   _s   .pdbi    t   .s     output file name:R'   R    s   _all_states.pdb(   R   R   Rj   t   adopt_xray_structureRS   RD   t   output_file_name_prefixt	   directoryt   _pdb_suffixR(   R8   R;   t   basenameR%   t   maxt   rfindR½   R<   t   min_max_mean_shiftRæ   RÉ   R    R¢   t   writet   replacet   abspathR¼   (   RÀ   RÍ   t   ofnR  t   suffixt   pfnt   ind(    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/geometry_minimization.pyRÉ   !  s,    '		c         C   s3   d t  j |  j |  j j ƒ  j ƒ  ƒ j ƒ  j ƒ  S(   Ns0   min,max,mean shift from start: %6.3f %6.3f %6.3f(   R   t   sqrtR¾   RS   Rç   t   dott   min_max_meant   as_tuple(   RÀ   (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/geometry_minimization.pyR  :  s    	c         C   s  |  j  j r|  j d  k	 rt d | d |  j ƒ t j j |  j	 ƒ j
 d d ƒ } |  j  j } |  j r‹ | d  k	 r‹ t j j | | ƒ } n  t | d ƒ } |  j d I| IJ| d IJ| J|  j } | j ƒ  } | j ƒ  j ƒ  } |  j j j d | d	 | d
 | ƒ | j ƒ  n  d  S(   NR   R   s   .pdbs   .geot   wbs     output file name:s&   # Geometry restraints after refinementRç   t   site_labelst   f(   RD   RÊ   R¹   R(   R   R   R8   R;   R  R¼   R  R  R½   R<   t   fileRS   Rç   t
   scattererst   extract_labelsRg   t   show_sortedt   close(   RÀ   RÍ   R   R  R*  RS   Rç   R)  (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/geometry_minimization.pyRÊ   ?  s$    !
	(   t   __name__t
   __module__R  R   RÁ   R¿   R   RÃ   RË   R   R}   RÄ   RÅ   Rî   Rð   RÆ   RÇ   RÈ   RÉ   R  RÊ   (    (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/geometry_minimization.pyR³   `  s$   															!		t   launcherc           B   s   e  Z d  „  Z RS(   c         C   sB   t  j |  j ƒ t  j |  j ƒ t d |  j d t j d t ƒ j	 S(   NR·   R   R½   (
   R8   t   mkdirt
   output_dirt   chdirR³   R·   RÞ   Rß   R*   R¼   (   RÀ   (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/geometry_minimization.pyR³   T  s    (   R0  R1  R³   (    (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/geometry_minimization.pyR2  S  s   c         C   s_   |  j  d  k r t d ƒ ‚ n  |  j d  k	 r[ t j j |  j ƒ s[ t d |  j ƒ ‚ q[ n  t S(   Ns(   Please specify a model file to minimize.s3   The path '%s' does not exist or is not a directory.(   R'   R(   R   R7   R8   R;   t   isdirR   (   RD   (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/geometry_minimization.pyt   validate_paramsZ  s    c         C   s2   g  } |  d  k	 r( | j |  d f ƒ n  | g  f S(   Ns   Minimized model(   R(   R)   (   t   resultt   output_files(    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/geometry_minimization.pyt
   finish_jobc  s    t   __main__i   R   s   Overall runtime: %-8.3fgš™™™™™¹?(6   t
   __future__R    t&   mmtbx.refinement.geometry_minimizationR=   R   t   mmtbx.utilsR+   R   t
   iotbx.philR   t   cctbx.array_familyR   t   libtbx.utilsR   R   t   libtbxR   R8   t   mmtbx.secondary_structureRÞ   t	   cStringIOR   t   mmtbx.validation.ramalyzeR   t   mmtbx.rotamer.rotamer_evalR	   t   mmtbx.secondary_structure.buildR
   t   base_params_strR   R   R   R   RM   Rß   R’   R¬   Rµ   t   objectR³   t   target_with_save_resultR2  R7  R:  R0  RÒ   R   t   argvR«   RÎ   t   ttt   absR»   R  (    (    (    sV   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/mmtbx/command_line/geometry_minimization.pyt   <module>   sF   :@
				+S	!	ó					