def is_alive(self): from libtbx.development.timers import work_clock return work_clock() < self.maxtime
def run(self): # String describing the run that will be output to the specified file. outString = 'reduce2 v.{}, run {}\n'.format(version, datetime.now().strftime("%Y-%m-%d %H:%M:%S")) for a in sys.argv: outString += ' {}'.format(a) outString += '\n' make_sub_header('Loading Model', out=self.logger) # Get our model. self.model = self.data_manager.get_model() # Fix up bogus unit cell when it occurs by checking crystal symmetry. cs = self.model.crystal_symmetry() if (cs is None) or (cs.unit_cell() is None): self.model = shift_and_box_model(model = self.model) if self.params.approach == 'add': # Add Hydrogens to the model make_sub_header('Adding Hydrogens', out=self.logger) startAdd = work_clock() reduce_add_h_obj = reduce_hydrogen.place_hydrogens( model = self.model, n_terminal_charge=self.params.n_terminal_charge, stop_for_unknowns=True ) reduce_add_h_obj.run() self.model = reduce_add_h_obj.get_model() doneAdd = work_clock() # Interpret the model after shifting and adding Hydrogens to it so that # all of the needed fields are filled in when we use them below. # @todo Remove this once place_hydrogens() does all the interpretation we need. make_sub_header('Interpreting Hydrogenated Model', out=self.logger) startInt = work_clock() self.model.get_hierarchy().sort_atoms_in_place() self.model.get_hierarchy().atoms().reset_serial() p = mmtbx.model.manager.get_default_pdb_interpretation_params() p.pdb_interpretation.allow_polymer_cross_special_position=True p.pdb_interpretation.clash_guard.nonbonded_distance_threshold=None p.pdb_interpretation.use_neutron_distances = self.params.use_neutron_distances p.pdb_interpretation.proceed_with_excessive_length_bonds=True #p.pdb_interpretation.sort_atoms=True self.model.process(make_restraints=True, pdb_interpretation_params=p) # make restraints doneInt = work_clock() make_sub_header('Optimizing', out=self.logger) startOpt = work_clock() Optimizers.probePhil = self.params.probe opt = Optimizers.FastOptimizer(self.params.add_flip_movers, self.model, probeRadius=0.25, altID=self.params.alt_id, preferenceMagnitude=self.params.preference_magnitude) doneOpt = work_clock() outString += opt.getInfo() outString += 'Time to Add Hydrogen = '+str(doneAdd-startAdd)+'\n' outString += 'Time to Interpret = '+str(doneInt-startInt)+'\n' outString += 'Time to Optimize = '+str(doneOpt-startOpt)+'\n' else: # Removing Hydrogens from the model rather than adding them. make_sub_header('Removing Hydrogens', out=self.logger) sel = self.model.selection("element H") for a in self.model.get_atoms(): if sel[a.i_seq]: a.parent().remove_atom(a) # Re-process the model because we have removed some atoms that were previously # bonded. Don't make restraints during the reprocessing. # We had to do this to keep from crashing on a call to pair_proxies when generating # mmCIF files, so we always do it for safety. self.model.process(make_restraints=False, pdb_interpretation_params=p) make_sub_header('Writing output', out=self.logger) # Write the description output to the specified file. of = open(self.params.output.description_file_name,"w") of.write(outString) of.close() # Determine whether to write a PDB or CIF file and write the appropriate text output. # Then determine the output file name and write it there. if str(self.params.output.suffix).lower() == "pdb": txt = self.model.model_as_pdb() suffix = ".pdb" else: txt = self.model.model_as_mmcif() suffix = ".cif" if self.params.output.model_file_base_name is not None: base = self.params.output.model_file_base_name else: file_name = self.data_manager.get_model_names()[0] base = os.path.splitext(os.path.basename(file_name))[0] + "_reduced" fullname = base+suffix with open(fullname, 'w') as f: f.write(txt) print('Wrote',fullname,'and',self.params.output.description_file_name, file = self.logger) # Report profiling info if we've been asked to in the Phil parameters if self.params.profile: print('Profile results:') import pstats profile_params = {'sort_by': 'time', 'num_entries': 20} self._pr.disable() ps = pstats.Stats(self._pr).sort_stats(profile_params['sort_by']) ps.print_stats(profile_params['num_entries'])
def __init__(self, seconds): from libtbx.development.timers import work_clock self.maxtime = work_clock() + seconds