2828###############################################################################
2929
3030import os
31-
32-
3331import numpy as np
32+ import tempfile
3433
3534import rmgpy
3635from rmgpy .quantity import Quantity
@@ -42,7 +41,6 @@ def test_ignition_delay(self):
4241 """
4342 Test that find_ignition_delay() works.
4443 """
45-
4644 t = np .arange (0 , 5 , 0.5 )
4745 P = np .array ([0 , 0.33 , 0.5 , 0.9 , 2 , 4 , 15 , 16 , 16.1 , 16.2 ])
4846 OH = np .array ([0 , 0.33 , 0.5 , 0.9 , 2 , 4 , 15 , 16 , 7 , 2 ])
@@ -82,7 +80,6 @@ class RMGToCanteraTest:
8280
8381 def setup_class (self ):
8482 from rmgpy .chemkin import load_chemkin_file
85-
8683 folder = os .path .join (os .path .dirname (rmgpy .__file__ ), "tools/data/various_kinetics" )
8784
8885 chemkin_path = os .path .join (folder , "chem_annotated.inp" )
@@ -118,19 +115,32 @@ def setup_class(self):
118115 self .rmg_surface_ct_reactions .extend (converted_reactions )
119116 else :
120117 self .rmg_surface_ct_reactions .append (converted_reactions )
118+
119+ with open (chemkin_surface_path , 'r' ) as f :
120+ surface_content = f .read ()
121+ if "SITE SDEN" in surface_content :
122+ # Inject a dummy phase name 'SURF'
123+ surface_content = surface_content .replace ("SITE SDEN" , "SITE SURF SDEN" )
124+
125+ # Write to a temporary file to avoid modifying the repo's test data
126+ tf = tempfile .NamedTemporaryFile (mode = 'w' , delete = False , suffix = '.inp' )
127+ tf .write (surface_content )
128+ tf .close ()
129+ # Use the temp file for Cantera loading
130+ chemkin_surface_path = tf .name
131+
132+
121133 job = Cantera ()
122134 job .surface = True
123- job .load_chemkin_model (chemkin_path , surface_file = chemkin_surface_path , quiet = True )
135+ job .load_chemkin_model (chemkin_path , surface_file = chemkin_surface_path , quiet = True , permissive = True )
124136 self .ct_surface_species = job .surface .species ()
125137 self .ct_surface_reactions = job .surface .reactions ()
126138
127-
128139 def test_species_conversion (self ):
129140 """
130141 Test that species objects convert properly
131142 """
132143 from rmgpy .tools .canteramodel import check_equivalent_cantera_species
133-
134144 for i in range (len (self .ctSpecies )):
135145 assert check_equivalent_cantera_species (self .ctSpecies [i ], self .rmg_ctSpecies [i ])
136146
@@ -139,7 +149,6 @@ def test_reaction_conversion(self):
139149 Test that reaction objects convert properly
140150 """
141151 from rmgpy .tools .canteramodel import check_equivalent_cantera_reaction
142-
143152 for i in range (len (self .ctReactions )):
144153 assert check_equivalent_cantera_reaction (self .ctReactions [i ], self .rmg_ctReactions [i ])
145154
@@ -148,7 +157,6 @@ def test_surface_species_conversion(self):
148157 Test that surface species objects convert properly
149158 """
150159 from rmgpy .tools .canteramodel import check_equivalent_cantera_species
151-
152160 for i in range (len (self .ct_surface_species )):
153161 #print("Chemkin-to-Cantera:", self.ct_surfaceSpecies[i].input_data)
154162 #print("Chemkin-to-RMG-to-Cantera:", self.rmg_surface_ctSpecies[i].input_data)
@@ -159,8 +167,7 @@ def test_surface_reaction_conversion(self):
159167 Test that surface reaction objects convert properly
160168 """
161169 from rmgpy .tools .canteramodel import check_equivalent_cantera_reaction
162-
163170 for i in range (len (self .ct_surface_reactions )):
164171 #print("Chemkin-to-Cantera:", self.ct_surfaceReactions[i].input_data)
165172 #print("Chemkin-to-RMG-to-Cantera:", self.rmg_surface_ctReactions[i].input_data)
166- assert check_equivalent_cantera_reaction (self .ct_surface_reactions [i ], self .rmg_surface_ct_reactions [i ])
173+ assert check_equivalent_cantera_reaction (self .ct_surface_reactions [i ], self .rmg_surface_ct_reactions [i ])
0 commit comments