I was working on an approach to simplify an old Javascript stoichiometric
routine that I have to determine the mass of model fragments in the Jmol window
- i.e. click break bonds and look at the resulting masses to emulate MS
fragmentation. While playing around, I noticed the Jmol is ideally suited to
doing this with very little code. Specifically, with a little Regular
Expression magic, Jmol’s reporting of molecular formulas IS a stoichiometric
calculation - in retrospect, no surprise. Any molecular formula IS a
stoichiometric calculation. Regular Expressions involve real sweat equity, at
least for me, so I’ll share this snippet with any who may have an interest.
Given the code length of my old (20 years) approach. I’m just shaking my head.
The Comments:
1) The element symbols are unique variables. The masses below are mono-isotopic
most abundant for MS “animation"
2) Standard Jmol to get molecular formula JavaScript array of the models in the
window
3) Regular Expression magic that converts each formula to a stoichiometric
statement and the resulting value
The JavaScript - be careful of possible Rich Text smart quotes if you
copy/paste:
H=1.007825;Li=7.016005;Be=9.012183;B=11.009305;C=12;N=14.003074;O=15.994915;F=18.998403;Cl=34.968853;Br=78.918336;I=126.904477;Na=22.989770;Mg=23.985045;Al=26.981541;Si=27.976928;P=30.973763;S=31.972072;
var strMods = Jmol.evaluateVar(jmolApplet0,
"getProperty('moleculeInfo.mf')").toString().split(",");
for (var i = 0; i < strMods.length; i++) { strMods[i] =
strMods[i].replace(/([a-z])\s([0-9])/ig,
'$1\*$2').replace(/([0-9])\s([a-z])/ig, '$1\+$2');alert(eval(strMods[i])); }
Otis
------------------------------------------------------------------------------
_______________________________________________
Jmol-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jmol-users