2021-05-11

Mass spec molecule guesser

The text below is a static HTML version of a python/jupyter notebook I made in 2019 for a friend working with mass spectrometry. As such, you can see the code I wrote and its real output, but can't execute the code for yourself on this webpage. If you want to try out the code for yourself, you can download the full notebook file here.

I am sure there are much more sophisticated molecule predictors freely available elsewhere. The original purpose of this code was mainly to provide a useful demonstration of how (relatively) easy it can be to use even basic computational tools to go beyond the limits of Microsoft Excel, reduce hand-work/guess-work, etc. This code merely relies on for loops, an if statement, an addition and multiplication equation, and a print command. That's it!

Three notes about the code and output below:

  1. Neither of the two main code blocks have errors. The output for each shows an error message because I forcefully interrupted its execution because:

  2. Each of the two main code blocks produces a lot of output. The first main code block produces about 500 lines of output, and completes (on my computer) in less than 5 minutes. The second main code block produces over 1,000 lines of output, and may take more than 10 minutes.

  3. The output "molecular formulae" have been formatted so that all formulae have the same number of characters. Thus an output like C07_N01_O13_S00_H065 should be read as C7N1O13H65.