Determine Empirical Formula from Molar Mass? [closed]








**Closed**. This question needs to be more [focused](/help/closed-questions). It is not currently accepting answers.
 
 






---








**Want to improve this question?** Update the question so it focuses on one problem only by [editing this post](/posts/112011/edit).




Closed 4 years ago.








[Improve this question](/posts/112011/edit) 



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.




Mass spec has the advantage of breaking the molecule into pieces and also a database of fingerprints. If there is a specific task at hand, this approach may not be the best. If this is a puzzle then perhaps you need multiple subroutines. For example, assess the mass numbers potential as an alkane, alkene, aldehyde, carboxylic acid etc.These could be quickly cleared against an array of known values. In any case, use more granular data. Using mass to 3 decimals places (C 12.011 and H 1.008) makes C6H14 an exact match at 86.178. C7H2 is 86.093 and would not have cleared. If you are limited to integers, multiply these by 1000 for analysis. 


 1