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 storing labelings or comparing against the structures already found.

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 et al., 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 in 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. 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. They are computed only when requested: enumerate_structures fills them in by default, enumerate_labelings with degeneracy=True, and skipping them (degeneracy=False) makes object listing about a quarter faster.

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, including at fixed concentration.

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 (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

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/test_hart_forcade.py compares the structure lists, superlattice by superlattice and in canonical form, with tests/hart_forcade.py, our own compiled reimplementation of the table-based 2008 algorithm (not enumlib), in 118 cases: fcc, bcc, simple-cubic, hexagonal and tetragonal parents, two to four species, with and without label exchange, at all and at fixed compositions.

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 194 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 (logs in scripts/*_M2.txt).
  • 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.

License and citation

MIT. If you use this code, please cite:

  1. R. H. Taylor et al., 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. and Curtarolo, Stefano},
  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.4

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.4
File Size Uploaded Provenance Actions
necklace_enum-0.3.4.tar.gz 42.1 kB With provenance Details for necklace_enum-0.3.4.tar.gz

Built distribution (wheel)

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

Total release size: 76.0 kB

Release files / necklace_enum-0.3.4.tar.gz

Download URL necklace_enum-0.3.4.tar.gz
Size 42.1 kB
Tags Source
SHA-256 checksum
How to use checksums
91ad022734ebb45bbf2f5c65fde126861862fc0a293a2383dbf9a53ddd4b8772
BLAKE2b-256 checksum
How to use checksums
34da6c73d74577711084fcbaaafbac38a0d1f211cf057e61f807c7ffcf1aeffe
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 27, 2026.

Transparency log

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

Download URL necklace_enum-0.3.4-py3-none-any.whl
Size 33.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
875668a10a25686927f25c6b7c347416f5ba9cf39f0f5602c352ba4bb12d11a9
BLAKE2b-256 checksum
How to use checksums
402db9e7f9e3fc8add37ea88c9d7191b7a20bfc33bcd9fba28054f45ea26d9f2
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 27, 2026.

Transparency log

Security for necklace-enum 0.3.4

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.4.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 27, 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