From a1e49931a90ede00483732ed647b55a9181fc92f Mon Sep 17 00:00:00 2001 From: Klaus Weinbauer <51136324+klausweinbauer@users.noreply.github.com> Date: Wed, 15 May 2024 14:19:05 +0200 Subject: [PATCH] Change how implicit hydrogens are added (#11) * change how implicit hydroges are added to the graph --- fgutils/utils.py | 8 +++++--- pyproject.toml | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/fgutils/utils.py b/fgutils/utils.py index fa1efdd..20e6063 100644 --- a/fgutils/utils.py +++ b/fgutils/utils.py @@ -41,9 +41,11 @@ def add_implicit_hydrogens(graph: nx.Graph) -> nx.Graph: if n_sym not in ["R", "H"] ] for n_id, n_sym in nodes: - assert ( - n_sym in valence_table.keys() - ), "Element {} not found in valence table.".format(n_sym) + if n_sym not in valence_table.keys(): + # No hydrogens are added if element is not in dict. These atoms + # are most likley not part of a functional group anyway so skipping + # hydrogens is fine + continue bond_cnt = sum([b for _, _, b in graph.edges(n_id, data="bond")]) # type: ignore # h_cnt can be negative; aromaticity is complicated, we just ignore that valence = valence_table[n_sym] diff --git a/pyproject.toml b/pyproject.toml index e4b809a..9918c45 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "fgutils" -version = "0.0.15" +version = "0.0.16" authors = [{name="Klaus Weinbauer", email="klaus@bioinf.uni-leipzig.de"}] description = "Library to get functional groups from molecular graphs." readme = "README.md"