md-exafs 0.2.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.
- md_exafs/__init__.py +56 -0
- md_exafs/__main__.py +7 -0
- md_exafs/cache_utils.py +84 -0
- md_exafs/cli.py +2450 -0
- md_exafs/constants.py +21 -0
- md_exafs/debye_waller.py +2808 -0
- md_exafs/debye_waller_core.py +7 -0
- md_exafs/exafs_data.py +2619 -0
- md_exafs/execution.py +466 -0
- md_exafs/experimental.py +168 -0
- md_exafs/feff_configs/nscf.yaml +28 -0
- md_exafs/feff_configs/publication.yaml +26 -0
- md_exafs/feff_configs/quick.yaml +25 -0
- md_exafs/feff_input.py +464 -0
- md_exafs/feff_utils.py +1595 -0
- md_exafs/hdf5.py +568 -0
- md_exafs/hdf5_store.py +1632 -0
- md_exafs/marimo_utils.py +72 -0
- md_exafs/paths.py +384 -0
- md_exafs/pipeline.py +1494 -0
- md_exafs/potentials.py +201 -0
- md_exafs/py.typed +0 -0
- md_exafs/selection.py +234 -0
- md_exafs/spectra.py +171 -0
- md_exafs/styles/__init__.py +20 -0
- md_exafs/styles/exafs_presentation.mplstyle +64 -0
- md_exafs/styles/exafs_publication.mplstyle +66 -0
- md_exafs/viz.py +187 -0
- md_exafs-0.2.0.dist-info/METADATA +274 -0
- md_exafs-0.2.0.dist-info/RECORD +33 -0
- md_exafs-0.2.0.dist-info/WHEEL +4 -0
- md_exafs-0.2.0.dist-info/entry_points.txt +4 -0
- md_exafs-0.2.0.dist-info/licenses/LICENSE +28 -0
md_exafs/__init__.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"""MD-EXAFS Core Engine - Trajectory analysis and path-resolved EXAFS reconstruction."""
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
from .constants import ETOK, HBAR2_OVER_2M_EV_ANGSTROM2
|
|
6
|
+
from .exafs_data import PathAggregator, PathContribution
|
|
7
|
+
from .feff_input import FeffConfig, build_feff_inp, normalize_tag
|
|
8
|
+
from .hdf5 import (
|
|
9
|
+
ArchiveReader,
|
|
10
|
+
BatchShardReader,
|
|
11
|
+
BatchShardWriter,
|
|
12
|
+
EnsembleReader,
|
|
13
|
+
EnsembleWriter,
|
|
14
|
+
ExafsHDF5Store,
|
|
15
|
+
)
|
|
16
|
+
from .paths import PathResult, make_path_key, path_chi
|
|
17
|
+
from .potentials import PotentialsManager
|
|
18
|
+
from .selection import (
|
|
19
|
+
parse_frame_slice,
|
|
20
|
+
resolve_frame_absorbers,
|
|
21
|
+
resolve_trajectory_absorbers,
|
|
22
|
+
)
|
|
23
|
+
from .spectra import average_chi_arrays, format_chi_ascii, xftf_arrays
|
|
24
|
+
|
|
25
|
+
__version__ = "0.2.0"
|
|
26
|
+
|
|
27
|
+
# Default cache directory for FEFF calculations and results
|
|
28
|
+
DEFAULT_CACHE_DIR = Path.home() / ".larch_cache"
|
|
29
|
+
|
|
30
|
+
__all__ = [
|
|
31
|
+
"__version__",
|
|
32
|
+
"DEFAULT_CACHE_DIR",
|
|
33
|
+
"HBAR2_OVER_2M_EV_ANGSTROM2",
|
|
34
|
+
"ETOK",
|
|
35
|
+
"FeffConfig",
|
|
36
|
+
"build_feff_inp",
|
|
37
|
+
"normalize_tag",
|
|
38
|
+
"PathResult",
|
|
39
|
+
"path_chi",
|
|
40
|
+
"make_path_key",
|
|
41
|
+
"xftf_arrays",
|
|
42
|
+
"average_chi_arrays",
|
|
43
|
+
"format_chi_ascii",
|
|
44
|
+
"resolve_frame_absorbers",
|
|
45
|
+
"resolve_trajectory_absorbers",
|
|
46
|
+
"parse_frame_slice",
|
|
47
|
+
"PotentialsManager",
|
|
48
|
+
"BatchShardWriter",
|
|
49
|
+
"BatchShardReader",
|
|
50
|
+
"EnsembleWriter",
|
|
51
|
+
"EnsembleReader",
|
|
52
|
+
"ArchiveReader",
|
|
53
|
+
"ExafsHDF5Store",
|
|
54
|
+
"PathAggregator",
|
|
55
|
+
"PathContribution",
|
|
56
|
+
]
|
md_exafs/__main__.py
ADDED
md_exafs/cache_utils.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"""Cache utilities for EXAFS processing pipeline."""
|
|
2
|
+
|
|
3
|
+
import hashlib
|
|
4
|
+
import pickle
|
|
5
|
+
import warnings
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from ase import Atoms
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def get_structure_hash(atoms: Atoms) -> str:
|
|
13
|
+
"""Generate a hash for atomic structure for caching purposes."""
|
|
14
|
+
return hashlib.md5( # noqa: S324
|
|
15
|
+
str(atoms.get_positions()).encode() + str(atoms.get_chemical_symbols()).encode()
|
|
16
|
+
).hexdigest()[:16]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def load_from_cache(
|
|
20
|
+
cache_key: str, cache_dir: str | Path | None, force_recalculate: bool = False
|
|
21
|
+
) -> tuple[Any, Any] | None:
|
|
22
|
+
"""Load cached results if available and not forcing recalculation.
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
cache_key: Unique identifier for the cached data
|
|
26
|
+
cache_dir: Directory where cache files are stored
|
|
27
|
+
force_recalculate: If True, ignore existing cache and return None
|
|
28
|
+
|
|
29
|
+
Returns:
|
|
30
|
+
Tuple of (k, chi) arrays if cache hit, None if cache miss or error
|
|
31
|
+
|
|
32
|
+
Note:
|
|
33
|
+
The returned chi array is complex (EXAFS chi(k) data) and k array
|
|
34
|
+
is real-valued k-space values.
|
|
35
|
+
"""
|
|
36
|
+
if not cache_dir:
|
|
37
|
+
return None
|
|
38
|
+
cache_file = Path(cache_dir) / f"{cache_key}.pkl"
|
|
39
|
+
if cache_file.exists() and not force_recalculate:
|
|
40
|
+
try:
|
|
41
|
+
with open(cache_file, "rb") as f:
|
|
42
|
+
cached_data = pickle.load(f) # noqa: S301 - controlled usage
|
|
43
|
+
return cached_data["k"], cached_data["chi"]
|
|
44
|
+
except (EOFError, pickle.UnpicklingError, KeyError):
|
|
45
|
+
try:
|
|
46
|
+
cache_file.unlink()
|
|
47
|
+
except OSError:
|
|
48
|
+
# If we can't delete the cache file, just let the user know
|
|
49
|
+
warnings.warn(
|
|
50
|
+
f"Failed to delete cache file {cache_file}",
|
|
51
|
+
UserWarning,
|
|
52
|
+
stacklevel=2,
|
|
53
|
+
)
|
|
54
|
+
return None
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def save_to_cache(
|
|
58
|
+
cache_key: str, chi: Any, k: Any, cache_dir: str | Path | None
|
|
59
|
+
) -> None:
|
|
60
|
+
"""Save processing results to cache for future use.
|
|
61
|
+
|
|
62
|
+
Args:
|
|
63
|
+
cache_key: Unique identifier for the cached data
|
|
64
|
+
chi: EXAFS chi(k) data (complex numpy array)
|
|
65
|
+
k: k-space values (real numpy array)
|
|
66
|
+
cache_dir: Directory where cache files are stored
|
|
67
|
+
|
|
68
|
+
Note:
|
|
69
|
+
Always stores complex chi data directly. Silently continues on cache
|
|
70
|
+
write failures with a warning.
|
|
71
|
+
"""
|
|
72
|
+
if not cache_dir:
|
|
73
|
+
return
|
|
74
|
+
cache_file = Path(cache_dir) / f"{cache_key}.pkl"
|
|
75
|
+
cache_file.parent.mkdir(parents=True, exist_ok=True)
|
|
76
|
+
cached_data = {"chi": chi, "k": k}
|
|
77
|
+
try:
|
|
78
|
+
with open(cache_file, "wb") as f:
|
|
79
|
+
pickle.dump(cached_data, f)
|
|
80
|
+
except OSError:
|
|
81
|
+
# If we can't write to cache, continue without caching but inform the user
|
|
82
|
+
warnings.warn(
|
|
83
|
+
f"Failed to write cache file {cache_file}", UserWarning, stacklevel=2
|
|
84
|
+
)
|