Skip to content

Commit

Permalink
prepare release
Browse files Browse the repository at this point in the history
  • Loading branch information
TieuLongPhan committed Dec 5, 2024
1 parent 42ba92d commit 5efa323
Show file tree
Hide file tree
Showing 7 changed files with 516 additions and 122 deletions.
105 changes: 77 additions & 28 deletions Test/SynGraph/Descriptor/test_graph_signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,92 @@ def setUp(self):
data = load_from_pickle("Data/test.pkl.gz")
self.rc = data[0]["GraphRules"][2]
self.its = data[0]["ITSGraph"][2]
self.graph_signature = GraphSignature(self.its)

def test_create_topology_signature(self):
signature = GraphSignature(self.rc)
self.assertEqual(
signature.create_topology_signature(
topo="Single Cyclic", cycle=[4], rstep=1
),
"114",
def test_validate_graph(self):
"""Test the validation of graph structure"""
# Test should pass if graph is valid (no exceptions)
try:
self.graph_signature._validate_graph()
except ValueError as e:
self.fail(f"Graph validation failed: {str(e)}")

def test_edge_signature(self):
"""Test edge signature creation"""
edge_signature = self.graph_signature.create_edge_signature(
include_neighbors=False, max_hop=1
)

# Check that the edge signature is a non-empty string
self.assertIsInstance(edge_signature, str)
self.assertGreater(len(edge_signature), 0)
self.assertIn("Br0", edge_signature)
self.assertIn("{0.0,1.0}", edge_signature)
self.assertIn("H0", edge_signature)

def test_edge_signature_with_neighbors(self):
"""Test edge signature creation including neighbors"""
edge_signature_with_neighbors = self.graph_signature.create_edge_signature(
include_neighbors=True, max_hop=1
)

def test_create_node_signature(self):
signature = GraphSignature(self.rc)
self.assertEqual(signature.create_node_signature(), "BrCHN")
# Check that the edge signature with neighbors includes node degrees and neighbors
self.assertIsInstance(edge_signature_with_neighbors, str)
self.assertGreater(len(edge_signature_with_neighbors), 0)
self.assertIn("d1", edge_signature_with_neighbors) # node degree for neighbor

def test_create_node_signature_condensed(self):
signature = GraphSignature(self.its)
self.assertEqual(signature.create_node_signature(), "BrC{23}ClHN{3}O{5}S")
def test_wl_hash(self):
"""Test the Weisfeiler-Lehman hash generation"""
wl_hash = self.graph_signature.create_wl_hash(iterations=3)

def test_create_edge_signature(self):
signature = GraphSignature(self.rc)
self.assertEqual(
signature.create_edge_signature(), "Br[-1]H/Br[1]C/C[-1]N/H[1]N"
# Check that the WL hash is a valid hexadecimal string
self.assertIsInstance(wl_hash, str)
self.assertRegex(wl_hash, r"^[a-f0-9]{64}$") # SHA-256 hash format

def test_graph_signature(self):
"""Test the complete graph signature creation"""
complete_graph_signature = self.graph_signature.create_graph_signature(
include_wl_hash=True, include_neighbors=True, max_hop=1
)

def test_create_graph_signature(self):
# Ensure the graph signature combines the results correctly
signature = GraphSignature(self.rc)
node_signature = "BrCHN"
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(topo="Single Cyclic", cycle=[4], rstep=1),
expected,
# Check that the graph signature is a non-empty string
self.assertIsInstance(complete_graph_signature, str)
self.assertGreater(len(complete_graph_signature), 0)

def test_invalid_node_attributes(self):
"""Test for missing node attributes"""
self.rc.add_node(4) # Missing 'element' and 'charge'

with self.assertRaises(ValueError) as context:
invalid_graph_signature = GraphSignature(self.rc)
invalid_graph_signature._validate_graph()

self.assertIn(
"Node 4 is missing the 'element' attribute", str(context.exception)
)

def test_invalid_edge_order(self):
"""Test for invalid edge 'order' attribute"""
self.its.add_edge(
3, 4, order="invalid_order", state="steady"
) # Invalid 'order' type

with self.assertRaises(ValueError) as context:
invalid_graph_signature = GraphSignature(self.its)
invalid_graph_signature._validate_graph()

self.assertIn("Edge (3, 4) has an invalid 'order'", str(context.exception))

def test_invalid_edge_state(self):
"""Test for invalid edge 'state' attribute"""
self.its.add_edge(2, 4, order=1.0, state="invalid_state") # Invalid 'state'

with self.assertRaises(ValueError) as context:
invalid_graph_signature = GraphSignature(self.its)
invalid_graph_signature._validate_graph()

self.assertIn("Edge (2, 4) has an invalid 'state'", str(context.exception))


# Running the tests
if __name__ == "__main__":
unittest.main()
3 changes: 2 additions & 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.12"
version = "0.0.13"
authors = [
{name="Tieu Long Phan", email="[email protected]"}
]
Expand All @@ -22,6 +22,7 @@ dependencies = [
"rdkit>=2024.3.3",
"networkx>=3.3",
"seaborn>=0.13.2",
"requests>=3.4.0",
]

[project.optional-dependencies]
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ rxn-chem-utils==1.5.0
rxn-utils==2.0.0
rxnmapper==0.3.0
rdkit >= 2024.3.3
pandas>=2.2.0
pandas>=2.2.0
requests>=3.4.0
Loading

0 comments on commit 5efa323

Please sign in to comment.