def parse_symm_db(args): """ :param args: :return: list of Entry instances that are significant in the CE database """ results = [] with open(work_dir + 'ce_symm.xml', 'r') as fin: xml = fin.read().split('data') ABC = 'QWERTYUIOPASDFGHJKLZXCVBNM' for data in xml: axis = {} significant = False for l in data.split('\n'): if 'isSig' in l: significant = l.split('>')[1].split('<')[0] == 'true' if not significant: break if '<x>' in l: axis['x'] = float(l.split('>')[1].split('<')[0]) if '<y>' in l: axis['y'] = float(l.split('>')[1].split('<')[0]) if '<z>' in l: axis['z'] = float(l.split('>')[1].split('<')[0]) if 'protodomain' in l: try: s = l.split('>')[1].split('<')[0].split(',') pdb = s[0][:4] chain = s[0][5] if len(s) < 2: continue segs = [] for s_ in s: if '_-' not in s_: start = int(''.join([ a for a in s_.split('_')[1].split('-')[0] if a not in ABC ])) end = int(''.join([ a for a in s_.split('_')[1].split('-')[1] if a not in ABC ])) if '_-' in s_: start = int(''.join([ a for a in s_.split('_-')[1].split('-')[0] if a not in ABC ])) end = int(''.join([ a for a in s_.split('_-')[1].split('-')[1] if a not in ABC ])) segs.append((start, end)) results.append( Entry(pdb, chain, segs, mp.XYZ(axis['x'], axis['y'], axis['z']))) except: print('SKIPPING', s) return results
def create_pdb_AA_AA_d_z(aa1: str, aa2: str, d: float, z: float, res_maker, path: str = './') -> None: """ create a pdb with residues aa1 and aa2 at the XY plane at Z=z and distance d """ res1 = res_maker.get_residue(aa1) res2 = res_maker.get_residue(aa2) res1.change_chain_name('A') res2.change_chain_name('B') # rotate around Z to oppose axis_z = mp.XYZ(0, 0, 1) res2.dot_matrix_me(mpf.rotation_matrix_around_vec(axis_z, np.pi)) # translate to get d distance move_d = mp.XYZ( 0, res1[res_maker.main_residue_atoms[res1.res_type][1]].xyz.y - res2[res_maker.main_residue_atoms[res2.res_type][1]].xyz.y + d, 0) res2.translate_xyz(move_d) # translate all to z move_z = mp.XYZ(0, 0, z) res1.translate_xyz(move_z) res2.translate_xyz(move_z) # setup in a MyPDB instance, and renumber and write pdb = mp.MyPDB() for res in [res1, res2]: for a in res.values(): pdb.add_atom(a) pdb.renumber() mp.write_PDB( '%s/%s_%s_%.2f_%.2f.pdb' % (path, res1.res_type, res2.res_type, d, z), pdb)
def translate_and_rotate_res_to_xy_plane(res: mp.Residue, atom_list: list) -> mp.Residue: xyz = copy.deepcopy(res[atom_list[0]].xyz) xyz = xyz.scalar_multi(-1) res.translate_xyz(xyz) # rotate a1 to xy plane proj_a2_xy = copy.deepcopy(res[atom_list[1]].xyz) proj_a2_xy.z = 0 a2_copy = copy.deepcopy(res[atom_list[1]].xyz) ang_a2_xy = np.arccos(a2_copy.unit().dot(proj_a2_xy.unit())) axis_a2_xy = a2_copy.unit().cross(proj_a2_xy.unit()).unit() rotation_matrix = rotation_matrix_around_vec(axis_a2_xy, ang_a2_xy) res.dot_matrix_me(rotation_matrix) # rotate a2 to xy plane proj_a2_xy = copy.deepcopy(res[atom_list[2]].xyz) proj_a2_xy.z = 0 a2_copy = copy.deepcopy(res[atom_list[2]].xyz) ang_a2_xy = np.arccos(a2_copy.unit().dot(proj_a2_xy.unit())) closest_point = point_on_normed_vec_closest_to_point( proj_a2_xy.as_nparray(), res[atom_list[1]].xyz.unit().as_nparray()) ang_a2_xy = angle_between_3_XYZs(a2_copy, closest_point, proj_a2_xy) axis = copy.deepcopy(res[atom_list[1]].xyz) rotation_matrix = rotation_matrix_around_vec(axis, -ang_a2_xy) res.dot_matrix_me(rotation_matrix) # rotate so that a2 and 3 are on both sides of the Y axis a1_copy = res[atom_list[0]].xyz a2_copy = res[atom_list[1]].xyz a3_copy = res[atom_list[2]].xyz ang_312 = angle_between_3_XYZs(a3_copy, a1_copy, a2_copy) ang_y12 = angle_between_3_XYZs(mp.XYZ(0, 1, 0), a1_copy, a2_copy) axis = mp.XYZ(0, 0, 1) rotation_matrix = rotation_matrix_around_vec(axis, -(ang_y12 + 0.5 * ang_312)) res.dot_matrix_me(rotation_matrix)
def test_symm_axis_interface(e: Entry, ch: str) -> bool: print(e) inter_resi = e.interface[ch] print(e.symm_segs) symm_resi = [a for seg in e.symm_segs for a in range(seg[0], seg[1] + 1)] print('symm_resi', symm_resi) print(inter_resi) pdb = mp.parse_PDB(find_pdb(e.pdb), with_non_residue=False) symm_com = mp.com_residues(chain=pdb[e.chain], residues=symm_resi) print(symm_resi, symm_com) pdb.translate_xyz(mp.XYZ(0, 0, 0) - symm_com) print('pdb translated') print('writing pdb %s_%s_translated.pdb' % (e.pdb, e.chain)) mp.write_PDB('%s_%s_translated.pdb' % (e.pdb, e.chain), pdb) print('now symm com is at', mp.com_residues(chain=pdb[e.chain], residues=symm_resi)) print('symm axis XYZ %r' % (e.symm_axis)) print_pymol_select(e)
def point_on_normed_vec_closest_to_point(p: np.array, v: np.array) -> mp.XYZ: vec = v * np.dot(p, v) return mp.XYZ(vec[0], vec[1], vec[2])