Skip to main content

necklace-enum

DOI

Enumerates derivative superstructures — the symmetrically distinct ways of decorating a parent lattice with several kinds of atoms — by generating them directly as canonical words, without filtering duplicates.

Project page: https://r-h-taylor.github.io/necklace-enum/ · Archived at Zenodo: https://doi.org/10.5281/zenodo.24330095

This is the reference implementation for

R. H. Taylor, Algorithm for low-memory derivative structure enumeration using toroidal necklaces (2026).

It keeps the superlattice and Smith-normal-form construction of Hart & Forcade (Phys. Rev. B 77, 224115 (2008)) and replaces their duplicate-removal step. Reading the sites column by column along the largest cyclic factor of the quotient group turns each labeling into a word. Translations act on the word as rotations combined with a single letterwise permutation, so the canonical structures are Lyndon words, which are generated directly with an extended necklace recursion.

Install

pip install necklace-enum            # numpy + numba
pip install "necklace-enum[ase]"     # to export ASE Atoms

From a clone of this repository (needed for the tests and the benchmark scripts):

pip install ".[test]"
pytest

Use

import necklace_enum as te

P = te.fcc(["Cu", "Au"])
te.count_structures(P, range(1, 13))                 # {n: count} without listing them

for s in te.enumerate_structures(P, 8, composition={"Cu": 6, "Au": 2}):
    atoms = s.to_ase()                               # or s.to_pymatgen(), or s.hnf / s.labels

hcp = te.hcp(["Li", "Vac", "Co"], allowed=[{"Li", "Vac"}, {"Co", "Vac"}])   # site restrictions
custom = te.Parent(lattice, basis, species=["A", "B", "C"])                 # any parent

Command line:

necklace-enum count fcc Cu,Au 1-12
necklace-enum count fcc 2 2-23 --label-exchange          # Hart & Forcade, Table V
necklace-enum list hcp Mg,Cd 4 --composition 5,3 --format extxyz -o out.xyz

Fast listing as arrays. enumerate_labelings takes the same arguments as enumerate_structures but hands the structures to Python as rows of integer arrays, in batches, instead of one Structure object each. It is several times faster and is the form to use when the structures go straight into NumPy code or a file:

for H, labels in te.enumerate_labelings(P, 12):     # labels: (rows, sites) array, one structure per row
    ...                                              # te.Structure(P, H, tuple(row)) rebuilds an object

Degeneracies (weights for statistical mechanics). Every structure carries its degeneracy, at fixed composition as well as over all compositions: s.degeneracy is the number of labelings of its superlattice that are equivalent to it (enumlib's labdegn), s.superlattice_degeneracy the number of equivalent superlattices of the same size (Hdegn), and s.total_degeneracy their product (Totdegn), the weight g in a partition function sum g exp(-E/kT). Summed over all structures of one size, the total degeneracies count every labeling of every superlattice exactly once. They come out of the generator itself: while testing a word for canonicity it compares the word with its images under the symmetry operations, and the comparisons that end equal are its stabilizer, so degeneracy = group order / stabilizer order at no extra pass and no measurable cost.

for s in te.enumerate_structures(P, 8, composition=(6, 2)):
    print(s.labels, s.degeneracy, s.superlattice_degeneracy, s.total_degeneracy)

for H, labels, g in te.enumerate_labelings(P, 12, composition=(9, 3), degeneracy=True):
    weights = g * te.superlattice_degeneracy(P, H)  # one weight per row of labels

stats = {}
te.count_structures(P, 12, stats=stats)              # stats["weight"]: sum of total degeneracies
necklace-enum list fcc Cu,Au 8 --composition 6,2 --degeneracy      # columns: g on cell, equivalent cells, total

to_ase() stores the three numbers in atoms.info, so they are kept in extended XYZ files.

Counting without listing. count_structures_burnside gives the same counts as count_structures, with the same arguments, by Burnside's lemma: it sums fixed points over the symmetry operations of each superlattice instead of generating structures. Its cost grows with the number of superlattices, not structures, so it reaches far larger cells (binary fcc at n = 32 in about a second, n = 96 in under half a minute):

te.count_structures_burnside(te.fcc(2), range(1, 61), label_exchange=True)
necklace-enum count fcc 2 1-60 --label-exchange --burnside
python scripts/oeis_counts.py --nmax 100 -o b_fcc_binary.txt     # OEIS b-file

Conventions.

  • By default, species are distinct: A₃B and AB₃ are different structures. With label_exchange=True, structures that differ only by a permutation of species are identified, as in Hart & Forcade's tables.
  • Only structures that contain every species are listed unless include_incomplete=True.
  • Structures that are periodic in a smaller cell are excluded; they appear at their own, smaller size.

enumlib compatibility

necklace-enum reads enumlib's input file and writes its struct_enum.out format, so it can take the place of enum.x in existing workflows:

necklace-enum enumlib struct_enum.in                    # writes struct_enum.out, as enum.x does
necklace-enum list fcc Cu,Au 1-12 --format enum -o struct_enum.out
te.run_enumlib_input("struct_enum.in", "struct_enum.out")
te.write_struct_enum("struct_enum.out", P, range(1, 13))
header, rows = te.read_struct_enum("struct_enum.out")    # also reads enumlib's own files

enumlib's makeStr.py and makestr.x (which pymatgen calls) build POSCAR files from this output unchanged. The output follows enumlib's conventions:

  • A "partial" listing without concentration restrictions identifies structures related by swapping species, as in Hart & Forcade's tables. "Full" listings and concentration-restricted runs list them separately.
  • The degeneracy columns are exact, in every mode: Totdegn summed over a cell size equals the number of (superlattice, labeling) pairs the structures stand for. enumlib writes labdegn = 0 in its fixed-concentration mode; necklace-enum fills it in there too.

scripts/compare_with_enumlib.py runs both programs on the same input and compares the results.

Verification

python check_necklace_enum.py           # stand-alone check incl. timing against Hart & Forcade (under a minute)
python check_necklace_enum.py --full    # more cases and larger cells (a few minutes)
pytest                   # brute force, published counts, export checks (about 15 s)
pytest --slow            # also binary fcc up to n = 23
python scripts/reproduce_paper.py [--full]

The tests compare the generated structures, one by one, with an independent brute-force code for fcc, bcc, simple-cubic and hcp parents (including site restrictions and fixed compositions). They also reproduce every count tabulated by Hart & Forcade, compare the Burnside counter with the generator over parents, species counts, compositions and site restrictions, and check that each exported crystal is primitive in its own cell and that no two 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/test_degeneracy.py checks the generator's degeneracies against an independent pass that applies every operation of each superlattice's group, over Bravais and multilattice parents, label exchange, fixed compositions and site restrictions, and checks that the total degeneracies count every labeling of every superlattice, by direct enumeration. tests/hart_forcade.py is a compiled reference implementation of the 2008 algorithm, used to check counts and to compare speed.

Performance and limits

  • The compiled generator labels binary fcc structures at tens of nanoseconds per structure. count_structures counts all 4,592,213,143 binary fcc structures with 32 sites per cell (up to label exchange) in about 230 s on one core of an Apple M2.
  • Memory does not grow with the number of structures. The generator's state is polynomial in the cell size, and listing streams structures from the compiled kernel in batches of 2^16 words. Counting stays within 10 MB of the 85 MB interpreter baseline up to 9.2 billion structures; listing stays below 0.22 GB (scripts/memory_compare.py).
  • enumerate_structures builds a Python object per structure, so listing that way is far slower than counting. enumerate_labelings hands over arrays instead and is several times faster; use it, counts or fixed compositions for very large runs.
  • The per-superlattice setup is plain Python and takes a few tenths of a second per size. For dilute fixed-composition runs it is larger than the labeling time.
  • Letters hold d * d1 * d2 sites. For multilattices with many sites and species the letter tables can grow large, in which case a MemoryError names the offending Smith normal form.
  • The first call compiles the kernels with Numba (a few seconds); later calls use the on-disk cache.

Changes

  • 0.3.1 (24 Nov 2026): a clear message instead of a traceback when an ASE output format is requested without ASE installed. Adds the data behind the paper's corrected Table 2 and Fig. 3: Enumlib.jl 0.5.0 memory (scripts/memory_enumlibjl050_M2.txt), the binary-fcc size sweep for n = 10-28 (scripts/sweep_binary_fcc*_M2.txt) and the figure script (scripts/make_fig_sweep.py).
  • 0.3.0 (24 Nov 2026): degeneracies computed inside the generator, in every mode including fixed composition: Structure.degeneracy, .superlattice_degeneracy, .total_degeneracy; enumerate_labelings(..., degeneracy=True); superlattice_degeneracy(); count_structures(..., stats=...) reports the total weight; --degeneracy on the command line; degeneracies in to_ase() info; the enumlib-format writer uses them (no separate pass). examples/necklace-try.sh, a short command-line tour; scripts/sweep_binary_fcc.py; benchmark logs now record the Enumlib.jl version.
  • 0.2.1 (22 Nov 2026): enumerate_labelings, fast listing as arrays of labelings; --cooldown option in the benchmark scripts; scripts/time_necklace.py; PyPI release.
  • 0.2.0 (21 Nov 2026): streaming listing with constant memory (resumable kernel); Burnside counter (burnside.py); benchmark and comparison scripts against enumlib, Enumlib.jl and dsenum; structure-by-structure check against enumlib (scripts/compare_structures_with_enumlib.py); binary fcc counts to 43 sites (scripts/oeis_counts.py); current paper in docs/.
  • 0.1.0 (18 Nov 2026): first release.

License and citation

MIT. If you use this code, please cite:

  1. R. H. Taylor, Algorithm for low-memory derivative structure enumeration using toroidal necklaces (2026). Software: necklace-enum, Zenodo, doi:10.5281/zenodo.24330095.
  2. G. L. W. Hart and R. W. Forcade, Algorithm for generating derivative structures, Phys. Rev. B 77, 224115 (2008), doi:10.1103/PhysRevB.77.224115.
@article{Taylor2026necklace,
  author = {Taylor, Richard H.},
  title  = {Algorithm for low-memory derivative structure enumeration using toroidal necklaces},
  year   = {2026},
  note   = {Software: necklace-enum, doi:10.5281/zenodo.24330095}
}

@article{HartForcade2008,
  author  = {Hart, Gus L. W. and Forcade, Rodney W.},
  title   = {Algorithm for generating derivative structures},
  journal = {Phys. Rev. B},
  volume  = {77},
  pages   = {224115},
  year    = {2008},
  doi     = {10.1103/PhysRevB.77.224115}
}

Metadata

Release files for necklace-enum 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for necklace-enum 0.3.1
File Size Uploaded Provenance Actions
necklace_enum-0.3.1.tar.gz 41.7 kB With provenance Details for necklace_enum-0.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for necklace-enum 0.3.1
File Interpreter ABI Platform Actions
necklace_enum-0.3.1-py3-none-any.whl Python 3 none any Details for necklace_enum-0.3.1-py3-none-any.whl

Total release size: 75.6 kB

Release files / necklace_enum-0.3.1.tar.gz

Download URL necklace_enum-0.3.1.tar.gz
Size 41.7 kB
Tags Source
SHA-256 checksum
How to use checksums
a3353ce7c9b732ab6e3e4c22c18121aaa48d773641c25632dafc73f8c9033e62
BLAKE2b-256 checksum
How to use checksums
78211f8fa2511ed18ead9639970024a1813492900a143dfe1c798e9d38e7553a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Release files / necklace_enum-0.3.1-py3-none-any.whl

Download URL necklace_enum-0.3.1-py3-none-any.whl
Size 33.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c2c548adb2a0137aa650ba9c492256a7a60e08313507a8db68c8670b55853df2
BLAKE2b-256 checksum
How to use checksums
863c68bc60e04c1d5fabf0f0be9a62d85cfb9b3d4e47bc24e66ee0d2f5446881
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

Security for necklace-enum 0.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for necklace_enum-0.3.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 24, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page