orthonym.rules.main_ring_pairs#

Note

Internal API. Names and behaviour may change between releases.

Pairs of interior-disjoint bridgehead paths for the von Baeyer main-ring search, without the pair scan.

polycyclic._find_main_ring_impl lists the simple bh1->bh2 paths of a ring system and, for each bridgehead pair, takes from them the pairs of paths whose interiors (the atoms other than bh1 and bh2) are disjoint: the two paths and the two bridgeheads are a main ring “Selection of the main ring”, the Blue Book Blue Book: “The main ring of a polycyclic hydrocarbon ring system is selected so as to include as many skeletal atoms of the structure as possible”), and a third path disjoint from both is the main bridge “Selection of the main bridge”, :9603; the main ring is divided as symmetrically as possible by it, “Selection of the main bridge and secondary bridges”, rule at :9661). A ring system of 13 or more rings lists thousands of paths for one bridgehead pair, and the loops that tested every pair of them for disjointness (_best_disjoint_pair_loop below and the loop of polycyclic._consider_multiatom_bridges, one perf-budget unit per pair) are quadratic: 13,419 paths are 90 million pairs, more than seven times the 12 million units of the budget, so the molecule was abstained at perf_op_budget.

The answer does not need the pairs. Number the paths by their position in order (the longest interior first). With one big integer per ring atom that holds the set of paths through it (bit p set for the path at position p), the paths disjoint from path p are the complement of the union of those integers over p’s interior atoms, one | per atom, and the paths of one length are a run of positions, so the partners of p of a given length are one &.

*best_disjoint_pair() (Cases 1 and 2): the pair with the largest ring size (the sum of the two

interior sizes plus two), then the larger balance (the smaller of them). Both are fixed by the two lengths, so the class of lengths is found first, longest partner of each path first, and only the pairs of that one class are listed and ranked by the canonical-rank tie key, as the loop ranked every pair that reached the incumbent’s class. The pair returned is the loop’s, pair for pair: the largest key (ring size, balance, canonical-rank tuple of the atoms of the two paths), and of two equal keys the one with the lower (i, j), i < j, which the loop met first and kept (it replaced the incumbent only on a strictly larger key).

*offered_multiatom_pairs() (Case 3): the pairs the loop offered to _MainRingBest.consider,

found among the disjoint pairs only, visited in the order of the loop, so the incumbent that bounds the ring size evolves as it did and the longest-bridge search (bridge_len) is asked for the same free atoms in the same order.

The perf budget is charged what the search does: the big-integer operations it makes, each at the fraction of a unit its size costs (_UNIT_BASE, _UNIT_BITS), and never more in all than the loop it replaces charged for the same list (one unit per pair of the list; in Case 3, per pair of the ring-size window the loop visits). A list of fewer than PAIR_SCAN_MAX_PATHS paths is searched by the loops, as it always was, with the units they charged.

orthonym.rules.main_ring_pairs.interior_masks(paths)#

Per path, its interior atoms (p[1:-1]) as one int bitmask (atom index -> bit) and the interior size. An & of two masks is the interior-disjointness test of two bh1->bh2 paths, in place of a set intersection per pair.

orthonym.rules.main_ring_pairs.PAIR_SCAN_MAX_PATHS = 96#

it is at most PAIR_SCAN_MAX_PATHS * (PAIR_SCAN_MAX_PATHS - 1) / 2 units, and the set arithmetic below costs more than that to set up.

Type:

A list of fewer paths than this is searched by the loops

orthonym.rules.main_ring_pairs.best_disjoint_pair(all_paths, spend, rank_key)#

Largest, then most symmetric, pair of interior-disjoint paths of all_paths (the bh1->bh2 paths). Deterministic: ties broken by the lowest canon-rank tuple, then by the lower position in the list. spend is charged for the work done (see the module docstring), never more than one unit per pair of the list.

class orthonym.rules.main_ring_pairs.PathSets(paths, plens, masks=None)#

Bases: object

The paths of one bridgehead pair as sets of paths, numbered by position in order (longest interior first, equal lengths in list order). through[a] has bit p set when the path at position p has atom a in its interior; runs are the (length, first position, last position + 1) of each length, longest first; atoms[p] are the interior atoms of the path at position p.

masks are the interior bitmasks of the paths in list order (interior_masks), when the caller has them. The sets through the atoms are the columns of the table of the interiors, one row of bytes a path: the byte of an atom in every row is one slice, and its bit one translate and int away.

n#
lens#
atoms#
by_len#
everything#
blocked(p)#

The paths that share an interior atom with the path at position p (p itself, unless its interior is empty).

after(p)#

The positions after p.

order#
through#
runs#
orthonym.rules.main_ring_pairs.offered_multiatom_pairs(all_paths, masks, plens, spend, incumbent, room, bridge_len)#

Case 3 of the main-ring search: the pairs (lo, hi, main bridge size), lo < hi indexes of the list, that polycyclic._consider_multiatom_bridges offers to _MainRingBest.consider, in the order it does (sorted): the pairs of bh1->bh2 paths of the largest ring size at least incumbent (and at most room) that are interior-disjoint and have a main bridge of 2 or more atoms. The loop also offered the pairs of a smaller ring size that it met before a larger one; consider drops those, and they are not listed.

The loop visits the pairs of the ring-size window in the order of order (the longest interior first, positions a < b) while the incumbent grows with each valid pair, and so does this search on the disjoint pairs, which are the only ones that reach the main bridge: the incumbent and the calls of bridge_len are the loop’s. bridge_len is None to look for the main bridge among the paths of the list (the longest path, of 2 or more atoms, disjoint from both).

Charged one unit per _UNIT_BITS bits of operation, and never more in all than the loop charged for the visited pairs of the ring-size window (the charge of the longest-bridge search, made by bridge_len itself, is the loop’s).