egqca 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
egqca/__init__.py ADDED
@@ -0,0 +1,77 @@
1
+ from ._banner import __version__
2
+ from .egqca_model import EGQCA
3
+ from .io import convert_volume_file
4
+ from .workflow import (
5
+ create_bands_in,
6
+ create_phonons_in,
7
+ extract_total_energies,
8
+ set_up_clusters_and_dft,
9
+ set_up_clusters_dat,
10
+ set_up_volume_dat,
11
+ get_directories,
12
+ update_DFT_in,
13
+ write_properties_file,
14
+ extract_eddp_energies,
15
+ )
16
+ from .comparison import (
17
+ EGQCAInput,
18
+ discover_egqca_inputs,
19
+ make_egqca_inputs,
20
+ plot_average_properties_comparison,
21
+ plot_excess_enthalpy_comparison,
22
+ plot_miscibility_gap_comparison,
23
+ plot_occurrence_probabilities_comparison,
24
+ plot_occurrence_probability_difference_from_ideal,
25
+ plot_thermodynamic_comparison,
26
+ run_egqca_comparison,
27
+ )
28
+
29
+ try:
30
+ from .ml import (
31
+ geometry_relaxation,
32
+ run_ml_relaxation,
33
+ collect_ml_results,
34
+ reset_ml_clusters,
35
+ rerun_nonconverged_ml,
36
+ phonon_dos_from_cache,
37
+ )
38
+ except ImportError: # optional ML stack
39
+ geometry_relaxation = None
40
+ run_ml_relaxation = None
41
+ collect_ml_results = None
42
+ reset_ml_clusters = None
43
+ rerun_nonconverged_ml = None
44
+ phonon_dos_from_cache = None
45
+
46
+
47
+ __all__ = [
48
+ "__version__",
49
+ "EGQCA",
50
+ "convert_volume_file",
51
+ "set_up_clusters_and_dft",
52
+ "run_ml_relaxation",
53
+ "collect_ml_results",
54
+ "reset_ml_clusters",
55
+ "rerun_nonconverged_ml",
56
+ "extract_total_energies",
57
+ "create_bands_in",
58
+ "create_phonons_in",
59
+ "set_up_clusters_dat",
60
+ "set_up_volume_dat",
61
+ "get_directories",
62
+ "update_DFT_in",
63
+ "write_properties_file",
64
+ "extract_eddp_energies",
65
+ "geometry_relaxation",
66
+ "phonon_dos_from_cache",
67
+ "EGQCAInput",
68
+ "discover_egqca_inputs",
69
+ "make_egqca_inputs",
70
+ "run_egqca_comparison",
71
+ "plot_thermodynamic_comparison",
72
+ "plot_excess_enthalpy_comparison",
73
+ "plot_miscibility_gap_comparison",
74
+ "plot_occurrence_probabilities_comparison",
75
+ "plot_occurrence_probability_difference_from_ideal",
76
+ "plot_average_properties_comparison",
77
+ ]
egqca/_banner.py ADDED
@@ -0,0 +1,109 @@
1
+ """Start-up banner and input summary printed by the main egqca entry points."""
2
+ from __future__ import annotations
3
+
4
+ import functools
5
+ import inspect
6
+ import threading
7
+ from collections.abc import Callable, Iterable
8
+ from datetime import datetime
9
+ from pathlib import Path
10
+
11
+ LOGO = r"""
12
+ _____ ____ ___ ____ _
13
+ | ____/ ___|/ _ \ / ___|/ \
14
+ | _|| | _| | | | | / _ \
15
+ | |__| |_| | |_| | |__/ ___ \
16
+ |_____\____|\__\_\\__/_/ \_\
17
+ """
18
+ TITLE = "Extended Generalized Quasichemical Approximation"
19
+ #AUTHORS = "Pedro Nunes Ferreira, Dominik Spath, Luka Wibmer"
20
+
21
+
22
+ def _get_version() -> str:
23
+ try:
24
+ from importlib.metadata import PackageNotFoundError, version
25
+ return version("egqca")
26
+ except PackageNotFoundError:
27
+ pass
28
+ # not installed, e.g. run from the source tree: read pyproject.toml
29
+ pyproject = Path(__file__).resolve().parents[2] / "pyproject.toml"
30
+ try:
31
+ import tomllib
32
+ with open(pyproject, "rb") as f:
33
+ return tomllib.load(f)["project"]["version"]
34
+ except (OSError, KeyError, ImportError, ValueError):
35
+ return "unknown"
36
+
37
+
38
+ __version__ = _get_version()
39
+
40
+ _depth = threading.local()
41
+
42
+
43
+ def header_lines() -> list[str]:
44
+ return [LOGO.strip("\n"), "", f" {TITLE}", #f" Authors: {AUTHORS}"
45
+ f" Version: {__version__}"]
46
+
47
+
48
+ def format_summary(task: str, items: Iterable[tuple[str, object]]) -> list[str]:
49
+ items = [(k, v) for k, v in items if v is not None]
50
+ width = max((len(k) for k, _ in items), default=0)
51
+ lines = [f" {task} ({datetime.now():%Y-%m-%d %H:%M:%S})", " " + "-" * 60]
52
+ lines += [f" {k:<{width}} : {v}" for k, v in items]
53
+ return lines
54
+
55
+
56
+ def print_banner(task: str, items: Iterable[tuple[str, object]]) -> list[str]:
57
+ """Print logo, authors, version and the input summary; return the summary lines."""
58
+ summary = format_summary(task, items)
59
+ print("\n".join(header_lines() + [""] + summary + [""]), flush=True)
60
+ return summary
61
+
62
+
63
+ def describe_grid(values, unit: str = "") -> str | None:
64
+ """Short description of a 1D grid: 'min ... max (N points)'."""
65
+ if values is None:
66
+ return None
67
+ import numpy as np
68
+ arr = np.asarray(values, dtype=float).ravel()
69
+ if arr.size == 0:
70
+ return "empty"
71
+ if arr.size <= 8:
72
+ return ", ".join(f"{v:g}" for v in arr) + (f" {unit}" if unit else "")
73
+ return f"{arr.min():g} ... {arr.max():g}{(' ' + unit) if unit else ''} ({arr.size} points)"
74
+
75
+
76
+ def entry_point(task: str, summary: Callable[[inspect.BoundArguments], Iterable[tuple[str, object]]] | Iterable[str]):
77
+ """Decorator printing the banner and an input summary when ``func`` is called.
78
+
79
+ ``summary`` is either a list of argument names to show, or a function that
80
+ takes the bound call arguments and returns ``(label, value)`` pairs. Calls
81
+ made from inside another entry point print nothing, so a workflow prints
82
+ its banner once.
83
+ """
84
+
85
+ def decorator(func):
86
+ signature = inspect.signature(func)
87
+
88
+ @functools.wraps(func)
89
+ def wrapper(*args, **kwargs):
90
+ depth = getattr(_depth, "value", 0)
91
+ if depth == 0:
92
+ bound = signature.bind(*args, **kwargs)
93
+ bound.apply_defaults()
94
+ if callable(summary):
95
+ # may replace arguments, e.g. turn an iterator into a list it can read twice
96
+ items = list(summary(bound))
97
+ else:
98
+ items = [(name, bound.arguments[name]) for name in summary]
99
+ print_banner(task, items)
100
+ args, kwargs = bound.args, bound.kwargs
101
+ _depth.value = depth + 1
102
+ try:
103
+ return func(*args, **kwargs)
104
+ finally:
105
+ _depth.value = depth
106
+
107
+ return wrapper
108
+
109
+ return decorator