def add_hydrogens(self): # Not used and not working anymore. self.whole_pdb_h = self.get_intermediate_result_hierarchy() cs = self.model.crystal_symmetry() pdb_str, changed = check_and_add_hydrogen( pdb_hierarchy=self.whole_pdb_h, file_name=None, nuclear=False, keep_hydrogens=False, verbose=False, model_number=0, n_hydrogen_cut_off=0, time_limit=120, allow_multiple_models=True, crystal_symmetry=self.cs, do_flips=True, log=self.log) self.whole_pdb_h = iotbx.pdb.input(lines=pdb_str, source_info=None).construct_hierarchy() # we need to renew everythig here: grm, whole model, xrs! self.whole_xrs = self.working_pdb_h.extract_xray_structure(crystal_symmetry=cs) self.get_grm() # self.get_filtered_ncs_group_list() # temp workaround, do something here to handle NCS cases self.working_pdb_h = self.whole_pdb_h self.working_xrs = self.working_pdb_h.extract_xray_structure(crystal_symmetry=cs) self.working_grm = self.whole_grm
def add_hydrogens(self, model, nuclear=False): from mmtbx.validation.clashscore import check_and_add_hydrogen hierarchy = model.get_hierarchy() reduce_str, check = check_and_add_hydrogen(pdb_hierarchy=hierarchy, file_name=None, nuclear=nuclear, keep_hydrogens=True, verbose=False, model_number=0, n_hydrogen_cut_off=0, time_limit=120, allow_multiple_models=True, crystal_symmetry=None, do_flips=False, log=None) #There should be a check here for whether Reduce completed return reduce_str
def test_file_with_unknown_pair_type(): ''' Verify that ready_set can fix issues with unknown_pair_type ''' model = obtain_model(raw_records = unknown_pairs_pdb_str, stop_for_unknowns = False) ph = model.get_hierarchy() pdb_with_h, h_were_added = mvc.check_and_add_hydrogen( pdb_hierarchy = ph, allow_multiple_models = False, crystal_symmetry = model.crystal_symmetry(), log = null_out()) sorry = None try: model = obtain_model(raw_records=pdb_with_h) except Sorry as e: sorry = e assert(sorry is not None)
def test_identifying_and_addition_of_hydrogen(self): """ test identifying and addition of hydrogen """ has_reduce = libtbx.env.has_module(name="reduce") if has_reduce: pdb_inp = iotbx.pdb.input(file_name=self.file_name) pdb_hierarchy = pdb_inp.construct_hierarchy() elements = pdb_hierarchy.atoms().extract_element() h_count_0 = elements.count(' H') + elements.count(' D') new_pdb_str, _ = check_and_add_hydrogen(file_name=self.file_name, verbose=False) pdb_inp = iotbx.pdb.input(source_info=None, lines=new_pdb_str) pdb_hierarchy = pdb_inp.construct_hierarchy() elements = pdb_hierarchy.atoms().extract_element() h_count_1 = elements.count(' H') + elements.count(' D') self.assertEqual(h_count_0, 0) self.assertTrue(h_count_1 > 0) else: # Skip test if reduce is not present pass
def test_identifying_and_addition_of_hydrogen(self): """ test identifying and addition of hydrogen """ has_reduce = libtbx.env.has_module(name="reduce") if has_reduce: pdb_inp = iotbx.pdb.input(file_name=self.file_name) pdb_hierarchy = pdb_inp.construct_hierarchy() elements = pdb_hierarchy.atoms().extract_element() h_count_0 = elements.count(' H') + elements.count(' D') new_pdb_str,_ = check_and_add_hydrogen( file_name=self.file_name, verbose=False) pdb_inp = iotbx.pdb.input(source_info=None, lines=new_pdb_str) pdb_hierarchy = pdb_inp.construct_hierarchy() elements = pdb_hierarchy.atoms().extract_element() h_count_1 = elements.count(' H') + elements.count(' D') self.assertEqual(h_count_0,0) self.assertTrue(h_count_1>0) else: # Skip test if reduce is not present pass
def run(args, out=None): """ Calculates number of non-bonded atoms overlaps in a model prints to log: When verbose=True the function print detailed results to log When verbose=False it will print: nb_overlaps_macro_molecule, nb_overlaps_due_to_sym_op, nb_overlaps_all Args: args (list): list of options. model=input_file input PDB file cif=input_file input CIF file for additional model information keep_hydrogens=True keep input hydrogen files (otherwise regenerate) nuclear=False use nuclear x-H distances and vdW radii verbose=True verbose text output time_limit=120 Time limit (sec) for Reduce optimization show_overlap_type=all what type of overlaps to show show_normalized_nbo=False Show non-bonded overlaps per 1000 atoms substitute_non_crystallographic_unit_cell_if_necessary=false fix CRYST1 records if needed out : where to wrote the output to. Returns: nb_overlaps (obj): Object containing overlap and overlap per thousand atoms information """ if not out: out = sys.stdout if not args: print >> out, usage_string return None cmdline = iotbx.phil.process_command_line_with_files( args=args, master_phil_string=master_phil_str, pdb_file_def="model", cif_file_def="cif", usage_string=usage_string) params = cmdline.work.extract() if (params.model is None): raise Usage(usage_string) pdb_file_name = [x for x in args if x.endswith('.pdb')] cif_file_name = [x for x in args if x.endswith('.cif')] assert pdb_file_name pdb_file_name = pdb_file_name[0] if not params.skip_hydrogen_test: pdb_with_h, h_were_added = mvc.check_and_add_hydrogen( file_name=pdb_file_name, model_number=0, nuclear=params.nuclear, verbose=params.verbose, time_limit=params.time_limit, keep_hydrogens=params.keep_hydrogens, allow_multiple_models=False, log=out) if h_were_added: pdb_file_name = pdb_file_name.replace('.pdb', '_with_h.pdb') open(pdb_file_name, 'w').write(pdb_with_h) files = [pdb_file_name] if cif_file_name: files += cif_file_name pdb_processed_file = pdb_inter.run( args=files, assume_hydrogens_all_missing=False, hard_minimum_nonbonded_distance=0.0, nonbonded_distance_threshold=None, substitute_non_crystallographic_unit_cell_if_necessary=params. substitute_non_crystallographic_unit_cell_if_necessary, log=null_out()) # test that CRYST1 records are ok sps = pdb_processed_file.all_chain_proxies.special_position_settings if not sps: msg = 'None valid CRSYT1 records.\n' msg += 'Consider running mmtbx.nonbonded_overlaps with the option:\n' msg += 'substitute_non_crystallographic_unit_cell_if_necessary=true' raise Sorry(msg) grm = pdb_processed_file.geometry_restraints_manager() xrs = pdb_processed_file.xray_structure() sites_cart = xrs.sites_cart() site_labels = xrs.scatterers().extract_labels() hd_sel = xrs.hd_selection() macro_mol_sel = nbo.get_macro_mol_sel(pdb_processed_file) nb_overlaps = nbo.info(geometry_restraints_manager=grm, macro_molecule_selection=macro_mol_sel, sites_cart=sites_cart, site_labels=site_labels, hd_sel=hd_sel) if params.verbose: nb_overlaps.show(log=out, nbo_type=params.show_overlap_type, normalized_nbo=params.show_normalized_nbo) else: all = nb_overlaps.result.nb_overlaps_all macro_molecule = nb_overlaps.result.nb_overlaps_macro_molecule sym = nb_overlaps.result.nb_overlaps_due_to_sym_op out_list = map(lambda x: str(round(x, 2)), [macro_molecule, sym, all]) print >> out, ', '.join(out_list) return nb_overlaps
def run (args, out=None) : """ Calculates number of non-bonded atoms overlaps in a model prints to log: When verbose=True the function print detailed results to log When verbose=False it will print: nb_overlaps_macro_molecule, nb_overlaps_due_to_sym_op, nb_overlaps_all Args: args (list): list of options. model=input_file input PDB file cif=input_file input CIF file for additional model information keep_hydrogens=True keep input hydrogen files (otherwise regenerate) nuclear=False use nuclear x-H distances and vdW radii verbose=True verbose text output time_limit=120 Time limit (sec) for Reduce optimization show_overlap_type=all what type of overlaps to show show_normalized_nbo=False Show non-bonded overlaps per 1000 atoms substitute_non_crystallographic_unit_cell_if_necessary=false fix CRYST1 records if needed out : where to wrote the output to. Returns: nb_overlaps (obj): Object containing overlap and overlap per thousand atoms information """ if not out: out = sys.stdout if not args: print >> out,usage_string return None cmdline = iotbx.phil.process_command_line_with_files( args=args, master_phil_string=master_phil_str, pdb_file_def="model", cif_file_def="cif", usage_string=usage_string) params = cmdline.work.extract() if (params.model is None) : raise Usage(usage_string) pdb_file_name = [x for x in args if x.endswith('.pdb')] cif_file_name = [x for x in args if x.endswith('.cif')] assert pdb_file_name pdb_file_name = pdb_file_name[0] if not params.skip_hydrogen_test: pdb_with_h, h_were_added = mvc.check_and_add_hydrogen( file_name=pdb_file_name, model_number=0, nuclear=params.nuclear, verbose=params.verbose, time_limit=params.time_limit, keep_hydrogens=params.keep_hydrogens, allow_multiple_models=False, log=out) if h_were_added: pdb_file_name = pdb_file_name.replace('.pdb','_with_h.pdb') open(pdb_file_name,'w').write(pdb_with_h) files = [pdb_file_name] if cif_file_name: files += cif_file_name pdb_processed_file = pdb_inter.run( args=files, assume_hydrogens_all_missing=False, hard_minimum_nonbonded_distance=0.0, nonbonded_distance_threshold=None, substitute_non_crystallographic_unit_cell_if_necessary= params.substitute_non_crystallographic_unit_cell_if_necessary, log=null_out() ) # test that CRYST1 records are ok sps = pdb_processed_file.all_chain_proxies.special_position_settings if not sps: msg = 'None valid CRSYT1 records.\n' msg += 'Consider running phenix.clashscore with the option:\n' msg += 'substitute_non_crystallographic_unit_cell_if_necessary=true' raise Sorry(msg) grm = pdb_processed_file.geometry_restraints_manager() xrs = pdb_processed_file.xray_structure() sites_cart = xrs.sites_cart() site_labels = xrs.scatterers().extract_labels() hd_sel = xrs.hd_selection() macro_mol_sel = nbo.get_macro_mol_sel(pdb_processed_file) nb_overlaps = nbo.info( geometry_restraints_manager=grm, macro_molecule_selection=macro_mol_sel, sites_cart=sites_cart, site_labels=site_labels, hd_sel=hd_sel) if params.verbose: nb_overlaps.show( log=out, nbo_type=params.show_overlap_type, normalized_nbo=params.show_normalized_nbo) else: all = nb_overlaps.result.nb_overlaps_all macro_molecule = nb_overlaps.result.nb_overlaps_macro_molecule sym = nb_overlaps.result.nb_overlaps_due_to_sym_op out_list = map(lambda x: str(round(x,2)),[macro_molecule,sym,all]) print >> out,', '.join(out_list) return nb_overlaps