Skip to content

Commit

Permalink
Fix bug in sorting molecules.
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
rwest committed Nov 13, 2024
1 parent dec6c76 commit b3b1714
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions rmgpy/data/thermo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down

0 comments on commit b3b1714

Please sign in to comment.