From 404156f689c8d65bcebca256b7d0d4095d15cf13 Mon Sep 17 00:00:00 2001 From: Xiaohui Qu Date: Tue, 27 Feb 2024 15:13:08 -0500 Subject: [PATCH 1/4] exclude vscode configure folder from git --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 9c843406..378663f5 100644 --- a/.gitignore +++ b/.gitignore @@ -144,3 +144,4 @@ dmypy.json # Cython debug symbols cython_debug/ +.vscode/settings.json From e2c06e831a8310950b2e0714bfdd16150834f511 Mon Sep 17 00:00:00 2001 From: Xiaohui Qu Date: Tue, 27 Feb 2024 16:56:24 -0500 Subject: [PATCH 2/4] add unittest requiring multiplicity in metadata.json --- lightshow/_tests/test_metadata.py | 39 +++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 lightshow/_tests/test_metadata.py diff --git a/lightshow/_tests/test_metadata.py b/lightshow/_tests/test_metadata.py new file mode 100644 index 00000000..36aaf5d5 --- /dev/null +++ b/lightshow/_tests/test_metadata.py @@ -0,0 +1,39 @@ +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, + ) + metadata_fn = target / Path("00000002") / Path("metadata.json") + with open(metadata_fn) as f: + d_metadata = json.load(f) + assert "multiplicities" in d_metadata + i_site, n_multi = 2, 4 + assert d_metadata[i_site] == n_multi From 4378a85b9021314a930878e7ce47773616277c46 Mon Sep 17 00:00:00 2001 From: Xiaohui Qu Date: Tue, 27 Feb 2024 17:15:55 -0500 Subject: [PATCH 3/4] implement multiplicity writing --- lightshow/_tests/test_metadata.py | 4 ++-- lightshow/database.py | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lightshow/_tests/test_metadata.py b/lightshow/_tests/test_metadata.py index 36aaf5d5..823eaec7 100644 --- a/lightshow/_tests/test_metadata.py +++ b/lightshow/_tests/test_metadata.py @@ -35,5 +35,5 @@ def test_multiplicipty_writing(database_from_file, tmp_path): with open(metadata_fn) as f: d_metadata = json.load(f) assert "multiplicities" in d_metadata - i_site, n_multi = 2, 4 - assert d_metadata[i_site] == n_multi + i_site, n_multi = "2", 4 + assert d_metadata["multiplicities"][i_site] == n_multi diff --git a/lightshow/database.py b/lightshow/database.py index 52a32221..00f6ed59 100644 --- a/lightshow/database.py +++ b/lightshow/database.py @@ -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) From f6b6cdd8fde279ac514b8bb5f9a965066e208a82 Mon Sep 17 00:00:00 2001 From: Xiaohui Qu Date: Wed, 28 Feb 2024 13:46:40 -0500 Subject: [PATCH 4/4] read fold name form Database.metadata to gaurantee the same structure in unittest --- lightshow/_tests/test_metadata.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/lightshow/_tests/test_metadata.py b/lightshow/_tests/test_metadata.py index 823eaec7..2ed537f0 100644 --- a/lightshow/_tests/test_metadata.py +++ b/lightshow/_tests/test_metadata.py @@ -31,9 +31,14 @@ def test_multiplicipty_writing(database_from_file, tmp_path): write_unit_cells=True, pbar=False, ) - metadata_fn = target / Path("00000002") / Path("metadata.json") - with open(metadata_fn) as f: - d_metadata = json.load(f) - assert "multiplicities" in d_metadata - i_site, n_multi = "2", 4 - assert d_metadata["multiplicities"][i_site] == n_multi + 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