From 6903cf2880291f3ef49cd99e3f07c367e67fd162 Mon Sep 17 00:00:00 2001 From: Connie Gao Date: Wed, 2 Apr 2014 21:48:10 -0400 Subject: [PATCH 1/9] Changing behavior of kineticsFamilies field loading of families. Now the following options for kineticsFamilies in the input file are allowed: - When kineticsFamilies field is set to 'default', the RMG recommended families are loaded from the database. This is also selected when the kineticsFamilies field is completely missing - 'all' indicates all families are turned on. - 'none' means none of the families are turned on. This is good for debugging. - A list of families means only those are selected, e.g. ['H_Abstraction','R_Recombination']. You can also deselect all but certain families by using the ! flag, e.g. ['!Intra_Disproportionation','Substitution_O'] Added additional error raising in rmgpy.data.kinetics in case any of the if/elif statements fall through when code changes occur. --- rmgpy/data/kinetics/__init__.py | 47 +++++++++++++++++++++++++++++---- rmgpy/rmg/input.py | 8 +++++- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/rmgpy/data/kinetics/__init__.py b/rmgpy/data/kinetics/__init__.py index 8935ff041f..4bc240614f 100644 --- a/rmgpy/data/kinetics/__init__.py +++ b/rmgpy/data/kinetics/__init__.py @@ -41,7 +41,7 @@ from rmgpy.molecule import Molecule, Group from rmgpy.species import Species from rmgpy.reaction import Reaction -from rmgpy.data.base import LogicNode +from rmgpy.data.base import LogicNode, DatabaseError from .common import KineticsError, saveEntry from .depository import DepositoryReaction, KineticsDepository @@ -109,18 +109,53 @@ def loadFamilies(self, path, families=None, depositories=None): Load the kinetics families from the given `path` on disk, where `path` points to the top-level folder of the kinetics families. """ - logging.info('Loading kinetics families from {0}'.format(path)) + + def recommendedFamilies(families): + self.families = {} + for label, value in families.iteritems(): + if value is True: + self.families[label] = KineticsFamily(label=label) familiesToLoad = [] for (root, dirs, files) in os.walk(os.path.join(path)): if root == path: - if families is None or families == 'all': + if families == 'default': + logging.info('Loading default kinetics families from {0}'.format(path)) + try: + global_context ={} + global_context['__builtins__'] = None + global_context['True'] = True + global_context['False'] = False + local_context = {} + local_context['__builtins__'] = None + local_context['recommendedFamilies'] = recommendedFamilies + f = open(os.path.join(path, 'recommended.py'), 'r') + exec f in global_context, local_context + f.close() + except: + raise DatabaseError('Error while reading list of recommended families from {0}/families/recommended.py.'.format(path)) + + for label, family in self.families.iteritems(): + familyPath = os.path.join(path, label) + family.load(familyPath, self.local_context, self.global_context, depositoryLabels=depositories) + return + + elif families == 'all': # All families are loaded by default + logging.info('Loading all of the kinetics families from {0}'.format(path)) for d in dirs: familiesToLoad.append(d) - elif isinstance(families, list) or isinstance(families, tuple): + elif families == 'none': + logging.info('Not loading any of the kinetics families from {0}'.format(path)) + # Don't load any of the families + pass + elif isinstance(families, list): + logging.info('Loading the user-specified kinetics families from {0}'.format(path)) # If all items in the list start with !, all families will be loaded except these - if all([label.startswith('!') for label in families]): + if len(families) == 0: + # if the list or tuple has nothing in it, assume that we should load all the families by default + raise DatabaseError('Kinetics families should be a non-empty list, or set to `default`, `all`, or `none`.') + elif all([label.startswith('!') for label in families]): for d in dirs: if '!{0}'.format(d) not in families: familiesToLoad.append(d) @@ -129,6 +164,8 @@ def loadFamilies(self, path, families=None, depositories=None): for d in dirs: if d in families: familiesToLoad.append(d) + else: + raise DatabaseError('Kinetics families was not specified properly. Should be set to `default`,`all`,`none`, or a list.') # Now we know what families to load, so let's load them self.families = {} diff --git a/rmgpy/rmg/input.py b/rmgpy/rmg/input.py index 4f00636602..79a65922ba 100644 --- a/rmgpy/rmg/input.py +++ b/rmgpy/rmg/input.py @@ -83,11 +83,17 @@ def database( assert isinstance(kineticsDepositories,list), "kineticsDepositories should be either 'default', 'all', or a list of names eg. ['training','PrIMe']." rmg.kineticsDepositories = kineticsDepositories if kineticsFamilies == 'default': + # This is loaded if the user specifies 'default', or if no kineticsFamilies field is used + rmg.kineticsFamilies = kineticsFamilies pass elif kineticsFamilies == 'all': + rmg.kineticsFamilies = kineticsFamilies + pass + elif kineticsFamilies == 'none': + rmg.kineticsFamilies = kineticsFamilies pass else: - assert isinstance(kineticsFamilies,list), "kineticsFamilies should be either 'default', 'all', or a list of names eg. ['H_Abstraction','!Intra_Disproportionation']." + assert isinstance(kineticsFamilies,list), "kineticsFamilies should be either 'default', 'all', 'none', or a list of names eg. ['H_Abstraction','R_Recombination'] or ['!Intra_Disproportionation']." rmg.kineticsFamilies = kineticsFamilies def species(label, structure, reactive=True): From fd4ddd1a4978191fdb0d19960960c703569c6348 Mon Sep 17 00:00:00 2001 From: Connie Gao Date: Wed, 2 Apr 2014 21:48:18 -0400 Subject: [PATCH 2/9] Set minimal example to 'default' kineticsFamilies. --- examples/rmg/minimal/input.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/rmg/minimal/input.py b/examples/rmg/minimal/input.py index 5a2effffbc..93dd6d1c26 100644 --- a/examples/rmg/minimal/input.py +++ b/examples/rmg/minimal/input.py @@ -4,7 +4,7 @@ reactionLibraries = [], seedMechanisms = [], kineticsDepositories = ['training'], - kineticsFamilies = ['!Intra_Disproportionation','!Substitution_O'], + kineticsFamilies = 'default', kineticsEstimator = 'rate rules', ) From b89eac9eb42e17ecbbc21c7b8f39a81567d83d45 Mon Sep 17 00:00:00 2001 From: Richard West Date: Wed, 2 Apr 2014 22:30:48 -0400 Subject: [PATCH 3/9] Simplify the parsing of kineticsFamilies = 'string' options from input file. Less code, hopefully easier to understand. --- rmgpy/rmg/input.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/rmgpy/rmg/input.py b/rmgpy/rmg/input.py index 79a65922ba..f3ccd43d21 100644 --- a/rmgpy/rmg/input.py +++ b/rmgpy/rmg/input.py @@ -82,16 +82,8 @@ def database( else: assert isinstance(kineticsDepositories,list), "kineticsDepositories should be either 'default', 'all', or a list of names eg. ['training','PrIMe']." rmg.kineticsDepositories = kineticsDepositories - if kineticsFamilies == 'default': - # This is loaded if the user specifies 'default', or if no kineticsFamilies field is used + if kineticsFamilies in ('default', 'all', 'none'): rmg.kineticsFamilies = kineticsFamilies - pass - elif kineticsFamilies == 'all': - rmg.kineticsFamilies = kineticsFamilies - pass - elif kineticsFamilies == 'none': - rmg.kineticsFamilies = kineticsFamilies - pass else: assert isinstance(kineticsFamilies,list), "kineticsFamilies should be either 'default', 'all', 'none', or a list of names eg. ['H_Abstraction','R_Recombination'] or ['!Intra_Disproportionation']." rmg.kineticsFamilies = kineticsFamilies From 720cdf8fcdce5633f87730d1ac0df0aa1b76e458 Mon Sep 17 00:00:00 2001 From: Richard West Date: Wed, 2 Apr 2014 22:52:13 -0400 Subject: [PATCH 4/9] Recommended reaction families read as a dictionary, not a function. With this commit, the recommended.py file in RMG-database/input/kinetics/families/recommended.py should just contain a dictionary, not a function call recommendedFamilies = { '1,2-Birad_to_alkene': True, '1,2_Insertion': False, } I'll make a corresponding commit in the RMG-database project. Other changes: Reduced code duplication, tidied up comments, and added more sanity checks on input, eg. we check that the list is all true or all false, not a mix, and we check that all the requested families can be found in the database (before we just silently skipped them) and check that all families in the database are listed in the recommended.py file as either True or False (in case we forget to add them). --- rmgpy/data/kinetics/__init__.py | 46 +++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/rmgpy/data/kinetics/__init__.py b/rmgpy/data/kinetics/__init__.py index 4bc240614f..1c4221627f 100644 --- a/rmgpy/data/kinetics/__init__.py +++ b/rmgpy/data/kinetics/__init__.py @@ -110,12 +110,6 @@ def loadFamilies(self, path, families=None, depositories=None): points to the top-level folder of the kinetics families. """ - def recommendedFamilies(families): - self.families = {} - for label, value in families.iteritems(): - if value is True: - self.families[label] = KineticsFamily(label=label) - familiesToLoad = [] for (root, dirs, files) in os.walk(os.path.join(path)): if root == path: @@ -128,42 +122,56 @@ def recommendedFamilies(families): global_context['False'] = False local_context = {} local_context['__builtins__'] = None - local_context['recommendedFamilies'] = recommendedFamilies f = open(os.path.join(path, 'recommended.py'), 'r') exec f in global_context, local_context f.close() + recommendedFamilies = local_context['recommendedFamilies'] + for recommended in recommendedFamilies.values(): + if not isinstance(recommended, bool): + raise DatabaseError("recommendedFamilies dictionary should contain only True or False values") except: - raise DatabaseError('Error while reading list of recommended families from {0}/families/recommended.py.'.format(path)) - - for label, family in self.families.iteritems(): - familyPath = os.path.join(path, label) - family.load(familyPath, self.local_context, self.global_context, depositoryLabels=depositories) - return - + raise DatabaseError('Error while reading list of recommended families from {0}/recommended.py.'.format(path)) + + for d in dirs: # load them in directory listing order, like other methods (better than a random dict order) + try: + recommended = recommendedFamilies[d] + except KeyError: + raise DatabaseError('Family {0} not found in recommendation list at {1}/recommended.py'.format(d, path)) + if recommended: + familiesToLoad.append(d) + for label, value in recommendedFamilies.iteritems(): + if value is True: + if label not in dirs: + raise DatabaseError('Family {0} recommended in {1}/recommended.py not found on disk.'.format(label, path)) + elif families == 'all': - # All families are loaded by default + # All families are loaded logging.info('Loading all of the kinetics families from {0}'.format(path)) for d in dirs: familiesToLoad.append(d) elif families == 'none': logging.info('Not loading any of the kinetics families from {0}'.format(path)) # Don't load any of the families - pass + familiesToLoad = [] elif isinstance(families, list): logging.info('Loading the user-specified kinetics families from {0}'.format(path)) # If all items in the list start with !, all families will be loaded except these if len(families) == 0: - # if the list or tuple has nothing in it, assume that we should load all the families by default raise DatabaseError('Kinetics families should be a non-empty list, or set to `default`, `all`, or `none`.') elif all([label.startswith('!') for label in families]): for d in dirs: if '!{0}'.format(d) not in families: familiesToLoad.append(d) - # Otherwise only the families given will be loaded - else: + elif any([label.startswith('!') for label in families]): + raise DatabaseError('Families list must either all or none have prefix "!", but not a mix.') + else: # only the families given will be loaded for d in dirs: if d in families: familiesToLoad.append(d) + for label in families: + if label not in dirs: + raise DatabaseError('Family {0} recommended in {1}/recommended.py not found on disk.'.format(label, path)) + else: raise DatabaseError('Kinetics families was not specified properly. Should be set to `default`,`all`,`none`, or a list.') From 5b57ab0063c123eef896d36bb2eb2bb58c2121bc Mon Sep 17 00:00:00 2001 From: Richard West Date: Wed, 2 Apr 2014 22:57:12 -0400 Subject: [PATCH 5/9] Change the flow control when loading families list. This is a small change, but it changes the indentation of a huge block of code so looks like a big one. --- rmgpy/data/kinetics/__init__.py | 121 ++++++++++++++++---------------- 1 file changed, 61 insertions(+), 60 deletions(-) diff --git a/rmgpy/data/kinetics/__init__.py b/rmgpy/data/kinetics/__init__.py index 1c4221627f..d7aaadbaa5 100644 --- a/rmgpy/data/kinetics/__init__.py +++ b/rmgpy/data/kinetics/__init__.py @@ -113,67 +113,68 @@ def loadFamilies(self, path, families=None, depositories=None): familiesToLoad = [] for (root, dirs, files) in os.walk(os.path.join(path)): if root == path: - if families == 'default': - logging.info('Loading default kinetics families from {0}'.format(path)) - try: - global_context ={} - global_context['__builtins__'] = None - global_context['True'] = True - global_context['False'] = False - local_context = {} - local_context['__builtins__'] = None - f = open(os.path.join(path, 'recommended.py'), 'r') - exec f in global_context, local_context - f.close() - recommendedFamilies = local_context['recommendedFamilies'] - for recommended in recommendedFamilies.values(): - if not isinstance(recommended, bool): - raise DatabaseError("recommendedFamilies dictionary should contain only True or False values") - except: - raise DatabaseError('Error while reading list of recommended families from {0}/recommended.py.'.format(path)) - - for d in dirs: # load them in directory listing order, like other methods (better than a random dict order) - try: - recommended = recommendedFamilies[d] - except KeyError: - raise DatabaseError('Family {0} not found in recommendation list at {1}/recommended.py'.format(d, path)) - if recommended: - familiesToLoad.append(d) - for label, value in recommendedFamilies.iteritems(): - if value is True: - if label not in dirs: - raise DatabaseError('Family {0} recommended in {1}/recommended.py not found on disk.'.format(label, path)) - - elif families == 'all': - # All families are loaded - logging.info('Loading all of the kinetics families from {0}'.format(path)) - for d in dirs: - familiesToLoad.append(d) - elif families == 'none': - logging.info('Not loading any of the kinetics families from {0}'.format(path)) - # Don't load any of the families - familiesToLoad = [] - elif isinstance(families, list): - logging.info('Loading the user-specified kinetics families from {0}'.format(path)) - # If all items in the list start with !, all families will be loaded except these - if len(families) == 0: - raise DatabaseError('Kinetics families should be a non-empty list, or set to `default`, `all`, or `none`.') - elif all([label.startswith('!') for label in families]): - for d in dirs: - if '!{0}'.format(d) not in families: - familiesToLoad.append(d) - elif any([label.startswith('!') for label in families]): - raise DatabaseError('Families list must either all or none have prefix "!", but not a mix.') - else: # only the families given will be loaded - for d in dirs: - if d in families: - familiesToLoad.append(d) - for label in families: - if label not in dirs: - raise DatabaseError('Family {0} recommended in {1}/recommended.py not found on disk.'.format(label, path)) + break # all we wanted was the list of dirs in the base path - else: - raise DatabaseError('Kinetics families was not specified properly. Should be set to `default`,`all`,`none`, or a list.') + if families == 'default': + logging.info('Loading default kinetics families from {0}'.format(path)) + try: + global_context = {} + global_context['__builtins__'] = None + global_context['True'] = True + global_context['False'] = False + local_context = {} + local_context['__builtins__'] = None + f = open(os.path.join(path, 'recommended.py'), 'r') + exec f in global_context, local_context + f.close() + recommendedFamilies = local_context['recommendedFamilies'] + for recommended in recommendedFamilies.values(): + if not isinstance(recommended, bool): + raise DatabaseError("recommendedFamilies dictionary should contain only True or False values") + except: + raise DatabaseError('Error while reading list of recommended families from {0}/recommended.py.'.format(path)) + + for d in dirs: # load them in directory listing order, like other methods (better than a random dict order) + try: + recommended = recommendedFamilies[d] + except KeyError: + raise DatabaseError('Family {0} not found in recommendation list at {1}/recommended.py'.format(d, path)) + if recommended: + familiesToLoad.append(d) + for label, value in recommendedFamilies.iteritems(): + if value is True: + if label not in dirs: + raise DatabaseError('Family {0} recommended in {1}/recommended.py not found on disk.'.format(label, path)) + + elif families == 'all': + # All families are loaded + logging.info('Loading all of the kinetics families from {0}'.format(path)) + for d in dirs: + familiesToLoad.append(d) + elif families == 'none': + logging.info('Not loading any of the kinetics families from {0}'.format(path)) + # Don't load any of the families + familiesToLoad = [] + elif isinstance(families, list): + logging.info('Loading the user-specified kinetics families from {0}'.format(path)) + # If all items in the list start with !, all families will be loaded except these + if len(families) == 0: + raise DatabaseError('Kinetics families should be a non-empty list, or set to `default`, `all`, or `none`.') + elif all([label.startswith('!') for label in families]): + for d in dirs: + if '!{0}'.format(d) not in families: + familiesToLoad.append(d) + elif any([label.startswith('!') for label in families]): + raise DatabaseError('Families list must either all or none have prefix "!", but not a mix.') + else: # only the families given will be loaded + for d in dirs: + if d in families: + familiesToLoad.append(d) + for label in families: + if label not in dirs: + raise DatabaseError('Family {0} recommended in {1}/recommended.py not found on disk.'.format(label, path)) + else: + raise DatabaseError('Kinetics families was not specified properly. Should be set to `default`,`all`,`none`, or a list.') # Now we know what families to load, so let's load them self.families = {} From 111a74248f6bdd53bacb76e2db8bc6eeadec36c0 Mon Sep 17 00:00:00 2001 From: Richard West Date: Wed, 2 Apr 2014 23:13:02 -0400 Subject: [PATCH 6/9] recommendedFamilies list (dict) stored in kinetics database attribute The loading of the recommendation list has been moved to its own method because it was getting complicated, and we want to be able to store this more permanently, even if we aren't going to use it. This will allow us to interrogate it, and, for example, to export the Java-style database with it. (is this still going to be neccessarry?) --- rmgpy/data/kinetics/__init__.py | 54 +++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/rmgpy/data/kinetics/__init__.py b/rmgpy/data/kinetics/__init__.py index d7aaadbaa5..c9547fce7d 100644 --- a/rmgpy/data/kinetics/__init__.py +++ b/rmgpy/data/kinetics/__init__.py @@ -59,6 +59,7 @@ class KineticsDatabase(object): """ def __init__(self): + self.recommendedFamilies = {} self.families = {} self.libraries = {} self.libraryOrder = [] @@ -101,9 +102,35 @@ def load(self, path, families=None, libraries=None, depositories=None): Load the kinetics database from the given `path` on disk, where `path` points to the top-level folder of the families database. """ + self.loadRecommendedFamiliesList(os.path.join(path, 'families', 'recommended.py')), self.loadFamilies(os.path.join(path, 'families'), families, depositories) self.loadLibraries(os.path.join(path, 'libraries'), libraries) + + def loadRecommendedFamiliesList(self, filepath): + """ + Load the list of recommended families from the given file + The file is usually 'kinetics/families/recommended.py'. + This is stored as a dictionary of True or False values (checked here), + and should contain entries for every available family (checked in loadFamilies). + """ + try: + global_context = {} + global_context['__builtins__'] = None + global_context['True'] = True + global_context['False'] = False + local_context = {} + local_context['__builtins__'] = None + f = open(filepath, 'r') + exec f in global_context, local_context + f.close() + self.recommendedFamilies = local_context['recommendedFamilies'] + except: + raise DatabaseError('Error while reading list of recommended families from {0}/recommended.py.'.format(path)) + for recommended in self.recommendedFamilies.values(): + if not isinstance(recommended, bool): + raise DatabaseError("recommendedFamilies dictionary should contain only True or False values") + def loadFamilies(self, path, families=None, depositories=None): """ Load the kinetics families from the given `path` on disk, where `path` @@ -117,34 +144,17 @@ def loadFamilies(self, path, families=None, depositories=None): if families == 'default': logging.info('Loading default kinetics families from {0}'.format(path)) - try: - global_context = {} - global_context['__builtins__'] = None - global_context['True'] = True - global_context['False'] = False - local_context = {} - local_context['__builtins__'] = None - f = open(os.path.join(path, 'recommended.py'), 'r') - exec f in global_context, local_context - f.close() - recommendedFamilies = local_context['recommendedFamilies'] - for recommended in recommendedFamilies.values(): - if not isinstance(recommended, bool): - raise DatabaseError("recommendedFamilies dictionary should contain only True or False values") - except: - raise DatabaseError('Error while reading list of recommended families from {0}/recommended.py.'.format(path)) - for d in dirs: # load them in directory listing order, like other methods (better than a random dict order) try: - recommended = recommendedFamilies[d] + recommended = self.recommendedFamilies[d] except KeyError: - raise DatabaseError('Family {0} not found in recommendation list at {1}/recommended.py'.format(d, path)) + raise DatabaseError('Family {0} not found in recommendation list (probably at {1}/recommended.py)'.format(d, path)) if recommended: familiesToLoad.append(d) - for label, value in recommendedFamilies.iteritems(): + for label, value in self.recommendedFamilies.iteritems(): if value is True: if label not in dirs: - raise DatabaseError('Family {0} recommended in {1}/recommended.py not found on disk.'.format(label, path)) + raise DatabaseError('Family {0} recommended (in {1}/recommended.py?) not found on disk.'.format(label, path)) elif families == 'all': # All families are loaded @@ -172,7 +182,7 @@ def loadFamilies(self, path, families=None, depositories=None): familiesToLoad.append(d) for label in families: if label not in dirs: - raise DatabaseError('Family {0} recommended in {1}/recommended.py not found on disk.'.format(label, path)) + raise DatabaseError('Family {0} not found on disk.'.format(label)) else: raise DatabaseError('Kinetics families was not specified properly. Should be set to `default`,`all`,`none`, or a list.') From 649c98993576cdb05e685264d3633007067f59d1 Mon Sep 17 00:00:00 2001 From: Richard West Date: Wed, 2 Apr 2014 23:16:15 -0400 Subject: [PATCH 7/9] Export the recommended families list to RMG-Java style database. Now that we have this data to hand, we may as well preserve it and pass it along. --- rmgpy/data/kinetics/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/rmgpy/data/kinetics/__init__.py b/rmgpy/data/kinetics/__init__.py index c9547fce7d..659ae6520b 100644 --- a/rmgpy/data/kinetics/__init__.py +++ b/rmgpy/data/kinetics/__init__.py @@ -321,14 +321,15 @@ def saveOld(self, path): // Families can be deactivated by simply changing the "on/off" column to off. // // This file was generated by exporting the entirety of RMG-Py, -// so has all families on by default. You may want to turn some off. +// so the on/off decisions come from the defaults there. // //////////////////////////////////////////////////////////////////////////////// // No. on/off Forward reaction """) for number, label in enumerate(sorted(self.families.keys())): - f.write("{num:<2d} on {label}\n".format(num=number, label=label)) + onoff = 'on ' if self.recommendedFamilies[label] else 'off' + f.write("{num:<2d} {onoff} {label}\n".format(num=number, label=label, onoff=onoff)) def generateReactions(self, reactants, products=None, **options): """ From f220a816279b19357f25cd504dc75dd4087ed9c2 Mon Sep 17 00:00:00 2001 From: Connie Gao Date: Thu, 3 Apr 2014 17:10:49 -0400 Subject: [PATCH 8/9] Make sure all the families listed in recommended.py are found in database. Not just the ones listed as 'True.' --- rmgpy/data/kinetics/__init__.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/rmgpy/data/kinetics/__init__.py b/rmgpy/data/kinetics/__init__.py index 659ae6520b..77100efabd 100644 --- a/rmgpy/data/kinetics/__init__.py +++ b/rmgpy/data/kinetics/__init__.py @@ -152,9 +152,8 @@ def loadFamilies(self, path, families=None, depositories=None): if recommended: familiesToLoad.append(d) for label, value in self.recommendedFamilies.iteritems(): - if value is True: - if label not in dirs: - raise DatabaseError('Family {0} recommended (in {1}/recommended.py?) not found on disk.'.format(label, path)) + if label not in dirs: + raise DatabaseError('Family {0} found (in {1}/recommended.py) not found on disk.'.format(label, path)) elif families == 'all': # All families are loaded From aa881bec984258fcf1c7a6fa7ac9844e1857553b Mon Sep 17 00:00:00 2001 From: Connie Gao Date: Thu, 3 Apr 2014 17:11:23 -0400 Subject: [PATCH 9/9] Unit test to make sure we get the right exception errors in loadFamilies. An exercise that showed me how bad I am at making unit tests quickly. --- rmgpy/data/kinetics/kineticsTest.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 rmgpy/data/kinetics/kineticsTest.py diff --git a/rmgpy/data/kinetics/kineticsTest.py b/rmgpy/data/kinetics/kineticsTest.py new file mode 100644 index 0000000000..1d7d70beb4 --- /dev/null +++ b/rmgpy/data/kinetics/kineticsTest.py @@ -0,0 +1,26 @@ +import os +import unittest +from external.wip import work_in_progress + +from rmgpy import settings +from rmgpy.data.kinetics import * +from rmgpy.data.base import DatabaseError +################################################### + +class TestKineticsDatabase(unittest.TestCase): + + def testLoadFamilies(self): + """ + Test that the loadFamilies function raises the correct exceptions + """ + path = os.path.join(settings['database.directory'],'kinetics','families') + database = KineticsDatabase() + + with self.assertRaises(DatabaseError): + database.loadFamilies(path, families='random') + with self.assertRaises(DatabaseError): + database.loadFamilies(path, families=['!H_Abstraction','Disproportionation']) + with self.assertRaises(DatabaseError): + database.loadFamilies(path, families=['fake_family']) + with self.assertRaises(DatabaseError): + database.loadFamilies(path, families=[]) \ No newline at end of file