def exercise(): mon_lib_srv = monomer_library.server.server() ener_lib = monomer_library.server.ener_lib() processed_pdb_file = monomer_library.pdb_interpretation.process( mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, file_name=None, raw_records=pdb_str, force_symmetry=True) pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy geometry_restraints = processed_pdb_file.geometry_restraints_manager( show_energies=False) # necessary for comparison xray_structure = processed_pdb_file.xray_structure() restraints_manager = mmtbx.restraints.manager(geometry=geometry_restraints, normalization=False) angle_proxies = restraints_manager.geometry.get_all_angle_proxies() riding_h_manager = riding.manager(pdb_hierarchy=pdb_hierarchy, geometry_restraints=geometry_restraints) h_connectivity = riding_h_manager.h_connectivity # get bonds stored in connectivity bond_list = {} angle_list = {} for neighbors in h_connectivity: if (neighbors is None): continue ih = neighbors.ih a0 = neighbors.a0 i_a0 = a0['iseq'] a1 = neighbors.a1 i_a1 = a1['iseq'] bond_list[ih] = [i_a0, a0['dist_ideal']] selected_atoms = tuple(sorted([ih, i_a0, i_a1])) angle_list[selected_atoms] = a1['angle_ideal'] if neighbors.a2: a2 = neighbors.a2 selected_atoms2 = tuple(sorted([ih, i_a0, a2['iseq']])) angle_list[selected_atoms2] = a2['angle_ideal'] if neighbors.a3: a3 = neighbors.a3 selected_atoms3 = tuple(sorted([ih, i_a0, a3['iseq']])) angle_list[selected_atoms3] = a3['angle_ideal'] if neighbors.h1: h1 = neighbors.h1 selected_atoms4 = tuple(sorted([ih, i_a0, h1['iseq']])) angle_list[selected_atoms4] = h1['angle_ideal'] if neighbors.b1: i_b1 = neighbors.b1['iseq'] third_nb_dict = {ih: i_b1} # determine bonds from pdb_str model = mmtbx.model.manager(restraints_manager=restraints_manager, xray_structure=xray_structure, pdb_hierarchy=pdb_hierarchy) bond_ctrl = {} for i in model.xh_connectivity_table(): bond_ctrl[i[1]] = [i[0], i[3]] # List of angle restraints angles = [(4, 1, 12), (0, 1, 12), (2, 1, 12), (13, 4, 14), (5, 4, 14), (5, 4, 13), (1, 4, 13), (1, 4, 14), (8, 6, 15), (5, 6, 15), (9, 7, 16), (5, 7, 16), (10, 8, 17), (6, 8, 17), (10, 11, 19), (7, 9, 18), (10, 9, 18)] angle_ctrl = {} for ap in angle_proxies: if (ap.i_seqs in angles): angle_ctrl[tuple(sorted(list(ap.i_seqs)))] = ap.angle_ideal # HH needs also third neighbors: third_nb_ctrl = {19: 8} assert ( bond_list == bond_ctrl), '1-2 neighbors and distance_ideal are wrong' assert ( angle_list == angle_ctrl), '1-3 neighbors and angle_ideal are wrong' assert (third_nb_dict == third_nb_ctrl), '1-4 neighbors are wrong'
def exercise(): pdb_inp = iotbx.pdb.input(lines=pdb_str.split("\n"), source_info=None) model = mmtbx.model.manager(model_input=pdb_inp, log=null_out(), build_grm=True) restraints_manager = model.get_restraints_manager() angle_proxies = restraints_manager.geometry.get_all_angle_proxies() connectivity_manager = connectivity.determine_connectivity( pdb_hierarchy=model.get_hierarchy(), geometry_restraints=restraints_manager.geometry) h_connectivity = connectivity_manager.h_connectivity # get bonds stored in connectivity bond_list = {} angle_list = {} for neighbors in h_connectivity: if (neighbors is None): continue ih = neighbors.ih a0 = neighbors.a0 i_a0 = a0['iseq'] a1 = neighbors.a1 i_a1 = a1['iseq'] bond_list[ih] = [i_a0, a0['dist_ideal']] selected_atoms = tuple(sorted([ih, i_a0, i_a1])) angle_list[selected_atoms] = a1['angle_ideal'] if neighbors.a2: a2 = neighbors.a2 selected_atoms2 = tuple(sorted([ih, i_a0, a2['iseq']])) angle_list[selected_atoms2] = a2['angle_ideal'] if neighbors.a3: a3 = neighbors.a3 selected_atoms3 = tuple(sorted([ih, i_a0, a3['iseq']])) angle_list[selected_atoms3] = a3['angle_ideal'] if neighbors.h1: h1 = neighbors.h1 selected_atoms4 = tuple(sorted([ih, i_a0, h1['iseq']])) angle_list[selected_atoms4] = h1['angle_ideal'] if neighbors.b1: i_b1 = neighbors.b1['iseq'] third_nb_dict = {ih: i_b1} bond_ctrl = {} for i in model.xh_connectivity_table(): bond_ctrl[i[1]] = [i[0], i[3]] # List of angle restraints angles = [(4, 1, 12), (0, 1, 12), (2, 1, 12), (13, 4, 14), (5, 4, 14), (5, 4, 13), (1, 4, 13), (1, 4, 14), (8, 6, 15), (5, 6, 15), (9, 7, 16), (5, 7, 16), (10, 8, 17), (6, 8, 17), (10, 11, 19), (7, 9, 18), (10, 9, 18)] angle_ctrl = {} for ap in angle_proxies: if (ap.i_seqs in angles): angle_ctrl[tuple(sorted(list(ap.i_seqs)))] = ap.angle_ideal # HH needs also third neighbors: third_nb_ctrl = {19: 8} assert ( bond_list == bond_ctrl), '1-2 neighbors and distance_ideal are wrong' assert ( angle_list == angle_ctrl), '1-3 neighbors and angle_ideal are wrong' assert (third_nb_dict == third_nb_ctrl), '1-4 neighbors are wrong'
def exercise(): mon_lib_srv = monomer_library.server.server() ener_lib = monomer_library.server.ener_lib() processed_pdb_file = monomer_library.pdb_interpretation.process( mon_lib_srv = mon_lib_srv, ener_lib = ener_lib, file_name = None, raw_records = pdb_str, force_symmetry = True) pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy xray_structure = processed_pdb_file.xray_structure() geometry_restraints = processed_pdb_file.geometry_restraints_manager( show_energies = False) restraints_manager = mmtbx.restraints.manager( geometry = geometry_restraints, normalization = False) sites_cart = xray_structure.sites_cart() bond_proxies_simple, asu = restraints_manager.geometry.get_all_bond_proxies( sites_cart = sites_cart) angle_proxies = restraints_manager.geometry.get_all_angle_proxies() hd_selection = xray_structure.hd_selection() # determine values with code to be tested connectivity = hydrogen_connectivity.determine_H_neighbors( geometry_restraints = geometry_restraints, bond_proxies = bond_proxies_simple, angle_proxies = angle_proxies, hd_selection = hd_selection, sites_cart = sites_cart) bond_list = {} angle_list = {} third_nb_list = {} for ih in connectivity.keys(): a0 = (connectivity[ih][0]) bond_list[ih]=[a0.iseq, a0.dist_ideal] for atom in connectivity[ih][1]: helper = tuple(sorted([ih, a0.iseq, atom.iseq])) angle_list[helper]=atom.angle_ideal if(len(connectivity[ih])==3): third_nb_list[ih]=[] for atom in connectivity[ih][2]: third_nb_list[ih].append(atom.iseq) # print third_nb_list[ih] #----------------------------------------------------------------------------- # This is useful to keep for debugging: human readable output of connectivity #----------------------------------------------------------------------------- # for ih in connectivity.keys(): # if(len(connectivity[ih])==3): # string = (" ".join([names[p.iseq] for p in connectivity[ih][2]])) # else: # string = 'n/a' # print names[ih],': ', names[(connectivity[ih][0][0]).iseq], \ # ',', (" ".join([names[p.iseq] for p in connectivity[ih][1]])), \ # ',', string #----------------------------------------------------------------------------- # determine values directly from pdb_str model = mmtbx.model.manager( restraints_manager = restraints_manager, xray_structure = xray_structure, pdb_hierarchy = pdb_hierarchy) bond_ctrl = {} for i in model.xh_connectivity_table(): bond_ctrl[i[1]]=[i[0],i[3]] # We know the angles beforehand angles = [ (4, 1, 12), (2, 1, 12), (0, 1, 12), (13, 4, 14), (5, 4, 14), (5, 4, 13), (1, 4, 13), (1, 4, 14), (8, 6, 15), (5, 6, 15), (9, 7, 16), (5, 7, 16), (10, 8, 17), (6, 8, 17), (10, 11, 19), (7, 9, 18), (10, 9, 18)] angle_ctrl = {} for ap in angle_proxies: if(ap.i_seqs in angles): angle_ctrl[tuple(sorted(list(ap.i_seqs)))]=ap.angle_ideal # HH needs also third neighbors: third_nb_ctrl = {19: [8, 9]} assert (bond_list == bond_ctrl), '1-2 neighbors and distance_ideal are wrong' assert (angle_list == angle_ctrl), '1-3 neighbors and angle_ideal are wrong' assert (third_nb_list == third_nb_ctrl), '1-4 neighbors are wrong'
def exercise(): mon_lib_srv = monomer_library.server.server() ener_lib = monomer_library.server.ener_lib() processed_pdb_file = monomer_library.pdb_interpretation.process( mon_lib_srv=mon_lib_srv, ener_lib=ener_lib, file_name=None, raw_records=pdb_str, force_symmetry=True) pdb_hierarchy = processed_pdb_file.all_chain_proxies.pdb_hierarchy geometry_restraints = processed_pdb_file.geometry_restraints_manager( show_energies=False) # necessary for comparison xray_structure = processed_pdb_file.xray_structure() restraints_manager = mmtbx.restraints.manager(geometry=geometry_restraints, normalization=False) angle_proxies = restraints_manager.geometry.get_all_angle_proxies() riding_h_manager = riding.manager(pdb_hierarchy=pdb_hierarchy, geometry_restraints=geometry_restraints) h_connectivity = riding_h_manager.h_connectivity bond_list = {} angle_list = {} third_nb_list = {} for ih in h_connectivity.keys(): a0 = (h_connectivity[ih][0]) bond_list[ih] = [a0.iseq, a0.dist_ideal] for atom in h_connectivity[ih][1] + h_connectivity[ih][2]: helper = tuple(sorted([ih, a0.iseq, atom.iseq])) angle_list[helper] = atom.angle_ideal if (len(h_connectivity[ih]) == 4): third_nb_list[ih] = [] for third in h_connectivity[ih][3]: third_nb_list[ih].append(third.iseq) #----------------------------------------------------------------------------- # This is useful to keep for debugging: human readable output of connectivity #----------------------------------------------------------------------------- # for ih in connectivity.keys(): # if(len(connectivity[ih])==3): # string = (" ".join([names[p.iseq] for p in connectivity[ih][2]])) # else: # string = 'n/a' # print names[ih],': ', names[(connectivity[ih][0][0]).iseq], \ # ',', (" ".join([names[p.iseq] for p in connectivity[ih][1]])), \ # ',', string #----------------------------------------------------------------------------- # determine bonds from pdb_str model = mmtbx.model.manager(restraints_manager=restraints_manager, xray_structure=xray_structure, pdb_hierarchy=pdb_hierarchy) bond_ctrl = {} for i in model.xh_connectivity_table(): bond_ctrl[i[1]] = [i[0], i[3]] # List of angle restraints angles = [(4, 1, 12), (2, 1, 12), (0, 1, 12), (13, 4, 14), (5, 4, 14), (5, 4, 13), (1, 4, 13), (1, 4, 14), (8, 6, 15), (5, 6, 15), (9, 7, 16), (5, 7, 16), (10, 8, 17), (6, 8, 17), (10, 11, 19), (7, 9, 18), (10, 9, 18)] angle_ctrl = {} for ap in angle_proxies: if (ap.i_seqs in angles): angle_ctrl[tuple(sorted(list(ap.i_seqs)))] = ap.angle_ideal # HH needs also third neighbors: third_nb_ctrl = {19: [8, 9]} assert ( bond_list == bond_ctrl), '1-2 neighbors and distance_ideal are wrong' assert ( angle_list == angle_ctrl), '1-3 neighbors and angle_ideal are wrong' assert (third_nb_list == third_nb_ctrl), '1-4 neighbors are wrong'