Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1import io
2from pathlib import Path
4import kmbio.PDB
5from kmtools import structure_tools
6from tkpod.plugins.modeller import Modeller
8from .adjacency_matrix import get_interaction_dataset
11def get_modeller_scores(row):
12 structure_data = row.structure_text
13 fh = io.StringIO()
14 fh.write(structure_data)
15 fh.seek(0)
17 parser = kmbio.PDB.PDBParser()
18 structure = parser.get_structure(fh, bioassembly_id=False)
19 chain = structure[0][row.chain_id]
20 sequence = structure_tools.get_chain_sequence(chain)
22 target = structure_tools.DomainTarget(0, row.chain_id, sequence, 1, len(sequence), sequence)
23 modeller_data = Modeller.build(structure, bioassembly_id=False, use_strict_alignment=True)
24 structure_bm, modeller_results = Modeller.create_model([target], modeller_data)
26 return structure_bm, sequence, modeller_results
29def get_pdb_interactions(row, pdb_ffindex_path: Path):
30 structure_id, _, chain_id = row.template_id.partition("_")
31 structure_url = f"ff://{pdb_ffindex_path}?{structure_id.lower()}.cif.gz"
33 with kmbio.PDB.open_url(structure_url) as fin:
34 structure = kmbio.PDB.MMCIFParser().get_structure(fin)
35 fin.seek(0)
36 structure_dict = kmbio.PDB.mmcif2dict(fin)
38 chain_sequence = structure_tools.get_chain_sequence(structure[0][chain_id])
40 if isinstance(structure_dict["_entity_poly.pdbx_strand_id"], str):
41 construct_sequence = structure_dict["_entity_poly.pdbx_seq_one_letter_code_can"]
42 else:
43 seq_idx = [
44 i
45 for i, v in enumerate(structure_dict["_entity_poly.pdbx_strand_id"])
46 if chain_id in v.split(",")
47 ][0]
48 construct_sequence = structure_dict["_entity_poly.pdbx_seq_one_letter_code_can"][seq_idx]
50 try:
51 offset = construct_sequence.index(chain_sequence[:10])
52 except ValueError:
53 offset = 0
55 target_1 = structure_tools.DomainTarget(
56 0,
57 chain_id,
58 row.template_ali,
59 row.template_start - offset,
60 row.template_end - offset,
61 row.query_ali,
62 )
64 modeller_data = Modeller.build(
65 structure_url, use_auth_id=True, bioassembly_id=False, use_strict_alignment=False
66 )
68 # ---
70 structure_fixed = kmbio.PDB.load(
71 modeller_data.structure_file, bioassembly_id=modeller_data.bioassembly_id
72 )
73 structure_fixed_cut, alignment = structure_tools.prepare_for_modeling(
74 structure_fixed, [target_1], strict=modeller_data.use_strict_alignment
75 )
77 interactions_core, interactions_core_aggbychain = get_interaction_dataset(structure_fixed_cut)
78 return interactions_core, interactions_core_aggbychain
81def get_homology_model_interactions(row):
82 structure_data = row.structure_text
83 fh = io.StringIO()
84 fh.write(structure_data)
85 fh.seek(0)
87 parser = kmbio.PDB.PDBParser()
88 structure = parser.get_structure(fh)
89 structure.id = row.unique_id
90 interactions_core, interactions_core_aggbychain = get_interaction_dataset(structure)
91 return interactions_core, interactions_core_aggbychain