def load_libraries(self, path, libraries=None): """ Load the listed kinetics libraries from the given `path` on disk. Loads them all if `libraries` list is not specified or `None`. The `path` points to the folder of kinetics libraries in the database, and the libraries should be in files like :file:`<path>/<library>.py`. """ if libraries is not None: for library_name in libraries: library_file = os.path.join(path, library_name, 'reactions.py') if os.path.exists(library_file): logging.info( 'Loading kinetics library {0} from {1}...'.format( library_name, library_file)) library = KineticsLibrary(label=library_name) library.load(library_file, self.local_context, self.global_context) self.libraries[library.label] = library else: if library_name == "KlippensteinH2O2": logging.info( """\n** Note: The KlippensteinH2O2 library was replaced and is no longer available in RMG. For H2 combustion chemistry consider using either the BurkeH2inN2 or BurkeH2inArHe library instead, depending on the main bath gas (N2 or Ar/He, respectively)\n""" ) raise IOError("Couldn't find kinetics library {0}".format( library_file)) else: # load all the libraries you can find # this cannot be activated in a normal RMG job. Only activated when loading the database for other purposes self.library_order = [] for (root, dirs, files) in os.walk(os.path.join(path)): for f in files: name, ext = os.path.splitext(f) if ext.lower() == '.py': library_file = os.path.join(root, f) label = os.path.dirname(library_file)[len(path) + 1:] logging.info( 'Loading kinetics library {0} from {1}...'.format( label, library_file)) library = KineticsLibrary(label=label) try: library.load(library_file, self.local_context, self.global_context) except: logging.error( "Problem loading reaction library {0!r}". format(library_file)) raise self.libraries[library.label] = library self.library_order.append( (library.label, 'Reaction Library'))
def import_kinetics(kinetics_path, kinetic_model, models): local_context = { "KineticsData": kinetics.KineticsData, "Arrhenius": kinetics.Arrhenius, "ArrheniusEP": kinetics.ArrheniusEP, "MultiArrhenius": kinetics.MultiArrhenius, "MultiPDepArrhenius": kinetics.MultiPDepArrhenius, "PDepArrhenius": kinetics.PDepArrhenius, "Chebyshev": kinetics.Chebyshev, "ThirdBody": kinetics.ThirdBody, "Lindemann": kinetics.Lindemann, "Troe": kinetics.Troe, "R": constants.R, } library = KineticsLibrary(label=kinetic_model.model_name) library.SKIP_DUPLICATES = True library.load(kinetics_path, local_context=local_context) for entry in library.entries.values(): try: with transaction.atomic(): rmg_kinetics_data = entry.data comment = entry.short_desc rmg_reaction = entry.item reaction = get_or_create_reaction(kinetic_model, rmg_reaction, models) kinetics_data = create_kinetics_data(kinetic_model, rmg_kinetics_data, models) base_fields = get_base_kinetics_data_fields(rmg_kinetics_data) kinetics_instance, created = models.Kinetics.objects.get_or_create( reaction=reaction, raw_data=kinetics_data, defaults=base_fields) if created and kinetics_data.get("type") not in [ "arrhenius", "arrhenius_ep", "multi_arrhenius", ]: create_and_save_efficiencies(kinetic_model, kinetics_instance, rmg_kinetics_data, models) models.KineticsComment.objects.get_or_create( kinetics=kinetics_instance, kinetic_model=kinetic_model, defaults={"comment": comment}, ) except Exception: logger.exception(f"Failed to import reaction {entry.label}")