There are a lot of chemical search engines (such as ChemSpider's Structure search) that allow users to draw and search for a molecule. How does it work? Is the comparison of images used? Could you give me an algorithm or pseudo code?
-
1$\begingroup$ That title had me confused a bit. How does a molecule search work? It doesn't, it molecules... $\endgroup$– Martin - マーチン ♦Commented Aug 9, 2017 at 1:55
-
1$\begingroup$ This site gives a pretty in depth explanation on how these work and has a series on how to develop such a search engine $\endgroup$– Tyberius ♦Commented Aug 10, 2017 at 16:06
3 Answers
Usually, structure search is implemented using a graph model. For example, let's take cyclohexane. On screen this is a hexagon - but this is converted on the server to a simple atom/bond graph model of six carbons in a ring.
This graph can then be compared to all the molecules in the database by various means. For example, subgraph isomorphism or fingerprints or even SMILES string comparison.
As far as I know, ChemSpider allows a variety of searches - with/without hydrogens, substructure search, element fingerprints, and so on. Each of these is a whole question by themselves, so I'm not sure how useful an algorithm that covers them all would be.
Using image based search wouldn't work very well since the same compound can be drawn in a lot of different and correct ways. However, it is possible to convert drawn structures or even 3D structures into text, for example using SMILES or InChI. Those can then be used for standard text based database search.
ChemSpider likely has an algorithm that takes the image and converts it to a SMILES string. It would likely have to do so in order to avoid problems in how the structure is drawn as @DSVA pointed out.
For example, if there's a large molecule (where there could be on the order of billions of slight conformational differences), it would be nearly impossible to find a perfect match in the database. However, by considering only the connectivity of atoms (as a SMILES string would achieve), the software could find a match nearly instantaneously.
ChemSpider has an option on their website to search using a SMILES string, so it's known that their software is capable of recognizing SMILES strings. However, I was unable to find confirmation as to whether SMILES is used as a search method as their software does not appear to be open-source.