Skip to content

Commit

Permalink
Sort disconnected components based on node indices
Browse files Browse the repository at this point in the history
  • Loading branch information
pckroon committed Jun 19, 2023
1 parent a654745 commit 9176c48
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pysmiles/write_smiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,12 @@ def write_smiles(molecule, default_element='*', start=None):
The SMILES string describing `molecule`.
"""
smiles = []
for nodes in nx.connected_components(molecule):
components = list(nx.connected_components(molecule))
try:
components = sorted(components, key=lambda c: sorted(c))
except TypeError:
pass
for nodes in components:
if start is not None and start in nodes:
start_ = start
else:
Expand Down

0 comments on commit 9176c48

Please sign in to comment.