SMILES#

The Simplified Molecular Input Line Entry System (SMILES) is a line format to represent molecules including stereochemistry, charge, and more.

Loading molecules from SMILES#

SMILES can be loaded as molecules using the molfoundry.smiles() or molfoundry.Graph.fromSMILES() functions, supporting all common SMILES conventions and some additional ones:

g = mf.smiles("OC(=O)CC(O)(C(=O)O)CC(=O)O")
printer = mf.GraphPrinter()
printer.drawMode = mf.DrawMode.Circles
g.print(printer)
g_{0}
H H H H H H H H O O O O O O O C C C C C C

Note

Dative bonds -> and <- are accepted and interpreted as normal single bonds.

Note

Stereochemistry is currently loaded as normal bond types but not further interpreted.

Loading molecules from SMILES with atom IDs#

Atoms in SMILES can be annotated with an ID. These are parsed and stored as node properties in the graph structure and can be retrieved from the graph vertices (molfoundry.Vertex.externalId). Atoms without an ID will return zero.

g = mf.smiles("[OH:1]C(=O)CC(O)(C(=O)O)C[C:4](=O)O")
print([v.externalId for v in g.vertices])
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 4, 0, 0, 0]

Loading molecules from SMILES as electron graphs#

Providing a molfoundry.GraphType allows loading a SMILES as an electron graph:

g = mf.smiles("OC(=O)CC(O)(C(=O)O)CC(=O)O", graphType=mf.GraphType.Electron)
g.print(printer)
g_{2}
H H H H H H H H C C C C C C O O O O O O O

Retrieving SMILES of a molecule#

The molfoundry.Graph.smiles property can be used to get a molecules SMILES string:

g = mf.smiles("OC(=O)CC(O)(C(=O)O)CC(=O)O")
print(g.smiles)
O=C(O)CC(O)(C(=O)O)CC(=O)O

Retrieving SMILES of a molecule with IDs#

If required, SMILES atoms can be annotated with IDs from the graph structure’s canonical labeling using the molfoundry.Graph.smilesWithIds:

print(g.smilesWithIds)
[O:8]=[C:17]([O:12][H:6])[C:18]([H:2])([H:3])[C:20]([O:11][H:7])([C:15](=[O:10])[O:14][H:4])[C:19]([H:0])([H:1])[C:16](=[O:9])[O:13][H:5]

Retrieving SMILES of a molecule with custom IDs#

Just like loading a SMILES with atom IDs, we can assign IDs to graph vertices using the molfoundry.Vertex.setExternalId() function and export them to SMILES:

g = mf.smiles("OC(=O)CC(O)(C(=O)O)CC(=O)O")
list(g.vertices)[2].setExternalId(14)
print(g.smilesWithExternalIds)
O=C(O)[CH]([H:14])C(O)(C(=O)O)CC(=O)O