Skip to content

Commit a041fde

Browse files
authored
Merge pull request #2753 from ReactionMechanismGenerator/fix_lithium_database_issues
Fix database issues with loading new kinetic libraries
2 parents 12c094a + 5ff3143 commit a041fde

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

rmgpy/data/kinetics/database.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@
4646
PDepArrhenius, MultiArrhenius, MultiPDepArrhenius, \
4747
Chebyshev, KineticsData, StickingCoefficient, \
4848
StickingCoefficientBEP, SurfaceArrhenius, SurfaceArrheniusBEP, \
49-
ArrheniusBM, SurfaceChargeTransfer, KineticsModel, Marcus
49+
ArrheniusBM, SurfaceChargeTransfer, KineticsModel, Marcus, \
50+
ArrheniusChargeTransfer, ArrheniusChargeTransferBM
51+
from rmgpy.kinetics.uncertainties import RateUncertainty
5052
from rmgpy.molecule import Molecule, Group
5153
from rmgpy.reaction import Reaction, same_species_lists
5254
from rmgpy.species import Species
@@ -70,6 +72,7 @@ def __init__(self):
7072
'KineticsData': KineticsData,
7173
'Arrhenius': Arrhenius,
7274
'ArrheniusEP': ArrheniusEP,
75+
'ArrheniusChargeTransfer': ArrheniusChargeTransfer,
7376
'MultiArrhenius': MultiArrhenius,
7477
'MultiPDepArrhenius': MultiPDepArrhenius,
7578
'PDepArrhenius': PDepArrhenius,
@@ -84,11 +87,13 @@ def __init__(self):
8487
'SurfaceChargeTransfer': SurfaceChargeTransfer,
8588
'R': constants.R,
8689
'ArrheniusBM': ArrheniusBM,
90+
'ArrheniusChargeTransferBM': ArrheniusChargeTransferBM,
8791
'SoluteData': SoluteData,
8892
'SoluteTSData': SoluteTSData,
8993
'SoluteTSDiffData': SoluteTSDiffData,
9094
'KineticsModel': KineticsModel,
9195
'Marcus': Marcus,
96+
'RateUncertainty': RateUncertainty,
9297
}
9398
self.global_context = {}
9499

@@ -263,7 +268,16 @@ def load_libraries(self, path, libraries=None):
263268
for f in files:
264269
if f.lower() == 'reactions.py':
265270
library_file = os.path.join(root, f)
266-
label = os.path.dirname(library_file)[len(path) + 1:]
271+
dirname = os.path.dirname(library_file)
272+
if dirname == path:
273+
label = os.path.basename(dirname)
274+
else:
275+
label = os.path.relpath(dirname, path)
276+
277+
if not label:
278+
logging.warning(f"Empty label for {library_file}. Using 'default'.")
279+
label = "default"
280+
267281
logging.info(f'Loading kinetics library {label} from {library_file}...')
268282
library = KineticsLibrary(label=label)
269283
try:

rmgpy/data/kinetics/library.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -464,11 +464,16 @@ def load(self, path, local_context=None, global_context=None):
464464
local_context[key] = value
465465

466466
# Process the file
467-
f = open(path, 'r')
467+
with open(path, 'r') as f:
468+
content = f.read()
468469
try:
469-
exec(f.read(), global_context, local_context)
470-
except Exception:
471-
logging.error('Error while reading database {0!r}.'.format(path))
470+
exec(content, global_context, local_context)
471+
except Exception as e:
472+
logging.exception(f'Error while reading database file {path}.')
473+
line_number = e.__traceback__.tb_next.tb_lineno
474+
logging.error(f'Error occurred at or near line {line_number} of {path}.')
475+
lines = content.splitlines()
476+
logging.error(f'Line: {lines[line_number - 1]}')
472477
raise
473478
f.close()
474479

0 commit comments

Comments
 (0)