Skip to content

Cage builders

CageBuilder is the base class every topology-specific builder inherits from; it holds the full build, optimise, enumerate, functionalise, save, and statistics API. Topology-specific classes (Tri4Di6CageBuilder, M6L12CubeCageBuilder, ...) only override the topology graph and the point-group transformation library. See Topologies for the full list.

CageBuilder

CageBuilder(linker: MoleculeInput = None, node: MoleculeInput = None, linker_fg=None, node_fg=None, node_fg_count: int = None, smarts_pattern: str = None, optimizer_step: float = 0.01, distance_threshold: float = 5.0, expansion_factor: float = 1.0, scale_multiplier: float = 1.0, linker_smiles: str = None, node_smiles: str = None)

Bases: ABC

Base class for building cages and enumerating their isomers.

Each subclass sets one STK topology graph and, optionally, a symmetry library. The shared workflow is: build, optimise, functionalise, count or enumerate isomers, then compute statistics and descriptors. Structures from files (a MOF CIF, a cage from elsewhere) enter the same workflow through :meth:load_from_file.

Optimise a built cage before functionalising it. STK can place bulky nodes away from their linkers, and functionalise() warns when the building blocks are not bonded.

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
>>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
>>> _ = cage.build()                                  # STK assembly
>>> _ = cage.optimise(include_charges=False, logfile=None)   # UFF4MOF, rigid building blocks
>>> anchors, slots = cage.functionalise()             # every aromatic C-H becomes an R site
>>> cage.point_group().name, cage.count_unique_isomers_burnside()
('Td', 176)

Initialise a cage builder.

The linker and node may be a SMILES string, an ASE Atoms object, or a structure file readable by ASE (.xyz, .mol, .mol2, .sdf, .pdb, .cif, ...).

Functional groups (the connection points) are found in this order:

  1. Single atom (nodes only): a node of one atom (e.g. "[Zn]") becomes an stk.SingleAtom building block.
  2. Dummy atoms: X atoms in a structure, or *, [*] or [#0] in a SMILES string, mark the connection points. SMILES dummies are rewritten as [Fr] placeholders (STK cannot build atomic number 0) and matched by the SMARTS [Fr][*].
  3. Given factory: linker_fg or node_fg.
  4. Automatic: the factories of FG_FACTORY_MAP are tried in turn.

Parameters:

Name Type Description Default
linker MoleculeInput

Linker building block. Defaults to default_linker.

None
node MoleculeInput

Node building block. Defaults to default_node.

None
linker_fg str or FunctionalGroupFactory

Functional-group factory of the linker: a key of FG_FACTORY_MAP, a factory instance, or None for automatic detection.

None
node_fg str or FunctionalGroupFactory

Functional-group factory of the node. "single_atom" for an isolated metal, None for automatic detection. The default node uses default_node_fg; a given node defaults to automatic detection.

None
node_fg_count int

Number of functional groups of a single-atom node (ignored otherwise). Defaults to default_node_fg_count.

None
smarts_pattern str

SMARTS pattern used when linker_fg or node_fg is "smarts".

None
optimizer_step float

Step size of the STK Collapser optimiser.

0.01
distance_threshold float

Distance threshold (Angstrom) of the STK Collapser optimiser.

5.0
expansion_factor float

After assembly, every building block is translated rigidly so that its distance from the cage centroid is multiplied by this factor. Use a value slightly above 1 when bulky nodes overlap their neighbours in the initial placement; the smallest factor is 2 * r_max / d for a node of outer radius r_max and vertex-vertex distance d (about 1.15 for uio66_tri_node).

1.0
scale_multiplier float

Passed to the STK topology graph, which scales its vertex positions by scale_multiplier times the largest building-block diameter. A bulky node next to a short linker (a Zr6 node with a phenylene) is then placed far from its linkers. To correct it, build once, note the node-node distance d0 and the distance you want d (linker length plus two metal-ligand bonds), and set scale_multiplier = d / d0.

1.0
linker_smiles str

Deprecated aliases of linker and node.

None
node_smiles str

Deprecated aliases of linker and node.

None
Source code in cage_isomer_builder/cage/base.py
def __init__(
    self,
    linker: MoleculeInput = None,
    node: MoleculeInput = None,
    linker_fg=None,
    node_fg=None,
    node_fg_count: int = None,
    smarts_pattern: str = None,
    optimizer_step: float = 0.01,
    distance_threshold: float = 5.0,
    expansion_factor: float = 1.0,
    scale_multiplier: float = 1.0,
    linker_smiles: str = None,
    node_smiles: str = None,
):
    """
    Initialise a cage builder.

    The linker and node may be a SMILES string, an ASE ``Atoms`` object, or a
    structure file readable by ASE (``.xyz``, ``.mol``, ``.mol2``, ``.sdf``,
    ``.pdb``, ``.cif``, ...).

    Functional groups (the connection points) are found in this order:

    1. **Single atom** (nodes only): a node of one atom (e.g. ``"[Zn]"``)
       becomes an ``stk.SingleAtom`` building block.
    2. **Dummy atoms**: ``X`` atoms in a structure, or ``*``, ``[*]`` or
       ``[#0]`` in a SMILES string, mark the connection points. SMILES dummies
       are rewritten as ``[Fr]`` placeholders (STK cannot build atomic number
       0) and matched by the SMARTS ``[Fr][*]``.
    3. **Given factory**: ``linker_fg`` or ``node_fg``.
    4. **Automatic**: the factories of ``FG_FACTORY_MAP`` are tried in turn.

    Parameters
    ----------
    linker : MoleculeInput, optional
        Linker building block. Defaults to ``default_linker``.
    node : MoleculeInput, optional
        Node building block. Defaults to ``default_node``.
    linker_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the linker: a key of ``FG_FACTORY_MAP``, a
        factory instance, or ``None`` for automatic detection.
    node_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the node. ``"single_atom"`` for an
        isolated metal, ``None`` for automatic detection. The default node uses
        ``default_node_fg``; a given node defaults to automatic detection.
    node_fg_count : int, optional
        Number of functional groups of a single-atom node (ignored otherwise).
        Defaults to ``default_node_fg_count``.
    smarts_pattern : str, optional
        SMARTS pattern used when ``linker_fg`` or ``node_fg`` is ``"smarts"``.
    optimizer_step : float, default 0.01
        Step size of the STK ``Collapser`` optimiser.
    distance_threshold : float, default 5.0
        Distance threshold (Angstrom) of the STK ``Collapser`` optimiser.
    expansion_factor : float, default 1.0
        After assembly, every building block is translated rigidly so that its
        distance from the cage centroid is multiplied by this factor. Use a value
        slightly above 1 when bulky nodes overlap their neighbours in the
        initial placement; the smallest factor is ``2 * r_max / d`` for a node of
        outer radius ``r_max`` and vertex-vertex distance ``d`` (about 1.15 for
        ``uio66_tri_node``).
    scale_multiplier : float, default 1.0
        Passed to the STK topology graph, which scales its vertex positions by
        ``scale_multiplier`` times the largest building-block diameter. A bulky
        node next to a short linker (a Zr6 node with a phenylene) is then placed
        far from its linkers. To correct it, build once, note the node-node
        distance ``d0`` and the distance you want ``d`` (linker length plus two
        metal-ligand bonds), and set ``scale_multiplier = d / d0``.
    linker_smiles, node_smiles : str, optional
        Deprecated aliases of ``linker`` and ``node``.
    """

    # Input normalization
    linker_input = linker if linker is not None else linker_smiles
    node_input = node if node is not None else node_smiles

    self.linker = normalize_molecule_input(
        mol=linker_input,
        default=self.default_linker,
    )

    self.node = normalize_molecule_input(
        mol=node_input,
        default=self.default_node,
    )

    self.linker_fg = (
        linker_fg
        if linker_fg is not None
        else self.default_linker_fg
    )

    self.node_fg = (
        node_fg
        if node_fg is not None
        else self.default_node_fg
        if node_input is None
        else None
    )

    self.node_fg_count = (
        node_fg_count
        if node_fg_count is not None
        else self.default_node_fg_count
    )

    self.smarts_pattern = smarts_pattern
    self.optimizer_step = optimizer_step
    self.distance_threshold = distance_threshold
    self.expansion_factor = expansion_factor
    self.scale_multiplier = scale_multiplier

    # Internal state
    self._stk_cage = None
    self._ase_cage = None
    self._fg_anchors = None
    self._fg_anchor_indices = None
    self._fg_anchor_h_positions = None
    self._fg_per_linker = None
    self._linker_atom_indices = None
    self._node_centers = None

adjacency

adjacency() -> dict

Bond graph of the current structure: from the STK bond matrix for a built structure (whatever its geometry), otherwise from distances (:func:cage_isomer_builder.utils.features.bond_graph).

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
>>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
>>> _ = cage.build()
>>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
>>> _ = cage.functionalise()
>>> graph = cage.adjacency()                           # from the STK bond matrix
>>> zr = next(i for i, a in enumerate(cage.to_ase()) if a.symbol == "Zr")
>>> len(graph[zr])                                     # 8 oxygens around each Zr
8
Source code in cage_isomer_builder/cage/base.py
def adjacency(self) -> dict:
    """
    Bond graph of the current structure: from the STK bond matrix for a built
    structure (whatever its geometry), otherwise from distances
    (:func:`cage_isomer_builder.utils.features.bond_graph`).

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
    >>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
    ...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
    >>> _ = cage.build()
    >>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
    >>> _ = cage.functionalise()
    >>> graph = cage.adjacency()                           # from the STK bond matrix
    >>> zr = next(i for i, a in enumerate(cage.to_ase()) if a.symbol == "Zr")
    >>> len(graph[zr])                                     # 8 oxygens around each Zr
    8
    """
    atoms = self.to_ase()
    if self._stk_cage is not None:
        _, bond_matrix = stk_2_ase_atoms(self._stk_cage)
        if len(bond_matrix) == len(atoms):
            return features.adjacency_from_bond_matrix(atoms, bond_matrix)
    return features.bond_graph(atoms)

build

build() -> stk.ConstructedMolecule

Build the cage using the configured node and linker.

Returns:

Type Description
ConstructedMolecule

Constructed STK cage.

Notes

Building blocks are generated automatically from the supplied node and linker inputs before constructing the topology graph. If expansion_factor > 1, each subunit is translated rigidly outward after assembly (see :meth:_expand_cage_rigid).

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
>>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
>>> _ = cage.build()
>>> cage.to_ase().get_chemical_formula()
'C120H132O128Zr24'
Source code in cage_isomer_builder/cage/base.py
def build(self) -> stk.ConstructedMolecule:
    """
    Build the cage using the configured node and linker.

    Returns
    -------
    stk.ConstructedMolecule
        Constructed STK cage.

    Notes
    -----
    Building blocks are generated automatically from the supplied node
    and linker inputs before constructing the topology graph.
    If ``expansion_factor > 1``, each subunit is translated rigidly
    outward after assembly (see :meth:`_expand_cage_rigid`).

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
    >>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
    ...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
    >>> _ = cage.build()
    >>> cage.to_ase().get_chemical_formula()
    'C120H132O128Zr24'
    """
    node_bb = self._make_node_bb()
    linker_bb = self._make_linker_bb()

    try:
        self._stk_cage = stk.ConstructedMolecule(
            topology_graph=self._build_stk_topology(
                node_bb=node_bb,
                linker_bb=linker_bb,
            )
        )
    except UnboundLocalError as error:
        # stk.Collapser shrinks the cage until building blocks come
        # within distance_threshold of each other. When they already are
        # (common with bulky Zr6 nodes) its loop never runs and it fails
        # on an unassigned 'step_result'; the uncollapsed construction is
        # then the right result.
        if not self._use_collapser or 'step_result' not in str(error):
            raise
        self._use_collapser = False
        self._stk_cage = stk.ConstructedMolecule(
            topology_graph=self._build_stk_topology(
                node_bb=node_bb,
                linker_bb=linker_bb,
            )
        )

    if self.expansion_factor > 1.0:
        self._expand_cage_rigid()

    return self._stk_cage

building_blocks

building_blocks() -> tuple

Atom indices of every linker and every node.

Returns:

Name Type Description
linkers list of list of int

In the order used for FG slots (self._linker_atom_indices).

nodes list of list of int

One list per node (metal cluster with whatever is bonded to it outside the linkers).

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
>>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
>>> _ = cage.build()
>>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
>>> _ = cage.functionalise()
>>> linkers, nodes = cage.building_blocks()
>>> len(linkers), len(nodes), len(nodes[0])
(6, 4, 86)
Source code in cage_isomer_builder/cage/base.py
def building_blocks(self) -> tuple:
    """
    Atom indices of every linker and every node.

    Returns
    -------
    linkers : list of list of int
        In the order used for FG slots (``self._linker_atom_indices``).
    nodes : list of list of int
        One list per node (metal cluster with whatever is bonded to it
        outside the linkers).

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
    >>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
    ...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
    >>> _ = cage.build()
    >>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
    >>> _ = cage.functionalise()
    >>> linkers, nodes = cage.building_blocks()
    >>> len(linkers), len(nodes), len(nodes[0])
    (6, 4, 86)
    """
    if self._fg_anchors is None:
        self.functionalise()
    atoms = self.to_ase()
    if self._stk_cage is not None:
        bb_atoms, bb_is_node = self._classify_atoms_by_bb(atoms)
        nodes = [list(v) for k, v in bb_atoms.items() if bb_is_node[k]]
        return [list(lk) for lk in self._linker_atom_indices], nodes
    in_linker = {i for lk in self._linker_atom_indices for i in lk}
    rest = [i for i in range(len(atoms)) if i not in in_linker]
    adjacency = self.adjacency()
    rest_set, seen, nodes = set(rest), set(), []
    for start in rest:
        if start in seen:
            continue
        comp, stack = [], [start]
        seen.add(start)
        while stack:
            a = stack.pop()
            comp.append(a)
            for b in adjacency[a]:
                if b in rest_set and b not in seen:
                    seen.add(b)
                    stack.append(b)
        nodes.append(sorted(comp))
    # Metal-metal contacts are not in the bond graph, so merge components
    # whose metals are within 3.6 Angstrom of each other.
    return [list(lk) for lk in self._linker_atom_indices], self._merge_metal_clusters(atoms, nodes)

count_defect_isomers

count_defect_isomers(n_missing_linkers=1, groups='A', linker_patterns: Optional[dict] = None) -> int

Number of symmetry-unique structures with n_missing_linkers linkers removed and the groups placed on the others (groups="" for bare linkers), from Burnside's lemma. A missing linker is a linker pattern whose sites all carry a vacancy label. With several linker types, n_missing_linkers is {type name: number} and groups or linker_patterns can be given per type.

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
>>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
>>> _ = cage.build()
>>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
>>> _ = cage.functionalise()
>>> cage.count_defect_isomers(1, groups="A")      # one linker missing, A on the other five
256
>>> cage.count_defect_isomers(1, groups="")       # bare: all six edges are equivalent
1
Source code in cage_isomer_builder/cage/base.py
def count_defect_isomers(self, n_missing_linkers=1, groups="A",
                         linker_patterns: Optional[dict] = None) -> int:
    """
    Number of symmetry-unique structures with ``n_missing_linkers`` linkers
    removed and the groups placed on the others (``groups=""`` for bare
    linkers), from Burnside's lemma. A missing linker is a linker pattern whose
    sites all carry a vacancy label. With several linker types,
    ``n_missing_linkers`` is ``{type name: number}`` and ``groups`` or
    ``linker_patterns`` can be given per type.

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
    >>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
    ...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
    >>> _ = cage.build()
    >>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
    >>> _ = cage.functionalise()
    >>> cage.count_defect_isomers(1, groups="A")      # one linker missing, A on the other five
    256
    >>> cage.count_defect_isomers(1, groups="")       # bare: all six edges are equivalent
    1
    """
    patterns = self._with_vacancies(groups, linker_patterns, n_missing_linkers)
    return self.count_rgroup_isomers(groups=groups, linker_patterns=patterns)

count_node_defect_isomers

count_node_defect_isomers(n_missing_nodes: int = 1) -> int

Symmetry-unique ways of removing n_missing_nodes nodes (linkers unfunctionalised), via Burnside's lemma on the node permutations.

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
>>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
>>> _ = cage.build()
>>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
>>> _ = cage.functionalise()
>>> cage.count_node_defect_isomers(1), cage.count_node_defect_isomers(2)   # Td: all equivalent
(1, 1)
Source code in cage_isomer_builder/cage/base.py
def count_node_defect_isomers(self, n_missing_nodes: int = 1) -> int:
    """Symmetry-unique ways of removing ``n_missing_nodes`` nodes (linkers
    unfunctionalised), via Burnside's lemma on the node permutations.

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
    >>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
    ...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
    >>> _ = cage.build()
    >>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
    >>> _ = cage.functionalise()
    >>> cage.count_node_defect_isomers(1), cage.count_node_defect_isomers(2)   # Td: all equivalent
    (1, 1)
    """
    group, nodes = self._node_group()
    n = len(nodes)
    if not 0 < n_missing_nodes <= n:
        raise ValueError(f"n_missing_nodes must be between 1 and {n}.")
    patterns = {"D": n_missing_nodes, "": n - n_missing_nodes}
    patterns = {k: v for k, v in patterns.items() if v}
    return rgroup.count_rgroup_isomers(group, n, 1, linker_patterns=patterns)

count_rgroup_isomers

count_rgroup_isomers(groups: Union[str, list] = 'AB', linker_patterns: Optional[dict] = None) -> int

Number of symmetry-unique isomers with several different groups placed at once, from Burnside's lemma.

Parameters:

Name Type Description Default
groups (str, list or dict)

Groups on every linker: "AB" one A and one B, "AAB" two A and one B, "A" one group per linker. A string is read one capital letter per group; give longer names as a list, e.g. ["NH2", "OH"]. With several linker types, a dict {type name: groups} gives each type its own groups (e.g. {"C6H4": "A", "C10H8N2": ""}).

"AB"
linker_patterns dict

Fixed numbers of linkers per pattern instead: {"A": 3, "B": 3} (three linkers with A, three with B) or {"AB": 2, "": 4} (four bare linkers). With several linker types, {type name: {pattern: number}}. Overrides groups.

None

Returns:

Type Description
int

Raises:

Type Description
ValueError

If the specification does not fit the linkers, or the symmetry operations do not form a group on the sites.

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
>>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
>>> _ = cage.build()
>>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
>>> _ = cage.functionalise()
>>> cage.count_rgroup_isomers("AB")                    # one A and one B on every linker
124464
>>> cage.count_rgroup_isomers(linker_patterns={"A": 3, "B": 3})   # 50:50 linkers
3424
Source code in cage_isomer_builder/cage/base.py
def count_rgroup_isomers(
    self,
    groups: Union[str, list] = "AB",
    linker_patterns: Optional[dict] = None,
) -> int:
    """
    Number of symmetry-unique isomers with several different groups placed at
    once, from Burnside's lemma.

    Parameters
    ----------
    groups : str, list or dict, default "AB"
        Groups on every linker: ``"AB"`` one A and one B, ``"AAB"`` two A and
        one B, ``"A"`` one group per linker. A string is read one capital letter
        per group; give longer names as a list, e.g. ``["NH2", "OH"]``. With
        several linker types, a dict ``{type name: groups}`` gives each type its
        own groups (e.g. ``{"C6H4": "A", "C10H8N2": ""}``).
    linker_patterns : dict, optional
        Fixed numbers of linkers per pattern instead: ``{"A": 3, "B": 3}``
        (three linkers with A, three with B) or ``{"AB": 2, "": 4}`` (four bare
        linkers). With several linker types, ``{type name: {pattern: number}}``.
        Overrides ``groups``.

    Returns
    -------
    int

    Raises
    ------
    ValueError
        If the specification does not fit the linkers, or the symmetry
        operations do not form a group on the sites.

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
    >>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
    ...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
    >>> _ = cage.build()
    >>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
    >>> _ = cage.functionalise()
    >>> cage.count_rgroup_isomers("AB")                    # one A and one B on every linker
    124464
    >>> cage.count_rgroup_isomers(linker_patterns={"A": 3, "B": 3})   # 50:50 linkers
    3424
    """
    group = self.slot_group()
    return rgroup.count_rgroup_isomers(
        group, len(self._fg_anchors), self._layout,
        groups=groups, linker_patterns=linker_patterns,
    )

count_unique_isomers_burnside

count_unique_isomers_burnside(active_per_linker: int = 1) -> int

Number of symmetry-unique isomers, from Burnside's lemma, without enumerating them.

Parameters:

Name Type Description Default
active_per_linker int

Number of groups on every linker: 1 gives the isomers of :meth:enumerate_isomers, 2 the ways of placing two identical groups on every linker, and so on. k and fg_per_linker - k give the same count.

1

Returns:

Type Description
int

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
>>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
>>> _ = cage.build()
>>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
>>> _ = cage.functionalise()
>>> cage.count_unique_isomers_burnside(), cage.count_unique_isomers_burnside(active_per_linker=2)
(176, 2013)
Source code in cage_isomer_builder/cage/base.py
def count_unique_isomers_burnside(self, active_per_linker: int = 1) -> int:
    """
    Number of symmetry-unique isomers, from Burnside's lemma, without
    enumerating them.

    Parameters
    ----------
    active_per_linker : int, default 1
        Number of groups on every linker: 1 gives the isomers of
        :meth:`enumerate_isomers`, 2 the ways of placing two identical groups on
        every linker, and so on. ``k`` and ``fg_per_linker - k`` give the same
        count.

    Returns
    -------
    int

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
    >>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
    ...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
    >>> _ = cage.build()
    >>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
    >>> _ = cage.functionalise()
    >>> cage.count_unique_isomers_burnside(), cage.count_unique_isomers_burnside(active_per_linker=2)
    (176, 2013)
    """
    # k identical groups per linker is groups="A" * k. The linker-cycle
    # formula of utils.rgroup stays fast for large periodic cells, where
    # the bitmask tables of utils.util do not.
    if self._fg_anchors is None:
        self.functionalise()
    fg_per_linker = min(self._layout.sizes)
    if not 0 <= active_per_linker <= fg_per_linker:
        raise ValueError(
            f"active_per_linker={active_per_linker} must be between 0 and "
            f"fg_per_linker={fg_per_linker}."
        )
    return self.count_rgroup_isomers(groups="A" * active_per_linker)

distance_scaling

distance_scaling(factors=(0.95, 1.0, 1.05))

FG site-pair distances at each scale factor and their slopes (see :func:cage_isomer_builder.utils.flexibility.distance_scaling).

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
>>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
>>> _ = cage.build()
>>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
>>> _ = cage.functionalise()
>>> pairs, distances, slopes = cage.distance_scaling((0.95, 1.0, 1.05))
>>> pairs.shape, distances.shape
((276, 2), (3, 276))
Source code in cage_isomer_builder/cage/base.py
def distance_scaling(self, factors=(0.95, 1.0, 1.05)):
    """
    FG site-pair distances at each scale factor and their slopes (see
    :func:`cage_isomer_builder.utils.flexibility.distance_scaling`).

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
    >>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
    ...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
    >>> _ = cage.build()
    >>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
    >>> _ = cage.functionalise()
    >>> pairs, distances, slopes = cage.distance_scaling((0.95, 1.0, 1.05))
    >>> pairs.shape, distances.shape
    ((276, 2), (3, 276))
    """
    linkers, nodes = self.building_blocks()
    return flexibility.distance_scaling(self.to_ase(), linkers + nodes,
                                        self._fg_anchor_indices, factors,
                                        self.pore_centre())

enumerate_defect_isomers

enumerate_defect_isomers(n_missing_linkers=1, groups='A', linker_patterns: Optional[dict] = None, output_path: Optional[str] = None, generate_files: bool = True, limit: Optional[int] = None)

Enumerate the structures counted by :meth:count_defect_isomers.

The missing linkers are deleted; the exposed node sites are left open (the same for cages, MOFs and COFs). Each file holds the R sites of the remaining linkers.

Returns:

Type Description
list of (RGroupIsomer, ase.Atoms)

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
>>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
>>> _ = cage.build()
>>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
>>> _ = cage.functionalise()
>>> iso, atoms = cage.enumerate_defect_isomers(1, groups="", generate_files=False)[0]
>>> len(cage.to_ase()) - len(atoms)               # one 10-atom linker removed
10
Source code in cage_isomer_builder/cage/base.py
def enumerate_defect_isomers(self, n_missing_linkers=1, groups="A",
                             linker_patterns: Optional[dict] = None,
                             output_path: Optional[str] = None,
                             generate_files: bool = True, limit: Optional[int] = None):
    """
    Enumerate the structures counted by :meth:`count_defect_isomers`.

    The missing linkers are deleted; the exposed node sites are left
    open (the same for cages, MOFs and COFs). Each file holds the R sites
    of the remaining linkers.

    Returns
    -------
    list of (RGroupIsomer, ase.Atoms)

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
    >>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
    ...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
    >>> _ = cage.build()
    >>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
    >>> _ = cage.functionalise()
    >>> iso, atoms = cage.enumerate_defect_isomers(1, groups="", generate_files=False)[0]
    >>> len(cage.to_ase()) - len(atoms)               # one 10-atom linker removed
    10
    """
    if self._fg_anchors is None:
        self.functionalise()
    patterns = self._with_vacancies(groups, linker_patterns, n_missing_linkers)
    isomers = self.enumerate_rgroup_isomers(groups=groups, linker_patterns=patterns,
                                            generate_files=False, limit=limit)
    offsets = self._layout.offsets
    out = []
    if generate_files and output_path:
        os.makedirs(output_path, exist_ok=True)
    for iso in isomers:
        atoms = rgroup.build_rgroup_isomer_atoms(
            self._ase_cage, self._fg_anchors, iso, self._fg_anchor_indices,
            self._fg_anchor_h_positions,
        )
        vac = (iso.labels.index(ensemble.VACANCY) + 1
               if ensemble.VACANCY in iso.labels else None)
        remove = set()
        for L, start in enumerate(offsets):
            if vac is not None and iso.site_labels[start] == vac:
                remove.update(self._linker_atom_indices[self._slot_linkers[L]])
        atoms = atoms[[i for i in range(len(atoms)) if i not in remove]]
        # Renumber the groups R1, R2, ... without the vacancy label.
        kept = [l for l in iso.labels if l != ensemble.VACANCY]
        renumber = np.zeros(len(iso.labels) + 1, dtype=int)
        for k, l in enumerate(iso.labels):
            if l != ensemble.VACANCY:
                renumber[k + 1] = kept.index(l) + 1
        atoms.set_array("rgroup", renumber[atoms.arrays["rgroup"]])
        atoms.info["rgroup_labels"] = " ".join(kept)
        atoms.info["missing_linkers"] = n_missing_linkers
        name = iso.name.replace(ensemble.VACANCY, "vac")
        atoms.info["isomer"] = name
        if generate_files and output_path:
            from cage_isomer_builder.utils.sites import write_isomer
            write_isomer(os.path.join(output_path, f"{name}.xyz"), atoms)
        out.append((iso, atoms))
    return out

enumerate_isomers

enumerate_isomers(output_path: str = None, generate_files: bool = True, limit: int = None, naming: str = 'sites') -> list

Enumerate the symmetry-unique isomers with one group on every linker.

Each candidate is checked against its own symmetry orbit, so memory use does not grow with the number of linkers; the run time grows with the number of raw placements unless limit stops early.

Parameters:

Name Type Description Default
output_path str

Directory for one extended XYZ file per isomer. Nothing is written if None or if generate_files is False.

None
generate_files bool
True
limit int

Stop after this many isomers. Canonical representatives occur about once per |symmetry group| raw placements, so a modest limit is fast even when the full enumeration is not.

None
naming (sites, vertex)

File names: the active site indices (0-4-9-13-16-22.xyz) or the vertex name (000-100-141-401.xyz, see :meth:vertex_scheme). Whenever the cage has vertex codes, every file records both names (info["isomer"] and info["vertex_name"]) and the environment labels (info["vertex_labels"], e.g. 000-100-114-140), whichever naming is used.

"sites"

Returns:

Type Description
list of list of int

The active site indices of each isomer.

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
>>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
>>> _ = cage.build()
>>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
>>> _ = cage.functionalise()
>>> import os, tempfile
>>> folder = tempfile.mkdtemp()
>>> isomers = cage.enumerate_isomers(output_path=folder, limit=3)
>>> isomers[0], sorted(os.listdir(folder))[0]
([0, 4, 8, 12, 16, 20], '0-4-8-12-16-20.xyz')
>>> from cage_isomer_builder.utils.sites import read_isomer
>>> info = read_isomer(os.path.join(folder, "0-4-8-12-16-20.xyz")).info
>>> info["vertex_linkers"]      # vertex 2 joins linkers 1, 3 and 5
'0:0,1,2 1:0,3,4 2:1,3,5 3:2,4,5'
>>> info["linker_sites"]        # linker 1 owns sites 4 to 7
'0:0-3 1:4-7 2:8-11 3:12-15 4:16-19 5:20-23'
>>> info["vertex_name"], info["vertex_labels"]
('000-100-110-111', '000-100-110-111')
>>> by_vertex = tempfile.mkdtemp()
>>> _ = cage.enumerate_isomers(output_path=by_vertex, limit=3, naming="vertex")
>>> name = sorted(os.listdir(by_vertex))[0]
>>> name, read_isomer(os.path.join(by_vertex, name)).info["isomer"]
('000-100-110-111.xyz', '0-4-8-12-16-20')
Source code in cage_isomer_builder/cage/base.py
def enumerate_isomers(
    self,
    output_path: str = None,
    generate_files: bool = True,
    limit: int = None,
    naming: str = "sites",
) -> list:
    """
    Enumerate the symmetry-unique isomers with one group on every linker.

    Each candidate is checked against its own symmetry orbit, so memory use does
    not grow with the number of linkers; the run time grows with the number of
    raw placements unless ``limit`` stops early.

    Parameters
    ----------
    output_path : str, optional
        Directory for one extended XYZ file per isomer. Nothing is written if
        None or if ``generate_files`` is False.
    generate_files : bool, default True
    limit : int, optional
        Stop after this many isomers. Canonical representatives occur about
        once per |symmetry group| raw placements, so a modest limit is fast even
        when the full enumeration is not.
    naming : {"sites", "vertex"}, default "sites"
        File names: the active site indices (``0-4-9-13-16-22.xyz``) or
        the vertex name (``000-100-141-401.xyz``, see
        :meth:`vertex_scheme`). Whenever the cage has vertex codes, every
        file records both names (``info["isomer"]`` and
        ``info["vertex_name"]``) and the environment labels
        (``info["vertex_labels"]``, e.g. ``000-100-114-140``), whichever
        naming is used.

    Returns
    -------
    list of list of int
        The active site indices of each isomer.

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
    >>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
    ...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
    >>> _ = cage.build()
    >>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
    >>> _ = cage.functionalise()
    >>> import os, tempfile
    >>> folder = tempfile.mkdtemp()
    >>> isomers = cage.enumerate_isomers(output_path=folder, limit=3)
    >>> isomers[0], sorted(os.listdir(folder))[0]
    ([0, 4, 8, 12, 16, 20], '0-4-8-12-16-20.xyz')
    >>> from cage_isomer_builder.utils.sites import read_isomer
    >>> info = read_isomer(os.path.join(folder, "0-4-8-12-16-20.xyz")).info
    >>> info["vertex_linkers"]      # vertex 2 joins linkers 1, 3 and 5
    '0:0,1,2 1:0,3,4 2:1,3,5 3:2,4,5'
    >>> info["linker_sites"]        # linker 1 owns sites 4 to 7
    '0:0-3 1:4-7 2:8-11 3:12-15 4:16-19 5:20-23'
    >>> info["vertex_name"], info["vertex_labels"]
    ('000-100-110-111', '000-100-110-111')
    >>> by_vertex = tempfile.mkdtemp()
    >>> _ = cage.enumerate_isomers(output_path=by_vertex, limit=3, naming="vertex")
    >>> name = sorted(os.listdir(by_vertex))[0]
    >>> name, read_isomer(os.path.join(by_vertex, name)).info["isomer"]
    ('000-100-110-111.xyz', '0-4-8-12-16-20')
    """
    if naming not in ("sites", "vertex"):
        raise ValueError(f"naming={naming!r}; use 'sites' or 'vertex'.")
    if self._fg_anchors is None:
        self.functionalise()

    scheme = None
    if naming == "vertex":
        scheme = self.vertex_scheme()          # raises if the cage has no vertex codes
    elif generate_files and output_path:
        try:
            scheme = self.vertex_scheme()
        except ValueError:
            scheme = None                      # e.g. a MOF: files keep the site names only

    if generate_files and output_path:
        os.makedirs(output_path, exist_ok=True)

    if self._fg_per_linker is None:
        # Linkers with different numbers of slots: the same isomers come
        # from the R-group enumeration with one group per linker.
        descriptors = (
            [i for i, v in enumerate(iso.site_labels) if v]
            for iso in rgroup.iter_rgroup_isomers(
                self.slot_group(), len(self._fg_anchors), self._layout,
                groups="A", limit=limit)
        )
    else:
        fg_per_linker = self._fg_per_linker
        n_linkers = len(self._fg_anchors) // fg_per_linker
        tl = self._get_transformation_library(self._fg_anchors.copy())
        descriptors = (d for _, d in iter_unique_isomers(tl, n_linkers, fg_per_linker,
                                                          limit=limit))

    unique_isomers = []
    for descriptor in descriptors:
        unique_isomers.append(descriptor)

        if generate_files and output_path:
            name, info = None, None
            if scheme is not None:
                vertex_name = scheme.name(descriptor)
                info = {"vertex_name": vertex_name,
                        "vertex_labels": "-".join(scheme.labels(descriptor)),
                        **scheme.to_info()}
                if naming == "vertex":
                    name = vertex_name
            generate_isomer_structure_file(
                self._ase_cage,
                self._fg_anchors,
                descriptor,
                self._fg_anchor_indices,
                output_path,
                fg_anchor_h_positions=self._fg_anchor_h_positions,
                name=name,
                info=info,
            )

    return unique_isomers

enumerate_node_defect_isomers

enumerate_node_defect_isomers(n_missing_nodes: int = 1, output_path: Optional[str] = None, generate_files: bool = True) -> list

The structures counted by :meth:count_node_defect_isomers: each missing node is deleted with all its atoms; the linker ends left behind stay open. FG slots are restored to H.

Returns:

Type Description
list of (tuple of removed node indices, ase.Atoms)

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
>>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
>>> _ = cage.build()
>>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
>>> _ = cage.functionalise()
>>> removed, atoms = cage.enumerate_node_defect_isomers(1, generate_files=False)[0]
>>> removed, len(cage.to_ase()) - len(atoms)      # one 86-atom Zr6 node removed
((0,), 86)
Source code in cage_isomer_builder/cage/base.py
def enumerate_node_defect_isomers(self, n_missing_nodes: int = 1,
                                  output_path: Optional[str] = None,
                                  generate_files: bool = True) -> list:
    """
    The structures counted by :meth:`count_node_defect_isomers`: each
    missing node is deleted with all its atoms; the linker ends left
    behind stay open. FG slots are restored to H.

    Returns
    -------
    list of (tuple of removed node indices, ase.Atoms)

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
    >>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
    ...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
    >>> _ = cage.build()
    >>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
    >>> _ = cage.functionalise()
    >>> removed, atoms = cage.enumerate_node_defect_isomers(1, generate_files=False)[0]
    >>> removed, len(cage.to_ase()) - len(atoms)      # one 86-atom Zr6 node removed
    ((0,), 86)
    """
    from cage_isomer_builder.utils.sites import write_isomer

    group, nodes = self._node_group()
    n = len(nodes)
    if not 0 < n_missing_nodes <= n:
        raise ValueError(f"n_missing_nodes must be between 1 and {n}.")
    patterns = {k: v for k, v in {"D": n_missing_nodes, "": n - n_missing_nodes}.items() if v}
    isomers = rgroup.enumerate_rgroup_isomers(group, n, 1, linker_patterns=patterns)
    base = self.to_ase(hydrogens=True)
    if generate_files and output_path:
        os.makedirs(output_path, exist_ok=True)
    out = []
    for iso in isomers:
        removed = tuple(k for k, v in enumerate(iso.site_labels) if v)
        drop = {i for k in removed for i in nodes[k]}
        atoms = base[[i for i in range(len(base)) if i not in drop]]
        atoms.info["missing_nodes"] = " ".join(map(str, removed))
        if generate_files and output_path:
            write_isomer(os.path.join(output_path,
                                      "nodes-" + "-".join(map(str, removed)) + ".xyz"), atoms)
        out.append((removed, atoms))
    return out

enumerate_rgroup_isomers

enumerate_rgroup_isomers(groups: Union[str, list] = 'AB', linker_patterns: Optional[dict] = None, output_path: str = None, generate_files: bool = True, limit: int = None, naming: str = 'sites') -> list

Enumerate the symmetry-unique isomers with several different groups.

Each isomer written to output_path is an extended XYZ file in which every active site is an R site (X atom) whose per-atom "rgroup" value says which group goes there (1 = first label, 2 = second, ...). :func:~cage_isomer_builder.utils.functionalise.functionalise_isomer_sites attaches the matching fragment at each site. A complete enumeration (limit=None) is checked against :meth:count_rgroup_isomers.

Parameters:

Name Type Description Default
groups Union[str, list]

As for :meth:count_rgroup_isomers.

'AB'
linker_patterns Union[str, list]

As for :meth:count_rgroup_isomers.

'AB'
output_path str

Directory for the structure files.

None
generate_files bool
True
limit int

Stop after this many isomers.

None
naming (sites, vertex)

File names: the groups' sites (NH2-0-4_OH-1-5.xyz) or the vertex name (AB.00.00-...xyz, see :meth:vertex_scheme). Whenever the cage has vertex codes, every file records both names (info["isomer"], info["vertex_name"]) and the environment labels (info["vertex_labels"]).

"sites"

Returns:

Type Description
list of RGroupIsomer

isomer.to_dict() gives {"A": [sites], "B": [sites], ...}.

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
>>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
>>> _ = cage.build()
>>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
>>> _ = cage.functionalise()
>>> first = cage.enumerate_rgroup_isomers(["NH2", "OH"], generate_files=False, limit=1)[0]
>>> first.to_dict()
{'NH2': [2, 6, 10, 14, 18, 22], 'OH': [3, 7, 11, 15, 19, 23]}

Files named by their vertex names:

>>> import os, tempfile
>>> folder = tempfile.mkdtemp()
>>> _ = cage.enumerate_rgroup_isomers(["NH2", "OH"], output_path=folder, limit=1,
...                                   naming="vertex")
>>> os.listdir(folder)
['AB.AB.AB-00.AB.AB-00.00.AB-00.00.00.xyz']
Source code in cage_isomer_builder/cage/base.py
def enumerate_rgroup_isomers(
    self,
    groups: Union[str, list] = "AB",
    linker_patterns: Optional[dict] = None,
    output_path: str = None,
    generate_files: bool = True,
    limit: int = None,
    naming: str = "sites",
) -> list:
    """
    Enumerate the symmetry-unique isomers with several different groups.

    Each isomer written to ``output_path`` is an extended XYZ file in which every
    active site is an R site (``X`` atom) whose per-atom ``"rgroup"`` value says
    which group goes there (1 = first label, 2 = second, ...).
    :func:`~cage_isomer_builder.utils.functionalise.functionalise_isomer_sites`
    attaches the matching fragment at each site. A complete enumeration
    (``limit=None``) is checked against :meth:`count_rgroup_isomers`.

    Parameters
    ----------
    groups, linker_patterns
        As for :meth:`count_rgroup_isomers`.
    output_path : str, optional
        Directory for the structure files.
    generate_files : bool, default True
    limit : int, optional
        Stop after this many isomers.
    naming : {"sites", "vertex"}, default "sites"
        File names: the groups' sites (``NH2-0-4_OH-1-5.xyz``) or the
        vertex name (``AB.00.00-...xyz``, see :meth:`vertex_scheme`).
        Whenever the cage has vertex codes, every file records both
        names (``info["isomer"]``, ``info["vertex_name"]``) and the
        environment labels (``info["vertex_labels"]``).

    Returns
    -------
    list of RGroupIsomer
        ``isomer.to_dict()`` gives ``{"A": [sites], "B": [sites], ...}``.

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
    >>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
    ...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
    >>> _ = cage.build()
    >>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
    >>> _ = cage.functionalise()
    >>> first = cage.enumerate_rgroup_isomers(["NH2", "OH"], generate_files=False, limit=1)[0]
    >>> first.to_dict()
    {'NH2': [2, 6, 10, 14, 18, 22], 'OH': [3, 7, 11, 15, 19, 23]}

    Files named by their vertex names:

    >>> import os, tempfile
    >>> folder = tempfile.mkdtemp()
    >>> _ = cage.enumerate_rgroup_isomers(["NH2", "OH"], output_path=folder, limit=1,
    ...                                   naming="vertex")
    >>> os.listdir(folder)
    ['AB.AB.AB-00.AB.AB-00.00.AB-00.00.00.xyz']
    """
    if naming not in ("sites", "vertex"):
        raise ValueError(f"naming={naming!r}; use 'sites' or 'vertex'.")
    group = self.slot_group()
    n_fg_slots = len(self._fg_anchors)
    scheme = None
    if naming == "vertex":
        scheme = self.vertex_scheme()          # raises if the cage has no vertex codes
    elif generate_files and output_path:
        try:
            scheme = self.vertex_scheme()
        except ValueError:
            scheme = None                      # e.g. a MOF: files keep the site names only
    isomers = rgroup.enumerate_rgroup_isomers(
        group, n_fg_slots, self._layout,
        groups=groups, linker_patterns=linker_patterns, limit=limit,
    )
    if generate_files and output_path:
        os.makedirs(output_path, exist_ok=True)
        for isomer in isomers:
            name, info = None, None
            if scheme is not None:
                vertex_name = scheme.name(isomer)
                info = {"vertex_name": vertex_name,
                        "vertex_labels": "-".join(scheme.labels(isomer)),
                        **scheme.to_info()}
                if naming == "vertex":
                    name = vertex_name
            rgroup.write_rgroup_isomer_file(
                self._ase_cage,
                self._fg_anchors,
                isomer,
                self._fg_anchor_indices,
                output_path,
                fg_anchor_h_positions=self._fg_anchor_h_positions,
                name=name,
                info=info,
            )
    return isomers

functionalise

functionalise(aromatic_only: bool = True)

Find the functional-group sites: every aromatic C-H of every linker becomes an R site (all linker types of a MOF with several, see :meth:slot_layout). aromatic_only=False also marks H on alkyl carbons.

Returns:

Name Type Description
fg_anchors Atoms

The site atoms.

fg_anchor_indices list of int

Index of each site atom in the structure.

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
>>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
>>> _ = cage.build()
>>> _ = cage.optimise(include_charges=False, logfile=None)
>>> anchors, slots = cage.functionalise()
>>> len(slots), set(cage.to_ase()[slots].get_chemical_symbols())   # 4 slots on each of 6 rings
(24, {'X'})
Source code in cage_isomer_builder/cage/base.py
def functionalise(self, aromatic_only: bool = True):
    """
    Find the functional-group sites: every aromatic C-H of every linker becomes
    an R site (all linker types of a MOF with several, see :meth:`slot_layout`).
    ``aromatic_only=False`` also marks H on alkyl carbons.

    Returns
    -------
    fg_anchors : ase.Atoms
        The site atoms.
    fg_anchor_indices : list of int
        Index of each site atom in the structure.

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
    >>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
    ...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
    >>> _ = cage.build()
    >>> _ = cage.optimise(include_charges=False, logfile=None)
    >>> anchors, slots = cage.functionalise()
    >>> len(slots), set(cage.to_ase()[slots].get_chemical_symbols())   # 4 slots on each of 6 rings
    (24, {'X'})
    """
    # Mark the sites on a copy and keep that as the builder's structure.
    functionalised = self.to_ase().copy()

    # For a built cage, building blocks come from STK's atom records,
    # which work even where blocks overlap in the initial placement.
    if self._stk_cage is not None:
        linker_atom_indices, metal_atom_indices = self._get_sbus_from_stk(functionalised)
        self._node_centers = self._get_node_centers_from_stk(functionalised)
        linker_types = [0] * len(linker_atom_indices)
        type_names = [functionalised[linker_atom_indices[0]].get_chemical_formula()]
    else:
        linker_atom_indices, linker_types, type_names, metal_atom_indices = \
            find_linkers(functionalised)
        self._node_centers = get_node_centers(functionalised, metal_atom_indices)

    self._linker_atom_indices = linker_atom_indices
    anchors, anchor_indices, h_positions = full_functionalisation(
        functionalised, sum(linker_atom_indices, []), aromatic_only=aromatic_only,
    )
    if not anchor_indices:
        raise ValueError("no aromatic C-H on any linker: nothing to functionalise.")
    self._set_slot_layout(functionalised, anchor_indices, h_positions,
                          linker_types, type_names)
    self._check_assembly()
    self._ase_cage = functionalised
    self._record_vertex_map()

    return self._fg_anchors, self._fg_anchor_indices

get_bond_matrix

get_bond_matrix() -> np.ndarray

Bond-order matrix of the built cage, taken from the STK construction rather than perceived from the geometry. It is correct even where bonded atoms are far apart, and it adds no bonds between atoms that are merely close. Used by the GULP and AMS writers and accepted by functionalise.place_guest_in_host(host_bond_matrix=...) and functionalise_isomer_sites(host_bond_matrix=...).

Returns:

Type Description
(ndarray, shape(n_atoms, n_atoms))

Raises:

Type Description
RuntimeError

If the structure was not built with :meth:build (a structure from :meth:load_from_file has no bond orders).

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
>>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
>>> _ = cage.build()
>>> bonds = cage.get_bond_matrix()
>>> bonds.shape, bool((bonds == bonds.T).all())
((404, 404), True)
Source code in cage_isomer_builder/cage/base.py
def get_bond_matrix(self) -> np.ndarray:
    """
    Bond-order matrix of the built cage, taken from the STK construction rather
    than perceived from the geometry. It is correct even where bonded atoms are
    far apart, and it adds no bonds between atoms that are merely close. Used by
    the GULP and AMS writers and accepted by
    ``functionalise.place_guest_in_host(host_bond_matrix=...)`` and
    ``functionalise_isomer_sites(host_bond_matrix=...)``.

    Returns
    -------
    np.ndarray, shape (n_atoms, n_atoms)

    Raises
    ------
    RuntimeError
        If the structure was not built with :meth:`build` (a structure from
        :meth:`load_from_file` has no bond orders).

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
    >>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
    ...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
    >>> _ = cage.build()
    >>> bonds = cage.get_bond_matrix()
    >>> bonds.shape, bool((bonds == bonds.T).all())
    ((404, 404), True)
    """
    if self._stk_cage is None:
        raise RuntimeError(
            "get_bond_matrix() requires the STK cage. Call build() "
            "first; a structure loaded via load_from_file() has no "
            "STK-derived bond order information."
        )
    _, bond_matrix = stk_2_ase_atoms(self._stk_cage)
    return bond_matrix

get_descriptor

get_descriptor(kinds=('fg', 'pi', 'donor', 'acceptor', 'open_metal'), by: str = 'kind', max_distance: Optional[float] = None, exclude_same_owner: bool = True, **feature_kwargs) -> distributions.Descriptor

Pair descriptor of every feature site of this (static) structure, including all cross terms between kinds. For a periodic structure pairs are counted over all images up to max_distance (default 20 Angstrom). See :mod:cage_isomer_builder.utils.distributions.

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
>>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
>>> _ = cage.build()
>>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
>>> _ = cage.functionalise()
>>> desc = cage.get_descriptor()
>>> desc.summary()[("fg", "pi")]            # 24 sites x 6 rings, minus each ring's own 4
(120, 120.0)
Source code in cage_isomer_builder/cage/base.py
def get_descriptor(self, kinds=("fg", "pi", "donor", "acceptor", "open_metal"),
                   by: str = "kind", max_distance: Optional[float] = None,
                   exclude_same_owner: bool = True, **feature_kwargs
                   ) -> "distributions.Descriptor":
    """
    Pair descriptor of every feature site of this (static) structure,
    including all cross terms between kinds. For a periodic structure
    pairs are counted over all images up to ``max_distance`` (default
    20 Angstrom). See :mod:`cage_isomer_builder.utils.distributions`.

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
    >>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
    ...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
    >>> _ = cage.build()
    >>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
    >>> _ = cage.functionalise()
    >>> desc = cage.get_descriptor()
    >>> desc.summary()[("fg", "pi")]            # 24 sites x 6 rings, minus each ring's own 4
    (120, 120.0)
    """
    fs = self.get_features(kinds=kinds, **feature_kwargs)
    if self.to_ase().pbc.any() and max_distance is None:
        max_distance = 20.0
    return distributions.pair_descriptor(fs, by=by, max_distance=max_distance,
                                         exclude_same_owner=exclude_same_owner)

get_ensemble_descriptor

get_ensemble_descriptor(groups='A', linker_patterns: Optional[dict] = None, n_missing_linkers: int = 0, mode: str = 'fixed', fractions: Optional[dict] = None, by: str = 'orientation', include_same_linker: bool = False, rotation_angles=None, angle_weights=None, threshold: float = 0.5, max_distance: Optional[float] = None) -> distributions.Descriptor

Exact FG pair descriptor averaged over every placement of the groups (several groups, partial functionalisation, missing linkers), optionally also over ring rotations. See :func:cage_isomer_builder.utils.ensemble.ensemble_descriptor.

Parameters:

Name Type Description Default
groups

As for :meth:count_rgroup_isomers.

'A'
linker_patterns

As for :meth:count_rgroup_isomers.

'A'
n_missing_linkers int or dict

Number of missing linkers (they carry no groups); {type name: number} when there are several linker types.

0
mode str

mode="independent" with fractions={pattern: fraction} describes any composition of a large crystal exactly.

'fixed'
fractions str

mode="independent" with fractions={pattern: fraction} describes any composition of a large crystal exactly.

'fixed'
by str

Pair types by group and endo/exo class, or by group only ("label").

"orientation"
include_same_linker bool

Also count pairs of two groups on one linker.

False
rotation_angles sequence of float

Ring rotation angles (degrees) to average over; every ring turns independently.

None
angle_weights sequence of float

One weight per angle (default uniform), e.g. Boltzmann weights from a torsion scan.

None
threshold float

Endo/exo cosine limit.

0.5
max_distance float

Periodic structures: pairs over all images up to this distance, per unit cell (default 20 Angstrom). Finite structures: an optional cutoff.

None

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
>>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
>>> _ = cage.build()
>>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
>>> _ = cage.functionalise()
>>> ens = cage.get_ensemble_descriptor(linker_patterns={"N": 3, "C": 3}, by="label")
>>> {key: round(weight, 3) for key, (_, weight) in ens.summary().items()}
{('fg:C', 'fg:C'): 3.0, ('fg:C', 'fg:N'): 9.0, ('fg:N', 'fg:N'): 3.0}
>>> flexible = cage.get_ensemble_descriptor(groups="A", rotation_angles=range(0, 360, 90))
>>> round(flexible.total(), 6)               # still 15 pairs of the 6 groups
15.0
Source code in cage_isomer_builder/cage/base.py
def get_ensemble_descriptor(self, groups="A", linker_patterns: Optional[dict] = None,
                            n_missing_linkers: int = 0, mode: str = "fixed",
                            fractions: Optional[dict] = None, by: str = "orientation",
                            include_same_linker: bool = False,
                            rotation_angles=None, angle_weights=None,
                            threshold: float = 0.5,
                            max_distance: Optional[float] = None,
                            ) -> "distributions.Descriptor":
    """
    Exact FG pair descriptor averaged over every placement of the groups
    (several groups, partial functionalisation, missing linkers), optionally
    also over ring rotations. See
    :func:`cage_isomer_builder.utils.ensemble.ensemble_descriptor`.

    Parameters
    ----------
    groups, linker_patterns
        As for :meth:`count_rgroup_isomers`.
    n_missing_linkers : int or dict, default 0
        Number of missing linkers (they carry no groups); ``{type name:
        number}`` when there are several linker types.
    mode, fractions
        ``mode="independent"`` with ``fractions={pattern: fraction}`` describes
        any composition of a large crystal exactly.
    by : str, default "orientation"
        Pair types by group and endo/exo class, or by group only (``"label"``).
    include_same_linker : bool, default False
        Also count pairs of two groups on one linker.
    rotation_angles : sequence of float, optional
        Ring rotation angles (degrees) to average over; every ring turns
        independently.
    angle_weights : sequence of float, optional
        One weight per angle (default uniform), e.g. Boltzmann weights from a
        torsion scan.
    threshold : float, default 0.5
        Endo/exo cosine limit.
    max_distance : float, optional
        Periodic structures: pairs over all images up to this distance, per
        unit cell (default 20 Angstrom). Finite structures: an optional cutoff.

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
    >>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
    ...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
    >>> _ = cage.build()
    >>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
    >>> _ = cage.functionalise()
    >>> ens = cage.get_ensemble_descriptor(linker_patterns={"N": 3, "C": 3}, by="label")
    >>> {key: round(weight, 3) for key, (_, weight) in ens.summary().items()}
    {('fg:C', 'fg:C'): 3.0, ('fg:C', 'fg:N'): 9.0, ('fg:N', 'fg:N'): 3.0}
    >>> flexible = cage.get_ensemble_descriptor(groups="A", rotation_angles=range(0, 360, 90))
    >>> round(flexible.total(), 6)               # still 15 pairs of the 6 groups
    15.0
    """
    if self._fg_anchors is None:
        self.functionalise()
    F = self._layout
    slots = self.slot_features(threshold=threshold)
    if mode != "independent":
        linker_patterns = self._with_vacancies(groups, linker_patterns, n_missing_linkers)
        groups = "A" if linker_patterns else groups
    kwargs = {}
    if rotation_angles is not None:
        atoms = self.to_ase()
        adjacency = self.adjacency()
        rotors = flexibility.find_rotors(atoms, self._linker_atom_indices, adjacency)
        pos, vec, ori, rotor_of_slot = flexibility.rotation_samples(
            atoms, rotors, self._fg_anchor_indices, rotation_angles,
            centre=self.pore_centre(), threshold=threshold, adjacency=adjacency,
        )
        kwargs = dict(positions=pos, vectors=vec, orientations=ori,
                      sample_weights=angle_weights,
                      rotor_of_slot=np.where(rotor_of_slot >= 0, rotor_of_slot,
                                             -1 - np.arange(len(rotor_of_slot))))
    if self.to_ase().pbc.any() and max_distance is None:
        max_distance = 20.0
    return ensemble.ensemble_descriptor(
        slots, F, groups=groups, linker_patterns=linker_patterns, mode=mode,
        fractions=fractions, by=by, include_same_linker=include_same_linker,
        max_distance=max_distance, **kwargs,
    )

get_features

get_features(kinds=('fg', 'pi', 'donor', 'acceptor', 'open_metal'), expected_cn: Optional[dict] = None, include_metal_bound: bool = False, threshold: float = 0.5, open_metal_method: str = 'auto') -> features.FeatureSet

Every feature site of the structure: FG slots, aromatic rings (with normals), H-bond donors/acceptors (with directions) and open metal sites (with the direction of the empty site). Owners are the building blocks (linkers first, then nodes), so pairs inside one building block can be excluded. Open metal sites come from mofstructure's geometric detector unless open_metal_method= "coordination". See :mod:cage_isomer_builder.utils.features.

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
>>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
>>> _ = cage.build()
>>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
>>> _ = cage.functionalise()
>>> cage.get_features().counts()            # R sites, rings, mu3-O acceptors; no open metals
{'acceptor': 32, 'fg': 24, 'pi': 6}
Source code in cage_isomer_builder/cage/base.py
def get_features(self, kinds=("fg", "pi", "donor", "acceptor", "open_metal"),
                 expected_cn: Optional[dict] = None, include_metal_bound: bool = False,
                 threshold: float = 0.5,
                 open_metal_method: str = "auto") -> "features.FeatureSet":
    """
    Every feature site of the structure: FG slots, aromatic rings
    (with normals), H-bond donors/acceptors (with directions) and open
    metal sites (with the direction of the empty site). Owners are the
    building blocks (linkers first, then nodes), so pairs inside one
    building block can be excluded. Open metal sites come from
    mofstructure's geometric detector unless ``open_metal_method=
    "coordination"``. See :mod:`cage_isomer_builder.utils.features`.

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
    >>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
    ...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
    >>> _ = cage.build()
    >>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
    >>> _ = cage.functionalise()
    >>> cage.get_features().counts()            # R sites, rings, mu3-O acceptors; no open metals
    {'acceptor': 32, 'fg': 24, 'pi': 6}
    """
    if self._fg_anchors is None:
        self.functionalise()
    atoms = self.to_ase()
    linkers, nodes = self.building_blocks()
    out = features.detect_features(
        atoms, kinds=[k for k in kinds if k != "fg"], owners=linkers + nodes,
        expected_cn=expected_cn, include_metal_bound=include_metal_bound,
        adjacency=self.adjacency(), open_metal_method=open_metal_method,
    )
    if "fg" in kinds:
        fs = self.slot_features(threshold=threshold)
        out = fs + out
    return out

get_statistics

get_statistics(n_kde_bins: int = 200, threshold: float = 0.5, max_distance: Optional[float] = None) -> CageStatistics

FG-FG distance statistics: every pair of sites on different linkers, once, split by where the sites point, with a smoothed curve.

A site is endo or exo by the direction of its C-site bond relative to the pore centre (see :func:cage_isomer_builder.utils.features.orientation_class): the cosine with the inward direction is above threshold (endo) or below -threshold (exo); otherwise the site is tangential and its pairs are counted in other_pairs. The counts are proportional to the average over all placements of one group per linker. For several groups, ratios, defects or flexibility, use :meth:get_ensemble_descriptor.

Parameters:

Name Type Description Default
n_kde_bins int

Number of points of the smoothed curve.

200
threshold float
0.5
max_distance float

Periodic structures: count pairs over all periodic images up to this distance, per unit cell (default 20 Angstrom).

None

Returns:

Type Description
CageStatistics

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
>>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
>>> _ = cage.build()
>>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
>>> _ = cage.functionalise()
>>> stats = cage.get_statistics()
>>> sum(stats.total_fg_pairs), sum(stats.other_pairs)    # face-on rings: tangential sites
(240, 240)
Source code in cage_isomer_builder/cage/base.py
def get_statistics(self, n_kde_bins: int = 200, threshold: float = 0.5,
                   max_distance: Optional[float] = None) -> CageStatistics:
    """
    FG-FG distance statistics: every pair of sites on different linkers, once,
    split by where the sites point, with a smoothed curve.

    A site is endo or exo by the direction of its C-site bond relative to the
    pore centre (see :func:`cage_isomer_builder.utils.features.orientation_class`):
    the cosine with the inward direction is above ``threshold`` (endo) or below
    ``-threshold`` (exo); otherwise the site is tangential and its pairs are
    counted in ``other_pairs``. The counts are proportional to the average over
    all placements of one group per linker. For several groups, ratios, defects
    or flexibility, use :meth:`get_ensemble_descriptor`.

    Parameters
    ----------
    n_kde_bins : int, default 200
        Number of points of the smoothed curve.
    threshold : float, default 0.5
    max_distance : float, optional
        Periodic structures: count pairs over all periodic images up to this
        distance, per unit cell (default 20 Angstrom).

    Returns
    -------
    CageStatistics

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
    >>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
    ...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
    >>> _ = cage.build()
    >>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
    >>> _ = cage.functionalise()
    >>> stats = cage.get_statistics()
    >>> sum(stats.total_fg_pairs), sum(stats.other_pairs)    # face-on rings: tangential sites
    (240, 240)
    """
    if self._fg_anchors is None:
        self.functionalise()

    n_fg_slots = len(self._fg_anchors)
    n_linkers = self._layout.n_linkers
    n_unique = self.count_unique_isomers_burnside()

    slots = self.slot_features(threshold=threshold)
    periodic = bool(self.to_ase().pbc.any())
    if periodic and max_distance is None:
        max_distance = 20.0
    desc = distributions.pair_descriptor(
        slots, by="orientation", max_distance=max_distance if periodic else None,
    )
    distance_keys, total = desc.histogram()
    if len(distance_keys) == 0:
        raise ValueError("no FG pairs between different linkers.")

    def column(cls_a, cls_b):
        key = tuple(sorted((f"fg:R1:{cls_a}", f"fg:R1:{cls_b}")))
        values, weights = desc.histogram([key]) if key in desc.pairs else ([], [])
        table = dict(zip(np.round(values, 2), weights))
        return [table.get(d, 0.0) for d in distance_keys]

    endo_endo = column("endo", "endo")
    endo_exo = column("endo", "exo")
    exo_exo = column("exo", "exo")
    other = [t - a - b - c for t, a, b, c in zip(total, endo_endo, endo_exo, exo_exo)]

    def as_int(x):
        return [int(round(v)) if abs(v - round(v)) < 1e-9 else float(v) for v in x]

    total, endo_endo, endo_exo, exo_exo, other = map(
        as_int, (total, endo_endo, endo_exo, exo_exo, other))
    kde_x, kde_y = kernel_density_estimation(
        list(distance_keys), [int(round(t)) for t in total], n_kde_bins)
    kde_x = np.asarray(kde_x).ravel()

    return CageStatistics(
        n_linkers=n_linkers,
        n_fg_slots=n_fg_slots,
        n_unique_isomers=n_unique,
        distance_keys=[float(d) for d in distance_keys],
        total_fg_pairs=total,
        endo_endo_pairs=endo_endo,
        endo_exo_pairs=endo_exo,
        exo_exo_pairs=exo_exo,
        kde_x=kde_x,
        kde_y=kde_y,
        other_pairs=other,
    )

load_from_file classmethod

load_from_file(path: str, primitive: bool = False, symprec: float = 0.01, **init_kwargs)

Create a builder from an existing structure instead of building one with STK. The structure can then be functionalised, analysed and enumerated.

Parameters:

Name Type Description Default
path str or Path

Structure file readable by ASE (PDB, CIF, XYZ, MOL, SDF, ...).

required
primitive bool

Replace a periodic cell by its primitive cell (see :func:~cage_isomer_builder.utils.symmetry.primitive_cell). A CIF often holds several primitive cells (four for a face-centred cell) and each multiplies the number of isomers. Every isomer then repeats in every primitive cell.

False
symprec float

spglib tolerance used when primitive=True.

1e-2
**init_kwargs

Passed to the constructor.

{}

Returns:

Type Description
CageBuilder

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage import CageBuilder
>>> len(CageBuilder.load_from_file(example_data.path("RUBTAK01")).to_ase())
440
>>> len(CageBuilder.load_from_file(example_data.path("RUBTAK01"), primitive=True).to_ase())
110
Source code in cage_isomer_builder/cage/base.py
@classmethod
def load_from_file(cls, path: str, primitive: bool = False,
                   symprec: float = 1e-2, **init_kwargs):
    """
    Create a builder from an existing structure instead of building one with
    STK. The structure can then be functionalised, analysed and enumerated.

    Parameters
    ----------
    path : str or pathlib.Path
        Structure file readable by ASE (PDB, CIF, XYZ, MOL, SDF, ...).
    primitive : bool, default False
        Replace a periodic cell by its primitive cell (see
        :func:`~cage_isomer_builder.utils.symmetry.primitive_cell`). A CIF often
        holds several primitive cells (four for a face-centred cell) and each
        multiplies the number of isomers. Every isomer then repeats in every
        primitive cell.
    symprec : float, default 1e-2
        spglib tolerance used when ``primitive=True``.
    **init_kwargs
        Passed to the constructor.

    Returns
    -------
    CageBuilder

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage import CageBuilder
    >>> len(CageBuilder.load_from_file(example_data.path("RUBTAK01")).to_ase())
    440
    >>> len(CageBuilder.load_from_file(example_data.path("RUBTAK01"), primitive=True).to_ase())
    110
    """
    instance = cls.__new__(cls)
    CageBuilder.__init__(instance, **init_kwargs)
    atoms = read(path)
    if primitive:
        atoms = symmetry.primitive_cell(atoms, symprec=symprec)
    instance._ase_cage = atoms
    return instance

optimise

optimise(fmax: float = 0.05, steps: int = 500, optimizer_cls=None, trajectory: Optional[str] = None, rigid_sbus: bool = True, include_charges: bool = True, charge: float = 0.0, method: str = 'UFF4MOF', logfile: Optional[str] = '-') -> Atoms

Optimise the cage geometry.

  • method="UFF4MOF" (default): the UFF4MOF force field with the STK bond orders and UFF atom types (see :mod:cage_isomer_builder.utils.optimise). The bonds are those of the construction, so atypical distances in the starting geometry do not change the connectivity.
  • method="GFN1-xTB" or "GFN2-xTB": tblite tight binding. It needs no bond orders or atom types, and so cannot be held to a bond matrix.

Call this after :meth:build and before :meth:functionalise. After :meth:functionalise, the site markers are removed before optimising and :meth:functionalise must be run again.

Parameters:

Name Type Description Default
fmax float

Force convergence threshold (eV/Angstrom).

0.05
steps int

Maximum number of steps.

500
optimizer_cls ASE optimizer class

Any ase.optimize class (LBFGS, BFGS, FIRE, ...). Default LBFGS.

None
trajectory str

Path of an ASE .traj file.

None
rigid_sbus bool

Keep every node and linker rigid (see :class:~cage_isomer_builder.utils.rigid_body.FixRigidBodies) and relax only their placement. The linker atoms bonded to a node stay free, so each metal-ligand bond can adjust without changing the rest of the linker. False relaxes every atom.

True
include_charges bool

Store partial charges on the result (set_initial_charges). With xTB they come from the optimisation. With UFF4MOF they come from one tblite GFN2-xTB calculation on the starting geometry and also drive UFF4MOF's Coulomb term. False computes no charges and runs UFF4MOF without the Coulomb term, as does a missing tblite (with a warning).

True
charge float

Total charge passed to tblite.

0.0
method str

"UFF4MOF", "GFN1-xTB" or "GFN2-xTB".

"UFF4MOF"
logfile str or None

Optimiser log: "-" for the terminal, a file path, or None for no output.

"-"

Returns:

Type Description
Atoms

The optimised structure, which also replaces the builder's structure.

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
>>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
>>> _ = cage.build()
>>> relaxed = cage.optimise(include_charges=False, logfile=None)
>>> len(relaxed), relaxed is cage.to_ase()
(404, True)
Source code in cage_isomer_builder/cage/base.py
def optimise(
    self,
    fmax: float = 0.05,
    steps: int = 500,
    optimizer_cls=None,
    trajectory: Optional[str] = None,
    rigid_sbus: bool = True,
    include_charges: bool = True,
    charge: float = 0.0,
    method: str = "UFF4MOF",
    logfile: Optional[str] = "-",
) -> Atoms:
    """
    Optimise the cage geometry.

    * ``method="UFF4MOF"`` (default): the UFF4MOF force field with the STK bond
      orders and UFF atom types (see :mod:`cage_isomer_builder.utils.optimise`).
      The bonds are those of the construction, so atypical distances in the
      starting geometry do not change the connectivity.
    * ``method="GFN1-xTB"`` or ``"GFN2-xTB"``: tblite tight binding. It needs no
      bond orders or atom types, and so cannot be held to a bond matrix.

    Call this after :meth:`build` and before :meth:`functionalise`. After
    :meth:`functionalise`, the site markers are removed before optimising and
    :meth:`functionalise` must be run again.

    Parameters
    ----------
    fmax : float, default 0.05
        Force convergence threshold (eV/Angstrom).
    steps : int, default 500
        Maximum number of steps.
    optimizer_cls : ASE optimizer class, optional
        Any ``ase.optimize`` class (``LBFGS``, ``BFGS``, ``FIRE``, ...). Default
        ``LBFGS``.
    trajectory : str, optional
        Path of an ASE ``.traj`` file.
    rigid_sbus : bool, default True
        Keep every node and linker rigid (see
        :class:`~cage_isomer_builder.utils.rigid_body.FixRigidBodies`) and relax
        only their placement. The linker atoms bonded to a node stay free, so
        each metal-ligand bond can adjust without changing the rest of the
        linker. ``False`` relaxes every atom.
    include_charges : bool, default True
        Store partial charges on the result (``set_initial_charges``). With xTB
        they come from the optimisation. With UFF4MOF they come from one tblite
        GFN2-xTB calculation on the starting geometry and also drive UFF4MOF's
        Coulomb term. ``False`` computes no charges and runs UFF4MOF without the
        Coulomb term, as does a missing tblite (with a warning).
    charge : float, default 0.0
        Total charge passed to tblite.
    method : str, default "UFF4MOF"
        ``"UFF4MOF"``, ``"GFN1-xTB"`` or ``"GFN2-xTB"``.
    logfile : str or None, default "-"
        Optimiser log: ``"-"`` for the terminal, a file path, or ``None`` for no
        output.

    Returns
    -------
    ase.Atoms
        The optimised structure, which also replaces the builder's structure.

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
    >>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
    ...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
    >>> _ = cage.build()
    >>> relaxed = cage.optimise(include_charges=False, logfile=None)
    >>> len(relaxed), relaxed is cage.to_ase()
    (404, True)
    """
    from cage_isomer_builder.utils.rigid_body import FixRigidBodies

    if self._stk_cage is not None:
        # Start from the STK cage so that site markers are never included.
        ase_atoms, bond_matrix = stk_2_ase_atoms(self._stk_cage)
    else:
        ase_atoms = self.to_ase().copy()
        # Remove the site markers, which have no force-field parameters.
        from cage_isomer_builder.utils.sites import site_indices
        markers = set(site_indices(ase_atoms))
        ase_atoms = ase_atoms[[i for i in range(len(ase_atoms)) if i not in markers]]
        bond_matrix = None

    if rigid_sbus:
        if self._stk_cage is None:
            raise RuntimeError(
                "rigid_sbus=True requires the STK cage to identify SBU "
                "groupings (unavailable after load_from_file()). Pass "
                "rigid_sbus=False to relax every atom independently instead."
            )
        bb_atoms, bb_is_node = self._classify_atoms_by_bb(ase_atoms)

        # Nodes stay fully rigid. Each linker atom bonded to a node is
        # left out of its linker's rigid group, so the metal-ligand bond
        # can adjust.
        node_bb_ids = {bb_id for bb_id, is_node in bb_is_node.items() if is_node}
        node_atom_ids = {idx for bb_id in node_bb_ids for idx in bb_atoms[bb_id]}
        donor_atom_ids = {
            i
            for i in range(len(ase_atoms))
            if i not in node_atom_ids
            for j in np.nonzero(bond_matrix[i])[0]
            if j in node_atom_ids
        }

        groups = [bb_atoms[bb_id] for bb_id in node_bb_ids] + [
            [idx for idx in atoms if idx not in donor_atom_ids]
            for bb_id, atoms in bb_atoms.items()
            if bb_id not in node_bb_ids
        ]
        groups = [g for g in groups if len(g) > 1]
        ase_atoms.set_constraint(FixRigidBodies.from_atoms(ase_atoms, groups))

    if method.upper() == "UFF4MOF":
        if bond_matrix is None:
            raise RuntimeError(
                "method='UFF4MOF' requires the STK bond matrix (unavailable "
                "after load_from_file()). Pass method='GFN2-xTB' instead."
            )
        from cage_isomer_builder.utils.optimise import run_uff4mof_optimisation

        charges = None
        if include_charges:
            from cage_isomer_builder.utils.tblite_charges import (
                predict_tblite_charges,
                tblite_available,
            )

            if tblite_available():
                # Computed once from the starting geometry and held fixed,
                # as is usual for UFF with QEq charges; they drive the
                # Coulomb term.
                charges = predict_tblite_charges(ase_atoms, charge=charge)
            else:
                warnings.warn(
                    "tblite is not installed, so no partial charges are "
                    "computed and UFF4MOF runs without its Coulomb term. "
                    "Install it with 'pip install cage_isomer_builder[xtb]', "
                    "or pass include_charges=False to silence this warning."
                )

        optimised = run_uff4mof_optimisation(
            atoms=ase_atoms,
            bond_matrix=bond_matrix,
            fmax=fmax,
            steps=steps,
            optimizer_cls=optimizer_cls,
            trajectory=trajectory,
            charges=charges,
            logfile=logfile,
        )
    else:
        from cage_isomer_builder.utils.tblite_optimise import run_tblite_optimisation

        optimised, charges = run_tblite_optimisation(
            atoms=ase_atoms,
            fmax=fmax,
            steps=steps,
            optimizer_cls=optimizer_cls,
            trajectory=trajectory,
            charge=charge,
            method=method,
            logfile=logfile,
        )

    if include_charges and charges is not None:
        optimised.set_initial_charges(charges)

    # Atom order is unchanged, so the vertex map of functionalise() still holds.
    if self._ase_cage is not None:
        for key in ("linker_sites", "vertex_linkers"):
            if key in self._ase_cage.info:
                optimised.info[key] = self._ase_cage.info[key]
    self._ase_cage = optimised
    return optimised

point_group

point_group() -> pointgroup.PointGroup

Point group of the finite structure's framework, detected from the atoms chosen by symmetry_reference with tolerance symmetry_tol.

result.name is the Schoenflies symbol (e.g. "Td"), result.order the number of operations and result.max_deviation how far (Angstrom) the structure is from perfect symmetry.

Raises:

Type Description
ValueError

For a periodic structure (which uses spglib), or if no consistent group exists at this tolerance (see utils.pointgroup).

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
>>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
>>> _ = cage.build()
>>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
>>> _ = cage.functionalise()
>>> pg = cage.point_group()
>>> pg.name, pg.order
('Td', 24)
Source code in cage_isomer_builder/cage/base.py
def point_group(self) -> "pointgroup.PointGroup":
    """
    Point group of the finite structure's framework, detected from the atoms
    chosen by ``symmetry_reference`` with tolerance ``symmetry_tol``.

    ``result.name`` is the Schoenflies symbol (e.g. ``"Td"``), ``result.order``
    the number of operations and ``result.max_deviation`` how far (Angstrom) the
    structure is from perfect symmetry.

    Raises
    ------
    ValueError
        For a periodic structure (which uses spglib), or if no consistent group
        exists at this tolerance (see utils.pointgroup).

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
    >>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
    ...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
    >>> _ = cage.build()
    >>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
    >>> _ = cage.functionalise()
    >>> pg = cage.point_group()
    >>> pg.name, pg.order
    ('Td', 24)
    """
    if self._fg_anchors is None:
        self.functionalise()
    ase_cage = self.to_ase()
    if ase_cage.pbc.any():
        raise ValueError("point_group() is for finite structures; periodic "
                         "structures use their space group via spglib.")
    ref = pointgroup.reference_indices(ase_cage, self.symmetry_reference)
    return pointgroup.detect_point_group(ase_cage[ref], tol=self.symmetry_tol)

pore_centre

pore_centre() -> Optional[np.ndarray]

Centre of the pore: the point-group centre of a finite structure (centroid of its non-H, non-site atoms if no group is found), None for a periodic one.

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
>>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
>>> _ = cage.build()
>>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
>>> _ = cage.functionalise()
>>> import numpy as np
>>> bool(np.allclose(cage.pore_centre(), cage.point_group().centre))
True
Source code in cage_isomer_builder/cage/base.py
def pore_centre(self) -> Optional[np.ndarray]:
    """
    Centre of the pore: the point-group centre of a finite structure
    (centroid of its non-H, non-site atoms if no group is found), None
    for a periodic one.

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
    >>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
    ...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
    >>> _ = cage.build()
    >>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
    >>> _ = cage.functionalise()
    >>> import numpy as np
    >>> bool(np.allclose(cage.pore_centre(), cage.point_group().centre))
    True
    """
    atoms = self.to_ase()
    if atoms.pbc.any():
        return None
    try:
        return np.asarray(self.point_group().centre)
    except ValueError:
        heavy = [i for i in range(len(atoms)) if atoms.numbers[i] > 1]
        return atoms.positions[heavy].mean(axis=0)

rotors

rotors() -> list

Rotatable linker rings (see :func:cage_isomer_builder.utils.flexibility.find_rotors).

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
>>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
>>> _ = cage.build()
>>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
>>> _ = cage.functionalise()
>>> len(cage.rotors())
6
Source code in cage_isomer_builder/cage/base.py
def rotors(self) -> list:
    """Rotatable linker rings (see :func:`cage_isomer_builder.utils.flexibility.find_rotors`).

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
    >>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
    ...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
    >>> _ = cage.build()
    >>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
    >>> _ = cage.functionalise()
    >>> len(cage.rotors())
    6
    """
    if self._fg_anchors is None:
        self.functionalise()
    return flexibility.find_rotors(self.to_ase(), self._linker_atom_indices,
                                   self.adjacency())

save

save(path: str) -> None

Save the cage structure to file.

A PDB file of a built cage is written by STK, with the bonds of the construction; every other format by ase.io.write. Both hold the current geometry, so the optimised one after :meth:optimise.

Parameters:

Name Type Description Default
path str

Output file path, e.g. "base_structure/Tet2Di4.pdb".

required

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
>>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
>>> _ = cage.build()
>>> import os, tempfile
>>> path = os.path.join(tempfile.mkdtemp(), "cage.xyz")
>>> cage.save(path)                               # any ASE format; PDB via STK
>>> os.path.getsize(path) > 0
True
Source code in cage_isomer_builder/cage/base.py
def save(self, path: str) -> None:
    """
    Save the cage structure to file.

    A PDB file of a built cage is written by STK, with the bonds of the
    construction; every other format by ``ase.io.write``. Both hold the
    current geometry, so the optimised one after :meth:`optimise`.

    Parameters
    ----------
    path : str
        Output file path, e.g. ``"base_structure/Tet2Di4.pdb"``.

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
    >>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
    ...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
    >>> _ = cage.build()
    >>> import os, tempfile
    >>> path = os.path.join(tempfile.mkdtemp(), "cage.xyz")
    >>> cage.save(path)                               # any ASE format; PDB via STK
    >>> os.path.getsize(path) > 0
    True
    """
    path = str(path)

    if self._stk_cage is not None and path.lower().endswith(".pdb"):
        stk.PdbWriter().write(molecule=self._current_stk_cage(), path=path)
        return

    ase_cage = self.to_ase()
    write(path, ase_cage)

scaled

scaled(factor: float) -> Atoms

The structure with every building block moved rigidly by an isotropic expansion (factor > 1) or contraction (< 1) about the pore centre (periodic: the cell is scaled).

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
>>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
>>> _ = cage.build()
>>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
>>> _ = cage.functionalise()
>>> import numpy as np
>>> bigger = cage.scaled(1.05)
>>> _, nodes = cage.building_blocks()
>>> r0 = np.linalg.norm(cage.to_ase().positions[nodes[0]].mean(0) - cage.pore_centre())
>>> r1 = np.linalg.norm(bigger.positions[nodes[0]].mean(0) - cage.pore_centre())
>>> round(float(r1 / r0), 6)
1.05
Source code in cage_isomer_builder/cage/base.py
def scaled(self, factor: float) -> Atoms:
    """The structure with every building block moved rigidly by an
    isotropic expansion (``factor`` > 1) or contraction (< 1) about the
    pore centre (periodic: the cell is scaled).

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
    >>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
    ...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
    >>> _ = cage.build()
    >>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
    >>> _ = cage.functionalise()
    >>> import numpy as np
    >>> bigger = cage.scaled(1.05)
    >>> _, nodes = cage.building_blocks()
    >>> r0 = np.linalg.norm(cage.to_ase().positions[nodes[0]].mean(0) - cage.pore_centre())
    >>> r1 = np.linalg.norm(bigger.positions[nodes[0]].mean(0) - cage.pore_centre())
    >>> round(float(r1 / r0), 6)
    1.05
    """
    linkers, nodes = self.building_blocks()
    return flexibility.scale_structure(self.to_ase(), linkers + nodes, factor,
                                       self.pore_centre())

slot_features

slot_features(threshold: float = 0.5, centre=None) -> features.FeatureSet

One fg feature per FG slot, in slot order, with its C-site direction and endo/exo/tangential class relative to :meth:pore_centre. The owner of a slot is the index of the linker holding it in :meth:building_blocks, so it matches the owners of :meth:get_features' other sites.

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
>>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
>>> _ = cage.build()
>>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
>>> _ = cage.functionalise()
>>> slots = cage.slot_features()
>>> len(slots), sorted(set(slots.orientation.tolist()))
(24, ['tangential'])
Source code in cage_isomer_builder/cage/base.py
def slot_features(self, threshold: float = 0.5, centre=None) -> "features.FeatureSet":
    """
    One ``fg`` feature per FG slot, in slot order, with its C-site
    direction and endo/exo/tangential class relative to
    :meth:`pore_centre`. The owner of a slot is the index of the linker
    holding it in :meth:`building_blocks`, so it matches the owners of
    :meth:`get_features`' other sites.

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
    >>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
    ...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
    >>> _ = cage.build()
    >>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
    >>> _ = cage.functionalise()
    >>> slots = cage.slot_features()
    >>> len(slots), sorted(set(slots.orientation.tolist()))
    (24, ['tangential'])
    """
    if self._fg_anchors is None:
        self.functionalise()
    atoms = self.to_ase()
    if centre is None:
        centre = self.pore_centre()
    fs = features.fg_features(atoms, self._fg_anchor_indices, centre=centre,
                              threshold=threshold, adjacency=self.adjacency())
    linker_of = {a: k for k, lk in enumerate(self._linker_atom_indices) for a in lk}
    fs.owners = np.array([linker_of.get(i, -1) for i in self._fg_anchor_indices])
    if (fs.owners < 0).any():
        fs.owners = np.array(self._slot_linkers)[self._layout.slot_linker]
    return fs

slot_group

slot_group() -> rgroup.SlotGroup

The structure's symmetry as permutations of its functional-group sites, checked to be a group that maps linkers onto linkers of the same type. Every isomer count and enumeration uses it; pass it to the functions of :mod:cage_isomer_builder.utils.rgroup and :mod:cage_isomer_builder.utils.ensemble.

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage import CageBuilder
>>> mof = CageBuilder.load_from_file(example_data.path("RUBTAK01"), primitive=True)
>>> _ = mof.functionalise()
>>> group = mof.slot_group()
>>> group.order, group.perms.shape            # Fm-3m: 48 operations on 24 sites
(48, (48, 24))
Source code in cage_isomer_builder/cage/base.py
def slot_group(self) -> "rgroup.SlotGroup":
    """
    The structure's symmetry as permutations of its functional-group sites,
    checked to be a group that maps linkers onto linkers of the same type.
    Every isomer count and enumeration uses it; pass it to the functions of
    :mod:`cage_isomer_builder.utils.rgroup` and
    :mod:`cage_isomer_builder.utils.ensemble`.

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage import CageBuilder
    >>> mof = CageBuilder.load_from_file(example_data.path("RUBTAK01"), primitive=True)
    >>> _ = mof.functionalise()
    >>> group = mof.slot_group()
    >>> group.order, group.perms.shape            # Fm-3m: 48 operations on 24 sites
    (48, (48, 24))
    """
    if self._fg_anchors is None:
        self.functionalise()
    n_fg_slots = len(self._fg_anchors)
    self._check_slot_layout()
    tl = self._get_transformation_library(self._fg_anchors.copy())
    return rgroup.prepare_group(list(zip(*tl)), n_fg_slots, self._layout)

slot_layout

slot_layout() -> rgroup.SlotLayout

How the FG slots are grouped: slots per linker and linker type (layout.type_names are the linkers' chemical formulas). A MOF with several kinds of linker has several types, possibly with different numbers of slots; groups can then be given per type, e.g. groups={"C6H4": "A", "C10H8N2": ""}.

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage import CageBuilder
>>> mof = CageBuilder.load_from_file(example_data.path("ABIXEQ"))   # two kinds of linker
>>> _ = mof.functionalise()
>>> layout = mof.slot_layout()
>>> layout.type_names, layout.sizes
(('C18H18N4', 'C6H4'), (8, 4))
Source code in cage_isomer_builder/cage/base.py
def slot_layout(self) -> "rgroup.SlotLayout":
    """
    How the FG slots are grouped: slots per linker and linker type
    (``layout.type_names`` are the linkers' chemical formulas). A MOF with
    several kinds of linker has several types, possibly with different
    numbers of slots; groups can then be given per type, e.g.
    ``groups={"C6H4": "A", "C10H8N2": ""}``.

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage import CageBuilder
    >>> mof = CageBuilder.load_from_file(example_data.path("ABIXEQ"))   # two kinds of linker
    >>> _ = mof.functionalise()
    >>> layout = mof.slot_layout()
    >>> layout.type_names, layout.sizes
    (('C18H18N4', 'C6H4'), (8, 4))
    """
    if self._fg_anchors is None:
        self.functionalise()
    return self._layout

to_ase

to_ase(hydrogens: bool = False) -> Atoms

The structure as ASE Atoms (converted from the STK cage on first use).

After :meth:functionalise it holds the R-site markers (X atoms). hydrogens=True returns a copy with every site turned back into its original H, i.e. the parent cage, for docking or optimisation.

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
>>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
>>> _ = cage.build()
>>> atoms = cage.to_ase()
>>> len(atoms), bool(atoms.pbc.any())
(404, False)
>>> _ = cage.functionalise()
>>> "X" in cage.to_ase().get_chemical_symbols(), "X" in cage.to_ase(hydrogens=True).symbols
(True, False)
Source code in cage_isomer_builder/cage/base.py
def to_ase(self, hydrogens: bool = False) -> Atoms:
    """
    The structure as ASE Atoms (converted from the STK cage on first use).

    After :meth:`functionalise` it holds the R-site markers (``X`` atoms).
    ``hydrogens=True`` returns a copy with every site turned back into its
    original H, i.e. the parent cage, for docking or optimisation.

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
    >>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
    ...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
    >>> _ = cage.build()
    >>> atoms = cage.to_ase()
    >>> len(atoms), bool(atoms.pbc.any())
    (404, False)
    >>> _ = cage.functionalise()
    >>> "X" in cage.to_ase().get_chemical_symbols(), "X" in cage.to_ase(hydrogens=True).symbols
    (True, False)
    """
    if self._ase_cage is None:
        if self._stk_cage is None:
            raise RuntimeError(
                "No structure available. Call build() or load_from_file() first."
            )
        self._ase_cage, _ = stk_2_ase_atoms(self._stk_cage)
    if not hydrogens or self._fg_anchor_indices is None:
        return self._ase_cage
    from cage_isomer_builder.utils.sites import clear_site

    parent = self._ase_cage.copy()
    for slot, atom in enumerate(self._fg_anchor_indices):
        clear_site(parent, atom, "H", self._fg_anchor_h_positions[slot])
    return parent

to_smiles

to_smiles() -> str

Convert the cage to a SMILES string using mofstructure (OpenBabel).

Returns:

Name Type Description
smiles str

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
>>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
>>> _ = cage.build()
>>> "Zr" in cage.to_smiles()
True
Source code in cage_isomer_builder/cage/base.py
def to_smiles(self) -> str:
    """
    Convert the cage to a SMILES string using mofstructure (OpenBabel).

    Returns
    -------
    smiles : str

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
    >>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
    ...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
    >>> _ = cage.build()
    >>> "Zr" in cage.to_smiles()
    True
    """
    return ase_2_pybel(self.to_ase()).write('smi').strip()

vertex_scheme

vertex_scheme() -> vertex_codes.VertexScheme

Vertex codes of this cage: what each vertex (node) sees of the groups on its linkers.

Seen from the pore centre with the vertex at the bottom of a linker, the linker reads 1 if its group is next to this vertex on the left, 4 if on the right, and 0 otherwise (one group per linker on a four-site linker); 5 for both, one character per depth on longer linkers, and pairs of group letters for several kinds of group. A vertex's code lists its linkers clockwise as seen from the pore centre, starting at the lowest-numbered linker (the vertex and linker numbers of info["vertex_linkers"]). The vertex name of an isomer, its codes in vertex order joined by -, is unique and converts back to the site indices; labels gives the environment of each vertex whatever linker its code starts at (see :mod:cage_isomer_builder.utils.vertex_codes).

Raises:

Type Description
ValueError

For a periodic structure, if a linker does not join two vertices, or a site is neither left nor right of its linker, or midway between its vertices.

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
>>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
>>> _ = cage.build()
>>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
>>> scheme = cage.vertex_scheme()
>>> scheme.name([0, 4, 9, 13, 16, 22]), scheme.labels([0, 4, 9, 13, 16, 22])
('000-100-141-401', ['000', '100', '114', '140'])
>>> scheme.resolve("000-100-141-401"), scheme.resolve("0-4-9-13-16-22")
([0, 4, 9, 13, 16, 22], [0, 4, 9, 13, 16, 22])
Source code in cage_isomer_builder/cage/base.py
def vertex_scheme(self) -> "vertex_codes.VertexScheme":
    """
    Vertex codes of this cage: what each vertex (node) sees of the groups on
    its linkers.

    Seen from the pore centre with the vertex at the bottom of a linker,
    the linker reads 1 if its group is next to this vertex on the left, 4
    if on the right, and 0 otherwise (one group per linker on a
    four-site linker); 5 for both, one character per depth on longer
    linkers, and pairs of group letters for several kinds of group. A vertex's code lists its linkers
    clockwise as seen from the pore centre, starting at the lowest-numbered
    linker (the vertex and linker numbers of ``info["vertex_linkers"]``).
    The vertex name of an isomer, its codes in vertex order joined by
    ``-``, is unique and converts back to the site indices;
    ``labels`` gives the environment of each vertex whatever linker its
    code starts at (see :mod:`cage_isomer_builder.utils.vertex_codes`).

    Raises
    ------
    ValueError
        For a periodic structure, if a linker does not join two vertices,
        or a site is neither left nor right of its linker, or midway
        between its vertices.

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
    >>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
    ...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
    >>> _ = cage.build()
    >>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
    >>> scheme = cage.vertex_scheme()
    >>> scheme.name([0, 4, 9, 13, 16, 22]), scheme.labels([0, 4, 9, 13, 16, 22])
    ('000-100-141-401', ['000', '100', '114', '140'])
    >>> scheme.resolve("000-100-141-401"), scheme.resolve("0-4-9-13-16-22")
    ([0, 4, 9, 13, 16, 22], [0, 4, 9, 13, 16, 22])
    """
    if self._fg_anchors is None:
        self.functionalise()
    centre = self.pore_centre()
    if centre is None:
        raise ValueError("vertex codes need a finite cage with a pore centre.")
    atoms = self.to_ase()
    pos = atoms.positions
    linkers, nodes = self.building_blocks()
    adjacency = self.adjacency()
    node_of = {a: n for n, g in enumerate(nodes) for a in g}

    linker_vertices, linker_centres = [], []
    for L, k in enumerate(self._slot_linkers):
        vertices = sorted({node_of[b] for a in linkers[k] for b in adjacency[a] if b in node_of})
        if len(vertices) != 2:
            raise ValueError(f"linker {L} joins {len(vertices)} vertices; vertex codes "
                             "need every linker to join two.")
        linker_vertices.append(tuple(vertices))
        heavy = [a for a in linkers[k] if atoms.numbers[a] > 1]
        linker_centres.append(pos[heavy].mean(axis=0))

    vertex_centres = []
    for g in nodes:
        metals = [a for a in g if features.is_metal(atoms.numbers[a])]
        vertex_centres.append(pos[metals or g].mean(axis=0))

    layout = self._layout
    linker_sites = [range(start, start + size)
                    for start, size in zip(layout.offsets, layout.sizes)]
    return vertex_codes.scheme_from_geometry(
        pos[self._fg_anchor_indices], linker_sites, linker_vertices,
        linker_centres, vertex_centres, centre)

vertex_table

vertex_table(max_placements: int = 4 ** 16, groups='A', linker_patterns: Optional[dict] = None) -> vertex_tables.VertexTable

Every symmetry-unique isomer, with its vertex name and environment labels, for statistics over vertex environments (see :mod:cage_isomer_builder.utils.vertex_table), without building any structures. With one group per linker (the default) the isomers are the ones :meth:enumerate_isomers writes, in the same order; otherwise the ones :meth:enumerate_rgroup_isomers writes.

Parameters:

Name Type Description Default
max_placements int

Refuse cages with more than this many raw placements (4 ** n_linkers for one group on four-site linkers).

``4 ** 16``
groups

What goes on the linkers, as for :meth:count_rgroup_isomers.

'A'
linker_patterns

What goes on the linkers, as for :meth:count_rgroup_isomers.

'A'

Raises:

Type Description
ValueError

If the cage has no vertex codes (see :meth:vertex_scheme), or is too large.

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
>>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
>>> _ = cage.build()
>>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
>>> table = cage.vertex_table()
>>> len(table), table.site_name(0), table.labels(0)
(176, '0-4-8-12-16-20', '111-110-100-000')
>>> table.environment_counts(both_hands=True)["114"]
64
>>> ab = cage.vertex_table(groups=["NH2", "OH"])
>>> len(ab) == cage.count_rgroup_isomers(["NH2", "OH"]), ab.site_name(0)
(True, 'NH2-2-6-10-14-18-22_OH-3-7-11-15-19-23')
Source code in cage_isomer_builder/cage/base.py
def vertex_table(self, max_placements: int = 4 ** 16, groups="A",
                 linker_patterns: Optional[dict] = None) -> "vertex_tables.VertexTable":
    """
    Every symmetry-unique isomer, with its vertex name and environment
    labels, for statistics over vertex environments (see
    :mod:`cage_isomer_builder.utils.vertex_table`), without building any
    structures. With one group per linker (the default) the isomers are
    the ones :meth:`enumerate_isomers` writes, in the same order;
    otherwise the ones :meth:`enumerate_rgroup_isomers` writes.

    Parameters
    ----------
    max_placements : int, default ``4 ** 16``
        Refuse cages with more than this many raw placements
        (``4 ** n_linkers`` for one group on four-site linkers).
    groups, linker_patterns
        What goes on the linkers, as for :meth:`count_rgroup_isomers`.

    Raises
    ------
    ValueError
        If the cage has no vertex codes (see :meth:`vertex_scheme`), or is
        too large.

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
    >>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
    ...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
    >>> _ = cage.build()
    >>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
    >>> table = cage.vertex_table()
    >>> len(table), table.site_name(0), table.labels(0)
    (176, '0-4-8-12-16-20', '111-110-100-000')
    >>> table.environment_counts(both_hands=True)["114"]
    64
    >>> ab = cage.vertex_table(groups=["NH2", "OH"])
    >>> len(ab) == cage.count_rgroup_isomers(["NH2", "OH"]), ab.site_name(0)
    (True, 'NH2-2-6-10-14-18-22_OH-3-7-11-15-19-23')
    """
    scheme = self.vertex_scheme()
    library = self._get_transformation_library(self._fg_anchors.copy())
    sym = vertex_tables.SiteSymmetry.from_permutations(
        scheme, list(zip(*library)), group=self.point_group().name, layout=self._layout)
    return vertex_tables.vertex_table(sym, max_placements, groups, linker_patterns)

write_ams_run

write_ams_run(path: Union[str, Path]) -> None

Write an AMS geometry-optimisation run script for this cage, with Cartesian coordinates (the optimised ones after :meth:optimise), bond orders from the STK bond matrix, lattice vectors for a periodic structure, and an Engine DFTB block.

Parameters:

Name Type Description Default
path str or Path

Output file, e.g. "Tet2Di4.run".

required

Raises:

Type Description
RuntimeError

If :meth:build has not been called (the bond orders come from STK).

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
>>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
>>> _ = cage.build()
>>> import os, tempfile
>>> path = os.path.join(tempfile.mkdtemp(), "cage.run")
>>> cage.write_ams_run(path)
>>> "BondOrders" in open(path).read()
True
Source code in cage_isomer_builder/cage/base.py
def write_ams_run(self, path: Union[str, Path]) -> None:
    """
    Write an AMS geometry-optimisation run script for this cage, with Cartesian
    coordinates (the optimised ones after :meth:`optimise`), bond orders from the STK bond matrix, lattice vectors for a
    periodic structure, and an ``Engine DFTB`` block.

    Parameters
    ----------
    path : str or Path
        Output file, e.g. ``"Tet2Di4.run"``.

    Raises
    ------
    RuntimeError
        If :meth:`build` has not been called (the bond orders come from STK).

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
    >>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
    ...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
    >>> _ = cage.build()
    >>> import os, tempfile
    >>> path = os.path.join(tempfile.mkdtemp(), "cage.run")
    >>> cage.write_ams_run(path)
    >>> "BondOrders" in open(path).read()
    True
    """
    if self._stk_cage is None:
        raise RuntimeError(
            "write_ams_run() requires the STK cage. Call build() first."
        )

    atoms, bond_matrix = stk_2_ase_atoms(self._current_stk_cage())
    write_run(str(path), atoms, bond_matrix)

write_gulp_gin

write_gulp_gin(path: Union[str, Path], lattice: str = 'conv', mechanical: bool = False) -> None

Write a GULP input file for this cage, with UFF4MOF atom types from gulp_setup (as used by optimise(method="UFF4MOF")), Cartesian coordinates (the optimised ones after :meth:optimise), connect records from the STK bond matrix and a uff4mof library block.

Parameters:

Name Type Description Default
path str or Path

Output file, e.g. "Tet2Di4.gin".

required
lattice str

"conv" (constant volume) or "conp" (constant pressure, the cell is optimised). Only matters for a periodic structure.

"conv"
mechanical bool

Use gulp_setup's mechanical-properties input (looser convergence, different optimiser settings).

False

Raises:

Type Description
RuntimeError

If :meth:build has not been called (the bond orders come from STK).

Notes

gulp_setup.mmanalysis.write_gin accepts bond orders 4, 3, 2, 1.5, 1, 0.5 and 0.25; any other order raises KeyError. STK bond matrices hold integer orders and 1.5 for aromatic bonds.

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
>>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
>>> _ = cage.build()
>>> import os, tempfile
>>> path = os.path.join(tempfile.mkdtemp(), "cage.gin")
>>> cage.write_gulp_gin(path)
>>> open(path).read().startswith("opti")
True
Source code in cage_isomer_builder/cage/base.py
def write_gulp_gin(
    self, path: Union[str, Path], lattice: str = "conv", mechanical: bool = False
) -> None:
    """
    Write a GULP input file for this cage, with UFF4MOF atom types from
    ``gulp_setup`` (as used by ``optimise(method="UFF4MOF")``), Cartesian
    coordinates (the optimised ones after :meth:`optimise`), ``connect`` records from the STK bond matrix and a ``uff4mof``
    library block.

    Parameters
    ----------
    path : str or Path
        Output file, e.g. ``"Tet2Di4.gin"``.
    lattice : str, default "conv"
        ``"conv"`` (constant volume) or ``"conp"`` (constant pressure, the cell
        is optimised). Only matters for a periodic structure.
    mechanical : bool, default False
        Use ``gulp_setup``'s mechanical-properties input (looser convergence,
        different optimiser settings).

    Raises
    ------
    RuntimeError
        If :meth:`build` has not been called (the bond orders come from STK).

    Notes
    -----
    ``gulp_setup.mmanalysis.write_gin`` accepts bond orders 4, 3, 2, 1.5, 1, 0.5
    and 0.25; any other order raises ``KeyError``. STK bond matrices hold
    integer orders and 1.5 for aromatic bonds.

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
    >>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
    ...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
    >>> _ = cage.build()
    >>> import os, tempfile
    >>> path = os.path.join(tempfile.mkdtemp(), "cage.gin")
    >>> cage.write_gulp_gin(path)
    >>> open(path).read().startswith("opti")
    True
    """
    if self._stk_cage is None:
        raise RuntimeError(
            "write_gulp_gin() requires the STK cage. Call build() first."
        )

    from gulp_setup.mmanalysis import analyze_mm, write_gin

    atoms, bond_matrix = stk_2_ase_atoms(self._current_stk_cage())
    _, mmtypes = analyze_mm(atoms, bond_order=bond_matrix)
    write_gin(str(path), atoms, bond_matrix, mmtypes, lattice=lattice, mechanical=mechanical)

CageStatistics dataclass

CageStatistics(n_linkers: int, n_fg_slots: int, n_unique_isomers: int, distance_keys: list, total_fg_pairs: list, endo_endo_pairs: list, endo_exo_pairs: list, exo_exo_pairs: list, kde_x: ndarray, kde_y: ndarray, other_pairs: list = None)

FG-FG distance statistics of a structure (see :meth:CageBuilder.get_statistics).

Attributes:

Name Type Description
n_linkers int

Number of linkers carrying sites.

n_fg_slots int

Total number of functional-group sites.

n_unique_isomers int

Symmetry-unique isomers with one group per linker (Burnside's lemma).

distance_keys list of float

Sorted distinct site-site distances between linkers (Angstrom).

total_fg_pairs list of int

Number of site pairs at each distance.

endo_endo_pairs list of int

Pairs where both sites point into the pore.

endo_exo_pairs list of int

Pairs with one site pointing in and one out.

exo_exo_pairs list of int

Pairs where both sites point out.

kde_x (ndarray, shape(n_kde_bins))

Distance grid of the smoothed curve.

kde_y (ndarray, shape(n_kde_bins))

Smoothed pair counts on kde_x, scaled to the total pair count.

other_pairs list of int

Pairs involving a tangential site (its C-site bond within 60 degrees of perpendicular to the pore direction, e.g. on a ring lying face-on to the pore) or, in periodic structures, an unclassified site. The four classes add up to total_fg_pairs.

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
>>> cage = Tri4Di6CageBuilder(node=example_data.path("uio66_tri_node"),
...                           linker=example_data.path("bdc"), scale_multiplier=0.225)
>>> _ = cage.build()
>>> _ = cage.optimise(include_charges=False, logfile=None)   # the UiO-66 tetrahedral cage
>>> _ = cage.functionalise()
>>> stats = cage.get_statistics()
>>> stats.n_linkers, stats.n_fg_slots, stats.n_unique_isomers, sum(stats.total_fg_pairs)
(6, 24, 176, 240)

Topology-specific builders

One cage builder per topology. Each sets the STK topology graph, the number of connection points of its node and, where one exists, its hand-written symmetry library for symmetry_method="topology".

Tet2Di4CageBuilder

Tet2Di4CageBuilder(linker: MoleculeInput = None, node: MoleculeInput = None, linker_fg=None, node_fg=None, node_fg_count: int = None, smarts_pattern: str = None, optimizer_step: float = 0.01, distance_threshold: float = 5.0, expansion_factor: float = 1.0, scale_multiplier: float = 1.0, linker_smiles: str = None, node_smiles: str = None)

Bases: CageBuilder

Tet2Di4: 2 tetratopic nodes + 4 ditopic linkers (TwoPlusFour). Point group D4h.

Examples:

>>> from cage_isomer_builder.cage import Tet2Di4CageBuilder
>>> cage = Tet2Di4CageBuilder()           # default single-atom [Zr] node + p-phenylenediamine
>>> _ = cage.build()
>>> cage.to_ase().get_chemical_formula()
'C24H16N8Zr2'
Source code in cage_isomer_builder/cage/base.py
def __init__(
    self,
    linker: MoleculeInput = None,
    node: MoleculeInput = None,
    linker_fg=None,
    node_fg=None,
    node_fg_count: int = None,
    smarts_pattern: str = None,
    optimizer_step: float = 0.01,
    distance_threshold: float = 5.0,
    expansion_factor: float = 1.0,
    scale_multiplier: float = 1.0,
    linker_smiles: str = None,
    node_smiles: str = None,
):
    """
    Initialise a cage builder.

    The linker and node may be a SMILES string, an ASE ``Atoms`` object, or a
    structure file readable by ASE (``.xyz``, ``.mol``, ``.mol2``, ``.sdf``,
    ``.pdb``, ``.cif``, ...).

    Functional groups (the connection points) are found in this order:

    1. **Single atom** (nodes only): a node of one atom (e.g. ``"[Zn]"``)
       becomes an ``stk.SingleAtom`` building block.
    2. **Dummy atoms**: ``X`` atoms in a structure, or ``*``, ``[*]`` or
       ``[#0]`` in a SMILES string, mark the connection points. SMILES dummies
       are rewritten as ``[Fr]`` placeholders (STK cannot build atomic number
       0) and matched by the SMARTS ``[Fr][*]``.
    3. **Given factory**: ``linker_fg`` or ``node_fg``.
    4. **Automatic**: the factories of ``FG_FACTORY_MAP`` are tried in turn.

    Parameters
    ----------
    linker : MoleculeInput, optional
        Linker building block. Defaults to ``default_linker``.
    node : MoleculeInput, optional
        Node building block. Defaults to ``default_node``.
    linker_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the linker: a key of ``FG_FACTORY_MAP``, a
        factory instance, or ``None`` for automatic detection.
    node_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the node. ``"single_atom"`` for an
        isolated metal, ``None`` for automatic detection. The default node uses
        ``default_node_fg``; a given node defaults to automatic detection.
    node_fg_count : int, optional
        Number of functional groups of a single-atom node (ignored otherwise).
        Defaults to ``default_node_fg_count``.
    smarts_pattern : str, optional
        SMARTS pattern used when ``linker_fg`` or ``node_fg`` is ``"smarts"``.
    optimizer_step : float, default 0.01
        Step size of the STK ``Collapser`` optimiser.
    distance_threshold : float, default 5.0
        Distance threshold (Angstrom) of the STK ``Collapser`` optimiser.
    expansion_factor : float, default 1.0
        After assembly, every building block is translated rigidly so that its
        distance from the cage centroid is multiplied by this factor. Use a value
        slightly above 1 when bulky nodes overlap their neighbours in the
        initial placement; the smallest factor is ``2 * r_max / d`` for a node of
        outer radius ``r_max`` and vertex-vertex distance ``d`` (about 1.15 for
        ``uio66_tri_node``).
    scale_multiplier : float, default 1.0
        Passed to the STK topology graph, which scales its vertex positions by
        ``scale_multiplier`` times the largest building-block diameter. A bulky
        node next to a short linker (a Zr6 node with a phenylene) is then placed
        far from its linkers. To correct it, build once, note the node-node
        distance ``d0`` and the distance you want ``d`` (linker length plus two
        metal-ligand bonds), and set ``scale_multiplier = d / d0``.
    linker_smiles, node_smiles : str, optional
        Deprecated aliases of ``linker`` and ``node``.
    """

    # Input normalization
    linker_input = linker if linker is not None else linker_smiles
    node_input = node if node is not None else node_smiles

    self.linker = normalize_molecule_input(
        mol=linker_input,
        default=self.default_linker,
    )

    self.node = normalize_molecule_input(
        mol=node_input,
        default=self.default_node,
    )

    self.linker_fg = (
        linker_fg
        if linker_fg is not None
        else self.default_linker_fg
    )

    self.node_fg = (
        node_fg
        if node_fg is not None
        else self.default_node_fg
        if node_input is None
        else None
    )

    self.node_fg_count = (
        node_fg_count
        if node_fg_count is not None
        else self.default_node_fg_count
    )

    self.smarts_pattern = smarts_pattern
    self.optimizer_step = optimizer_step
    self.distance_threshold = distance_threshold
    self.expansion_factor = expansion_factor
    self.scale_multiplier = scale_multiplier

    # Internal state
    self._stk_cage = None
    self._ase_cage = None
    self._fg_anchors = None
    self._fg_anchor_indices = None
    self._fg_anchor_h_positions = None
    self._fg_per_linker = None
    self._linker_atom_indices = None
    self._node_centers = None

Tet3_3Di3CageBuilder

Tet3_3Di3CageBuilder(linker: MoleculeInput = None, node: MoleculeInput = None, linker_fg=None, node_fg=None, node_fg_count: int = None, smarts_pattern: str = None, optimizer_step: float = 0.01, distance_threshold: float = 5.0, expansion_factor: float = 1.0, scale_multiplier: float = 1.0, linker_smiles: str = None, node_smiles: str = None)

Bases: CageBuilder

Tet3-3Di3: 3 tetratopic nodes + 6 ditopic linkers (_ThreePlusSix). Point group D3h.

Examples:

>>> from cage_isomer_builder.cage import Tet3_3Di3CageBuilder
>>> cage = Tet3_3Di3CageBuilder()           # default single-atom [Zr] node + p-phenylenediamine
>>> _ = cage.build()
>>> cage.to_ase().get_chemical_formula()
'C36H24N12Zr3'
Source code in cage_isomer_builder/cage/base.py
def __init__(
    self,
    linker: MoleculeInput = None,
    node: MoleculeInput = None,
    linker_fg=None,
    node_fg=None,
    node_fg_count: int = None,
    smarts_pattern: str = None,
    optimizer_step: float = 0.01,
    distance_threshold: float = 5.0,
    expansion_factor: float = 1.0,
    scale_multiplier: float = 1.0,
    linker_smiles: str = None,
    node_smiles: str = None,
):
    """
    Initialise a cage builder.

    The linker and node may be a SMILES string, an ASE ``Atoms`` object, or a
    structure file readable by ASE (``.xyz``, ``.mol``, ``.mol2``, ``.sdf``,
    ``.pdb``, ``.cif``, ...).

    Functional groups (the connection points) are found in this order:

    1. **Single atom** (nodes only): a node of one atom (e.g. ``"[Zn]"``)
       becomes an ``stk.SingleAtom`` building block.
    2. **Dummy atoms**: ``X`` atoms in a structure, or ``*``, ``[*]`` or
       ``[#0]`` in a SMILES string, mark the connection points. SMILES dummies
       are rewritten as ``[Fr]`` placeholders (STK cannot build atomic number
       0) and matched by the SMARTS ``[Fr][*]``.
    3. **Given factory**: ``linker_fg`` or ``node_fg``.
    4. **Automatic**: the factories of ``FG_FACTORY_MAP`` are tried in turn.

    Parameters
    ----------
    linker : MoleculeInput, optional
        Linker building block. Defaults to ``default_linker``.
    node : MoleculeInput, optional
        Node building block. Defaults to ``default_node``.
    linker_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the linker: a key of ``FG_FACTORY_MAP``, a
        factory instance, or ``None`` for automatic detection.
    node_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the node. ``"single_atom"`` for an
        isolated metal, ``None`` for automatic detection. The default node uses
        ``default_node_fg``; a given node defaults to automatic detection.
    node_fg_count : int, optional
        Number of functional groups of a single-atom node (ignored otherwise).
        Defaults to ``default_node_fg_count``.
    smarts_pattern : str, optional
        SMARTS pattern used when ``linker_fg`` or ``node_fg`` is ``"smarts"``.
    optimizer_step : float, default 0.01
        Step size of the STK ``Collapser`` optimiser.
    distance_threshold : float, default 5.0
        Distance threshold (Angstrom) of the STK ``Collapser`` optimiser.
    expansion_factor : float, default 1.0
        After assembly, every building block is translated rigidly so that its
        distance from the cage centroid is multiplied by this factor. Use a value
        slightly above 1 when bulky nodes overlap their neighbours in the
        initial placement; the smallest factor is ``2 * r_max / d`` for a node of
        outer radius ``r_max`` and vertex-vertex distance ``d`` (about 1.15 for
        ``uio66_tri_node``).
    scale_multiplier : float, default 1.0
        Passed to the STK topology graph, which scales its vertex positions by
        ``scale_multiplier`` times the largest building-block diameter. A bulky
        node next to a short linker (a Zr6 node with a phenylene) is then placed
        far from its linkers. To correct it, build once, note the node-node
        distance ``d0`` and the distance you want ``d`` (linker length plus two
        metal-ligand bonds), and set ``scale_multiplier = d / d0``.
    linker_smiles, node_smiles : str, optional
        Deprecated aliases of ``linker`` and ``node``.
    """

    # Input normalization
    linker_input = linker if linker is not None else linker_smiles
    node_input = node if node is not None else node_smiles

    self.linker = normalize_molecule_input(
        mol=linker_input,
        default=self.default_linker,
    )

    self.node = normalize_molecule_input(
        mol=node_input,
        default=self.default_node,
    )

    self.linker_fg = (
        linker_fg
        if linker_fg is not None
        else self.default_linker_fg
    )

    self.node_fg = (
        node_fg
        if node_fg is not None
        else self.default_node_fg
        if node_input is None
        else None
    )

    self.node_fg_count = (
        node_fg_count
        if node_fg_count is not None
        else self.default_node_fg_count
    )

    self.smarts_pattern = smarts_pattern
    self.optimizer_step = optimizer_step
    self.distance_threshold = distance_threshold
    self.expansion_factor = expansion_factor
    self.scale_multiplier = scale_multiplier

    # Internal state
    self._stk_cage = None
    self._ase_cage = None
    self._fg_anchors = None
    self._fg_anchor_indices = None
    self._fg_anchor_h_positions = None
    self._fg_per_linker = None
    self._linker_atom_indices = None
    self._node_centers = None

Tet4_4Di8CageBuilder

Tet4_4Di8CageBuilder(linker: MoleculeInput = None, node: MoleculeInput = None, linker_fg=None, node_fg=None, node_fg_count: int = None, smarts_pattern: str = None, optimizer_step: float = 0.01, distance_threshold: float = 5.0, expansion_factor: float = 1.0, scale_multiplier: float = 1.0, linker_smiles: str = None, node_smiles: str = None)

Bases: CageBuilder

Tet4-4Di8: 4 tetratopic nodes + 8 ditopic linkers (FourPlusEight). Point group D4h.

Examples:

>>> from cage_isomer_builder.cage import Tet4_4Di8CageBuilder
>>> cage = Tet4_4Di8CageBuilder()           # default single-atom [Zr] node + p-phenylenediamine
>>> _ = cage.build()
>>> cage.to_ase().get_chemical_formula()
'C48H32N16Zr4'
Source code in cage_isomer_builder/cage/base.py
def __init__(
    self,
    linker: MoleculeInput = None,
    node: MoleculeInput = None,
    linker_fg=None,
    node_fg=None,
    node_fg_count: int = None,
    smarts_pattern: str = None,
    optimizer_step: float = 0.01,
    distance_threshold: float = 5.0,
    expansion_factor: float = 1.0,
    scale_multiplier: float = 1.0,
    linker_smiles: str = None,
    node_smiles: str = None,
):
    """
    Initialise a cage builder.

    The linker and node may be a SMILES string, an ASE ``Atoms`` object, or a
    structure file readable by ASE (``.xyz``, ``.mol``, ``.mol2``, ``.sdf``,
    ``.pdb``, ``.cif``, ...).

    Functional groups (the connection points) are found in this order:

    1. **Single atom** (nodes only): a node of one atom (e.g. ``"[Zn]"``)
       becomes an ``stk.SingleAtom`` building block.
    2. **Dummy atoms**: ``X`` atoms in a structure, or ``*``, ``[*]`` or
       ``[#0]`` in a SMILES string, mark the connection points. SMILES dummies
       are rewritten as ``[Fr]`` placeholders (STK cannot build atomic number
       0) and matched by the SMARTS ``[Fr][*]``.
    3. **Given factory**: ``linker_fg`` or ``node_fg``.
    4. **Automatic**: the factories of ``FG_FACTORY_MAP`` are tried in turn.

    Parameters
    ----------
    linker : MoleculeInput, optional
        Linker building block. Defaults to ``default_linker``.
    node : MoleculeInput, optional
        Node building block. Defaults to ``default_node``.
    linker_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the linker: a key of ``FG_FACTORY_MAP``, a
        factory instance, or ``None`` for automatic detection.
    node_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the node. ``"single_atom"`` for an
        isolated metal, ``None`` for automatic detection. The default node uses
        ``default_node_fg``; a given node defaults to automatic detection.
    node_fg_count : int, optional
        Number of functional groups of a single-atom node (ignored otherwise).
        Defaults to ``default_node_fg_count``.
    smarts_pattern : str, optional
        SMARTS pattern used when ``linker_fg`` or ``node_fg`` is ``"smarts"``.
    optimizer_step : float, default 0.01
        Step size of the STK ``Collapser`` optimiser.
    distance_threshold : float, default 5.0
        Distance threshold (Angstrom) of the STK ``Collapser`` optimiser.
    expansion_factor : float, default 1.0
        After assembly, every building block is translated rigidly so that its
        distance from the cage centroid is multiplied by this factor. Use a value
        slightly above 1 when bulky nodes overlap their neighbours in the
        initial placement; the smallest factor is ``2 * r_max / d`` for a node of
        outer radius ``r_max`` and vertex-vertex distance ``d`` (about 1.15 for
        ``uio66_tri_node``).
    scale_multiplier : float, default 1.0
        Passed to the STK topology graph, which scales its vertex positions by
        ``scale_multiplier`` times the largest building-block diameter. A bulky
        node next to a short linker (a Zr6 node with a phenylene) is then placed
        far from its linkers. To correct it, build once, note the node-node
        distance ``d0`` and the distance you want ``d`` (linker length plus two
        metal-ligand bonds), and set ``scale_multiplier = d / d0``.
    linker_smiles, node_smiles : str, optional
        Deprecated aliases of ``linker`` and ``node``.
    """

    # Input normalization
    linker_input = linker if linker is not None else linker_smiles
    node_input = node if node is not None else node_smiles

    self.linker = normalize_molecule_input(
        mol=linker_input,
        default=self.default_linker,
    )

    self.node = normalize_molecule_input(
        mol=node_input,
        default=self.default_node,
    )

    self.linker_fg = (
        linker_fg
        if linker_fg is not None
        else self.default_linker_fg
    )

    self.node_fg = (
        node_fg
        if node_fg is not None
        else self.default_node_fg
        if node_input is None
        else None
    )

    self.node_fg_count = (
        node_fg_count
        if node_fg_count is not None
        else self.default_node_fg_count
    )

    self.smarts_pattern = smarts_pattern
    self.optimizer_step = optimizer_step
    self.distance_threshold = distance_threshold
    self.expansion_factor = expansion_factor
    self.scale_multiplier = scale_multiplier

    # Internal state
    self._stk_cage = None
    self._ase_cage = None
    self._fg_anchors = None
    self._fg_anchor_indices = None
    self._fg_anchor_h_positions = None
    self._fg_per_linker = None
    self._linker_atom_indices = None
    self._node_centers = None

Tet5Di10CageBuilder

Tet5Di10CageBuilder(linker: MoleculeInput = None, node: MoleculeInput = None, linker_fg=None, node_fg=None, node_fg_count: int = None, smarts_pattern: str = None, optimizer_step: float = 0.01, distance_threshold: float = 5.0, expansion_factor: float = 1.0, scale_multiplier: float = 1.0, linker_smiles: str = None, node_smiles: str = None)

Bases: CageBuilder

Tet5Di10: 5 tetratopic nodes (pentagonal arrangement) + 10 ditopic linkers (FivePlusTen). Point group D5h.

Examples:

>>> from cage_isomer_builder.cage import Tet5Di10CageBuilder
>>> cage = Tet5Di10CageBuilder()           # default single-atom [Zr] node + p-phenylenediamine
>>> _ = cage.build()
>>> cage.to_ase().get_chemical_formula()
'C60H40N20Zr5'
Source code in cage_isomer_builder/cage/base.py
def __init__(
    self,
    linker: MoleculeInput = None,
    node: MoleculeInput = None,
    linker_fg=None,
    node_fg=None,
    node_fg_count: int = None,
    smarts_pattern: str = None,
    optimizer_step: float = 0.01,
    distance_threshold: float = 5.0,
    expansion_factor: float = 1.0,
    scale_multiplier: float = 1.0,
    linker_smiles: str = None,
    node_smiles: str = None,
):
    """
    Initialise a cage builder.

    The linker and node may be a SMILES string, an ASE ``Atoms`` object, or a
    structure file readable by ASE (``.xyz``, ``.mol``, ``.mol2``, ``.sdf``,
    ``.pdb``, ``.cif``, ...).

    Functional groups (the connection points) are found in this order:

    1. **Single atom** (nodes only): a node of one atom (e.g. ``"[Zn]"``)
       becomes an ``stk.SingleAtom`` building block.
    2. **Dummy atoms**: ``X`` atoms in a structure, or ``*``, ``[*]`` or
       ``[#0]`` in a SMILES string, mark the connection points. SMILES dummies
       are rewritten as ``[Fr]`` placeholders (STK cannot build atomic number
       0) and matched by the SMARTS ``[Fr][*]``.
    3. **Given factory**: ``linker_fg`` or ``node_fg``.
    4. **Automatic**: the factories of ``FG_FACTORY_MAP`` are tried in turn.

    Parameters
    ----------
    linker : MoleculeInput, optional
        Linker building block. Defaults to ``default_linker``.
    node : MoleculeInput, optional
        Node building block. Defaults to ``default_node``.
    linker_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the linker: a key of ``FG_FACTORY_MAP``, a
        factory instance, or ``None`` for automatic detection.
    node_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the node. ``"single_atom"`` for an
        isolated metal, ``None`` for automatic detection. The default node uses
        ``default_node_fg``; a given node defaults to automatic detection.
    node_fg_count : int, optional
        Number of functional groups of a single-atom node (ignored otherwise).
        Defaults to ``default_node_fg_count``.
    smarts_pattern : str, optional
        SMARTS pattern used when ``linker_fg`` or ``node_fg`` is ``"smarts"``.
    optimizer_step : float, default 0.01
        Step size of the STK ``Collapser`` optimiser.
    distance_threshold : float, default 5.0
        Distance threshold (Angstrom) of the STK ``Collapser`` optimiser.
    expansion_factor : float, default 1.0
        After assembly, every building block is translated rigidly so that its
        distance from the cage centroid is multiplied by this factor. Use a value
        slightly above 1 when bulky nodes overlap their neighbours in the
        initial placement; the smallest factor is ``2 * r_max / d`` for a node of
        outer radius ``r_max`` and vertex-vertex distance ``d`` (about 1.15 for
        ``uio66_tri_node``).
    scale_multiplier : float, default 1.0
        Passed to the STK topology graph, which scales its vertex positions by
        ``scale_multiplier`` times the largest building-block diameter. A bulky
        node next to a short linker (a Zr6 node with a phenylene) is then placed
        far from its linkers. To correct it, build once, note the node-node
        distance ``d0`` and the distance you want ``d`` (linker length plus two
        metal-ligand bonds), and set ``scale_multiplier = d / d0``.
    linker_smiles, node_smiles : str, optional
        Deprecated aliases of ``linker`` and ``node``.
    """

    # Input normalization
    linker_input = linker if linker is not None else linker_smiles
    node_input = node if node is not None else node_smiles

    self.linker = normalize_molecule_input(
        mol=linker_input,
        default=self.default_linker,
    )

    self.node = normalize_molecule_input(
        mol=node_input,
        default=self.default_node,
    )

    self.linker_fg = (
        linker_fg
        if linker_fg is not None
        else self.default_linker_fg
    )

    self.node_fg = (
        node_fg
        if node_fg is not None
        else self.default_node_fg
        if node_input is None
        else None
    )

    self.node_fg_count = (
        node_fg_count
        if node_fg_count is not None
        else self.default_node_fg_count
    )

    self.smarts_pattern = smarts_pattern
    self.optimizer_step = optimizer_step
    self.distance_threshold = distance_threshold
    self.expansion_factor = expansion_factor
    self.scale_multiplier = scale_multiplier

    # Internal state
    self._stk_cage = None
    self._ase_cage = None
    self._fg_anchors = None
    self._fg_anchor_indices = None
    self._fg_anchor_h_positions = None
    self._fg_per_linker = None
    self._linker_atom_indices = None
    self._node_centers = None

Tet6Di12CageBuilder

Tet6Di12CageBuilder(linker: MoleculeInput = None, node: MoleculeInput = None, linker_fg=None, node_fg=None, node_fg_count: int = None, smarts_pattern: str = None, optimizer_step: float = 0.01, distance_threshold: float = 5.0, expansion_factor: float = 1.0, scale_multiplier: float = 1.0, linker_smiles: str = None, node_smiles: str = None)

Bases: CageBuilder

Tet6Di12: 6 tetratopic nodes + 12 ditopic linkers (SixPlusTwelve). Point group Oh.

Examples:

>>> from cage_isomer_builder.cage import Tet6Di12CageBuilder
>>> cage = Tet6Di12CageBuilder()           # default single-atom [Zr] node + p-phenylenediamine
>>> _ = cage.build()
>>> cage.to_ase().get_chemical_formula()
'C72H48N24Zr6'
Source code in cage_isomer_builder/cage/base.py
def __init__(
    self,
    linker: MoleculeInput = None,
    node: MoleculeInput = None,
    linker_fg=None,
    node_fg=None,
    node_fg_count: int = None,
    smarts_pattern: str = None,
    optimizer_step: float = 0.01,
    distance_threshold: float = 5.0,
    expansion_factor: float = 1.0,
    scale_multiplier: float = 1.0,
    linker_smiles: str = None,
    node_smiles: str = None,
):
    """
    Initialise a cage builder.

    The linker and node may be a SMILES string, an ASE ``Atoms`` object, or a
    structure file readable by ASE (``.xyz``, ``.mol``, ``.mol2``, ``.sdf``,
    ``.pdb``, ``.cif``, ...).

    Functional groups (the connection points) are found in this order:

    1. **Single atom** (nodes only): a node of one atom (e.g. ``"[Zn]"``)
       becomes an ``stk.SingleAtom`` building block.
    2. **Dummy atoms**: ``X`` atoms in a structure, or ``*``, ``[*]`` or
       ``[#0]`` in a SMILES string, mark the connection points. SMILES dummies
       are rewritten as ``[Fr]`` placeholders (STK cannot build atomic number
       0) and matched by the SMARTS ``[Fr][*]``.
    3. **Given factory**: ``linker_fg`` or ``node_fg``.
    4. **Automatic**: the factories of ``FG_FACTORY_MAP`` are tried in turn.

    Parameters
    ----------
    linker : MoleculeInput, optional
        Linker building block. Defaults to ``default_linker``.
    node : MoleculeInput, optional
        Node building block. Defaults to ``default_node``.
    linker_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the linker: a key of ``FG_FACTORY_MAP``, a
        factory instance, or ``None`` for automatic detection.
    node_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the node. ``"single_atom"`` for an
        isolated metal, ``None`` for automatic detection. The default node uses
        ``default_node_fg``; a given node defaults to automatic detection.
    node_fg_count : int, optional
        Number of functional groups of a single-atom node (ignored otherwise).
        Defaults to ``default_node_fg_count``.
    smarts_pattern : str, optional
        SMARTS pattern used when ``linker_fg`` or ``node_fg`` is ``"smarts"``.
    optimizer_step : float, default 0.01
        Step size of the STK ``Collapser`` optimiser.
    distance_threshold : float, default 5.0
        Distance threshold (Angstrom) of the STK ``Collapser`` optimiser.
    expansion_factor : float, default 1.0
        After assembly, every building block is translated rigidly so that its
        distance from the cage centroid is multiplied by this factor. Use a value
        slightly above 1 when bulky nodes overlap their neighbours in the
        initial placement; the smallest factor is ``2 * r_max / d`` for a node of
        outer radius ``r_max`` and vertex-vertex distance ``d`` (about 1.15 for
        ``uio66_tri_node``).
    scale_multiplier : float, default 1.0
        Passed to the STK topology graph, which scales its vertex positions by
        ``scale_multiplier`` times the largest building-block diameter. A bulky
        node next to a short linker (a Zr6 node with a phenylene) is then placed
        far from its linkers. To correct it, build once, note the node-node
        distance ``d0`` and the distance you want ``d`` (linker length plus two
        metal-ligand bonds), and set ``scale_multiplier = d / d0``.
    linker_smiles, node_smiles : str, optional
        Deprecated aliases of ``linker`` and ``node``.
    """

    # Input normalization
    linker_input = linker if linker is not None else linker_smiles
    node_input = node if node is not None else node_smiles

    self.linker = normalize_molecule_input(
        mol=linker_input,
        default=self.default_linker,
    )

    self.node = normalize_molecule_input(
        mol=node_input,
        default=self.default_node,
    )

    self.linker_fg = (
        linker_fg
        if linker_fg is not None
        else self.default_linker_fg
    )

    self.node_fg = (
        node_fg
        if node_fg is not None
        else self.default_node_fg
        if node_input is None
        else None
    )

    self.node_fg_count = (
        node_fg_count
        if node_fg_count is not None
        else self.default_node_fg_count
    )

    self.smarts_pattern = smarts_pattern
    self.optimizer_step = optimizer_step
    self.distance_threshold = distance_threshold
    self.expansion_factor = expansion_factor
    self.scale_multiplier = scale_multiplier

    # Internal state
    self._stk_cage = None
    self._ase_cage = None
    self._fg_anchors = None
    self._fg_anchor_indices = None
    self._fg_anchor_h_positions = None
    self._fg_per_linker = None
    self._linker_atom_indices = None
    self._node_centers = None

Tet8Di16CageBuilder

Tet8Di16CageBuilder(linker: MoleculeInput = None, node: MoleculeInput = None, linker_fg=None, node_fg=None, node_fg_count: int = None, smarts_pattern: str = None, optimizer_step: float = 0.01, distance_threshold: float = 5.0, expansion_factor: float = 1.0, scale_multiplier: float = 1.0, linker_smiles: str = None, node_smiles: str = None)

Bases: CageBuilder

Tet8Di16: 8 tetratopic nodes + 16 ditopic linkers (EightPlusSixteen). Point group D4d.

Examples:

>>> from cage_isomer_builder.cage import Tet8Di16CageBuilder
>>> cage = Tet8Di16CageBuilder()           # default single-atom [Zr] node + p-phenylenediamine
>>> _ = cage.build()
>>> cage.to_ase().get_chemical_formula()
'C96H64N32Zr8'
Source code in cage_isomer_builder/cage/base.py
def __init__(
    self,
    linker: MoleculeInput = None,
    node: MoleculeInput = None,
    linker_fg=None,
    node_fg=None,
    node_fg_count: int = None,
    smarts_pattern: str = None,
    optimizer_step: float = 0.01,
    distance_threshold: float = 5.0,
    expansion_factor: float = 1.0,
    scale_multiplier: float = 1.0,
    linker_smiles: str = None,
    node_smiles: str = None,
):
    """
    Initialise a cage builder.

    The linker and node may be a SMILES string, an ASE ``Atoms`` object, or a
    structure file readable by ASE (``.xyz``, ``.mol``, ``.mol2``, ``.sdf``,
    ``.pdb``, ``.cif``, ...).

    Functional groups (the connection points) are found in this order:

    1. **Single atom** (nodes only): a node of one atom (e.g. ``"[Zn]"``)
       becomes an ``stk.SingleAtom`` building block.
    2. **Dummy atoms**: ``X`` atoms in a structure, or ``*``, ``[*]`` or
       ``[#0]`` in a SMILES string, mark the connection points. SMILES dummies
       are rewritten as ``[Fr]`` placeholders (STK cannot build atomic number
       0) and matched by the SMARTS ``[Fr][*]``.
    3. **Given factory**: ``linker_fg`` or ``node_fg``.
    4. **Automatic**: the factories of ``FG_FACTORY_MAP`` are tried in turn.

    Parameters
    ----------
    linker : MoleculeInput, optional
        Linker building block. Defaults to ``default_linker``.
    node : MoleculeInput, optional
        Node building block. Defaults to ``default_node``.
    linker_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the linker: a key of ``FG_FACTORY_MAP``, a
        factory instance, or ``None`` for automatic detection.
    node_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the node. ``"single_atom"`` for an
        isolated metal, ``None`` for automatic detection. The default node uses
        ``default_node_fg``; a given node defaults to automatic detection.
    node_fg_count : int, optional
        Number of functional groups of a single-atom node (ignored otherwise).
        Defaults to ``default_node_fg_count``.
    smarts_pattern : str, optional
        SMARTS pattern used when ``linker_fg`` or ``node_fg`` is ``"smarts"``.
    optimizer_step : float, default 0.01
        Step size of the STK ``Collapser`` optimiser.
    distance_threshold : float, default 5.0
        Distance threshold (Angstrom) of the STK ``Collapser`` optimiser.
    expansion_factor : float, default 1.0
        After assembly, every building block is translated rigidly so that its
        distance from the cage centroid is multiplied by this factor. Use a value
        slightly above 1 when bulky nodes overlap their neighbours in the
        initial placement; the smallest factor is ``2 * r_max / d`` for a node of
        outer radius ``r_max`` and vertex-vertex distance ``d`` (about 1.15 for
        ``uio66_tri_node``).
    scale_multiplier : float, default 1.0
        Passed to the STK topology graph, which scales its vertex positions by
        ``scale_multiplier`` times the largest building-block diameter. A bulky
        node next to a short linker (a Zr6 node with a phenylene) is then placed
        far from its linkers. To correct it, build once, note the node-node
        distance ``d0`` and the distance you want ``d`` (linker length plus two
        metal-ligand bonds), and set ``scale_multiplier = d / d0``.
    linker_smiles, node_smiles : str, optional
        Deprecated aliases of ``linker`` and ``node``.
    """

    # Input normalization
    linker_input = linker if linker is not None else linker_smiles
    node_input = node if node is not None else node_smiles

    self.linker = normalize_molecule_input(
        mol=linker_input,
        default=self.default_linker,
    )

    self.node = normalize_molecule_input(
        mol=node_input,
        default=self.default_node,
    )

    self.linker_fg = (
        linker_fg
        if linker_fg is not None
        else self.default_linker_fg
    )

    self.node_fg = (
        node_fg
        if node_fg is not None
        else self.default_node_fg
        if node_input is None
        else None
    )

    self.node_fg_count = (
        node_fg_count
        if node_fg_count is not None
        else self.default_node_fg_count
    )

    self.smarts_pattern = smarts_pattern
    self.optimizer_step = optimizer_step
    self.distance_threshold = distance_threshold
    self.expansion_factor = expansion_factor
    self.scale_multiplier = scale_multiplier

    # Internal state
    self._stk_cage = None
    self._ase_cage = None
    self._fg_anchors = None
    self._fg_anchor_indices = None
    self._fg_anchor_h_positions = None
    self._fg_per_linker = None
    self._linker_atom_indices = None
    self._node_centers = None

Tet16Di32CageBuilder

Tet16Di32CageBuilder(*args, optimizer_step=1.5, distance_threshold=6.0, **kwargs)

Bases: CageBuilder

Tet16Di32: M12L24, 12 tetratopic nodes + 24 ditopic linkers. Point group D4h.

Examples:

>>> from cage_isomer_builder.cage import Tet16Di32CageBuilder
>>> cage = Tet16Di32CageBuilder()           # default single-atom [Zr] node + p-phenylenediamine
>>> _ = cage.build()
>>> cage.to_ase().get_chemical_formula()
'C144H96N48Zr12'
Source code in cage_isomer_builder/cage/library.py
def __init__(self, *args, optimizer_step=1.5, distance_threshold=6.0, **kwargs):
    super().__init__(
        *args,
        optimizer_step=optimizer_step,
        distance_threshold=distance_threshold,
        **kwargs,
    )

Tet24Di48CageBuilder

Tet24Di48CageBuilder(linker: MoleculeInput = None, node: MoleculeInput = None, linker_fg=None, node_fg=None, node_fg_count: int = None, smarts_pattern: str = None, optimizer_step: float = 0.01, distance_threshold: float = 5.0, expansion_factor: float = 1.0, scale_multiplier: float = 1.0, linker_smiles: str = None, node_smiles: str = None)

Bases: CageBuilder

Tet24Di48: M24L48, 24 tetratopic nodes + 48 ditopic linkers. Point group Oh.

Examples:

>>> from cage_isomer_builder.cage import Tet24Di48CageBuilder
>>> cage = Tet24Di48CageBuilder()           # default single-atom [Zr] node + p-phenylenediamine
>>> _ = cage.build()
>>> cage.to_ase().get_chemical_formula()
'C288H192N96Zr24'
Source code in cage_isomer_builder/cage/base.py
def __init__(
    self,
    linker: MoleculeInput = None,
    node: MoleculeInput = None,
    linker_fg=None,
    node_fg=None,
    node_fg_count: int = None,
    smarts_pattern: str = None,
    optimizer_step: float = 0.01,
    distance_threshold: float = 5.0,
    expansion_factor: float = 1.0,
    scale_multiplier: float = 1.0,
    linker_smiles: str = None,
    node_smiles: str = None,
):
    """
    Initialise a cage builder.

    The linker and node may be a SMILES string, an ASE ``Atoms`` object, or a
    structure file readable by ASE (``.xyz``, ``.mol``, ``.mol2``, ``.sdf``,
    ``.pdb``, ``.cif``, ...).

    Functional groups (the connection points) are found in this order:

    1. **Single atom** (nodes only): a node of one atom (e.g. ``"[Zn]"``)
       becomes an ``stk.SingleAtom`` building block.
    2. **Dummy atoms**: ``X`` atoms in a structure, or ``*``, ``[*]`` or
       ``[#0]`` in a SMILES string, mark the connection points. SMILES dummies
       are rewritten as ``[Fr]`` placeholders (STK cannot build atomic number
       0) and matched by the SMARTS ``[Fr][*]``.
    3. **Given factory**: ``linker_fg`` or ``node_fg``.
    4. **Automatic**: the factories of ``FG_FACTORY_MAP`` are tried in turn.

    Parameters
    ----------
    linker : MoleculeInput, optional
        Linker building block. Defaults to ``default_linker``.
    node : MoleculeInput, optional
        Node building block. Defaults to ``default_node``.
    linker_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the linker: a key of ``FG_FACTORY_MAP``, a
        factory instance, or ``None`` for automatic detection.
    node_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the node. ``"single_atom"`` for an
        isolated metal, ``None`` for automatic detection. The default node uses
        ``default_node_fg``; a given node defaults to automatic detection.
    node_fg_count : int, optional
        Number of functional groups of a single-atom node (ignored otherwise).
        Defaults to ``default_node_fg_count``.
    smarts_pattern : str, optional
        SMARTS pattern used when ``linker_fg`` or ``node_fg`` is ``"smarts"``.
    optimizer_step : float, default 0.01
        Step size of the STK ``Collapser`` optimiser.
    distance_threshold : float, default 5.0
        Distance threshold (Angstrom) of the STK ``Collapser`` optimiser.
    expansion_factor : float, default 1.0
        After assembly, every building block is translated rigidly so that its
        distance from the cage centroid is multiplied by this factor. Use a value
        slightly above 1 when bulky nodes overlap their neighbours in the
        initial placement; the smallest factor is ``2 * r_max / d`` for a node of
        outer radius ``r_max`` and vertex-vertex distance ``d`` (about 1.15 for
        ``uio66_tri_node``).
    scale_multiplier : float, default 1.0
        Passed to the STK topology graph, which scales its vertex positions by
        ``scale_multiplier`` times the largest building-block diameter. A bulky
        node next to a short linker (a Zr6 node with a phenylene) is then placed
        far from its linkers. To correct it, build once, note the node-node
        distance ``d0`` and the distance you want ``d`` (linker length plus two
        metal-ligand bonds), and set ``scale_multiplier = d / d0``.
    linker_smiles, node_smiles : str, optional
        Deprecated aliases of ``linker`` and ``node``.
    """

    # Input normalization
    linker_input = linker if linker is not None else linker_smiles
    node_input = node if node is not None else node_smiles

    self.linker = normalize_molecule_input(
        mol=linker_input,
        default=self.default_linker,
    )

    self.node = normalize_molecule_input(
        mol=node_input,
        default=self.default_node,
    )

    self.linker_fg = (
        linker_fg
        if linker_fg is not None
        else self.default_linker_fg
    )

    self.node_fg = (
        node_fg
        if node_fg is not None
        else self.default_node_fg
        if node_input is None
        else None
    )

    self.node_fg_count = (
        node_fg_count
        if node_fg_count is not None
        else self.default_node_fg_count
    )

    self.smarts_pattern = smarts_pattern
    self.optimizer_step = optimizer_step
    self.distance_threshold = distance_threshold
    self.expansion_factor = expansion_factor
    self.scale_multiplier = scale_multiplier

    # Internal state
    self._stk_cage = None
    self._ase_cage = None
    self._fg_anchors = None
    self._fg_anchor_indices = None
    self._fg_anchor_h_positions = None
    self._fg_per_linker = None
    self._linker_atom_indices = None
    self._node_centers = None

Tri2Di3CageBuilder

Tri2Di3CageBuilder(linker: MoleculeInput = None, node: MoleculeInput = None, linker_fg=None, node_fg=None, node_fg_count: int = None, smarts_pattern: str = None, optimizer_step: float = 0.01, distance_threshold: float = 5.0, expansion_factor: float = 1.0, scale_multiplier: float = 1.0, linker_smiles: str = None, node_smiles: str = None)

Bases: CageBuilder

Tri2Di3: 2 tritopic (triamine) nodes + 3 ditopic linkers (_TwoPlusThree). Point group D3h.

Examples:

>>> from cage_isomer_builder.cage import Tri2Di3CageBuilder
>>> cage = Tri2Di3CageBuilder()           # default single-atom [Zr] node + p-phenylenediamine
>>> _ = cage.build()
>>> cage.to_ase().get_chemical_formula()
'C18H12N6Zr2'
Source code in cage_isomer_builder/cage/base.py
def __init__(
    self,
    linker: MoleculeInput = None,
    node: MoleculeInput = None,
    linker_fg=None,
    node_fg=None,
    node_fg_count: int = None,
    smarts_pattern: str = None,
    optimizer_step: float = 0.01,
    distance_threshold: float = 5.0,
    expansion_factor: float = 1.0,
    scale_multiplier: float = 1.0,
    linker_smiles: str = None,
    node_smiles: str = None,
):
    """
    Initialise a cage builder.

    The linker and node may be a SMILES string, an ASE ``Atoms`` object, or a
    structure file readable by ASE (``.xyz``, ``.mol``, ``.mol2``, ``.sdf``,
    ``.pdb``, ``.cif``, ...).

    Functional groups (the connection points) are found in this order:

    1. **Single atom** (nodes only): a node of one atom (e.g. ``"[Zn]"``)
       becomes an ``stk.SingleAtom`` building block.
    2. **Dummy atoms**: ``X`` atoms in a structure, or ``*``, ``[*]`` or
       ``[#0]`` in a SMILES string, mark the connection points. SMILES dummies
       are rewritten as ``[Fr]`` placeholders (STK cannot build atomic number
       0) and matched by the SMARTS ``[Fr][*]``.
    3. **Given factory**: ``linker_fg`` or ``node_fg``.
    4. **Automatic**: the factories of ``FG_FACTORY_MAP`` are tried in turn.

    Parameters
    ----------
    linker : MoleculeInput, optional
        Linker building block. Defaults to ``default_linker``.
    node : MoleculeInput, optional
        Node building block. Defaults to ``default_node``.
    linker_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the linker: a key of ``FG_FACTORY_MAP``, a
        factory instance, or ``None`` for automatic detection.
    node_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the node. ``"single_atom"`` for an
        isolated metal, ``None`` for automatic detection. The default node uses
        ``default_node_fg``; a given node defaults to automatic detection.
    node_fg_count : int, optional
        Number of functional groups of a single-atom node (ignored otherwise).
        Defaults to ``default_node_fg_count``.
    smarts_pattern : str, optional
        SMARTS pattern used when ``linker_fg`` or ``node_fg`` is ``"smarts"``.
    optimizer_step : float, default 0.01
        Step size of the STK ``Collapser`` optimiser.
    distance_threshold : float, default 5.0
        Distance threshold (Angstrom) of the STK ``Collapser`` optimiser.
    expansion_factor : float, default 1.0
        After assembly, every building block is translated rigidly so that its
        distance from the cage centroid is multiplied by this factor. Use a value
        slightly above 1 when bulky nodes overlap their neighbours in the
        initial placement; the smallest factor is ``2 * r_max / d`` for a node of
        outer radius ``r_max`` and vertex-vertex distance ``d`` (about 1.15 for
        ``uio66_tri_node``).
    scale_multiplier : float, default 1.0
        Passed to the STK topology graph, which scales its vertex positions by
        ``scale_multiplier`` times the largest building-block diameter. A bulky
        node next to a short linker (a Zr6 node with a phenylene) is then placed
        far from its linkers. To correct it, build once, note the node-node
        distance ``d0`` and the distance you want ``d`` (linker length plus two
        metal-ligand bonds), and set ``scale_multiplier = d / d0``.
    linker_smiles, node_smiles : str, optional
        Deprecated aliases of ``linker`` and ``node``.
    """

    # Input normalization
    linker_input = linker if linker is not None else linker_smiles
    node_input = node if node is not None else node_smiles

    self.linker = normalize_molecule_input(
        mol=linker_input,
        default=self.default_linker,
    )

    self.node = normalize_molecule_input(
        mol=node_input,
        default=self.default_node,
    )

    self.linker_fg = (
        linker_fg
        if linker_fg is not None
        else self.default_linker_fg
    )

    self.node_fg = (
        node_fg
        if node_fg is not None
        else self.default_node_fg
        if node_input is None
        else None
    )

    self.node_fg_count = (
        node_fg_count
        if node_fg_count is not None
        else self.default_node_fg_count
    )

    self.smarts_pattern = smarts_pattern
    self.optimizer_step = optimizer_step
    self.distance_threshold = distance_threshold
    self.expansion_factor = expansion_factor
    self.scale_multiplier = scale_multiplier

    # Internal state
    self._stk_cage = None
    self._ase_cage = None
    self._fg_anchors = None
    self._fg_anchor_indices = None
    self._fg_anchor_h_positions = None
    self._fg_per_linker = None
    self._linker_atom_indices = None
    self._node_centers = None

Tri4Di6CageBuilder

Tri4Di6CageBuilder(linker: MoleculeInput = None, node: MoleculeInput = None, linker_fg=None, node_fg=None, node_fg_count: int = None, smarts_pattern: str = None, optimizer_step: float = 0.01, distance_threshold: float = 5.0, expansion_factor: float = 1.0, scale_multiplier: float = 1.0, linker_smiles: str = None, node_smiles: str = None)

Bases: CageBuilder

Tri4Di6: 4 tritopic nodes + 6 ditopic linkers (FourPlusSix). Point group Td.

With symmetry_method="topology" the operations come from the four node centres (universal_transformation_library), which also works for multi-atom nodes such as Zr6 clusters.

Examples:

>>> from cage_isomer_builder.cage import Tri4Di6CageBuilder
>>> cage = Tri4Di6CageBuilder()           # default single-atom [Zr] node + p-phenylenediamine
>>> _ = cage.build()
>>> cage.to_ase().get_chemical_formula()
'C36H24N12Zr4'
Source code in cage_isomer_builder/cage/base.py
def __init__(
    self,
    linker: MoleculeInput = None,
    node: MoleculeInput = None,
    linker_fg=None,
    node_fg=None,
    node_fg_count: int = None,
    smarts_pattern: str = None,
    optimizer_step: float = 0.01,
    distance_threshold: float = 5.0,
    expansion_factor: float = 1.0,
    scale_multiplier: float = 1.0,
    linker_smiles: str = None,
    node_smiles: str = None,
):
    """
    Initialise a cage builder.

    The linker and node may be a SMILES string, an ASE ``Atoms`` object, or a
    structure file readable by ASE (``.xyz``, ``.mol``, ``.mol2``, ``.sdf``,
    ``.pdb``, ``.cif``, ...).

    Functional groups (the connection points) are found in this order:

    1. **Single atom** (nodes only): a node of one atom (e.g. ``"[Zn]"``)
       becomes an ``stk.SingleAtom`` building block.
    2. **Dummy atoms**: ``X`` atoms in a structure, or ``*``, ``[*]`` or
       ``[#0]`` in a SMILES string, mark the connection points. SMILES dummies
       are rewritten as ``[Fr]`` placeholders (STK cannot build atomic number
       0) and matched by the SMARTS ``[Fr][*]``.
    3. **Given factory**: ``linker_fg`` or ``node_fg``.
    4. **Automatic**: the factories of ``FG_FACTORY_MAP`` are tried in turn.

    Parameters
    ----------
    linker : MoleculeInput, optional
        Linker building block. Defaults to ``default_linker``.
    node : MoleculeInput, optional
        Node building block. Defaults to ``default_node``.
    linker_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the linker: a key of ``FG_FACTORY_MAP``, a
        factory instance, or ``None`` for automatic detection.
    node_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the node. ``"single_atom"`` for an
        isolated metal, ``None`` for automatic detection. The default node uses
        ``default_node_fg``; a given node defaults to automatic detection.
    node_fg_count : int, optional
        Number of functional groups of a single-atom node (ignored otherwise).
        Defaults to ``default_node_fg_count``.
    smarts_pattern : str, optional
        SMARTS pattern used when ``linker_fg`` or ``node_fg`` is ``"smarts"``.
    optimizer_step : float, default 0.01
        Step size of the STK ``Collapser`` optimiser.
    distance_threshold : float, default 5.0
        Distance threshold (Angstrom) of the STK ``Collapser`` optimiser.
    expansion_factor : float, default 1.0
        After assembly, every building block is translated rigidly so that its
        distance from the cage centroid is multiplied by this factor. Use a value
        slightly above 1 when bulky nodes overlap their neighbours in the
        initial placement; the smallest factor is ``2 * r_max / d`` for a node of
        outer radius ``r_max`` and vertex-vertex distance ``d`` (about 1.15 for
        ``uio66_tri_node``).
    scale_multiplier : float, default 1.0
        Passed to the STK topology graph, which scales its vertex positions by
        ``scale_multiplier`` times the largest building-block diameter. A bulky
        node next to a short linker (a Zr6 node with a phenylene) is then placed
        far from its linkers. To correct it, build once, note the node-node
        distance ``d0`` and the distance you want ``d`` (linker length plus two
        metal-ligand bonds), and set ``scale_multiplier = d / d0``.
    linker_smiles, node_smiles : str, optional
        Deprecated aliases of ``linker`` and ``node``.
    """

    # Input normalization
    linker_input = linker if linker is not None else linker_smiles
    node_input = node if node is not None else node_smiles

    self.linker = normalize_molecule_input(
        mol=linker_input,
        default=self.default_linker,
    )

    self.node = normalize_molecule_input(
        mol=node_input,
        default=self.default_node,
    )

    self.linker_fg = (
        linker_fg
        if linker_fg is not None
        else self.default_linker_fg
    )

    self.node_fg = (
        node_fg
        if node_fg is not None
        else self.default_node_fg
        if node_input is None
        else None
    )

    self.node_fg_count = (
        node_fg_count
        if node_fg_count is not None
        else self.default_node_fg_count
    )

    self.smarts_pattern = smarts_pattern
    self.optimizer_step = optimizer_step
    self.distance_threshold = distance_threshold
    self.expansion_factor = expansion_factor
    self.scale_multiplier = scale_multiplier

    # Internal state
    self._stk_cage = None
    self._ase_cage = None
    self._fg_anchors = None
    self._fg_anchor_indices = None
    self._fg_anchor_h_positions = None
    self._fg_per_linker = None
    self._linker_atom_indices = None
    self._node_centers = None

Tri4_2Di6CageBuilder

Tri4_2Di6CageBuilder(linker: MoleculeInput = None, node: MoleculeInput = None, linker_fg=None, node_fg=None, node_fg_count: int = None, smarts_pattern: str = None, optimizer_step: float = 0.01, distance_threshold: float = 5.0, expansion_factor: float = 1.0, scale_multiplier: float = 1.0, linker_smiles: str = None, node_smiles: str = None)

Bases: CageBuilder

Tri4-2Di6: 4 tritopic nodes + 6 ditopic linkers (FourPlusSix2 isomeric variant). Point group D2h.

Examples:

>>> from cage_isomer_builder.cage import Tri4_2Di6CageBuilder
>>> cage = Tri4_2Di6CageBuilder()           # default single-atom [Zr] node + p-phenylenediamine
>>> _ = cage.build()
>>> cage.to_ase().get_chemical_formula()
'C36H24N12Zr4'
Source code in cage_isomer_builder/cage/base.py
def __init__(
    self,
    linker: MoleculeInput = None,
    node: MoleculeInput = None,
    linker_fg=None,
    node_fg=None,
    node_fg_count: int = None,
    smarts_pattern: str = None,
    optimizer_step: float = 0.01,
    distance_threshold: float = 5.0,
    expansion_factor: float = 1.0,
    scale_multiplier: float = 1.0,
    linker_smiles: str = None,
    node_smiles: str = None,
):
    """
    Initialise a cage builder.

    The linker and node may be a SMILES string, an ASE ``Atoms`` object, or a
    structure file readable by ASE (``.xyz``, ``.mol``, ``.mol2``, ``.sdf``,
    ``.pdb``, ``.cif``, ...).

    Functional groups (the connection points) are found in this order:

    1. **Single atom** (nodes only): a node of one atom (e.g. ``"[Zn]"``)
       becomes an ``stk.SingleAtom`` building block.
    2. **Dummy atoms**: ``X`` atoms in a structure, or ``*``, ``[*]`` or
       ``[#0]`` in a SMILES string, mark the connection points. SMILES dummies
       are rewritten as ``[Fr]`` placeholders (STK cannot build atomic number
       0) and matched by the SMARTS ``[Fr][*]``.
    3. **Given factory**: ``linker_fg`` or ``node_fg``.
    4. **Automatic**: the factories of ``FG_FACTORY_MAP`` are tried in turn.

    Parameters
    ----------
    linker : MoleculeInput, optional
        Linker building block. Defaults to ``default_linker``.
    node : MoleculeInput, optional
        Node building block. Defaults to ``default_node``.
    linker_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the linker: a key of ``FG_FACTORY_MAP``, a
        factory instance, or ``None`` for automatic detection.
    node_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the node. ``"single_atom"`` for an
        isolated metal, ``None`` for automatic detection. The default node uses
        ``default_node_fg``; a given node defaults to automatic detection.
    node_fg_count : int, optional
        Number of functional groups of a single-atom node (ignored otherwise).
        Defaults to ``default_node_fg_count``.
    smarts_pattern : str, optional
        SMARTS pattern used when ``linker_fg`` or ``node_fg`` is ``"smarts"``.
    optimizer_step : float, default 0.01
        Step size of the STK ``Collapser`` optimiser.
    distance_threshold : float, default 5.0
        Distance threshold (Angstrom) of the STK ``Collapser`` optimiser.
    expansion_factor : float, default 1.0
        After assembly, every building block is translated rigidly so that its
        distance from the cage centroid is multiplied by this factor. Use a value
        slightly above 1 when bulky nodes overlap their neighbours in the
        initial placement; the smallest factor is ``2 * r_max / d`` for a node of
        outer radius ``r_max`` and vertex-vertex distance ``d`` (about 1.15 for
        ``uio66_tri_node``).
    scale_multiplier : float, default 1.0
        Passed to the STK topology graph, which scales its vertex positions by
        ``scale_multiplier`` times the largest building-block diameter. A bulky
        node next to a short linker (a Zr6 node with a phenylene) is then placed
        far from its linkers. To correct it, build once, note the node-node
        distance ``d0`` and the distance you want ``d`` (linker length plus two
        metal-ligand bonds), and set ``scale_multiplier = d / d0``.
    linker_smiles, node_smiles : str, optional
        Deprecated aliases of ``linker`` and ``node``.
    """

    # Input normalization
    linker_input = linker if linker is not None else linker_smiles
    node_input = node if node is not None else node_smiles

    self.linker = normalize_molecule_input(
        mol=linker_input,
        default=self.default_linker,
    )

    self.node = normalize_molecule_input(
        mol=node_input,
        default=self.default_node,
    )

    self.linker_fg = (
        linker_fg
        if linker_fg is not None
        else self.default_linker_fg
    )

    self.node_fg = (
        node_fg
        if node_fg is not None
        else self.default_node_fg
        if node_input is None
        else None
    )

    self.node_fg_count = (
        node_fg_count
        if node_fg_count is not None
        else self.default_node_fg_count
    )

    self.smarts_pattern = smarts_pattern
    self.optimizer_step = optimizer_step
    self.distance_threshold = distance_threshold
    self.expansion_factor = expansion_factor
    self.scale_multiplier = scale_multiplier

    # Internal state
    self._stk_cage = None
    self._ase_cage = None
    self._fg_anchors = None
    self._fg_anchor_indices = None
    self._fg_anchor_h_positions = None
    self._fg_per_linker = None
    self._linker_atom_indices = None
    self._node_centers = None

Tri6Di9CageBuilder

Tri6Di9CageBuilder(linker: MoleculeInput = None, node: MoleculeInput = None, linker_fg=None, node_fg=None, node_fg_count: int = None, smarts_pattern: str = None, optimizer_step: float = 0.01, distance_threshold: float = 5.0, expansion_factor: float = 1.0, scale_multiplier: float = 1.0, linker_smiles: str = None, node_smiles: str = None)

Bases: CageBuilder

Tri6Di9: 6 tritopic nodes + 9 ditopic linkers (SixPlusNine). Point group D3h.

Examples:

>>> from cage_isomer_builder.cage import Tri6Di9CageBuilder
>>> cage = Tri6Di9CageBuilder()           # default single-atom [Zr] node + p-phenylenediamine
>>> _ = cage.build()
>>> cage.to_ase().get_chemical_formula()
'C54H36N18Zr6'
Source code in cage_isomer_builder/cage/base.py
def __init__(
    self,
    linker: MoleculeInput = None,
    node: MoleculeInput = None,
    linker_fg=None,
    node_fg=None,
    node_fg_count: int = None,
    smarts_pattern: str = None,
    optimizer_step: float = 0.01,
    distance_threshold: float = 5.0,
    expansion_factor: float = 1.0,
    scale_multiplier: float = 1.0,
    linker_smiles: str = None,
    node_smiles: str = None,
):
    """
    Initialise a cage builder.

    The linker and node may be a SMILES string, an ASE ``Atoms`` object, or a
    structure file readable by ASE (``.xyz``, ``.mol``, ``.mol2``, ``.sdf``,
    ``.pdb``, ``.cif``, ...).

    Functional groups (the connection points) are found in this order:

    1. **Single atom** (nodes only): a node of one atom (e.g. ``"[Zn]"``)
       becomes an ``stk.SingleAtom`` building block.
    2. **Dummy atoms**: ``X`` atoms in a structure, or ``*``, ``[*]`` or
       ``[#0]`` in a SMILES string, mark the connection points. SMILES dummies
       are rewritten as ``[Fr]`` placeholders (STK cannot build atomic number
       0) and matched by the SMARTS ``[Fr][*]``.
    3. **Given factory**: ``linker_fg`` or ``node_fg``.
    4. **Automatic**: the factories of ``FG_FACTORY_MAP`` are tried in turn.

    Parameters
    ----------
    linker : MoleculeInput, optional
        Linker building block. Defaults to ``default_linker``.
    node : MoleculeInput, optional
        Node building block. Defaults to ``default_node``.
    linker_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the linker: a key of ``FG_FACTORY_MAP``, a
        factory instance, or ``None`` for automatic detection.
    node_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the node. ``"single_atom"`` for an
        isolated metal, ``None`` for automatic detection. The default node uses
        ``default_node_fg``; a given node defaults to automatic detection.
    node_fg_count : int, optional
        Number of functional groups of a single-atom node (ignored otherwise).
        Defaults to ``default_node_fg_count``.
    smarts_pattern : str, optional
        SMARTS pattern used when ``linker_fg`` or ``node_fg`` is ``"smarts"``.
    optimizer_step : float, default 0.01
        Step size of the STK ``Collapser`` optimiser.
    distance_threshold : float, default 5.0
        Distance threshold (Angstrom) of the STK ``Collapser`` optimiser.
    expansion_factor : float, default 1.0
        After assembly, every building block is translated rigidly so that its
        distance from the cage centroid is multiplied by this factor. Use a value
        slightly above 1 when bulky nodes overlap their neighbours in the
        initial placement; the smallest factor is ``2 * r_max / d`` for a node of
        outer radius ``r_max`` and vertex-vertex distance ``d`` (about 1.15 for
        ``uio66_tri_node``).
    scale_multiplier : float, default 1.0
        Passed to the STK topology graph, which scales its vertex positions by
        ``scale_multiplier`` times the largest building-block diameter. A bulky
        node next to a short linker (a Zr6 node with a phenylene) is then placed
        far from its linkers. To correct it, build once, note the node-node
        distance ``d0`` and the distance you want ``d`` (linker length plus two
        metal-ligand bonds), and set ``scale_multiplier = d / d0``.
    linker_smiles, node_smiles : str, optional
        Deprecated aliases of ``linker`` and ``node``.
    """

    # Input normalization
    linker_input = linker if linker is not None else linker_smiles
    node_input = node if node is not None else node_smiles

    self.linker = normalize_molecule_input(
        mol=linker_input,
        default=self.default_linker,
    )

    self.node = normalize_molecule_input(
        mol=node_input,
        default=self.default_node,
    )

    self.linker_fg = (
        linker_fg
        if linker_fg is not None
        else self.default_linker_fg
    )

    self.node_fg = (
        node_fg
        if node_fg is not None
        else self.default_node_fg
        if node_input is None
        else None
    )

    self.node_fg_count = (
        node_fg_count
        if node_fg_count is not None
        else self.default_node_fg_count
    )

    self.smarts_pattern = smarts_pattern
    self.optimizer_step = optimizer_step
    self.distance_threshold = distance_threshold
    self.expansion_factor = expansion_factor
    self.scale_multiplier = scale_multiplier

    # Internal state
    self._stk_cage = None
    self._ase_cage = None
    self._fg_anchors = None
    self._fg_anchor_indices = None
    self._fg_anchor_h_positions = None
    self._fg_per_linker = None
    self._linker_atom_indices = None
    self._node_centers = None

Tri8Di12CageBuilder

Tri8Di12CageBuilder(linker: MoleculeInput = None, node: MoleculeInput = None, linker_fg=None, node_fg=None, node_fg_count: int = None, smarts_pattern: str = None, optimizer_step: float = 0.01, distance_threshold: float = 5.0, expansion_factor: float = 1.0, scale_multiplier: float = 1.0, linker_smiles: str = None, node_smiles: str = None)

Bases: CageBuilder

Tri8Di12: 8 tritopic nodes + 12 ditopic linkers (EightPlusTwelve). Point group Oh.

With symmetry_method="topology" the operations come from the eight node centres (universal_transformation_library).

Examples:

>>> from cage_isomer_builder.cage import Tri8Di12CageBuilder
>>> cage = Tri8Di12CageBuilder()           # default single-atom [Zr] node + p-phenylenediamine
>>> _ = cage.build()
>>> cage.to_ase().get_chemical_formula()
'C72H48N24Zr8'
Source code in cage_isomer_builder/cage/base.py
def __init__(
    self,
    linker: MoleculeInput = None,
    node: MoleculeInput = None,
    linker_fg=None,
    node_fg=None,
    node_fg_count: int = None,
    smarts_pattern: str = None,
    optimizer_step: float = 0.01,
    distance_threshold: float = 5.0,
    expansion_factor: float = 1.0,
    scale_multiplier: float = 1.0,
    linker_smiles: str = None,
    node_smiles: str = None,
):
    """
    Initialise a cage builder.

    The linker and node may be a SMILES string, an ASE ``Atoms`` object, or a
    structure file readable by ASE (``.xyz``, ``.mol``, ``.mol2``, ``.sdf``,
    ``.pdb``, ``.cif``, ...).

    Functional groups (the connection points) are found in this order:

    1. **Single atom** (nodes only): a node of one atom (e.g. ``"[Zn]"``)
       becomes an ``stk.SingleAtom`` building block.
    2. **Dummy atoms**: ``X`` atoms in a structure, or ``*``, ``[*]`` or
       ``[#0]`` in a SMILES string, mark the connection points. SMILES dummies
       are rewritten as ``[Fr]`` placeholders (STK cannot build atomic number
       0) and matched by the SMARTS ``[Fr][*]``.
    3. **Given factory**: ``linker_fg`` or ``node_fg``.
    4. **Automatic**: the factories of ``FG_FACTORY_MAP`` are tried in turn.

    Parameters
    ----------
    linker : MoleculeInput, optional
        Linker building block. Defaults to ``default_linker``.
    node : MoleculeInput, optional
        Node building block. Defaults to ``default_node``.
    linker_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the linker: a key of ``FG_FACTORY_MAP``, a
        factory instance, or ``None`` for automatic detection.
    node_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the node. ``"single_atom"`` for an
        isolated metal, ``None`` for automatic detection. The default node uses
        ``default_node_fg``; a given node defaults to automatic detection.
    node_fg_count : int, optional
        Number of functional groups of a single-atom node (ignored otherwise).
        Defaults to ``default_node_fg_count``.
    smarts_pattern : str, optional
        SMARTS pattern used when ``linker_fg`` or ``node_fg`` is ``"smarts"``.
    optimizer_step : float, default 0.01
        Step size of the STK ``Collapser`` optimiser.
    distance_threshold : float, default 5.0
        Distance threshold (Angstrom) of the STK ``Collapser`` optimiser.
    expansion_factor : float, default 1.0
        After assembly, every building block is translated rigidly so that its
        distance from the cage centroid is multiplied by this factor. Use a value
        slightly above 1 when bulky nodes overlap their neighbours in the
        initial placement; the smallest factor is ``2 * r_max / d`` for a node of
        outer radius ``r_max`` and vertex-vertex distance ``d`` (about 1.15 for
        ``uio66_tri_node``).
    scale_multiplier : float, default 1.0
        Passed to the STK topology graph, which scales its vertex positions by
        ``scale_multiplier`` times the largest building-block diameter. A bulky
        node next to a short linker (a Zr6 node with a phenylene) is then placed
        far from its linkers. To correct it, build once, note the node-node
        distance ``d0`` and the distance you want ``d`` (linker length plus two
        metal-ligand bonds), and set ``scale_multiplier = d / d0``.
    linker_smiles, node_smiles : str, optional
        Deprecated aliases of ``linker`` and ``node``.
    """

    # Input normalization
    linker_input = linker if linker is not None else linker_smiles
    node_input = node if node is not None else node_smiles

    self.linker = normalize_molecule_input(
        mol=linker_input,
        default=self.default_linker,
    )

    self.node = normalize_molecule_input(
        mol=node_input,
        default=self.default_node,
    )

    self.linker_fg = (
        linker_fg
        if linker_fg is not None
        else self.default_linker_fg
    )

    self.node_fg = (
        node_fg
        if node_fg is not None
        else self.default_node_fg
        if node_input is None
        else None
    )

    self.node_fg_count = (
        node_fg_count
        if node_fg_count is not None
        else self.default_node_fg_count
    )

    self.smarts_pattern = smarts_pattern
    self.optimizer_step = optimizer_step
    self.distance_threshold = distance_threshold
    self.expansion_factor = expansion_factor
    self.scale_multiplier = scale_multiplier

    # Internal state
    self._stk_cage = None
    self._ase_cage = None
    self._fg_anchors = None
    self._fg_anchor_indices = None
    self._fg_anchor_h_positions = None
    self._fg_per_linker = None
    self._linker_atom_indices = None
    self._node_centers = None

Tri20Di30CageBuilder

Tri20Di30CageBuilder(linker: MoleculeInput = None, node: MoleculeInput = None, linker_fg=None, node_fg=None, node_fg_count: int = None, smarts_pattern: str = None, optimizer_step: float = 0.01, distance_threshold: float = 5.0, expansion_factor: float = 1.0, scale_multiplier: float = 1.0, linker_smiles: str = None, node_smiles: str = None)

Bases: CageBuilder

Tri20Di30: 20 tritopic nodes + 30 ditopic linkers (TwentyPlusThirty). Point group Ih.

Full enumeration of 4^30 isomers is impractical; use count_unique_isomers_burnside() instead.

Examples:

>>> from cage_isomer_builder.cage import Tri20Di30CageBuilder
>>> cage = Tri20Di30CageBuilder()           # default single-atom [Zr] node + p-phenylenediamine
>>> _ = cage.build()
>>> cage.to_ase().get_chemical_formula()
'C180H120N60Zr20'
Source code in cage_isomer_builder/cage/base.py
def __init__(
    self,
    linker: MoleculeInput = None,
    node: MoleculeInput = None,
    linker_fg=None,
    node_fg=None,
    node_fg_count: int = None,
    smarts_pattern: str = None,
    optimizer_step: float = 0.01,
    distance_threshold: float = 5.0,
    expansion_factor: float = 1.0,
    scale_multiplier: float = 1.0,
    linker_smiles: str = None,
    node_smiles: str = None,
):
    """
    Initialise a cage builder.

    The linker and node may be a SMILES string, an ASE ``Atoms`` object, or a
    structure file readable by ASE (``.xyz``, ``.mol``, ``.mol2``, ``.sdf``,
    ``.pdb``, ``.cif``, ...).

    Functional groups (the connection points) are found in this order:

    1. **Single atom** (nodes only): a node of one atom (e.g. ``"[Zn]"``)
       becomes an ``stk.SingleAtom`` building block.
    2. **Dummy atoms**: ``X`` atoms in a structure, or ``*``, ``[*]`` or
       ``[#0]`` in a SMILES string, mark the connection points. SMILES dummies
       are rewritten as ``[Fr]`` placeholders (STK cannot build atomic number
       0) and matched by the SMARTS ``[Fr][*]``.
    3. **Given factory**: ``linker_fg`` or ``node_fg``.
    4. **Automatic**: the factories of ``FG_FACTORY_MAP`` are tried in turn.

    Parameters
    ----------
    linker : MoleculeInput, optional
        Linker building block. Defaults to ``default_linker``.
    node : MoleculeInput, optional
        Node building block. Defaults to ``default_node``.
    linker_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the linker: a key of ``FG_FACTORY_MAP``, a
        factory instance, or ``None`` for automatic detection.
    node_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the node. ``"single_atom"`` for an
        isolated metal, ``None`` for automatic detection. The default node uses
        ``default_node_fg``; a given node defaults to automatic detection.
    node_fg_count : int, optional
        Number of functional groups of a single-atom node (ignored otherwise).
        Defaults to ``default_node_fg_count``.
    smarts_pattern : str, optional
        SMARTS pattern used when ``linker_fg`` or ``node_fg`` is ``"smarts"``.
    optimizer_step : float, default 0.01
        Step size of the STK ``Collapser`` optimiser.
    distance_threshold : float, default 5.0
        Distance threshold (Angstrom) of the STK ``Collapser`` optimiser.
    expansion_factor : float, default 1.0
        After assembly, every building block is translated rigidly so that its
        distance from the cage centroid is multiplied by this factor. Use a value
        slightly above 1 when bulky nodes overlap their neighbours in the
        initial placement; the smallest factor is ``2 * r_max / d`` for a node of
        outer radius ``r_max`` and vertex-vertex distance ``d`` (about 1.15 for
        ``uio66_tri_node``).
    scale_multiplier : float, default 1.0
        Passed to the STK topology graph, which scales its vertex positions by
        ``scale_multiplier`` times the largest building-block diameter. A bulky
        node next to a short linker (a Zr6 node with a phenylene) is then placed
        far from its linkers. To correct it, build once, note the node-node
        distance ``d0`` and the distance you want ``d`` (linker length plus two
        metal-ligand bonds), and set ``scale_multiplier = d / d0``.
    linker_smiles, node_smiles : str, optional
        Deprecated aliases of ``linker`` and ``node``.
    """

    # Input normalization
    linker_input = linker if linker is not None else linker_smiles
    node_input = node if node is not None else node_smiles

    self.linker = normalize_molecule_input(
        mol=linker_input,
        default=self.default_linker,
    )

    self.node = normalize_molecule_input(
        mol=node_input,
        default=self.default_node,
    )

    self.linker_fg = (
        linker_fg
        if linker_fg is not None
        else self.default_linker_fg
    )

    self.node_fg = (
        node_fg
        if node_fg is not None
        else self.default_node_fg
        if node_input is None
        else None
    )

    self.node_fg_count = (
        node_fg_count
        if node_fg_count is not None
        else self.default_node_fg_count
    )

    self.smarts_pattern = smarts_pattern
    self.optimizer_step = optimizer_step
    self.distance_threshold = distance_threshold
    self.expansion_factor = expansion_factor
    self.scale_multiplier = scale_multiplier

    # Internal state
    self._stk_cage = None
    self._ase_cage = None
    self._fg_anchors = None
    self._fg_anchor_indices = None
    self._fg_anchor_h_positions = None
    self._fg_per_linker = None
    self._linker_atom_indices = None
    self._node_centers = None

Tet6Tri8CageBuilder

Tet6Tri8CageBuilder(linker: MoleculeInput = None, node: MoleculeInput = None, linker_fg=None, node_fg=None, node_fg_count: int = None, smarts_pattern: str = None, optimizer_step: float = 0.01, distance_threshold: float = 5.0, expansion_factor: float = 1.0, scale_multiplier: float = 1.0, linker_smiles: str = None, node_smiles: str = None)

Bases: CageBuilder

Tet6Tri8: 6 tetratopic nodes + 8 tritopic linkers (SixPlusEight). Point group Oh.

Isomers are counted from the point group detected from the atoms (the default symmetry_method="detect"); there is no hand-written library for symmetry_method="topology".

Examples:

>>> from cage_isomer_builder.cage import Tet6Tri8CageBuilder
>>> cage = Tet6Tri8CageBuilder()           # default single-atom [Zr] node + 1,3,5-triaminobenzene
>>> _ = cage.build()
>>> cage.to_ase().get_chemical_formula()
'C48H24N24Zr6'
Source code in cage_isomer_builder/cage/base.py
def __init__(
    self,
    linker: MoleculeInput = None,
    node: MoleculeInput = None,
    linker_fg=None,
    node_fg=None,
    node_fg_count: int = None,
    smarts_pattern: str = None,
    optimizer_step: float = 0.01,
    distance_threshold: float = 5.0,
    expansion_factor: float = 1.0,
    scale_multiplier: float = 1.0,
    linker_smiles: str = None,
    node_smiles: str = None,
):
    """
    Initialise a cage builder.

    The linker and node may be a SMILES string, an ASE ``Atoms`` object, or a
    structure file readable by ASE (``.xyz``, ``.mol``, ``.mol2``, ``.sdf``,
    ``.pdb``, ``.cif``, ...).

    Functional groups (the connection points) are found in this order:

    1. **Single atom** (nodes only): a node of one atom (e.g. ``"[Zn]"``)
       becomes an ``stk.SingleAtom`` building block.
    2. **Dummy atoms**: ``X`` atoms in a structure, or ``*``, ``[*]`` or
       ``[#0]`` in a SMILES string, mark the connection points. SMILES dummies
       are rewritten as ``[Fr]`` placeholders (STK cannot build atomic number
       0) and matched by the SMARTS ``[Fr][*]``.
    3. **Given factory**: ``linker_fg`` or ``node_fg``.
    4. **Automatic**: the factories of ``FG_FACTORY_MAP`` are tried in turn.

    Parameters
    ----------
    linker : MoleculeInput, optional
        Linker building block. Defaults to ``default_linker``.
    node : MoleculeInput, optional
        Node building block. Defaults to ``default_node``.
    linker_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the linker: a key of ``FG_FACTORY_MAP``, a
        factory instance, or ``None`` for automatic detection.
    node_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the node. ``"single_atom"`` for an
        isolated metal, ``None`` for automatic detection. The default node uses
        ``default_node_fg``; a given node defaults to automatic detection.
    node_fg_count : int, optional
        Number of functional groups of a single-atom node (ignored otherwise).
        Defaults to ``default_node_fg_count``.
    smarts_pattern : str, optional
        SMARTS pattern used when ``linker_fg`` or ``node_fg`` is ``"smarts"``.
    optimizer_step : float, default 0.01
        Step size of the STK ``Collapser`` optimiser.
    distance_threshold : float, default 5.0
        Distance threshold (Angstrom) of the STK ``Collapser`` optimiser.
    expansion_factor : float, default 1.0
        After assembly, every building block is translated rigidly so that its
        distance from the cage centroid is multiplied by this factor. Use a value
        slightly above 1 when bulky nodes overlap their neighbours in the
        initial placement; the smallest factor is ``2 * r_max / d`` for a node of
        outer radius ``r_max`` and vertex-vertex distance ``d`` (about 1.15 for
        ``uio66_tri_node``).
    scale_multiplier : float, default 1.0
        Passed to the STK topology graph, which scales its vertex positions by
        ``scale_multiplier`` times the largest building-block diameter. A bulky
        node next to a short linker (a Zr6 node with a phenylene) is then placed
        far from its linkers. To correct it, build once, note the node-node
        distance ``d0`` and the distance you want ``d`` (linker length plus two
        metal-ligand bonds), and set ``scale_multiplier = d / d0``.
    linker_smiles, node_smiles : str, optional
        Deprecated aliases of ``linker`` and ``node``.
    """

    # Input normalization
    linker_input = linker if linker is not None else linker_smiles
    node_input = node if node is not None else node_smiles

    self.linker = normalize_molecule_input(
        mol=linker_input,
        default=self.default_linker,
    )

    self.node = normalize_molecule_input(
        mol=node_input,
        default=self.default_node,
    )

    self.linker_fg = (
        linker_fg
        if linker_fg is not None
        else self.default_linker_fg
    )

    self.node_fg = (
        node_fg
        if node_fg is not None
        else self.default_node_fg
        if node_input is None
        else None
    )

    self.node_fg_count = (
        node_fg_count
        if node_fg_count is not None
        else self.default_node_fg_count
    )

    self.smarts_pattern = smarts_pattern
    self.optimizer_step = optimizer_step
    self.distance_threshold = distance_threshold
    self.expansion_factor = expansion_factor
    self.scale_multiplier = scale_multiplier

    # Internal state
    self._stk_cage = None
    self._ase_cage = None
    self._fg_anchors = None
    self._fg_anchor_indices = None
    self._fg_anchor_h_positions = None
    self._fg_per_linker = None
    self._linker_atom_indices = None
    self._node_centers = None

Tri4Tri4CageBuilder

Tri4Tri4CageBuilder(linker: MoleculeInput = None, node: MoleculeInput = None, linker_fg=None, node_fg=None, node_fg_count: int = None, smarts_pattern: str = None, optimizer_step: float = 0.01, distance_threshold: float = 5.0, expansion_factor: float = 1.0, scale_multiplier: float = 1.0, linker_smiles: str = None, node_smiles: str = None)

Bases: CageBuilder

Tri4Tri4: 4 + 4 tritopic building blocks (FourPlusFour). Point group Td.

Isomers are counted from the point group detected from the atoms (the default symmetry_method="detect"); there is no hand-written library for symmetry_method="topology".

Examples:

>>> from cage_isomer_builder.cage import Tri4Tri4CageBuilder
>>> cage = Tri4Tri4CageBuilder()           # default single-atom [Zr] node + 1,3,5-triaminobenzene
>>> _ = cage.build()
>>> cage.to_ase().get_chemical_formula()
'C24H12N12Zr4'
Source code in cage_isomer_builder/cage/base.py
def __init__(
    self,
    linker: MoleculeInput = None,
    node: MoleculeInput = None,
    linker_fg=None,
    node_fg=None,
    node_fg_count: int = None,
    smarts_pattern: str = None,
    optimizer_step: float = 0.01,
    distance_threshold: float = 5.0,
    expansion_factor: float = 1.0,
    scale_multiplier: float = 1.0,
    linker_smiles: str = None,
    node_smiles: str = None,
):
    """
    Initialise a cage builder.

    The linker and node may be a SMILES string, an ASE ``Atoms`` object, or a
    structure file readable by ASE (``.xyz``, ``.mol``, ``.mol2``, ``.sdf``,
    ``.pdb``, ``.cif``, ...).

    Functional groups (the connection points) are found in this order:

    1. **Single atom** (nodes only): a node of one atom (e.g. ``"[Zn]"``)
       becomes an ``stk.SingleAtom`` building block.
    2. **Dummy atoms**: ``X`` atoms in a structure, or ``*``, ``[*]`` or
       ``[#0]`` in a SMILES string, mark the connection points. SMILES dummies
       are rewritten as ``[Fr]`` placeholders (STK cannot build atomic number
       0) and matched by the SMARTS ``[Fr][*]``.
    3. **Given factory**: ``linker_fg`` or ``node_fg``.
    4. **Automatic**: the factories of ``FG_FACTORY_MAP`` are tried in turn.

    Parameters
    ----------
    linker : MoleculeInput, optional
        Linker building block. Defaults to ``default_linker``.
    node : MoleculeInput, optional
        Node building block. Defaults to ``default_node``.
    linker_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the linker: a key of ``FG_FACTORY_MAP``, a
        factory instance, or ``None`` for automatic detection.
    node_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the node. ``"single_atom"`` for an
        isolated metal, ``None`` for automatic detection. The default node uses
        ``default_node_fg``; a given node defaults to automatic detection.
    node_fg_count : int, optional
        Number of functional groups of a single-atom node (ignored otherwise).
        Defaults to ``default_node_fg_count``.
    smarts_pattern : str, optional
        SMARTS pattern used when ``linker_fg`` or ``node_fg`` is ``"smarts"``.
    optimizer_step : float, default 0.01
        Step size of the STK ``Collapser`` optimiser.
    distance_threshold : float, default 5.0
        Distance threshold (Angstrom) of the STK ``Collapser`` optimiser.
    expansion_factor : float, default 1.0
        After assembly, every building block is translated rigidly so that its
        distance from the cage centroid is multiplied by this factor. Use a value
        slightly above 1 when bulky nodes overlap their neighbours in the
        initial placement; the smallest factor is ``2 * r_max / d`` for a node of
        outer radius ``r_max`` and vertex-vertex distance ``d`` (about 1.15 for
        ``uio66_tri_node``).
    scale_multiplier : float, default 1.0
        Passed to the STK topology graph, which scales its vertex positions by
        ``scale_multiplier`` times the largest building-block diameter. A bulky
        node next to a short linker (a Zr6 node with a phenylene) is then placed
        far from its linkers. To correct it, build once, note the node-node
        distance ``d0`` and the distance you want ``d`` (linker length plus two
        metal-ligand bonds), and set ``scale_multiplier = d / d0``.
    linker_smiles, node_smiles : str, optional
        Deprecated aliases of ``linker`` and ``node``.
    """

    # Input normalization
    linker_input = linker if linker is not None else linker_smiles
    node_input = node if node is not None else node_smiles

    self.linker = normalize_molecule_input(
        mol=linker_input,
        default=self.default_linker,
    )

    self.node = normalize_molecule_input(
        mol=node_input,
        default=self.default_node,
    )

    self.linker_fg = (
        linker_fg
        if linker_fg is not None
        else self.default_linker_fg
    )

    self.node_fg = (
        node_fg
        if node_fg is not None
        else self.default_node_fg
        if node_input is None
        else None
    )

    self.node_fg_count = (
        node_fg_count
        if node_fg_count is not None
        else self.default_node_fg_count
    )

    self.smarts_pattern = smarts_pattern
    self.optimizer_step = optimizer_step
    self.distance_threshold = distance_threshold
    self.expansion_factor = expansion_factor
    self.scale_multiplier = scale_multiplier

    # Internal state
    self._stk_cage = None
    self._ase_cage = None
    self._fg_anchors = None
    self._fg_anchor_indices = None
    self._fg_anchor_h_positions = None
    self._fg_per_linker = None
    self._linker_atom_indices = None
    self._node_centers = None

Tri1Tri1CageBuilder

Tri1Tri1CageBuilder(linker: MoleculeInput = None, node: MoleculeInput = None, linker_fg=None, node_fg=None, node_fg_count: int = None, smarts_pattern: str = None, optimizer_step: float = 0.01, distance_threshold: float = 5.0, expansion_factor: float = 1.0, scale_multiplier: float = 1.0, linker_smiles: str = None, node_smiles: str = None)

Bases: CageBuilder

Tri1Tri1: 1 + 1 tritopic building blocks (OnePlusOne). Point group C3v.

Isomers are counted from the point group detected from the atoms (the default symmetry_method="detect"); there is no hand-written library for symmetry_method="topology".

Examples:

>>> from cage_isomer_builder.cage import Tri1Tri1CageBuilder
>>> cage = Tri1Tri1CageBuilder()           # default single-atom [Zr] node + 1,3,5-triaminobenzene
>>> _ = cage.build()
>>> cage.to_ase().get_chemical_formula()
'C6H3N3Zr'
Source code in cage_isomer_builder/cage/base.py
def __init__(
    self,
    linker: MoleculeInput = None,
    node: MoleculeInput = None,
    linker_fg=None,
    node_fg=None,
    node_fg_count: int = None,
    smarts_pattern: str = None,
    optimizer_step: float = 0.01,
    distance_threshold: float = 5.0,
    expansion_factor: float = 1.0,
    scale_multiplier: float = 1.0,
    linker_smiles: str = None,
    node_smiles: str = None,
):
    """
    Initialise a cage builder.

    The linker and node may be a SMILES string, an ASE ``Atoms`` object, or a
    structure file readable by ASE (``.xyz``, ``.mol``, ``.mol2``, ``.sdf``,
    ``.pdb``, ``.cif``, ...).

    Functional groups (the connection points) are found in this order:

    1. **Single atom** (nodes only): a node of one atom (e.g. ``"[Zn]"``)
       becomes an ``stk.SingleAtom`` building block.
    2. **Dummy atoms**: ``X`` atoms in a structure, or ``*``, ``[*]`` or
       ``[#0]`` in a SMILES string, mark the connection points. SMILES dummies
       are rewritten as ``[Fr]`` placeholders (STK cannot build atomic number
       0) and matched by the SMARTS ``[Fr][*]``.
    3. **Given factory**: ``linker_fg`` or ``node_fg``.
    4. **Automatic**: the factories of ``FG_FACTORY_MAP`` are tried in turn.

    Parameters
    ----------
    linker : MoleculeInput, optional
        Linker building block. Defaults to ``default_linker``.
    node : MoleculeInput, optional
        Node building block. Defaults to ``default_node``.
    linker_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the linker: a key of ``FG_FACTORY_MAP``, a
        factory instance, or ``None`` for automatic detection.
    node_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the node. ``"single_atom"`` for an
        isolated metal, ``None`` for automatic detection. The default node uses
        ``default_node_fg``; a given node defaults to automatic detection.
    node_fg_count : int, optional
        Number of functional groups of a single-atom node (ignored otherwise).
        Defaults to ``default_node_fg_count``.
    smarts_pattern : str, optional
        SMARTS pattern used when ``linker_fg`` or ``node_fg`` is ``"smarts"``.
    optimizer_step : float, default 0.01
        Step size of the STK ``Collapser`` optimiser.
    distance_threshold : float, default 5.0
        Distance threshold (Angstrom) of the STK ``Collapser`` optimiser.
    expansion_factor : float, default 1.0
        After assembly, every building block is translated rigidly so that its
        distance from the cage centroid is multiplied by this factor. Use a value
        slightly above 1 when bulky nodes overlap their neighbours in the
        initial placement; the smallest factor is ``2 * r_max / d`` for a node of
        outer radius ``r_max`` and vertex-vertex distance ``d`` (about 1.15 for
        ``uio66_tri_node``).
    scale_multiplier : float, default 1.0
        Passed to the STK topology graph, which scales its vertex positions by
        ``scale_multiplier`` times the largest building-block diameter. A bulky
        node next to a short linker (a Zr6 node with a phenylene) is then placed
        far from its linkers. To correct it, build once, note the node-node
        distance ``d0`` and the distance you want ``d`` (linker length plus two
        metal-ligand bonds), and set ``scale_multiplier = d / d0``.
    linker_smiles, node_smiles : str, optional
        Deprecated aliases of ``linker`` and ``node``.
    """

    # Input normalization
    linker_input = linker if linker is not None else linker_smiles
    node_input = node if node is not None else node_smiles

    self.linker = normalize_molecule_input(
        mol=linker_input,
        default=self.default_linker,
    )

    self.node = normalize_molecule_input(
        mol=node_input,
        default=self.default_node,
    )

    self.linker_fg = (
        linker_fg
        if linker_fg is not None
        else self.default_linker_fg
    )

    self.node_fg = (
        node_fg
        if node_fg is not None
        else self.default_node_fg
        if node_input is None
        else None
    )

    self.node_fg_count = (
        node_fg_count
        if node_fg_count is not None
        else self.default_node_fg_count
    )

    self.smarts_pattern = smarts_pattern
    self.optimizer_step = optimizer_step
    self.distance_threshold = distance_threshold
    self.expansion_factor = expansion_factor
    self.scale_multiplier = scale_multiplier

    # Internal state
    self._stk_cage = None
    self._ase_cage = None
    self._fg_anchors = None
    self._fg_anchor_indices = None
    self._fg_anchor_h_positions = None
    self._fg_per_linker = None
    self._linker_atom_indices = None
    self._node_centers = None

Tri2_2Tri2CageBuilder

Tri2_2Tri2CageBuilder(linker: MoleculeInput = None, node: MoleculeInput = None, linker_fg=None, node_fg=None, node_fg_count: int = None, smarts_pattern: str = None, optimizer_step: float = 0.01, distance_threshold: float = 5.0, expansion_factor: float = 1.0, scale_multiplier: float = 1.0, linker_smiles: str = None, node_smiles: str = None)

Bases: CageBuilder

Tri2²Tri2: 2 + 2 tritopic building blocks (TwoPlusTwo). Point group D2h.

Isomers are counted from the point group detected from the atoms (the default symmetry_method="detect"); there is no hand-written library for symmetry_method="topology".

Examples:

>>> from cage_isomer_builder.cage import Tri2_2Tri2CageBuilder
>>> cage = Tri2_2Tri2CageBuilder()           # default single-atom [Zr] node + 1,3,5-triaminobenzene
>>> _ = cage.build()
>>> cage.to_ase().get_chemical_formula()
'C12H6N6Zr2'
Source code in cage_isomer_builder/cage/base.py
def __init__(
    self,
    linker: MoleculeInput = None,
    node: MoleculeInput = None,
    linker_fg=None,
    node_fg=None,
    node_fg_count: int = None,
    smarts_pattern: str = None,
    optimizer_step: float = 0.01,
    distance_threshold: float = 5.0,
    expansion_factor: float = 1.0,
    scale_multiplier: float = 1.0,
    linker_smiles: str = None,
    node_smiles: str = None,
):
    """
    Initialise a cage builder.

    The linker and node may be a SMILES string, an ASE ``Atoms`` object, or a
    structure file readable by ASE (``.xyz``, ``.mol``, ``.mol2``, ``.sdf``,
    ``.pdb``, ``.cif``, ...).

    Functional groups (the connection points) are found in this order:

    1. **Single atom** (nodes only): a node of one atom (e.g. ``"[Zn]"``)
       becomes an ``stk.SingleAtom`` building block.
    2. **Dummy atoms**: ``X`` atoms in a structure, or ``*``, ``[*]`` or
       ``[#0]`` in a SMILES string, mark the connection points. SMILES dummies
       are rewritten as ``[Fr]`` placeholders (STK cannot build atomic number
       0) and matched by the SMARTS ``[Fr][*]``.
    3. **Given factory**: ``linker_fg`` or ``node_fg``.
    4. **Automatic**: the factories of ``FG_FACTORY_MAP`` are tried in turn.

    Parameters
    ----------
    linker : MoleculeInput, optional
        Linker building block. Defaults to ``default_linker``.
    node : MoleculeInput, optional
        Node building block. Defaults to ``default_node``.
    linker_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the linker: a key of ``FG_FACTORY_MAP``, a
        factory instance, or ``None`` for automatic detection.
    node_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the node. ``"single_atom"`` for an
        isolated metal, ``None`` for automatic detection. The default node uses
        ``default_node_fg``; a given node defaults to automatic detection.
    node_fg_count : int, optional
        Number of functional groups of a single-atom node (ignored otherwise).
        Defaults to ``default_node_fg_count``.
    smarts_pattern : str, optional
        SMARTS pattern used when ``linker_fg`` or ``node_fg`` is ``"smarts"``.
    optimizer_step : float, default 0.01
        Step size of the STK ``Collapser`` optimiser.
    distance_threshold : float, default 5.0
        Distance threshold (Angstrom) of the STK ``Collapser`` optimiser.
    expansion_factor : float, default 1.0
        After assembly, every building block is translated rigidly so that its
        distance from the cage centroid is multiplied by this factor. Use a value
        slightly above 1 when bulky nodes overlap their neighbours in the
        initial placement; the smallest factor is ``2 * r_max / d`` for a node of
        outer radius ``r_max`` and vertex-vertex distance ``d`` (about 1.15 for
        ``uio66_tri_node``).
    scale_multiplier : float, default 1.0
        Passed to the STK topology graph, which scales its vertex positions by
        ``scale_multiplier`` times the largest building-block diameter. A bulky
        node next to a short linker (a Zr6 node with a phenylene) is then placed
        far from its linkers. To correct it, build once, note the node-node
        distance ``d0`` and the distance you want ``d`` (linker length plus two
        metal-ligand bonds), and set ``scale_multiplier = d / d0``.
    linker_smiles, node_smiles : str, optional
        Deprecated aliases of ``linker`` and ``node``.
    """

    # Input normalization
    linker_input = linker if linker is not None else linker_smiles
    node_input = node if node is not None else node_smiles

    self.linker = normalize_molecule_input(
        mol=linker_input,
        default=self.default_linker,
    )

    self.node = normalize_molecule_input(
        mol=node_input,
        default=self.default_node,
    )

    self.linker_fg = (
        linker_fg
        if linker_fg is not None
        else self.default_linker_fg
    )

    self.node_fg = (
        node_fg
        if node_fg is not None
        else self.default_node_fg
        if node_input is None
        else None
    )

    self.node_fg_count = (
        node_fg_count
        if node_fg_count is not None
        else self.default_node_fg_count
    )

    self.smarts_pattern = smarts_pattern
    self.optimizer_step = optimizer_step
    self.distance_threshold = distance_threshold
    self.expansion_factor = expansion_factor
    self.scale_multiplier = scale_multiplier

    # Internal state
    self._stk_cage = None
    self._ase_cage = None
    self._fg_anchors = None
    self._fg_anchor_indices = None
    self._fg_anchor_h_positions = None
    self._fg_per_linker = None
    self._linker_atom_indices = None
    self._node_centers = None

M2L4LanternCageBuilder

M2L4LanternCageBuilder(linker: MoleculeInput = None, node: MoleculeInput = None, linker_fg=None, node_fg=None, node_fg_count: int = None, smarts_pattern: str = None, optimizer_step: float = 0.01, distance_threshold: float = 5.0, expansion_factor: float = 1.0, scale_multiplier: float = 1.0, linker_smiles: str = None, node_smiles: str = None)

Bases: CageBuilder

M2L4Lantern: 2 tetratopic nodes + 4 ditopic linkers. Point group D4h.

Examples:

>>> from cage_isomer_builder.cage import M2L4LanternCageBuilder
>>> cage = M2L4LanternCageBuilder()           # default single-atom [Zr] node + p-phenylenediamine
>>> _ = cage.build()
>>> cage.to_ase().get_chemical_formula()
'C24H16N8Zr2'
Source code in cage_isomer_builder/cage/base.py
def __init__(
    self,
    linker: MoleculeInput = None,
    node: MoleculeInput = None,
    linker_fg=None,
    node_fg=None,
    node_fg_count: int = None,
    smarts_pattern: str = None,
    optimizer_step: float = 0.01,
    distance_threshold: float = 5.0,
    expansion_factor: float = 1.0,
    scale_multiplier: float = 1.0,
    linker_smiles: str = None,
    node_smiles: str = None,
):
    """
    Initialise a cage builder.

    The linker and node may be a SMILES string, an ASE ``Atoms`` object, or a
    structure file readable by ASE (``.xyz``, ``.mol``, ``.mol2``, ``.sdf``,
    ``.pdb``, ``.cif``, ...).

    Functional groups (the connection points) are found in this order:

    1. **Single atom** (nodes only): a node of one atom (e.g. ``"[Zn]"``)
       becomes an ``stk.SingleAtom`` building block.
    2. **Dummy atoms**: ``X`` atoms in a structure, or ``*``, ``[*]`` or
       ``[#0]`` in a SMILES string, mark the connection points. SMILES dummies
       are rewritten as ``[Fr]`` placeholders (STK cannot build atomic number
       0) and matched by the SMARTS ``[Fr][*]``.
    3. **Given factory**: ``linker_fg`` or ``node_fg``.
    4. **Automatic**: the factories of ``FG_FACTORY_MAP`` are tried in turn.

    Parameters
    ----------
    linker : MoleculeInput, optional
        Linker building block. Defaults to ``default_linker``.
    node : MoleculeInput, optional
        Node building block. Defaults to ``default_node``.
    linker_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the linker: a key of ``FG_FACTORY_MAP``, a
        factory instance, or ``None`` for automatic detection.
    node_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the node. ``"single_atom"`` for an
        isolated metal, ``None`` for automatic detection. The default node uses
        ``default_node_fg``; a given node defaults to automatic detection.
    node_fg_count : int, optional
        Number of functional groups of a single-atom node (ignored otherwise).
        Defaults to ``default_node_fg_count``.
    smarts_pattern : str, optional
        SMARTS pattern used when ``linker_fg`` or ``node_fg`` is ``"smarts"``.
    optimizer_step : float, default 0.01
        Step size of the STK ``Collapser`` optimiser.
    distance_threshold : float, default 5.0
        Distance threshold (Angstrom) of the STK ``Collapser`` optimiser.
    expansion_factor : float, default 1.0
        After assembly, every building block is translated rigidly so that its
        distance from the cage centroid is multiplied by this factor. Use a value
        slightly above 1 when bulky nodes overlap their neighbours in the
        initial placement; the smallest factor is ``2 * r_max / d`` for a node of
        outer radius ``r_max`` and vertex-vertex distance ``d`` (about 1.15 for
        ``uio66_tri_node``).
    scale_multiplier : float, default 1.0
        Passed to the STK topology graph, which scales its vertex positions by
        ``scale_multiplier`` times the largest building-block diameter. A bulky
        node next to a short linker (a Zr6 node with a phenylene) is then placed
        far from its linkers. To correct it, build once, note the node-node
        distance ``d0`` and the distance you want ``d`` (linker length plus two
        metal-ligand bonds), and set ``scale_multiplier = d / d0``.
    linker_smiles, node_smiles : str, optional
        Deprecated aliases of ``linker`` and ``node``.
    """

    # Input normalization
    linker_input = linker if linker is not None else linker_smiles
    node_input = node if node is not None else node_smiles

    self.linker = normalize_molecule_input(
        mol=linker_input,
        default=self.default_linker,
    )

    self.node = normalize_molecule_input(
        mol=node_input,
        default=self.default_node,
    )

    self.linker_fg = (
        linker_fg
        if linker_fg is not None
        else self.default_linker_fg
    )

    self.node_fg = (
        node_fg
        if node_fg is not None
        else self.default_node_fg
        if node_input is None
        else None
    )

    self.node_fg_count = (
        node_fg_count
        if node_fg_count is not None
        else self.default_node_fg_count
    )

    self.smarts_pattern = smarts_pattern
    self.optimizer_step = optimizer_step
    self.distance_threshold = distance_threshold
    self.expansion_factor = expansion_factor
    self.scale_multiplier = scale_multiplier

    # Internal state
    self._stk_cage = None
    self._ase_cage = None
    self._fg_anchors = None
    self._fg_anchor_indices = None
    self._fg_anchor_h_positions = None
    self._fg_per_linker = None
    self._linker_atom_indices = None
    self._node_centers = None

M3L6CageBuilder

M3L6CageBuilder(linker: MoleculeInput = None, node: MoleculeInput = None, linker_fg=None, node_fg=None, node_fg_count: int = None, smarts_pattern: str = None, optimizer_step: float = 0.01, distance_threshold: float = 5.0, expansion_factor: float = 1.0, scale_multiplier: float = 1.0, linker_smiles: str = None, node_smiles: str = None)

Bases: CageBuilder

M3L6: 3 tetratopic nodes + 6 ditopic linkers. Point group D3h.

Examples:

>>> from cage_isomer_builder.cage import M3L6CageBuilder
>>> cage = M3L6CageBuilder()           # default single-atom [Zr] node + p-phenylenediamine
>>> _ = cage.build()
>>> cage.to_ase().get_chemical_formula()
'C36H24N12Zr3'
Source code in cage_isomer_builder/cage/base.py
def __init__(
    self,
    linker: MoleculeInput = None,
    node: MoleculeInput = None,
    linker_fg=None,
    node_fg=None,
    node_fg_count: int = None,
    smarts_pattern: str = None,
    optimizer_step: float = 0.01,
    distance_threshold: float = 5.0,
    expansion_factor: float = 1.0,
    scale_multiplier: float = 1.0,
    linker_smiles: str = None,
    node_smiles: str = None,
):
    """
    Initialise a cage builder.

    The linker and node may be a SMILES string, an ASE ``Atoms`` object, or a
    structure file readable by ASE (``.xyz``, ``.mol``, ``.mol2``, ``.sdf``,
    ``.pdb``, ``.cif``, ...).

    Functional groups (the connection points) are found in this order:

    1. **Single atom** (nodes only): a node of one atom (e.g. ``"[Zn]"``)
       becomes an ``stk.SingleAtom`` building block.
    2. **Dummy atoms**: ``X`` atoms in a structure, or ``*``, ``[*]`` or
       ``[#0]`` in a SMILES string, mark the connection points. SMILES dummies
       are rewritten as ``[Fr]`` placeholders (STK cannot build atomic number
       0) and matched by the SMARTS ``[Fr][*]``.
    3. **Given factory**: ``linker_fg`` or ``node_fg``.
    4. **Automatic**: the factories of ``FG_FACTORY_MAP`` are tried in turn.

    Parameters
    ----------
    linker : MoleculeInput, optional
        Linker building block. Defaults to ``default_linker``.
    node : MoleculeInput, optional
        Node building block. Defaults to ``default_node``.
    linker_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the linker: a key of ``FG_FACTORY_MAP``, a
        factory instance, or ``None`` for automatic detection.
    node_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the node. ``"single_atom"`` for an
        isolated metal, ``None`` for automatic detection. The default node uses
        ``default_node_fg``; a given node defaults to automatic detection.
    node_fg_count : int, optional
        Number of functional groups of a single-atom node (ignored otherwise).
        Defaults to ``default_node_fg_count``.
    smarts_pattern : str, optional
        SMARTS pattern used when ``linker_fg`` or ``node_fg`` is ``"smarts"``.
    optimizer_step : float, default 0.01
        Step size of the STK ``Collapser`` optimiser.
    distance_threshold : float, default 5.0
        Distance threshold (Angstrom) of the STK ``Collapser`` optimiser.
    expansion_factor : float, default 1.0
        After assembly, every building block is translated rigidly so that its
        distance from the cage centroid is multiplied by this factor. Use a value
        slightly above 1 when bulky nodes overlap their neighbours in the
        initial placement; the smallest factor is ``2 * r_max / d`` for a node of
        outer radius ``r_max`` and vertex-vertex distance ``d`` (about 1.15 for
        ``uio66_tri_node``).
    scale_multiplier : float, default 1.0
        Passed to the STK topology graph, which scales its vertex positions by
        ``scale_multiplier`` times the largest building-block diameter. A bulky
        node next to a short linker (a Zr6 node with a phenylene) is then placed
        far from its linkers. To correct it, build once, note the node-node
        distance ``d0`` and the distance you want ``d`` (linker length plus two
        metal-ligand bonds), and set ``scale_multiplier = d / d0``.
    linker_smiles, node_smiles : str, optional
        Deprecated aliases of ``linker`` and ``node``.
    """

    # Input normalization
    linker_input = linker if linker is not None else linker_smiles
    node_input = node if node is not None else node_smiles

    self.linker = normalize_molecule_input(
        mol=linker_input,
        default=self.default_linker,
    )

    self.node = normalize_molecule_input(
        mol=node_input,
        default=self.default_node,
    )

    self.linker_fg = (
        linker_fg
        if linker_fg is not None
        else self.default_linker_fg
    )

    self.node_fg = (
        node_fg
        if node_fg is not None
        else self.default_node_fg
        if node_input is None
        else None
    )

    self.node_fg_count = (
        node_fg_count
        if node_fg_count is not None
        else self.default_node_fg_count
    )

    self.smarts_pattern = smarts_pattern
    self.optimizer_step = optimizer_step
    self.distance_threshold = distance_threshold
    self.expansion_factor = expansion_factor
    self.scale_multiplier = scale_multiplier

    # Internal state
    self._stk_cage = None
    self._ase_cage = None
    self._fg_anchors = None
    self._fg_anchor_indices = None
    self._fg_anchor_h_positions = None
    self._fg_per_linker = None
    self._linker_atom_indices = None
    self._node_centers = None

M4L6TetrahedronSpacerCageBuilder

M4L6TetrahedronSpacerCageBuilder(linker: MoleculeInput = None, node: MoleculeInput = None, linker_fg=None, node_fg=None, node_fg_count: int = None, smarts_pattern: str = None, optimizer_step: float = 0.01, distance_threshold: float = 5.0, expansion_factor: float = 1.0, scale_multiplier: float = 1.0, linker_smiles: str = None, node_smiles: str = None)

Bases: CageBuilder

M4L6TetrahedronSpacer: 4 tritopic nodes + 6 ditopic (spacered) linkers. Point group Td.

Examples:

>>> from cage_isomer_builder.cage import M4L6TetrahedronSpacerCageBuilder
>>> cage = M4L6TetrahedronSpacerCageBuilder()           # default single-atom [Zr] node + p-phenylenediamine
>>> _ = cage.build()
>>> cage.to_ase().get_chemical_formula()
'C36H24N12Zr4'
Source code in cage_isomer_builder/cage/base.py
def __init__(
    self,
    linker: MoleculeInput = None,
    node: MoleculeInput = None,
    linker_fg=None,
    node_fg=None,
    node_fg_count: int = None,
    smarts_pattern: str = None,
    optimizer_step: float = 0.01,
    distance_threshold: float = 5.0,
    expansion_factor: float = 1.0,
    scale_multiplier: float = 1.0,
    linker_smiles: str = None,
    node_smiles: str = None,
):
    """
    Initialise a cage builder.

    The linker and node may be a SMILES string, an ASE ``Atoms`` object, or a
    structure file readable by ASE (``.xyz``, ``.mol``, ``.mol2``, ``.sdf``,
    ``.pdb``, ``.cif``, ...).

    Functional groups (the connection points) are found in this order:

    1. **Single atom** (nodes only): a node of one atom (e.g. ``"[Zn]"``)
       becomes an ``stk.SingleAtom`` building block.
    2. **Dummy atoms**: ``X`` atoms in a structure, or ``*``, ``[*]`` or
       ``[#0]`` in a SMILES string, mark the connection points. SMILES dummies
       are rewritten as ``[Fr]`` placeholders (STK cannot build atomic number
       0) and matched by the SMARTS ``[Fr][*]``.
    3. **Given factory**: ``linker_fg`` or ``node_fg``.
    4. **Automatic**: the factories of ``FG_FACTORY_MAP`` are tried in turn.

    Parameters
    ----------
    linker : MoleculeInput, optional
        Linker building block. Defaults to ``default_linker``.
    node : MoleculeInput, optional
        Node building block. Defaults to ``default_node``.
    linker_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the linker: a key of ``FG_FACTORY_MAP``, a
        factory instance, or ``None`` for automatic detection.
    node_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the node. ``"single_atom"`` for an
        isolated metal, ``None`` for automatic detection. The default node uses
        ``default_node_fg``; a given node defaults to automatic detection.
    node_fg_count : int, optional
        Number of functional groups of a single-atom node (ignored otherwise).
        Defaults to ``default_node_fg_count``.
    smarts_pattern : str, optional
        SMARTS pattern used when ``linker_fg`` or ``node_fg`` is ``"smarts"``.
    optimizer_step : float, default 0.01
        Step size of the STK ``Collapser`` optimiser.
    distance_threshold : float, default 5.0
        Distance threshold (Angstrom) of the STK ``Collapser`` optimiser.
    expansion_factor : float, default 1.0
        After assembly, every building block is translated rigidly so that its
        distance from the cage centroid is multiplied by this factor. Use a value
        slightly above 1 when bulky nodes overlap their neighbours in the
        initial placement; the smallest factor is ``2 * r_max / d`` for a node of
        outer radius ``r_max`` and vertex-vertex distance ``d`` (about 1.15 for
        ``uio66_tri_node``).
    scale_multiplier : float, default 1.0
        Passed to the STK topology graph, which scales its vertex positions by
        ``scale_multiplier`` times the largest building-block diameter. A bulky
        node next to a short linker (a Zr6 node with a phenylene) is then placed
        far from its linkers. To correct it, build once, note the node-node
        distance ``d0`` and the distance you want ``d`` (linker length plus two
        metal-ligand bonds), and set ``scale_multiplier = d / d0``.
    linker_smiles, node_smiles : str, optional
        Deprecated aliases of ``linker`` and ``node``.
    """

    # Input normalization
    linker_input = linker if linker is not None else linker_smiles
    node_input = node if node is not None else node_smiles

    self.linker = normalize_molecule_input(
        mol=linker_input,
        default=self.default_linker,
    )

    self.node = normalize_molecule_input(
        mol=node_input,
        default=self.default_node,
    )

    self.linker_fg = (
        linker_fg
        if linker_fg is not None
        else self.default_linker_fg
    )

    self.node_fg = (
        node_fg
        if node_fg is not None
        else self.default_node_fg
        if node_input is None
        else None
    )

    self.node_fg_count = (
        node_fg_count
        if node_fg_count is not None
        else self.default_node_fg_count
    )

    self.smarts_pattern = smarts_pattern
    self.optimizer_step = optimizer_step
    self.distance_threshold = distance_threshold
    self.expansion_factor = expansion_factor
    self.scale_multiplier = scale_multiplier

    # Internal state
    self._stk_cage = None
    self._ase_cage = None
    self._fg_anchors = None
    self._fg_anchor_indices = None
    self._fg_anchor_h_positions = None
    self._fg_per_linker = None
    self._linker_atom_indices = None
    self._node_centers = None

M4L8CageBuilder

M4L8CageBuilder(linker: MoleculeInput = None, node: MoleculeInput = None, linker_fg=None, node_fg=None, node_fg_count: int = None, smarts_pattern: str = None, optimizer_step: float = 0.01, distance_threshold: float = 5.0, expansion_factor: float = 1.0, scale_multiplier: float = 1.0, linker_smiles: str = None, node_smiles: str = None)

Bases: CageBuilder

M4L8: 4 tetratopic nodes + 8 ditopic linkers. Point group D2d.

Examples:

>>> from cage_isomer_builder.cage import M4L8CageBuilder
>>> cage = M4L8CageBuilder()           # default single-atom [Zr] node + p-phenylenediamine
>>> _ = cage.build()
>>> cage.to_ase().get_chemical_formula()
'C48H32N16Zr4'
Source code in cage_isomer_builder/cage/base.py
def __init__(
    self,
    linker: MoleculeInput = None,
    node: MoleculeInput = None,
    linker_fg=None,
    node_fg=None,
    node_fg_count: int = None,
    smarts_pattern: str = None,
    optimizer_step: float = 0.01,
    distance_threshold: float = 5.0,
    expansion_factor: float = 1.0,
    scale_multiplier: float = 1.0,
    linker_smiles: str = None,
    node_smiles: str = None,
):
    """
    Initialise a cage builder.

    The linker and node may be a SMILES string, an ASE ``Atoms`` object, or a
    structure file readable by ASE (``.xyz``, ``.mol``, ``.mol2``, ``.sdf``,
    ``.pdb``, ``.cif``, ...).

    Functional groups (the connection points) are found in this order:

    1. **Single atom** (nodes only): a node of one atom (e.g. ``"[Zn]"``)
       becomes an ``stk.SingleAtom`` building block.
    2. **Dummy atoms**: ``X`` atoms in a structure, or ``*``, ``[*]`` or
       ``[#0]`` in a SMILES string, mark the connection points. SMILES dummies
       are rewritten as ``[Fr]`` placeholders (STK cannot build atomic number
       0) and matched by the SMARTS ``[Fr][*]``.
    3. **Given factory**: ``linker_fg`` or ``node_fg``.
    4. **Automatic**: the factories of ``FG_FACTORY_MAP`` are tried in turn.

    Parameters
    ----------
    linker : MoleculeInput, optional
        Linker building block. Defaults to ``default_linker``.
    node : MoleculeInput, optional
        Node building block. Defaults to ``default_node``.
    linker_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the linker: a key of ``FG_FACTORY_MAP``, a
        factory instance, or ``None`` for automatic detection.
    node_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the node. ``"single_atom"`` for an
        isolated metal, ``None`` for automatic detection. The default node uses
        ``default_node_fg``; a given node defaults to automatic detection.
    node_fg_count : int, optional
        Number of functional groups of a single-atom node (ignored otherwise).
        Defaults to ``default_node_fg_count``.
    smarts_pattern : str, optional
        SMARTS pattern used when ``linker_fg`` or ``node_fg`` is ``"smarts"``.
    optimizer_step : float, default 0.01
        Step size of the STK ``Collapser`` optimiser.
    distance_threshold : float, default 5.0
        Distance threshold (Angstrom) of the STK ``Collapser`` optimiser.
    expansion_factor : float, default 1.0
        After assembly, every building block is translated rigidly so that its
        distance from the cage centroid is multiplied by this factor. Use a value
        slightly above 1 when bulky nodes overlap their neighbours in the
        initial placement; the smallest factor is ``2 * r_max / d`` for a node of
        outer radius ``r_max`` and vertex-vertex distance ``d`` (about 1.15 for
        ``uio66_tri_node``).
    scale_multiplier : float, default 1.0
        Passed to the STK topology graph, which scales its vertex positions by
        ``scale_multiplier`` times the largest building-block diameter. A bulky
        node next to a short linker (a Zr6 node with a phenylene) is then placed
        far from its linkers. To correct it, build once, note the node-node
        distance ``d0`` and the distance you want ``d`` (linker length plus two
        metal-ligand bonds), and set ``scale_multiplier = d / d0``.
    linker_smiles, node_smiles : str, optional
        Deprecated aliases of ``linker`` and ``node``.
    """

    # Input normalization
    linker_input = linker if linker is not None else linker_smiles
    node_input = node if node is not None else node_smiles

    self.linker = normalize_molecule_input(
        mol=linker_input,
        default=self.default_linker,
    )

    self.node = normalize_molecule_input(
        mol=node_input,
        default=self.default_node,
    )

    self.linker_fg = (
        linker_fg
        if linker_fg is not None
        else self.default_linker_fg
    )

    self.node_fg = (
        node_fg
        if node_fg is not None
        else self.default_node_fg
        if node_input is None
        else None
    )

    self.node_fg_count = (
        node_fg_count
        if node_fg_count is not None
        else self.default_node_fg_count
    )

    self.smarts_pattern = smarts_pattern
    self.optimizer_step = optimizer_step
    self.distance_threshold = distance_threshold
    self.expansion_factor = expansion_factor
    self.scale_multiplier = scale_multiplier

    # Internal state
    self._stk_cage = None
    self._ase_cage = None
    self._fg_anchors = None
    self._fg_anchor_indices = None
    self._fg_anchor_h_positions = None
    self._fg_per_linker = None
    self._linker_atom_indices = None
    self._node_centers = None

M4L82CageBuilder

M4L82CageBuilder(linker: MoleculeInput = None, node: MoleculeInput = None, linker_fg=None, node_fg=None, node_fg_count: int = None, smarts_pattern: str = None, optimizer_step: float = 0.01, distance_threshold: float = 5.0, expansion_factor: float = 1.0, scale_multiplier: float = 1.0, linker_smiles: str = None, node_smiles: str = None)

Bases: CageBuilder

M4L82: 4 tetratopic nodes + 8 ditopic linkers (M4L8 vertex-arrangement isomer). Point group D2d.

Examples:

>>> from cage_isomer_builder.cage import M4L82CageBuilder
>>> cage = M4L82CageBuilder()           # default single-atom [Zr] node + p-phenylenediamine
>>> _ = cage.build()
>>> cage.to_ase().get_chemical_formula()
'C48H32N16Zr4'
Source code in cage_isomer_builder/cage/base.py
def __init__(
    self,
    linker: MoleculeInput = None,
    node: MoleculeInput = None,
    linker_fg=None,
    node_fg=None,
    node_fg_count: int = None,
    smarts_pattern: str = None,
    optimizer_step: float = 0.01,
    distance_threshold: float = 5.0,
    expansion_factor: float = 1.0,
    scale_multiplier: float = 1.0,
    linker_smiles: str = None,
    node_smiles: str = None,
):
    """
    Initialise a cage builder.

    The linker and node may be a SMILES string, an ASE ``Atoms`` object, or a
    structure file readable by ASE (``.xyz``, ``.mol``, ``.mol2``, ``.sdf``,
    ``.pdb``, ``.cif``, ...).

    Functional groups (the connection points) are found in this order:

    1. **Single atom** (nodes only): a node of one atom (e.g. ``"[Zn]"``)
       becomes an ``stk.SingleAtom`` building block.
    2. **Dummy atoms**: ``X`` atoms in a structure, or ``*``, ``[*]`` or
       ``[#0]`` in a SMILES string, mark the connection points. SMILES dummies
       are rewritten as ``[Fr]`` placeholders (STK cannot build atomic number
       0) and matched by the SMARTS ``[Fr][*]``.
    3. **Given factory**: ``linker_fg`` or ``node_fg``.
    4. **Automatic**: the factories of ``FG_FACTORY_MAP`` are tried in turn.

    Parameters
    ----------
    linker : MoleculeInput, optional
        Linker building block. Defaults to ``default_linker``.
    node : MoleculeInput, optional
        Node building block. Defaults to ``default_node``.
    linker_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the linker: a key of ``FG_FACTORY_MAP``, a
        factory instance, or ``None`` for automatic detection.
    node_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the node. ``"single_atom"`` for an
        isolated metal, ``None`` for automatic detection. The default node uses
        ``default_node_fg``; a given node defaults to automatic detection.
    node_fg_count : int, optional
        Number of functional groups of a single-atom node (ignored otherwise).
        Defaults to ``default_node_fg_count``.
    smarts_pattern : str, optional
        SMARTS pattern used when ``linker_fg`` or ``node_fg`` is ``"smarts"``.
    optimizer_step : float, default 0.01
        Step size of the STK ``Collapser`` optimiser.
    distance_threshold : float, default 5.0
        Distance threshold (Angstrom) of the STK ``Collapser`` optimiser.
    expansion_factor : float, default 1.0
        After assembly, every building block is translated rigidly so that its
        distance from the cage centroid is multiplied by this factor. Use a value
        slightly above 1 when bulky nodes overlap their neighbours in the
        initial placement; the smallest factor is ``2 * r_max / d`` for a node of
        outer radius ``r_max`` and vertex-vertex distance ``d`` (about 1.15 for
        ``uio66_tri_node``).
    scale_multiplier : float, default 1.0
        Passed to the STK topology graph, which scales its vertex positions by
        ``scale_multiplier`` times the largest building-block diameter. A bulky
        node next to a short linker (a Zr6 node with a phenylene) is then placed
        far from its linkers. To correct it, build once, note the node-node
        distance ``d0`` and the distance you want ``d`` (linker length plus two
        metal-ligand bonds), and set ``scale_multiplier = d / d0``.
    linker_smiles, node_smiles : str, optional
        Deprecated aliases of ``linker`` and ``node``.
    """

    # Input normalization
    linker_input = linker if linker is not None else linker_smiles
    node_input = node if node is not None else node_smiles

    self.linker = normalize_molecule_input(
        mol=linker_input,
        default=self.default_linker,
    )

    self.node = normalize_molecule_input(
        mol=node_input,
        default=self.default_node,
    )

    self.linker_fg = (
        linker_fg
        if linker_fg is not None
        else self.default_linker_fg
    )

    self.node_fg = (
        node_fg
        if node_fg is not None
        else self.default_node_fg
        if node_input is None
        else None
    )

    self.node_fg_count = (
        node_fg_count
        if node_fg_count is not None
        else self.default_node_fg_count
    )

    self.smarts_pattern = smarts_pattern
    self.optimizer_step = optimizer_step
    self.distance_threshold = distance_threshold
    self.expansion_factor = expansion_factor
    self.scale_multiplier = scale_multiplier

    # Internal state
    self._stk_cage = None
    self._ase_cage = None
    self._fg_anchors = None
    self._fg_anchor_indices = None
    self._fg_anchor_h_positions = None
    self._fg_per_linker = None
    self._linker_atom_indices = None
    self._node_centers = None

M4L8xCageBuilder

M4L8xCageBuilder(linker: MoleculeInput = None, node: MoleculeInput = None, linker_fg=None, node_fg=None, node_fg_count: int = None, smarts_pattern: str = None, optimizer_step: float = 0.01, distance_threshold: float = 5.0, expansion_factor: float = 1.0, scale_multiplier: float = 1.0, linker_smiles: str = None, node_smiles: str = None)

Bases: CageBuilder

M4L8x: 4 tetratopic nodes + 8 ditopic linkers (M4L8 vertex-arrangement isomer). Point group D2d.

Examples:

>>> from cage_isomer_builder.cage import M4L8xCageBuilder
>>> cage = M4L8xCageBuilder()           # default single-atom [Zr] node + p-phenylenediamine
>>> _ = cage.build()
>>> cage.to_ase().get_chemical_formula()
'C48H32N16Zr4'
Source code in cage_isomer_builder/cage/base.py
def __init__(
    self,
    linker: MoleculeInput = None,
    node: MoleculeInput = None,
    linker_fg=None,
    node_fg=None,
    node_fg_count: int = None,
    smarts_pattern: str = None,
    optimizer_step: float = 0.01,
    distance_threshold: float = 5.0,
    expansion_factor: float = 1.0,
    scale_multiplier: float = 1.0,
    linker_smiles: str = None,
    node_smiles: str = None,
):
    """
    Initialise a cage builder.

    The linker and node may be a SMILES string, an ASE ``Atoms`` object, or a
    structure file readable by ASE (``.xyz``, ``.mol``, ``.mol2``, ``.sdf``,
    ``.pdb``, ``.cif``, ...).

    Functional groups (the connection points) are found in this order:

    1. **Single atom** (nodes only): a node of one atom (e.g. ``"[Zn]"``)
       becomes an ``stk.SingleAtom`` building block.
    2. **Dummy atoms**: ``X`` atoms in a structure, or ``*``, ``[*]`` or
       ``[#0]`` in a SMILES string, mark the connection points. SMILES dummies
       are rewritten as ``[Fr]`` placeholders (STK cannot build atomic number
       0) and matched by the SMARTS ``[Fr][*]``.
    3. **Given factory**: ``linker_fg`` or ``node_fg``.
    4. **Automatic**: the factories of ``FG_FACTORY_MAP`` are tried in turn.

    Parameters
    ----------
    linker : MoleculeInput, optional
        Linker building block. Defaults to ``default_linker``.
    node : MoleculeInput, optional
        Node building block. Defaults to ``default_node``.
    linker_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the linker: a key of ``FG_FACTORY_MAP``, a
        factory instance, or ``None`` for automatic detection.
    node_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the node. ``"single_atom"`` for an
        isolated metal, ``None`` for automatic detection. The default node uses
        ``default_node_fg``; a given node defaults to automatic detection.
    node_fg_count : int, optional
        Number of functional groups of a single-atom node (ignored otherwise).
        Defaults to ``default_node_fg_count``.
    smarts_pattern : str, optional
        SMARTS pattern used when ``linker_fg`` or ``node_fg`` is ``"smarts"``.
    optimizer_step : float, default 0.01
        Step size of the STK ``Collapser`` optimiser.
    distance_threshold : float, default 5.0
        Distance threshold (Angstrom) of the STK ``Collapser`` optimiser.
    expansion_factor : float, default 1.0
        After assembly, every building block is translated rigidly so that its
        distance from the cage centroid is multiplied by this factor. Use a value
        slightly above 1 when bulky nodes overlap their neighbours in the
        initial placement; the smallest factor is ``2 * r_max / d`` for a node of
        outer radius ``r_max`` and vertex-vertex distance ``d`` (about 1.15 for
        ``uio66_tri_node``).
    scale_multiplier : float, default 1.0
        Passed to the STK topology graph, which scales its vertex positions by
        ``scale_multiplier`` times the largest building-block diameter. A bulky
        node next to a short linker (a Zr6 node with a phenylene) is then placed
        far from its linkers. To correct it, build once, note the node-node
        distance ``d0`` and the distance you want ``d`` (linker length plus two
        metal-ligand bonds), and set ``scale_multiplier = d / d0``.
    linker_smiles, node_smiles : str, optional
        Deprecated aliases of ``linker`` and ``node``.
    """

    # Input normalization
    linker_input = linker if linker is not None else linker_smiles
    node_input = node if node is not None else node_smiles

    self.linker = normalize_molecule_input(
        mol=linker_input,
        default=self.default_linker,
    )

    self.node = normalize_molecule_input(
        mol=node_input,
        default=self.default_node,
    )

    self.linker_fg = (
        linker_fg
        if linker_fg is not None
        else self.default_linker_fg
    )

    self.node_fg = (
        node_fg
        if node_fg is not None
        else self.default_node_fg
        if node_input is None
        else None
    )

    self.node_fg_count = (
        node_fg_count
        if node_fg_count is not None
        else self.default_node_fg_count
    )

    self.smarts_pattern = smarts_pattern
    self.optimizer_step = optimizer_step
    self.distance_threshold = distance_threshold
    self.expansion_factor = expansion_factor
    self.scale_multiplier = scale_multiplier

    # Internal state
    self._stk_cage = None
    self._ase_cage = None
    self._fg_anchors = None
    self._fg_anchor_indices = None
    self._fg_anchor_h_positions = None
    self._fg_per_linker = None
    self._linker_atom_indices = None
    self._node_centers = None

M6L12CubeCageBuilder

M6L12CubeCageBuilder(linker: MoleculeInput = None, node: MoleculeInput = None, linker_fg=None, node_fg=None, node_fg_count: int = None, smarts_pattern: str = None, optimizer_step: float = 0.01, distance_threshold: float = 5.0, expansion_factor: float = 1.0, scale_multiplier: float = 1.0, linker_smiles: str = None, node_smiles: str = None)

Bases: CageBuilder

M6L12Cube: 6 tetratopic nodes + 12 ditopic linkers. Point group Oh.

Examples:

>>> from cage_isomer_builder.cage import M6L12CubeCageBuilder
>>> cage = M6L12CubeCageBuilder()           # default single-atom [Zr] node + p-phenylenediamine
>>> _ = cage.build()
>>> cage.to_ase().get_chemical_formula()
'C72H48N24Zr6'
Source code in cage_isomer_builder/cage/base.py
def __init__(
    self,
    linker: MoleculeInput = None,
    node: MoleculeInput = None,
    linker_fg=None,
    node_fg=None,
    node_fg_count: int = None,
    smarts_pattern: str = None,
    optimizer_step: float = 0.01,
    distance_threshold: float = 5.0,
    expansion_factor: float = 1.0,
    scale_multiplier: float = 1.0,
    linker_smiles: str = None,
    node_smiles: str = None,
):
    """
    Initialise a cage builder.

    The linker and node may be a SMILES string, an ASE ``Atoms`` object, or a
    structure file readable by ASE (``.xyz``, ``.mol``, ``.mol2``, ``.sdf``,
    ``.pdb``, ``.cif``, ...).

    Functional groups (the connection points) are found in this order:

    1. **Single atom** (nodes only): a node of one atom (e.g. ``"[Zn]"``)
       becomes an ``stk.SingleAtom`` building block.
    2. **Dummy atoms**: ``X`` atoms in a structure, or ``*``, ``[*]`` or
       ``[#0]`` in a SMILES string, mark the connection points. SMILES dummies
       are rewritten as ``[Fr]`` placeholders (STK cannot build atomic number
       0) and matched by the SMARTS ``[Fr][*]``.
    3. **Given factory**: ``linker_fg`` or ``node_fg``.
    4. **Automatic**: the factories of ``FG_FACTORY_MAP`` are tried in turn.

    Parameters
    ----------
    linker : MoleculeInput, optional
        Linker building block. Defaults to ``default_linker``.
    node : MoleculeInput, optional
        Node building block. Defaults to ``default_node``.
    linker_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the linker: a key of ``FG_FACTORY_MAP``, a
        factory instance, or ``None`` for automatic detection.
    node_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the node. ``"single_atom"`` for an
        isolated metal, ``None`` for automatic detection. The default node uses
        ``default_node_fg``; a given node defaults to automatic detection.
    node_fg_count : int, optional
        Number of functional groups of a single-atom node (ignored otherwise).
        Defaults to ``default_node_fg_count``.
    smarts_pattern : str, optional
        SMARTS pattern used when ``linker_fg`` or ``node_fg`` is ``"smarts"``.
    optimizer_step : float, default 0.01
        Step size of the STK ``Collapser`` optimiser.
    distance_threshold : float, default 5.0
        Distance threshold (Angstrom) of the STK ``Collapser`` optimiser.
    expansion_factor : float, default 1.0
        After assembly, every building block is translated rigidly so that its
        distance from the cage centroid is multiplied by this factor. Use a value
        slightly above 1 when bulky nodes overlap their neighbours in the
        initial placement; the smallest factor is ``2 * r_max / d`` for a node of
        outer radius ``r_max`` and vertex-vertex distance ``d`` (about 1.15 for
        ``uio66_tri_node``).
    scale_multiplier : float, default 1.0
        Passed to the STK topology graph, which scales its vertex positions by
        ``scale_multiplier`` times the largest building-block diameter. A bulky
        node next to a short linker (a Zr6 node with a phenylene) is then placed
        far from its linkers. To correct it, build once, note the node-node
        distance ``d0`` and the distance you want ``d`` (linker length plus two
        metal-ligand bonds), and set ``scale_multiplier = d / d0``.
    linker_smiles, node_smiles : str, optional
        Deprecated aliases of ``linker`` and ``node``.
    """

    # Input normalization
    linker_input = linker if linker is not None else linker_smiles
    node_input = node if node is not None else node_smiles

    self.linker = normalize_molecule_input(
        mol=linker_input,
        default=self.default_linker,
    )

    self.node = normalize_molecule_input(
        mol=node_input,
        default=self.default_node,
    )

    self.linker_fg = (
        linker_fg
        if linker_fg is not None
        else self.default_linker_fg
    )

    self.node_fg = (
        node_fg
        if node_fg is not None
        else self.default_node_fg
        if node_input is None
        else None
    )

    self.node_fg_count = (
        node_fg_count
        if node_fg_count is not None
        else self.default_node_fg_count
    )

    self.smarts_pattern = smarts_pattern
    self.optimizer_step = optimizer_step
    self.distance_threshold = distance_threshold
    self.expansion_factor = expansion_factor
    self.scale_multiplier = scale_multiplier

    # Internal state
    self._stk_cage = None
    self._ase_cage = None
    self._fg_anchors = None
    self._fg_anchor_indices = None
    self._fg_anchor_h_positions = None
    self._fg_per_linker = None
    self._linker_atom_indices = None
    self._node_centers = None

M8L6CubeCageBuilder

M8L6CubeCageBuilder(linker: MoleculeInput = None, node: MoleculeInput = None, linker_fg=None, node_fg=None, node_fg_count: int = None, smarts_pattern: str = None, optimizer_step: float = 0.01, distance_threshold: float = 5.0, expansion_factor: float = 1.0, scale_multiplier: float = 1.0, linker_smiles: str = None, node_smiles: str = None)

Bases: CageBuilder

M8L6Cube: 8 tritopic corner nodes + 6 tetratopic face linkers. Point group Oh.

Unlike most other topologies here, linker must be tetratopic (4 functional groups): it caps a cube face, not an edge.

Examples:

>>> from cage_isomer_builder.cage import M8L6CubeCageBuilder
>>> cage = M8L6CubeCageBuilder()           # default single-atom [Zr] node + 1,2,4,5-tetraaminobenzene
>>> _ = cage.build()
>>> cage.to_ase().get_chemical_formula()
'C36H12N24Zr8'
Source code in cage_isomer_builder/cage/base.py
def __init__(
    self,
    linker: MoleculeInput = None,
    node: MoleculeInput = None,
    linker_fg=None,
    node_fg=None,
    node_fg_count: int = None,
    smarts_pattern: str = None,
    optimizer_step: float = 0.01,
    distance_threshold: float = 5.0,
    expansion_factor: float = 1.0,
    scale_multiplier: float = 1.0,
    linker_smiles: str = None,
    node_smiles: str = None,
):
    """
    Initialise a cage builder.

    The linker and node may be a SMILES string, an ASE ``Atoms`` object, or a
    structure file readable by ASE (``.xyz``, ``.mol``, ``.mol2``, ``.sdf``,
    ``.pdb``, ``.cif``, ...).

    Functional groups (the connection points) are found in this order:

    1. **Single atom** (nodes only): a node of one atom (e.g. ``"[Zn]"``)
       becomes an ``stk.SingleAtom`` building block.
    2. **Dummy atoms**: ``X`` atoms in a structure, or ``*``, ``[*]`` or
       ``[#0]`` in a SMILES string, mark the connection points. SMILES dummies
       are rewritten as ``[Fr]`` placeholders (STK cannot build atomic number
       0) and matched by the SMARTS ``[Fr][*]``.
    3. **Given factory**: ``linker_fg`` or ``node_fg``.
    4. **Automatic**: the factories of ``FG_FACTORY_MAP`` are tried in turn.

    Parameters
    ----------
    linker : MoleculeInput, optional
        Linker building block. Defaults to ``default_linker``.
    node : MoleculeInput, optional
        Node building block. Defaults to ``default_node``.
    linker_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the linker: a key of ``FG_FACTORY_MAP``, a
        factory instance, or ``None`` for automatic detection.
    node_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the node. ``"single_atom"`` for an
        isolated metal, ``None`` for automatic detection. The default node uses
        ``default_node_fg``; a given node defaults to automatic detection.
    node_fg_count : int, optional
        Number of functional groups of a single-atom node (ignored otherwise).
        Defaults to ``default_node_fg_count``.
    smarts_pattern : str, optional
        SMARTS pattern used when ``linker_fg`` or ``node_fg`` is ``"smarts"``.
    optimizer_step : float, default 0.01
        Step size of the STK ``Collapser`` optimiser.
    distance_threshold : float, default 5.0
        Distance threshold (Angstrom) of the STK ``Collapser`` optimiser.
    expansion_factor : float, default 1.0
        After assembly, every building block is translated rigidly so that its
        distance from the cage centroid is multiplied by this factor. Use a value
        slightly above 1 when bulky nodes overlap their neighbours in the
        initial placement; the smallest factor is ``2 * r_max / d`` for a node of
        outer radius ``r_max`` and vertex-vertex distance ``d`` (about 1.15 for
        ``uio66_tri_node``).
    scale_multiplier : float, default 1.0
        Passed to the STK topology graph, which scales its vertex positions by
        ``scale_multiplier`` times the largest building-block diameter. A bulky
        node next to a short linker (a Zr6 node with a phenylene) is then placed
        far from its linkers. To correct it, build once, note the node-node
        distance ``d0`` and the distance you want ``d`` (linker length plus two
        metal-ligand bonds), and set ``scale_multiplier = d / d0``.
    linker_smiles, node_smiles : str, optional
        Deprecated aliases of ``linker`` and ``node``.
    """

    # Input normalization
    linker_input = linker if linker is not None else linker_smiles
    node_input = node if node is not None else node_smiles

    self.linker = normalize_molecule_input(
        mol=linker_input,
        default=self.default_linker,
    )

    self.node = normalize_molecule_input(
        mol=node_input,
        default=self.default_node,
    )

    self.linker_fg = (
        linker_fg
        if linker_fg is not None
        else self.default_linker_fg
    )

    self.node_fg = (
        node_fg
        if node_fg is not None
        else self.default_node_fg
        if node_input is None
        else None
    )

    self.node_fg_count = (
        node_fg_count
        if node_fg_count is not None
        else self.default_node_fg_count
    )

    self.smarts_pattern = smarts_pattern
    self.optimizer_step = optimizer_step
    self.distance_threshold = distance_threshold
    self.expansion_factor = expansion_factor
    self.scale_multiplier = scale_multiplier

    # Internal state
    self._stk_cage = None
    self._ase_cage = None
    self._fg_anchors = None
    self._fg_anchor_indices = None
    self._fg_anchor_h_positions = None
    self._fg_per_linker = None
    self._linker_atom_indices = None
    self._node_centers = None

M9L18CageBuilder

M9L18CageBuilder(linker: MoleculeInput = None, node: MoleculeInput = None, linker_fg=None, node_fg=None, node_fg_count: int = None, smarts_pattern: str = None, optimizer_step: float = 0.01, distance_threshold: float = 5.0, expansion_factor: float = 1.0, scale_multiplier: float = 1.0, linker_smiles: str = None, node_smiles: str = None)

Bases: CageBuilder

M9L18: 9 tetratopic nodes + 18 ditopic linkers.

Isomers are counted from the point group detected from the atoms (the default symmetry_method="detect"). symmetry_method="topology" is not available: with 9 metal nodes, universal_transformation_library's node-permutation search (N! permutations) is past its practical limit.

Examples:

>>> from cage_isomer_builder.cage import M9L18CageBuilder
>>> cage = M9L18CageBuilder()           # default single-atom [Zr] node + p-phenylenediamine
>>> _ = cage.build()
>>> cage.to_ase().get_chemical_formula()
'C108H72N36Zr9'
Source code in cage_isomer_builder/cage/base.py
def __init__(
    self,
    linker: MoleculeInput = None,
    node: MoleculeInput = None,
    linker_fg=None,
    node_fg=None,
    node_fg_count: int = None,
    smarts_pattern: str = None,
    optimizer_step: float = 0.01,
    distance_threshold: float = 5.0,
    expansion_factor: float = 1.0,
    scale_multiplier: float = 1.0,
    linker_smiles: str = None,
    node_smiles: str = None,
):
    """
    Initialise a cage builder.

    The linker and node may be a SMILES string, an ASE ``Atoms`` object, or a
    structure file readable by ASE (``.xyz``, ``.mol``, ``.mol2``, ``.sdf``,
    ``.pdb``, ``.cif``, ...).

    Functional groups (the connection points) are found in this order:

    1. **Single atom** (nodes only): a node of one atom (e.g. ``"[Zn]"``)
       becomes an ``stk.SingleAtom`` building block.
    2. **Dummy atoms**: ``X`` atoms in a structure, or ``*``, ``[*]`` or
       ``[#0]`` in a SMILES string, mark the connection points. SMILES dummies
       are rewritten as ``[Fr]`` placeholders (STK cannot build atomic number
       0) and matched by the SMARTS ``[Fr][*]``.
    3. **Given factory**: ``linker_fg`` or ``node_fg``.
    4. **Automatic**: the factories of ``FG_FACTORY_MAP`` are tried in turn.

    Parameters
    ----------
    linker : MoleculeInput, optional
        Linker building block. Defaults to ``default_linker``.
    node : MoleculeInput, optional
        Node building block. Defaults to ``default_node``.
    linker_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the linker: a key of ``FG_FACTORY_MAP``, a
        factory instance, or ``None`` for automatic detection.
    node_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the node. ``"single_atom"`` for an
        isolated metal, ``None`` for automatic detection. The default node uses
        ``default_node_fg``; a given node defaults to automatic detection.
    node_fg_count : int, optional
        Number of functional groups of a single-atom node (ignored otherwise).
        Defaults to ``default_node_fg_count``.
    smarts_pattern : str, optional
        SMARTS pattern used when ``linker_fg`` or ``node_fg`` is ``"smarts"``.
    optimizer_step : float, default 0.01
        Step size of the STK ``Collapser`` optimiser.
    distance_threshold : float, default 5.0
        Distance threshold (Angstrom) of the STK ``Collapser`` optimiser.
    expansion_factor : float, default 1.0
        After assembly, every building block is translated rigidly so that its
        distance from the cage centroid is multiplied by this factor. Use a value
        slightly above 1 when bulky nodes overlap their neighbours in the
        initial placement; the smallest factor is ``2 * r_max / d`` for a node of
        outer radius ``r_max`` and vertex-vertex distance ``d`` (about 1.15 for
        ``uio66_tri_node``).
    scale_multiplier : float, default 1.0
        Passed to the STK topology graph, which scales its vertex positions by
        ``scale_multiplier`` times the largest building-block diameter. A bulky
        node next to a short linker (a Zr6 node with a phenylene) is then placed
        far from its linkers. To correct it, build once, note the node-node
        distance ``d0`` and the distance you want ``d`` (linker length plus two
        metal-ligand bonds), and set ``scale_multiplier = d / d0``.
    linker_smiles, node_smiles : str, optional
        Deprecated aliases of ``linker`` and ``node``.
    """

    # Input normalization
    linker_input = linker if linker is not None else linker_smiles
    node_input = node if node is not None else node_smiles

    self.linker = normalize_molecule_input(
        mol=linker_input,
        default=self.default_linker,
    )

    self.node = normalize_molecule_input(
        mol=node_input,
        default=self.default_node,
    )

    self.linker_fg = (
        linker_fg
        if linker_fg is not None
        else self.default_linker_fg
    )

    self.node_fg = (
        node_fg
        if node_fg is not None
        else self.default_node_fg
        if node_input is None
        else None
    )

    self.node_fg_count = (
        node_fg_count
        if node_fg_count is not None
        else self.default_node_fg_count
    )

    self.smarts_pattern = smarts_pattern
    self.optimizer_step = optimizer_step
    self.distance_threshold = distance_threshold
    self.expansion_factor = expansion_factor
    self.scale_multiplier = scale_multiplier

    # Internal state
    self._stk_cage = None
    self._ase_cage = None
    self._fg_anchors = None
    self._fg_anchor_indices = None
    self._fg_anchor_h_positions = None
    self._fg_per_linker = None
    self._linker_atom_indices = None
    self._node_centers = None

TenPlusTwentyCageBuilder

TenPlusTwentyCageBuilder(linker: MoleculeInput = None, node: MoleculeInput = None, linker_fg=None, node_fg=None, node_fg_count: int = None, smarts_pattern: str = None, optimizer_step: float = 0.01, distance_threshold: float = 5.0, expansion_factor: float = 1.0, scale_multiplier: float = 1.0, linker_smiles: str = None, node_smiles: str = None)

Bases: CageBuilder

TenPlusTwenty: 10 tetratopic nodes + 20 ditopic linkers.

Isomers are counted from the detected point group (the default); the node-permutation library of symmetry_method="topology" is not available (see M9L18).

Examples:

>>> from cage_isomer_builder.cage import TenPlusTwentyCageBuilder
>>> cage = TenPlusTwentyCageBuilder()           # default single-atom [Zr] node + p-phenylenediamine
>>> _ = cage.build()
>>> cage.to_ase().get_chemical_formula()
'C120H80N40Zr10'
Source code in cage_isomer_builder/cage/base.py
def __init__(
    self,
    linker: MoleculeInput = None,
    node: MoleculeInput = None,
    linker_fg=None,
    node_fg=None,
    node_fg_count: int = None,
    smarts_pattern: str = None,
    optimizer_step: float = 0.01,
    distance_threshold: float = 5.0,
    expansion_factor: float = 1.0,
    scale_multiplier: float = 1.0,
    linker_smiles: str = None,
    node_smiles: str = None,
):
    """
    Initialise a cage builder.

    The linker and node may be a SMILES string, an ASE ``Atoms`` object, or a
    structure file readable by ASE (``.xyz``, ``.mol``, ``.mol2``, ``.sdf``,
    ``.pdb``, ``.cif``, ...).

    Functional groups (the connection points) are found in this order:

    1. **Single atom** (nodes only): a node of one atom (e.g. ``"[Zn]"``)
       becomes an ``stk.SingleAtom`` building block.
    2. **Dummy atoms**: ``X`` atoms in a structure, or ``*``, ``[*]`` or
       ``[#0]`` in a SMILES string, mark the connection points. SMILES dummies
       are rewritten as ``[Fr]`` placeholders (STK cannot build atomic number
       0) and matched by the SMARTS ``[Fr][*]``.
    3. **Given factory**: ``linker_fg`` or ``node_fg``.
    4. **Automatic**: the factories of ``FG_FACTORY_MAP`` are tried in turn.

    Parameters
    ----------
    linker : MoleculeInput, optional
        Linker building block. Defaults to ``default_linker``.
    node : MoleculeInput, optional
        Node building block. Defaults to ``default_node``.
    linker_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the linker: a key of ``FG_FACTORY_MAP``, a
        factory instance, or ``None`` for automatic detection.
    node_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the node. ``"single_atom"`` for an
        isolated metal, ``None`` for automatic detection. The default node uses
        ``default_node_fg``; a given node defaults to automatic detection.
    node_fg_count : int, optional
        Number of functional groups of a single-atom node (ignored otherwise).
        Defaults to ``default_node_fg_count``.
    smarts_pattern : str, optional
        SMARTS pattern used when ``linker_fg`` or ``node_fg`` is ``"smarts"``.
    optimizer_step : float, default 0.01
        Step size of the STK ``Collapser`` optimiser.
    distance_threshold : float, default 5.0
        Distance threshold (Angstrom) of the STK ``Collapser`` optimiser.
    expansion_factor : float, default 1.0
        After assembly, every building block is translated rigidly so that its
        distance from the cage centroid is multiplied by this factor. Use a value
        slightly above 1 when bulky nodes overlap their neighbours in the
        initial placement; the smallest factor is ``2 * r_max / d`` for a node of
        outer radius ``r_max`` and vertex-vertex distance ``d`` (about 1.15 for
        ``uio66_tri_node``).
    scale_multiplier : float, default 1.0
        Passed to the STK topology graph, which scales its vertex positions by
        ``scale_multiplier`` times the largest building-block diameter. A bulky
        node next to a short linker (a Zr6 node with a phenylene) is then placed
        far from its linkers. To correct it, build once, note the node-node
        distance ``d0`` and the distance you want ``d`` (linker length plus two
        metal-ligand bonds), and set ``scale_multiplier = d / d0``.
    linker_smiles, node_smiles : str, optional
        Deprecated aliases of ``linker`` and ``node``.
    """

    # Input normalization
    linker_input = linker if linker is not None else linker_smiles
    node_input = node if node is not None else node_smiles

    self.linker = normalize_molecule_input(
        mol=linker_input,
        default=self.default_linker,
    )

    self.node = normalize_molecule_input(
        mol=node_input,
        default=self.default_node,
    )

    self.linker_fg = (
        linker_fg
        if linker_fg is not None
        else self.default_linker_fg
    )

    self.node_fg = (
        node_fg
        if node_fg is not None
        else self.default_node_fg
        if node_input is None
        else None
    )

    self.node_fg_count = (
        node_fg_count
        if node_fg_count is not None
        else self.default_node_fg_count
    )

    self.smarts_pattern = smarts_pattern
    self.optimizer_step = optimizer_step
    self.distance_threshold = distance_threshold
    self.expansion_factor = expansion_factor
    self.scale_multiplier = scale_multiplier

    # Internal state
    self._stk_cage = None
    self._ase_cage = None
    self._fg_anchors = None
    self._fg_anchor_indices = None
    self._fg_anchor_h_positions = None
    self._fg_per_linker = None
    self._linker_atom_indices = None
    self._node_centers = None

TwelvePlusThirtyCageBuilder

TwelvePlusThirtyCageBuilder(linker: MoleculeInput = None, node: MoleculeInput = None, linker_fg=None, node_fg=None, node_fg_count: int = None, smarts_pattern: str = None, optimizer_step: float = 0.01, distance_threshold: float = 5.0, expansion_factor: float = 1.0, scale_multiplier: float = 1.0, linker_smiles: str = None, node_smiles: str = None)

Bases: CageBuilder

TwelvePlusThirty: 12 pentatopic nodes + 30 ditopic linkers. Point group Ih.

Isomers are counted from the detected point group (the default); the node-permutation library of symmetry_method="topology" is not available (see M9L18).

Examples:

>>> from cage_isomer_builder.cage import TwelvePlusThirtyCageBuilder
>>> cage = TwelvePlusThirtyCageBuilder()           # default single-atom [Zr] node + p-phenylenediamine
>>> _ = cage.build()
>>> cage.to_ase().get_chemical_formula()
'C180H120N60Zr12'
Source code in cage_isomer_builder/cage/base.py
def __init__(
    self,
    linker: MoleculeInput = None,
    node: MoleculeInput = None,
    linker_fg=None,
    node_fg=None,
    node_fg_count: int = None,
    smarts_pattern: str = None,
    optimizer_step: float = 0.01,
    distance_threshold: float = 5.0,
    expansion_factor: float = 1.0,
    scale_multiplier: float = 1.0,
    linker_smiles: str = None,
    node_smiles: str = None,
):
    """
    Initialise a cage builder.

    The linker and node may be a SMILES string, an ASE ``Atoms`` object, or a
    structure file readable by ASE (``.xyz``, ``.mol``, ``.mol2``, ``.sdf``,
    ``.pdb``, ``.cif``, ...).

    Functional groups (the connection points) are found in this order:

    1. **Single atom** (nodes only): a node of one atom (e.g. ``"[Zn]"``)
       becomes an ``stk.SingleAtom`` building block.
    2. **Dummy atoms**: ``X`` atoms in a structure, or ``*``, ``[*]`` or
       ``[#0]`` in a SMILES string, mark the connection points. SMILES dummies
       are rewritten as ``[Fr]`` placeholders (STK cannot build atomic number
       0) and matched by the SMARTS ``[Fr][*]``.
    3. **Given factory**: ``linker_fg`` or ``node_fg``.
    4. **Automatic**: the factories of ``FG_FACTORY_MAP`` are tried in turn.

    Parameters
    ----------
    linker : MoleculeInput, optional
        Linker building block. Defaults to ``default_linker``.
    node : MoleculeInput, optional
        Node building block. Defaults to ``default_node``.
    linker_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the linker: a key of ``FG_FACTORY_MAP``, a
        factory instance, or ``None`` for automatic detection.
    node_fg : str or stk.FunctionalGroupFactory, optional
        Functional-group factory of the node. ``"single_atom"`` for an
        isolated metal, ``None`` for automatic detection. The default node uses
        ``default_node_fg``; a given node defaults to automatic detection.
    node_fg_count : int, optional
        Number of functional groups of a single-atom node (ignored otherwise).
        Defaults to ``default_node_fg_count``.
    smarts_pattern : str, optional
        SMARTS pattern used when ``linker_fg`` or ``node_fg`` is ``"smarts"``.
    optimizer_step : float, default 0.01
        Step size of the STK ``Collapser`` optimiser.
    distance_threshold : float, default 5.0
        Distance threshold (Angstrom) of the STK ``Collapser`` optimiser.
    expansion_factor : float, default 1.0
        After assembly, every building block is translated rigidly so that its
        distance from the cage centroid is multiplied by this factor. Use a value
        slightly above 1 when bulky nodes overlap their neighbours in the
        initial placement; the smallest factor is ``2 * r_max / d`` for a node of
        outer radius ``r_max`` and vertex-vertex distance ``d`` (about 1.15 for
        ``uio66_tri_node``).
    scale_multiplier : float, default 1.0
        Passed to the STK topology graph, which scales its vertex positions by
        ``scale_multiplier`` times the largest building-block diameter. A bulky
        node next to a short linker (a Zr6 node with a phenylene) is then placed
        far from its linkers. To correct it, build once, note the node-node
        distance ``d0`` and the distance you want ``d`` (linker length plus two
        metal-ligand bonds), and set ``scale_multiplier = d / d0``.
    linker_smiles, node_smiles : str, optional
        Deprecated aliases of ``linker`` and ``node``.
    """

    # Input normalization
    linker_input = linker if linker is not None else linker_smiles
    node_input = node if node is not None else node_smiles

    self.linker = normalize_molecule_input(
        mol=linker_input,
        default=self.default_linker,
    )

    self.node = normalize_molecule_input(
        mol=node_input,
        default=self.default_node,
    )

    self.linker_fg = (
        linker_fg
        if linker_fg is not None
        else self.default_linker_fg
    )

    self.node_fg = (
        node_fg
        if node_fg is not None
        else self.default_node_fg
        if node_input is None
        else None
    )

    self.node_fg_count = (
        node_fg_count
        if node_fg_count is not None
        else self.default_node_fg_count
    )

    self.smarts_pattern = smarts_pattern
    self.optimizer_step = optimizer_step
    self.distance_threshold = distance_threshold
    self.expansion_factor = expansion_factor
    self.scale_multiplier = scale_multiplier

    # Internal state
    self._stk_cage = None
    self._ase_cage = None
    self._fg_anchors = None
    self._fg_anchor_indices = None
    self._fg_anchor_h_positions = None
    self._fg_per_linker = None
    self._linker_atom_indices = None
    self._node_centers = None

Building-block helpers

Functions in cage_isomer_builder.cage.base that turn node and linker inputs (SMILES, files, ASE atoms) into STK building blocks, and find the linkers and nodes of a structure.

The cage builder base class: building a cage with STK or loading a structure, optimising it, marking its functional-group sites, counting and enumerating isomers, and computing descriptors.

dummies_to_placeholder

dummies_to_placeholder(smiles: str) -> str

Rewrite every SMILES dummy atom as the [Fr] placeholder that :func:make_dummy_factory matches.

Examples:

>>> from cage_isomer_builder.cage.base import dummies_to_placeholder
>>> dummies_to_placeholder("[*]c1ccc(*)cc1"), dummies_to_placeholder("[1*:1]CC[#0]")
('[Fr]c1ccc([Fr])cc1', '[Fr]CC[Fr]')
Source code in cage_isomer_builder/cage/base.py
def dummies_to_placeholder(smiles: str) -> str:
    """
    Rewrite every SMILES dummy atom as the ``[Fr]`` placeholder that
    :func:`make_dummy_factory` matches.

    Examples
    --------
    >>> from cage_isomer_builder.cage.base import dummies_to_placeholder
    >>> dummies_to_placeholder("[*]c1ccc(*)cc1"), dummies_to_placeholder("[1*:1]CC[#0]")
    ('[Fr]c1ccc([Fr])cc1', '[Fr]CC[Fr]')
    """
    return _DUMMY_RE.sub("[Fr]", smiles)

make_dummy_factory

make_dummy_factory() -> stk.SmartsFunctionalGroupFactory

Factory for dummy atoms attached to any atom, written as the [Fr] placeholder (see :func:dummies_to_placeholder).

Atom 0: dummy atom, deleted. Atom 1: real attachment atom, used as bonder.

Examples:

>>> import stk
>>> from cage_isomer_builder.cage.base import dummies_to_placeholder, make_dummy_factory
>>> smiles = dummies_to_placeholder("[*]c1ccc([*])cc1")
>>> stk.BuildingBlock(smiles, [make_dummy_factory()]).get_num_functional_groups()
2
Source code in cage_isomer_builder/cage/base.py
def make_dummy_factory() -> stk.SmartsFunctionalGroupFactory:
    """
    Factory for dummy atoms attached to any atom, written as the ``[Fr]``
    placeholder (see :func:`dummies_to_placeholder`).

    Atom 0: dummy atom, deleted.
    Atom 1: real attachment atom, used as bonder.

    Examples
    --------
    >>> import stk
    >>> from cage_isomer_builder.cage.base import dummies_to_placeholder, make_dummy_factory
    >>> smiles = dummies_to_placeholder("[*]c1ccc([*])cc1")
    >>> stk.BuildingBlock(smiles, [make_dummy_factory()]).get_num_functional_groups()
    2
    """
    return stk.SmartsFunctionalGroupFactory(
        smarts=DUMMY_SMARTS,
        bonders=(1,),
        deleters=(0,),
    )

find_unique_building_units

find_unique_building_units(list_of_connected_components, bonds_to_break, ase_atom, porphyrin_checker, all_regions)

Split a MOF or cage into its building units, metal SBUs and organic linkers (adapted from mofstructure).

Parameters:

Name Type Description Default
list_of_connected_components list

Connected components of the structure's bond graph.

required
bonds_to_break list of list

Atom indices at each breaking point.

required
ase_atom Atoms
required
porphyrin_checker list of int

Indices of porphyrin atoms.

required
all_regions dict

Region index -> connected-component mapping.

required

Returns:

Name Type Description
mof_metal list of ase.Atoms

Metal building-unit fragments.

mof_linker list of ase.Atoms

Organic linker building-unit fragments.

building_unit_regions dict

Region index -> atom-index mapping.

Examples:

>>> from cage_isomer_builder import example_data
>>> uio66 = example_data.read("RUBTAK01")
>>> from mofstructure.mofdeconstructor import secondary_building_units
>>> from cage_isomer_builder.cage.base import find_unique_building_units
>>> components, breaks, porphyrin, regions, _ = secondary_building_units(uio66)
>>> metals, organics, _ = find_unique_building_units(components, breaks, uio66, porphyrin, regions)
>>> [m.get_chemical_formula() for m in metals], [o.get_chemical_formula() for o in organics]
(['C12O32Zr6'], ['C6H4'])
Source code in cage_isomer_builder/cage/base.py
def find_unique_building_units(list_of_connected_components,
                               bonds_to_break,
                               ase_atom,
                               porphyrin_checker,
                               all_regions):
    """
    Split a MOF or cage into its building units, metal SBUs and organic
    linkers (adapted from mofstructure).

    Parameters
    ----------
    list_of_connected_components : list
        Connected components of the structure's bond graph.
    bonds_to_break : list of list
        Atom indices at each breaking point.
    ase_atom : ase.Atoms
    porphyrin_checker : list of int
        Indices of porphyrin atoms.
    all_regions : dict
        Region index -> connected-component mapping.

    Returns
    -------
    mof_metal : list of ase.Atoms
        Metal building-unit fragments.
    mof_linker : list of ase.Atoms
        Organic linker building-unit fragments.
    building_unit_regions : dict
        Region index -> atom-index mapping.

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> uio66 = example_data.read("RUBTAK01")
    >>> from mofstructure.mofdeconstructor import secondary_building_units
    >>> from cage_isomer_builder.cage.base import find_unique_building_units
    >>> components, breaks, porphyrin, regions, _ = secondary_building_units(uio66)
    >>> metals, organics, _ = find_unique_building_units(components, breaks, uio66, porphyrin, regions)
    >>> [m.get_chemical_formula() for m in metals], [o.get_chemical_formula() for o in organics]
    (['C12O32Zr6'], ['C6H4'])
    """
    mof_metal = []
    mof_linker = []
    building_unit_regions = {}
    all_breaking_point = sum(bonds_to_break, [])
    for idx, key in enumerate(all_regions):
        components = list_of_connected_components[all_regions[key][0]]
        point_of_extension = [i for i in all_breaking_point if i in components]
        mapped_indices = {i: j for j, i in enumerate(components)}
        molecule_to_write = ase_atom[components]
        molecule_to_write.info['point_of_extension'] = [
            mapped_indices[i] for i in point_of_extension]

        atom_indices_mapping = [
            list_of_connected_components[i] for i in all_regions[key]]
        molecule_to_write.info['atom_indices_mapping'] = atom_indices_mapping

        metal = [i.index for i in molecule_to_write if i.symbol in _metal_symbols()
                 and i.index not in porphyrin_checker]
        if len(metal) > 0:
            mof_metal.append(molecule_to_write)
        else:
            mof_linker.append(molecule_to_write)
        building_unit_regions[idx] = molecule_to_write.info['atom_indices_mapping']
    return mof_metal, mof_linker, building_unit_regions

find_linkers

find_linkers(ase_atom)

Every linker of a MOF or cage, grouped by chemical type.

A linker is an organic building unit (from mofstructure's deconstruction) bonded to the framework at two or more points, so terminal ligands (e.g. a thiolate bound to one metal) and unbound guests are not linkers. All linker types are kept. If no unit has two connection points, the first organic unit with at least six atoms is used.

Returns:

Name Type Description
linker_atom_indices list of list of int

Atom indices of every linker instance.

linker_types list of int

Type index of each instance.

type_names list of str

Chemical formula of each type (made unique if two types share one).

metal_atom_indices list of int

Every atom not in a linker.

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage.base import find_linkers
>>> linkers, types, names, rest = find_linkers(example_data.read("ABIXEQ"))
>>> names, len(linkers)                        # two linker types, one of each per cell
(['C18H18N4', 'C6H4'], 2)
>>> find_linkers(example_data.read("ABINOQ"))[2]   # bipyridine; terminal thiolates excluded
['C10H8N2']
Source code in cage_isomer_builder/cage/base.py
def find_linkers(ase_atom):
    """
    Every linker of a MOF or cage, grouped by chemical type.

    A linker is an organic building unit (from mofstructure's deconstruction)
    bonded to the framework at two or more points, so terminal ligands (e.g. a
    thiolate bound to one metal) and unbound guests are not linkers. All linker
    types are kept. If no unit has two connection points, the first organic unit
    with at least six atoms is used.

    Returns
    -------
    linker_atom_indices : list of list of int
        Atom indices of every linker instance.
    linker_types : list of int
        Type index of each instance.
    type_names : list of str
        Chemical formula of each type (made unique if two types share one).
    metal_atom_indices : list of int
        Every atom not in a linker.

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage.base import find_linkers
    >>> linkers, types, names, rest = find_linkers(example_data.read("ABIXEQ"))
    >>> names, len(linkers)                        # two linker types, one of each per cell
    (['C18H18N4', 'C6H4'], 2)
    >>> find_linkers(example_data.read("ABINOQ"))[2]   # bipyridine; terminal thiolates excluded
    ['C10H8N2']
    """
    c_components, breaking_point, porpyrin, regions, _ = secondary_building_units(ase_atom)
    _, organic_sbu, _ = find_unique_building_units(
        c_components, breaking_point, ase_atom, porpyrin, regions)
    chosen = [sbu for sbu in organic_sbu if len(sbu.info['point_of_extension']) >= 2]
    if not chosen:
        chosen = [sbu for sbu in organic_sbu if len(sbu) >= 6][:1]
    if not chosen:
        raise ValueError("no linker found: no organic building unit is bonded to the "
                         "framework at two or more points.")
    linker_atom_indices, linker_types, type_names = [], [], []
    for t, sbu in enumerate(chosen):
        name = sbu.get_chemical_formula()
        while name in type_names:
            name += "'"
        type_names.append(name)
        for instance in sbu.info['atom_indices_mapping']:
            linker_atom_indices.append(list(instance))
            linker_types.append(t)
    in_linker = {i for lk in linker_atom_indices for i in lk}
    rest = [i for i in range(len(ase_atom)) if i not in in_linker]
    return linker_atom_indices, linker_types, type_names, rest

get_sbus_indices

get_sbus_indices(ase_atom)

Return linker and metal atom indices from a MOF or metal-organic cage.

Parameters:

Name Type Description Default
ase_atom Atoms

Structure to analyse.

required

Returns:

Name Type Description
linker_atom_indices list of list of int

Atom indices per organic linker.

metal_atom_indices list of int

Flat list of atom indices belonging to metal nodes.

Examples:

>>> from cage_isomer_builder import example_data
>>> uio66 = example_data.read("RUBTAK01")
>>> from cage_isomer_builder.cage.base import get_sbus_indices
>>> linkers, rest = get_sbus_indices(uio66)
>>> len(linkers), len(linkers[0]), len(rest)    # 24 phenylene rings in the cell
(24, 10, 200)
Source code in cage_isomer_builder/cage/base.py
def get_sbus_indices(ase_atom):
    """
    Return linker and metal atom indices from a MOF or metal-organic cage.

    Parameters
    ----------
    ase_atom : ase.Atoms
        Structure to analyse.

    Returns
    -------
    linker_atom_indices : list of list of int
        Atom indices per organic linker.
    metal_atom_indices : list of int
        Flat list of atom indices belonging to metal nodes.

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> uio66 = example_data.read("RUBTAK01")
    >>> from cage_isomer_builder.cage.base import get_sbus_indices
    >>> linkers, rest = get_sbus_indices(uio66)
    >>> len(linkers), len(linkers[0]), len(rest)    # 24 phenylene rings in the cell
    (24, 10, 200)
    """

    linker_atom_indices, _, _, rest = find_linkers(ase_atom)
    return linker_atom_indices, rest

get_node_centers

get_node_centers(ase_atom, metal_atom_indices)

Return the centre-of-mass position of each metal node instance.

Builds a bond graph restricted to the supplied metal atom indices, finds connected components (one per node cluster), and returns one CoM per component. This works for both single-atom nodes (each atom is its own component) and multi-atom clusters (e.g. Zr6).

metal_atom_indices is every atom outside the linkers (from :func:get_sbus_indices), so groups bonded to a node, such as capping methyls, are part of its cluster.

Parameters:

Name Type Description Default
ase_atom Atoms
required
metal_atom_indices list of int

Flat list of atom indices belonging to nodes (not linkers).

required

Returns:

Name Type Description
node_centers np.ndarray, shape (n_nodes, 3), or None if empty

Examples:

>>> from cage_isomer_builder import example_data
>>> uio66 = example_data.read("RUBTAK01")
>>> from cage_isomer_builder.cage.base import get_node_centers, get_sbus_indices
>>> _, rest = get_sbus_indices(uio66)
>>> get_node_centers(uio66, rest).shape          # the four Zr6 nodes of the fcu cell
(4, 3)
Source code in cage_isomer_builder/cage/base.py
def get_node_centers(ase_atom, metal_atom_indices):
    """
    Return the centre-of-mass position of each metal node instance.

    Builds a bond graph restricted to the supplied metal atom indices,
    finds connected components (one per node cluster), and returns one
    CoM per component. This works for both single-atom nodes (each atom
    is its own component) and multi-atom clusters (e.g. Zr6).

    ``metal_atom_indices`` is every atom outside the linkers (from
    :func:`get_sbus_indices`), so groups bonded to a node, such as capping
    methyls, are part of its cluster.

    Parameters
    ----------
    ase_atom : ase.Atoms
    metal_atom_indices : list of int
        Flat list of atom indices belonging to nodes (not linkers).

    Returns
    -------
    node_centers : np.ndarray, shape (n_nodes, 3), or None if empty

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> uio66 = example_data.read("RUBTAK01")
    >>> from cage_isomer_builder.cage.base import get_node_centers, get_sbus_indices
    >>> _, rest = get_sbus_indices(uio66)
    >>> get_node_centers(uio66, rest).shape          # the four Zr6 nodes of the fcu cell
    (4, 3)
    """
    if not metal_atom_indices:
        return None

    metal_sub = ase_atom[metal_atom_indices]
    adjacency: dict[int, list[int]] = {i: [] for i in range(len(metal_sub))}
    for i, j in bonded_pairs(metal_sub):
        adjacency[i].append(j)
        adjacency[j].append(i)

    # BFS to find connected components within the node subgraph
    n = len(metal_sub)
    visited = [False] * n
    components = []
    for start in range(n):
        if visited[start]:
            continue
        component = []
        queue = [start]
        visited[start] = True
        while queue:
            node = queue.pop()
            component.append(node)
            for nb in adjacency[node]:
                if not visited[nb]:
                    visited[nb] = True
                    queue.append(nb)
        components.append(component)

    centers = [
        ase_atom[[metal_atom_indices[i] for i in comp]].get_center_of_mass()
        for comp in components
    ]
    return np.array(centers)

is_file_like

is_file_like(value: Any) -> bool

Return True if value looks like a molecular structure file path.

Examples:

>>> from cage_isomer_builder.cage.base import is_file_like
>>> is_file_like("linker.xyz"), is_file_like("Nc1ccc(N)cc1")
(True, False)
Source code in cage_isomer_builder/cage/base.py
def is_file_like(value: Any) -> bool:
    """Return True if value looks like a molecular structure file path.

    Examples
    --------
    >>> from cage_isomer_builder.cage.base import is_file_like
    >>> is_file_like("linker.xyz"), is_file_like("Nc1ccc(N)cc1")
    (True, False)
    """
    if not isinstance(value, (str, Path)):
        return False

    path = Path(value)
    return path.suffix.lower() in _STRUCTURE_EXTENSIONS

is_smiles_like

is_smiles_like(value: Any) -> bool

Return True if value should be interpreted as a SMILES string.

Examples:

>>> from cage_isomer_builder.cage.base import is_smiles_like
>>> is_smiles_like("Nc1ccc(N)cc1"), is_smiles_like("linker.mol2")
(True, False)
Source code in cage_isomer_builder/cage/base.py
def is_smiles_like(value: Any) -> bool:
    """Return True if value should be interpreted as a SMILES string.

    Examples
    --------
    >>> from cage_isomer_builder.cage.base import is_smiles_like
    >>> is_smiles_like("Nc1ccc(N)cc1"), is_smiles_like("linker.mol2")
    (True, False)
    """
    return isinstance(value, str) and not is_file_like(value)

atoms_to_smiles

atoms_to_smiles(atoms: Atoms) -> str

Convert ASE Atoms to SMILES using mofstructure/OpenBabel.

Examples:

>>> from ase.build import molecule
>>> from cage_isomer_builder.cage.base import atoms_to_smiles
>>> atoms_to_smiles(molecule("CH3OH")).split()[0]
'CO'
Source code in cage_isomer_builder/cage/base.py
def atoms_to_smiles(atoms: Atoms) -> str:
    """
    Convert ASE Atoms to SMILES using mofstructure/OpenBabel.

    Examples
    --------
    >>> from ase.build import molecule
    >>> from cage_isomer_builder.cage.base import atoms_to_smiles
    >>> atoms_to_smiles(molecule("CH3OH")).split()[0]
    'CO'
    """
    smiles = ase_2_pybel(atoms).write("smi")
    if not smiles:
        raise ValueError("Could not convert ASE Atoms object to SMILES.")
    return smiles

file_to_atoms

file_to_atoms(path: Union[str, Path]) -> Atoms

Read a molecular structure file with ASE.

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage.base import file_to_atoms
>>> file_to_atoms(example_data.path("methane")).get_chemical_formula()
'CH4'
Source code in cage_isomer_builder/cage/base.py
def file_to_atoms(path: Union[str, Path]) -> Atoms:
    """Read a molecular structure file with ASE.

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage.base import file_to_atoms
    >>> file_to_atoms(example_data.path("methane")).get_chemical_formula()
    'CH4'
    """
    path = Path(path)
    if not path.exists():
        raise FileNotFoundError(f"Structure file not found: {path}")
    return read(str(path))

mol_input_to_smiles

mol_input_to_smiles(mol: MoleculeInput) -> str

Convert SMILES, file path, or ASE Atoms into a SMILES string.

Examples:

>>> from ase.build import molecule
>>> from cage_isomer_builder.cage.base import mol_input_to_smiles
>>> mol_input_to_smiles("  NCCN "), mol_input_to_smiles(molecule("CH4")).split()[0]
('NCCN', 'C')
Source code in cage_isomer_builder/cage/base.py
def mol_input_to_smiles(mol: MoleculeInput) -> str:
    """
    Convert SMILES, file path, or ASE Atoms into a SMILES string.

    Examples
    --------
    >>> from ase.build import molecule
    >>> from cage_isomer_builder.cage.base import mol_input_to_smiles
    >>> mol_input_to_smiles("  NCCN "), mol_input_to_smiles(molecule("CH4")).split()[0]
    ('NCCN', 'C')
    """
    if isinstance(mol, Atoms):
        return atoms_to_smiles(mol)

    if is_file_like(mol):
        return atoms_to_smiles(file_to_atoms(mol))

    if is_smiles_like(mol):
        return mol.strip()

    raise TypeError(
        "Molecule input must be a SMILES string, a structure file path, "
        "or an ASE Atoms object."
    )

mol_input_to_atoms_or_none

mol_input_to_atoms_or_none(mol: MoleculeInput) -> Optional[Atoms]

Return ASE Atoms if input is a file or ASE Atoms, otherwise None.

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage.base import mol_input_to_atoms_or_none
>>> print(mol_input_to_atoms_or_none("NCCN"))    # a SMILES string has no coordinates
None
>>> len(mol_input_to_atoms_or_none(example_data.path("methane")))
5
Source code in cage_isomer_builder/cage/base.py
def mol_input_to_atoms_or_none(mol: MoleculeInput) -> Optional[Atoms]:
    """
    Return ASE Atoms if input is a file or ASE Atoms, otherwise None.

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage.base import mol_input_to_atoms_or_none
    >>> print(mol_input_to_atoms_or_none("NCCN"))    # a SMILES string has no coordinates
    None
    >>> len(mol_input_to_atoms_or_none(example_data.path("methane")))
    5
    """
    if isinstance(mol, Atoms):
        return mol

    if is_file_like(mol):
        return file_to_atoms(mol)

    return None

normalize_molecule_input

normalize_molecule_input(mol: Optional[MoleculeInput], default: MoleculeInput) -> MoleculeInput

Normalize user molecule input for later building-block creation.

Defaults and SMILES strings are kept as SMILES. Structure files are read once into ASE Atoms, and ASE Atoms are passed through.

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage.base import normalize_molecule_input
>>> normalize_molecule_input(None, default="[Zr]"), normalize_molecule_input(" NCCN", "[Zr]")
('[Zr]', 'NCCN')
>>> type(normalize_molecule_input(example_data.path("bdc"), "[Zr]")).__name__   # files are read
'Atoms'
Source code in cage_isomer_builder/cage/base.py
def normalize_molecule_input(
    mol: Optional[MoleculeInput],
    default: MoleculeInput,
) -> MoleculeInput:
    """
    Normalize user molecule input for later building-block creation.

    Defaults and SMILES strings are kept as SMILES. Structure files are read
    once into ASE Atoms, and ASE Atoms are passed through.

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage.base import normalize_molecule_input
    >>> normalize_molecule_input(None, default="[Zr]"), normalize_molecule_input(" NCCN", "[Zr]")
    ('[Zr]', 'NCCN')
    >>> type(normalize_molecule_input(example_data.path("bdc"), "[Zr]")).__name__   # files are read
    'Atoms'
    """
    if mol is None:
        return default

    if is_smiles_like(mol):
        return mol.strip()

    atoms = mol_input_to_atoms_or_none(mol)
    if atoms is not None:
        return atoms

    raise TypeError(
        "Molecule input must be a SMILES string, a structure file path, "
        "or an ASE Atoms object."
    )

get_smiles_and_position_matrix

get_smiles_and_position_matrix(mol: MoleculeInput) -> tuple[str, Optional[np.ndarray]]

Return SMILES and coordinates for STK BuildingBlock construction.

Examples:

>>> from ase.build import molecule
>>> from cage_isomer_builder.cage.base import get_smiles_and_position_matrix
>>> get_smiles_and_position_matrix("NCCN")
('NCCN', None)
>>> smiles, positions = get_smiles_and_position_matrix(molecule("CH4"))
>>> positions.shape
(5, 3)
Source code in cage_isomer_builder/cage/base.py
def get_smiles_and_position_matrix(
    mol: MoleculeInput,
) -> tuple[str, Optional[np.ndarray]]:
    """
    Return SMILES and coordinates for STK BuildingBlock construction.

    Examples
    --------
    >>> from ase.build import molecule
    >>> from cage_isomer_builder.cage.base import get_smiles_and_position_matrix
    >>> get_smiles_and_position_matrix("NCCN")
    ('NCCN', None)
    >>> smiles, positions = get_smiles_and_position_matrix(molecule("CH4"))
    >>> positions.shape
    (5, 3)
    """
    atoms = mol_input_to_atoms_or_none(mol)
    if atoms is None:
        return mol_input_to_smiles(mol), None

    return atoms_to_smiles(atoms), atoms.get_positions()

has_dummy_marker_atoms

has_dummy_marker_atoms(atoms: Atoms) -> bool

Return True if ASE Atoms contains dummy attachment markers.

Examples:

>>> from ase.build import molecule
>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage.base import has_dummy_marker_atoms
>>> has_dummy_marker_atoms(example_data.read("bdc")), has_dummy_marker_atoms(molecule("CH4"))
(True, False)
Source code in cage_isomer_builder/cage/base.py
def has_dummy_marker_atoms(atoms: Atoms) -> bool:
    """Return True if ASE Atoms contains dummy attachment markers.

    Examples
    --------
    >>> from ase.build import molecule
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage.base import has_dummy_marker_atoms
    >>> has_dummy_marker_atoms(example_data.read("bdc")), has_dummy_marker_atoms(molecule("CH4"))
    (True, False)
    """
    return any(atom.symbol == "X" for atom in atoms)

remove_dummy_marker_atoms

remove_dummy_marker_atoms(atoms: Atoms) -> tuple[Atoms, list[int]]

Remove dummy marker and noble-gas atoms; return bonder indices.

X atoms mark attachment directions. Noble-gas atoms (He, Ne, ...) are orientation markers added by MOF deconstruction tools. Both are removed before STK construction. Each X marker is paired with the nearest non-hydrogen atom of the stripped molecule, which becomes the bonder of the corresponding functional group.

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage.base import remove_dummy_marker_atoms
>>> stripped, bonders = remove_dummy_marker_atoms(example_data.read("bdc"))
>>> stripped.get_chemical_formula(), [stripped[i].symbol for i in bonders]
('C6H4', ['C', 'C'])
Source code in cage_isomer_builder/cage/base.py
def remove_dummy_marker_atoms(atoms: Atoms) -> tuple[Atoms, list[int]]:
    """
    Remove dummy marker and noble-gas atoms; return bonder indices.

    ``X`` atoms mark attachment directions. Noble-gas atoms (He, Ne, ...) are
    orientation markers added by MOF deconstruction tools. Both are removed
    before STK construction. Each ``X`` marker is paired with the nearest
    non-hydrogen atom of the stripped molecule, which becomes the bonder of the
    corresponding functional group.

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage.base import remove_dummy_marker_atoms
    >>> stripped, bonders = remove_dummy_marker_atoms(example_data.read("bdc"))
    >>> stripped.get_chemical_formula(), [stripped[i].symbol for i in bonders]
    ('C6H4', ['C', 'C'])
    """
    dummy_positions = [
        atom.position
        for atom in atoms
        if atom.symbol == "X"
    ]
    keep_indices = [
        atom.index
        for atom in atoms
        if atom.symbol != "X" and atom.symbol not in _NOBLE_GAS_SYMBOLS
    ]
    stripped = atoms[keep_indices]
    stripped_positions = stripped.get_positions()
    candidate_indices = [
        atom.index
        for atom in stripped
        if atom.symbol != "H"
    ]

    if not candidate_indices:
        candidate_indices = list(range(len(stripped)))

    bonder_ids = []
    candidate_positions = stripped_positions[candidate_indices]
    for position in dummy_positions:
        distances = np.linalg.norm(candidate_positions - position, axis=1)
        bonder_ids.append(candidate_indices[int(np.argmin(distances))])

    return stripped, bonder_ids

make_building_block_from_dummy_markers

make_building_block_from_dummy_markers(atoms: Atoms) -> stk.BuildingBlock

Build an STK BuildingBlock from ASE Atoms with X marker atoms.

Uses BuildingBlock.init() directly, without a SMILES round trip, so the atom order and 3D coordinates are kept. A SMILES round trip through OpenBabel and RDKit reorders atoms, which would put the bonders of large inorganic clusters (e.g. UiO-66 Zr nodes) at the wrong positions.

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage.base import make_building_block_from_dummy_markers
>>> bb = make_building_block_from_dummy_markers(example_data.read("bdc"))
>>> bb.get_num_atoms(), bb.get_num_functional_groups()
(10, 2)
Source code in cage_isomer_builder/cage/base.py
def make_building_block_from_dummy_markers(
    atoms: Atoms,
) -> stk.BuildingBlock:
    """
    Build an STK BuildingBlock from ASE Atoms with ``X`` marker atoms.

    Uses ``BuildingBlock.init()`` directly, without a SMILES round trip, so the
    atom order and 3D coordinates are kept. A SMILES round trip through
    OpenBabel and RDKit reorders atoms, which would put the bonders of large
    inorganic clusters (e.g. UiO-66 Zr nodes) at the wrong positions.

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage.base import make_building_block_from_dummy_markers
    >>> bb = make_building_block_from_dummy_markers(example_data.read("bdc"))
    >>> bb.get_num_atoms(), bb.get_num_functional_groups()
    (10, 2)
    """
    stripped, bonder_ids = remove_dummy_marker_atoms(atoms)

    # Build STK atoms in the same order as the stripped ASE Atoms object.
    stk_atoms = []
    for i, atom in enumerate(stripped):
        element_cls = getattr(stk, atom.symbol, None)
        if element_cls is None:
            raise ValueError(
                f"STK does not expose element stk.{atom.symbol!r}. "
                "Remove unsupported elements from the building block file."
            )
        stk_atoms.append(element_cls(i))

    bonds = _bonds_from_ase_atoms(stripped, stk_atoms)

    functional_groups = [
        stk.GenericFunctionalGroup(
            atoms=(stk_atoms[i],),
            bonders=(stk_atoms[i],),
            deleters=(),
        )
        for i in bonder_ids
    ]

    return stk.BuildingBlock.init(
        atoms=stk_atoms,
        bonds=bonds,
        position_matrix=stripped.get_positions(),
        functional_groups=functional_groups,
    )

has_dummy_atom

has_dummy_atom(smiles: str) -> bool

Detect dummy atoms in SMILES.

Handles common dummy representations: - [*] - * - [#0]

Examples:

>>> from cage_isomer_builder.cage.base import has_dummy_atom
>>> has_dummy_atom("[*]c1ccc([*])cc1"), has_dummy_atom("c1ccccc1")
(True, False)
Source code in cage_isomer_builder/cage/base.py
def has_dummy_atom(smiles: str) -> bool:
    """
    Detect dummy atoms in SMILES.

    Handles common dummy representations:
    - [*]
    - *
    - [#0]

    Examples
    --------
    >>> from cage_isomer_builder.cage.base import has_dummy_atom
    >>> has_dummy_atom("[*]c1ccc([*])cc1"), has_dummy_atom("c1ccccc1")
    (True, False)
    """
    return "*" in smiles or "[#0]" in smiles

is_single_atom_smiles

is_single_atom_smiles(smiles: str) -> bool

Return True for bracketed single-atom SMILES such as [Zn], [Pd], [Zr].

Examples:

>>> from cage_isomer_builder.cage.base import is_single_atom_smiles
>>> is_single_atom_smiles("[Zn]"), is_single_atom_smiles("[Zn]O")
(True, False)
Source code in cage_isomer_builder/cage/base.py
def is_single_atom_smiles(smiles: str) -> bool:
    """Return True for bracketed single-atom SMILES such as [Zn], [Pd], [Zr].

    Examples
    --------
    >>> from cage_isomer_builder.cage.base import is_single_atom_smiles
    >>> is_single_atom_smiles("[Zn]"), is_single_atom_smiles("[Zn]O")
    (True, False)
    """
    return bool(_SINGLE_ATOM_RE.match(smiles.strip()))

is_single_atom_input

is_single_atom_input(mol: MoleculeInput) -> bool

Return True if input represents exactly one atom.

Examples:

>>> from ase import Atoms
>>> from cage_isomer_builder.cage.base import is_single_atom_input
>>> is_single_atom_input("[Pd]"), is_single_atom_input(Atoms("Cu")), is_single_atom_input("NCCN")
(True, True, False)
Source code in cage_isomer_builder/cage/base.py
def is_single_atom_input(mol: MoleculeInput) -> bool:
    """
    Return True if input represents exactly one atom.

    Examples
    --------
    >>> from ase import Atoms
    >>> from cage_isomer_builder.cage.base import is_single_atom_input
    >>> is_single_atom_input("[Pd]"), is_single_atom_input(Atoms("Cu")), is_single_atom_input("NCCN")
    (True, True, False)
    """
    if isinstance(mol, Atoms):
        return len(mol) == 1

    if is_file_like(mol):
        return len(file_to_atoms(mol)) == 1

    if is_smiles_like(mol):
        return is_single_atom_smiles(mol)

    return False

get_single_atom_symbol

get_single_atom_symbol(mol: MoleculeInput) -> str

Extract element symbol from a single-atom input.

Examples:

>>> from ase import Atoms
>>> from cage_isomer_builder.cage.base import get_single_atom_symbol
>>> get_single_atom_symbol("[Pd]"), get_single_atom_symbol(Atoms("Cu"))
('Pd', 'Cu')
Source code in cage_isomer_builder/cage/base.py
def get_single_atom_symbol(mol: MoleculeInput) -> str:
    """
    Extract element symbol from a single-atom input.

    Examples
    --------
    >>> from ase import Atoms
    >>> from cage_isomer_builder.cage.base import get_single_atom_symbol
    >>> get_single_atom_symbol("[Pd]"), get_single_atom_symbol(Atoms("Cu"))
    ('Pd', 'Cu')
    """
    if isinstance(mol, Atoms):
        if len(mol) != 1:
            raise ValueError("ASE Atoms object is not a single atom.")
        return mol[0].symbol

    if is_file_like(mol):
        atoms = file_to_atoms(mol)
        if len(atoms) != 1:
            raise ValueError(f"File {mol!r} does not contain a single atom.")
        return atoms[0].symbol

    smiles = str(mol).strip()
    match = _SINGLE_ATOM_RE.match(smiles)
    if not match:
        raise ValueError(f"Expected single-atom SMILES, got {smiles!r}.")

    return match.group(1)

make_single_atom_building_block

make_single_atom_building_block(mol: MoleculeInput, fg_count: int) -> stk.BuildingBlock

Build an STK single-atom BuildingBlock.

This is intended for metal nodes such as [Zn], [Pd], [Zr], etc.

Examples:

>>> from cage_isomer_builder.cage.base import make_single_atom_building_block
>>> make_single_atom_building_block("[Zr]", fg_count=4).get_num_functional_groups()
4
Source code in cage_isomer_builder/cage/base.py
def make_single_atom_building_block(
    mol: MoleculeInput,
    fg_count: int,
) -> stk.BuildingBlock:
    """
    Build an STK single-atom BuildingBlock.

    This is intended for metal nodes such as [Zn], [Pd], [Zr], etc.

    Examples
    --------
    >>> from cage_isomer_builder.cage.base import make_single_atom_building_block
    >>> make_single_atom_building_block("[Zr]", fg_count=4).get_num_functional_groups()
    4
    """
    symbol = get_single_atom_symbol(mol)
    element_cls = getattr(stk, symbol, None)

    if element_cls is None:
        raise ValueError(
            f"STK does not expose element stk.{symbol}. "
            "Check whether this element is supported by your STK version."
        )

    atoms = mol_input_to_atoms_or_none(mol)

    if atoms is not None:
        position_matrix = atoms.get_positions()
        smiles = f"[{symbol}]"
    else:
        position_matrix = [[0.0, 0.0, 0.0]]
        smiles = str(mol).strip()

    return stk.BuildingBlock(
        smiles=smiles,
        functional_groups=(
            stk.SingleAtom(element_cls(0))
            for _ in range(fg_count)
        ),
        position_matrix=position_matrix,
    )

resolve_factory

resolve_factory(fg: Any, smarts_pattern: Optional[str] = None)

Resolve a functional-group name or factory instance.

Returns None for 'single_atom'.

Examples:

>>> from cage_isomer_builder.cage.base import resolve_factory
>>> type(resolve_factory("primary_amine")).__name__, resolve_factory("single_atom")
('PrimaryAminoFactory', None)
Source code in cage_isomer_builder/cage/base.py
def resolve_factory(
    fg: Any,
    smarts_pattern: Optional[str] = None,
):
    """
    Resolve a functional-group name or factory instance.

    Returns None for 'single_atom'.

    Examples
    --------
    >>> from cage_isomer_builder.cage.base import resolve_factory
    >>> type(resolve_factory("primary_amine")).__name__, resolve_factory("single_atom")
    ('PrimaryAminoFactory', None)
    """
    if fg is None:
        return None

    if not isinstance(fg, str):
        return fg

    if fg not in FG_FACTORY_MAP:
        raise ValueError(
            f"Unknown functional group {fg!r}. "
            f"Choose from {list(FG_FACTORY_MAP)} or pass a factory instance."
        )

    factory_cls = FG_FACTORY_MAP[fg]

    if fg == "single_atom":
        return None

    if fg == "smarts":
        if smarts_pattern is None:
            raise ValueError("smarts_pattern is required when fg='smarts'.")

        return stk.SmartsFunctionalGroupFactory(
            smarts=smarts_pattern,
            bonders=(1,),
            deleters=(0,),
        )

    return factory_cls()

try_building_block_with_factory

try_building_block_with_factory(smiles: str, factory, position_matrix: Optional[ndarray] = None) -> Optional[stk.BuildingBlock]

Try one factory and return the BuildingBlock only if it finds FGs.

Examples:

>>> import stk
>>> from cage_isomer_builder.cage.base import try_building_block_with_factory
>>> print(try_building_block_with_factory("CCO", stk.PrimaryAminoFactory()))   # no amine
None
Source code in cage_isomer_builder/cage/base.py
def try_building_block_with_factory(
    smiles: str,
    factory,
    position_matrix: Optional[np.ndarray] = None,
) -> Optional[stk.BuildingBlock]:
    """
    Try one factory and return the BuildingBlock only if it finds FGs.

    Examples
    --------
    >>> import stk
    >>> from cage_isomer_builder.cage.base import try_building_block_with_factory
    >>> print(try_building_block_with_factory("CCO", stk.PrimaryAminoFactory()))   # no amine
    None
    """
    try:
        bb = stk.BuildingBlock(
            smiles=smiles,
            functional_groups=[factory],
            position_matrix=position_matrix,
        )
    except Exception:
        return None

    if bb.get_num_functional_groups() == 0:
        return None

    return bb

autodetect_building_block

autodetect_building_block(mol: MoleculeInput, fg: Any = None, fg_count: int = 1, smarts_pattern: Optional[str] = None, allow_single_atom: bool = True, role: str = 'building block') -> stk.BuildingBlock

Build an STK BuildingBlock from SMILES, file, or ASE Atoms.

Detection priority
  1. If true single atom and allow_single_atom=True: use stk.SingleAtom.
  2. If ASE/file input contains X marker atoms: strip markers and create GenericFunctionalGroup bonders.
  3. Convert file/ASE input to SMILES using mofstructure/OpenBabel.
  4. If SMILES dummy atoms (*, [*], [#0]) are present: rewrite them as [Fr] and use the [Fr][*] SMARTS factory.
  5. If user provided fg: use that factory.
  6. Otherwise search FG_FACTORY_MAP.

Examples:

>>> from cage_isomer_builder import example_data
>>> from cage_isomer_builder.cage.base import autodetect_building_block
>>> autodetect_building_block("Nc1ccc(N)cc1").get_num_functional_groups()    # two amines
2
>>> autodetect_building_block(example_data.path("bdc")).get_num_functional_groups()  # X markers
2
>>> autodetect_building_block("[Zr]", fg_count=4).get_num_functional_groups()
4
Source code in cage_isomer_builder/cage/base.py
def autodetect_building_block(
    mol: MoleculeInput,
    fg: Any = None,
    fg_count: int = 1,
    smarts_pattern: Optional[str] = None,
    allow_single_atom: bool = True,
    role: str = "building block",
) -> stk.BuildingBlock:
    """
    Build an STK BuildingBlock from SMILES, file, or ASE Atoms.

    Detection priority
    ------------------
    1. If true single atom and allow_single_atom=True:
       use stk.SingleAtom.
    2. If ASE/file input contains ``X`` marker atoms:
       strip markers and create GenericFunctionalGroup bonders.
    3. Convert file/ASE input to SMILES using mofstructure/OpenBabel.
    4. If SMILES dummy atoms (``*``, ``[*]``, ``[#0]``) are present:
       rewrite them as ``[Fr]`` and use the ``[Fr][*]`` SMARTS factory.
    5. If user provided fg:
       use that factory.
    6. Otherwise search FG_FACTORY_MAP.

    Examples
    --------
    >>> from cage_isomer_builder import example_data
    >>> from cage_isomer_builder.cage.base import autodetect_building_block
    >>> autodetect_building_block("Nc1ccc(N)cc1").get_num_functional_groups()    # two amines
    2
    >>> autodetect_building_block(example_data.path("bdc")).get_num_functional_groups()  # X markers
    2
    >>> autodetect_building_block("[Zr]", fg_count=4).get_num_functional_groups()
    4
    """

    if allow_single_atom and is_single_atom_input(mol):
        return make_single_atom_building_block(
            mol=mol,
            fg_count=fg_count,
        )

    atoms = mol_input_to_atoms_or_none(mol)
    if atoms is not None and has_dummy_marker_atoms(atoms):
        return make_building_block_from_dummy_markers(atoms)

    smiles, position_matrix = get_smiles_and_position_matrix(mol)

    if has_dummy_atom(smiles):
        bb = try_building_block_with_factory(
            smiles=dummies_to_placeholder(smiles),
            factory=make_dummy_factory(),
            position_matrix=position_matrix,
        )
        if bb is not None:
            return bb

    if fg is not None:
        factory = resolve_factory(
            fg=fg,
            smarts_pattern=smarts_pattern,
        )

        if factory is None:
            return make_single_atom_building_block(
                mol=mol,
                fg_count=fg_count,
            )

        bb = try_building_block_with_factory(
            smiles=smiles,
            factory=factory,
            position_matrix=position_matrix,
        )
        if bb is not None:
            return bb

        raise ValueError(
            f"Factory {fg!r} was provided for {role}, but it found no "
            f"functional groups in SMILES: {smiles}"
        )

    for name, factory_cls in FG_FACTORY_MAP.items():
        if name in {"single_atom", "smarts"}:
            continue

        bb = try_building_block_with_factory(
            smiles=smiles,
            factory=factory_cls(),
            position_matrix=position_matrix,
        )
        if bb is not None:
            return bb

    raise ValueError(
        f"Could not detect functional groups for {role}.\n"
        f"SMILES used: {smiles}\n"
        "Solutions:\n"
        "  - add dummy atoms such as [*]...[*],\n"
        "  - pass linker_fg= or node_fg= explicitly,\n"
        "  - or extend FG_FACTORY_MAP."
    )