From 244eee73961a4950675182424c4b654e5aa4958b Mon Sep 17 00:00:00 2001 From: Xavier Robin <xavalias-github@xavier.robin.name> Date: Mon, 30 Jan 2023 16:01:43 +0100 Subject: [PATCH] refactor: don't expose graphs Reason is, it's unclear if they are useful anywhere else --- modules/mol/alg/pymod/ligand_scoring.py | 12 ++++++------ modules/mol/alg/tests/test_ligand_scoring.py | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/modules/mol/alg/pymod/ligand_scoring.py b/modules/mol/alg/pymod/ligand_scoring.py index 5fd5aa78d..ff0fbfb78 100644 --- a/modules/mol/alg/pymod/ligand_scoring.py +++ b/modules/mol/alg/pymod/ligand_scoring.py @@ -725,7 +725,7 @@ class LigandScorer: return self._lddt_pli_details -def ResidueToGraph(residue, by_atom_index=False): +def _ResidueToGraph(residue, by_atom_index=False): """Return a NetworkX graph representation of the residue. :param residue: the residue from which to derive the graph @@ -738,12 +738,12 @@ def ResidueToGraph(residue, by_atom_index=False): :type by_atom_index: :class:`bool` :rtype: :class:`~networkx.classes.graph.Graph` - Nodes are labeled with the Atom's :attr:`~ost.mol.AtomHandle.mass`. + Nodes are labeled with the Atom's lowercase :attr:`~ost.mol.AtomHandle.element`. """ nxg = networkx.Graph() for atom in residue.atoms: - nxg.add_node(atom.name, element=atom.mass) + nxg.add_node(atom.name, element=atom.element.lower()) # This will list all edges twice - once for every atom of the pair. # But as of NetworkX 3.0 adding the same edge twice has no effect, so we're good. @@ -844,8 +844,8 @@ def _ComputeSymmetries(model_ligand, target_ligand, substructure_match=False, """ # Get the Graphs of the ligands - model_graph = ResidueToGraph(model_ligand, by_atom_index=by_atom_index) - target_graph = ResidueToGraph(target_ligand, by_atom_index=by_atom_index) + model_graph = _ResidueToGraph(model_ligand, by_atom_index=by_atom_index) + target_graph = _ResidueToGraph(target_ligand, by_atom_index=by_atom_index) if not networkx.is_connected(model_graph): raise RuntimeError("Disconnected graph for model ligand %s" % model_ligand) @@ -891,4 +891,4 @@ class NoSymmetryError(Exception): pass -__all__ = ["LigandScorer", "ResidueToGraph", "SCRMSD", "NoSymmetryError"] +__all__ = ["LigandScorer", "SCRMSD", "NoSymmetryError"] diff --git a/modules/mol/alg/tests/test_ligand_scoring.py b/modules/mol/alg/tests/test_ligand_scoring.py index 1b2d1b244..37aa4c514 100644 --- a/modules/mol/alg/tests/test_ligand_scoring.py +++ b/modules/mol/alg/tests/test_ligand_scoring.py @@ -137,13 +137,13 @@ class TestLigandScoring(unittest.TestCase): """ mdl_lig = io.LoadEntity(os.path.join('testfiles', "P84080_model_02_ligand_0.sdf")) - graph = _ResidueToGraph(mdl_lig.residues[0]) + graph = ligand_scoring._ResidueToGraph(mdl_lig.residues[0]) assert len(graph.edges) == 34 assert len(graph.nodes) == 32 # Check an arbitrary node assert [a for a in graph.adj["14"].keys()] == ["13", "29"] - graph = _ResidueToGraph(mdl_lig.residues[0], by_atom_index=True) + graph = ligand_scoring._ResidueToGraph(mdl_lig.residues[0], by_atom_index=True) assert len(graph.edges) == 34 assert len(graph.nodes) == 32 # Check an arbitrary node -- GitLab