Vertex-label tables¶
Every symmetry-unique isomer with its vertex name and environment labels, for
a built cage or an ideal polyhedron: cage_isomer_builder.utils.vertex_table.
Vertex-label tables: every symmetry-unique isomer, with the vertex name and
environment labels of each (see
:mod:cage_isomer_builder.utils.vertex_codes), for statistics over vertex
environments. One group per linker by default; groups and
linker_patterns place several groups, or several kinds, per linker, as
in :meth:~cage_isomer_builder.cage.base.CageBuilder.enumerate_rgroup_isomers.
Works for any cage whose vertex scheme is known:
- an ideal polyhedron (:func:
ideal_cage): a named one (:data:POLYHEDRA) or any vertex coordinates, with a linker on every edge lying flat on the cage (perpendicular to the radial direction): a four-site ring, or any sites (:data:LINKERS); - a built cage:
:meth:
~cage_isomer_builder.cage.base.CageBuilder.vertex_table.
Symmetry-equivalent placements are one isomer, mirror images included; each
is represented by the placement with the smallest index (linker 0 the most
significant base-4 digit), as in
:meth:~cage_isomer_builder.cage.base.CageBuilder.enumerate_isomers. A
chiral isomer therefore appears once, in one hand: its mirror_labels
give the other hand's labels, and an operation is improper exactly when it
swaps left and right (1 and 4) at the sites.
The enumeration checks all placements (4 ** n_linkers for one group on
four-site linkers), vectorised, so it is practical up to about 16 linkers (octahedron, cube, trigonal prism,
square antiprism), not for the icosahedron or dodecahedron (30 linkers).
For any size, without enumerating:
- :func:
count_isomerscounts the isomers and :func:count_environmentsthe vertex environments over all isomers, exactly (Burnside's lemma); - :func:
sample_labelsestimates the distribution of label multisets from random placements, weighted by their stabiliser sizes so that the sample is uniform over isomers, with standard errors.
SiteSymmetry
dataclass
¶
SiteSymmetry(scheme: VertexScheme, perms: ndarray, improper: ndarray, group: str = '', layout: Optional[SlotLayout] = None)
A vertex scheme with the symmetry operations of its cage.
Attributes:
| Name | Type | Description |
|---|---|---|
scheme |
VertexScheme
|
|
perms |
np.ndarray, shape (|G|, n_sites)
|
|
improper |
np.ndarray of bool, shape (|G|,)
|
True for the operations that swap left and right (reflections, inversion, improper rotations). |
group |
str
|
Schoenflies symbol, when known ( |
layout |
(SlotLayout, optional)
|
Linker types (:class: |
Examples:
>>> from cage_isomer_builder.utils.vertex_table import ideal_cage
>>> cage = ideal_cage("tetrahedron")
>>> cage.group, cage.order, cage.n_linkers, int(cage.improper.sum())
('Td', 24, 6, 12)
order
property
¶
n_linkers
property
¶
from_permutations
classmethod
¶
from_permutations(scheme: VertexScheme, perms, group: str = '', layout: Optional[SlotLayout] = None) -> SiteSymmetry
Build from site permutations (identity included or not); which ones are improper is read from the scheme: they send every left site to a right one.
Raises:
| Type | Description |
|---|---|
ValueError
|
If an operation keeps some sites' sides and swaps others', or the permutations do not move whole linkers. |
Examples:
Two vertices joined by two linkers; swapping the linkers keeps left and right, the swap of the two ends of each linker does not:
>>> from cage_isomer_builder.utils.vertex_codes import VertexScheme
>>> from cage_isomer_builder.utils.vertex_table import SiteSymmetry
>>> scheme = VertexScheme(((0, 1), (0, 1)), ((0, 1, 2, 3), (4, 5, 6, 7)),
... {0: (0, 1), 1: (0, 4), 2: (1, 1), 3: (1, 4),
... 4: (0, 1), 5: (0, 4), 6: (1, 1), 7: (1, 4)})
>>> sym = SiteSymmetry.from_permutations(
... scheme, [[4, 5, 6, 7, 0, 1, 2, 3], [3, 2, 1, 0, 7, 6, 5, 4]])
>>> sym.order, sym.improper.tolist()
(3, [False, False, True])
Source code in cage_isomer_builder/utils/vertex_table.py
VertexTable
dataclass
¶
VertexTable(sym: SiteSymmetry, indices: ndarray, achiral: ndarray, groups: Union[str, list, dict] = 'A', linker_patterns: Optional[dict] = None)
The symmetry-unique isomers of a cage, kept as placement indices: names and labels are worked out on request, and the counts in vectorised chunks, so tables of hundreds of millions of isomers fit in memory.
Attributes:
| Name | Type | Description |
|---|---|---|
sym |
SiteSymmetry
|
|
indices |
np.ndarray of int64
|
Placement index of each isomer (see :func: |
achiral |
np.ndarray of bool
|
|
groups, linker_patterns |
What goes on the linkers (see :func: |
Examples:
>>> from cage_isomer_builder.utils.vertex_table import ideal_cage, vertex_table
>>> table = vertex_table(ideal_cage("tetrahedron"))
>>> len(table), table.site_name(0), table.name(0), table.labels(0)
(176, '0-4-8-12-16-20', '111-011-001-000', '111-110-100-000')
>>> table.mirror_labels(0), bool(table.achiral[0])
('444-440-400-000', False)
Two groups on every linker, and one A and one B:
>>> vertex_table(ideal_cage("tetrahedron"), groups="AA").name(0)
'000-500-550-555'
>>> ab = vertex_table(ideal_cage("tetrahedron"), groups="AB")
>>> ab.site_name(0)
'A-2-6-10-14-18-22_B-3-7-11-15-19-23'
>>> ab.name(0)
'00.00.00-AB.00.00-AB.AB.00-AB.AB.AB'
isomer ¶
Sites of isomer i, sorted (one kind of group), or
{group: sites} (several kinds).
Examples:
>>> from cage_isomer_builder.utils.vertex_table import ideal_cage, vertex_table
>>> vertex_table(ideal_cage("tetrahedron")).isomer(1)
[0, 4, 8, 12, 16, 21]
Source code in cage_isomer_builder/utils/vertex_table.py
site_name ¶
Site name of isomer i, as in the isomer file names
(0-4-8-12-16-21, or A-0-4_B-1-5 for several kinds).
Examples:
>>> from cage_isomer_builder.utils.vertex_table import ideal_cage, vertex_table
>>> vertex_table(ideal_cage("tetrahedron")).site_name(1)
'0-4-8-12-16-21'
Source code in cage_isomer_builder/utils/vertex_table.py
name ¶
Vertex name of isomer i (anchored codes in vertex order).
Examples:
>>> from cage_isomer_builder.utils.vertex_table import ideal_cage, vertex_table
>>> table = vertex_table(ideal_cage("tetrahedron"))
>>> table.name(1) == table.sym.scheme.name(table.isomer(1))
True
Source code in cage_isomer_builder/utils/vertex_table.py
labels ¶
Environment labels of isomer i, sorted with 5 < 1 < 4 < 0 (A < B
< ... < 0): its multiset of vertex environments.
Examples:
>>> from cage_isomer_builder.utils.vertex_table import ideal_cage, vertex_table
>>> vertex_table(ideal_cage("octahedron")).labels(0)
'1111-1110-1100-1100-1000-0000'
Source code in cage_isomer_builder/utils/vertex_table.py
mirror_labels ¶
The labels of the mirror image of isomer i (left and right
swapped, linkers read the other way round).
Examples:
>>> from cage_isomer_builder.utils.vertex_table import ideal_cage, vertex_table
>>> vertex_table(ideal_cage("octahedron")).mirror_labels(0)
'4444-4440-4400-4400-4000-0000'
Source code in cage_isomer_builder/utils/vertex_table.py
label_counts ¶
Number of isomers with each label multiset, most common first.
With merge_mirrors, a multiset and its mirror image count
together (under the one of the two that sorts first), so the result
does not depend on which hand represents each chiral isomer.
Examples:
>>> from cage_isomer_builder.utils.vertex_table import ideal_cage, vertex_table
>>> table = vertex_table(ideal_cage("tetrahedron"))
>>> len(table.label_counts()), len(table.label_counts(merge_mirrors=True))
(55, 54)
>>> table.label_counts().most_common(1)
[('110-140-100-400', 8)]
Source code in cage_isomer_builder/utils/vertex_table.py
environment_counts ¶
How often each vertex environment occurs, over all vertices of all
isomers, in label order. With both_hands every isomer counts in
both hands, which makes mirror-image environments (114 and 144, ...)
equally common.
Examples:
>>> from cage_isomer_builder.utils.vertex_table import ideal_cage, vertex_table
>>> counts = vertex_table(ideal_cage("tetrahedron")).environment_counts(both_hands=True)
>>> counts["114"] == counts["144"], sum(counts.values())
(True, 1408)
Source code in cage_isomer_builder/utils/vertex_table.py
write ¶
Write the table as tab-separated text (gzip-compressed if path
ends in .gz): site name, vertex name, labels, mirror labels,
chiral (Y/N). Returns path.
Examples:
>>> import os, tempfile
>>> from cage_isomer_builder.utils.vertex_table import ideal_cage, vertex_table
>>> path = vertex_table(ideal_cage("tetrahedron")).write(
... os.path.join(tempfile.mkdtemp(), "tet.tsv"))
>>> print(open(path).read().splitlines()[1])
0-4-8-12-16-20 111-011-001-000 111-110-100-000 444-440-400-000 Y
Source code in cage_isomer_builder/utils/vertex_table.py
LabelSample
dataclass
¶
LabelSample(sym: SiteSymmetry, n_samples: int, n_isomers: int, labels: list, fractions: ndarray, stderr: ndarray, hits: ndarray, environments: dict)
Distribution of label multisets, and environment counts, over the
symmetry-unique isomers, estimated from random placements (see
:func:sample_labels). Each multiset is merged with its mirror image
(under the one that sorts first), so every isomer has one, whichever
hand represents it.
Attributes:
| Name | Type | Description |
|---|---|---|
sym |
SiteSymmetry
|
|
n_samples |
int
|
|
n_isomers |
int
|
Exact number of isomers (:func: |
labels |
list of str
|
The multisets seen, most common first. |
fractions |
ndarray
|
Estimated fraction of isomers with each multiset (sums to 1). |
stderr |
ndarray
|
Standard error of each fraction. |
hits |
np.ndarray of int
|
Number of samples that gave each multiset. |
environments |
dict
|
|
Examples:
>>> from cage_isomer_builder.utils.vertex_table import ideal_cage, sample_labels
>>> sample = sample_labels(ideal_cage("icosahedron"), 20000, seed=1)
>>> sample.n_samples, sample.n_isomers, round(float(sample.fractions.sum()), 6)
(20000, 9607679214180672, 1.0)
fraction ¶
(fraction, standard error) of the isomers with a label multiset
(either hand), (0.0, 0.0) if no sample gave it.
Examples:
>>> from cage_isomer_builder.utils.vertex_table import ideal_cage, sample_labels
>>> sample = sample_labels(ideal_cage("tetrahedron"), 50000, seed=0)
>>> f, se = sample.fraction("110-140-100-400")
>>> abs(f - 8 / 176) < 3 * se # exact: 8 of the 176 isomers
True
Source code in cage_isomer_builder/utils/vertex_table.py
write ¶
Write the distribution as tab-separated text (gzip-compressed if
path ends in .gz): labels, fraction, standard error,
estimated number of isomers, samples. Returns path.
Examples:
>>> import os, tempfile
>>> from cage_isomer_builder.utils.vertex_table import ideal_cage, sample_labels
>>> path = sample_labels(ideal_cage("cube"), 1000, seed=0).write(
... os.path.join(tempfile.mkdtemp(), "cube.tsv"))
>>> open(path).readline().split()
['#', 'labels', 'fraction', 'stderr', 'est_isomers', 'samples']
Source code in cage_isomer_builder/utils/vertex_table.py
hull_edges ¶
Edges of a convex polyhedron: the sides of the faces of the convex hull
of vertices (coplanar hull triangles are merged into one face, so
square and pentagonal faces get no diagonals).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vertices
|
(array, shape(n, 3))
|
|
required |
tol
|
float
|
Faces whose planes differ by less than this (relative to the size of the polyhedron) are one face. |
1e-3
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If a vertex is not a corner of the hull. |
Examples:
A triangular prism taller than it is wide: 9 edges, no square diagonals.
>>> from cage_isomer_builder.utils.vertex_table import hull_edges
>>> hull_edges([[1, 0, 1], [-0.5, 0.866, 1], [-0.5, -0.866, 1],
... [1, 0, -1], [-0.5, 0.866, -1], [-0.5, -0.866, -1]])
[(0, 1), (0, 2), (0, 3), (1, 2), (1, 4), (2, 5), (3, 4), (3, 5), (4, 5)]
Source code in cage_isomer_builder/utils/vertex_table.py
ideal_cage ¶
ideal_cage(polyhedron: Union[str, Sequence], edges: Optional[Sequence] = None, radius: float = 10.0, ring: float = 1.2, tol: float = 0.05, linker: Union[str, Sequence] = 'phenylene') -> SiteSymmetry
An ideal cage: a vertex at every corner of a polyhedron and a linker along every edge, its sites lying flat on the cage (perpendicular to the radial direction). For a symmetric linker the polyhedron's whole point group acts on the sites; otherwise the group the decorated cage keeps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
polyhedron
|
(str or array, shape(n_vertices, 3))
|
A name from :data: |
required |
edges
|
sequence of (int, int)
|
Default: the edges of the convex hull (:func: |
None
|
radius
|
float
|
The vertices are scaled to this mean distance from the centre. |
10.0
|
ring
|
float
|
Length unit (Angstrom) of the site offsets: a phenylene's sites are
|
1.2
|
tol
|
float
|
Matching tolerance (Angstrom) of the point-group detection. |
0.05
|
linker
|
str or sequence of (along, across)
|
A name from :data: |
"phenylene"
|
Raises:
| Type | Description |
|---|---|
ValueError
|
For an unknown name, a site beyond the end of its edge, or a
polyhedron whose linkers cannot be read left/right (see
:func: |
Examples:
>>> from cage_isomer_builder.utils.vertex_table import ideal_cage
>>> oct_ = ideal_cage("octahedron")
>>> oct_.group, oct_.n_linkers, oct_.scheme.vertex_linkers[0]
('Oh', 12, (0, 1, 2, 3))
>>> ideal_cage("trigonal_prism").group
'D3h'
>>> bpdc = ideal_cage("tetrahedron", linker="biphenyl")
>>> bpdc.group, len(bpdc.scheme.linker_sites[0]), bpdc.scheme.depths(0, 0)
('Td', 8, 2)
>>> ideal_cage("tetrahedron", linker="fumarate").group # trans: no mirror planes
'T'
Source code in cage_isomer_builder/utils/vertex_table.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 | |
count_isomers ¶
count_isomers(sym: SiteSymmetry, chiral: bool = False, groups='A', linker_patterns: Optional[dict] = None) -> int
Number of symmetry-unique isomers, from Burnside's lemma (no enumeration, so fine for any size).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sym
|
SiteSymmetry
|
|
required |
chiral
|
bool
|
Count mirror images as different isomers (proper rotations only). |
False
|
groups
|
What goes on the linkers, as for
:meth: |
'A'
|
|
linker_patterns
|
What goes on the linkers, as for
:meth: |
'A'
|
Examples:
>>> from cage_isomer_builder.utils.vertex_table import count_isomers, ideal_cage
>>> count_isomers(ideal_cage("tetrahedron")), count_isomers(ideal_cage("octahedron"))
(176, 349928)
>>> count_isomers(ideal_cage("icosahedron"))
9607679214180672
>>> tet = ideal_cage("tetrahedron")
>>> count_isomers(tet, groups="AA"), count_isomers(tet, groups="AB")
(2013, 124464)
>>> count_isomers(tet, linker_patterns={"A": 3, "": 3})
56
Source code in cage_isomer_builder/utils/vertex_table.py
unique_placements ¶
unique_placements(sym: SiteSymmetry, max_placements: int = 4 ** 16, groups='A', linker_patterns: Optional[dict] = None)
Indices of the symmetry-unique placements and whether each is achiral
(left unchanged by an improper operation). Each isomer is represented
as the builder's enumerations represent it: by the smallest index of its
orbit (each linker's state is a digit, linker 0 the most significant;
states in ascending order of their site labels, except that with one
group on every linker state j is the group on site j, as in
:meth:~cage_isomer_builder.cage.base.CageBuilder.enumerate_isomers),
or in mixed mode by the placement whose linker patterns, then site
labels, sort first, as in
:meth:~cage_isomer_builder.cage.base.CageBuilder.enumerate_rgroup_isomers.
The index is split into two halves, so every operation is two table lookups and an add per placement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sym
|
SiteSymmetry
|
|
required |
max_placements
|
int
|
Refuse larger enumerations (all raw placements are checked). |
``4 ** 16``
|
groups
|
See :func: |
'A'
|
|
linker_patterns
|
See :func: |
'A'
|
Returns:
| Name | Type | Description |
|---|---|---|
indices |
np.ndarray of int64
|
|
achiral |
np.ndarray of bool
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If there are more than |
Examples:
>>> from cage_isomer_builder.utils.vertex_table import ideal_cage, unique_placements
>>> idx, achiral = unique_placements(ideal_cage("tetrahedron"))
>>> len(idx), int(idx[0]), int(achiral.sum())
(176, 0, 0)
>>> len(unique_placements(ideal_cage("tetrahedron"), groups="AB")[0])
124464
Source code in cage_isomer_builder/utils/vertex_table.py
789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 | |
vertex_table ¶
vertex_table(sym: SiteSymmetry, max_placements: int = 4 ** 16, groups='A', linker_patterns: Optional[dict] = None) -> VertexTable
Every symmetry-unique isomer (see :class:VertexTable).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sym
|
SiteSymmetry
|
From :func: |
required |
max_placements
|
int
|
See :func: |
``4 ** 16``
|
groups
|
What goes on the linkers (see :func: |
'A'
|
|
linker_patterns
|
What goes on the linkers (see :func: |
'A'
|
Examples:
>>> from cage_isomer_builder.utils.vertex_table import ideal_cage, vertex_table
>>> table = vertex_table(ideal_cage("octahedron"))
>>> len(table), int(table.achiral.sum())
(349928, 192)
>>> counts = table.label_counts(merge_mirrors=True)
>>> len(counts), max(counts.values()), counts["1111-1111-1111-1111-1111-1111"]
(10440, 256, 0)
Source code in cage_isomer_builder/utils/vertex_table.py
count_environments ¶
count_environments(sym: SiteSymmetry, groups='A', linker_patterns: Optional[dict] = None, max_combinations: int = 2000000) -> Counter
How often each vertex environment occurs over all vertices of all
symmetry-unique isomers, every isomer counted in both hands: exact, from
Burnside's lemma, without enumerating the isomers, so fine for any
number of linkers. Equal to :meth:VertexTable.environment_counts
with both_hands=True where a table can be built; the counts add up
to 2 * n_vertices * n_isomers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sym
|
SiteSymmetry
|
|
required |
groups
|
What goes on the linkers (see :func: |
'A'
|
|
linker_patterns
|
What goes on the linkers (see :func: |
'A'
|
|
max_combinations
|
int
|
Refuse when a vertex sees more combinations of its linkers than
this (many sites and kinds of group on high-degree vertices);
:func: |
2000000
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If a vertex has more than |
Examples:
>>> from cage_isomer_builder.utils.vertex_table import (
... count_environments, count_isomers, ideal_cage, vertex_table)
>>> tet = ideal_cage("tetrahedron")
>>> count_environments(tet) == vertex_table(tet).environment_counts(both_hands=True)
True
>>> ico = ideal_cage("icosahedron")
>>> counts = count_environments(ico)
>>> sum(counts.values()) == 2 * 12 * count_isomers(ico), counts["11111"]
(True, 225179981581120)
Source code in cage_isomer_builder/utils/vertex_table.py
1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 | |
sample_labels ¶
sample_labels(sym: SiteSymmetry, n_samples: int, seed: Optional[int] = 0, chunk: int = 1 << 16, groups='A', linker_patterns: Optional[dict] = None) -> LabelSample
Estimate the distribution of label multisets over the symmetry-unique
isomers, and the environment counts, from n_samples random
placements, for cages too big to enumerate.
Placements are drawn uniformly; an isomer whose placements are fixed by
k operations is drawn k times less often than the others, so
each sample counts with weight k (its stabiliser size), which makes
the estimate uniform over isomers. The fractions are the weighted
shares, their standard errors from the delta method. Summed over all
placements instead of a sample, the same weights give the exact counts
(Burnside).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sym
|
SiteSymmetry
|
|
required |
n_samples
|
int
|
|
required |
seed
|
int or None
|
Random seed ( |
0
|
chunk
|
int
|
Placements processed at once. |
65536
|
groups
|
What goes on the linkers (see :func: |
'A'
|
|
linker_patterns
|
What goes on the linkers (see :func: |
'A'
|
Examples:
>>> from cage_isomer_builder.utils.vertex_table import ideal_cage, sample_labels, vertex_table
>>> sample = sample_labels(ideal_cage("octahedron"), 100000, seed=0)
>>> exact = vertex_table(ideal_cage("octahedron")).label_counts(merge_mirrors=True)
>>> labels, n = exact.most_common(1)[0]
>>> f, se = sample.fraction(labels)
>>> n, abs(f - n / 349928) < 3 * se
(256, True)
Source code in cage_isomer_builder/utils/vertex_table.py
1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 | |