Molar masses of compounds Task
Write a program that takes in a compound made solely of elements with an atomic number less than or equal to 92 (Uranium), and outputs the molar mass of the compound in grams/mole.
Rules and Restrictions

You may not use a function that directly calculates molar masses for you.
Your program must be able to run on an offline machine.
You MAY use a separate data file. Contents of this file must be provided.
Your score is the length of your program in bytes, plus the the length of your data file in bytes, should you choose to use one.
This is code-golf, therefore, lowest score wins.

Input
A string containing the compound. This string may be read through STDIN, passed as an argument, or set to a variable (please specify which). The following are all valid inputs:

CH2 (one Carbon, two Hydrogens)
(CH2)8 (8 Carbons, 16 Hydrogens)
U (1 Uranium)

Your program is not required to function for embedded parentheses (i.e. ((CH3)2N4)4), nor for any compound that contains an element with atomic number greater than 92. If your program does not function for either of the above two cases, it must output Invalid formula for such cases - no undefined behavior.
Output
You should output, to STDOUT or to a variable, the molar mass of the compound in grams/mole. A list of atomic masses of elements is available here (Wikipedia). Your answer should be accurate to the decimal place for compounds containing fewer than 100 atoms (rounded).
If the input is invalid, Invalid formula must be outputted.
Information on calculating the molar mass of a compound in grams/mole (Wikipedia).
Examples
Input                   Output
H2O                     18.015
O                       15.999 (16 acceptable)
C6H2(NO2)3CH3           227.132
FOOF                    69.995
C6H12Op3                Invalid formula
Np                      237 (or Invalid formula)
((C)3)4                 144.132 (or Invalid formula)
CodeGolf                Invalid formula
Bash, 978 708 675 673 650 636 632 631 598 594 

211 bytes for the program and 382 bytes for the data.

Input is on STDIN, output is on STDOUT. WARNING: creates files called g and a, if they exist, they will be overwritten!


zcat y&gt;g 2&gt;a
s=(`sed 's/[A-Z][a-z]*/&amp; /g;q'&lt;g`)
p=1.008
v=`sed 's/[0-9]\+/*&amp;/g;s/(/+(0/g'`
r=(`tail -1 g`)
for n in {0..91};{
p=`bc&lt;&lt;&lt;$p+${r[n]}`
v=${v//${s[n]}/+$p}
}
o=`bc&lt;&lt;&lt;0$v 2&gt;a`
echo ${o:-Invalid formula}


Data file

This requires a file called y, which is the zopfli-compressed form of this data (no trailing newline). zopfli is a gzip-compatible compression algorithm and can be decompressed with standard gzip tools. It was run with 1024 iterations (this is probably too much). The last 8 bytes were then removed.

HHeLiBeBCNOFNeNaMgAlSiPSClKArCaScTiVCrMnFeNiCoCuZnGaGeAsSeBrKrRbSrYZrNbMoTcRuRhPdAgCdInSnSbITeXeCsBaLaCePrNdPmSmEuGdTbDyHoErTmYbLuHfTaWReOsIrPtAuHgTlPbBiPoAtRnFrRaAcPaThU
0 2.995 2.937 2.072 1.798 1.201 1.996 1.992 2.999 1.182 2.81 1.315 2.677 1.103 2.889 1.086 3.39 3.648 .850 .130 4.878 2.911 3.075 1.054 2.942 .907 2.848 .24 4.613 1.834 4.346 2.904 2.292 4.038 .944 3.894 1.670 2.152 1.286 2.318 1.682 3.054 2.04 3.07 1.836 3.514 1.448 4.543 2.407 3.892 3.050 5.144 .696 3.693 1.612 4.422 1.578 1.211 .792 3.334 .758 5.36 1.604 5.286 1.675 3.575 2.43 2.329 1.675 4.120 1.913 3.523 2.458 2.892 2.367 4.023 1.987 2.867 1.883 3.625 3.788 2.82 1.78 .02 1 12 1 3 1 4.036 1.002 5.991


The base64 of y is (use base64 -d to reproduce the original file):

H4sIAAAAAAACAwTB226DMAwA0G9LvEJQIbVi70LfHPBoJAiSaR729zsnBB2LVw/x0UWNMm1up4IE
+90ZCC1cvsCm2mkscEJ71l56dRept7ulTDY/Lebp5CW19MLVbbAOlSrlgfVH4fIyCihaXPGg49b6
lfPHXzhvxsecxxZ+Wb6TPq7B8O1a2HjH7Aue7p1qZ0ncgsKvz/8WxuRGoigGgfcfxYvA8r7kn9iA
ei6ohAt/+lzuihmD1PFnMrdIV0PeNfOczh3Ylrw8hnHaM6w1WC8V3X4hcYjOfbKlTyz0pewsP5nh
plOUK9mkPzkd4HLiCbktIGyQI5uaUvZzNBrwLhOf9hJij+Jo5WBf6mHLfh2OFqeaxOHbaGAZl5mL
h5UBI3Hlx99GX4llPumDjgw+NIee7uCaRbrZkzluIhJYi2E0ZU2gb5OnYBTSJQMRfv91irmCz4KK
B5Va5J7T7IGjHnR22PeAd+m3F3KW/voz4BMFPGNgxHE0Loq65M6+Pw==


The md5sum is d392b0f5516033f2ae0985745f299efd.

Explanation

The numbers in the file are increments of relative atomic mass (so the relative atomic mass of lithium is 1.008 + 0 + 2.995 + 2.937).

This script works by converting the chemical formula into an arithmetical expression with + and *, replacing each symbol with its relative atomic mass, then feeding the expression to bc. If the formula contains invalid symbols, bc will give a syntax error and output nothing to STDOUT; in that case, the output is Invalid formula.

If STDIN is empty, the output is 0. Nested brackets are supported.

zcat y&gt;g 2&gt;a # Unzip the file y and output result to the file g. Send standard error to file a (there will be an error because the last 8 bytes are missing)
s=(`sed 's/[A-Z][a-z]*/&amp; /g;q'&lt;g`)  # Read from g to sed; append a space after any capital letter optionally followed by a lowercase letter; exit at the end of the first line so the atomic masses are not processed in this way; parse result as space-separated array and save to variable $s
p=1.008 # In the upcoming loop, $p is the value obtained in the previous iteration
v=`sed 's/[0-9]\+/*&amp;/g;s/(/+(0/g'` # Read from standard input to sed; prepend a * after any sequence of digits; replace ( with +(0; save to $v
r=(`tail -1 g`) # Get the last line of file g; parse as space-separated array; save to $r
for n in {0..91};{ # Loop once for each number from 0 to 91; set $n to the current number each iteration
p=`bc&lt;&lt;&lt;$p+${r[n]}` # Concatenate $p, + and the next number from $r; send to bc and evaluate as arithmetic expression; save to $p (i.e. add the next increment from the file to $p)
v=${v//${s[n]}/+$p} # Replace every occurence of the current element symbol with + and $p (i.e. replace each symbol with a + and its relative atomic mass
} # end loop
o=`bc&lt;&lt;&lt;0$v 2&gt;a` # Prepend 0 to $v; send to bc and evaluate as arithmetic expression; redirect any errors on standard error to the file a; save result to $o
echo ${o:-Invalid formula} # If $o is empty (if there was a syntax error), output Invalid formula; otherwise output $o


Example

C6H2(NO2)3CH3  #input
C*6H*2+(0NO*2)*3CH*3  #after line 3
+12.011*6+*1.008*2+(0+14.007+15.999*2)*3+12.011+1.008*3  #after the loop in lines 4-6
0+12.011*6+*1.008*2+(0+14.007+15.999*2)*3+12.011+1.008*3  #given to bc in line 7
227.132 #output as evaluated by bc