def run_simulation(input_file, chemkin_file, dict_file, diffusion_limited=True, check_duplicates=True): """ Runs a standalone simulation of RMG. Runs sensitivity analysis if sensitive species are given. Also runs uncertainty analysis if uncertainty options block is present in input file. diffusion_limited=True implies that if it is a liquid reactor diffusion limitations will be enforced otherwise they will not be in a liquid reactor """ output_dir = os.path.abspath(os.path.dirname(input_file)) initialize_log(logging.INFO, os.path.join(output_dir, 'simulate.log')) rmg = load_rmg_job(input_file, chemkin_file, dict_file, generate_images=False, check_duplicates=check_duplicates) start_time = time() # conduct simulation simulate(rmg, diffusion_limited) end_time = time() time_taken = end_time - start_time logging.info("Simulation took {0} seconds".format(time_taken))
def run(input_file, output_directory, original=None, maximum_isotopic_atoms=1, use_original_reactions=False, kinetic_isotope_effect=None): """ Accepts one input file with the RMG-Py model to generate. Firstly, generates the RMG model for the first input file. Takes the core species of that mechanism and generates all isotopomers of those core species. Next, generates all reactions between the generated pool of isotopomers, and writes it to file. """ logging.info("isotope: Starting the RMG isotope generation method 'run'") if not original: logging.info( "isotope: original model not found, generating new one in directory `rmg`" ) logging.info( "isotope: check `rmg/RMG.log` for the rest of the logging info.") outputdir_rmg = os.path.join(output_directory, 'rmg') os.mkdir(outputdir_rmg) rmg = generate_rmg_model(input_file, outputdir_rmg) else: logging.info( "isotope: original model being copied from previous RMG job in folder {}" .format(original)) outputdir_rmg = original chemkin_file = os.path.join(outputdir_rmg, 'chemkin', 'chem_annotated.inp') dict_file = os.path.join(outputdir_rmg, 'chemkin', 'species_dictionary.txt') rmg = load_rmg_job(input_file, chemkin_file, dict_file, generate_images=False, use_chemkin_names=True) logging.info("isotope: generating isotope model") logging.info('Generating isotopomers for the core species in {}'.format( outputdir_rmg)) isotopes = [] logging.info("isotope: adding all the new and old isotopomers") for spc in rmg.reaction_model.core.species: find_cp0_and_cpinf(spc, spc.thermo) isotopes.append([spc] + generate_isotopomers(spc, maximum_isotopic_atoms)) logging.info('isotope: number of isotopomers: {}'.format( sum([len(isotopomer) for isotopomer in isotopes if isotopomer]))) outputdir_iso = os.path.join(output_directory, 'iso') os.mkdir(outputdir_iso) logging.info( 'isotope: Generating RMG isotope model in {}'.format(outputdir_iso)) generate_isotope_model(outputdir_iso, rmg, isotopes, use_original_reactions=use_original_reactions, kinetic_isotope_effect=kinetic_isotope_effect)
def create_flux_diagram(input_file, chemkin_file, species_dict, save_path=None, species_path=None, java=False, settings=None, chemkin_output='', central_species_list=None, superimpose=False, save_states=False, read_states=False, diffusion_limited=True, check_duplicates=True): """ Generates the flux diagram based on a condition 'input_file', chemkin.inp chemkin_file, a species_dict txt file, plus an optional chemkin_output file. """ if java == True: warnings.warn("RMG-Java loading is no longer supported and may be" \ "removed in version 2.3.", DeprecationWarning) if species_path is None: species_path = os.path.join(os.path.dirname(input_file), 'species') generate_images = True else: generate_images = False print('Loading RMG job...') rmg = load_rmg_job(input_file, chemkin_file, species_dict, generate_images=generate_images, use_java=java, check_duplicates=check_duplicates) if save_path is None: save_path = os.path.join(rmg.output_directory, 'flux') # if you have a chemkin output, then you only have one reaction_system if chemkin_output: out_dir = os.path.join(save_path, '1') try: os.makedirs(out_dir) except OSError: pass print('Extracting species concentrations and calculating reaction rates from chemkin output...') time, core_species_concentrations, core_reaction_rates = load_chemkin_output(chemkin_output, rmg.reaction_model) print('Generating flux diagram for chemkin output...') generate_flux_diagram(rmg.reaction_model, time, core_species_concentrations, core_reaction_rates, out_dir, central_species_list=central_species_list, superimpose=superimpose, species_directory=species_path, settings=settings) else: # Generate a flux diagram video for each reaction system for index, reaction_system in enumerate(rmg.reaction_systems): out_dir = os.path.join(save_path, '{0:d}'.format(index + 1)) try: os.makedirs(out_dir) except OSError: # Fail silently on any OS errors pass # If there is no termination time, then add one to prevent jobs from # running forever if not any([isinstance(term, TerminationTime) for term in reaction_system.termination]): reaction_system.termination.append(TerminationTime((1e10, 's'))) states_file = os.path.join(out_dir, 'states.npz') if read_states: print('Reading simulation states from file...') states = np.load(states_file) time = states['time'] core_species_concentrations = states['core_species_concentrations'] core_reaction_rates = states['core_reaction_rates'] else: # Enable diffusion-limited rates if diffusion_limited and isinstance(reaction_system, LiquidReactor): rmg.load_database() solvent_data = rmg.database.solvation.get_solvent_data(rmg.solvent) diffusion_limiter.enable(solvent_data, rmg.database.solvation) print('Conducting simulation of reaction system {0:d}...'.format(index + 1)) time, core_species_concentrations, core_reaction_rates = simulate(rmg.reaction_model, reaction_system, settings) if save_states: np.savez_compressed(states_file, time=time, core_species_concentrations=core_species_concentrations, core_reaction_rates=core_reaction_rates) print('Generating flux diagram for reaction system {0:d}...'.format(index + 1)) generate_flux_diagram(rmg.reaction_model, time, core_species_concentrations, core_reaction_rates, out_dir, central_species_list=central_species_list, superimpose=superimpose, species_directory=species_path, settings=settings)