Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Site Multiplicities to Structure Specific Metadata #248

Merged
merged 5 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,4 @@ dmypy.json

# Cython debug symbols
cython_debug/
.vscode/settings.json
44 changes: 44 additions & 0 deletions lightshow/_tests/test_metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import json
from pathlib import Path

from lightshow.parameters.feff import FEFFParameters


def test_multiplicipty_writing(database_from_file, tmp_path):
target = Path(tmp_path) / Path("multi") / Path("destination")
target.mkdir(exist_ok=True, parents=True)
R = 10.0
feff_parameters = FEFFParameters(
cards={
"S02": "0",
"COREHOLE": "RPA",
"CONTROL": "1 1 1 1 1 1",
"XANES": "4 0.04 0.1",
"SCF": "7.0 0 100 0.2 3",
"FMS": "9.0 0",
"EXCHANGE": "0 0.0 0.0 2",
"RPATH": "-1",
},
edge="K",
radius=R - 1.0,
spectrum="XANES",
name="FEFF",
)
database_from_file.write(
target,
absorbing_atoms="all",
options=[feff_parameters],
write_unit_cells=True,
pbar=False,
)
for k, v in database_from_file.metadata.items():
metadata_fn = target / Path(k) / Path("metadata.json")
with open(metadata_fn) as f:
d_metadata = json.load(f)
prim_meta = v["primitive"]
for i_site, n_multi in zip(
prim_meta["sites"], prim_meta["multiplicities"]
):
i_site = str(i_site)
assert "multiplicities" in d_metadata
assert d_metadata["multiplicities"][i_site] == n_multi
8 changes: 8 additions & 0 deletions lightshow/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,14 @@ def _write_origin_paths(self, root, pbar=False):
fname = Path(root) / key / "metadata.json"
origin = str(Path(metadata["origin"]).resolve())
new_metadata = {"origin": origin}
multiplicities = {
i_site: n_multi
for i_site, n_multi in zip(
metadata["primitive"]["sites"],
metadata["primitive"]["multiplicities"],
)
}
new_metadata["multiplicities"] = multiplicities
with open(fname, "w") as outfile:
json.dump(new_metadata, outfile, indent=4, sort_keys=True)

Expand Down
Loading