Skip to content

Commit 20843b0

Browse files
rwestbjkreitz
authored andcommitted
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).
1 parent cc33d89 commit 20843b0

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

rmgpy/data/thermo.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,19 +1646,18 @@ def species_enthalpy(species):
16461646
else:
16471647
atom.label = label
16481648

1649-
# a tuple of the H298, the ThermoData object, and the molecule
1650-
resonance_data.append((thermo.get_enthalpy(298), thermo, molecule))
1649+
# a tuple of molecule and its thermo
1650+
resonance_data.append((molecule, thermo))
16511651

16521652
# Get the enthalpy of formation of every adsorbate at 298 K and
16531653
# determine the resonance structure with the lowest enthalpy of formation.
16541654
# We assume that the lowest enthalpy of formation is the correct
1655-
# thermodynamic property for the adsorbate.
1655+
# thermodynamic property for the adsorbate, and the preferred representation.
16561656

1657-
# first element of each tuple is H298, so sort by that
1658-
resonance_data = sorted(resonance_data)
1657+
resonance_data = sorted(resonance_data, key=lambda x: x[1].H298.value_si)
16591658

16601659
# reorder the resonance structures (molecules) by their H298
1661-
species.molecule = [mol for h, thermo, mol in resonance_data]
1660+
species.molecule = [mol for mol, thermo in resonance_data]
16621661

16631662
thermo = resonance_data[0][1]
16641663

0 commit comments

Comments
 (0)