def run( pdb_filename, model_completion=True, keep_alt_loc=False, skip_validation=False, calculate_charge=False, append_to_end_of_model=False, ): # # do all *.pdb in a directory # if os.path.isdir(pdb_filename): loop_over_dir(pdb_filename) return # # fetch a PDB code # if pdb_filename.find(".pdb") == -1: if not os.path.exists('%s.pdb' % pdb_filename): run_fetch_pdb(pdb_filename) pdb_filename = '%s.pdb' % pdb_filename if 1: # read file option ppf = hierarchy_utils.get_processed_pdb(pdb_filename=pdb_filename) elif 0: # raw records example pdb_inp = iotbx.pdb.input(pdb_filename) hierarchy = pdb_inp.construct_hierarchy() raw_records = [] for atom in hierarchy.atoms(): raw_records.append(atom.format_atom_record()) ppf = hierarchy_utils.get_processed_pdb(raw_records=raw_records) else: # from hierarchy pdb_inp = iotbx.pdb.input(pdb_filename) hierarchy = pdb_inp.construct_hierarchy() ppf = hierarchy_utils.get_processed_pdb( pdb_inp=hierarchy.as_pdb_input()) if not skip_validation: initial_model_statistics = mmtbx.model.statistics.geometry( pdb_hierarchy=ppf.all_chain_proxies.pdb_hierarchy) # should use cctbx if keep_alt_loc: pass else: hierarchy = remove_alternative_locations( ppf.all_chain_proxies.pdb_hierarchy) ppf.all_chain_proxies.pdb_hierarchy.shift_to_origin( ppf.all_chain_proxies.pdb_inp.crystal_symmetry()) ppf.all_chain_proxies.pdb_hierarchy.remove_residue_groups_with_atoms_on_special_positions_selective( ppf.all_chain_proxies.pdb_inp.crystal_symmetry()) if 0: output = hierarchy_utils.write_hierarchy( pdb_filename, # uses to get output filename ppf.all_chain_proxies.pdb_inp, ppf.all_chain_proxies.pdb_hierarchy, "temp0") ppf = hierarchy_utils.get_processed_pdb(pdb_filename=output) else: raw_records = hierarchy_utils.get_raw_records( ppf.all_chain_proxies.pdb_inp, ppf.all_chain_proxies.pdb_hierarchy, ) ppf = hierarchy_utils.get_processed_pdb(raw_records=raw_records) hetero_charges = charges.get_hetero_charges( ppf.all_chain_proxies.pdb_inp, ppf.all_chain_proxies.pdb_hierarchy, ) if not hetero_charges: # some defaults hetero_charges = charges.default_ion_charges inter_residue_bonds = charges.get_inter_residue_bonds(ppf) # # extends side chains and add hydrogens # if model_completion: use_capping_hydrogens = False fname = 'complete' else: use_capping_hydrogens = True fname = 'capping' #assert 0 # model has H ppf = completion.complete_pdb_hierarchy( ppf.all_chain_proxies.pdb_hierarchy, ppf.geometry_restraints_manager(), pdb_filename=pdb_filename, pdb_inp=ppf.all_chain_proxies.pdb_inp, use_capping_hydrogens=use_capping_hydrogens, append_to_end_of_model=append_to_end_of_model, ) if calculate_charge: new_pdb_filename = hierarchy_utils.write_hierarchy( pdb_filename, # uses to get output filename ppf.all_chain_proxies.pdb_inp, ppf.all_chain_proxies.pdb_hierarchy, fname) ## need now inter_residue_bonds because of added hydrogens ## maybe update the bond table!!! ppf = hierarchy_utils.get_processed_pdb(pdb_filename=new_pdb_filename) inter_residue_bonds = charges.get_inter_residue_bonds(ppf, verbose=True) total_charge = charges.calculate_pdb_hierarchy_charge( ppf.all_chain_proxies.pdb_hierarchy, hetero_charges=hetero_charges, inter_residue_bonds=inter_residue_bonds, ) print "total_charge", total_charge # Idealize H as riding params = mmtbx.model.manager.get_default_pdb_interpretation_params() params.pdb_interpretation.use_neutron_distances = True h = ppf.all_chain_proxies.pdb_hierarchy asc = h.atom_selection_cache() sel = asc.selection("element H or element D") model = mmtbx.model.manager( model_input=None, build_grm=True, pdb_hierarchy=ppf.all_chain_proxies.pdb_hierarchy, pdb_interpretation_params=params, crystal_symmetry=ppf.all_chain_proxies.pdb_inp.crystal_symmetry(), log=null_out()) model.idealize_h_riding() model.set_occupancies(value=0, selection=sel) ## after no error getting total charge, write the completed pdb file hierarchy_utils.write_hierarchy( pdb_filename, # uses to get output filename ppf.all_chain_proxies.pdb_inp, model.get_hierarchy(), fname) if not skip_validation: final_model_statistics = mmtbx.model.statistics.geometry( pdb_hierarchy=ppf.all_chain_proxies.pdb_hierarchy)
def complete_pdb_hierarchy( hierarchy, geometry_restraints_manager, use_capping_hydrogens=False, append_to_end_of_model=False, pdb_filename=None, pdb_inp=None, original_pdb_filename=None, verbose=False, debug=False, ): """Complete PDB hierarchy with hydrogen atoms as needed This needs to move to Phenix with better functionality Args: hierarchy (hierarchy): Starting model geometry_restraints_manager (GRM): Starting restraints use_capping_hydrogens (bool, optional): Capping or not append_to_end_of_model (bool, optional): Added atoms go to end of atom list pdb_filename (None, optional): Description pdb_inp (None, optional): Description original_pdb_filename (None, optional): Description verbose (bool, optional): Description debug (bool, optional): Description Returns: TYPE: Description Raises: Sorry: Description """ for ag in hierarchy.atom_groups(): if get_class(ag.resname) in ['common_rna_dna']: raise Sorry('Nucleotides are not currently supported. e.g. %s' % ag.resname) from mmtbx.building import extend_sidechains original_hierarchy = None params = hierarchy_utils.get_pdb_interpretation_params() params.restraints_library.cdl = False if use_capping_hydrogens: params.link_distance_cutoff = 1.8 # avoid linking across a single missing AA if original_pdb_filename: original_pdb_inp = iotbx.pdb.input(original_pdb_filename) original_hierarchy = original_pdb_inp.construct_hierarchy() if debug: output = hierarchy_utils.write_hierarchy( pdb_filename, pdb_inp, hierarchy, 'temp1', ) # # assume model is heavy-atom complete # if not use_capping_hydrogens: if debug: ppf = hierarchy_utils.get_processed_pdb(pdb_filename=output) else: raw_records = hierarchy_utils.get_raw_records(pdb_inp, hierarchy) ppf = hierarchy_utils.get_processed_pdb( raw_records=raw_records, params=params, ) sites_cart = hierarchy.atoms().extract_xyz() ppf.all_chain_proxies.pdb_hierarchy.atoms().set_xyz(sites_cart) n_changed = extend_sidechains.extend_protein_model( ppf.all_chain_proxies.pdb_hierarchy, mon_lib_server, add_hydrogens=False, ) if debug: print('number of side chains changed', n_changed) output = hierarchy_utils.write_hierarchy( pdb_filename, pdb_inp, ppf.all_chain_proxies.pdb_hierarchy, 'temp2', ) # # need to use Reduce/ReadySet! to add hydrogens # if not use_capping_hydrogens: output = hierarchy_utils.write_hierarchy( pdb_filename, pdb_inp, ppf.all_chain_proxies.pdb_hierarchy, 'readyset_input', ) hierarchy = hierarchy_utils.add_hydrogens_using_ReadySet(output) # # remove side chain acid hydrogens - maybe not required since recent changes # if debug: ppf = hierarchy_utils.get_processed_pdb( pdb_filename=output, params=params, ) else: raw_records = hierarchy_utils.get_raw_records(pdb_inp, hierarchy) ppf = hierarchy_utils.get_processed_pdb( raw_records=raw_records, params=params, ) sites_cart = hierarchy.atoms().extract_xyz() ppf.all_chain_proxies.pdb_hierarchy.atoms().set_xyz(sites_cart) remove_acid_side_chain_hydrogens(ppf.all_chain_proxies.pdb_hierarchy) # # add hydrogens in special cases # eg ETA # eg N - H, H2 # if debug: ppf = hierarchy_utils.get_processed_pdb( pdb_filename=output, params=params, ) else: hierarchy = ppf.all_chain_proxies.pdb_hierarchy raw_records = hierarchy_utils.get_raw_records(pdb_inp, hierarchy) ppf = hierarchy_utils.get_processed_pdb( raw_records=raw_records, params=params, ) sites_cart = hierarchy.atoms().extract_xyz() ppf.all_chain_proxies.pdb_hierarchy.atoms().set_xyz(sites_cart) special_case_hydrogens( ppf.all_chain_proxies.pdb_hierarchy, ppf.geometry_restraints_manager(), #use_capping_hydrogens=use_capping_hydrogens, #append_to_end_of_model=append_to_end_of_model, #original_hierarchy=original_hierarchy, verbose=verbose, ) # # add terminals atoms including hydrogens and OXT - more docs here... # if debug: output = hierarchy_utils.write_hierarchy( pdb_filename, pdb_inp, ppf.all_chain_proxies.pdb_hierarchy, 'temp3', ) ppf = hierarchy_utils.get_processed_pdb( pdb_filename=output, params=params, ) else: hierarchy = ppf.all_chain_proxies.pdb_hierarchy raw_records = hierarchy_utils.get_raw_records(pdb_inp, hierarchy) ppf = hierarchy_utils.get_processed_pdb( raw_records=raw_records, params=params, ) sites_cart = hierarchy.atoms().extract_xyz() ppf.all_chain_proxies.pdb_hierarchy.atoms().set_xyz(sites_cart) # # moved to mmtbx.ligands # add_terminal_hydrogens( ppf.all_chain_proxies.pdb_hierarchy, ppf.geometry_restraints_manager(), use_capping_hydrogens=use_capping_hydrogens, append_to_end_of_model=append_to_end_of_model, original_hierarchy=original_hierarchy, verbose=verbose, ) # in place ppf.all_chain_proxies.pdb_hierarchy.atoms( ).set_chemical_element_simple_if_necessary() ppf.all_chain_proxies.pdb_hierarchy.sort_atoms_in_place() #display_hierarchy_atoms(ppf.all_chain_proxies.pdb_hierarchy) #ppf.all_chain_proxies.pdb_hierarchy.atoms_reset_serial() #ppf.all_chain_proxies.pdb_hierarchy.atoms().reset_i_seq() return ppf
def run(pdb_filename, model_completion=True, keep_alt_loc=False, skip_validation=False, calculate_charge=False, ): # # do all *.pdb in a directory # if os.path.isdir(pdb_filename): loop_over_dir(pdb_filename) return # # fetch a PDB code # if pdb_filename.find(".pdb")==-1: if not os.path.exists('%s.pdb' % pdb_filename): run_fetch_pdb(pdb_filename) pdb_filename = '%s.pdb' % pdb_filename if 0: # moved adding hydrogens to complete_pdb_hierarchy if pdb_filename.endswith('.updated.pdb'): pdb_filename_h = pdb_filename else: pdb_filename_h = pdb_filename.replace('.pdb', '.updated.pdb') if not os.path.exists(pdb_filename_h): pdb_filename_h = os.path.basename(pdb_filename_h) print 'pdb_filename_h',pdb_filename_h if not os.path.exists(pdb_filename_h): pdb_filename = run_ready_set(pdb_filename) else: pdb_filename = pdb_filename_h if 1: # read file option ppf = hierarchy_utils.get_processed_pdb(pdb_filename=pdb_filename) elif 0: # raw records example pdb_inp = iotbx.pdb.input(pdb_filename) hierarchy = pdb_inp.construct_hierarchy() raw_records = [] for atom in hierarchy.atoms(): raw_records.append(atom.format_atom_record()) ppf = hierarchy_utils.get_processed_pdb(raw_records=raw_records) else: # from hierarchy pdb_inp = iotbx.pdb.input(pdb_filename) hierarchy = pdb_inp.construct_hierarchy() ppf = hierarchy_utils.get_processed_pdb(pdb_inp=hierarchy.as_pdb_input()) if not skip_validation: initial_model_statistics = mmtbx.model.statistics.geometry( pdb_hierarchy = ppf.all_chain_proxies.pdb_hierarchy) # should use cctbx if keep_alt_loc: pass else: hierarchy = remove_alternative_locations( ppf.all_chain_proxies.pdb_hierarchy ) ppf.all_chain_proxies.pdb_hierarchy.shift_to_origin( ppf.all_chain_proxies.pdb_inp.crystal_symmetry()) ppf.all_chain_proxies.pdb_hierarchy.remove_residue_groups_with_atoms_on_special_positions_selective(ppf.all_chain_proxies.pdb_inp.crystal_symmetry()) if 0: output = hierarchy_utils.write_hierarchy( pdb_filename, # uses to get output filename ppf.all_chain_proxies.pdb_inp, hierarchy, "temp0") ppf = hierarchy_utils.get_processed_pdb(pdb_filename=output) else: raw_records = hierarchy_utils.get_raw_records( ppf.all_chain_proxies.pdb_inp, ppf.all_chain_proxies.pdb_hierarchy, ) ppf = hierarchy_utils.get_processed_pdb(raw_records=raw_records) hetero_charges = charges.get_hetero_charges( ppf.all_chain_proxies.pdb_inp, ppf.all_chain_proxies.pdb_hierarchy, ) if not hetero_charges: # some defaults hetero_charges = charges.default_ion_charges inter_residue_bonds = charges.get_inter_residue_bonds(ppf) # # extends side chains and add hydrogens # if model_completion: use_capping_hydrogens=False fname = 'complete' else: use_capping_hydrogens=True fname = 'capping' #assert 0 # model has H ppf = completion.complete_pdb_hierarchy( ppf.all_chain_proxies.pdb_hierarchy, ppf.geometry_restraints_manager(), pdb_filename=pdb_filename, pdb_inp=ppf.all_chain_proxies.pdb_inp, use_capping_hydrogens=use_capping_hydrogens, ) if calculate_charge: new_pdb_filename = hierarchy_utils.write_hierarchy( pdb_filename, # uses to get output filename ppf.all_chain_proxies.pdb_inp, ppf.all_chain_proxies.pdb_hierarchy, fname) ## need now inter_residue_bonds because of added hydrogens ## maybe update the bond table!!! ppf = hierarchy_utils.get_processed_pdb(pdb_filename=new_pdb_filename) inter_residue_bonds = charges.get_inter_residue_bonds(ppf, verbose=True) total_charge = charges.calculate_pdb_hierarchy_charge( ppf.all_chain_proxies.pdb_hierarchy, hetero_charges=hetero_charges, inter_residue_bonds=inter_residue_bonds, ) print "total_charge",total_charge ## after no error getting total charge, write the completed pdb file hierarchy_utils.write_hierarchy(pdb_filename, # uses to get output filename ppf.all_chain_proxies.pdb_inp, ppf.all_chain_proxies.pdb_hierarchy, fname) if not skip_validation: final_model_statistics = mmtbx.model.statistics.geometry( pdb_hierarchy = ppf.all_chain_proxies.pdb_hierarchy)
def run( pdb_filename=None, pdb_hierarchy=None, crystal_symmetry=None, model_completion=True, original_pdb_filename=None, append_to_end_of_model=True, ): # # function as be used in two main modes # 1. completing a model with hydrogens in a protein-like manner # 2. completing a cluster with hydrogens in a QM-sensible manner # # Validation # if pdb_hierarchy: assert crystal_symmetry assert pdb_filename is None # # output # if model_completion: use_capping_hydrogens = False fname = 'complete' else: use_capping_hydrogens = True fname = 'capping' # # adjust parameters # params = None if use_capping_hydrogens: params = hierarchy_utils.get_pdb_interpretation_params() params.link_distance_cutoff = 1.8 if pdb_hierarchy: raw_records = hierarchy_utils.get_raw_records( pdb_inp=None, pdb_hierarchy=pdb_hierarchy, crystal_symmetry=crystal_symmetry, ) ppf = hierarchy_utils.get_processed_pdb(raw_records=raw_records) sites_cart = pdb_hierarchy.atoms().extract_xyz() ppf.all_chain_proxies.pdb_hierarchy.atoms().set_xyz(sites_cart) else: ppf = hierarchy_utils.get_processed_pdb( pdb_filename=pdb_filename, params=params, ) # # guts # ppf = complete_pdb_hierarchy( ppf.all_chain_proxies.pdb_hierarchy, ppf.geometry_restraints_manager(), use_capping_hydrogens=use_capping_hydrogens, append_to_end_of_model=append_to_end_of_model, # needed for clustering # code and Molprobity pdb_filename=pdb_filename, # used just for naming of debug output pdb_inp=ppf.all_chain_proxies.pdb_inp, # used in get_raw_records. why verbose=False, ) if pdb_filename: output = hierarchy_utils.write_hierarchy( pdb_filename, ppf.all_chain_proxies.pdb_inp, ppf.all_chain_proxies.pdb_hierarchy, fname, ) return ppf.all_chain_proxies.pdb_hierarchy