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 # if pdb_hierarchy: assert crystal_symmetry assert pdb_filename is None if model_completion: use_capping_hydrogens=False fname = 'complete' else: use_capping_hydrogens=True fname = 'capping' #assert 0 # model has H 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, ) 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? original_pdb_filename=original_pdb_filename, # used to define breaks in # main chain for capping 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
def __init__( self, pdb_filename=None, raw_records=None, pdb_inp=None, ligand_cif_file_names=None, cif_objects=None, electrons=True, # hidden verbose=False, ): self.verbose = verbose self.pdb_filename = pdb_filename self.raw_records = raw_records assert not (ligand_cif_file_names and cif_objects) ppf = hierarchy_utils.get_processed_pdb( pdb_filename=pdb_filename, raw_records=raw_records, pdb_inp=pdb_inp, cif_objects=cif_objects, ) self.inter_residue_bonds = get_inter_residue_bonds(ppf) self.update_pdb_hierarchy( ppf.all_chain_proxies.pdb_hierarchy, ppf.all_chain_proxies.pdb_inp.crystal_symmetry_from_cryst1(), ) self.pdb_inp = ppf.all_chain_proxies.pdb_inp assert self.crystal_symmetry, 'There is no CRYST1 record in the input file' self.hetero_charges = get_hetero_charges( self.pdb_inp, self.pdb_hierarchy, ) if not self.hetero_charges: # some defaults self.hetero_charges = default_ion_charges #if verbose: # for key, item in self.inter_residue_bonds.items(): # if type(key)!=type(0) and len(key)==2: print key, item # merge atoms from clustering self.pdb_hierarchy = hierarchy_utils.merge_atoms_at_end_to_residues( self.pdb_hierarchy, ) self.mon_lib_server = ppf.mon_lib_srv self.electrons = electrons
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, ): for ag in hierarchy.atom_groups(): if get_class(ag.resname) in ['common_rna_dna']: raise Sorry('') from mmtbx.building import extend_sidechains params = None original_hierarchy = None if use_capping_hydrogens: params = hierarchy_utils.get_pdb_interpretation_params() 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) 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
return rc args = sys.argv[1:] del sys.argv[1:] kwds = {} remove = [] for i, arg in enumerate(args): if arg.find('=') > -1: kwds.update(_fake_phil_parse(arg)) remove.append(i) remove.reverse() for r in remove: del args[r] if 'test_from_clustering' in args: args.remove('test_from_clustering') ppf = hierarchy_utils.get_processed_pdb(args[0]) sites_cart = ppf.all_chain_proxies.pdb_hierarchy.atoms().extract_xyz() sites_cart[0] = (4.123456789, 7.7, 1.5) ppf.all_chain_proxies.pdb_hierarchy.atoms().set_xyz(sites_cart) kwds['pdb_hierarchy'] = ppf.all_chain_proxies.pdb_hierarchy kwds[ 'crystal_symmetry'] = ppf.all_chain_proxies.pdb_inp.crystal_symmetry( ) display_hierarchy_atoms(kwds['pdb_hierarchy']) rc = run(None, **kwds) #print '='*80 display_hierarchy_atoms(rc) assert 0, 'FINISHED TESTING' #print 'run',args,kwds run(*tuple(args), **kwds)