Skip to main content

Understanding SMILES

Every molecule in this project is given as a SMILES string (Simplified Molecular Input Line Entry System). In Iteration 1 you used these strings without reading them. In this iteration you work with the raw data, so it helps to know what a SMILES string says about a molecule, and what it does not say. You don’t need to write SMILES strings yourself, and you don’t need a chemistry background for this page.

SMILES: a way to write the structure of a molecule as a single line of text: its atoms, the bonds between them, and its rings.

An organic molecule from the starter dataset: a chain of connected rings, with sulfur, nitrogen and oxygen atoms.

A molecule from the starter dataset and its SMILES string. By the end of this page you can read most of this string.
Cn1c2ccccc2c2ccc(-c3ccc(-c4ccc(-c5cccs5)c5nonc54)s3)cc21

Atoms

Each atom is written as its element symbol: C for carbon, N for nitrogen, O for oxygen, S for sulfur. Atoms written next to each other are bonded. So CCO is a carbon bonded to a carbon, bonded to an oxygen: ethanol.

Hydrogen atoms are usually left out. Every atom gets as many hydrogens as it needs to have its normal number of bonds. Carbon normally has four bonds, so the first C in CCO has three hydrogens. The drawings follow the same habit: a corner or end of a line without a letter is a carbon, and its hydrogens are not drawn.

Ethanol drawn as a zigzag line ending in OH.

CCO, as it is usually drawn

Ethanol with all six hydrogen atoms drawn.

CCO, with all hydrogens drawn

Some atoms need square brackets: elements outside the common set B, C, N, O, P, S, F, Cl, Br and I, such as silicon ([Si], or [SiH2] for a silicon atom with two hydrogens), and atoms with a charge or an explicit hydrogen, such as [O-] or [nH]. An aromatic atom in brackets is lowercase too: [se] is a selenium atom in an aromatic ring, as in selenophene, the selenium version of thiophene below. You will see [Si], [SiH2] and [se] in the project molecules.

Bonds

A single bond needs no symbol. A double bond is written as = and a triple bond as #.

Ethanol: single bonds only.

CCO: single bonds only

Acetaldehyde, with the carbon-oxygen double bond highlighted.

CC=O: a double bond

Acetonitrile, with the carbon-nitrogen triple bond highlighted.

CC#N: a triple bond

Branches

A SMILES string is read from left to right, like a path through the molecule. When the path splits, the side branch goes in parentheses, and the path continues after the closing parenthesis. In CC(O)CC, the O hangs off the second carbon, and the chain continues with two more carbons. Branches can contain bonds and further branches: in CC(=O)O, the branch is a double-bonded oxygen.

2-Butanol, with the OH group of the branch highlighted.

CC(O)CC: the branch is the O

Acetic acid, with the double-bonded oxygen of the branch highlighted.

CC(=O)O: the branch is the =O

Rings

A line of text cannot close a loop, so rings are written as a chain plus a label. A digit after an atom opens a ring, and the same digit later closes it: the two atoms with that digit are bonded. C1CCCCC1 is a chain of six carbons in which the first and the last are bonded, a ring of six.

When a molecule has several rings, each ring gets its own digit while it is open. A digit can be used again after its ring is closed, so the digits count open rings, not all rings. In the long project molecule above, the digits go up to 5, but the molecule has more than five rings.

Cyclohexane, with the bond between the first and the last carbon highlighted.

C1CCCCC1: the two 1s create the highlighted bond

Naphthalene, two fused rings, with the two ring-closure bonds highlighted.

c1ccc2ccccc2c1: two ring closures, 1 and 2

Aromatic rings

Lowercase letters mark atoms in an aromatic ring: a flat ring in which the electrons are shared over the whole ring, as in benzene. Benzene can be written as c1ccccc1 or, with alternating single and double bonds, as C1=CC=CC=C1. Both strings describe the same molecule.

Aromatic rings are everywhere in this project. Organic solar-cell molecules are often long chains of rings like the ones below, for example rings with a sulfur atom (s).

The letters are not always taken literally. RDKit decides itself which rings are aromatic, so it changes some strings when it reads them: in some of the project molecules, a ring written in lowercase is not aromatic for RDKit, or the other way around. Compute features from the molecule that RDKit makes (Chem.MolFromSmiles), not from the letters of the string.

Benzene, a six-membered aromatic ring.

Benzene: c1ccccc1

Thiophene, a five-membered aromatic ring with one sulfur atom.

Thiophene: c1ccsc1

Benzothiadiazole, a benzene ring fused with a five-membered ring of two nitrogens and a sulfur.

Benzothiadiazole: c1ccc2nsnc2c1

What a SMILES string does not say

SMILES describes which atoms are bonded to which. It does not describe the shape of the molecule in space: the drawings on this page are flat, but real molecules are three-dimensional and can bend and rotate.

Some molecules have the same atoms and bonds but a different arrangement in space. SMILES has optional symbols for this: / and \ for the two sides of a double bond, and @ and @@ for the arrangement around an atom. When these symbols are left out, the string does not say which of the arrangements is meant.

Trans-1,2-difluoroethene: the two fluorine atoms on opposite sides of the double bond.

F/C=C/F: the fluorines on opposite sides

Cis-1,2-difluoroethene: the two fluorine atoms on the same side of the double bond.

F/C=C\F: the fluorines on the same side

FC=CF, without the slashes, can be either of the two.

The SMILES strings in this project contain none of these symbols. Two molecules that differ only in such an arrangement would therefore have the same string, and the same descriptors.

One molecule, many strings

You can start a SMILES string at any atom, choose the order of the branches, number the rings in another way, and write aromatic rings in lowercase or with alternating bonds. Each choice gives another valid string for the same molecule:

Molecule Some valid SMILES strings
Ethanol CCO, OCC, C(O)C
Thiophene c1ccsc1, s1cccc1, C1=CSC=C1
Acetic acid CC(=O)O, OC(=O)C

The same holds for the long molecules of the project. These two strings describe the molecule at the top of this page:

Cn1c2ccccc2c2ccc(-c3ccc(-c4ccc(-c5cccs5)c5nonc54)s3)cc21
c1cc(-c2ccc(-c3cc4c(c5ccccc5n4C)cc3)s2)c2nonc2c1-c1sccc1

A canonical SMILES is one string chosen by a fixed set of rules, so that a molecule always gets the same string, however it was written before. RDKit, the chemistry library of this course, computes it when it reads a molecule and writes it out again:

Canonical SMILES: the one SMILES string that a program always produces for a given molecule.

from rdkit import Chem

for smiles in ["CCO", "OCC", "C(O)C"]:
    print(Chem.MolToSmiles(Chem.MolFromSmiles(smiles)))
# CCO
# CCO
# CCO

The rules differ between programs, and sometimes between versions of the same program. The canonical SMILES of RDKit is not the same as that of another chemistry package, so canonical strings can only be compared when they were made by the same software. A string is also not canonical just because it is in a dataset: the first string of the project molecule above comes from the starter dataset, and RDKit’s canonical version of it has c45) where that string has c54).

Further reading