Skip to content

Commit

Permalink
enhance graph descriptors
Browse files Browse the repository at this point in the history
  • Loading branch information
TieuLongPhan committed Dec 17, 2024
1 parent 3b6e031 commit 8da3ad6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
Empty file added CHANGELOG.md
Empty file.
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ build-backend = "hatchling.build"

[project]
name = "synutility"
version = "0.0.13"
version = "0.0.14"
authors = [
{name="Tieu Long Phan", email="[email protected]"}
]
description = "Utility for reaction modeling using graph grammar"
readme = "README.md"
long-description = {file = "CHANGELOG.md"}
long-description-content-type = "text/markdown"
requires-python = ">=3.11"
classifiers = [
"Programming Language :: Python :: 3",
Expand All @@ -32,4 +34,4 @@ all = ["drfp==0.3.6", "xgboost>=2.1.1", "fgutils>=0.1.3", "rxn-chem-utils==1.5.0
homepage = "https://github.com/TieuLongPhan/SynUtils"
source = "https://github.com/TieuLongPhan/SynUtils"
issues = "https://github.com/TieuLongPhan/SynUtils/issues"
documentation = "https://tieulongphan.github.io/SynUtils/"
documentation = "https://tieulongphan.github.io/SynUtils/"
4 changes: 2 additions & 2 deletions synutility/SynAAM/its_construction.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import networkx as nx
from typing import Tuple, Dict, Any
from copy import deepcopy
from copy import deepcopy, copy


class ITSConstruction:
Expand Down Expand Up @@ -136,7 +136,7 @@ def add_edges_to_ITS(
Returns:
- nx.Graph: The updated graph with added edges.
"""
new_ITS = deepcopy(ITS)
new_ITS = ITS.copy()

# Add edges from G and H
for graph_from, graph_to, reverse in [(G, H, False), (H, G, True)]:
Expand Down
24 changes: 18 additions & 6 deletions synutility/SynGraph/Descriptor/graph_descriptors.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,30 @@ def check_graph_type(G: nx.Graph) -> str:
return "Complex Cyclic"

@staticmethod
def get_cycle_member_rings(G: nx.Graph) -> List[int]:
def get_cycle_member_rings(G: nx.Graph, type="minimal") -> List[int]:
"""
Finds all cycles in the graph and returns a list of their sizes.
Identifies all cycles in the given graph using cycle bases to ensure no overlap
and returns a list of the sizes of these cycles (member rings),
sorted in ascending order.
Parameters:
- G (nx.Graph): The graph to analyze.
- G (nx.Graph): The NetworkX graph to be analyzed.
Returns:
- List[int]: Sorted list of cycle sizes.
- List[int]: A sorted list of cycle sizes (member rings) found in the graph.
"""
GraphDescriptor._validate_graph_input(G)
return sorted(len(cycle) for cycle in nx.minimum_cycle_basis(G))
if not isinstance(G, nx.Graph):
raise TypeError("Input must be a networkx Graph object.")

if type == "minimal":
cycles = nx.minimum_cycle_basis(G)
else:
cycles = nx.cycle_basis(G)
member_rings = [len(cycle) for cycle in cycles]

member_rings.sort()

return member_rings

@staticmethod
def get_element_count(graph: nx.Graph) -> Dict[str, int]:
Expand Down

0 comments on commit 8da3ad6

Please sign in to comment.