amchi 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
amchi-0.0.1/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Andreas V. Copan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
amchi-0.0.1/PKG-INFO ADDED
@@ -0,0 +1,41 @@
1
+ Metadata-Version: 2.4
2
+ Name: amchi
3
+ Version: 0.0.1
4
+ Author: Andreas V. Copan
5
+ Author-email: Andreas V. Copan <avcopan@uga.edu>
6
+ License-Expression: MIT
7
+ License-File: LICENSE
8
+ Requires-Dist: networkx>=3.5
9
+ Requires-Dist: numpy>=2.2
10
+ Requires-Dist: pydantic>=2.9
11
+ Requires-Python: >=3.13
12
+ Project-URL: Repository, https://github.com/avcopan/amchi
13
+ Project-URL: Documentation, https://avcopan.github.io/amchi/
14
+ Description-Content-Type: text/markdown
15
+
16
+ # amchi
17
+
18
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
19
+ [![Pixi Badge](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/prefix-dev/pixi/main/assets/badge/v0.json)](https://pixi.sh)
20
+ [![Code style: ruff](https://img.shields.io/badge/code%20style-ruff-000000.svg)](https://github.com/astral-sh/ruff)
21
+ [![Typing: ty](https://img.shields.io/badge/typing-ty-EFC621.svg)](https://github.com/astral-sh/ty)
22
+ [![Copier](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/copier-org/copier/master/img/badge/badge-grayscale-border.json)](https://github.com/copier-org/copier)
23
+
24
+ Description here...
25
+
26
+ ## Installation
27
+
28
+ Installation instructions...
29
+
30
+ ## Usage
31
+
32
+ Usage instructions...
33
+
34
+ ## Contributing
35
+
36
+ Pull requests are welcome. For major changes, please open an issue first
37
+ to discuss what you would like to change.
38
+
39
+ ## Credits
40
+
41
+ This package was created with [copier](https://copier.readthedocs.io/) and the [avcopan/copier-pixi-python](https://github.com/avcopan/copier-pixi-python) project template.
amchi-0.0.1/README.md ADDED
@@ -0,0 +1,26 @@
1
+ # amchi
2
+
3
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)
4
+ [![Pixi Badge](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/prefix-dev/pixi/main/assets/badge/v0.json)](https://pixi.sh)
5
+ [![Code style: ruff](https://img.shields.io/badge/code%20style-ruff-000000.svg)](https://github.com/astral-sh/ruff)
6
+ [![Typing: ty](https://img.shields.io/badge/typing-ty-EFC621.svg)](https://github.com/astral-sh/ty)
7
+ [![Copier](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/copier-org/copier/master/img/badge/badge-grayscale-border.json)](https://github.com/copier-org/copier)
8
+
9
+ Description here...
10
+
11
+ ## Installation
12
+
13
+ Installation instructions...
14
+
15
+ ## Usage
16
+
17
+ Usage instructions...
18
+
19
+ ## Contributing
20
+
21
+ Pull requests are welcome. For major changes, please open an issue first
22
+ to discuss what you would like to change.
23
+
24
+ ## Credits
25
+
26
+ This package was created with [copier](https://copier.readthedocs.io/) and the [avcopan/copier-pixi-python](https://github.com/avcopan/copier-pixi-python) project template.
@@ -0,0 +1,96 @@
1
+ [project]
2
+ name = "amchi"
3
+ version = "0.0.1"
4
+ readme = "README.md"
5
+ license = "MIT"
6
+ license-files = ["LICENSE"]
7
+ dependencies = [
8
+ "networkx>=3.5",
9
+ "numpy>=2.2",
10
+ "pydantic>=2.9",
11
+ ]
12
+ requires-python = ">= 3.13"
13
+
14
+ [[project.authors]]
15
+ name = "Andreas V. Copan"
16
+ email = "avcopan@uga.edu"
17
+
18
+ [project.urls]
19
+ Repository = "https://github.com/avcopan/amchi"
20
+ Documentation = "https://avcopan.github.io/amchi/"
21
+
22
+ [build-system]
23
+ build-backend = "uv_build"
24
+ requires = ["uv_build"]
25
+
26
+ [tool.ruff]
27
+ extend-exclude = [".claude"]
28
+
29
+ [tool.ruff.lint]
30
+ select = ["ALL"]
31
+ ignore = [
32
+ "COM812",
33
+ "TID252",
34
+ "D203",
35
+ "D213",
36
+ "CPY001",
37
+ ]
38
+
39
+ [tool.ruff.lint.per-file-ignores]
40
+ "tests/**.py" = [
41
+ "S101",
42
+ "PLR2004",
43
+ ]
44
+
45
+ [tool.ruff.lint.pydocstyle]
46
+ convention = "google"
47
+
48
+ [tool.ty.environment]
49
+ python = ".pixi/envs/test/bin/python"
50
+
51
+ [tool.ty.src]
52
+ include = [
53
+ "src",
54
+ "tests",
55
+ ]
56
+
57
+ [tool.importlinter]
58
+ root_package = "amchi"
59
+
60
+ [[tool.importlinter.contracts]]
61
+ name = "Module Layering"
62
+ type = "layers"
63
+ layers = [
64
+ "amchi._amchi",
65
+ "amchi._layers",
66
+ "amchi._canon",
67
+ "amchi._parity",
68
+ "amchi._candidates",
69
+ "amchi._resonance",
70
+ "amchi._connect",
71
+ "amchi._graph",
72
+ "amchi._types",
73
+ "amchi._element",
74
+ ]
75
+
76
+ [tool.pytest.ini_options]
77
+ testpaths = [
78
+ "tests",
79
+ "src",
80
+ ]
81
+ addopts = [
82
+ "--doctest-modules",
83
+ "--cov=amchi",
84
+ "--cov-report=term-missing",
85
+ "--cov-report=html",
86
+ ]
87
+ doctest_optionflags = "NORMALIZE_WHITESPACE"
88
+
89
+ [tool.coverage.run]
90
+ branch = true
91
+ source = ["amchi"]
92
+
93
+ [tool.coverage.report]
94
+ show_missing = true
95
+ skip_covered = true
96
+ fail_under = 80
@@ -0,0 +1,95 @@
1
+ [project]
2
+ name = "amchi"
3
+ version = "0.0.1"
4
+ readme = "README.md" # the PyPI page
5
+ license = "MIT"
6
+ license-files = ["LICENSE"]
7
+ authors = [{name = "Andreas V. Copan", email = "avcopan@uga.edu"}]
8
+ dependencies = [
9
+ "networkx>=3.5",
10
+ "numpy>=2.2",
11
+ "pydantic>=2.9",
12
+ ]
13
+ requires-python = ">= 3.13"
14
+
15
+ [project.urls]
16
+ Repository = "https://github.com/avcopan/amchi"
17
+ Documentation = "https://avcopan.github.io/amchi/"
18
+
19
+ [build-system]
20
+ build-backend = "uv_build"
21
+ requires = ["uv_build"]
22
+
23
+ # Ruff configurations
24
+ [tool.ruff]
25
+ extend-exclude = [".claude"] # vendored agent skills
26
+
27
+ [tool.ruff.lint]
28
+ select = ["ALL"]
29
+ ignore = [
30
+ "COM812", # missing trailing comma (handled by format)
31
+ "TID252", # relative import
32
+ "D203", # conflict: incorrect blank line before class (uses D211 instead)
33
+ "D213", # conflict: multi-line summary second line (uses D212 instead)
34
+ "CPY001", # copyright notice
35
+ ]
36
+
37
+ [tool.ruff.lint.per-file-ignores]
38
+ "tests/**.py" = ["S101", "PLR2004"] # assert, magic values
39
+
40
+ [tool.ruff.lint.pydocstyle]
41
+ convention = "google"
42
+
43
+ # Ty configurations
44
+ [tool.ty.environment]
45
+ python = ".pixi/envs/test/bin/python"
46
+
47
+ [tool.ty.src]
48
+ include = [
49
+ "src",
50
+ "tests",
51
+ ]
52
+
53
+ # Import-linter configurations
54
+ [tool.importlinter]
55
+ root_package = "amchi"
56
+
57
+ [[tool.importlinter.contracts]]
58
+ name = "Module Layering"
59
+ type = "layers"
60
+ # Highest layer first, in the reverse of the module table in VISION.md.
61
+ # The parentheses make a layer optional until its module exists: remove each pair when
62
+ # the module is added.
63
+ layers = [
64
+ "amchi._amchi",
65
+ "amchi._layers",
66
+ "amchi._canon",
67
+ "amchi._parity",
68
+ "amchi._candidates",
69
+ "amchi._resonance",
70
+ "amchi._connect",
71
+ "amchi._graph",
72
+ "amchi._types",
73
+ "amchi._element",
74
+ ]
75
+
76
+ # Pytest configurations
77
+ [tool.pytest.ini_options]
78
+ testpaths = ["tests", "src"]
79
+ addopts = [
80
+ "--doctest-modules",
81
+ "--cov=amchi",
82
+ "--cov-report=term-missing",
83
+ "--cov-report=html",
84
+ ]
85
+ doctest_optionflags = "NORMALIZE_WHITESPACE"
86
+
87
+ # Pytest-cov configurations
88
+ [tool.coverage.run]
89
+ branch = true
90
+ source = ["amchi"]
91
+
92
+ [tool.coverage.report]
93
+ show_missing = true
94
+ skip_covered = true
95
+ fail_under = 80
@@ -0,0 +1,30 @@
1
+ """amchi."""
2
+
3
+ __version__ = "0.0.1"
4
+
5
+ from ._amchi import from_geometry, from_ts_geometries, string
6
+ from ._candidates import add_bond_candidate, candidates, remove_candidate
7
+ from ._connect import connectivity, ts_connectivity
8
+ from ._element import AmchiError, UnsupportedElementError
9
+ from ._parity import ParityMargins, parity_margins
10
+ from ._types import Bond, Candidates, Connectivity, GeometryLike, IllDefinedParityError
11
+
12
+ __all__ = [
13
+ "AmchiError",
14
+ "Bond",
15
+ "Candidates",
16
+ "Connectivity",
17
+ "GeometryLike",
18
+ "IllDefinedParityError",
19
+ "ParityMargins",
20
+ "UnsupportedElementError",
21
+ "add_bond_candidate",
22
+ "candidates",
23
+ "connectivity",
24
+ "from_geometry",
25
+ "from_ts_geometries",
26
+ "parity_margins",
27
+ "remove_candidate",
28
+ "string",
29
+ "ts_connectivity",
30
+ ]
@@ -0,0 +1,259 @@
1
+ """The public pipeline: the AMChI string of a species or a TS from its three inputs.
2
+
3
+ The components are written one by one and joined as the old AutoMol joins them
4
+ (`amchi.base.sorted_join`): sorted by the old sort key, highest first, with repeated
5
+ layers written once behind a multiplier (`2*`).
6
+ """
7
+
8
+ import itertools
9
+ from collections import Counter
10
+ from collections.abc import Sequence
11
+
12
+ import numpy as np
13
+
14
+ from ._candidates import candidates as _candidates
15
+ from ._canon import CanonicalForm, canonical_forms
16
+ from ._connect import connectivity as _connectivity
17
+ from ._connect import ts_connectivity as _ts_connectivity
18
+ from ._element import valence
19
+ from ._graph import MolGraph, explicit_graph, implicit_graph
20
+ from ._layers import component_layers, component_string
21
+ from ._parity import stereo_graph
22
+ from ._types import Candidates, Connectivity, GeometryLike
23
+
24
+ _LETTERS = ("c", "h", "b", "t", "m", "s", "k", "f", "r")
25
+ """The layers after the formula, in the order they are written."""
26
+
27
+
28
+ def string(
29
+ geometry: GeometryLike,
30
+ connectivity: Connectivity,
31
+ candidates: Candidates,
32
+ *,
33
+ stereo: bool = True,
34
+ ) -> str:
35
+ """The AMChI string of a species or a transition state (TS).
36
+
37
+ A TS has breaking or forming bonds in its connectivity, and its string has the
38
+ `k` (breaking) and `f` (forming) layers, as read in its canonical direction, and
39
+ an `r` layer if the given direction is the reverse of that (`r1`) or not (`r0`).
40
+ With `stereo=False`, the candidates are ignored, and the string has no `b`, `t`,
41
+ `m` or `s` layer.
42
+
43
+ Raises:
44
+ UnsupportedElementError: A symbol has no element data.
45
+ IllDefinedParityError: A stereocenter's parity is exactly zero.
46
+ ValueError: The inputs don't fit each other: the coordinates aren't N x 3,
47
+ a bond names a missing atom, or a candidate's neighbors aren't the
48
+ neighbors of its atom or bond (for a TS: aren't among them, over the
49
+ breaking and forming bonds too).
50
+
51
+ Examples:
52
+ >>> import amchi
53
+ >>> from types import SimpleNamespace
54
+ >>> water = SimpleNamespace(
55
+ ... symbols=["O", "H", "H"],
56
+ ... coordinates=[[0, 0, 0], [0.96, 0, 0], [-0.24, 0.93, 0]],
57
+ ... )
58
+ >>> connectivity = amchi.Connectivity(bonds=[(0, 1), (0, 2)])
59
+ >>> amchi.string(water, connectivity, amchi.Candidates())
60
+ 'AMChI=2S/H2O/h1H2'
61
+ """
62
+ symbols = list(geometry.symbols)
63
+ if not stereo:
64
+ candidates = Candidates()
65
+ _check(symbols, geometry, connectivity, candidates)
66
+ graph = implicit_graph(explicit_graph(symbols, connectivity))
67
+ graph = stereo_graph(graph, geometry, candidates)
68
+ forms = canonical_forms(graph)
69
+ return _join(graph, forms)
70
+
71
+
72
+ def from_geometry(geometry: GeometryLike, *, stereo: bool = True) -> str:
73
+ """The AMChI string of a species, with its connectivity and candidates derived.
74
+
75
+ Raises the errors of `string`.
76
+
77
+ Examples:
78
+ >>> import amchi
79
+ >>> from types import SimpleNamespace
80
+ >>> # CHFClBr and its mirror image
81
+ >>> chfclbr = SimpleNamespace(
82
+ ... symbols=["C", "H", "F", "Cl", "Br"],
83
+ ... coordinates=[
84
+ ... [0, 0, 0], [0, 0, 1.09], [1.31, 0, -0.46],
85
+ ... [-0.83, 1.44, -0.59], [-0.91, -1.58, -0.65],
86
+ ... ],
87
+ ... )
88
+ >>> amchi.from_geometry(chfclbr)
89
+ 'AMChI=2S/CHBrClF/c2-1(3)4/h1H/t1-/m1/s1'
90
+ >>> chfclbr.coordinates = [[-x, y, z] for x, y, z in chfclbr.coordinates]
91
+ >>> amchi.from_geometry(chfclbr)
92
+ 'AMChI=2S/CHBrClF/c2-1(3)4/h1H/t1-/m0/s1'
93
+ >>> amchi.from_geometry(chfclbr, stereo=False)
94
+ 'AMChI=2S/CHBrClF/c2-1(3)4/h1H'
95
+ """
96
+ connectivity = _connectivity(geometry)
97
+ if not stereo:
98
+ return string(geometry, connectivity, Candidates(), stereo=False)
99
+ candidates = _candidates(geometry.symbols, connectivity)
100
+ return string(geometry, connectivity, candidates)
101
+
102
+
103
+ def from_ts_geometries(
104
+ geometry: GeometryLike,
105
+ reactant_geometry: GeometryLike,
106
+ product_geometry: GeometryLike,
107
+ *,
108
+ stereo: bool = True,
109
+ ) -> str:
110
+ """The AMChI string of a TS, with its connectivity and candidates derived.
111
+
112
+ The three geometries are in the same atom order: the TS (for the parities) and
113
+ its reactant side and product side (for the bonds and the candidates). With
114
+ `stereo=False` the string has no `b`, `t`, `m` or `s` layer.
115
+
116
+ Raises the errors of `string`, and `ValueError` if the atoms differ.
117
+
118
+ Examples:
119
+ >>> import amchi
120
+ >>> from types import SimpleNamespace
121
+ >>> symbols = ["C", "H", "H", "H", "H", "O", "H"]
122
+ >>> ring = [[0, 0, 0.3], [1, 0, 0.3], [-0.5, 0.87, 0.3], [-0.5, -0.87, 0.3]]
123
+ >>> # CH3 + H2O: H4 moves from O5 to C0
124
+ >>> ts = SimpleNamespace(
125
+ ... symbols=symbols,
126
+ ... coordinates=[[0, 0, 0], *ring[1:], [0, 0, -1.3], [0, 0, -2.5],
127
+ ... [0.9, 0, -2.8]],
128
+ ... )
129
+ >>> reactant = SimpleNamespace(
130
+ ... symbols=symbols,
131
+ ... coordinates=[[0, 0, 0], *ring[1:], [-0.5, 0.5, -3.2], [0, 0, -2.5],
132
+ ... [0.9, 0, -2.8]],
133
+ ... )
134
+ >>> product = SimpleNamespace(
135
+ ... symbols=symbols,
136
+ ... coordinates=[[0, 0, 0], *ring[1:], [0, 0, -1.09], [0, 0, -3.2],
137
+ ... [0.9, 0, -3.5]],
138
+ ... )
139
+ >>> amchi.from_ts_geometries(ts, reactant, product)
140
+ 'AMChI=2S/CH5O/c1-3-2/h2H,1H3/k3-2/f3-1/r0'
141
+ >>> amchi.from_ts_geometries(ts, product, reactant)
142
+ 'AMChI=2S/CH5O/c1-3-2/h2H,1H3/k3-2/f3-1/r1'
143
+ """
144
+ connectivity = _ts_connectivity(reactant_geometry, product_geometry)
145
+ if not stereo:
146
+ return string(geometry, connectivity, Candidates(), stereo=False)
147
+ candidates = _candidates(geometry.symbols, connectivity)
148
+ return string(geometry, connectivity, candidates)
149
+
150
+
151
+ def _check(
152
+ symbols: Sequence[str],
153
+ geometry: GeometryLike,
154
+ connectivity: Connectivity,
155
+ candidates: Candidates,
156
+ ) -> None:
157
+ """Check the three inputs against each other."""
158
+ for symbol in set(symbols):
159
+ valence(symbol) # raises UnsupportedElementError
160
+ shape = np.shape(geometry.coordinates)
161
+ if shape != (len(symbols), 3):
162
+ msg = f"Expected {len(symbols)} x 3 coordinates, got {shape}"
163
+ raise ValueError(msg)
164
+ # A species' candidate lists exactly its atom's or bond's neighbors. A TS's
165
+ # lists those of one side or of several, so only some of all its neighbors.
166
+ is_ts = bool(connectivity.breaking or connectivity.forming)
167
+ fits = set.issubset if is_ts else set.__eq__
168
+ neighbors: list[set[int]] = [set() for _ in symbols]
169
+ for i, j in (*connectivity.bonds, *connectivity.breaking, *connectivity.forming):
170
+ if j >= len(symbols):
171
+ msg = f"A bond names a missing atom: {(i, j)}"
172
+ raise ValueError(msg)
173
+ neighbors[i].add(j)
174
+ neighbors[j].add(i)
175
+ for atoms in (candidates.atoms, candidates.reverse_atoms):
176
+ for atom, atom_neighbors in atoms.items():
177
+ if atom >= len(symbols) or not fits(set(atom_neighbors), neighbors[atom]):
178
+ msg = f"An atom candidate's neighbors aren't its atom's: {atom}"
179
+ raise ValueError(msg)
180
+ for (i, j), (side_i, side_j) in candidates.bonds.items():
181
+ if (
182
+ j >= len(symbols)
183
+ or i not in neighbors[j]
184
+ or not fits(set(side_i), neighbors[i] - {j})
185
+ or not fits(set(side_j), neighbors[j] - {i})
186
+ ):
187
+ msg = f"A bond candidate's neighbors aren't its bond's: {(i, j)}"
188
+ raise ValueError(msg)
189
+
190
+
191
+ def _join(graph: MolGraph, forms: Sequence[CanonicalForm]) -> str:
192
+ """The string of all components, sorted and joined as the old code does."""
193
+ layers = [component_layers(graph, form) for form in forms]
194
+ symbols = _sorted_symbols({graph.nodes[k]["symbol"] for k in graph} | {"H"})
195
+ keys = [_sort_key(graph, form, symbols) for form in forms]
196
+ order = sorted(range(len(forms)), key=keys.__getitem__, reverse=True)
197
+ layers = [layers[i] for i in order]
198
+
199
+ joined = {"formula": _join_layer([x["formula"] for x in layers], "", ".")}
200
+ for letter in _LETTERS:
201
+ values = [x.get(letter, "") for x in layers]
202
+ if not any(values):
203
+ continue
204
+ if letter == "m":
205
+ joined[letter] = "".join(value or "." for value in values)
206
+ elif letter == "s":
207
+ joined[letter] = max((value for value in values if value), key=int)
208
+ else:
209
+ joined[letter] = _join_layer(values, "*", ";")
210
+ return component_string(joined)
211
+
212
+
213
+ def _join_layer(values: Sequence[str], count_separator: str, separator: str) -> str:
214
+ """Join one layer of each component, with a count before a repeated value.
215
+
216
+ As the old `join_layer_strings`: equal neighbors are counted (`2*1H2`), and an
217
+ empty value is kept as an empty slot between separators.
218
+ """
219
+ parts = []
220
+ for value, group in itertools.groupby(values):
221
+ count = len(list(group))
222
+ if value:
223
+ parts.append(f"{count}{count_separator}{value}" if count > 1 else value)
224
+ else:
225
+ parts.append(separator * (count - 1))
226
+ return separator.join(parts)
227
+
228
+
229
+ def _sorted_symbols(symbols: set[str]) -> list[str]:
230
+ """C first, then alphabetical: the old `argsort` doesn't put H second."""
231
+ return sorted(symbols, key=lambda s: (s != "C", s))
232
+
233
+
234
+ def _sort_key(graph: MolGraph, form: CanonicalForm, symbols: Sequence[str]) -> tuple:
235
+ """The old sort key of a component (`amchi.base.argsort`), from its layers.
236
+
237
+ The formula counts, the neighbors and the hydrogen count of each atom by
238
+ canonical number, the bond and atom parities in the order of their layers, and
239
+ whether it is the inverted enantiomer. The charge, always 0 here, is left out.
240
+ """
241
+ atoms = sorted(form.numbers, key=form.numbers.__getitem__)
242
+ counts = Counter(graph.nodes[k]["symbol"] for k in atoms)
243
+ counts["H"] += sum(graph.nodes[k]["hydrogens"] for k in atoms)
244
+ formula = tuple(counts[s] for s in symbols)
245
+ neighbors = [sorted(form.numbers[n] for n in graph[k]) for k in atoms]
246
+ hydrogens = [graph.nodes[k]["hydrogens"] for k in atoms]
247
+ bond_parities = [
248
+ parity
249
+ for _, parity in sorted(
250
+ (sorted((form.numbers[i], form.numbers[j]), reverse=True), parity)
251
+ for (i, j), parity in form.bond_parities.items()
252
+ )
253
+ ]
254
+ atom_parities = [form.atom_parities[k] for k in atoms if k in form.atom_parities]
255
+ # None (no m layer) sorts below both values, where the old code would fail
256
+ inverted = (
257
+ -1 if form.is_canonical_enantiomer is None else not form.is_canonical_enantiomer
258
+ )
259
+ return (formula, neighbors, hydrogens, bond_parities, atom_parities, inverted)