Skip to content

Commit 033ff5f

Browse files
committed
Added errorString attribute to Network class.
The errorString attribute is used by the readFile() function to store the error messages that are generated when an invalid MEASURE input file is loaded. This enables them to remain available after readFile() returns, so that they can be inspected or displayed in the future. Note that readFile() now returns the loaded data even when the network is invalid. Therefore, a proper test for a valid input file is that the return value from readFile() is not None *and* the errorString of the returned network is empty.
1 parent 5b87fd8 commit 033ff5f

3 files changed

Lines changed: 17 additions & 15 deletions

File tree

rmgpy/measure/input.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -517,32 +517,32 @@ def readFile(path):
517517
errorString0 = ''
518518
# All isomers must have states data
519519
if isomer.states is None:
520-
errorString0 += ' Required molecular degree of freedom data was not provided.\n'
520+
errorString0 += '* Required molecular degree of freedom data was not provided.\n'
521521
# All isomers must have collision parameters
522522
if isomer.lennardJones is None:
523-
errorString0 += ' Required Lennard-Jones parameters were not provided.\n'
523+
errorString0 += '* Required Lennard-Jones parameters were not provided.\n'
524524
if isomer.molecularWeight == 0:
525-
errorString0 += ' Required molecular weight was not provided.\n'
525+
errorString0 += '* Required molecular weight was not provided.\n'
526526
if errorString0 != '':
527-
errorString = 'For unimolecular isomer "{0}":\n{1}'.format(isomer, errorString0)
527+
errorString = 'For unimolecular isomer "{0}":\n{1}\n'.format(isomer, errorString0)
528528

529529
for rxn in network.pathReactions:
530530
errorString0 = ''
531531

532532
# If both the reactants and the products are product channels, then the path reaction is invalid
533533
if rxn.reactants in network.products and rxn.products in network.products:
534-
errorString0 += ' Both the reactants and the products are product channels.\n'
534+
errorString0 += '* Both the reactants and the products are product channels.\n'
535535

536536
# Reactions of the form A + B -> C + D are not allowed
537537
elif len(rxn.reactants) > 1 and len(rxn.products) > 1:
538-
errorString0 += ' Both the reactants and the products are bimolecular.\n'
538+
errorString0 += '* Both the reactants and the products are bimolecular.\n'
539539

540540
# The remaining errors are only meaningful if the path reaction is allowed
541541
else:
542542

543543
# All reactions must have either high-pressure-limit kinetics or transition state data
544544
if rxn.kinetics is None and rxn.transitionState.states is None:
545-
errorString0 += ' Unable to determine microcanonical rate k(E); you must specify either the high-P kinetics or transition state molecular degrees of freedom.\n'
545+
errorString0 += '* Unable to determine microcanonical rate k(E). you must specify either\n the high-P kinetics or transition state molecular degrees of freedom.\n'
546546

547547
# Certain reactions require that both reactants and products have thermo data
548548
thermoRequired = False
@@ -557,22 +557,22 @@ def readFile(path):
557557
if thermoRequired:
558558
for spec in rxn.reactants:
559559
if spec.thermo is None:
560-
errorString0 += ' Unable to determine thermo data for reactant "{0}"; you must specify a thermodynamics model.\n'.format(spec)
560+
errorString0 += '* Unable to determine thermodynamics data for reactant "{0}".\n You must specify molecular degrees of freedom or a thermodynamics model.\n'.format(spec)
561561
for spec in rxn.products:
562562
if spec.thermo is None:
563-
errorString0 += ' Unable to determine thermo data for product "{0}"; you must specify a thermodynamics model.\n'.format(spec)
563+
errorString0 += '* Unable to determine thermodynamics data for product "{0}".\n You must specify molecular degrees of freedom or a thermodynamics model.\n'.format(spec)
564564

565565
if errorString0 != '':
566-
errorString += 'For path reaction "{0}":\n{1}'.format(rxn, errorString0)
566+
errorString += 'For path reaction "{0}":\n{1}\n'.format(rxn, errorString0)
567567

568568
if errorString != '':
569569
raise InputError(errorString)
570570

571571
except InputError, e:
572+
network.errorString = str(e)
572573
logging.error('The input file "{0}" was invalid:'.format(path))
573574
logging.info(e)
574-
return None
575-
575+
576576
# Print lots of information about the loaded network
577577
# In particular, we want to give all of the energies on the PES
578578
# This will help the user decide if the range of energies selected is
@@ -581,8 +581,9 @@ def readFile(path):
581581

582582
# If there are no isomers, then there's nothing to do
583583
if len(network.isomers) == 0:
584-
logging.info('Could not find any unimolecular isomers based on this network, so there is nothing to do.')
585-
return None
584+
message = 'Could not find any unimolecular isomers based on this network, so there is nothing to do.'
585+
network.errorString = message
586+
logging.info(message)
586587

587588
return network, Tlist, Plist, Elist, method, model, Tmin, Tmax, Pmin, Pmax
588589

rmgpy/measure/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def execute(inputFile, outputFile=None, drawFile=None, logFile=None, quiet=False
131131
params = readFile(os.path.relpath(inputFile))
132132

133133
# Only proceed if the input network is valid
134-
if params is not None:
134+
if params is not None and params[0].errorString == '':
135135

136136
network, Tlist, Plist, Elist, method, model, Tmin, Tmax, Pmin, Pmax = params
137137

rmgpy/measure/network.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ def __init__(self, index=-1, isomers=None, reactants=None, products=None, pathRe
9191
self.valid = False
9292
self.title = title
9393
self.description = description
94+
self.errorString = ''
9495

9596
def __str__(self):
9697
if self.index != -1:

0 commit comments

Comments
 (0)