Skip to content

Commit

Permalink
Prepare release v.0.0.10 (#11)
Browse files Browse the repository at this point in the history
 Improvements:

- Combine graph descriptors and graph fingerprints
- Add parallel processing
- Add MØD rule apply (not testing yet due to conflict in conda)

Bug fix:

- MolToGraph adapted unsanitized rdkit.Mol


* add graph_descriptors

* update doc

* prepare release

* fix version

* prepare release

* prepare release 0.0.8

* update Molecule subpackage

* update reaction cleaning

* add graph fingerprint

* update graph signature

* add nx_to_gml function

* update format package, transforming gml to nx and reverse; transformaing mol to nx and reverse

* format

* add new features, prepare release

* fix format

* combine graph descriptors, add parallel, fix MolToGraph

* prepare release 0.0.10
  • Loading branch information
TieuLongPhan authored Nov 11, 2024
1 parent fa4868b commit 8c17232
Show file tree
Hide file tree
Showing 7 changed files with 267 additions and 170 deletions.
57 changes: 38 additions & 19 deletions Test/SynGraph/Descriptor/test_graph_descriptors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import unittest
import networkx as nx
from synutility.SynIO.data_type import load_from_pickle
from synutility.SynGraph.Descriptor.graph_descriptors import GraphDescriptor


Expand Down Expand Up @@ -84,7 +85,9 @@ def setUp(self):
self.graph.add_edge(35, 29, order=(0, 1.0), standard_order=-1.0)
self.graph.add_edge(28, 29, order=(1.0, 0), standard_order=1.0)
# Prepare the data dictionary
self.data = [{"RC": self.graph}]
self.data = {"RC": self.graph, "ITS": self.graph}

self.data_parallel = load_from_pickle("Data/test.pkl.gz")

def test_is_acyclic_graph(self):
self.assertTrue(GraphDescriptor.is_acyclic_graph(self.acyclic_graph))
Expand Down Expand Up @@ -149,27 +152,43 @@ def test_get_element_count(self):

def test_get_descriptors(self):
# Expected output after processing
expected_output = [
{
"RC": self.graph,
"topo": "Single Cyclic", # Adjust based on expected graph type analysis
"cycle": [
4
], # Expected cycle results, to be filled after actual function implementation
"atom_count": {"N": 1, "H": 1, "C": 1, "Br": 1},
"rtype": "Elementary", # Expected reaction type
"rstep": 1, # This should be based on the actual cycles count
}
]
expected_output = {
"RC": self.graph,
"topo": "Single Cyclic", # Adjust based on expected graph type analysis
"cycle": [
4
], # Expected cycle results, to be filled after actual function implementation
"atom_count": {"N": 1, "H": 1, "C": 1, "Br": 1},
"rtype": "Elementary", # Expected reaction type
"rstep": 1, # This should be based on the actual cycles count
}

# Run the descriptor function
GraphDescriptor.get_descriptors(self.data, "RC")
results = GraphDescriptor.get_descriptors(self.data, "RC")
self.assertEqual(results["topo"], expected_output["topo"])
self.assertEqual(results["cycle"], expected_output["cycle"])
self.assertEqual(results["rstep"], expected_output["rstep"])
self.assertEqual(results["atom_count"], expected_output["atom_count"])

def test_get_descriptors_parallel(self):
# Expected output after processing
expected_output = {
"RC": self.graph,
"topo": "Single Cyclic",
"cycle": [4],
"atom_count": {"N": 1, "H": 1, "C": 1, "Br": 1},
"rtype": "Elementary",
"rstep": 1,
}

# Validate that the data has been enhanced correctly
for obtained, expected in zip(self.data, expected_output):
print("Hi", obtained)
print("hiii", expected)
self.assertDictEqual(obtained, expected)
# Run the descriptor function
results = GraphDescriptor.process_entries_in_parallel(
self.data_parallel, "GraphRules", "ITSGraph", n_jobs=4
)
self.assertEqual(results[0]["topo"], expected_output["topo"])
self.assertEqual(results[0]["cycle"], expected_output["cycle"])
self.assertEqual(results[0]["rstep"], expected_output["rstep"])
self.assertEqual(results[0]["atom_count"], expected_output["atom_count"])


if __name__ == "__main__":
Expand Down
12 changes: 10 additions & 2 deletions Test/SynGraph/Descriptor/test_graph_signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ def setUp(self):

def test_create_topology_signature(self):
signature = GraphSignature(self.rc)
self.assertEqual(signature.create_topology_signature(), "114")
self.assertEqual(
signature.create_topology_signature(
topo="Single Cyclic", cycle=[4], rstep=1
),
"114",
)

def test_create_node_signature(self):
signature = GraphSignature(self.rc)
Expand All @@ -36,7 +41,10 @@ def test_create_graph_signature(self):
edge_signature = "Br[-1]H/Br[1]C/C[-1]N/H[1]N"
topo_signature = "114"
expected = f"{topo_signature}.{node_signature}.{edge_signature}"
self.assertEqual(signature.create_graph_signature(), expected)
self.assertEqual(
signature.create_graph_signature(topo="Single Cyclic", cycle=[4], rstep=1),
expected,
)


# Running the tests
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 = "synutility"
version = "0.0.9"
version = "0.0.10"
authors = [
{name="Tieu Long Phan", email="[email protected]"}
]
Expand Down
Loading

0 comments on commit 8c17232

Please sign in to comment.