Skip to content

Config utilities

BaseConfig dataclass

BaseConfig(
    verbose: int = 0,
    log_dir: Path | str = "",
    log_mode: str = "w",
)

Base dataclass for parameter file generation configuration.

get_checked_and_derived_config

get_checked_and_derived_config() -> BaseConfig

Performs checks and populates derived fields, including setting up logging.

Source code in tinkertool/utils/config_utils.py
168
169
170
171
172
173
174
175
176
177
178
179
def get_checked_and_derived_config(self) -> 'BaseConfig':
    """Performs checks and populates derived fields, including setting up logging."""
    if self.log_file is not None: # Already run
        return self

    time_str = time.strftime("%Y%m%d-%H%M%S")
    self.log_file = Path(self.log_dir).joinpath(f'tinkertool_{time_str}.log')

    if self.log_mode != 'o' and not logging.getLogger('tinkertool_log').handlers:
        setup_logging(self.verbose, self.log_file, self.log_mode, 'tinkertool_log')

    return self

CheckedBaseConfig dataclass

CheckedBaseConfig(
    verbose: int = 0,
    log_dir: Path | str = "",
    log_mode: str = "w",
    *,
    log_file: Path = (
        lambda: joinpath(
            "output",
            f"tinkertool.{strftime('%Y%m%d-%H%M%S')}.log",
        )
    )(),
)

Bases: BaseConfig

BaseConfig subclass that performs argument checking in post_init.

add_config_helpers

add_config_helpers(cls: Type[TypeVarT]) -> Type[TypeVarT]

Decorator to add CLI/config helper methods to a dataclass.

Source code in tinkertool/utils/config_utils.py
19
20
21
22
23
24
25
def add_config_helpers(cls: Type[TypeVarT]) -> Type[TypeVarT]:
    """Decorator to add CLI/config helper methods to a dataclass."""
    # Use type: ignore to suppress Pylance warnings about dynamic attribute assignment
    cls.help = classmethod(_help)  # type: ignore
    cls.from_cli = classmethod(_from_cli)  # type: ignore
    cls.describe = _describe  # type: ignore
    return cls