rd.from_connectivity()
Build a molecule from connectivity, perceiving its Lewis structure.
Usage
rd.from_connectivity(
symbols,
bonds,
*,
charge=0,
spin=0,
coords=None,
)Bond orders, formal charges, and radical electrons come from an integer linear program over the bonded atoms:
- Each atom takes one (charge, valence) state from RDKit’s valence model, where a charged atom uses the valences of its isoelectronic neutral counterpart.
- Each bond takes an order of 1, 2, or 3.
- Each atom’s valence is saturated by its bond orders plus radical electrons.
- Formal charges sum to charge and radical electrons sum to spin.
The objective penalizes, from most to least severe: closed-shell lone pairs beyond the default valence (singlet carbenes), formal charges, valence expansion, and multiple radical electrons on one atom. Ties put negative charge on more electronegative atoms, and positive charge and radicals on less electronegative ones.
Parameters
symbols: Sequence[str]-
Atomic symbols.
bonds: Collection[tuple[int, int]]-
Pairs of bonded atom indices.
charge: int = 0-
Total molecular charge.
spin: int = 0-
Number of unpaired electrons.
coords: ArrayLike | None = None-
Coordinates, shape
(N, 3), added as a conformer if given.
Returns
Mol- Sanitized RDKit molecule with explicit hydrogens.
Raises
NotImplementedError-
If the molecule contains a metal.
GeometryConversionError- If no Lewis structure is consistent with the connectivity, charge, and spin.