Skip to content

Commit f609e81

Browse files
committed
Remove alphabetical sort in descend_tree for overlapping children
When multiple tree children match a structure, the previous fix sorted them by label and picked the first. This breaks when siblings overlap (e.g. Nitrites sorts before Nitro alphabetically, but Nitro is the intended match because it appears first in the tree file). The tree is constructed deterministically from the database files, so the children list order is already deterministic. Simply picking the first matching child (next_node[0]) restores correct behavior while remaining deterministic. Fixes: - test_statmech: Nitro sample molecule was matching Nitrites (alphabetically first) instead of Nitro (tree order first) - test_degeneracy_keeps_separate_transition_states_separated - test_add_ring_correction_thermo_data_from_tree_for_existing_tricyclic
1 parent 39cecf0 commit f609e81

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

rmgpy/data/base.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,11 +1066,10 @@ def descend_tree(self, structure, atoms, root=None, strict=False):
10661066
else:
10671067
return root
10681068
else:
1069-
# Multiple children match - sort by node label for deterministic selection
1070-
next_node.sort(key=lambda n: n.label)
1071-
# logging.warning('For {0}, a node {1} with overlapping children {2} was encountered '
1072-
# 'in tree with top level nodes {3}. Assuming the first match is the '
1073-
# 'better one.'.format(structure, root, next, self.top))
1069+
# Multiple children match - pick the first in tree order.
1070+
# The tree is constructed deterministically, so this is deterministic.
1071+
# (Sorting by label can pick the wrong node when siblings overlap,
1072+
# e.g. Nitrites sorts before Nitro but Nitro is the intended match.)
10741073
return self.descend_tree(structure, atoms, next_node[0], strict)
10751074

10761075
def are_siblings(self, node, node_other):

0 commit comments

Comments
 (0)