The raw search query
True if the query should be treated as SMILES
looksLikeSmiles("CCO") // true (pure organic atoms, 3+ chars)
looksLikeSmiles("CC(=O)O") // true (branch + double bond)
looksLikeSmiles("c1ccccc1") // true (ring-closure digits)
looksLikeSmiles("CO") // false (ambiguous: could be carbon monoxide)
looksLikeSmiles("ethanol") // false (name)
looksLikeSmiles("64-17-5") // false (CAS)
export function looksLikeSmiles(query: string): boolean {
const value = query.trim();
if (!value || /\s/.test(value)) return false;
if (isCAS(value)) return false;
if (!isProbablyValidSmiles(value)) return false;
if (STRONG_SMILES_CHARS.test(value) || RING_CLOSURE.test(value)) return true;
return PURE_ORGANIC_ATOMS.test(value) && value.length >= 3;
}
Heuristically decides whether a raw query looks like a SMILES structure rather than a chemical name or CAS number. Deliberately conservative: it only flags strong structural signals (bond/ branch/bracket characters, ring-closure digits) or pure organic-atom tokens of 3+ characters, so ambiguous short tokens like
COand ordinary names stay on the normal name-search path.