necklace-enum 0.2.1__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.
- necklace_enum-0.2.1/LICENSE +21 -0
- necklace_enum-0.2.1/PKG-INFO +193 -0
- necklace_enum-0.2.1/README.md +157 -0
- necklace_enum-0.2.1/pyproject.toml +47 -0
- necklace_enum-0.2.1/setup.cfg +4 -0
- necklace_enum-0.2.1/src/necklace_enum/__init__.py +12 -0
- necklace_enum-0.2.1/src/necklace_enum/burnside.py +312 -0
- necklace_enum-0.2.1/src/necklace_enum/cli.py +97 -0
- necklace_enum-0.2.1/src/necklace_enum/core.py +334 -0
- necklace_enum-0.2.1/src/necklace_enum/enumlib_format.py +298 -0
- necklace_enum-0.2.1/src/necklace_enum/kernel.py +480 -0
- necklace_enum-0.2.1/src/necklace_enum/lattice.py +233 -0
- necklace_enum-0.2.1/src/necklace_enum/parent.py +112 -0
- necklace_enum-0.2.1/src/necklace_enum.egg-info/PKG-INFO +193 -0
- necklace_enum-0.2.1/src/necklace_enum.egg-info/SOURCES.txt +25 -0
- necklace_enum-0.2.1/src/necklace_enum.egg-info/dependency_links.txt +1 -0
- necklace_enum-0.2.1/src/necklace_enum.egg-info/entry_points.txt +2 -0
- necklace_enum-0.2.1/src/necklace_enum.egg-info/requires.txt +13 -0
- necklace_enum-0.2.1/src/necklace_enum.egg-info/top_level.txt +1 -0
- necklace_enum-0.2.1/tests/test_bruteforce.py +45 -0
- necklace_enum-0.2.1/tests/test_burnside.py +58 -0
- necklace_enum-0.2.1/tests/test_enumlib_format.py +139 -0
- necklace_enum-0.2.1/tests/test_export.py +45 -0
- necklace_enum-0.2.1/tests/test_hart_forcade.py +13 -0
- necklace_enum-0.2.1/tests/test_labelings.py +50 -0
- necklace_enum-0.2.1/tests/test_published.py +47 -0
- necklace_enum-0.2.1/tests/test_streaming.py +23 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Richard H. Taylor
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: necklace-enum
|
|
3
|
+
Version: 0.2.1
|
|
4
|
+
Summary: Derivative superstructures generated as Lyndon words on the quotient group of a superlattice
|
|
5
|
+
Author-email: "Richard H. Taylor" <r_taylor@outlook.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://r-h-taylor.github.io/necklace-enum/
|
|
8
|
+
Project-URL: Repository, https://github.com/r-h-taylor/necklace-enum
|
|
9
|
+
Project-URL: Paper, https://r-h-taylor.github.io/necklace-enum/necklace-enum.pdf
|
|
10
|
+
Project-URL: Archive, https://doi.org/10.5281/zenodo.24330096
|
|
11
|
+
Keywords: derivative structures,enumeration,alloys,cluster expansion,Lyndon words,necklaces,Hart-Forcade
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Physics
|
|
21
|
+
Classifier: Topic :: Scientific/Engineering :: Chemistry
|
|
22
|
+
Requires-Python: >=3.10
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
License-File: LICENSE
|
|
25
|
+
Requires-Dist: numpy>=1.24
|
|
26
|
+
Requires-Dist: numba>=0.59
|
|
27
|
+
Provides-Extra: ase
|
|
28
|
+
Requires-Dist: ase>=3.22; extra == "ase"
|
|
29
|
+
Provides-Extra: pymatgen
|
|
30
|
+
Requires-Dist: pymatgen; extra == "pymatgen"
|
|
31
|
+
Provides-Extra: test
|
|
32
|
+
Requires-Dist: pytest; extra == "test"
|
|
33
|
+
Requires-Dist: ase>=3.22; extra == "test"
|
|
34
|
+
Requires-Dist: spglib; extra == "test"
|
|
35
|
+
Dynamic: license-file
|
|
36
|
+
|
|
37
|
+
# necklace-enum
|
|
38
|
+
|
|
39
|
+
[](https://doi.org/10.5281/zenodo.24330096)
|
|
40
|
+
|
|
41
|
+
Enumerates derivative superstructures — the symmetrically distinct ways of decorating a parent lattice with
|
|
42
|
+
several kinds of atoms — by generating them directly as canonical words, without filtering duplicates.
|
|
43
|
+
|
|
44
|
+
Project page: https://r-h-taylor.github.io/necklace-enum/ · Archived at Zenodo: https://doi.org/10.5281/zenodo.24330096
|
|
45
|
+
|
|
46
|
+
This is the reference implementation for
|
|
47
|
+
|
|
48
|
+
> R. H. Taylor, *Toroidal necklaces for low-memory derivative structure enumeration* (2026).
|
|
49
|
+
|
|
50
|
+
It keeps the superlattice and Smith-normal-form construction of Hart & Forcade
|
|
51
|
+
([Phys. Rev. B 77, 224115 (2008)](https://doi.org/10.1103/PhysRevB.77.224115)) and replaces their duplicate-removal
|
|
52
|
+
step. Reading the sites column by column along the largest cyclic factor of the quotient group turns each labeling
|
|
53
|
+
into a word. Translations act on the word as rotations combined with a single letterwise permutation, so the
|
|
54
|
+
canonical structures are Lyndon words, which are generated directly with an extended necklace recursion.
|
|
55
|
+
|
|
56
|
+
## Install
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
pip install necklace-enum # numpy + numba
|
|
60
|
+
pip install "necklace-enum[ase]" # to export ASE Atoms
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
From a clone of this repository (needed for the tests and the benchmark scripts):
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
pip install ".[test]"
|
|
67
|
+
pytest
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Use
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
import necklace_enum as te
|
|
74
|
+
|
|
75
|
+
P = te.fcc(["Cu", "Au"])
|
|
76
|
+
te.count_structures(P, range(1, 13)) # {n: count} without listing them
|
|
77
|
+
|
|
78
|
+
for s in te.enumerate_structures(P, 8, composition={"Cu": 6, "Au": 2}):
|
|
79
|
+
atoms = s.to_ase() # or s.to_pymatgen(), or s.hnf / s.labels
|
|
80
|
+
|
|
81
|
+
hcp = te.hcp(["Li", "Vac", "Co"], allowed=[{"Li", "Vac"}, {"Co", "Vac"}]) # site restrictions
|
|
82
|
+
custom = te.Parent(lattice, basis, species=["A", "B", "C"]) # any parent
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Command line:
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
necklace-enum count fcc Cu,Au 1-12
|
|
89
|
+
necklace-enum count fcc 2 2-23 --label-exchange # Hart & Forcade, Table V
|
|
90
|
+
necklace-enum list hcp Mg,Cd 4 --composition 5,3 --format extxyz -o out.xyz
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
**Fast listing as arrays.** `enumerate_labelings` takes the same arguments as `enumerate_structures` but hands the
|
|
94
|
+
structures to Python as rows of integer arrays, in batches, instead of one `Structure` object each. It is several
|
|
95
|
+
times faster and is the form to use when the structures go straight into NumPy code or a file:
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
for H, labels in te.enumerate_labelings(P, 12): # labels: (rows, sites) array, one structure per row
|
|
99
|
+
... # te.Structure(P, H, tuple(row)) rebuilds an object
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
**Counting without listing.** `count_structures_burnside` gives the same counts as `count_structures`, with the
|
|
103
|
+
same arguments, by Burnside's lemma: it sums fixed points over the symmetry operations of each superlattice instead
|
|
104
|
+
of generating structures. Its cost grows with the number of superlattices, not structures, so it reaches far larger
|
|
105
|
+
cells (binary fcc at n = 32 in about a second, n = 96 in under half a minute):
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
te.count_structures_burnside(te.fcc(2), range(1, 61), label_exchange=True)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
necklace-enum count fcc 2 1-60 --label-exchange --burnside
|
|
113
|
+
python scripts/oeis_counts.py --nmax 100 -o b_fcc_binary.txt # OEIS b-file
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
**Conventions.**
|
|
117
|
+
- By default, species are distinct: A₃B and AB₃ are different structures. With `label_exchange=True`, structures
|
|
118
|
+
that differ only by a permutation of species are identified, as in Hart & Forcade's tables.
|
|
119
|
+
- Only structures that contain every species are listed unless `include_incomplete=True`.
|
|
120
|
+
- Structures that are periodic in a smaller cell are excluded; they appear at their own, smaller size.
|
|
121
|
+
|
|
122
|
+
## enumlib compatibility
|
|
123
|
+
|
|
124
|
+
necklace-enum reads enumlib's input file and writes its `struct_enum.out` format, so it can take the place of
|
|
125
|
+
`enum.x` in existing workflows:
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
necklace-enum enumlib struct_enum.in # writes struct_enum.out, as enum.x does
|
|
129
|
+
necklace-enum list fcc Cu,Au 1-12 --format enum -o struct_enum.out
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
te.run_enumlib_input("struct_enum.in", "struct_enum.out")
|
|
134
|
+
te.write_struct_enum("struct_enum.out", P, range(1, 13))
|
|
135
|
+
header, rows = te.read_struct_enum("struct_enum.out") # also reads enumlib's own files
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
enumlib's `makeStr.py` and `makestr.x` (which pymatgen calls) build POSCAR files from this output unchanged.
|
|
139
|
+
The output follows enumlib's conventions:
|
|
140
|
+
- A "partial" listing without concentration restrictions identifies structures related by swapping species, as in
|
|
141
|
+
Hart & Forcade's tables. "Full" listings and concentration-restricted runs list them separately.
|
|
142
|
+
- The degeneracy columns are exact: `Totdegn` summed over a cell size equals the number of (superlattice, labeling)
|
|
143
|
+
pairs the structures stand for. enumlib writes `labdegn = 0` in its fixed-concentration mode.
|
|
144
|
+
|
|
145
|
+
`scripts/compare_with_enumlib.py` runs both programs on the same input and compares the results.
|
|
146
|
+
|
|
147
|
+
## Verification
|
|
148
|
+
|
|
149
|
+
```bash
|
|
150
|
+
python check_necklace_enum.py # stand-alone check incl. timing against Hart & Forcade (under a minute)
|
|
151
|
+
python check_necklace_enum.py --full # more cases and larger cells (a few minutes)
|
|
152
|
+
pytest # brute force, published counts, export checks (about 15 s)
|
|
153
|
+
pytest --slow # also binary fcc up to n = 23
|
|
154
|
+
python scripts/reproduce_paper.py [--full]
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
The tests compare the generated structures, one by one, with an independent brute-force code for fcc, bcc,
|
|
158
|
+
simple-cubic and hcp parents (including site restrictions and fixed compositions). They also reproduce every count
|
|
159
|
+
tabulated by Hart & Forcade, compare the Burnside counter with the generator over parents, species counts,
|
|
160
|
+
compositions and site restrictions, and check that each exported crystal is primitive in its own cell and that no two
|
|
161
|
+
exported crystals are symmetry-equivalent. The enumlib-format tests rebuild every structure from the written file with enumlib's indexing rule and check the degeneracy columns against a direct count. `tests/hart_forcade.py` is a compiled reference implementation of the 2008 algorithm, used to check counts and to compare speed.
|
|
162
|
+
|
|
163
|
+
## Performance and limits
|
|
164
|
+
|
|
165
|
+
- The compiled generator labels binary fcc structures at tens of nanoseconds per structure. `count_structures`
|
|
166
|
+
counts all 4,592,213,143 binary fcc structures with 32 sites per cell (up to label exchange) in about 230 s on
|
|
167
|
+
one core of an Apple M2.
|
|
168
|
+
- Memory does not grow with the number of structures. The generator's state is polynomial in the cell size, and
|
|
169
|
+
listing streams structures from the compiled kernel in batches of 2^16 words. Counting stays within 10 MB of the
|
|
170
|
+
85 MB interpreter baseline up to 9.2 billion structures; listing stays below 0.22 GB
|
|
171
|
+
(`scripts/memory_compare.py`).
|
|
172
|
+
- `enumerate_structures` builds a Python object per structure, so listing that way is far slower than counting.
|
|
173
|
+
`enumerate_labelings` hands over arrays instead and is several times faster; use it, counts or fixed compositions
|
|
174
|
+
for very large runs.
|
|
175
|
+
- The per-superlattice setup is plain Python and takes a few tenths of a second per size. For dilute fixed-composition
|
|
176
|
+
runs it is larger than the labeling time.
|
|
177
|
+
- Letters hold `d * d1 * d2` sites. For multilattices with many sites and species the letter tables can grow large,
|
|
178
|
+
in which case a `MemoryError` names the offending Smith normal form.
|
|
179
|
+
- The first call compiles the kernels with Numba (a few seconds); later calls use the on-disk cache.
|
|
180
|
+
|
|
181
|
+
## Changes
|
|
182
|
+
|
|
183
|
+
- **0.2.1** (22 Nov 2026): `enumerate_labelings`, fast listing as arrays of labelings; `--cooldown` option in the
|
|
184
|
+
benchmark scripts; `scripts/time_necklace.py`; PyPI release.
|
|
185
|
+
- **0.2.0** (21 Nov 2026): streaming listing with constant memory (resumable kernel); Burnside counter
|
|
186
|
+
(`burnside.py`); benchmark and comparison scripts against enumlib, Enumlib.jl and dsenum; structure-by-structure
|
|
187
|
+
check against enumlib (`scripts/compare_structures_with_enumlib.py`); binary fcc counts to 43 sites
|
|
188
|
+
(`scripts/oeis_counts.py`); current paper in `docs/`.
|
|
189
|
+
- **0.1.0** (18 Nov 2026): first release.
|
|
190
|
+
|
|
191
|
+
## License
|
|
192
|
+
|
|
193
|
+
MIT. If you use this code, please cite the paper above and Hart & Forcade (2008).
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# necklace-enum
|
|
2
|
+
|
|
3
|
+
[](https://doi.org/10.5281/zenodo.24330096)
|
|
4
|
+
|
|
5
|
+
Enumerates derivative superstructures — the symmetrically distinct ways of decorating a parent lattice with
|
|
6
|
+
several kinds of atoms — by generating them directly as canonical words, without filtering duplicates.
|
|
7
|
+
|
|
8
|
+
Project page: https://r-h-taylor.github.io/necklace-enum/ · Archived at Zenodo: https://doi.org/10.5281/zenodo.24330096
|
|
9
|
+
|
|
10
|
+
This is the reference implementation for
|
|
11
|
+
|
|
12
|
+
> R. H. Taylor, *Toroidal necklaces for low-memory derivative structure enumeration* (2026).
|
|
13
|
+
|
|
14
|
+
It keeps the superlattice and Smith-normal-form construction of Hart & Forcade
|
|
15
|
+
([Phys. Rev. B 77, 224115 (2008)](https://doi.org/10.1103/PhysRevB.77.224115)) and replaces their duplicate-removal
|
|
16
|
+
step. Reading the sites column by column along the largest cyclic factor of the quotient group turns each labeling
|
|
17
|
+
into a word. Translations act on the word as rotations combined with a single letterwise permutation, so the
|
|
18
|
+
canonical structures are Lyndon words, which are generated directly with an extended necklace recursion.
|
|
19
|
+
|
|
20
|
+
## Install
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
pip install necklace-enum # numpy + numba
|
|
24
|
+
pip install "necklace-enum[ase]" # to export ASE Atoms
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
From a clone of this repository (needed for the tests and the benchmark scripts):
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pip install ".[test]"
|
|
31
|
+
pytest
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Use
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
import necklace_enum as te
|
|
38
|
+
|
|
39
|
+
P = te.fcc(["Cu", "Au"])
|
|
40
|
+
te.count_structures(P, range(1, 13)) # {n: count} without listing them
|
|
41
|
+
|
|
42
|
+
for s in te.enumerate_structures(P, 8, composition={"Cu": 6, "Au": 2}):
|
|
43
|
+
atoms = s.to_ase() # or s.to_pymatgen(), or s.hnf / s.labels
|
|
44
|
+
|
|
45
|
+
hcp = te.hcp(["Li", "Vac", "Co"], allowed=[{"Li", "Vac"}, {"Co", "Vac"}]) # site restrictions
|
|
46
|
+
custom = te.Parent(lattice, basis, species=["A", "B", "C"]) # any parent
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Command line:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
necklace-enum count fcc Cu,Au 1-12
|
|
53
|
+
necklace-enum count fcc 2 2-23 --label-exchange # Hart & Forcade, Table V
|
|
54
|
+
necklace-enum list hcp Mg,Cd 4 --composition 5,3 --format extxyz -o out.xyz
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**Fast listing as arrays.** `enumerate_labelings` takes the same arguments as `enumerate_structures` but hands the
|
|
58
|
+
structures to Python as rows of integer arrays, in batches, instead of one `Structure` object each. It is several
|
|
59
|
+
times faster and is the form to use when the structures go straight into NumPy code or a file:
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
for H, labels in te.enumerate_labelings(P, 12): # labels: (rows, sites) array, one structure per row
|
|
63
|
+
... # te.Structure(P, H, tuple(row)) rebuilds an object
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
**Counting without listing.** `count_structures_burnside` gives the same counts as `count_structures`, with the
|
|
67
|
+
same arguments, by Burnside's lemma: it sums fixed points over the symmetry operations of each superlattice instead
|
|
68
|
+
of generating structures. Its cost grows with the number of superlattices, not structures, so it reaches far larger
|
|
69
|
+
cells (binary fcc at n = 32 in about a second, n = 96 in under half a minute):
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
te.count_structures_burnside(te.fcc(2), range(1, 61), label_exchange=True)
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
necklace-enum count fcc 2 1-60 --label-exchange --burnside
|
|
77
|
+
python scripts/oeis_counts.py --nmax 100 -o b_fcc_binary.txt # OEIS b-file
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
**Conventions.**
|
|
81
|
+
- By default, species are distinct: A₃B and AB₃ are different structures. With `label_exchange=True`, structures
|
|
82
|
+
that differ only by a permutation of species are identified, as in Hart & Forcade's tables.
|
|
83
|
+
- Only structures that contain every species are listed unless `include_incomplete=True`.
|
|
84
|
+
- Structures that are periodic in a smaller cell are excluded; they appear at their own, smaller size.
|
|
85
|
+
|
|
86
|
+
## enumlib compatibility
|
|
87
|
+
|
|
88
|
+
necklace-enum reads enumlib's input file and writes its `struct_enum.out` format, so it can take the place of
|
|
89
|
+
`enum.x` in existing workflows:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
necklace-enum enumlib struct_enum.in # writes struct_enum.out, as enum.x does
|
|
93
|
+
necklace-enum list fcc Cu,Au 1-12 --format enum -o struct_enum.out
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
te.run_enumlib_input("struct_enum.in", "struct_enum.out")
|
|
98
|
+
te.write_struct_enum("struct_enum.out", P, range(1, 13))
|
|
99
|
+
header, rows = te.read_struct_enum("struct_enum.out") # also reads enumlib's own files
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
enumlib's `makeStr.py` and `makestr.x` (which pymatgen calls) build POSCAR files from this output unchanged.
|
|
103
|
+
The output follows enumlib's conventions:
|
|
104
|
+
- A "partial" listing without concentration restrictions identifies structures related by swapping species, as in
|
|
105
|
+
Hart & Forcade's tables. "Full" listings and concentration-restricted runs list them separately.
|
|
106
|
+
- The degeneracy columns are exact: `Totdegn` summed over a cell size equals the number of (superlattice, labeling)
|
|
107
|
+
pairs the structures stand for. enumlib writes `labdegn = 0` in its fixed-concentration mode.
|
|
108
|
+
|
|
109
|
+
`scripts/compare_with_enumlib.py` runs both programs on the same input and compares the results.
|
|
110
|
+
|
|
111
|
+
## Verification
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
python check_necklace_enum.py # stand-alone check incl. timing against Hart & Forcade (under a minute)
|
|
115
|
+
python check_necklace_enum.py --full # more cases and larger cells (a few minutes)
|
|
116
|
+
pytest # brute force, published counts, export checks (about 15 s)
|
|
117
|
+
pytest --slow # also binary fcc up to n = 23
|
|
118
|
+
python scripts/reproduce_paper.py [--full]
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
The tests compare the generated structures, one by one, with an independent brute-force code for fcc, bcc,
|
|
122
|
+
simple-cubic and hcp parents (including site restrictions and fixed compositions). They also reproduce every count
|
|
123
|
+
tabulated by Hart & Forcade, compare the Burnside counter with the generator over parents, species counts,
|
|
124
|
+
compositions and site restrictions, and check that each exported crystal is primitive in its own cell and that no two
|
|
125
|
+
exported crystals are symmetry-equivalent. The enumlib-format tests rebuild every structure from the written file with enumlib's indexing rule and check the degeneracy columns against a direct count. `tests/hart_forcade.py` is a compiled reference implementation of the 2008 algorithm, used to check counts and to compare speed.
|
|
126
|
+
|
|
127
|
+
## Performance and limits
|
|
128
|
+
|
|
129
|
+
- The compiled generator labels binary fcc structures at tens of nanoseconds per structure. `count_structures`
|
|
130
|
+
counts all 4,592,213,143 binary fcc structures with 32 sites per cell (up to label exchange) in about 230 s on
|
|
131
|
+
one core of an Apple M2.
|
|
132
|
+
- Memory does not grow with the number of structures. The generator's state is polynomial in the cell size, and
|
|
133
|
+
listing streams structures from the compiled kernel in batches of 2^16 words. Counting stays within 10 MB of the
|
|
134
|
+
85 MB interpreter baseline up to 9.2 billion structures; listing stays below 0.22 GB
|
|
135
|
+
(`scripts/memory_compare.py`).
|
|
136
|
+
- `enumerate_structures` builds a Python object per structure, so listing that way is far slower than counting.
|
|
137
|
+
`enumerate_labelings` hands over arrays instead and is several times faster; use it, counts or fixed compositions
|
|
138
|
+
for very large runs.
|
|
139
|
+
- The per-superlattice setup is plain Python and takes a few tenths of a second per size. For dilute fixed-composition
|
|
140
|
+
runs it is larger than the labeling time.
|
|
141
|
+
- Letters hold `d * d1 * d2` sites. For multilattices with many sites and species the letter tables can grow large,
|
|
142
|
+
in which case a `MemoryError` names the offending Smith normal form.
|
|
143
|
+
- The first call compiles the kernels with Numba (a few seconds); later calls use the on-disk cache.
|
|
144
|
+
|
|
145
|
+
## Changes
|
|
146
|
+
|
|
147
|
+
- **0.2.1** (22 Nov 2026): `enumerate_labelings`, fast listing as arrays of labelings; `--cooldown` option in the
|
|
148
|
+
benchmark scripts; `scripts/time_necklace.py`; PyPI release.
|
|
149
|
+
- **0.2.0** (21 Nov 2026): streaming listing with constant memory (resumable kernel); Burnside counter
|
|
150
|
+
(`burnside.py`); benchmark and comparison scripts against enumlib, Enumlib.jl and dsenum; structure-by-structure
|
|
151
|
+
check against enumlib (`scripts/compare_structures_with_enumlib.py`); binary fcc counts to 43 sites
|
|
152
|
+
(`scripts/oeis_counts.py`); current paper in `docs/`.
|
|
153
|
+
- **0.1.0** (18 Nov 2026): first release.
|
|
154
|
+
|
|
155
|
+
## License
|
|
156
|
+
|
|
157
|
+
MIT. If you use this code, please cite the paper above and Hart & Forcade (2008).
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "necklace-enum"
|
|
7
|
+
version = "0.2.1"
|
|
8
|
+
description = "Derivative superstructures generated as Lyndon words on the quotient group of a superlattice"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
license-files = ["LICENSE"]
|
|
12
|
+
authors = [{name = "Richard H. Taylor", email = "r_taylor@outlook.com"}]
|
|
13
|
+
requires-python = ">=3.10"
|
|
14
|
+
dependencies = ["numpy>=1.24", "numba>=0.59"]
|
|
15
|
+
keywords = ["derivative structures", "enumeration", "alloys", "cluster expansion", "Lyndon words", "necklaces", "Hart-Forcade"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 4 - Beta",
|
|
18
|
+
"Intended Audience :: Science/Research",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Programming Language :: Python :: 3.13",
|
|
25
|
+
"Topic :: Scientific/Engineering :: Physics",
|
|
26
|
+
"Topic :: Scientific/Engineering :: Chemistry",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
[project.urls]
|
|
30
|
+
Homepage = "https://r-h-taylor.github.io/necklace-enum/"
|
|
31
|
+
Repository = "https://github.com/r-h-taylor/necklace-enum"
|
|
32
|
+
Paper = "https://r-h-taylor.github.io/necklace-enum/necklace-enum.pdf"
|
|
33
|
+
Archive = "https://doi.org/10.5281/zenodo.24330096"
|
|
34
|
+
|
|
35
|
+
[project.optional-dependencies]
|
|
36
|
+
ase = ["ase>=3.22"]
|
|
37
|
+
pymatgen = ["pymatgen"]
|
|
38
|
+
test = ["pytest", "ase>=3.22", "spglib"]
|
|
39
|
+
|
|
40
|
+
[project.scripts]
|
|
41
|
+
necklace-enum = "necklace_enum.cli:main"
|
|
42
|
+
|
|
43
|
+
[tool.setuptools.packages.find]
|
|
44
|
+
where = ["src"]
|
|
45
|
+
|
|
46
|
+
[tool.pytest.ini_options]
|
|
47
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"""necklace_enum: derivative structures generated as Lyndon words on the quotient group.
|
|
2
|
+
|
|
3
|
+
Reference implementation for R. H. Taylor, "Toroidal necklaces for low-memory derivative structure enumeration".
|
|
4
|
+
"""
|
|
5
|
+
from .burnside import count_structures_burnside
|
|
6
|
+
from .core import Structure, count_structures, enumerate_labelings, enumerate_structures
|
|
7
|
+
from .enumlib_format import read_struct_enum, read_struct_enum_in, run_enumlib_input, write_struct_enum
|
|
8
|
+
from .parent import Parent, bcc, fcc, hcp, sc
|
|
9
|
+
|
|
10
|
+
__version__ = "0.2.1"
|
|
11
|
+
__all__ = ["Parent", "Structure", "bcc", "count_structures", "count_structures_burnside", "enumerate_labelings", "enumerate_structures", "fcc", "hcp",
|
|
12
|
+
"read_struct_enum", "read_struct_enum_in", "run_enumlib_input", "sc", "write_struct_enum"]
|