def load_thermo_lib_by_path(path: str, thermo_db: ThermoDatabase, reload: bool = False): """ Load thermo library given its library path and store it into the given RMG ThermoDatabase instance Args: path (str): Path to thermo library file thermo_database (ThermoDatabase): RMG thermo database object reload (bool): Whether to reload the library if this library is in the ThermoDatabase """ lib = ThermoLibrary() try: lib.load(path, ThermoDatabase().local_context, ThermoDatabase().global_context) except FileNotFoundError: print(f'The library file {path} does not exist.') except (SyntaxError, ImportError): print(f'The library file {path} is not valid.') else: if path in thermo_db.library_order and not reload: print(f'The library {path} has already been loaded.') return elif path not in thermo_db.library_order: thermo_db.library_order.append(path) lib.label = path lib.name = path thermo_db.libraries[lib.label] = lib print(f'The thermodynamics library {path} is loaded.')
import argparse import os from rmgpy.data.thermo import ThermoLibrary if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('inputPath', metavar='INPUT', type=str, nargs=1, help='the input path of the RMG-Java thermo library directory') parser.add_argument('libraryName', metavar='OUTPUT', type=str, nargs=1, help='the libraryName for the RMG-Py format thermo library') args = parser.parse_args() inputPath = args.inputPath[0] libraryName = args.libraryName[0] library = ThermoLibrary() library.loadOld( dictstr = os.path.join(inputPath, 'Dictionary.txt'), treestr = '', libstr = os.path.join(inputPath, 'Library.txt'), numParameters = 12, numLabels = 1, pattern = False, ) library.name = libraryName # Save in Py format library.save(os.path.join('input/thermo/libraries/', libraryName+'.py'))
metavar='INPUT', type=str, nargs=1, help='the input path of the RMG-Java thermo library directory') parser.add_argument( 'libraryName', metavar='OUTPUT', type=str, nargs=1, help='the libraryName for the RMG-Py format thermo library') args = parser.parse_args() inputPath = args.inputPath[0] libraryName = args.libraryName[0] library = ThermoLibrary() library.loadOld( dictstr=os.path.join(inputPath, 'Dictionary.txt'), treestr='', libstr=os.path.join(inputPath, 'Library.txt'), numParameters=12, numLabels=1, pattern=False, ) library.name = libraryName # Save in Py format library.save( os.path.join(settings['database.directory'], 'thermo', 'libraries', libraryName + '.py'))