Skip to content

Commit

Permalink
Fixed bug occurring when a reaction model is created from a dictionar…
Browse files Browse the repository at this point in the history
…y and 'vib_energies_ts' is not defined for a non-activated adsorption step
  • Loading branch information
hprats committed Feb 9, 2025
1 parent a1782ca commit c5ba1e9
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions zacrostools/reaction_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,20 @@ def _validate_dataframe(self, df: Optional[pd.DataFrame] = None):
if missing_columns:
raise ReactionModelError(f"Missing required columns: {missing_columns}")

# Pre-process the 'vib_energies_ts' column:
# For non-activated adsorption steps (i.e. those with a defined gas-phase 'molecule'
# and an activation energy of 0.0), if the cell is missing (i.e. not a list and is NaN),
# replace it with an empty list.
if 'vib_energies_ts' in df.columns:
for idx, row in df.iterrows():
val = row['vib_energies_ts']
# Only check for NaN if 'val' is not already a list.
if not isinstance(val, list) and pd.isna(val):
# Check if this is an adsorption step (has a molecule) with zero activation energy.
if ('molecule' in row and pd.notna(row['molecule'])
and row['activ_eng'] == 0.0):
df.at[idx, 'vib_energies_ts'] = []

# Validate data types for list columns
for col in self.LIST_COLUMNS:
if col in df.columns:
Expand Down

0 comments on commit c5ba1e9

Please sign in to comment.