aromaticity
Aromaticity perception for molecular graphs.
Implements Hückel's 4n+2 rule for detecting aromatic rings, with support for heteroatoms (N, O, S) in various bonding environments.
The detection flow is: 1. Get Kekulé bond orders from geometry (single/double/triple) 2. Find rings with conjugated bonds (alternating or equal unsaturation) 3. Check 4n+2 π electron count
count_pi_electrons(graph, ring)
Count the number of π electrons contributed to a ring.
Different atoms contribute different numbers based on their bonding environment: - Carbon (sp2): 1 electron - Nitrogen (pyridine-like, =N-): 1 electron - Nitrogen (pyrrole-like, -NH-): 2 electrons - Oxygen/Sulfur with lone pairs: 2 electrons
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
MolecularGraph
|
A MolecularGraph instance. |
required |
ring
|
tuple[int, ...]
|
Tuple of atom indices forming the ring. |
required |
Returns:
| Type | Description |
|---|---|
int | None
|
Number of π electrons, or None if the ring cannot be aromatic. |
Source code in chmpy/graph/aromaticity.py
get_aromatic_rings(graph)
Get all aromatic rings in the graph.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
MolecularGraph
|
A MolecularGraph instance. |
required |
Returns:
| Type | Description |
|---|---|
list[tuple[int, ...]]
|
List of tuples containing atom indices for each aromatic ring. |
Source code in chmpy/graph/aromaticity.py
is_aromatic_atom(graph, atom_idx)
Check if an atom is aromatic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
MolecularGraph
|
A MolecularGraph instance. |
required |
atom_idx
|
int
|
Index of the atom to check. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the atom is part of an aromatic ring. |
Source code in chmpy/graph/aromaticity.py
is_aromatic_bond(graph, atom_i, atom_j)
Check if a bond is aromatic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
MolecularGraph
|
A MolecularGraph instance. |
required |
atom_i
|
int
|
First atom index. |
required |
atom_j
|
int
|
Second atom index. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the bond is part of an aromatic ring. |
Source code in chmpy/graph/aromaticity.py
is_aromatic_ring(graph, ring)
Check if a ring is aromatic using Hückel's 4n+2 rule.
A ring is aromatic if: 1. It is planar (assumed for small rings) 2. All atoms can participate in aromaticity (C, N, O, S, etc.) 3. Ring is conjugated (bonds are unsaturated based on geometry) 4. It has 4n+2 π electrons (n = 0, 1, 2, ...)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
MolecularGraph
|
A MolecularGraph instance. |
required |
ring
|
tuple[int, ...]
|
Tuple of atom indices forming the ring. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the ring is aromatic. |
Source code in chmpy/graph/aromaticity.py
perceive_aromaticity(graph)
Perceive aromaticity in a molecular graph.
Identifies aromatic atoms and bonds based on ring membership and Hückel's 4n+2 rule for π electrons.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
MolecularGraph
|
A MolecularGraph instance. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Tuple of (aromatic_atoms, aromatic_bonds) where: |
ndarray
|
|
tuple[ndarray, ndarray]
|
|