Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix database issues with loading new kinetic libraries #2753

Merged
merged 4 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions rmgpy/data/kinetics/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@
PDepArrhenius, MultiArrhenius, MultiPDepArrhenius, \
Chebyshev, KineticsData, StickingCoefficient, \
StickingCoefficientBEP, SurfaceArrhenius, SurfaceArrheniusBEP, \
ArrheniusBM, SurfaceChargeTransfer, KineticsModel, Marcus
ArrheniusBM, SurfaceChargeTransfer, KineticsModel, Marcus, \
ArrheniusChargeTransfer, ArrheniusChargeTransferBM
from rmgpy.kinetics.uncertainties import RateUncertainty
from rmgpy.molecule import Molecule, Group
from rmgpy.reaction import Reaction, same_species_lists
from rmgpy.species import Species
Expand All @@ -70,6 +72,7 @@ def __init__(self):
'KineticsData': KineticsData,
'Arrhenius': Arrhenius,
'ArrheniusEP': ArrheniusEP,
'ArrheniusChargeTransfer': ArrheniusChargeTransfer,
'MultiArrhenius': MultiArrhenius,
'MultiPDepArrhenius': MultiPDepArrhenius,
'PDepArrhenius': PDepArrhenius,
Expand All @@ -84,11 +87,13 @@ def __init__(self):
'SurfaceChargeTransfer': SurfaceChargeTransfer,
'R': constants.R,
'ArrheniusBM': ArrheniusBM,
'ArrheniusChargeTransferBM': ArrheniusChargeTransferBM,
'SoluteData': SoluteData,
'SoluteTSData': SoluteTSData,
'SoluteTSDiffData': SoluteTSDiffData,
'KineticsModel': KineticsModel,
'Marcus': Marcus,
'RateUncertainty': RateUncertainty,
}
self.global_context = {}

Expand Down Expand Up @@ -263,7 +268,16 @@ def load_libraries(self, path, libraries=None):
for f in files:
if f.lower() == 'reactions.py':
library_file = os.path.join(root, f)
label = os.path.dirname(library_file)[len(path) + 1:]
dirname = os.path.dirname(library_file)
if dirname == path:
label = os.path.basename(dirname)
else:
label = os.path.relpath(dirname, path)

if not label:
logging.warning(f"Empty label for {library_file}. Using 'default'.")
label = "default"

logging.info(f'Loading kinetics library {label} from {library_file}...')
library = KineticsLibrary(label=label)
try:
Expand Down
13 changes: 9 additions & 4 deletions rmgpy/data/kinetics/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,11 +464,16 @@ def load(self, path, local_context=None, global_context=None):
local_context[key] = value

# Process the file
f = open(path, 'r')
with open(path, 'r') as f:
content = f.read()
try:
exec(f.read(), global_context, local_context)
except Exception:
logging.error('Error while reading database {0!r}.'.format(path))
exec(content, global_context, local_context)
except Exception as e:
logging.exception(f'Error while reading database file {path}.')
line_number = e.__traceback__.tb_next.tb_lineno
logging.error(f'Error occurred at or near line {line_number} of {path}.')
lines = content.splitlines()
logging.error(f'Line: {lines[line_number - 1]}')
raise
f.close()

Expand Down
Loading