Skip to content
Snippets Groups Projects
Unverified Commit 244eee73 authored by Xavier Robin's avatar Xavier Robin
Browse files

refactor: don't expose graphs

Reason is, it's unclear if they are useful anywhere else
parent 8cc728bb
Branches
Tags
No related merge requests found
......@@ -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"]
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment