Skip to content

Commit 2758d34

Browse files
committed
Enhance reaction comparison by adding checks for reaction counts and conditional comparison of Arrhenius parameters
1 parent ef756ba commit 2758d34

1 file changed

Lines changed: 26 additions & 5 deletions

File tree

test/rmgpy/yaml_writer/compare_yaml_outputs.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,38 @@ def compare_reactions(self):
138138
reactions2 = self.yaml2.get_reaction_df()
139139
comparison_results = {}
140140

141+
# Check if reaction counts match
142+
count1 = sum(len(df) for df in reactions1.values())
143+
count2 = sum(len(df) for df in reactions2.values())
144+
if count1 != count2:
145+
return False
146+
141147
for key1, df1 in reactions1.items():
148+
df1 = df1.copy()
142149
df1['normalized_equation'] = df1['equation'].apply(self.normalize_equation)
143150
for key2, df2 in reactions2.items():
151+
df2 = df2.copy()
144152
df2['normalized_equation'] = df2['equation'].apply(self.normalize_equation)
145153
merged_df = pd.merge(df1, df2, on='normalized_equation', suffixes=('_1', '_2'), how='inner')
146154
if not merged_df.empty:
147-
merged_df['A_diff'] = merged_df['A_1'].round(2) - merged_df['A_2'].round(2)
148-
merged_df['b_diff'] = merged_df['b_1'].round(2) - merged_df['b_2'].round(2)
149-
merged_df['Ea_diff'] = merged_df['Ea_1'].round(2) - merged_df['Ea_2'].round(2)
150-
comparison_results[f'{key1}_{key2}'] = merged_df[['normalized_equation', 'A_diff', 'b_diff', 'Ea_diff']]
155+
# Only compare A, b, Ea if they exist in both dataframes
156+
has_arrhenius = all(
157+
col in merged_df.columns
158+
for col in ['A_1', 'A_2', 'b_1', 'b_2', 'Ea_1', 'Ea_2']
159+
)
160+
if has_arrhenius:
161+
merged_df['A_diff'] = merged_df['A_1'].round(2) - merged_df['A_2'].round(2)
162+
merged_df['b_diff'] = merged_df['b_1'].round(2) - merged_df['b_2'].round(2)
163+
merged_df['Ea_diff'] = merged_df['Ea_1'].round(2) - merged_df['Ea_2'].round(2)
164+
comparison_results[f'{key1}_{key2}'] = merged_df[['normalized_equation', 'A_diff', 'b_diff', 'Ea_diff']]
165+
166+
if not comparison_results:
167+
return False
168+
151169
for key, df in comparison_results.items():
152-
if not (df['A_diff'].eq(0).all() and df['b_diff'].eq(0).all() and df['Ea_diff'].eq(0).all()):
170+
a_match = df['A_diff'].eq(0).all()
171+
b_match = df['b_diff'].eq(0).all()
172+
ea_match = df['Ea_diff'].eq(0).all()
173+
if not (a_match and b_match and ea_match):
153174
return False
154175
return True

0 commit comments

Comments
 (0)