From 0ac01c58cf268749f56da4e323ae82200e153788 Mon Sep 17 00:00:00 2001 From: Dani Bodor Date: Mon, 18 Sep 2023 04:39:37 +0200 Subject: [PATCH] UNFINISHED update external modules for separating `max_edge_distance` from `interaction_radius` --- deeprank2/utils/buildgraph.py | 12 ++++++------ deeprank2/utils/graph.py | 23 +++++++++++------------ 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/deeprank2/utils/buildgraph.py b/deeprank2/utils/buildgraph.py index 9006fced6..2c5a4a943 100644 --- a/deeprank2/utils/buildgraph.py +++ b/deeprank2/utils/buildgraph.py @@ -156,14 +156,14 @@ def get_structure(pdb, id_: str) -> PDBStructure: def get_contact_atoms( # pylint: disable=too-many-locals pdb_path: str, chain_ids: List[str], - distance_cutoff: float + interaction_radius: float ) -> List[Atom]: """Gets the contact atoms from pdb2sql and wraps them in python objects.""" interface = get_interface(pdb_path) try: atom_indexes = interface.get_contact_atoms( - cutoff=distance_cutoff, + cutoff=interaction_radius, chain1=chain_ids[0], chain2=chain_ids[1], ) @@ -209,16 +209,16 @@ def get_residue_contact_pairs( # pylint: disable=too-many-locals structure: PDBStructure, chain_id1: str, chain_id2: str, - distance_cutoff: float, + interaction_radius: float, ) -> List[Pair]: - """Get the residues that contact each other at a protein-protein interface. + """Find all residue pairs that may influence each other. Args: pdb_path (str): The path of the pdb file, that the structure was built from. structure (:class:`PDBStructure`): From which to take the residues. chain_id1 (str): First protein chain identifier. chain_id2 (str): Second protein chain identifier. - distance_cutoff (float): Max distance between two interacting residues. + interaction_radius (float): Maximum distance between residues to consider them as interacting. Returns: List[Pair]: The pairs of contacting residues. @@ -228,7 +228,7 @@ def get_residue_contact_pairs( # pylint: disable=too-many-locals interface = get_interface(pdb_path) try: contact_residues = interface.get_contact_residues( - cutoff=distance_cutoff, + cutoff=interaction_radius, chain1=chain_id1, chain2=chain_id2, return_contact_pairs=True, diff --git a/deeprank2/utils/graph.py b/deeprank2/utils/graph.py index de6c23890..06412f518 100644 --- a/deeprank2/utils/graph.py +++ b/deeprank2/utils/graph.py @@ -5,15 +5,15 @@ import h5py import numpy as np import pdb2sql.transform -from deeprank2.molstruct.atom import Atom -from deeprank2.molstruct.pair import AtomicContact, Contact, ResidueContact -from deeprank2.molstruct.residue import Residue, get_residue_center -from deeprank2.utils.grid import Augmentation, Grid, GridSettings, MapMethod from scipy.spatial import distance_matrix from deeprank2.domain import edgestorage as Efeat from deeprank2.domain import nodestorage as Nfeat from deeprank2.domain import targetstorage as targets +from deeprank2.molstruct.atom import Atom +from deeprank2.molstruct.pair import AtomicContact, Contact, ResidueContact +from deeprank2.molstruct.residue import Residue, get_residue_center +from deeprank2.utils.grid import Augmentation, Grid, GridSettings, MapMethod _log = logging.getLogger(__name__) @@ -94,9 +94,8 @@ def position(self) -> np.array: class Graph: - def __init__(self, id_: str, cutoff_distance: Optional[float] = None): + def __init__(self, id_: str): self.id = id_ - self.cutoff_distance = cutoff_distance self._nodes = {} self._edges = {} @@ -320,7 +319,7 @@ def get_all_chains(self) -> List[str]: def build_atomic_graph( # pylint: disable=too-many-locals - atoms: List[Atom], graph_id: str, edge_distance_cutoff: float + atoms: List[Atom], graph_id: str, max_edge_distance: float ) -> Graph: """Builds a graph, using the atoms as nodes. @@ -332,9 +331,9 @@ def build_atomic_graph( # pylint: disable=too-many-locals positions[atom_index] = atom.position distances = distance_matrix(positions, positions, p=2) - neighbours = distances < edge_distance_cutoff + neighbours = distances < max_edge_distance - graph = Graph(graph_id, edge_distance_cutoff) + graph = Graph(graph_id) for atom1_index, atom2_index in np.transpose(np.nonzero(neighbours)): if atom1_index != atom2_index: @@ -355,7 +354,7 @@ def build_atomic_graph( # pylint: disable=too-many-locals def build_residue_graph( # pylint: disable=too-many-locals - residues: List[Residue], graph_id: str, edge_distance_cutoff: float + residues: List[Residue], graph_id: str, max_edge_distance: float ) -> Graph: """Builds a graph, using the residues as nodes. @@ -381,7 +380,7 @@ def build_residue_graph( # pylint: disable=too-many-locals distances = distance_matrix(positions, positions, p=2) # determine which atoms are close enough - neighbours = distances < edge_distance_cutoff + neighbours = distances < max_edge_distance atom_index_pairs = np.transpose(np.nonzero(neighbours)) @@ -389,7 +388,7 @@ def build_residue_graph( # pylint: disable=too-many-locals residue_index_pairs = np.unique(atoms_residues[atom_index_pairs], axis=0) # build the graph - graph = Graph(graph_id, edge_distance_cutoff) + graph = Graph(graph_id) for residue1_index, residue2_index in residue_index_pairs: residue1 = residues[residue1_index]