Skip to content

Commit

Permalink
Revert to node numbering based on list of solvent-exposed residues - …
Browse files Browse the repository at this point in the history
…more efficient
  • Loading branch information
jvsguerra committed Sep 21, 2021
1 parent bd6d6f5 commit 251c662
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
6 changes: 4 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ In addition, users can save graph as a PDB file, with nodes represented by the C

.. code:: python
>>> SERD.g2pdb(graph, atomic, 'graph.pdb')
>>> SERD.g2pdb(graph, atomic, residues, 'graph.pdb')
If users prefer, instead of running **SERD.detect** function, users can apply the detection of solvent-exposed residues in a step-by-step fashion. Below, we briefly describe this procedure.

Expand Down Expand Up @@ -476,7 +476,7 @@ Create a graph from a list of solvent-exposed residues.

Cutoff for beta-carbon is based on CAPRI round 28. For more details, refer to https://www.ebi.ac.uk/msd-srv/capri/round28/round28.html.

**SERD.g2pdb(graph, atomic, fn='graph.pdb')**
**SERD.g2pdb(graph, atomic, residues, fn='graph.pdb')**

Save a graph to a PDB-formatted file. Each node are represented by the
CA atom of the residue and edges are represented by CONECT record.
Expand All @@ -487,6 +487,8 @@ Create a graph from a list of solvent-exposed residues.
* **atomic** (*numpy.ndarray*) – A numpy array with atomic data (residue number, chain, residue name, atom name, xyz coordinates
and radius) for each atom.

* **residues** – A list of solvent-exposed residues.

* **fn** (`Union <https://docs.python.org/3/library/typing.html#typing.Union>`_\[`str <https://docs.python.org/3/library/stdtypes.html#str>`_, `pathlib.Path <https://docs.python.org/3/library/pathlib.html#pathlib.Path>`_], *optional*) – A path to a PDB file, by default “graph.pdb”.

*******
Expand Down
14 changes: 8 additions & 6 deletions SERD/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -824,24 +824,22 @@ def r2g(
if selection != "all":
atomic = _get_atom_selection(atomic, selection=selection)

# Keep solvent exposed residues
# https://stackoverflow.com/questions/51352527/check-for-identical-rows-in-different-numpy-arrays
atomic = atomic[(atomic[:, 0:3][:, None] == residues).all(-1).any(-1)]

# Calculate distance
distance = _calculate_distance(atomic[:, 4:7])

if selection == "all":
distance = _all_atoms_to_residues(atomic, distance)
atomic = _get_atom_selection(atomic, selection=selection)

# Calculate adjacency matrix
if intraresidual:
adjacency = (distance < cutoff).astype(int)
else:
adjacency = numpy.logical_and(distance > 0.0, distance < cutoff).astype(int)

# Keep solvent exposed residues
# https://stackoverflow.com/questions/51352527/check-for-identical-rows-in-different-numpy-arrays
adjacency[:, ~(atomic[:, 0:3][:, None] == residues).all(-1).any(-1)] = 0
adjacency[~(atomic[:, 0:3][:, None] == residues).all(-1).any(-1), :] = 0

# Create networkx.Graph
G = networkx.Graph()
G.add_edges_from(numpy.argwhere(adjacency))
Expand All @@ -852,6 +850,7 @@ def r2g(
def g2pdb(
graph: networkx.classes.graph.Graph,
atomic: numpy.ndarray,
residues: List[List[str]],
fn: Union[str, pathlib.Path] = "graph.pdb",
):
"""Save a graph to a PDB-formatted file. Each node are represented by the
Expand All @@ -864,11 +863,14 @@ def g2pdb(
atomic : numpy.ndarray
A numpy array with atomic data (residue number, chain, residue name, atom name, xyz coordinates
and radius) for each atom.
residues : List[List[str]]
A list of solvent-exposed residues.
fn : Union[str, pathlib.Path], optional
A path to a PDB file, by default "graph.pdb".
"""
# Get atom information of solvent-exposed residues
atomic = _get_atom_selection(atomic, selection="CA")
atomic = atomic[(atomic[:, 0:3][:, None] == residues).all(-1).any(-1)]

# Write nodes to pdb
with open(fn, "w") as f:
Expand Down

0 comments on commit 251c662

Please sign in to comment.