Molecular graph equivalence
Use evaluate_equivalence(mol1, mol2) to compare two RDKit graphs. It looks for an atom mapping consistent with connectivity, formal charge, and electron assignments. Supported resonance moves can establish equivalence between different drawings. 简体中文
Read a decision
These acetamide structures keep the same atoms and hydrogen attachments. The double bond and formal charges change position.
from rdkit import Chem
from molgr.utils.equivalence import evaluate_equivalence
left = Chem.MolFromSmiles("CC(=O)N")
right = Chem.MolFromSmiles("CC([O-])=[NH2+]")
result = evaluate_equivalence(left, right)
print(result.decision.value) # equivalent
decision.value |
Meaning | Example |
|---|---|---|
equivalent |
A mapping satisfies the selected conditions, with a resonance path if needed. | Different atom numbering or the two acetamide forms above. |
not_equivalent |
Evidence contradicts the selected conditions. | Different elements, isotopes, total charge, or incompatible connectivity. |
inconclusive |
The input, rules, and budget leave the comparison undecided. | Search limit reached, unsupported query atoms, or incomplete stereo labels. |
check_equivalence(...) returns (bool, result). Both a mismatch and an inconclusive comparison return False. Store result.decision to count these separately in benchmarks.
Coordination and stereochemistry
By default, comparison ignores metal-incident edges and stereo labels. To compare coordination environments, request metal connectivity explicitly. These inputs differ by one N→Cu contact.
from rdkit import Chem
from molgr.utils.equivalence import evaluate_equivalence
bound = Chem.MolFromSmiles("N->[Cu]")
separate = Chem.MolFromSmiles("N.[Cu]")
print(evaluate_equivalence(bound, separate).decision.value) # equivalent
result = evaluate_equivalence(bound, separate, ignore_metal_coordination_bonds=False)
print(result.decision.value) # not_equivalent
| Option | Default | When to change it |
|---|---|---|
ignore_metal_coordination_bonds |
True |
Set to False to preserve metal–ligand and metal–metal connectivity under the same atom mapping. The evaluator’s Lewis representation rules still apply to metal bond order and direction. |
use_chirality |
False |
Set to True to compare existing stereo labels. Fully labeled inputs can mismatch if every mapping contradicts the labels. A missing label on one side can leave the result inconclusive. |
The evaluator reads assigned labels. It supports tetrahedral, double-bond, square-planar, trigonal-bipyramidal, and octahedral stereochemistry. Ignoring metal edges also skips labels that depend on those edges. Isotopes, metal elements, and normalized metal formal states still enter comparison.
Do different radical counts prove a mismatch?
RDKit can infer radicals on low-valence atoms, while MolGR can explicitly label unpaired electrons. The evaluator distinguishes an explicit zero from a missing annotation. For supported carbene and metal Lewis forms, it normalizes local bonds and electron assignments before comparing labels under a mapping. Fragment radical totals alone do not establish a mismatch.
Resonance and search budgets
Resonance moves change local bond orders, charges, and radical positions while fixing the atomic skeleton and hydrogen attachments. This covers amide resonance. Tautomerization that moves hydrogen between atoms is outside these rules. Preserve the inconclusive result when the search exhausts its budget without a witness.
| Parameter | Default | Work limited |
|---|---|---|
max_resonance |
5000 |
Both sides together may generate up to twice this value (10,000 states by default). Regions, mappings, and retries share the budget. |
max_resonance_steps |
24 |
Maximum length of the path connecting both states in each region. |
max_mappings |
None |
Maximum complete mappings checked. The default allows 10,000. |
max_mapping_nodes |
100000 |
Search nodes visited during mapping, including partial assignments. |
The input limit is 4,096 atoms including expanded hydrogens. A direct graph match can return before resonance search.
What evidence supports a decision?
reasonsummarizes the decision.invariantsrecords required properties such as total charge and elemental composition.contradictionslists conflicts.atom_mappinggives the matching right-hand index for each left-hand atom. Indices start at zero after hydrogen expansion. Aresonance_witnesscan show how both sides reach the same electronic state, using left-hand indices for both paths.bounded_searchandnative_statsreport explored states, mappings, and stopping conditions. Missing electronic labels are unknown. Only labels present on both sides can be compared.
To check whether one molecule preserves its bonds, explicit hydrogens, and donor direction through serialization, use SMILES round-trip validation.