From 1ae09c5f112c4459b23df7da2da2b0eb8f344c84 Mon Sep 17 00:00:00 2001 From: Richard West Date: Wed, 13 Nov 2024 08:31:34 -0500 Subject: [PATCH] Fix bug in sorting molecules. If two resonance structures had the same H298 then it would look to the second element of the tuples to sort and crash. This should avoid that (hopefully). --- rmgpy/data/thermo.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/rmgpy/data/thermo.py b/rmgpy/data/thermo.py index e2bacdedd5..e59e709211 100644 --- a/rmgpy/data/thermo.py +++ b/rmgpy/data/thermo.py @@ -1631,19 +1631,18 @@ def species_enthalpy(species): else: atom.label = label - # a tuple of the H298, the ThermoData object, and the molecule - resonance_data.append((thermo.get_enthalpy(298), thermo, molecule)) + # a tuple of molecule and its thermo + resonance_data.append((molecule, thermo)) # Get the enthalpy of formation of every adsorbate at 298 K and # determine the resonance structure with the lowest enthalpy of formation. # We assume that the lowest enthalpy of formation is the correct - # thermodynamic property for the adsorbate. + # thermodynamic property for the adsorbate, and the preferred representation. - # first element of each tuple is H298, so sort by that - resonance_data = sorted(resonance_data) + resonance_data = sorted(resonance_data, key=lambda x: x[1].H298.value_si) # reorder the resonance structures (molecules) by their H298 - species.molecule = [mol for h, thermo, mol in resonance_data] + species.molecule = [mol for mol, thermo in resonance_data] thermo = resonance_data[0][1]