Skip to content

Commit

Permalink
v0.0.8 (#3)
Browse files Browse the repository at this point in the history
* Update README.md

* Update test-and-lint.yml

* prepare release v0.0.7

* fix issue in implicit hydrogen computation

* allow non-carbon atoms to belong to no functional group

* fix linting

* prepare release v0.0.8

---------

Co-authored-by: Klaus Weinbauer <klaus@becks.bioinf.uni-leipzig.de>
  • Loading branch information
klausweinbauer and Klaus Weinbauer authored Apr 15, 2024
1 parent be2f6d4 commit ef2547c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 11 deletions.
9 changes: 0 additions & 9 deletions fgutils/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,6 @@ def __get_functional_groups(self, graph: nx.Graph) -> list[tuple[str, list[int]]
elif i in unidentified_ids:
unidentified_ids.remove(i)
groups.append((node.fgconfig.name, indices))
if len(unidentified_ids) > 0:
raise RuntimeError(
"Could not find a functional group for atom(s) {}.".format(
[
"{}@{}".format(graph.nodes[i]["symbol"], i)
for i in unidentified_ids
]
)
)
return groups

def get(self, value) -> list[tuple[str, list[int]]]:
Expand Down
2 changes: 1 addition & 1 deletion fgutils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def add_implicit_hydrogens(graph: nx.Graph) -> nx.Graph:
n_sym in valence_table.keys()
), "Element {} not found in valence table.".format(n_sym)
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
h_cnt = int(8 - valence_table[n_sym] - bond_cnt)
assert h_cnt >= 0, "Negative hydrogen count."
for h_id in range(len(graph), len(graph) + h_cnt):
graph.add_node(h_id, symbol="H")
graph.add_edge(n_id, h_id, bond=1)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "fgutils"
version = "0.0.7"
version = "0.0.8"
authors = [{name="Klaus Weinbauer", email="klaus@bioinf.uni-leipzig.de"}]
description = "Library to get functional groups from molecular graphs."
readme = "README.md"
Expand Down
35 changes: 35 additions & 0 deletions test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,38 @@ def test_add_implicit_hydrogens_3():
assert 6 == len(graph)
_assert_Hs(graph, 1, 3)
_assert_Hs(graph, 4, 1)


def test_sulfur_ring():
graph = parse("C:1N:C:S:C:1")
graph = add_implicit_hydrogens(graph)
assert 8 == len(graph)
_assert_Hs(graph, 0, 1)
_assert_Hs(graph, 1, 0)
_assert_Hs(graph, 2, 1)
_assert_Hs(graph, 3, 0)
_assert_Hs(graph, 4, 1)


def test_nitrogen_5ring():
graph = parse("C:1C:N(H):C:C:1")
graph = add_implicit_hydrogens(graph)
assert 10 == len(graph)
_assert_Hs(graph, 0, 1)
_assert_Hs(graph, 1, 1)
_assert_Hs(graph, 2, 1)
_assert_Hs(graph, 3, 0)
_assert_Hs(graph, 4, 1)
_assert_Hs(graph, 5, 1)


def test_nitrogen_6ring():
graph = parse("C:1C:C:N:C:C:1")
graph = add_implicit_hydrogens(graph)
assert 11 == len(graph)
_assert_Hs(graph, 0, 1)
_assert_Hs(graph, 1, 1)
_assert_Hs(graph, 2, 1)
_assert_Hs(graph, 3, 0)
_assert_Hs(graph, 4, 1)
_assert_Hs(graph, 5, 1)

0 comments on commit ef2547c

Please sign in to comment.