uclchem.makerates.config#

Pydantic-based configuration system for UCLCHEM Makerates.

This module provides validated configuration handling with clear defaults, type checking, and automatic documentation generation.

Module Contents#

Classes#

MakeratesConfig

Configuration for UCLCHEM Makerates chemical network generation.

Attributes#

class uclchem.makerates.config.MakeratesConfig(/, **data: Any)[source]#

Bases: pydantic.BaseModel

Configuration for UCLCHEM Makerates chemical network generation.

This class validates all configuration parameters and provides sensible defaults where appropriate. All file paths are resolved relative to the configuration file location.

Examples

>>> from uclchem.utils import UCLCHEM_ROOT_DIR
>>> config = MakeratesConfig.from_yaml(UCLCHEM_ROOT_DIR/ "../../Makerates/user_settings.yaml")
>>> print(config.species_file)
data/default/default_species.csv

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

auto_enable_rates_storage() MakeratesConfig[source]#

Automatically enable rates storage if needed for exothermicity.

Returns:

validated MakeratesConfig.

Return type:

MakeratesConfig

check_three_phase_deprecation() MakeratesConfig[source]#

Raise error if three_phase is explicitly set to False.

Returns:

validated MakeratesConfig.

Return type:

MakeratesConfig

Raises:

ValueError – If three_phase is False.

classmethod from_yaml(yaml_path: str | pathlib.Path) MakeratesConfig[source]#

Load and validate configuration from a YAML file.

All relative paths in the config file are resolved relative to the directory containing the YAML file.

Parameters:

yaml_path (str | Path) – Path to the YAML configuration file

Returns:

Validated MakeratesConfig instance

Return type:

MakeratesConfig

Raises:

FileNotFoundError – If config file doesn’t exist

classmethod generate_template(output_path: str | pathlib.Path = 'user_settings_template.yaml')[source]#

Generate a template configuration file with all parameters documented.

Parameters:

output_path (str | Path) – Where to write the template file. Default = “user_settings_template.yaml”

get_all_reaction_files() list[pathlib.Path][source]#

Get all reaction files (database + custom) as resolved paths.

Returns:

files – List of absolute paths to all reaction files

Return type:

list[Path]

get_all_reaction_types() list[ReactionFileTypes][source]#

Get all reaction types (database + custom) in correct order.

Returns:

types – list of reaction type strings

Return type:

list[ReactionFileTypes]

log_configuration() None[source]#

Log the current configuration for debugging.

classmethod normalize_coolants_file(v: str | pathlib.Path | None) pathlib.Path | None[source]#

Normalize a single coolant file path to a Path object.

Parameters:

v (str | Path | None) – string to normalize

Returns:

Path instance, or None if v is None

Return type:

Path | None

Raises:

TypeError – If coolants_file is not a string or Path instance.

classmethod normalize_to_list(v: str | pathlib.Path | list | None) list[str | pathlib.Path] | None[source]#

Convert single values to lists for consistent handling.

Parameters:

v (str | Path | list | None) – variable to make consistent.

Returns:

list of strings or paths, or None if v is None

Return type:

list[str | Path] | None

classmethod normalize_type_to_list(v: str | list[str] | None) list[str] | None[source]#

Convert single type strings to lists for consistent handling.

Parameters:

v (str | list[str] | None) – variable to convert to list

Returns:

v – list of string, or None if original v is None

Return type:

list[str] | None

classmethod print_help()[source]#

Print detailed help about all configuration parameters.

resolve_path(path: str | pathlib.Path) pathlib.Path[source]#

Resolve a path relative to the configuration file directory.

Parameters:

path (str | Path) – Path to resolve (can be absolute or relative)

Returns:

Resolved absolute Path

Return type:

Path

classmethod validate_coolants(v: list[dict[str, str]] | None) list[dict[str, str | float]] | None[source]#

Validate inline coolants format.

Parameters:

v (list[dict[str, str]] | None) – variable to make consistent

Returns:

validated – list of validated coolant dictionaries

Return type:

list[dict[str, str | float]] | None

Raises:
  • TypeError – If v is not a list of dictionaries.

  • KeyError – If entries in v do not contain keys ‘file’ and ‘name’

  • ValueError – If entries in v with keys ‘file’ are not bare file names.

validate_coolants_mutual_exclusion() MakeratesConfig[source]#

Ensure coolants and coolants_file are mutually exclusive.

Returns:

validated MakeratesConfig.

Return type:

MakeratesConfig

Raises:

ValueError – If both coolants and coolants_file are specified.

validate_reaction_files_and_types() MakeratesConfig[source]#

Ensure reaction files and types are consistent.

Returns:

validated MakeratesConfig.

Return type:

MakeratesConfig

Raises:
  • ValueError – If the length of reaction files and reaction file types is not the same

  • ValueError – If custom_reaction_type is not specified but custom_reaction_file is.

add_crp_photo_to_grain: bool = None[source]#
coolant_data_dir: pathlib.Path | None = None[source]#
coolants: list[dict] | None = None[source]#
coolants_file: pathlib.Path | None = None[source]#
custom_reaction_file: pathlib.Path | list[pathlib.Path] | None = None[source]#
custom_reaction_type: ReactionFileTypes | list[ReactionFileTypes] | None = None[source]#
database_reaction_exothermicity: list[pathlib.Path] | None = None[source]#
database_reaction_file: pathlib.Path | list[pathlib.Path] = None[source]#
database_reaction_type: ReactionFileTypes | list[ReactionFileTypes] = None[source]#
derive_reaction_exothermicity: bool | str | list[str] = None[source]#
enable_rates_storage: bool = None[source]#
gas_phase_extrapolation: bool = None[source]#
grain_assisted_recombination_file: pathlib.Path | None = None[source]#
model_config[source]#

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

output_directory: pathlib.Path | None = None[source]#
species_file: pathlib.Path = None[source]#
three_phase: bool = None[source]#
uclchem.makerates.config.ReactionFileTypes[source]#
uclchem.makerates.config.logger[source]#