Vertex codes¶
Naming isomers by what each vertex sees of the groups on its linkers: cage_isomer_builder.utils.vertex_codes.
Vertex codes: name an isomer by what each vertex (node) sees of the groups on its linkers.
Every linker joins two vertices. Seen from the pore centre with one vertex at the bottom, each site of the linker is next to one of its two vertices, on the left or on the right of the linker, at some depth: 1 for the sites closest to that vertex, 2 for the next ones, and so on. A para-phenylene has four sites, numbered 1 (bottom left), 2 (top left), 3 (top right), 4 (bottom right): sites 1 and 4 are next to the bottom vertex at depth 1, and 2 and 3 next to the top one. A biphenyl has two depths at each end.
Seen from one vertex, a linker reads one character per depth for the sites next to this vertex (groups next to the other vertex are that vertex's business):
- one kind of group:
1if the left site has a group,4if the right one has,5(1 + 4) if both have,0if neither; - several kinds (A, B, ...): two characters per depth, the group on the
left site and the group on the right one,
0for none (A0,0B,AB).
One group per linker on four-site linkers gives the codes of one digit per
linker (0, 1, 4) used throughout. Where a linker reads more than
one character, the linkers of a code are separated by .
(10.00.04).
A vertex code lists its linkers clockwise as seen from the pore centre. Two forms are used:
- the anchored code starts at the vertex's lowest-numbered linker. The
vertex name of an isomer, its anchored codes in vertex order joined by
-(e.g.000-100-141-401), is unique and converts back to the site indices exactly; - the environment label is the rotation of the code that sorts first
with 5 < 1 < 4 < 0 (several kinds: A < B < ... < 0), e.g.
114,140,104. It names the vertex environment whatever linker it starts at, so different isomers can share the same labels.
The mirror image of a vertex swaps left and right (1 and 4, or the two characters of each pair) and reads its linkers the other way round.
VertexScheme
dataclass
¶
How the sites of a cage map onto vertex codes.
Attributes:
| Name | Type | Description |
|---|---|---|
vertex_linkers |
tuple of tuple of int
|
For each vertex, its linkers clockwise as seen from the pore centre, starting at the lowest-numbered one. |
linker_sites |
tuple of tuple of int
|
The site numbers of each linker. |
site_codes |
dict
|
|
An isomer is given as its occupied sites (one kind of group), or as |
|
|
``{group |
sites}`` (several kinds; the first is A, the second B, ...),
|
|
or as an |
class:`~cage_isomer_builder.utils.rgroup.RGroupIsomer`.
|
|
Examples:
Two vertices joined by two linkers, sites 0-3 and 4-7:
>>> from cage_isomer_builder.utils.vertex_codes import VertexScheme
>>> scheme = VertexScheme(
... vertex_linkers=((0, 1), (0, 1)),
... linker_sites=((0, 1, 2, 3), (4, 5, 6, 7)),
... site_codes={0: (0, 1), 1: (0, 4), 2: (1, 1), 3: (1, 4),
... 4: (0, 1), 5: (0, 4), 6: (1, 1), 7: (1, 4)})
>>> scheme.name([1, 6])
'40-01'
>>> scheme.isomer("40-01")
[1, 6]
>>> scheme.resolve("1-6"), scheme.resolve("40-01") # either name gives the isomer
([1, 6], [1, 6])
Two groups on a linker, and two kinds of group:
>>> scheme.name([0, 1, 6])
'50-01'
>>> scheme.name({"NH2": [0], "OH": [1, 6]})
'AB.00-00.B0'
>>> scheme.isomer("AB.00-00.B0")
{'A': [0], 'B': [1, 6]}
n_vertices
property
¶
view ¶
(vertex, side, depth) of a site: the vertex it is next to, 1
(left) or 4 (right) seen from there, and its depth (1 = closest).
Examples:
>>> from cage_isomer_builder.utils.vertex_codes import VertexScheme
>>> VertexScheme(((0,), (0,)), ((0, 1, 2),), {0: (0, 1), 1: (0, 1, 2), 2: (1, 4)}).view(1)
(0, 1, 2)
Source code in cage_isomer_builder/utils/vertex_codes.py
depths ¶
Number of depths vertex reads on linker (characters per
linker with one kind of group, twice that with several).
Examples:
>>> from cage_isomer_builder.utils.vertex_codes import VertexScheme
>>> scheme = VertexScheme(((0,), (0,)), ((0, 1, 2),), {0: (0, 1), 1: (0, 1, 2), 2: (1, 4)})
>>> scheme.depths(0, 0), scheme.depths(1, 0)
(2, 1)
Source code in cage_isomer_builder/utils/vertex_codes.py
codes ¶
Anchored code of every vertex, in vertex order.
Examples:
>>> from cage_isomer_builder.utils.vertex_codes import VertexScheme
>>> 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)})
>>> scheme.codes([1, 6])
['40', '01']
Source code in cage_isomer_builder/utils/vertex_codes.py
name ¶
Vertex name: the anchored codes joined by -. Unique for every
placement, and :meth:isomer converts it back.
Examples:
>>> from cage_isomer_builder.utils.vertex_codes import VertexScheme
>>> 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)})
>>> scheme.name([0, 4])
'11-00'
Source code in cage_isomer_builder/utils/vertex_codes.py
labels ¶
Environment label of every vertex, in vertex order (see
:func:environment_label).
Examples:
>>> from cage_isomer_builder.utils.vertex_codes import VertexScheme
>>> 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)})
>>> scheme.labels([1, 6])
['40', '10']
Source code in cage_isomer_builder/utils/vertex_codes.py
is_vertex_name ¶
True if name has the form of a vertex name of this cage (one code
per vertex, one token per linker of the right width).
Examples:
>>> from cage_isomer_builder.utils.vertex_codes import VertexScheme
>>> 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)})
>>> scheme.is_vertex_name("40-01"), scheme.is_vertex_name("1-6")
(True, False)
Source code in cage_isomer_builder/utils/vertex_codes.py
isomer ¶
The isomer with this vertex name: its sites (sorted) with one kind of
group, or {"A": sites, "B": sites, ...} with several.
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> from cage_isomer_builder.utils.vertex_codes import VertexScheme
>>> 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)})
>>> scheme.isomer("11-00"), scheme.isomer("50-00")
([0, 4], [0, 1])
Source code in cage_isomer_builder/utils/vertex_codes.py
resolve ¶
The isomer given by its vertex name ("000-100-141-401"), its
site name ("0-4-9-13-16-22"), an R-group isomer name
("NH2-0-5_OH-1-6"), its list of sites or {group: sites}:
sorted sites, or {group: sorted sites} for several kinds.
Examples:
>>> from cage_isomer_builder.utils.vertex_codes import VertexScheme
>>> 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)})
>>> scheme.resolve([6, 1]), scheme.resolve("1-6"), scheme.resolve("40-01")
([1, 6], [1, 6], [1, 6])
>>> scheme.resolve("NH2-0_OH-1-6")
{'NH2': [0], 'OH': [1, 6]}
Source code in cage_isomer_builder/utils/vertex_codes.py
to_info ¶
The scheme as text entries for a structure's info, so an isomer
file carries what it takes to convert between its names
(:meth:from_info reads them back).
vertex_order: each vertex's linkers in reading order ("0:0,1,2 1:0,4,3": vertex 1 reads linker 0, then 4, then 3),linker_sites: the sites of each linker ("0:0-3 1:4-7"),site_codes:site:vertex/digitfor every site ("9:2/1": site 9 is next to vertex 2, on the left), with/depthadded beyond the first depth ("9:2/1/2").
Examples:
>>> from cage_isomer_builder.utils.vertex_codes import VertexScheme
>>> 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)})
>>> info = scheme.to_info()
>>> info["vertex_order"], info["linker_sites"]
('0:0,1 1:0,1', '0:0-3 1:4-7')
>>> info["site_codes"]
'0:0/1 1:0/4 2:1/1 3:1/4 4:0/1 5:0/4 6:1/1 7:1/4'
>>> VertexScheme.from_info(info) == scheme
True
Source code in cage_isomer_builder/utils/vertex_codes.py
from_info
classmethod
¶
Read the scheme back from a structure's info (see
:meth:to_info), e.g. from an isomer file written by
:meth:~cage_isomer_builder.cage.base.CageBuilder.enumerate_isomers.
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Examples:
>>> from cage_isomer_builder.utils.vertex_codes import VertexScheme
>>> scheme = VertexScheme.from_info({
... "vertex_order": "0:0,1 1:0,1", "linker_sites": "0:0-3 1:4-7",
... "site_codes": "0:0/1 1:0/4 2:1/1 3:1/4 4:0/1 5:0/4 6:1/1 7:1/4"})
>>> scheme.name([1, 6])
'40-01'
>>> VertexScheme.from_info({"isomer": "1-6"})
Traceback (most recent call last):
...
ValueError: no vertex scheme (vertex_order, linker_sites, site_codes) in this structure: ...
Source code in cage_isomer_builder/utils/vertex_codes.py
environment_label ¶
The environment label of a vertex code: its rotation (by whole linkers) that sorts first with 5 < 1 < 4 < 0, or A < B < ... < 0.
Examples:
>>> from cage_isomer_builder.utils.vertex_codes import environment_label
>>> environment_label("141"), environment_label("401"), environment_label("041")
('114', '140', '104')
>>> environment_label("00.10.05"), environment_label("0B.A0.00")
('10.05.00', 'A0.00.0B')
Source code in cage_isomer_builder/utils/vertex_codes.py
mirror_code ¶
The code of the mirror image of a vertex, read from the same linker: left and right swap (1 <-> 4, or the two characters of each pair) and the linkers are read the other way round.
Examples:
>>> from cage_isomer_builder.utils.vertex_codes import mirror_code
>>> mirror_code("140"), mirror_code("10.00.05"), mirror_code("A0.0B.00")
('014', '05.00.40', '00.B0.0A')
Source code in cage_isomer_builder/utils/vertex_codes.py
mirror_label ¶
Environment label of the mirror image of a vertex (see
:func:mirror_code).
Examples:
>>> from cage_isomer_builder.utils.vertex_codes import mirror_label
>>> mirror_label("114"), mirror_label("110"), mirror_label("140")
('144', '440', '140')
>>> mirror_label("A0.0B.00")
'B0.0A.00'
Source code in cage_isomer_builder/utils/vertex_codes.py
environments ¶
Every environment label of a vertex with n_linkers linkers, one
group per linker on four-site linkers, sorted with 1 < 4 < 0.
Examples:
>>> from cage_isomer_builder.utils.vertex_codes import environments
>>> labels = environments(3)
>>> len(labels), labels
(11, ['111', '114', '110', '144', '140', '104', '100', '444', '440', '400', '000'])
Source code in cage_isomer_builder/utils/vertex_codes.py
site_name ¶
Site name of an isomer, as isomer files are named: its sites joined by
-, or {group: sites} as NH2-0-5_OH-1 (bare if empty).
Examples:
>>> from cage_isomer_builder.utils.vertex_codes import site_name
>>> site_name([0, 4, 9]), site_name({"NH2": [0, 5], "OH": [1]})
('0-4-9', 'NH2-0-5_OH-1')
Source code in cage_isomer_builder/utils/vertex_codes.py
scheme_from_geometry ¶
scheme_from_geometry(site_positions, linker_sites, linker_vertices, linker_centres, vertex_centres, centre, tol: float = 0.2, midway: float = 0.02) -> VertexScheme
Work out the vertex scheme of a cage from its geometry.
Every site is next to the closer of the linker's two vertices; the sites on one side next to one vertex get depths 1, 2, ... from the closest. Linkers may have any number of sites.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
site_positions
|
(array, shape(n_sites, 3))
|
|
required |
linker_sites
|
sequence of sequence of int
|
The sites of each linker. |
required |
linker_vertices
|
sequence of (int, int)
|
The two vertices each linker joins. |
required |
linker_centres
|
(array, shape(n, 3))
|
|
required |
vertex_centres
|
(array, shape(n, 3))
|
|
required |
centre
|
(array, shape(3))
|
Pore centre: left, right and clockwise are as seen from here. |
required |
tol
|
float
|
Smallest sine of the angle that still tells left from right, or one linker from the next around a vertex. |
0.2
|
midway
|
float
|
Smallest difference (relative to the linker length) between a site's distances to the two vertices, or between two sites on one side: closer is ambiguous. |
0.02
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If a site is neither left nor right, or midway between the vertices, two sites on one side cannot be ordered, or the linkers of a vertex cannot be put in order around it. |
Examples:
One linker along z from vertex 0 (bottom) to vertex 1, its ring facing a pore centre at -x. Looking from there with vertex 0 at the bottom, -y is on the right; turned round for vertex 1, +y is:
>>> import numpy as np
>>> from cage_isomer_builder.utils.vertex_codes import scheme_from_geometry
>>> sites = np.array([[0, -1, -1], [0, -1, 1], [0, 1, 1], [0, 1, -1]], float)
>>> scheme = scheme_from_geometry(sites, [[0, 1, 2, 3]], [(0, 1)], [[0, 0, 0]],
... [[0, 0, -3], [0, 0, 3]], [-5, 0, 0])
>>> scheme.site_codes
{0: (0, 4), 1: (1, 1), 2: (1, 4), 3: (0, 1)}
A biphenyl: two sites on each side at each end, the outer ones at depth 2:
>>> sites = np.array([[0, y, z] for z in (-3, -1, 1, 3) for y in (-1, 1)], float)
>>> scheme = scheme_from_geometry(sites, [range(8)], [(0, 1)], [[0, 0, 0]],
... [[0, 0, -5], [0, 0, 5]], [-5, 0, 0])
>>> [scheme.view(s) for s in range(4)]
[(0, 4, 1), (0, 1, 1), (0, 4, 2), (0, 1, 2)]
Source code in cage_isomer_builder/utils/vertex_codes.py
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 | |