Skip to content

Commit

Permalink
UNFINISHED
Browse files Browse the repository at this point in the history
update external modules for separating `max_edge_distance` from `interaction_radius`
  • Loading branch information
DaniBodor committed Sep 18, 2023
1 parent 22030bc commit 0ac01c5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
12 changes: 6 additions & 6 deletions deeprank2/utils/buildgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
)
Expand Down Expand Up @@ -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.
Expand All @@ -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,
Expand Down
23 changes: 11 additions & 12 deletions deeprank2/utils/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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.
Expand All @@ -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:

Expand All @@ -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.
Expand All @@ -381,15 +380,15 @@ 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))

# point out the unique residues for the atom pairs
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]
Expand Down

0 comments on commit 0ac01c5

Please sign in to comment.