Skip to content

Commit

Permalink
Merge pull request #33 from uclchem/develop
Browse files Browse the repository at this point in the history
UCLCHEM V3.2.0
  • Loading branch information
Marcus-Keil authored Mar 27, 2023
2 parents e382154 + 2d6e7d0 commit 21c9010
Show file tree
Hide file tree
Showing 54 changed files with 8,988 additions and 14,987 deletions.
8 changes: 0 additions & 8 deletions .idea/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion .idea/.name

This file was deleted.

12 changes: 0 additions & 12 deletions .idea/UCLCHEM.iml

This file was deleted.

15 changes: 0 additions & 15 deletions .idea/inspectionProfiles/Project_Default.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/inspectionProfiles/profiles_settings.xml

This file was deleted.

4 changes: 0 additions & 4 deletions .idea/misc.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

131 changes: 67 additions & 64 deletions Makerates/MakeRates.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,69 +7,72 @@
# by UCLCHEM to run. It also performs basic cleaning and sanity checks on the network.
#
####################################################################################################
import src.io_functions as io
from src.network import *
import os
import yaml

param_list = [
"species_file",
"database_reaction_file",
"database_reaction_type",
"custom_reaction_file",
"custom_reaction_type",
"three_phase",
]

with open("user_settings.yaml", "r") as f:
user_params = yaml.safe_load(f)
for param in param_list:
try:
print(f"{param} : {user_params[param]}")
except:
raise KeyError(f"{param} not found in user_settings.yaml")
# All code that is run by this script resides in src/uclchem/makerates/makerates.py

try:
user_output_dir = user_params["output_directory"]
if not os.path.exists(user_output_dir):
os.makedirs(user_output_dir)
except:
user_output_dir = None

#################################################################################################


print("\n################################################")
print("Reading and checking input")
print("################################################\n")

# Read user inputs
species_list, user_defined_bulk = io.read_species_file(user_params["species_file"])
reactions1, dropped_reactions = io.read_reaction_file(
user_params["database_reaction_file"], species_list, user_params["database_reaction_type"]
)
reactions2, dropped_reactions = io.read_reaction_file(user_params["custom_reaction_file"], species_list, user_params["custom_reaction_type"])

# Create Network
network = Network(species=species_list, reactions=reactions1 + reactions2, three_phase=user_params["three_phase"], user_defined_bulk=user_defined_bulk)

io.output_drops(dropped_reactions, user_output_dir)

# check network to see if there are potential problems
print("Checking Network")
network.check_network()


print("\n################################################")
print("Checks complete, writing output files")
print("################################################\n")

io.write_outputs(network, user_output_dir)


ngrain = len([x for x in species_list if x.is_surface_species()])


print(f"Total number of species = {len(network.species_list)}")
print(f"Number of surface species = {ngrain}")
print(f"Number of reactions = {len(network.reaction_list)}")
from uclchem.makerates import run_makerates
except ModuleNotFoundError as err:
raise ModuleNotFoundError(
"The uclchem module could not be found, please make sure it is installed\nPlease refer to uclchem.github.io for installation instructions."
) from err
import logging
from argparse import ArgumentParser
import pathlib


def get_args():
"""Allows for interacting with MakeRates.py via the command line i.e.
```
python3 MakeRates.py /home/user/some_directory/custom_settings.yaml --verbosity DEBUG
```
Returns:
Namespace: Arguments passed via the CLI or their defaults
"""
parser = ArgumentParser()
parser.add_argument(
"settings_path", nargs="?", default="user_settings.yaml", type=pathlib.Path
)
parser.add_argument("-v", "--verbosity_stdout", default="WARNING", type=str)
parser.add_argument("-d", "--debug", action="store_true")
return parser.parse_args()


def get_logger(verbosity_stdout: str, debug: bool):
"""Define a logger that logs both to file and stdout"""
# TODO: fix that both verbosity for file and stdout are the same type, but it works for now.
if debug:
verbosity_file = logging.DEBUG
verbosity_stdout = "DEBUG"
else:
verbosity_file = logging.INFO
verbosity_stdout = verbosity_stdout
# Make sure the verbosity to the file is always smaller than stdout to avoid confusion
if verbosity_stdout.upper() == "DEBUG":
verbosity_file = logging.DEBUG
logging.basicConfig(
level=verbosity_file,
format="%(asctime)s %(levelname)s: %(message)s",
datefmt="%m-%d %H:%M",
filename="makerates.log",
filemode="w",
)
# define a Handler which writes INFO messages or higher to the sys.stderr
console = logging.StreamHandler()
console.setLevel(verbosity_stdout)
# set a format which is simpler for console use
formatter = logging.Formatter(" %(levelname)-8s %(message)s")
# tell the handler to use this format
console.setFormatter(formatter)
# add the handler to the root logger
logging.getLogger("").addHandler(console)

# Now, we can log to the root logger, or any other logger. First the root...
logging.info(
f"Configured the logging. Files verbosity is {logging.getLevelName(verbosity_file)} and stdout verbosity is {verbosity_stdout}"
)


if __name__ == "__main__":
args = get_args()
get_logger(args.verbosity_stdout, args.debug)
run_makerates(args.settings_path)
2 changes: 1 addition & 1 deletion Makerates/comparenetworks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# enter two reaction files to see all reactions that are one file but not the other

from src.io_functions import *
from uclchem.makerates.io_functions import read_species_file, read_reaction_file


reactions1 = "inputFiles/default_grain_network.csv"
Expand Down
2 changes: 1 addition & 1 deletion Makerates/comparespecies.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# enter two species files to see all species that are one file but not the other

from src.io_functions import *
from uclchem.makerates.io_functions import read_species_file


speciesFile = "inputFiles/default_species.csv"
Expand Down
4 changes: 4 additions & 0 deletions Makerates/inputFiles/default_grain_network.csv
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,7 @@ C2N,FREEZE,,#CH3CNH,,,,1,0,0,,,
C2N+,FREEZE,,#CH3CNH,,,,1,1,0,,,
C3N,FREEZE,,#HC3N,,,,1,0,0,,,
C2NH+,FREEZE,,#CH3CNH,,,,1,1,0,,,

! Handle HEH and H3
H3+,FREEZE,,#H,#H,#H,,1,1,0,,,
HEH+,FREEZE,,#H,#HE,,,1,1,0,,,
Binary file not shown.
Binary file not shown.
Binary file removed Makerates/src/__pycache__/network.cpython-38.pyc
Binary file not shown.
Binary file removed Makerates/src/__pycache__/network.cpython-39.pyc
Binary file not shown.
Binary file removed Makerates/src/__pycache__/reaction.cpython-38.pyc
Binary file not shown.
Binary file removed Makerates/src/__pycache__/reaction.cpython-39.pyc
Binary file not shown.
Binary file removed Makerates/src/__pycache__/species.cpython-38.pyc
Binary file not shown.
Binary file removed Makerates/src/__pycache__/species.cpython-39.pyc
Binary file not shown.
Loading

0 comments on commit 21c9010

Please sign in to comment.