hklforge 0.2.2__tar.gz → 0.2.3__tar.gz
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.
- {hklforge-0.2.2 → hklforge-0.2.3}/PKG-INFO +1 -1
- {hklforge-0.2.2 → hklforge-0.2.3}/src/hklforge/crystal/spacegroups.py +25 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/src/hklforge/crystal/structure.py +30 -1
- {hklforge-0.2.2 → hklforge-0.2.3}/src/hklforge/view/viewer.html +3 -1
- {hklforge-0.2.2 → hklforge-0.2.3}/src/hklforge.egg-info/PKG-INFO +1 -1
- {hklforge-0.2.2 → hklforge-0.2.3}/src/hklforge.egg-info/scm_version.json +2 -2
- {hklforge-0.2.2 → hklforge-0.2.3}/tests/test_crystal.py +43 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/.githooks/pre-push +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/.github/workflows/ci.yml +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/.github/workflows/publish.yml +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/.gitignore +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/.vscode/settings.json +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/CLAUDE.md +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/LICENSE +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/README.md +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/dev/build_notebooks.py +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/dev/cdp.py +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/dev/check_naz_scan.py +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/dev/check_viewer.py +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/dev/conda-forge/recipe.yaml +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/dev/conda-forge/run_test.py +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/dev/diffcalc_stats.py +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/dev/make_spacegroup_table.py +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/dev/reference/bernina_two_reflections.py +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/dev/reference/check_two_reflections_vs_diffcalc.py +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/dev/reference/compare_ad_hoc_psic.py +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/dev/reference/compare_libhkl_builtins.py +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/dev/reference/compare_libhkl_e6c.py +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/dev/reference/compare_libhkl_planner.py +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/docs/README.md +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/docs/crystallography.md +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/docs/figures/azimuths.png +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/docs/figures/omega.png +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/docs/figures/psi.png +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/docs/figures/psic_circles.png +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/docs/figures/reference_angles.png +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/docs/figures/scattering.png +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/docs/figures/surface_angles.png +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/docs/figures/tau.png +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/docs/make_figures.py +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/docs/modes.md +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/docs/releasing.md +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/docs/verification.md +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/docs/viewer.md +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/docs/virtual_angles.md +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/examples/01_quickstart.ipynb +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/examples/02_virtual_angles.ipynb +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/examples/03_diffcalc_comparison.ipynb +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/examples/04_double_diffraction.ipynb +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/examples/05_custom_geometries.ipynb +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/examples/06_crystallography_planning.ipynb +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/pyproject.toml +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/setup.cfg +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/src/hklforge/__init__.py +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/src/hklforge/crystal/__init__.py +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/src/hklforge/crystal/bz.py +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/src/hklforge/crystal/cell.py +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/src/hklforge/crystal/cif.py +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/src/hklforge/crystal/reflections.py +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/src/hklforge/crystal/spacegroups.json +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/src/hklforge/draw.py +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/src/hklforge/geometries/__init__.py +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/src/hklforge/geometries/e4ch.yml +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/src/hklforge/geometries/fourcv.yml +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/src/hklforge/geometries/k4cv.yml +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/src/hklforge/geometries/k6c.yml +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/src/hklforge/geometries/psic.yml +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/src/hklforge/geometry.py +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/src/hklforge/lattice.py +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/src/hklforge/orient.py +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/src/hklforge/rotation.py +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/src/hklforge/solve.py +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/src/hklforge/view/__init__.py +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/src/hklforge/view/explorer.py +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/src/hklforge/virtual.py +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/src/hklforge.egg-info/SOURCES.txt +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/src/hklforge.egg-info/dependency_links.txt +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/src/hklforge.egg-info/requires.txt +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/src/hklforge.egg-info/scm_file_list.json +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/src/hklforge.egg-info/top_level.txt +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/tests/data/Bi2Se3.cif +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/tests/data/GaAs.cif +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/tests/data/TiO2_rutile.cif +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/tests/test_builtins.py +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/tests/test_bz.py +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/tests/test_double.py +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/tests/test_energy.py +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/tests/test_forward.py +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/tests/test_frame.py +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/tests/test_orient.py +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/tests/test_rotation.py +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/tests/test_solve_diffcalc.py +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/tests/test_solve_generic.py +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/tests/test_view.py +0 -0
- {hklforge-0.2.2 → hklforge-0.2.3}/tests/test_virtual.py +0 -0
|
@@ -66,6 +66,31 @@ def parse_triplet(text: str):
|
|
|
66
66
|
return R, t
|
|
67
67
|
|
|
68
68
|
|
|
69
|
+
def format_triplet(R, t) -> str:
|
|
70
|
+
"""(R, t) -> 'x,y,z' triplet, e.g. '-y+1/4,x+1/4,z+1/4' (``parse_triplet``'s inverse)."""
|
|
71
|
+
parts = []
|
|
72
|
+
for i in range(3):
|
|
73
|
+
terms = ""
|
|
74
|
+
for j, var in enumerate("xyz"):
|
|
75
|
+
c = int(round(R[i][j]))
|
|
76
|
+
if c:
|
|
77
|
+
terms += ("-" if c < 0 else "+" if terms else "") + (f"{abs(c)}*" if abs(c) != 1 else "") + var
|
|
78
|
+
f = Fraction(float(t[i])).limit_denominator(48)
|
|
79
|
+
if f:
|
|
80
|
+
terms += ("-" if f < 0 else "+" if terms else "") + str(abs(f))
|
|
81
|
+
parts.append(terms or "0")
|
|
82
|
+
return ",".join(parts)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def same_ops(a, b) -> bool:
|
|
86
|
+
"""Whether two lists of (R, t) are the same set of operations (t modulo 1)."""
|
|
87
|
+
def key(op):
|
|
88
|
+
R, t = op
|
|
89
|
+
return (tuple(int(round(x)) for x in np.ravel(R)),
|
|
90
|
+
tuple(int(round((float(x) % 1.0) * 48)) % 48 for x in t))
|
|
91
|
+
return len(a) == len(b) and {key(o) for o in a} == {key(o) for o in b}
|
|
92
|
+
|
|
93
|
+
|
|
69
94
|
def _reduced(v) -> tuple:
|
|
70
95
|
v = [int(round(x)) for x in v]
|
|
71
96
|
g = 0
|
|
@@ -24,7 +24,7 @@ import numpy as np
|
|
|
24
24
|
|
|
25
25
|
from . import cif
|
|
26
26
|
from .cell import AVOGADRO, b_matrix, cell_tuple, volume
|
|
27
|
-
from .spacegroups import SpaceGroup, parse_triplet
|
|
27
|
+
from .spacegroups import SpaceGroup, format_triplet, parse_triplet, same_ops
|
|
28
28
|
|
|
29
29
|
try:
|
|
30
30
|
import xraydb
|
|
@@ -59,6 +59,35 @@ class Structure:
|
|
|
59
59
|
raise ValueError("a structure needs a space group or its symmetry operations")
|
|
60
60
|
self.ops = self.space_group.all_ops()
|
|
61
61
|
|
|
62
|
+
# --- as plain data (JSON) ---
|
|
63
|
+
|
|
64
|
+
def to_dict(self) -> dict:
|
|
65
|
+
"""Everything needed to rebuild it (``from_dict``), as JSON-ready data:
|
|
66
|
+
name, cell, space group name, the sites as
|
|
67
|
+
``[label, element, scatterer, x, y, z, occupancy, b_iso]`` and, only
|
|
68
|
+
when they are not the space group's own (a CIF's operations in another
|
|
69
|
+
setting, or no recognised space group), the symmetry operations as
|
|
70
|
+
'x,y,z' triplets."""
|
|
71
|
+
out = {"name": self.name, "cell": {k: float(v) for k, v in self.cell.items()},
|
|
72
|
+
"space_group": None if self.space_group is None else self.space_group.name,
|
|
73
|
+
"sites": [[s.label, s.element, s.scatterer, *(round(float(x), 6) for x in s.xyz),
|
|
74
|
+
round(float(s.occupancy), 6), round(float(s.b_iso), 6)] for s in self.sites]}
|
|
75
|
+
if self.space_group is None or not same_ops(self.ops, self.space_group.all_ops()):
|
|
76
|
+
out["ops"] = [format_triplet(R, t) for R, t in self.ops]
|
|
77
|
+
if self.notes:
|
|
78
|
+
out["notes"] = list(self.notes)
|
|
79
|
+
return out
|
|
80
|
+
|
|
81
|
+
@classmethod
|
|
82
|
+
def from_dict(cls, d: dict) -> "Structure":
|
|
83
|
+
"""The inverse of ``to_dict``."""
|
|
84
|
+
sg = SpaceGroup(d["space_group"]) if d.get("space_group") else None
|
|
85
|
+
ops = [parse_triplet(t) for t in d["ops"]] if d.get("ops") else None
|
|
86
|
+
sites = [Site(str(lab), str(el), str(scat), np.array([float(x), float(y), float(z)]),
|
|
87
|
+
float(occ), float(b)) for lab, el, scat, x, y, z, occ, b in d["sites"]]
|
|
88
|
+
return cls(str(d.get("name", "")), {k: float(v) for k, v in d["cell"].items()}, sg, sites, ops,
|
|
89
|
+
list(d.get("notes", [])))
|
|
90
|
+
|
|
62
91
|
# --- the unit cell ---
|
|
63
92
|
|
|
64
93
|
def atoms(self):
|
|
@@ -3367,7 +3367,7 @@ window.HKLFORGE_VIEW = Object.assign({"id": "diff3d", "storage": "hklforge-viewe
|
|
|
3367
3367
|
// AUTO_EVERY of work, before "start fresh" / a restore);
|
|
3368
3368
|
// PREF_KEY whether to remember at all ("0" = only explicit snapshots).
|
|
3369
3369
|
// The page talks back through a hidden text widget (class diff3d-state-in):
|
|
3370
|
-
// first {kind:"offer",
|
|
3370
|
+
// first {kind:"offer", ..., address: the app page's URL}, then {kind:"memory", ...} whenever the
|
|
3371
3371
|
// snapshots change. The app only starts sending autosaves after the offer,
|
|
3372
3372
|
// so its defaults never overwrite the stored state. The app's requests
|
|
3373
3373
|
// come as msg.memory.ops, numbered; each is done once.
|
|
@@ -3445,6 +3445,8 @@ window.HKLFORGE_VIEW = Object.assign({"id": "diff3d", "storage": "hklforge-viewe
|
|
|
3445
3445
|
if (!doc.querySelector("." + ID + "-state-in input")) return;
|
|
3446
3446
|
stateOffered = true;
|
|
3447
3447
|
const offer = Object.assign({ kind: "offer" }, memoryReport());
|
|
3448
|
+
// the address of the app's page: the app may take a state from it (a link)
|
|
3449
|
+
try { offer.address = String(doc.location.href); } catch (e) { /* not readable */ }
|
|
3448
3450
|
try {
|
|
3449
3451
|
const stored = remembering() ? lsGet(STATE_KEY) : null;
|
|
3450
3452
|
const rec = stored ? JSON.parse(stored) : null;
|
|
@@ -195,3 +195,46 @@ def test_equivalence_groups_and_columns():
|
|
|
195
195
|
assert list(cols["allowed"]) == [True, True, False]
|
|
196
196
|
assert cols["why not"][1] == "allowed by symmetry, F = 0 (atom positions)"
|
|
197
197
|
assert cols["|F|²"][0] == pytest.approx(cols["|F|"][0] ** 2) and cols["I rel"][0] == pytest.approx(1)
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
def test_triplet_round_trip():
|
|
201
|
+
from hklforge.crystal.spacegroups import format_triplet, same_ops
|
|
202
|
+
for name in ("Fd-3m:2", "R-3m:H", "P21/c", "P63/mmc", "I41/amd:1"):
|
|
203
|
+
ops = SpaceGroup(name).all_ops()
|
|
204
|
+
again = [parse_triplet(format_triplet(R, t)) for R, t in ops]
|
|
205
|
+
assert same_ops(ops, again)
|
|
206
|
+
assert format_triplet(*parse_triplet("1/2-x, y, -z")) == "-x+1/2,y,-z"
|
|
207
|
+
assert not same_ops(SpaceGroup("Fd-3m:1").all_ops(), SpaceGroup("Fd-3m:2").all_ops())
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
@pytest.mark.parametrize("source", [NACL, SI_NUMBER_ONLY, DATA / "TiO2_rutile.cif", DATA / "GaAs.cif",
|
|
211
|
+
DATA / "Bi2Se3.cif"])
|
|
212
|
+
def test_structure_dict_round_trip(source):
|
|
213
|
+
import json
|
|
214
|
+
|
|
215
|
+
from hklforge.crystal.structure import Structure
|
|
216
|
+
st = read_cif(source)
|
|
217
|
+
d = json.loads(json.dumps(st.to_dict())) # plain JSON
|
|
218
|
+
again = Structure.from_dict(d)
|
|
219
|
+
assert again.cell == st.cell and again.name == st.name and again.notes == st.notes
|
|
220
|
+
assert (again.space_group is None) == (st.space_group is None)
|
|
221
|
+
if st.space_group is not None:
|
|
222
|
+
assert again.space_group.name == st.space_group.name
|
|
223
|
+
a, b = st.atoms()[1], again.atoms()[1]
|
|
224
|
+
assert len(a) == len(b) and np.allclose(np.sort(a, axis=0), np.sort(b, axis=0), atol=1e-6)
|
|
225
|
+
assert [s.scatterer for s in again.sites] == [s.scatterer for s in st.sites]
|
|
226
|
+
if xraydb is not None:
|
|
227
|
+
assert np.allclose(np.abs(again.structure_factors(H[:30], 9000)), np.abs(st.structure_factors(H[:30], 9000)))
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def test_structure_dict_keeps_ops_without_space_group():
|
|
231
|
+
from hklforge.crystal.structure import Structure
|
|
232
|
+
text = NACL.replace("_symmetry_space_group_name_H-M 'F m -3 m'",
|
|
233
|
+
"loop_\n_symmetry_equiv_pos_as_xyz\n" + "\n".join(
|
|
234
|
+
f"'{t}'" for t in ("x,y,z", "x,y+1/2,z+1/2", "x+1/2,y,z+1/2", "x+1/2,y+1/2,z")))
|
|
235
|
+
st = read_cif(text)
|
|
236
|
+
assert st.space_group is None
|
|
237
|
+
d = st.to_dict()
|
|
238
|
+
assert len(d["ops"]) == 4
|
|
239
|
+
assert len(Structure.from_dict(d).atoms()[1]) == len(st.atoms()[1]) == 8
|
|
240
|
+
assert "ops" not in read_cif(NACL).to_dict() # the space group's own: not repeated
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|