necklace-enum 0.2.1__py3-none-any.whl
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/__init__.py +12 -0
- necklace_enum/burnside.py +312 -0
- necklace_enum/cli.py +97 -0
- necklace_enum/core.py +334 -0
- necklace_enum/enumlib_format.py +298 -0
- necklace_enum/kernel.py +480 -0
- necklace_enum/lattice.py +233 -0
- necklace_enum/parent.py +112 -0
- necklace_enum-0.2.1.dist-info/METADATA +193 -0
- necklace_enum-0.2.1.dist-info/RECORD +14 -0
- necklace_enum-0.2.1.dist-info/WHEEL +5 -0
- necklace_enum-0.2.1.dist-info/entry_points.txt +2 -0
- necklace_enum-0.2.1.dist-info/licenses/LICENSE +21 -0
- necklace_enum-0.2.1.dist-info/top_level.txt +1 -0
|
@@ -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"]
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
"""Counting derivative structures by Burnside's lemma, without listing them.
|
|
2
|
+
|
|
3
|
+
This is an independent route to the numbers produced by ``count_structures``: it
|
|
4
|
+
shares the superlattice list and the symmetry operations with the generator, but
|
|
5
|
+
not the word picture or the generator kernel. Its cost grows with the number of
|
|
6
|
+
superlattices and symmetry operations, not with the number of structures, so it
|
|
7
|
+
reaches sizes far beyond any listing.
|
|
8
|
+
|
|
9
|
+
For one superlattice S with quotient group G = L/S, the derivative structures are
|
|
10
|
+
the orbits of *primitive* labelings (no nonzero translation of G fixes them) under
|
|
11
|
+
|
|
12
|
+
Gamma_S = (translations G x| operations fixing S) x label exchanges.
|
|
13
|
+
|
|
14
|
+
Burnside's lemma gives
|
|
15
|
+
|
|
16
|
+
#orbits = (1/|Gamma_S|) * sum over gamma in Gamma_S of #{primitive labelings fixed by gamma},
|
|
17
|
+
|
|
18
|
+
and primitivity is imposed by Moebius inversion on the lattice of subgroups of G:
|
|
19
|
+
|
|
20
|
+
#{primitive, fixed by gamma} = sum over subgroups K of G of mu(0, K) * #{fixed by gamma, K-invariant}.
|
|
21
|
+
|
|
22
|
+
For a finite abelian group, mu(0, K) is nonzero only when every Sylow part of K is
|
|
23
|
+
elementary abelian, K = sum_p (Z_p)^r_p, and then mu(0, K) = prod_p (-1)^r_p p^(r_p(r_p-1)/2).
|
|
24
|
+
A labeling that is K-invariant and fixed by gamma is also invariant under the images
|
|
25
|
+
of K under gamma's linear part, so K is first closed under that action; the
|
|
26
|
+
labeling is then a labeling of the coset space, and the number fixed by gamma is a
|
|
27
|
+
product over the cycles of the induced permutation.
|
|
28
|
+
|
|
29
|
+
All arithmetic on counts uses Python integers, so there is no overflow.
|
|
30
|
+
"""
|
|
31
|
+
from __future__ import annotations
|
|
32
|
+
|
|
33
|
+
import itertools
|
|
34
|
+
from collections import Counter
|
|
35
|
+
from math import prod
|
|
36
|
+
|
|
37
|
+
import numpy as np
|
|
38
|
+
from numba import njit
|
|
39
|
+
|
|
40
|
+
from .core import _composition_vector, _label_group, _site_perm, _sizes, _stabilizer_ops
|
|
41
|
+
from .lattice import Quotient, unique_superlattices
|
|
42
|
+
from .parent import Parent
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
# ---------------------------------------------------------------- number theory
|
|
46
|
+
def _prime_factors(n):
|
|
47
|
+
out, p = [], 2
|
|
48
|
+
while p * p <= n:
|
|
49
|
+
if n % p == 0:
|
|
50
|
+
out.append(p)
|
|
51
|
+
while n % p == 0:
|
|
52
|
+
n //= p
|
|
53
|
+
p += 1
|
|
54
|
+
if n > 1:
|
|
55
|
+
out.append(n)
|
|
56
|
+
return out
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
# ---------------------------------------------------------------- subgroups of G
|
|
60
|
+
def _span(q: Quotient, gens):
|
|
61
|
+
"""Subgroup of G generated by the elements gens (indices), as a sorted tuple of indices."""
|
|
62
|
+
elems = q.elems
|
|
63
|
+
S = {int(q.index(np.zeros(3, dtype=np.int64)))}
|
|
64
|
+
frontier = list(S)
|
|
65
|
+
gvecs = [elems[g] for g in gens]
|
|
66
|
+
while frontier:
|
|
67
|
+
new = []
|
|
68
|
+
for s in frontier:
|
|
69
|
+
for v in gvecs:
|
|
70
|
+
x = int(q.index(elems[s] + v))
|
|
71
|
+
if x not in S:
|
|
72
|
+
S.add(x)
|
|
73
|
+
new.append(x)
|
|
74
|
+
frontier = new
|
|
75
|
+
return tuple(sorted(S))
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def _moebius_subgroups(q: Quotient):
|
|
79
|
+
"""[(subgroup as tuple of element indices, mu(0, subgroup))] for the subgroups with
|
|
80
|
+
nonzero Moebius value: products over primes p of elementary abelian p-subgroups."""
|
|
81
|
+
d = q.d
|
|
82
|
+
per_prime = []
|
|
83
|
+
for p in _prime_factors(q.n):
|
|
84
|
+
# G[p] = elements of order dividing p: spanned by (d_i / p) e_i for p | d_i
|
|
85
|
+
basis = []
|
|
86
|
+
for i in range(3):
|
|
87
|
+
if d[i] % p == 0:
|
|
88
|
+
v = np.zeros(3, dtype=np.int64)
|
|
89
|
+
v[i] = d[i] // p
|
|
90
|
+
basis.append(int(q.index(v)))
|
|
91
|
+
socle = _span(q, basis)
|
|
92
|
+
# every subspace of the F_p-vector space G[p], with its dimension
|
|
93
|
+
subs = {}
|
|
94
|
+
nonzero = [x for x in socle if q.elems[x].any()]
|
|
95
|
+
for r in range(len(basis) + 1):
|
|
96
|
+
for gens in itertools.combinations(nonzero, r):
|
|
97
|
+
K = _span(q, gens)
|
|
98
|
+
if len(K) == p ** r and K not in subs:
|
|
99
|
+
subs[K] = r
|
|
100
|
+
per_prime.append([(K, (-1) ** r * p ** (r * (r - 1) // 2)) for K, r in subs.items()])
|
|
101
|
+
out = []
|
|
102
|
+
for combo in itertools.product(*per_prime):
|
|
103
|
+
gens = [x for K, _ in combo for x in K]
|
|
104
|
+
K = _span(q, gens) if gens else _span(q, [])
|
|
105
|
+
out.append((K, prod(mu for _, mu in combo)))
|
|
106
|
+
return out
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def _closure(q: Quotient, K, T):
|
|
110
|
+
"""Smallest subgroup containing K that is invariant under g -> T g (mod D)."""
|
|
111
|
+
gens = set(K)
|
|
112
|
+
while True:
|
|
113
|
+
imgs = {int(x) for x in q.index(q.elems[list(gens)] @ T.T)}
|
|
114
|
+
if imgs <= gens:
|
|
115
|
+
break
|
|
116
|
+
gens = set(_span(q, sorted(gens | imgs)))
|
|
117
|
+
return tuple(sorted(gens))
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
# ---------------------------------------------------------------- cycle types
|
|
121
|
+
@njit(cache=True)
|
|
122
|
+
def _cycle_types(base, tcos, nsite_cos, kind_class, nclass, out):
|
|
123
|
+
"""For each translation t (row of tcos), the permutation of the quotient sites
|
|
124
|
+
(i, c) -> (base_kind[i,c], tcos[t, base_coset[i,c]]) is decomposed into cycles;
|
|
125
|
+
out[t, L, cl] counts cycles of length L whose sites have allowed-class cl."""
|
|
126
|
+
nt = tcos.shape[0]
|
|
127
|
+
Nq = base.shape[0]
|
|
128
|
+
seen = np.zeros(Nq, dtype=np.bool_)
|
|
129
|
+
perm = np.empty(Nq, dtype=np.int64)
|
|
130
|
+
for t in range(nt):
|
|
131
|
+
for x in range(Nq):
|
|
132
|
+
b = base[x]
|
|
133
|
+
kind = b // nsite_cos
|
|
134
|
+
c = b % nsite_cos
|
|
135
|
+
perm[x] = kind * nsite_cos + tcos[t, c]
|
|
136
|
+
seen[:] = False
|
|
137
|
+
for x in range(Nq):
|
|
138
|
+
if seen[x]:
|
|
139
|
+
continue
|
|
140
|
+
L = 0
|
|
141
|
+
y = x
|
|
142
|
+
while not seen[y]:
|
|
143
|
+
seen[y] = True
|
|
144
|
+
y = perm[y]
|
|
145
|
+
L += 1
|
|
146
|
+
out[t, L, kind_class[x]] += 1
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
# ---------------------------------------------------------------- fixed-point counts
|
|
150
|
+
class _Labels:
|
|
151
|
+
"""Per-cycle counts: a cycle of length L on sites of allowed-class cl, under label
|
|
152
|
+
permutation eps, admits labels c with eps^L(c) = c, all of eps^i(c) allowed (and,
|
|
153
|
+
for inclusion-exclusion, inside a species subset U)."""
|
|
154
|
+
|
|
155
|
+
def __init__(self, P: Parent, LG, classes):
|
|
156
|
+
self.k = P.k
|
|
157
|
+
self.LG = [tuple(int(x) for x in e) for e in LG]
|
|
158
|
+
self.classes = classes # list of frozensets of allowed species
|
|
159
|
+
self._cache = {}
|
|
160
|
+
|
|
161
|
+
def orbit_seq(self, e, c, L):
|
|
162
|
+
seq = [c]
|
|
163
|
+
for _ in range(L - 1):
|
|
164
|
+
seq.append(e[seq[-1]])
|
|
165
|
+
return seq if e[seq[-1]] == c else None
|
|
166
|
+
|
|
167
|
+
def count(self, e, L, cl, U):
|
|
168
|
+
key = (e, L, cl, U)
|
|
169
|
+
if key not in self._cache:
|
|
170
|
+
A = self.classes[cl] & U
|
|
171
|
+
n = 0
|
|
172
|
+
for c in A:
|
|
173
|
+
seq = self.orbit_seq(e, c, L)
|
|
174
|
+
if seq is not None and all(s in A for s in seq):
|
|
175
|
+
n += 1
|
|
176
|
+
self._cache[key] = n
|
|
177
|
+
return self._cache[key]
|
|
178
|
+
|
|
179
|
+
def poly(self, e, L, cl, w):
|
|
180
|
+
"""Generating polynomial {count vector: multiplicity} of the labels of one cycle
|
|
181
|
+
whose sites each stand for w sites of the crystal."""
|
|
182
|
+
key = ("poly", e, L, cl, w)
|
|
183
|
+
if key not in self._cache:
|
|
184
|
+
out = Counter()
|
|
185
|
+
for c in self.classes[cl]:
|
|
186
|
+
seq = self.orbit_seq(e, c, L)
|
|
187
|
+
if seq is None or not all(s in self.classes[cl] for s in seq):
|
|
188
|
+
continue
|
|
189
|
+
v = [0] * self.k
|
|
190
|
+
for s in seq:
|
|
191
|
+
v[s] += w
|
|
192
|
+
out[tuple(v)] += 1
|
|
193
|
+
self._cache[key] = dict(out)
|
|
194
|
+
return self._cache[key]
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def _fixed_all(lab: _Labels, ctype, e, incomplete):
|
|
198
|
+
"""Labelings fixed by (cycle type, label permutation e), all compositions."""
|
|
199
|
+
k = lab.k
|
|
200
|
+
if incomplete:
|
|
201
|
+
U = frozenset(range(k))
|
|
202
|
+
return prod(lab.count(e, L, cl, U) ** m for (L, cl), m in ctype)
|
|
203
|
+
total = 0
|
|
204
|
+
for r in range(k + 1): # inclusion-exclusion
|
|
205
|
+
for U in itertools.combinations(range(k), r):
|
|
206
|
+
U = frozenset(U)
|
|
207
|
+
f = 1
|
|
208
|
+
for (L, cl), m in ctype:
|
|
209
|
+
c = lab.count(e, L, cl, U)
|
|
210
|
+
if c == 0:
|
|
211
|
+
f = 0
|
|
212
|
+
break
|
|
213
|
+
f *= c ** m
|
|
214
|
+
total += (-1) ** (k - r) * f
|
|
215
|
+
return total
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
def _fixed_comp(lab: _Labels, ctype, e, conc, w):
|
|
219
|
+
"""Labelings fixed by (cycle type, e) with exactly the composition conc; every
|
|
220
|
+
quotient site stands for w sites."""
|
|
221
|
+
conc = tuple(int(x) for x in conc)
|
|
222
|
+
states = {tuple([0] * lab.k): 1}
|
|
223
|
+
for (L, cl), m in ctype:
|
|
224
|
+
terms = lab.poly(e, L, cl, w)
|
|
225
|
+
for _ in range(m):
|
|
226
|
+
new = Counter()
|
|
227
|
+
for s, ways in states.items():
|
|
228
|
+
for v, mult in terms.items():
|
|
229
|
+
t = tuple(a + b for a, b in zip(s, v))
|
|
230
|
+
if all(a <= b for a, b in zip(t, conc)):
|
|
231
|
+
new[t] += ways * mult
|
|
232
|
+
states = new
|
|
233
|
+
if not states:
|
|
234
|
+
return 0
|
|
235
|
+
return states.get(conc, 0)
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
# ---------------------------------------------------------------- driver
|
|
239
|
+
def _count_one(P: Parent, n, label_exchange, conc, include_incomplete):
|
|
240
|
+
d = P.d
|
|
241
|
+
LG = _label_group(P, label_exchange)
|
|
242
|
+
if conc is not None:
|
|
243
|
+
LG = [p for p in LG if all(conc[p[l]] == conc[l] for l in range(P.k))]
|
|
244
|
+
classes = sorted(set(P.allowed), key=sorted)
|
|
245
|
+
kind_cl = [classes.index(a) for a in P.allowed]
|
|
246
|
+
lab = _Labels(P, LG, classes)
|
|
247
|
+
total_num = 0
|
|
248
|
+
for H in unique_superlattices(n, P.rots):
|
|
249
|
+
q = Quotient(H)
|
|
250
|
+
ops = _stabilizer_ops(P, H)
|
|
251
|
+
order = q.n * len(ops) * len(LG)
|
|
252
|
+
subgroups = _moebius_subgroups(q)
|
|
253
|
+
acc = 0
|
|
254
|
+
for op in ops:
|
|
255
|
+
T = q.L @ op[0] @ q.Linv
|
|
256
|
+
sp = _site_perm(P, q, op) # site i*n+g -> image
|
|
257
|
+
for K0, mu in subgroups:
|
|
258
|
+
K = _closure(q, K0, T)
|
|
259
|
+
Kset = np.array(K)
|
|
260
|
+
# coset id of every element: smallest index in g + K
|
|
261
|
+
cid_raw = q.index(q.elems[:, None, :] + q.elems[Kset][None, :, :]).min(1)
|
|
262
|
+
reps, cid = np.unique(cid_raw, return_inverse=True)
|
|
263
|
+
nc = len(reps)
|
|
264
|
+
# translations by coset representatives act on cosets
|
|
265
|
+
tcos = cid[q.index(q.elems[reps][:, None, :] + q.elems[reps][None, :, :])]
|
|
266
|
+
tcos = tcos.T.copy() # tcos[t, c] = coset of rep_c + rep_t
|
|
267
|
+
# op acting on quotient sites (i, coset)
|
|
268
|
+
base = np.empty(d * nc, dtype=np.int64)
|
|
269
|
+
kind_class = np.empty(d * nc, dtype=np.int64)
|
|
270
|
+
for i in range(d):
|
|
271
|
+
for ci, g in enumerate(reps):
|
|
272
|
+
img = sp[i * q.n + g]
|
|
273
|
+
base[i * nc + ci] = (img // q.n) * nc + cid[img % q.n]
|
|
274
|
+
kind_class[i * nc + ci] = kind_cl[i]
|
|
275
|
+
hist = np.zeros((nc, d * nc + 1, len(classes)), dtype=np.int64)
|
|
276
|
+
_cycle_types(base, tcos, nc, kind_class, len(classes), hist)
|
|
277
|
+
# each coset translation stands for |K| translations of G
|
|
278
|
+
types = Counter()
|
|
279
|
+
for t in range(nc):
|
|
280
|
+
nz = np.argwhere(hist[t])
|
|
281
|
+
types[tuple((int(L), int(c), int(hist[t, L, c])) for L, c in nz)] += 1
|
|
282
|
+
for ct, mult in types.items():
|
|
283
|
+
ctype = [((L, c), m) for L, c, m in ct]
|
|
284
|
+
for e in lab.LG:
|
|
285
|
+
if conc is not None:
|
|
286
|
+
f = _fixed_comp(lab, ctype, e, conc, len(K))
|
|
287
|
+
else:
|
|
288
|
+
f = _fixed_all(lab, ctype, e, include_incomplete)
|
|
289
|
+
acc += mu * mult * len(K) * f
|
|
290
|
+
if acc % order:
|
|
291
|
+
raise ArithmeticError(f"Burnside sum not divisible by group order for H={H.tolist()}")
|
|
292
|
+
total_num += acc // order
|
|
293
|
+
return total_num
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
def count_structures_burnside(parent: Parent, sizes, composition=None, label_exchange=False,
|
|
297
|
+
include_incomplete=False):
|
|
298
|
+
"""Number of derivative structures for each size, by Burnside's lemma.
|
|
299
|
+
|
|
300
|
+
Same arguments and conventions as :func:`count_structures`, and the same
|
|
301
|
+
results, but computed without generating any structure. Returns {n: count}.
|
|
302
|
+
"""
|
|
303
|
+
out = {}
|
|
304
|
+
for n in _sizes(sizes):
|
|
305
|
+
conc = None
|
|
306
|
+
if composition is not None:
|
|
307
|
+
conc = _composition_vector(parent, composition, n * parent.d)
|
|
308
|
+
if conc is None:
|
|
309
|
+
out[n] = 0
|
|
310
|
+
continue
|
|
311
|
+
out[n] = _count_one(parent, n, label_exchange, conc, include_incomplete)
|
|
312
|
+
return out
|
necklace_enum/cli.py
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"""Command line: count or list derivative structures.
|
|
2
|
+
|
|
3
|
+
Examples
|
|
4
|
+
--------
|
|
5
|
+
necklace-enum count fcc Cu,Au 1-12
|
|
6
|
+
necklace-enum count fcc 3 2-10 --label-exchange
|
|
7
|
+
necklace-enum count fcc 2 1-60 --label-exchange --burnside # counts only, no listing
|
|
8
|
+
necklace-enum list hcp Mg,Cd 4 --composition 5,3 --format extxyz -o out.xyz
|
|
9
|
+
necklace-enum list fcc Cu,Au 1-8 --format enum -o struct_enum.out
|
|
10
|
+
necklace-enum enumlib [struct_enum.in] # drop-in for enumlib's enum.x
|
|
11
|
+
"""
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import argparse
|
|
15
|
+
import sys
|
|
16
|
+
import time
|
|
17
|
+
|
|
18
|
+
from . import bcc, count_structures, count_structures_burnside, enumerate_structures, fcc, hcp, sc
|
|
19
|
+
|
|
20
|
+
PARENTS = {"fcc": fcc, "bcc": bcc, "sc": sc, "hcp": hcp}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _sizes(text):
|
|
24
|
+
out = []
|
|
25
|
+
for part in text.split(","):
|
|
26
|
+
if "-" in part:
|
|
27
|
+
a, b = part.split("-")
|
|
28
|
+
out.extend(range(int(a), int(b) + 1))
|
|
29
|
+
else:
|
|
30
|
+
out.append(int(part))
|
|
31
|
+
return out
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _species(text):
|
|
35
|
+
return int(text) if text.isdigit() else text.split(",")
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def main(argv=None):
|
|
39
|
+
argv = sys.argv[1:] if argv is None else list(argv)
|
|
40
|
+
if argv and argv[0] == "enumlib":
|
|
41
|
+
from .enumlib_format import run_enumlib_input
|
|
42
|
+
infile = argv[1] if len(argv) > 1 else "struct_enum.in"
|
|
43
|
+
t = time.perf_counter()
|
|
44
|
+
n = run_enumlib_input(infile, "struct_enum.out")
|
|
45
|
+
print(f"wrote struct_enum.out: {n:,d} structures ({time.perf_counter() - t:.1f} s)")
|
|
46
|
+
return 0
|
|
47
|
+
ap = argparse.ArgumentParser(prog="necklace-enum", description=__doc__,
|
|
48
|
+
formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
49
|
+
ap.add_argument("action", choices=["count", "list"])
|
|
50
|
+
ap.add_argument("parent", choices=sorted(PARENTS))
|
|
51
|
+
ap.add_argument("species", help="comma-separated names (Cu,Au) or a number of species")
|
|
52
|
+
ap.add_argument("sizes", help="supercell sizes, e.g. 1-12 or 4,6,8")
|
|
53
|
+
ap.add_argument("--composition", help="atom counts per species, e.g. 6,2")
|
|
54
|
+
ap.add_argument("--label-exchange", action="store_true",
|
|
55
|
+
help="identify structures related by permuting species (Hart-Forcade tables)")
|
|
56
|
+
ap.add_argument("--format", default="summary",
|
|
57
|
+
help="'summary', 'enum' (enumlib's struct_enum.out) or an ASE format such as extxyz")
|
|
58
|
+
ap.add_argument("--include-incomplete", action="store_true",
|
|
59
|
+
help="also list structures in which some species is absent")
|
|
60
|
+
ap.add_argument("--burnside", action="store_true",
|
|
61
|
+
help="count by Burnside's lemma instead of generating (count only; reaches far larger sizes)")
|
|
62
|
+
ap.add_argument("-o", "--output", help="output file for --format other than summary")
|
|
63
|
+
args = ap.parse_args(argv)
|
|
64
|
+
|
|
65
|
+
P = PARENTS[args.parent](_species(args.species))
|
|
66
|
+
comp = [int(x) for x in args.composition.split(",")] if args.composition else None
|
|
67
|
+
sizes = _sizes(args.sizes)
|
|
68
|
+
if args.action == "count":
|
|
69
|
+
total = 0
|
|
70
|
+
for n in sizes:
|
|
71
|
+
t = time.perf_counter()
|
|
72
|
+
counter = count_structures_burnside if args.burnside else count_structures
|
|
73
|
+
c = counter(P, n, composition=comp, label_exchange=args.label_exchange,
|
|
74
|
+
include_incomplete=args.include_incomplete)[n]
|
|
75
|
+
total += c
|
|
76
|
+
print(f"n={n:3d} {c:>14,d} ({time.perf_counter() - t:.2f} s)")
|
|
77
|
+
print(f"total {total:,d}")
|
|
78
|
+
return 0
|
|
79
|
+
if args.format == "enum":
|
|
80
|
+
from .enumlib_format import write_struct_enum
|
|
81
|
+
n = write_struct_enum(args.output or "struct_enum.out", P, sizes, composition=comp,
|
|
82
|
+
include_incomplete=args.include_incomplete)
|
|
83
|
+
print(f"wrote {args.output or 'struct_enum.out'}: {n:,d} structures")
|
|
84
|
+
return 0
|
|
85
|
+
structs = enumerate_structures(P, sizes, composition=comp, label_exchange=args.label_exchange,
|
|
86
|
+
include_incomplete=args.include_incomplete)
|
|
87
|
+
if args.format == "summary":
|
|
88
|
+
for s in structs:
|
|
89
|
+
print(s.size, s.hnf.ravel().tolist(), "".join(str(P.species[x])[0] for x in s.labels))
|
|
90
|
+
return 0
|
|
91
|
+
from ase.io import write
|
|
92
|
+
write(args.output or sys.stdout, [s.to_ase() for s in structs], format=args.format)
|
|
93
|
+
return 0
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
if __name__ == "__main__":
|
|
97
|
+
sys.exit(main())
|