Skip to content

Commit 5fa7bf7

Browse files
committed
Chemkin was not writing isotopes correctly.
In this patch, we skip using the Molecule.get_element_count() because that returns just the element.symbol, and deuterium is H.
1 parent d1473f8 commit 5fa7bf7

3 files changed

Lines changed: 21 additions & 2 deletions

File tree

rmgpy/chemkin.pyx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1588,8 +1588,13 @@ def write_thermo_entry(species, element_counts=None, verbose=True):
15881588
assert thermo.polynomials[1].cm2 == 0 and thermo.polynomials[1].cm1 == 0
15891589

15901590
# Determine the number of each type of element in the molecule
1591+
# Need to use the element's chemkin name, not the element symbol, because of isotopes.
1592+
# so we can't just use molecule[0].get_element_count().
15911593
if element_counts is None:
1592-
element_counts = get_element_count(species.molecule[0])
1594+
element_counts = {}
1595+
for atom in species.molecule[0].atoms:
1596+
element = atom.element.chemkin_name
1597+
element_counts[element] = element_counts.get(element, 0) + 1
15931598

15941599
# Sort the element_counts dictionary so that it's C, H, Al, B, Cl, D, etc.
15951600
# if there's any C, else Al, B, Cl, D, H, if not. This is the "Hill" system

rmgpy/molecule/element.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def __init__(self, number, symbol, name, mass, isotope=-1, chemkin_name=None):
7777
self.name = name
7878
self.mass = mass
7979
self.isotope = isotope
80-
self.chemkin_name = chemkin_name or self.name
80+
self.chemkin_name = chemkin_name or self.symbol
8181
if symbol in {'X','L','R','e'}:
8282
self.cov_radius = 0
8383
else:

test/rmgpy/chemkinTest.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,20 @@ def test_read_thermo_block(self):
791791
assert formula == {"H": 6, "C": 2}
792792
assert self.nasa.is_identical_to(thermo)
793793

794+
def test_write_thermo_block_for_isotope_uses_chemkin_name(self):
795+
"""Isotopic atoms should use their Chemkin names in thermo composition."""
796+
deuterium = Species().from_adjacency_list(
797+
"1 H u0 p0 c0 i2 {2,S}\n"
798+
"2 H u0 p0 c0 {1,S}"
799+
)
800+
deuterium.thermo = self.nasa
801+
802+
result = write_thermo_entry(deuterium, verbose=False)
803+
804+
first_line = result.splitlines()[0]
805+
assert "D 1" in first_line
806+
assert "H 1" in first_line
807+
794808
def test_write_thermo_block_5_elem(self):
795809
"""Test that we can write a thermo block for a species with 5 elements"""
796810
species = Species().from_adjacency_list(

0 commit comments

Comments
 (0)