def loadKinetics(self, path, reactionLibraries=None, seedMechanisms=None, kineticsFamilies=None, kineticsDepositories=None): """ Load the RMG kinetics database from the given `path` on disk, where `path` points to the top-level folder of the RMG kinetics database. """ kineticsLibraries = [] libraryOrder = [] if seedMechanisms is None and reactionLibraries is None: kineticsLibraries = None if seedMechanisms is not None: for library in seedMechanisms: kineticsLibraries.append(library) libraryOrder.append((library, 'Seed')) if reactionLibraries is not None: for library in reactionLibraries: kineticsLibraries.append(library) libraryOrder.append((library, 'Reaction Library')) self.kinetics = KineticsDatabase() self.kinetics.libraryOrder = libraryOrder self.kinetics.load(path, families=kineticsFamilies, libraries=kineticsLibraries, depositories=kineticsDepositories) broadcast(self.kinetics, 'kinetics')
def setUp(self): """ A function run before each unit test in this class. """ # Set up a dummy database dir_path = os.path.dirname(os.path.realpath(__file__)) self.database = KineticsDatabase() self.database.loadFamilies(os.path.join(dir_path, "family_test_data"), families=['intra_H_migration']) self.family = self.database.families['intra_H_migration']
def setUp(self): """ A function run before each unit test in this class. """ # Set up a dummy database self.database = KineticsDatabase() self.database.loadFamilies(os.path.join( settings['test_data.directory'], 'testing_database/kinetics/families'), families=['intra_H_migration']) self.family = self.database.families['intra_H_migration']
def test_load_families_incorrect(self): """Test invalid methods for loading kinetics families""" path = os.path.join(settings['test_data.directory'], 'testing_database', 'kinetics', 'families') database = KineticsDatabase() database.loadRecommendedFamiliesList(os.path.join(path, 'recommended.py')) 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'])
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=[])
def setUpClass(cls): """A function run ONCE before all unit tests in this class.""" # Set up a dummy database cls.database = RMGDatabase() cls.database.load( path=os.path.join(settings['test_data.directory'], 'testing_database'), thermo_libraries=[], reaction_libraries=[], kinetics_families=[], depository=False, solvation=False, testing=True, ) cls.database.load_forbidden_structures() cls.thermoDatabase = ThermoDatabase() # the real full Thermo Database cls.thermoDatabase.load(path=os.path.join(settings['database.directory'], 'thermo'), libraries=['primaryThermoLibrary']) cls.kineticsDatabase = KineticsDatabase() cls.kineticsDatabase.load_families( path=os.path.join(settings['test_data.directory'], 'testing_database/kinetics/families'), families=[ 'Singlet_Carbene_Intra_Disproportionation', ], ) cls.family = cls.kineticsDatabase.families['Singlet_Carbene_Intra_Disproportionation'] cls.treerxns = cls.family.get_training_set(thermo_database=cls.thermoDatabase, remove_degeneracy=True, estimate_thermo=True, fix_labels=True, get_reverse=True)
def loadKinetics(self, path, reactionLibraries=None, seedMechanisms=None, kineticsFamilies=None, kineticsDepositories=None ): """ Load the RMG kinetics database from the given `path` on disk, where `path` points to the top-level folder of the RMG kinetics database. """ kineticsLibraries = [] libraryOrder = [] if seedMechanisms is None and reactionLibraries is None: kineticsLibraries = None if seedMechanisms is not None: for library in seedMechanisms: kineticsLibraries.append(library) libraryOrder.append((library,'Seed')) if reactionLibraries is not None: for library in reactionLibraries: kineticsLibraries.append(library) libraryOrder.append((library,'Reaction Library')) self.kinetics = KineticsDatabase() self.kinetics.libraryOrder = libraryOrder self.kinetics.load(path, families=kineticsFamilies, libraries=kineticsLibraries, depositories=kineticsDepositories ) broadcast(self.kinetics, 'kinetics')
def loadOld(self, path): """ Load the old RMG database from the given `path` on disk, where `path` points to the top-level folder of the old RMG database. """ self.thermo = ThermoDatabase() self.thermo.loadOld(path) self.transport = TransportDatabase() #self.transport.loadOld(path) # Currently no loadOld import function available for transport groups self.forbiddenStructures = ForbiddenStructures() self.forbiddenStructures.loadOld(os.path.join(path, 'ForbiddenStructures.txt')) self.kinetics = KineticsDatabase() self.kinetics.loadOld(path) self.statmech = StatmechDatabase() self.statmech.loadOld(path) self.solvation = SolvationDatabase()
def setUpClass(cls): """A function run ONCE before all unit tests in this class.""" # Set up a dummy database cls.database = RMGDatabase() cls.database.load( path=os.path.join(settings['test_data.directory'], 'testing_database'), thermoLibraries=[], reactionLibraries=[], kineticsFamilies=[], depository=False, solvation=False, testing=True, ) cls.database.loadForbiddenStructures() cls.thermoDatabase = ThermoDatabase() #the real full Thermo Database cls.thermoDatabase.load(path=os.path.join( settings['database.directory'], 'thermo'), libraries=['primaryThermoLibrary']) cls.kineticsDatabase = KineticsDatabase() cls.kineticsDatabase.loadFamilies( path=os.path.join(settings['test_data.directory'], 'testing_database/kinetics/families'), families=[ 'Singlet_Carbene_Intra_Disproportionation', ], ) cls.family = cls.kineticsDatabase.families[ 'Singlet_Carbene_Intra_Disproportionation']
def setUp(self): """ A function run before each unit test in this class. """ # Set up a dummy database dir_path = os.path.dirname(os.path.realpath(__file__)) self.database = KineticsDatabase() self.database.loadFamilies(os.path.join(dir_path,"family_test_data"), families=['intra_H_migration']) self.family = self.database.families['intra_H_migration']
def setUp(self): """ A function run before each unit test in this class. """ # Set up a dummy database self.database = KineticsDatabase() self.database.loadFamilies(os.path.join(settings['test_data.directory'], 'testing_database/kinetics/families'), families=['intra_H_migration']) self.family = self.database.families['intra_H_migration']
def setUpClass(cls): """ A function run ONCE before all unit tests in this class. """ # Set up a dummy database cls.database = KineticsDatabase() cls.database.loadLibraries(os.path.join(settings['test_data.directory'], 'testing_database','kinetics','libraries'), libraries=None) #this loads all of them: ['GRI-Mech3.0', 'ethane-oxidation']) cls.libraries = cls.database.libraries
def setUpClass(cls): """ A function run ONCE before all unit tests in this class. """ # Set up a dummy database cls.database = KineticsDatabase() cls.database.loadFamilies( os.path.join(settings['test_data.directory'], 'testing_database/kinetics/families'), families=['intra_H_migration', 'R_Addition_MultipleBond']) cls.family = cls.database.families['intra_H_migration']
def read_kinetic_lib_from_path(lib_path, kinetic_db, overwrite=False, create=False): """ Read RMG kinetic library given its file path. The species dictionary should be included under the same directory. Args: lib_path (str): Path to thermo library file kinetic_db (RMG KineticsDatabase): RMG database object """ if not os.path.exists(lib_path) and create: create_kinetic_lib(os.path.dirname(lib_path)) lib = KineticsLibrary() kinetic_db.libraries[lib_path] = lib kinetic_db.library_order.append(lib_path) logging.info( 'Created kinetics library {1} at {0} ...'.format( os.path.split(lib_path)[0], os.path.split(lib_path)[1]), ) elif lib_path not in kinetic_db.library_order or overwrite: lib = KineticsLibrary() try: lib.load(lib_path, KineticsDatabase().local_context, KineticsDatabase().global_context) except: logging.error('The library file %s is not vaild.' % (lib_path)) else: lib.label = lib_path kinetic_db.libraries[lib.label] = lib kinetic_db.library_order.append(lib.label) logging.info( 'Loading kinetics library {1} from {0} ...'.format( os.path.split(lib_path)[0], os.path.split(lib_path)[1]), ) else: logging.warning('The library %s has already been loaded' % (lib_path))
class TestFamily(unittest.TestCase): def setUp(self): """ A function run before each unit test in this class. """ # Set up a dummy database self.database = KineticsDatabase() self.database.loadFamilies(os.path.join( settings['test_data.directory'], 'testing_database/kinetics/families'), families=['intra_H_migration']) self.family = self.database.families['intra_H_migration'] def testGetBackboneRoots(self): """ Test the getBackboneRoots() function """ backbones = self.family.getBackboneRoots() self.assertEquals(backbones[0].label, "RnH") def testGetEndRoots(self): """ Test the getEndRoots() function """ ends = self.family.getEndRoots() self.assertEquals(len(ends), 2) self.assertIn(self.family.groups.entries["Y_rad_out"], ends) self.assertIn(self.family.groups.entries["XH_out"], ends) def testGetTopLevelGroups(self): """ Test the getTopLevelGroups() function """ topGroups = self.family.getTopLevelGroups( self.family.groups.entries["RnH"]) self.assertEquals(len(topGroups), 2) self.assertIn(self.family.groups.entries["R5Hall"], topGroups) self.assertIn(self.family.groups.entries["R6Hall"], topGroups)
class TestFamily(unittest.TestCase): def setUp(self): """ A function run before each unit test in this class. """ # Set up a dummy database dir_path = os.path.dirname(os.path.realpath(__file__)) self.database = KineticsDatabase() self.database.loadFamilies(os.path.join(dir_path,"family_test_data"), families=['intra_H_migration']) self.family = self.database.families['intra_H_migration'] def testGetBackboneRoots(self): """ Test the getBackboneRoots() function """ backbones = self.family.getBackboneRoots() self.assertEquals(backbones[0].label, "RnH") def testGetEndRoots(self): """ Test the getEndRoots() function """ ends = self.family.getEndRoots() self.assertEquals(len(ends), 2) self.assertIn(self.family.groups.entries["Y_rad_out"], ends) self.assertIn(self.family.groups.entries["XH_out"], ends) def testGetTopLevelGroups(self): """ Test the getTopLevelGroups() function """ topGroups = self.family.getTopLevelGroups(self.family.groups.entries["RnH"]) self.assertEquals(len(topGroups), 2) self.assertIn(self.family.groups.entries["R5Hall"], topGroups) self.assertIn(self.family.groups.entries["R6Hall"], topGroups)
def loadOld(self, path): """ Load the old RMG database from the given `path` on disk, where `path` points to the top-level folder of the old RMG database. """ self.thermo = ThermoDatabase() self.thermo.loadOld(path) self.transport = TransportDatabase() #self.transport.loadOld(path) # Currently no loadOld import function available for transport groups self.forbiddenStructures = ForbiddenStructures() self.forbiddenStructures.loadOld(os.path.join(path, 'ForbiddenStructures.txt')) self.kinetics = KineticsDatabase() self.kinetics.loadOld(path) self.statmech = StatmechDatabase() self.statmech.loadOld(path)
def setUpClass(cls): """ A function run ONCE before all unit tests in this class. """ # Set up a dummy database cls.database = KineticsDatabase() cls.database.loadFamilies( path=os.path.join(settings['test_data.directory'], 'testing_database/kinetics/families'), families=[ 'intra_H_migration', 'R_Addition_MultipleBond', 'H_Abstraction', 'Intra_ene_reaction', '6_membered_central_C-C_shift', '1,2_shiftC', 'Intra_R_Add_Exo_scission', 'intra_substitutionS_isomerization', 'R_Addition_COm' ], ) cls.family = cls.database.families['intra_H_migration']
class RMGDatabase: """ The primary class for working with the RMG database. """ def __init__(self): self.thermo = None self.transport = None self.forbiddenStructures = None self.kinetics = None self.statmech = None self.solvation = None # Store the newly created database in the module. global database # assert database is None, "Should only make one instance of RMGDatabase because it's stored as a module-level variable." if database is None: database = self else: logging.warning( "Should only make one instance of RMGDatabase because it's stored as a module-level variable!" ) logging.warning("Unexpected behaviour may result!") def load(self, path, thermoLibraries=None, transportLibraries=None, reactionLibraries=None, seedMechanisms=None, kineticsFamilies=None, kineticsDepositories=None, statmechLibraries=None, depository=True, solvation=True, testing=False): """ Load the RMG database from the given `path` on disk, where `path` points to the top-level folder of the RMG database. If none of the optional arguments are provided, then the entire database will be loaded. You can use the optional arguments to specify that only certain components of the database be loaded. Argument testing will load a lighter version of the database used for unit-tests """ self.loadThermo(os.path.join(path, 'thermo'), thermoLibraries, depository) if not testing: self.loadTransport(os.path.join(path, 'transport'), transportLibraries) self.loadForbiddenStructures( os.path.join(path, 'forbiddenStructures.py')) self.loadKinetics(os.path.join(path, 'kinetics'), reactionLibraries, seedMechanisms, kineticsFamilies, kineticsDepositories) if not testing: self.loadStatmech(os.path.join(path, 'statmech'), statmechLibraries, depository) if solvation: self.loadSolvation(os.path.join(path, 'solvation')) def loadThermo(self, path, thermoLibraries=None, depository=True): """ Load the RMG thermo database from the given `path` on disk, where `path` points to the top-level folder of the RMG thermo database. """ self.thermo = ThermoDatabase() self.thermo.load(path, thermoLibraries, depository) broadcast(self.thermo, 'thermo') def loadTransport(self, path, transportLibraries=None): """ Load the RMG transport database from the given 'path' on disk, where 'path' points to the top-level folder of the RMG transport database. """ self.transport = TransportDatabase() self.transport.load(path, transportLibraries) broadcast(self.transport, 'transport') def loadForbiddenStructures(self, path=None): """ Load the RMG forbidden structures from the given `path` on disk, where `path` points to the forbidden structures file. If no path is given, a blank forbidden structures object is created. """ self.forbiddenStructures = ForbiddenStructures() if path is not None: self.forbiddenStructures.load(path) broadcast(self.forbiddenStructures, 'forbidden') def loadKinetics(self, path, reactionLibraries=None, seedMechanisms=None, kineticsFamilies=None, kineticsDepositories=None): """ Load the RMG kinetics database from the given `path` on disk, where `path` points to the top-level folder of the RMG kinetics database. """ kineticsLibraries = [] libraryOrder = [] if seedMechanisms is None and reactionLibraries is None: kineticsLibraries = None if seedMechanisms is not None: for library in seedMechanisms: kineticsLibraries.append(library) libraryOrder.append((library, 'Seed')) if reactionLibraries is not None: for library in reactionLibraries: kineticsLibraries.append(library) libraryOrder.append((library, 'Reaction Library')) self.kinetics = KineticsDatabase() self.kinetics.libraryOrder = libraryOrder self.kinetics.load(path, families=kineticsFamilies, libraries=kineticsLibraries, depositories=kineticsDepositories) broadcast(self.kinetics, 'kinetics') def loadSolvation(self, path): """ Load the RMG solvation database from the given `path` on disk, where `path` points to the top-level folder of the RMG solvation database. """ self.solvation = SolvationDatabase() self.solvation.load(path) broadcast(self.solvation, 'solvation') def loadStatmech(self, path, statmechLibraries=None, depository=True): """ Load the RMG statmech database from the given `path` on disk, where `path` points to the top-level folder of the RMG statmech database. """ self.statmech = StatmechDatabase() self.statmech.load(path, statmechLibraries, depository) broadcast(self.statmech, 'statmech') def loadOld(self, path): """ Load the old RMG database from the given `path` on disk, where `path` points to the top-level folder of the old RMG database. """ self.thermo = ThermoDatabase() self.thermo.loadOld(path) self.transport = TransportDatabase() #self.transport.loadOld(path) # Currently no loadOld import function available for transport groups self.forbiddenStructures = ForbiddenStructures() self.forbiddenStructures.loadOld( os.path.join(path, 'ForbiddenStructures.txt')) self.kinetics = KineticsDatabase() self.kinetics.loadOld(path) self.statmech = StatmechDatabase() self.statmech.loadOld(path) self.solvation = SolvationDatabase() # Not completely implemented # self.solvation.loadOld(path) def save(self, path): """ Save the RMG database to the given `path` on disk. """ if not os.path.exists(path): os.makedirs(path) self.forbiddenStructures.save( os.path.join(path, 'forbiddenStructures.py')) self.thermo.save(os.path.join(path, 'thermo')) # self.transport.save(os.path.join(path, 'transport')) #Currently no function for saving transport groups self.kinetics.save(os.path.join(path, 'kinetics')) self.statmech.save(os.path.join(path, 'statmech')) self.solvation.save(os.path.join(path, 'solvation')) self.transport.save(os.path.join(path, 'transport')) def saveOld(self, path): """ Save the old RMG database to the given `path` on disk. """ if not os.path.exists(path): os.makedirs(path) self.thermo.saveOld(path) self.transport.saveOld(path) self.forbiddenStructures.saveOld( os.path.join(path, 'ForbiddenStructures.txt')) self.kinetics.saveOld(path) self.statmech.saveOld(path)
def test_load_families_correct(self): """Test valid methods for loading kinetics families.""" path = os.path.join(settings['test_data.directory'], 'testing_database', 'kinetics', 'families') database = KineticsDatabase() database.loadRecommendedFamiliesList(os.path.join(path, 'recommended.py')) try: database.loadFamilies(path, families=[]) except DatabaseError: self.fail("Unable to load families using list []") try: database.loadFamilies(path, families='none') except DatabaseError: self.fail("Unable to load families using keyword 'none'") try: database.loadFamilies(path, families='default') except DatabaseError: self.fail("Unable to load families using keyword 'default'") try: database.loadFamilies(path, families=['default', 'pah']) except DatabaseError: self.fail("Unable to load families using list ['default', 'pah']") try: database.loadFamilies(path, families=['R_Addition_MultipleBond']) except DatabaseError: self.fail("Unable to load families using list ['R_Addition_MultipleBond']") try: database.loadFamilies(path, families=['!H_Abstraction', '!Disproportionation']) except DatabaseError: self.fail("Unable to load families using list ['!H_Abstraction', '!Disproportionation']") try: database.loadFamilies(path, families='!pah') except DatabaseError: self.fail("Unable to load families using keyword '!pah'") try: database.loadFamilies(path, families=['H_Abstraction', 'pah']) except DatabaseError: self.fail("Unable to load families using list ['H_Abstraction', 'pah']")
class RMGDatabase: """ The primary class for working with the RMG database. """ def __init__(self): self.thermo = None self.transport = None self.forbiddenStructures = None self.kinetics = None self.statmech = None self.solvation = None # Store the newly created database in the module. global database # assert database is None, "Should only make one instance of RMGDatabase because it's stored as a module-level variable." if database is None: database = self else: logging.warning("Should only make one instance of RMGDatabase because it's stored as a module-level variable!") logging.warning("Unexpected behaviour may result!") def load(self, path, thermoLibraries=None, transportLibraries=None, reactionLibraries=None, seedMechanisms=None, kineticsFamilies=None, kineticsDepositories=None, statmechLibraries=None, depository=True, solvation=True, testing = False): """ Load the RMG database from the given `path` on disk, where `path` points to the top-level folder of the RMG database. If none of the optional arguments are provided, then the entire database will be loaded. You can use the optional arguments to specify that only certain components of the database be loaded. Argument testing will load a lighter version of the database used for unit-tests """ self.loadThermo(os.path.join(path, 'thermo'), thermoLibraries, depository) if not testing: self.loadTransport(os.path.join(path, 'transport'), transportLibraries) self.loadForbiddenStructures(os.path.join(path, 'forbiddenStructures.py')) self.loadKinetics(os.path.join(path, 'kinetics'), reactionLibraries, seedMechanisms, kineticsFamilies, kineticsDepositories ) if not testing: self.loadStatmech(os.path.join(path, 'statmech'), statmechLibraries, depository) if solvation: self.loadSolvation(os.path.join(path, 'solvation')) def loadThermo(self, path, thermoLibraries=None, depository=True): """ Load the RMG thermo database from the given `path` on disk, where `path` points to the top-level folder of the RMG thermo database. """ self.thermo = ThermoDatabase() self.thermo.load(path, thermoLibraries, depository) broadcast(self.thermo, 'thermo') def loadTransport(self, path, transportLibraries=None): """ Load the RMG transport database from the given 'path' on disk, where 'path' points to the top-level folder of the RMG transport database. """ self.transport = TransportDatabase() self.transport.load(path, transportLibraries) broadcast(self.transport, 'transport') def loadForbiddenStructures(self, path): """ Load the RMG forbidden structures from the given `path` on disk, where `path` points to the forbidden structures file. """ self.forbiddenStructures = ForbiddenStructures() self.forbiddenStructures.load(path) broadcast(self.forbiddenStructures, 'forbidden') def loadKinetics(self, path, reactionLibraries=None, seedMechanisms=None, kineticsFamilies=None, kineticsDepositories=None ): """ Load the RMG kinetics database from the given `path` on disk, where `path` points to the top-level folder of the RMG kinetics database. """ kineticsLibraries = [] libraryOrder = [] if seedMechanisms is None and reactionLibraries is None: kineticsLibraries = None if seedMechanisms is not None: for library in seedMechanisms: kineticsLibraries.append(library) libraryOrder.append((library,'Seed')) if reactionLibraries is not None: for library in reactionLibraries: kineticsLibraries.append(library) libraryOrder.append((library,'Reaction Library')) self.kinetics = KineticsDatabase() self.kinetics.libraryOrder = libraryOrder self.kinetics.load(path, families=kineticsFamilies, libraries=kineticsLibraries, depositories=kineticsDepositories ) broadcast(self.kinetics, 'kinetics') def loadSolvation(self, path): """ Load the RMG solvation database from the given `path` on disk, where `path` points to the top-level folder of the RMG solvation database. """ self.solvation = SolvationDatabase() self.solvation.load(path) broadcast(self.solvation, 'solvation') def loadStatmech(self, path, statmechLibraries=None, depository=True): """ Load the RMG statmech database from the given `path` on disk, where `path` points to the top-level folder of the RMG statmech database. """ self.statmech = StatmechDatabase() self.statmech.load(path, statmechLibraries, depository) broadcast(self.statmech, 'statmech') def loadOld(self, path): """ Load the old RMG database from the given `path` on disk, where `path` points to the top-level folder of the old RMG database. """ self.thermo = ThermoDatabase() self.thermo.loadOld(path) self.transport = TransportDatabase() #self.transport.loadOld(path) # Currently no loadOld import function available for transport groups self.forbiddenStructures = ForbiddenStructures() self.forbiddenStructures.loadOld(os.path.join(path, 'ForbiddenStructures.txt')) self.kinetics = KineticsDatabase() self.kinetics.loadOld(path) self.statmech = StatmechDatabase() self.statmech.loadOld(path) self.solvation = SolvationDatabase() # Not completely implemented # self.solvation.loadOld(path) def save(self, path): """ Save the RMG database to the given `path` on disk. """ if not os.path.exists(path): os.makedirs(path) self.forbiddenStructures.save(os.path.join(path, 'forbiddenStructures.py')) self.thermo.save(os.path.join(path, 'thermo')) # self.transport.save(os.path.join(path, 'transport')) #Currently no function for saving transport groups self.kinetics.save(os.path.join(path, 'kinetics')) self.statmech.save(os.path.join(path, 'statmech')) self.solvation.save(os.path.join(path, 'solvation')) self.transport.save(os.path.join(path, 'transport')) def saveOld(self, path): """ Save the old RMG database to the given `path` on disk. """ if not os.path.exists(path): os.makedirs(path) self.thermo.saveOld(path) self.transport.saveOld(path) self.forbiddenStructures.saveOld(os.path.join(path, 'ForbiddenStructures.txt')) self.kinetics.saveOld(path) self.statmech.saveOld(path)
def test_load_families_correct(self): """Test valid methods for loading kinetics families.""" path = os.path.join(settings['test_data.directory'], 'testing_database', 'kinetics', 'families') database = KineticsDatabase() database.loadRecommendedFamiliesList( os.path.join(path, 'recommended.py')) try: database.loadFamilies(path, families=[]) except DatabaseError: self.fail("Unable to load families using list []") try: database.loadFamilies(path, families='none') except DatabaseError: self.fail("Unable to load families using keyword 'none'") try: database.loadFamilies(path, families='default') except DatabaseError: self.fail("Unable to load families using keyword 'default'") try: database.loadFamilies(path, families=['default', 'pah']) except DatabaseError: self.fail("Unable to load families using list ['default', 'pah']") try: database.loadFamilies(path, families=['R_Addition_MultipleBond']) except DatabaseError: self.fail( "Unable to load families using list ['R_Addition_MultipleBond']" ) try: database.loadFamilies( path, families=['!H_Abstraction', '!Disproportionation']) except DatabaseError: self.fail( "Unable to load families using list ['!H_Abstraction', '!Disproportionation']" ) try: database.loadFamilies(path, families='!pah') except DatabaseError: self.fail("Unable to load families using keyword '!pah'") try: database.loadFamilies(path, families=['H_Abstraction', 'pah']) except DatabaseError: self.fail( "Unable to load families using list ['H_Abstraction', 'pah']")
class RMGDatabase(object): """ The primary class for working with the RMG database. """ def __init__(self): self.thermo = None self.transport = None self.forbidden_structures = None self.kinetics = None self.statmech = None self.solvation = None self.surface = None # Store the newly created database in the module. global database if database is not None: logging.warning( 'An instance of RMGDatabase already exists. Re-initializing it.' ) database = self def load( self, path, thermo_libraries=None, transport_libraries=None, reaction_libraries=None, seed_mechanisms=None, kinetics_families=None, kinetics_depositories=None, statmech_libraries=None, depository=True, solvation=True, surface=True, # on by default, because solvation is also on by default testing=False): """ Load the RMG database from the given `path` on disk, where `path` points to the top-level folder of the RMG database. If none of the optional arguments are provided, then the entire database will be loaded. You can use the optional arguments to specify that only certain components of the database be loaded. Argument testing will load a lighter version of the database used for unit-tests """ if not testing: self.load_transport(os.path.join(path, 'transport'), transport_libraries) self.load_forbidden_structures( os.path.join(path, 'forbiddenStructures.py')) self.load_kinetics(os.path.join(path, 'kinetics'), reaction_libraries, seed_mechanisms, kinetics_families, kinetics_depositories) if not testing: self.load_statmech(os.path.join(path, 'statmech'), statmech_libraries, depository) if solvation: self.load_solvation(os.path.join(path, 'solvation')) if surface: self.load_thermo(os.path.join(path, 'thermo'), thermo_libraries, depository, surface) def load_thermo(self, path, thermo_libraries=None, depository=True, surface=False): """ Load the RMG thermo database from the given `path` on disk, where `path` points to the top-level folder of the RMG thermo database. """ self.thermo = ThermoDatabase() self.thermo.load(path, thermo_libraries, depository, surface) def load_transport(self, path, transport_libraries=None): """ Load the RMG transport database from the given 'path' on disk, where 'path' points to the top-level folder of the RMG transport database. """ self.transport = TransportDatabase() self.transport.load(path, transport_libraries) def load_forbidden_structures(self, path=None): """ Load the RMG forbidden structures from the given `path` on disk, where `path` points to the forbidden structures file. If no path is given, a blank forbidden structures object is created. """ self.forbidden_structures = ForbiddenStructures() if path is not None: self.forbidden_structures.load(path) def load_kinetics(self, path, reaction_libraries=None, seed_mechanisms=None, kinetics_families=None, kinetics_depositories=None): """ Load the RMG kinetics database from the given `path` on disk, where `path` points to the top-level folder of the RMG kinetics database. """ kinetics_libraries = [] library_order = [] if seed_mechanisms is None and reaction_libraries is None: kinetics_libraries = None if seed_mechanisms is not None: for library in seed_mechanisms: kinetics_libraries.append(library) library_order.append((library, 'Seed')) if reaction_libraries is not None: for library in reaction_libraries: kinetics_libraries.append(library) library_order.append((library, 'Reaction Library')) self.kinetics = KineticsDatabase() self.kinetics.library_order = library_order self.kinetics.load(path, families=kinetics_families, libraries=kinetics_libraries, depositories=kinetics_depositories) def load_solvation(self, path): """ Load the RMG solvation database from the given `path` on disk, where `path` points to the top-level folder of the RMG solvation database. """ self.solvation = SolvationDatabase() self.solvation.load(path) def load_surface(self, path): """ Load the RMG metal database from the given `path` on disk, where `path` points to the top-level folder of the RMG surface database. """ self.surface = MetalDatabase() self.surface.load(path) def load_statmech(self, path, statmech_libraries=None, depository=True): """ Load the RMG statmech database from the given `path` on disk, where `path` points to the top-level folder of the RMG statmech database. """ self.statmech = StatmechDatabase() self.statmech.load(path, statmech_libraries, depository) def load_old(self, path): """ Load the old RMG database from the given `path` on disk, where `path` points to the top-level folder of the old RMG database. """ self.thermo = ThermoDatabase() self.thermo.load_old(path) self.transport = TransportDatabase() # self.transport.load_old(path) # Currently no load_old import function available for transport groups self.forbidden_structures = ForbiddenStructures() self.forbidden_structures.load_old( os.path.join(path, 'ForbiddenStructures.txt')) self.kinetics = KineticsDatabase() self.kinetics.load_old(path) self.statmech = StatmechDatabase() self.statmech.load_old(path) self.solvation = SolvationDatabase() # Not completely implemented # self.solvation.load_old(path) def save(self, path): """ Save the RMG database to the given `path` on disk. """ if not os.path.exists(path): os.makedirs(path) self.forbidden_structures.save( os.path.join(path, 'forbiddenStructures.py')) self.thermo.save(os.path.join(path, 'thermo')) # self.transport.save(os.path.join(path, 'transport')) #Currently no function for saving transport groups self.kinetics.save(os.path.join(path, 'kinetics')) self.statmech.save(os.path.join(path, 'statmech')) self.solvation.save(os.path.join(path, 'solvation')) self.transport.save(os.path.join(path, 'transport')) def save_old(self, path): """ Save the old RMG database to the given `path` on disk. """ if not os.path.exists(path): os.makedirs(path) self.thermo.save_old(path) self.transport.save_old(path) self.forbidden_structures.save_old( os.path.join(path, 'ForbiddenStructures.txt')) self.kinetics.save_old(path) self.statmech.save_old(path)