smiles invalid valence error

Reading SMILES Valence Errors: Which Atom Is Wrong and Why

A SMILES invalid valence error flags one overbonded atom. Read the message and fix the charge, bracket, or typo behind each common case.

ChemStitchJune 12, 2026

You paste a SMILES straight out of a vendor catalog and the parser rejects it with something like Explicit valence for atom # 7 N, 4, is greater than permitted. The string looked fine. The error even tells you the atom and the count — but not what to actually change. A SMILES invalid valence error almost always means one atom has more bonds (or the wrong charge) than the element allows, and the parser won’t guess which fix you intended. Here are the valence errors that stop a structure from loading, how to read the message, and the specific correction for each — starting with the overbonded nitrogen behind most of them.

How to read the error message first

RDKit and most toolkits report the offending atom by index and element: Explicit valence for atom # N X, V, is greater than permitted. The index is zero-based and counts atoms in the order they appear in the SMILES, so atom #0 is the first atom you wrote. X is the element, V is the valence the parser computed. Before changing anything, count to that atom in your string and add up its bonds. The mismatch between V and the element’s normal valence is the whole problem.

Tip The atom index is zero-based and follows write-order, not the drawing. In CC(=O)[N+](C)(C)(C)C, atom #3 is the nitrogen — the fourth atom written. Counting to the named index is faster than re-reading the whole string.

Mistake 1 — Neutral nitrogen written with four bonds

What you see: Explicit valence for atom # 3 N, 4, is greater than permitted on a quaternary ammonium or a protonated amine written without its charge.

Why it happens: Neutral nitrogen has a normal valence of 3. A four-coordinate nitrogen is real chemistry — a quaternary ammonium or a protonated amine — but it carries a formal +1 charge. If you write the four bonds and omit the charge, the parser sees a neutral nitrogen with valence 4, which is impossible, and stops.

The fix: Add the formal charge in brackets. Tetramethylammonium is [N+](C)(C)(C)C, not N(C)(C)(C)C. A protonated secondary amine is C[NH2+]C. The bracket does double duty: it declares the charge and switches off the automatic hydrogen-filling that would otherwise add an extra bond.

Mistake 2 — A halogen or oxygen carrying too many bonds

What you see: Explicit valence for atom # 4 Cl, 2, is greater than permitted, or the same for F, Br, or a doubly-bonded neutral oxygen in the wrong place.

Why it happens: The halogens are monovalent and neutral oxygen is divalent. A chlorine with two bonds usually means a typo — a ring-closure digit landed on the halogen, or a branch parenthesis closed in the wrong spot, leaving Cl bridging two atoms. The parser is right: a neutral chlorine cannot bond twice.

The fix: If the second bond is a real hypervalent species — a chlorate or a sulfonyl-type oxygen — write the explicit charges or use the correct oxidation state. More often it is a string error: check for a stray ring-closure number on the halogen (Clc1ccccc1 is chlorobenzene; Cl1ccccc1 tries to ring-close through the chlorine) or a misplaced closing parenthesis.

Common Mistake A ring-closure digit immediately after a terminal atom binds to that atom. OC1=CC=CC=C1 is phenol; O1C=CC=CC=1 silently builds a different ring through the oxygen. When a monovalent or divalent atom throws a valence error, look for a ring digit or branch that attached to it by accident.

Mistake 3 — Hypervalent sulfur or phosphorus without explicit valence

What you see: a valence error on S (sulfone, sulfonamide, sulfate) or P (phosphate, phosphonate) where you expect 4, 5, or 6 bonds.

Why it happens: Sulfur and phosphorus genuinely take expanded octets, and toolkits do allow common higher valences (S at 2/4/6, P at 3/5). The error appears when the written bond count lands on a value the toolkit’s valence model doesn’t list as permitted for that element — for example, a sulfur drawn with five single bonds, or a phosphorus pushed past 5 by an extra double bond.

The fix: Write the group the conventional way. A sulfonyl is two double-bonded oxygens: methanesulfonamide is CS(=O)(=O)N, with sulfur at valence 6 across two =O and two single bonds. A phosphate ester uses P(=O)(O)(O)O. If you intended a charged, fully ionized form, write the anionic oxygens explicitly: OP(=O)([O-])[O-]. The conventional connectivity keeps the atom inside the toolkit’s allowed-valence set.

Mistake 4 — Aromatic-flag valence errors (the kekulization cousin)

What you see: a valence or sanitization error on a lowercase aromatic atom, often an aromatic nitrogen or carbon that can’t carry the bonds the aromatic system implies.

Why it happens: Lowercase atoms assert aromaticity, and the parser then has to assign a valid bonding pattern. An aromatic nitrogen written as bare n when it should hold a hydrogen, or an aromatic carbon given an extra exocyclic double bond, produces a valence the aromatic model can’t satisfy. This overlaps with the kekulization failure but surfaces as a valence complaint when the atom itself is overloaded.

The fix: For an aromatic nitrogen that carries a hydrogen, bracket it as [nH] — pyrrole is [nH]1cccc1. When the issue is an aromatic atom with an impossible substituent count, the cleaner move is often to write the ring in Kekulé (uppercase, alternating single/double) form and let the toolkit perceive aromaticity itself. The full treatment of aromatic-nitrogen protonation lives in our walkthrough of why a SMILES won’t kekulize and how to fix the [nH] nitrogen.

Spot-check yourself before you blame the parser

When a valence error appears, run this short pass. Count to the named atom index. Add up its bonds, counting a double bond as 2 and a triple as 3. Compare against the element’s normal valence (C 4, N 3, O 2, halogens 1, S 2/4/6, P 3/5). If the real species is charged or hypervalent, the bracket-and-charge form usually resolves it; if it isn’t, you have a typo — a stray ring digit, a misplaced parenthesis, or a missing bracket. The error is almost never a toolkit bug. A 2017 RDKit thread on “bad valences accepted by the SMILES parser” is mostly about the parser being too permissive, not too strict.

Pasting the string into an editor that names the offending atom on the canvas turns this from string-counting into pointing. Our browser-based SMILES-to-structure tool classifies the parse failure, names the atom, and — for the unambiguous aromatic-nitrogen case — offers the [nH] rewrite, so you see exactly which atom the message means before you edit. For the broader skill of reading and debugging line notation, see our reference on reading and debugging SMILES notation.

Most valence errors come down to one atom and one missing piece of information — a charge, a bracket, or a deleted typo. Read the index, count the bonds, and fix that one atom rather than rewriting the whole string. The toolkit’s own RDKit Getting Started documentation and the OpenSMILES specification both spell out the valence model the parser is enforcing.

Try ChemStitch

AI-powered chemical structure editor. Free 14-day trial.

Start free trial →