# Flexibility and thermo

The LS set is the dynamical model. A bond with an LS is rigid, and a bond without one may be a rotor. The same LS decide the symmetry number, so conformer sampling, scans and the partition function all agree.


# What the routines read now

The charge, the spin and the neighbours are fields and functions today:

``` python
>>> import protomol as pm
>>> ch3 = pm.MolGraph(symbols=["C", "H", "H", "H"], bonds=[(0, 1), (0, 2), (0, 3)])
>>> ch3.charge, ch3.spin
(0, 1)
>>> pm.neighbors(ch3, 0)
(1, 2, 3)
>>> pm.display(ch3)  # doctest: +SKIP
```


# Conformer sampling

At a TS, CREST holds the reacting core: the atoms of the breaking and forming bonds. The rings are sampled by CREST too: they are fluxional in v1, with no LS on a ring's conformer, so each ring conformer is a CREST minimum of the same graph.

``` python
>>> ts = pm.examples.abstraction_ts()
>>> sorted(pm.reacting_core(ts))          # TS only: the atoms CREST holds
[0, 2, 3]
>>> pm.rings(pm.from_smiles("C1CCCCC1"))  # each ring in cycle order
[(0, 1, 2, 3, 4, 5)]
>>> # conformers = run_crest(pm.embed(ts), constrain=pm.reacting_core(ts))  # ae, illustrative
```

The torsions to sample are the rotors' axes. A bond with a bond LS is never one, and a linear chain gives one axis between its outer ends:

``` python
>>> [rotor.axis for rotor in pm.rotors(pm.examples.species())]  # 2 CH3, OH, C1-C3
[(1, 0), (1, 2), (1, 3), (4, 5)]
>>> pm.rotors(pm.from_smiles("CC#CC"))     # 2-butyne: one torsion across C≡C
[Rotor(axis=(0, 3), top=(7, 8, 9))]
```

A conformer search can invert a centre or flip a bond, so each conformer is checked against the graph, and kept only if nothing disagrees. Here an embedding of the graph and of its mirror image stand in for CREST's conformers:

``` python
>>> smg = pm.examples.species()
>>> conformers = [pm.embed(smg), pm.embed(pm.enantiomer(smg))]  # stand in for CREST's
>>> kept = [geo for geo in conformers if not pm.geometry_mismatches(smg, geo)]
>>> len(kept)
1
```


# Scans for the partition function

A rotor's `top` is the smaller side, the atoms that turn (MESS's `Group`), and it hangs off `axis[1]`. MESS gets every rotor with `Symmetry 1` and its scan over 360°, with the total symmetry number below. At a TS the rotors are read on the condensed graph, and a transferred H counts as linear, so the abstraction TS has one torsion about C0···O2:

``` python
>>> pm.rotors(pm.examples.abstraction_ts())
[Rotor(axis=(0, 1), top=(6, 7, 8)), Rotor(axis=(0, 2), top=(9,))]
>>> # for rotor in pm.rotors(smg):
>>> #     scan_torsion(geo, axis=rotor.axis, moving=rotor.top)  # 360°, illustrative
```

An umbrella is a pyramidal centre the LS leave flexible, whose inversion is a double well: a radical C such as CH3's, or an amine N that a scheme left without its [Tetrahedral](../reference/Tetrahedral.md#protomol.Tetrahedral). At low T, NH3's [Tetrahedral](../reference/Tetrahedral.md#protomol.Tetrahedral) holds it:

``` python
>>> pm.umbrellas(pm.from_smiles("[CH3]"))
[Umbrella(center=0, neighbors=(1, 2, 3))]
>>> pm.umbrellas(pm.from_smiles("N")), pm.umbrellas(pm.remove_stereo(pm.from_smiles("N"), 0))
([], [Umbrella(center=0, neighbors=(1, 2, 3))])
>>> # for umb in pm.umbrellas(smg):
>>> #     scan_umbrella(geo, umb.center, umb.neighbors)  # illustrative
```

The symmetry number is the total number of stereo-preserving automorphisms, for MESS's `SymmetryFactor` with every rotor at `Symmetry 1`. It needs every LS determined, since stereoisomers can differ in it, and it refuses a ring of 4 or more atoms with a flexible bond until a ring model exists (pm open question 25): there, use an interim value.

``` python
>>> pm.symmetry_number(pm.from_smiles("C")), pm.symmetry_number(pm.from_smiles("CC"))
(12, 18)
>>> pm.symmetry_number(pm.from_smiles("C=C=C"))  # allene: D2d
4
>>> pm.symmetry_number(pm.from_smiles("C1CCCCC1"))
Traceback (most recent call last):
...
protomol._types.GraphError: The ring (0, 1, 2, 3, 4, 5) is flexible (a bond with no bond LS), and sigma for ring conformers isn't settled yet (open question 25): use an interim sigma
```

MESS-PF also takes `smg.spin` (as 2S + 1).


# The kinetics network

> **Note: Note**
>
> The network API is open (am Phase 6).

``` python
# Nodes are the identities of each TS's sides; enantiomeric nodes are lumped (illustrative)
nodes = {identity(side) for ts in channels for side in (pm.reactants(ts), pm.products(ts))}
```

Two nodes are an enantiomeric pair, to lump and adjust sigma_eff, when one's mirror image has the other's canonical JSON:

``` python
>>> smg_a = pm.examples.species()
>>> smg_b = pm.from_smiles(r"C[C@H](O)/C=C/C")
>>> pm.canonical_json(pm.enantiomer(smg_a)) == pm.canonical_json(smg_b)
True
```
