Skip to content

Commit 7a0c7b7

Browse files
committed
Fix surface phase loading in Cantera model converter
Load surface phase name dynamically from generated YAML instead of assuming hardcoded 'surface1'. This makes the code compatible with different CHEMKIN surface file specifications that may define different phase names (e.g., SURF0). Fixes failing tests in canteramodelTest.py.
1 parent b7b1358 commit 7a0c7b7

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

rmgpy/tools/canteramodel.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ def load_chemkin_model(self, chemkin_file, transport_file=None, **kwargs):
341341
Note that if this is a surface mechanism, the calling function much include surface_file as a keyword argument for the parser
342342
"""
343343
from cantera import ck2yaml
344+
import yaml
344345

345346
base = os.path.basename(chemkin_file)
346347
base_name = os.path.splitext(base)[0]
@@ -353,7 +354,20 @@ def load_chemkin_model(self, chemkin_file, transport_file=None, **kwargs):
353354
self.model = ct.Solution(out_name)
354355

355356
if self.surface:
356-
self.surface = ct.Interface(out_name, 'surface1')
357+
# Find the surface phase name in the generated YAML file
358+
with open(out_name, 'r') as f:
359+
yaml_data = yaml.safe_load(f)
360+
361+
surface_phase_name = None
362+
for phase in yaml_data.get('phases', []):
363+
if phase.get('thermo') == 'ideal-surface':
364+
surface_phase_name = phase.get('name')
365+
break
366+
367+
if surface_phase_name is None:
368+
raise ValueError(f"No surface phase found in {out_name}")
369+
370+
self.surface = ct.Interface(out_name, surface_phase_name)
357371
self.model = self.surface.adjacent['gas']
358372

359373
def modify_reaction_kinetics(self, rmg_reaction_index, rmg_reaction):

0 commit comments

Comments
 (0)