From 251c66277192bd947814cf723abcc28a771de330 Mon Sep 17 00:00:00 2001 From: jvsguerra Date: Tue, 21 Sep 2021 18:50:24 -0300 Subject: [PATCH] Revert to node numbering based on list of solvent-exposed residues - more efficient --- README.rst | 6 ++++-- SERD/__init__.py | 14 ++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/README.rst b/README.rst index 3051574..36d3ed6 100644 --- a/README.rst +++ b/README.rst @@ -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. @@ -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. @@ -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 `_\[`str `_, `pathlib.Path `_], *optional*) – A path to a PDB file, by default “graph.pdb”. ******* diff --git a/SERD/__init__.py b/SERD/__init__.py index 006b6d1..2951549 100644 --- a/SERD/__init__.py +++ b/SERD/__init__.py @@ -824,12 +824,15 @@ 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: @@ -837,11 +840,6 @@ def r2g( 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)) @@ -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 @@ -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: