# Determine Empirical Formula from Molar Mass? [closed]

I am trying to write a computer program that predicts the empirical formula of a compound based only on that compound's mass, like what you would get from a high resolution mass spec.

I have the basics of the program figured out. I start with the highest mass element and assume the compound is entirely made of it, then iterate through the lower mass elements until I find combinations that get close to the compound's mass. For example, let's assume the heaviest element I consider is Oxygen and I have a mass of 86.178 g/mol. I begin by assuming the compound is made of 5 Oxygens, but 5 Oxygens doesn't get close enough the goal, so I assume 4 Oxygens and 1 Nitrogen and so on until I land on 6 Carbons and 14 Hydrogens.

The program was successfully able to produce C6H14, but also produced nonsense like C7H2 and C0H85. I decided to check the degree of unsaturation of each potential compound and found that by throwing out everything with negative unsaturations I was able to get rid of most of the junk. But the C7H2 is still considered "valid", with an unsaturation of 7. I know this formula is wrong, but I can't think of a simple rule I can program in to check for these mistakes.

I've considered making sure that there are more non-carbon atoms than carbon atoms, but this clearly doesn't apply to inorganic compounds. I've considered that the oxidation state of the entire molecule must be equal to the charge, but I don't know how to get the oxidation state of the whole molecule based only on elemental composition.

I can't be the first person to attempt this, so I thought I'd ask here if anyone knew a better way to determine the empirical formula from the molar mass.

And I'm aware that there could be situations where 1 mass could correspond to more than 1 formula, but the program should produce both formulas.

• Yes, there are computer programs that analyze mass spectra. However it is a lot more complicated than just finding the peak with the highest mass number. For mass spectra you also have to consider isotopes for instance.
– MaxW
Commented Apr 2, 2019 at 15:04
• Doing this from scratch for any type of compounds is going to be very hard. Even with a restricted set (say compounds of C,H,O, and N) it isn't easy. Not least because the combinatorial complexity in organic chemistry will give plenty of overlapping formulae. Even counting isomers of saturated hydrocarbons is non-trivial as the possible number of isomers of each grows extremely rapidly with the number of carbons. Commented Apr 2, 2019 at 19:56
• Relevant literature for you to read: bmcbioinformatics.biomedcentral.com/articles/10.1186/… Commented Apr 3, 2019 at 20:55
• ncbi.nlm.nih.gov/pubmed/17389044 Commented Apr 3, 2019 at 20:56