Config¶
Layered configuration for the engines and wrappers, built on molcfg.
Quick reference¶
| Symbol | Summary | Preferred for |
|---|---|---|
load_config |
Merge the four layers (defaults → user → project → run), validate, freeze |
Getting the config an engine or wrapper runs with |
tool_settings |
One tool's resolved settings, each with the layer and key it came from | Inspecting what a tool will run |
ToolSettings |
executable, env, env_manager, conda_executable, launcher, env_vars, timeout, sources |
Reading resolved settings |
user_config_path |
~/.molcrafts/molpy/config/config.toml (MOLCRAFTS_HOME moves it) |
Finding the user layer's file |
PROJECT_CONFIG_NAME |
molpy.toml, the project layer's file name |
Finding the project layer's file |
LAYERS |
("defaults", "user", "project", "run") |
Naming a layer |
DEFAULTS |
The package defaults (the defaults layer) |
Seeing what an unset key means |
Canonical example¶
from molpy.config import load_config, tool_settings
config = load_config({"engine": {"lammps": {"launcher": ["srun", "-n", "4"]}}})
settings = tool_settings(config, "engine.lammps")
print(settings.launcher) # ('srun', '-n', '4')
print(settings.sources["launcher"]) # ('run', 'engine.lammps.launcher')
print(settings.sources["env"]) # ('defaults', 'engine.env') unless a file sets it
Key behavior¶
- Tables:
[conda](executable),[engine]and[engine.<name>]forlammps,gromacs,openmm,cp2k;[wrapper]and[wrapper.<name>]forantechamber,tleap,parmchk2,prepgen,sander - Keys:
executable,env,env_manager("conda"/"venv"),env_vars,timeout(seconds) and, for engines,launcher; a group table holds what its tools share, a tool's own key replaces the group's - Later layers win key by key; tables such as
env_varsmerge across layers, lists such aslauncherare replaced - An unknown key or a wrong type is refused when the config loads, naming the key and the files read; the loaded config is frozen
- Loading and resolving log to
molpy.config(DEBUG)
Related¶
Full API¶
load_config ¶
Resolve molpy's configuration through its four layers.
Later layers win key by key (molcfg's deep merge): defaults, then
user (:func:user_config_path, when the file exists), then
project (molpy.toml in project_dir, when it exists), then
run (overrides). The merged result is validated against the schema
in this module's docstring and frozen.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
overrides
|
Mapping[str, Any] | None
|
The |
None
|
project_dir
|
str | Path | None
|
Where |
None
|
environ
|
Mapping[str, str] | None
|
The environment the user config directory is resolved in;
|
None
|
Returns:
| Type | Description |
|---|---|
Config
|
The frozen :class: |
Config
|
names the layer a value came from. |
Raises:
| Type | Description |
|---|---|
ValidationError
|
A layer sets an unknown key or a value of the wrong type. The message names the offending keys. |
tool_settings ¶
Resolve the settings of tool ("engine.lammps", "wrapper.tleap").
Each setting is the tool's own key when a layer set it, else its group's
(engine.<key> / wrapper.<key>); :attr:ToolSettings.sources
records which, and from which layer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config
|
A config from :func: |
required |
tool
|
str
|
|
required |
Raises:
| Type | Description |
|---|---|
KeyError
|
tool is not a known engine or wrapper. |
ValueError
|
A |
ToolSettings
dataclass
¶
ToolSettings(
tool,
executable,
env,
env_manager,
conda_executable,
launcher=(),
env_vars=dict(),
timeout=None,
sources=dict(),
)
What one engine or wrapper runs with, resolved from a config.
Attributes:
| Name | Type | Description |
|---|---|---|
tool |
str
|
The tool's table, |
executable |
str | None
|
The program to run (a name looked up in the
environment, or a path); |
env |
str | None
|
Conda env name / prefix, or venv prefix; |
env_manager |
Literal['conda', 'venv'] | None
|
|
conda_executable |
str
|
The |
launcher |
tuple[str, ...]
|
MPI / scheduler prefix before the executable (engines only; empty for wrappers). |
env_vars |
Mapping[str, str]
|
Environment variables set for the subprocess. |
timeout |
float | None
|
Seconds before the subprocess is killed; |
sources |
Mapping[str, tuple[str, str]]
|
Setting name → |
user_config_path ¶
The user layer's file: ~/.molcrafts/molpy/config/config.toml.
The directory is :func:molcfg.project_config_dir ("molpy"), which
honours MOLCRAFTS_HOME and creates the directory; the file itself may
not exist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
environ
|
Mapping[str, str] | None
|
The environment to resolve |
None
|