There is not one, but there are multiple approaches to describe a molecule by a SMILES string. It is up to the developers of the programs (and databases) to define which one is used and to declare this in the documentation. Thus, read the manual; if they do not state this explicitly, ask them.
One of the better approaches taken is, for example the one by OpenBabel; it offers you to write e.g., either a canonical, universal, or inchified SMILES string.
If SMILES you work with have origin in multiple sources adhering to more than one dialect, you may request e.g., OpenBabel to consolidate the representation you subsequently use. Thus
obabel -:"C1=CN=CC=C1C(=O)NN" -ocan
yields to the canonical SMILES string NNC(=O)c1ccncc1
. In case you have a file listing many SMILES, consider a conversion like
obabel -ismi input.txt -ocan -O output_canonical.smi
Noel M O'Boyle wrote a paper about the methods to identify a canonical SMILES representation of (organic) structures which provides insight here, too.
Towards a Universal SMILES representation - A standard method to generate canonical SMILES based on the InChI in J. Cheminf. 2012; doi 10.1186/1758-2946-4-22.
A comment suggested to use InChI and their hashed form, InChI keys as a replacement of SMILES. Their spread in databases (example NIST, or examples compiled by Warr) may be tempting and checking identity of entries based on InChI key appealing in terms of performance and collision resistance once they are in hand (e.g., Goodman et al.).
However, the discern of different compounds which are tautomers of each other currently is not possible using standard InChI/InChI key. Take, for example, 2-hydroxypyridine and its tautomer, 2-pyridone. Depending on the polarity of the solvent, one form may be favoured over the other; and while both structures differ, and are described by two different canonical SMILES, the standard InChI and InChIKey are the same for both:
because
«different tautomers have the same connectivity/hydrogen layer»
see 4.7. Standard InChI specifics, InChI trust's Technical FAQ by 2012-05-12
What can be done, e.g. using InChI trust's reference binaries (version 1.06/December 2020, repository), is to invoke the inclusion of a fixed H layer then leading to InChI
InChI=1/C5H5NO/c7-5-3-1-2-4-6-5/h1-4H,(H,6,7)/f/h7H
InChI=1/C5H5NO/c7-5-3-1-2-4-6-5/h1-4H,(H,6,7)/f/h6H
and
InChIKey=UBQKCCHYAOITMY-QDQILVOLNA-N
InChIKey=UBQKCCHYAOITMY-BRMMOCHJNA-N
As of now, the inclusion of a fixed H layer in InChI leads to a non-standard description (thus, there is no leading 1S
). Equally note that only the second hash block is affected to yield a different InChIKey.
Thus, in short depending on what you aim for, use InChI/InChIKey with caution.
References:
Goodman, J. M.; Platnev, I.; Thiessen, P.; Bolton, E.; Heller, S. R. InChI version 1.06: now more than 99.99% reliable in J. Cheminform. 13, 2021, 40; doi 10.1186/s13321-021-00517-z, open access.
Warr, W. A. Many InChIs and quite some feat in J. Comput. Aided Mol. Des. 29, 2015, 681–694; doi 10.1007/s10822-015-9854-3.