## Oxygen by stoichiometry

Using the asoxide(...) and obystoichiometry(...) functions

using NeXLCore

Start with a measured dictionary of mass fractions and use the function obystoichiometry(...) to calculate the mass fraction of oxygen (using the default set of valences.)

measured = Dict(n"Al"=>0.06986, n"Si"=>0.042324, n"Ca"=>0.063917, n"Ti"=>0.072963, n"Zn"=>0.11421, n"Ge"=>0.317435)
measured[n"O"] = obystoichiometry(measured)
0.35244186490890517
material("ADM-65005a",measured)
ADM-65005a[Ti=0.0730,Al=0.0699,Ge=0.3174,Ca=0.0639,Zn=0.1142,Si=0.0423,O=0.
3524]

The variable NeXLCore.valences contains the default valences. Copy it and then edit it to use different assumptions.

altvalences = [ NeXLCore.defaultValences... ]
altvalences[z(n"Fe")] = 3
3

In one case, FeO, and in the other Fe<sub>2</sub>O<sub>3</sub>.

( asoxide(n"Fe"), asoxide(n"Fe",valences=altvalences) )
(FeO[Fe=0.7773,O=0.2227], Fe₂O₃[Fe=0.6994,O=0.3006])

You can add a similar argument to obystoichiometry(...) also.

There is a second usage of asoxide(...) when a dictionary is provided. This calculates a mixture of oxides from the mass fraction of each constituent oxide. The results is a dictionary that maps the oxide to the mass-fractions of that oxide. This is intended to be used when you have measured the mass fraction of all elements except O and want to know how much oxygen is in the sample.

asoxide(n"Al"=>0.0491,n"Ca"=>0.1090,n"Fe"=>0.0774,n"Mg"=>0.1166,n"Si"=>0.2120)
Dict{Material, AbstractFloat} with 5 entries:
SiO₂[O=0.5326,Si=0.4674]  => 0.453537
MgO[Mg=0.6030,O=0.3970]   => 0.193353
Al₂O₃[Al=0.5293,O=0.4707] => 0.0927716
FeO[Fe=0.7773,O=0.2227]   => 0.0995742
CaO[Ca=0.7147,O=0.2853]   => 0.152512

The result may be passed to the sum(...) function to produce a Material datum.

k412=sum(asoxide(n"Al"=>0.0491,n"Ca"=>0.1090,n"Fe"=>0.0774,n"Mg"=>0.1166,n"Si"=>0.2120), name="K412")
k411=sum(asoxide(n"Mg"=>0.0885,n"Si"=>0.2538,n"Ca"=>0.1106,n"Fe"=>0.1122), name="K411")
ENV["Columns"]=160
using DataFrames
vcat(asa(DataFrame, k411),asa(DataFrame, k412))
11×7 DataFrame
Row │ Material  Element  Z      A        C(z)      Norm[C(z)]  A(z)
│ String    String   Int64  Float64  Float64   Float64     Float64
─────┼────────────────────────────────────────────────────────────────────
1 │ K411      O            8  15.999   0.423712   0.428506   0.602854
2 │ K411      Mg          12  24.305   0.0885     0.0895014  0.0828862
3 │ K411      Si          14  28.085   0.2538     0.256672   0.205708
4 │ K411      Ca          20  40.0784  0.1106     0.111851   0.0628173
5 │ K411      Fe          26  55.8452  0.1122     0.11347    0.0457342
6 │ K412      O            8  15.999   0.427648   0.431206   0.59398
7 │ K412      Mg          12  24.305   0.1166     0.11757    0.106606
8 │ K412      Al          13  26.9815  0.0491     0.0495085  0.0404383
9 │ K412      Si          14  28.085   0.212      0.213764   0.167741
10 │ K412      Ca          20  40.0784  0.109      0.109907   0.0604358
11 │ K412      Fe          26  55.8452  0.0774     0.078044   0.0307988
asa(DataFrame, [k411, k412] )
2×8 DataFrame
Row │ Material  O          Mg         Al         Si         Ca         Fe
Total
│ String    Abstract…  Abstract…  Abstract…  Abstract…  Abstract…  Abs
tract…  Abstract…
─────┼─────────────────────────────────────────────────────────────────────
──────────────────
1 │ K411       0.423712     0.0885     0.0        0.2538     0.1106
0.1122   0.988812
2 │ K412       0.427648     0.1166     0.0491     0.212      0.109
0.0774   0.991748