## canonical_direction()


`gra` or its reverse with the smaller canonical JSON, and whether reversed.


Usage

``` python
canonical_direction(gra: R) -> tuple[R, bool]
 
canonical_direction(gra: ReactionGraph | StereoReactionGraph) -> tuple[ReactionGraph | StereoReactionGraph, bool]
```


A reaction graph and its [reverse](reverse.md#protomol.reverse) describe one TS from the two sides, and their canonical forms differ. This picks one of them by comparing [canonical_json](canonical_json.md#protomol.canonical_json), so the result is the same for both, up to atom numbering if the two are equal (a symmetric self-reaction, where a tie keeps `gra`). Atom indices are kept, so an atom map from [canonical_form](canonical_form.md#protomol.canonical_form) of the result applies to the input's atoms as they are. [canonical_form](canonical_form.md#protomol.canonical_form) itself stays faithful to its input.

The canonical TS, the same for a TS, its reverse and their mirror images (P60), is `canonical_direction(canonical_enantiomer(gra))`.

``` python
>>> from protomol import examples
>>> ts = examples.abstraction_ts()
>>> chosen, flipped = canonical_direction(ts)
>>> chosen2, flipped2 = canonical_direction(reverse(ts))
>>> chosen == chosen2, flipped != flipped2
```

(True, True)
