Author Topic: A different way to estimate H2O mass fraction  (Read 155 times)

Brian Joy

  • Professor
  • ****
  • Posts: 170
A different way to estimate H2O mass fraction
« on: October 09, 2020, 02:08:39 pm »
Hi John,

Here is a continuation of our discussion yesterday regarding estimation of mass fraction H2O:

It's awkward to have to add OH- or molecular H2O to a mineral by specifying a molar ratio of hydrogen to oxygen or some other element.  The much easier, efficient, reliable, AND intuitive way to do it is simply to give some information on the chosen formula unit and apply this within the recursive algorithm used to determine the matrix correction factors.  The method can be applied to any mineral or other compound that contains OH- with or without substitution by F- and/or Cl- and with or without molecular H2O.

First I run a program to help me construct a settings file (here for amphibole analyses) that contains information on the X-ray line used, accelerating potential, count rates on the standards, and all other information required to process the X-ray data.  In order to do this, it first reads some files output by the JEOL PC-EPMA software.  I specify information on the formula unit as follows:



When I run my program to process the raw X-ray data, here is the result:



The elements are specified by atomic number on the left-hand side.  Note that I never had to specify a ratio of hydrogen to oxygen -- it was specified automatically in accordance with the chosen formula unit after subtraction of F- and Cl-.  For an amphibole, as long as you have reason to believe that no significant O2- substitutes for OH- on the monvalent anion site, then it's reasonable to assume that the molar OH- content of the amphibole is equal to 2 - nF- - nCl- after normalization to 23 anhydrous oxygens (or total anion charge = 46).  This should be true regardless of any other assumptions that have been made about the formula unit regarding, for instance, distribtion of Na across the M4 and A sites and its effect on Fe2O3/FeO (which would in turn affect the matrix correction factors for F and Cl, among other things).  In this case, the amphibole comes from a graphite-bearing metamorphic rock and likely grew at temperature in the vicinity of 800°C, and so Fe2O3 content is likely very low.

Also, note that the apfu sum of atomic numbers 1, 9, and 17 is exactly two.

Lastly, shame on you people who don't analyze for halogens in amphiboles!  Here’s what another 51-year-old Brian has to say about it:  https://www.youtube.com/watch?v=n4bply6Ibqw
Brian Joy
Queen's University
Kingston, Ontario
JEOL JXA-8230

Probeman

  • Emeritus
  • *****
  • Posts: 2079
  • Never sleeps...
    • John Donovan
Re: A different way to estimate H2O mass fraction
« Reply #1 on: October 09, 2020, 02:50:52 pm »
Firstly this is awesome. Thank-you. 

Secondly, if you send me the FORTAN code I will try to implement it in PFE and CalcZAF.

Thirdly, who doesn't analyze halogens in amphiboles?
The only stupid question is the one not asked!

Brian Joy

  • Professor
  • ****
  • Posts: 170
Re: A different way to estimate H2O mass fraction
« Reply #2 on: October 09, 2020, 03:43:41 pm »
Thirdly, who doesn't analyze halogens in amphiboles?

I'm continually shocked at how often people request that I "ignore" halogens in amphiboles.  Instead I ignore the request and analyze for halogens as a matter of course (obviously).

Let me pick through my code over the weekend, and I'll get back to you with some thoughts on how to implement my method in PFE.
Brian Joy
Queen's University
Kingston, Ontario
JEOL JXA-8230

John Donovan

  • Administrator
  • Emeritus
  • *****
  • Posts: 2631
  • Other duties as assigned...
    • Probe Software
Re: A different way to estimate H2O mass fraction
« Reply #3 on: October 09, 2020, 09:11:17 pm »
Thirdly, who doesn't analyze halogens in amphiboles?

I'm continually shocked at how often people request that I "ignore" halogens in amphiboles.  Instead I ignore the request and analyze for halogens as a matter of course (obviously).

Let me pick through my code over the weekend, and I'll get back to you with some thoughts on how to implement my method in PFE.

Hi Brian,
So I assume that we'll be calling this new code similarly to how we already calculate excess oxygen from ferric iron (i.e., by formula charge balance), once again from inside the matrix iteration loop, but this time we're calculating the OH or H2O based on the measured cations and halogens? So the user input will be a mineral formula, to be utilized with these measured molar fractions?
john
John J. Donovan, Pres. 
(541) 343-3400

"Not Absolutely Certain, Yet Reliable"

Brian Joy

  • Professor
  • ****
  • Posts: 170
Re: A different way to estimate H2O mass fraction
« Reply #4 on: October 10, 2020, 12:50:51 am »
So I assume that we'll be calling this new code similarly to how we already calculate excess oxygen from ferric iron (i.e., by formula charge balance), once again from inside the matrix iteration loop, but this time we're calculating the OH or H2O based on the measured cations and halogens? So the user input will be a mineral formula, to be utilized with these measured molar fractions?
john

Hi John,

That's exactly right.

For the case of an amphibole, for instance, you could even specify constraints on site occupancies and thus get an estimate of Fe2O3/FeO simultaneously with the estimate of wt% H2O.  For instance, for the amphibole analysis that I posted above, I know that it experienced metamorphism at high temperature and low pressure, and so it might be reasonable to assume that all Na+ resides on the A site, i.e., sum cations minus (Na+ + K+) equals 15 (per 23 anhydrous oxygens).  This recalculation results in an increase in the number of cations per formula unit relative to the case in which some or all Na+ resides on M4, and so it also results in a lower recalculated value of Fe2O3/FeO.

But an easier example is apatite.  As long as no C4+ subsitutes for P5+ (the case of "carbonate-apatite"), the user could simply specify the presence of 12.5 anhydrous oxygens (i.e., anion charge = 25) and the presence of one monovalent anion site and thus find nOH- = 1 - nF- - nCl- (and then calculate wt% H2O from nOH- for that iteration).  In the case of carbonate-apatite, wt% F can exceed the value for end-member fluorapatite.  For instance, the presence of CO2 has been reported in Durango apatite (I forget the references).

It's easy to specify a number of H2O molecules as well.  For the case of lawsonite, for instance, both OH- and molecular H2O are present.  In the prompts within my program that creates the settings file, I describe how to handle this particular case (though my directions to myself look a little convoluted).

Note that some of these recalculations have to be applied with care, but, as long as care is taken, these and a variety of others can be performed in automated fashion within the iterations required to determine the matrix correction factors.  For instance, you could apply a totally analogous technique to estimate wt% CO2 in a carbonate, wt% B2O3 in a borate, or whatever oxide or element in whatever compound and also account for substitution by some measurable cation or anion (like Al3+ for B3+.  It can all be done within the recursive algorithm simply by applying some restrictions based on the user-chosen formula unit.

I've been meaning to revise my program to handle easily generalizable cases and also more specific cases (like amphibole), but this will require a serious restructuring of the code and construction of a "library" of templates and specific cases.  Like I said, I'll have a look at my code at some point during the long weekend (Canadian Thanksgiving) -- or maybe you already see an easy way to implement the generalizable and specific cases in your code (which I haven't looked at in a while).
Brian Joy
Queen's University
Kingston, Ontario
JEOL JXA-8230

Brian Joy

  • Professor
  • ****
  • Posts: 170
Re: A different way to estimate H2O mass fraction
« Reply #5 on: October 15, 2020, 02:38:57 pm »
Hi John,

I sat down with the goal of extracting the code that I use to determine wt% H2O after considering substitution of F- and Cl- for OH-.  What I discovered instead is that my code, as it exists, could be organized much better and could also be generalized a bit.  So it’s clear to me that I need to rewrite some of my code before presenting it to anyone.  I’m going to do this over the next several weeks as I get the chance.

Let me just restate my purpose as clearly as possible first: 

The goal is to determine wt% H2O and/or wt% oxides of other light, unmeasured elements and/or Fe2O3/FeO using just a few pieces of information on the formula unit.  The calculations are performed during each iteration of the recursive algorithm used to determine the matrix correction factors such that the matrix corrections take into account the unmeasured elements/oxides and/or added oxygen and, if applicable, the mass of oxygen replaced by halogens.

For the general case, cation site assignments are ignored.  The following information is required from the user:
1.  Total number of anhydrous oxygens per formula unit (counting each monovalent ion as being equal to ½ O2- and ignoring molecular H2O).
2.  Number of monovalent anions (OH-, F-, Cl-) per formula unit, if applicable.
3.  Additional oxide mass fractions to be determined by specifying a number of cations per formula unit (if applicable):  H2O not accounted for in (1), Li2O, BeO, B2O3, CO2, N2O5.  More than one may be chosen.
4.  Total number of cations per formula unit (only necessary for determination of Fe2O3/FeO)
5.  If a measured element substitutes for an element in the oxides listed in (3), then the user may specify the substituting measured element and the light, unmeasured element for which it substitutes.  For the general case, it may be necessary to specify that all of the given measured element substitutes for just one of the light elements (I need to think about this some more).

In cases in which it is appropriate, the general treatment above can be replaced by one in which cations are restricted to specific sites.  The goals are the same as for the general case.  For an amphibole, for instance, a formula unit can be calculated based on the following assumptions, each of which must be tested to determine whether it violates restrictions on site occupancies:
1.  All Fe is present as FeO.
2.  Sum of cations excluding K+ equals 15.  This places all Na+ on M4, results in a relatively small number of cations per formula unit (which can vary between 15 and 16 per 23 anhydrous oxygens), and tends to place an upper limit on Fe2O3/FeO (if this recalculation is stoichiometrically allowable).
3.  Sum of cations excluding K+ and Na+ equals 15.  This places all Na+ on A, results in a relatively large number of cations per formula unit, and places a lower limit on Fe2O3/FeO if assumption (1) violates restrictions on site occupancies.
4.  Sum of cations excluding K+, Na+, and Ca2+ equals 13.  This allows Na+ on both M4 and A.
For the case of an amphibole, it might be possible to specify an amount of O2- that substitutes on the nominally monovalent anion site, but this would have to be known independently.  Again, each case listed above must be tested for violations of restrictions on site occupancies.

I should point out that, especially when considering recalculation for Fe2O3/FeO, error in all measured elements should be propagated through the calculation (see, for instance, Giaramita and Day, 1990, Am Min 75:170-182).  If the mineral or synthetic compound is a silicate, then, since Si4+ has a relatively high charge, imprecision and inaccuracy in wt% SiO2 in particular will have a large effect on recalculated Fe2O3/FeO.

OK, now I need to figure out how all of this should be coded (better)!  I welcome comments from anyone on what I've outlined above.

Brian

« Last Edit: October 15, 2020, 02:45:31 pm by Brian Joy »
Brian Joy
Queen's University
Kingston, Ontario
JEOL JXA-8230

John Donovan

  • Administrator
  • Emeritus
  • *****
  • Posts: 2631
  • Other duties as assigned...
    • Probe Software
Re: A different way to estimate H2O mass fraction
« Reply #6 on: October 16, 2020, 04:54:13 pm »
Hi John,

I sat down with the goal of extracting the code that I use to determine wt% H2O after considering substitution of F- and Cl- for OH-.  What I discovered instead is that my code, as it exists, could be organized much better and could also be generalized a bit.  So it’s clear to me that I need to rewrite some of my code before presenting it to anyone.  I’m going to do this over the next several weeks as I get the chance.

Let me just restate my purpose as clearly as possible first: 

The goal is to determine wt% H2O and/or wt% oxides of other light, unmeasured elements and/or Fe2O3/FeO using just a few pieces of information on the formula unit.  The calculations are performed during each iteration of the recursive algorithm used to determine the matrix correction factors such that the matrix corrections take into account the unmeasured elements/oxides and/or added oxygen and, if applicable, the mass of oxygen replaced by halogens.

For the general case, cation site assignments are ignored.  The following information is required from the user:
1.  Total number of anhydrous oxygens per formula unit (counting each monovalent ion as being equal to ½ O2- and ignoring molecular H2O).
2.  Number of monovalent anions (OH-, F-, Cl-) per formula unit, if applicable.
3.  Additional oxide mass fractions to be determined by specifying a number of cations per formula unit (if applicable):  H2O not accounted for in (1), Li2O, BeO, B2O3, CO2, N2O5.  More than one may be chosen.
4.  Total number of cations per formula unit (only necessary for determination of Fe2O3/FeO)
5.  If a measured element substitutes for an element in the oxides listed in (3), then the user may specify the substituting measured element and the light, unmeasured element for which it substitutes.  For the general case, it may be necessary to specify that all of the given measured element substitutes for just one of the light elements (I need to think about this some more).

In cases in which it is appropriate, the general treatment above can be replaced by one in which cations are restricted to specific sites.  The goals are the same as for the general case.  For an amphibole, for instance, a formula unit can be calculated based on the following assumptions, each of which must be tested to determine whether it violates restrictions on site occupancies:
1.  All Fe is present as FeO.
2.  Sum of cations excluding K+ equals 15.  This places all Na+ on M4, results in a relatively small number of cations per formula unit (which can vary between 15 and 16 per 23 anhydrous oxygens), and tends to place an upper limit on Fe2O3/FeO (if this recalculation is stoichiometrically allowable).
3.  Sum of cations excluding K+ and Na+ equals 15.  This places all Na+ on A, results in a relatively large number of cations per formula unit, and places a lower limit on Fe2O3/FeO if assumption (1) violates restrictions on site occupancies.
4.  Sum of cations excluding K+, Na+, and Ca2+ equals 13.  This allows Na+ on both M4 and A.
For the case of an amphibole, it might be possible to specify an amount of O2- that substitutes on the nominally monovalent anion site, but this would have to be known independently.  Again, each case listed above must be tested for violations of restrictions on site occupancies.

I should point out that, especially when considering recalculation for Fe2O3/FeO, error in all measured elements should be propagated through the calculation (see, for instance, Giaramita and Day, 1990, Am Min 75:170-182).  If the mineral or synthetic compound is a silicate, then, since Si4+ has a relatively high charge, imprecision and inaccuracy in wt% SiO2 in particular will have a large effect on recalculated Fe2O3/FeO.

OK, now I need to figure out how all of this should be coded (better)!  I welcome comments from anyone on what I've outlined above.

Brian

Hi Brian,
I would be more interested in implementing a general solution that is not dependent on the site occupancy, but relies merely on the mineral formula and the measured elements.

Do you think it would be worthwhile to implement such a method that only asks the user to specify the complete formula (including molecular H2O) and then from the measured cations (and measured halogen anions), then proceed to calculate the total H2O and OH using charge balance considerations?
john
« Last Edit: October 16, 2020, 05:16:35 pm by John Donovan »
John J. Donovan, Pres. 
(541) 343-3400

"Not Absolutely Certain, Yet Reliable"

Brian Joy

  • Professor
  • ****
  • Posts: 170
Re: A different way to estimate H2O mass fraction
« Reply #7 on: October 17, 2020, 12:13:44 am »
Do you think it would be worthwhile to implement such a method that only asks the user to specify the complete formula (including molecular H2O) and then from the measured cations (and measured halogen anions), then proceed to calculate the total H2O and OH using charge balance considerations?

Yes, I think that's a good way to proceed in terms of user-friendliness.  Probably the easiest way to implement your method would be to have a list of named mineral formula units from which the user could choose.  For instance, an entry could be "Tourmaline:  (Na,K,Ca)M3Al6(Si6O18)(BO3)3(OH,F,Cl)4, where M = Mg, Fe, Mn, Li, Al."  The program could then calculate wt% B2O3 and wt% H2O after subtraction of F- and Cl- from OH-.  In this and in many other cases, it might be necessary to assume that all Fe is present as FeO (or allow the user to choose Fe2O3/FeO).  The user would have to specify the number of Li apfu (if necessary, as it may well be), and then the program could also calculate wt% Li2O (or the user could provide a fixed wt% Li2O).

Now that I read what I just wrote, the above is exactly why I tend to gravitate toward a more general approach (and selected specific cases), as hydrous minerals can be complicated.
« Last Edit: October 17, 2020, 12:42:35 am by Brian Joy »
Brian Joy
Queen's University
Kingston, Ontario
JEOL JXA-8230

John Donovan

  • Administrator
  • Emeritus
  • *****
  • Posts: 2631
  • Other duties as assigned...
    • Probe Software
Re: A different way to estimate H2O mass fraction
« Reply #8 on: October 17, 2020, 09:43:54 am »
Do you think it would be worthwhile to implement such a method that only asks the user to specify the complete formula (including molecular H2O) and then from the measured cations (and measured halogen anions), then proceed to calculate the total H2O and OH using charge balance considerations?

Yes, I think that's a good way to proceed in terms of user-friendliness.  Probably the easiest way to implement your method would be to have a list of named mineral formula units from which the user could choose.  For instance, an entry could be "Tourmaline:  (Na,K,Ca)M3Al6(Si6O18)(BO3)3(OH,F,Cl)4, where M = Mg, Fe, Mn, Li, Al."  The program could then calculate wt% B2O3 and wt% H2O after subtraction of F- and Cl- from OH-.  In this and in many other cases, it might be necessary to assume that all Fe is present as FeO (or allow the user to choose Fe2O3/FeO).  The user would have to specify the number of Li apfu (if necessary, as it may well be), and then the program could also calculate wt% Li2O (or the user could provide a fixed wt% Li2O).

Now that I read what I just wrote, the above is exactly why I tend to gravitate toward a more general approach (and selected specific cases), as hydrous minerals can be complicated.

Ha!  Exactly yes. That is why I suggested just using a mineral formula.

To help with this effort, here's some code I found (and modified) somewhere many years ago (can't remember where now), that takes a formula string and calculates the number of atoms of each element:

Code: [Select]
' (c) Copyright 1995-2020 by John J. Donovan
Option Explicit
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal
' in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
' copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
' FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
' IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Sub MWCalculate(astring As String, numelms As Integer, elems() As String, fatoms() As Single, weight As Single)
' Parse elements and calculate the molecular weight of the passed formula

ierror = False
On Error GoTo MWCalculateError

Dim i As Integer

Dim AtomName As String, AtomNum As Integer
Dim AtomWeight As Single, NumAtoms As Single
Dim MolFormula As String, MolWeight As Single

Dim BlockOn As Integer, BlockWeight As Single
Dim NumBlocks As Integer

Dim ElemFormula As String, MolPercent As String
Dim ElemKinds As Integer

Dim tstring As String, fstring As String

ReDim NumElems(1 To MAXELM%) As Integer
ReDim NumElemsInBlock(1 To MAXELM%) As Integer

' Check for blank string
fstring$ = astring$
If Trim$(fstring$) = vbNullString Then GoTo MWCalculateEmptyString
   
Do Until fstring$ = vbNullString
AtomName$ = vbNullString
AtomNum% = 0
NumAtoms! = 0
tstring$ = Left$(fstring$, 1)
   
' Select on each character
    Select Case tstring$
   
' Alphabetic character
    Case "A" To "Z", "a" To "z"
      AtomName$ = UCase$(tstring$)
      fstring$ = Mid$(fstring$, 2): tstring$ = Left$(fstring$, 1)
      If tstring$ >= "a" And tstring$ <= "z" Then
        AtomName$ = AtomName$ & tstring$
      End If
      For i = MAXELM% To 1 Step -1
        If AtomName$ = RTrim$(Symup$(i%)) Then AtomNum% = i%: Exit For
      Next i%
      If AtomNum% = 0 Then
        If Len(AtomName$) = 2 Then
          AtomName$ = Left$(AtomName$, 1)
          For i% = MAXELM% To 1 Step -1
            If AtomName$ = RTrim$(Symup$(i%)) Then AtomNum% = i%: Exit For
          Next i%
          If AtomNum% = 0 Then GoTo MWCalculateNoElement
        Else
          GoTo MWCalculateNoElement
        End If
      Else
        If Len(AtomName$) = 2 Then fstring$ = Mid$(fstring$, 2)
      End If
      AtomWeight! = AllAtomicWts!(AtomNum%)
      NumAtoms! = MWNumber!(fstring$)
     
      ' Add in number of atoms
      If Not BlockOn% Then
        NumElems%(AtomNum%) = NumElems%(AtomNum%) + NumAtoms!
        MolWeight! = MolWeight! + AtomWeight! * NumAtoms!
       
      ' Add in number of atoms in block "()"
      Else
        BlockWeight! = BlockWeight! + AtomWeight! * NumAtoms!
        NumElemsInBlock%(AtomNum%) = NumElemsInBlock%(AtomNum%) + NumAtoms!
      End If
     
      If MolFormula$ <> vbNullString And Right$(MolFormula$, 1) <> "(" Then MolFormula$ = MolFormula$ + "-"
      MolFormula$ = MolFormula$ + AtomName$
      If NumAtoms! <> 1 Then MolFormula$ = MolFormula$ + LTrim$(Str$(NumAtoms!))
     
' Open parentheses
    Case "("
      If Not BlockOn% Then
        BlockOn% = True
        If MolFormula$ <> vbNullString Then MolFormula$ = MolFormula$ + "-"
        MolFormula$ = MolFormula$ + "("
        fstring$ = Mid$(fstring$, 2)
      Else
        GoTo MWCalculateSyntaxError
      End If
     
' Close parentheses
    Case ")"
      If BlockOn% Then
        BlockOn% = False
        fstring$ = Mid$(fstring$, 2)
        NumBlocks% = MWNumber!(fstring$)
        MolWeight! = MolWeight! + BlockWeight! * NumBlocks%
       
        ' Add in number of atoms in block
        For i% = 1 To MAXELM%
            NumElems%(i%) = NumElems%(i%) + NumElemsInBlock%(i%) * NumBlocks%
            NumElemsInBlock%(i%) = 0
        Next i%
       
        BlockWeight! = 0
        MolFormula$ = MolFormula$ + ")"
        If NumBlocks% <> 1 Then MolFormula$ = MolFormula$ + LTrim$(Str$(NumBlocks%))
      Else
        GoTo MWCalculateSyntaxError
      End If
     
' Delimiters
    Case " ", "-", "_", ",", ";": fstring$ = Mid$(fstring$, 2)
   
' All other
    Case Else
      GoTo MWCalculateSyntaxError
    End Select

Loop

' Load return arrays
  If MolFormula$ <> vbNullString Then
    ElemFormula$ = vbNullString
    MolPercent$ = vbNullString
    ElemKinds% = 0
    For i% = MAXELM% To 1 Step -1   ' start from high atomic numbers
      If NumElems%(i%) <> 0 Then
        ElemFormula$ = ElemFormula$ + RTrim$(Symup$(i%))
        If NumElems%(i%) <> 0 Then ElemFormula$ = ElemFormula$ + LTrim$(Str$(NumElems%(i%)))
        If MolPercent$ <> vbNullString Then MolPercent$ = MolPercent$ + "  "
        MolPercent$ = MolPercent$ + RTrim$(Symup$(i%))
        MolPercent$ = MolPercent$ + Str$(CInt((AllAtomicWts!(i%) * NumElems%(i%) * 100 / MolWeight!) * 100) / 100) + "%"
        ElemKinds% = ElemKinds% + 1
       
        elems$(ElemKinds%) = Symup$(i%)
        fatoms!(ElemKinds%) = NumElems%(i%)
        If fatoms!(ElemKinds%) = 0# Then fatoms!(ElemKinds%) = 1#
       
      End If
    Next i%
  End If
 
' Check for elements
If ElemKinds% < 1 Then GoTo MWCalculateNoElements
   
' Return parameters
numelms% = ElemKinds%
weight! = MolWeight!

' DebugMode results
If DebugMode Then
msg$ = MolFormula$ & " = "
msg$ = msg$ & ElemFormula$ & " = "
msg$ = msg$ & Str$(MolWeight!) & "g/mol, "
msg$ = msg$ & MolPercent$
Call IOWriteLog(msg$)
End If
   
Exit Sub

' Errors
MWCalculateError:
MsgBox Error$, vbOKOnly + vbCritical, "MWCalculate"
ierror = True
Exit Sub

MWCalculateEmptyString:
msg$ = "Empty formula string"
MsgBox msg$, vbOKOnly + vbExclamation, "MWCalculate"
ierror = True
Exit Sub

MWCalculateNoElement:
msg$ = AtomName$ & " is not a valid element"
MsgBox msg$, vbOKOnly + vbExclamation, "MWCalculate"
ierror = True
Exit Sub

MWCalculateSyntaxError:
msg$ = tstring$ & " <- Syntax error!"
MsgBox msg$, vbOKOnly + vbExclamation, "MWCalculate"
ierror = True
Exit Sub

MWCalculateNoElements:
msg$ = "No elements found in string " & astring$
MsgBox msg$, vbOKOnly + vbExclamation, "MWCalculate"
ierror = True
Exit Sub

End Sub

Function MWNumber(cstring As String) As Single
' Convert numeric characters to value
Dim sString As String, tstring As String

ierror = False
On Error GoTo MWNumberError

  sString$ = vbNullString
  Do Until cstring$ = vbNullString
    tstring$ = Left$(cstring$, 1)
    Select Case tstring$
    Case "0" To "9", ".": sString$ = sString$ + tstring$: cstring$ = Mid$(cstring$, 2)
    Case Else: Exit Do
    End Select
  Loop
  If sString$ = vbNullString Then MWNumber! = 1 Else MWNumber! = Val(sString$)

Exit Function

' Errors
MWNumberError:
MsgBox Error$, vbOKOnly + vbCritical, "MWNumber"
ierror = True
Exit Function

End Function

It's pretty sophisticated in that it can handle subscripts and parentheses. It even can distinguish things like Co (cobalt) and CO (carbon monoxide) as long as you use capitalization properly.

You can play around with it using the formula entry methods in the main window of CalcZAF.  E.g.,:

« Last Edit: October 17, 2020, 09:58:23 am by John Donovan »
John J. Donovan, Pres. 
(541) 343-3400

"Not Absolutely Certain, Yet Reliable"

Brian Joy

  • Professor
  • ****
  • Posts: 170
Re: A different way to estimate H2O mass fraction
« Reply #9 on: October 17, 2020, 04:31:03 pm »
OK, but then how would you handle solid solutions, minerals that might or might not contain vacant sites, or formula units that have been entered incorrectly by the user?
Brian Joy
Queen's University
Kingston, Ontario
JEOL JXA-8230

John Donovan

  • Administrator
  • Emeritus
  • *****
  • Posts: 2631
  • Other duties as assigned...
    • Probe Software
Re: A different way to estimate H2O mass fraction
« Reply #10 on: October 17, 2020, 05:05:15 pm »
OK, but then how would you handle solid solutions, minerals that might or might not contain vacant sites, or formula units that have been entered incorrectly by the user?

I would tell them to contact someone who actually understands mineralogy programming like Brian Joy, Jullien Allaz or Andrew Locock!    :)

If the user enters the wrong mineral formula? Well, you know how it is: garbage in, garbage out! 

But now that I think about it, it might be worthwhile to provide a dropdown combo control so they can either select a pre-defined mineral formula or enter it manually themselves.  How does that sound?
« Last Edit: October 17, 2020, 06:14:18 pm by John Donovan »
John J. Donovan, Pres. 
(541) 343-3400

"Not Absolutely Certain, Yet Reliable"

John Donovan

  • Administrator
  • Emeritus
  • *****
  • Posts: 2631
  • Other duties as assigned...
    • Probe Software
Re: A different way to estimate H2O mass fraction
« Reply #11 on: October 18, 2020, 09:42:05 am »
I had to remind myself that this topic was an "offshoot" of another topic that was discussing a new vanadium silicate standard (cavansite) which contains molecular water:

https://probesoftware.com/smf/index.php?topic=1321.0

My original comment was that we should include the molecular water into the matrix calculation and when Matthew did that he found that the Ca and V concentrations changed by about 3 to 4%.  So it was worth including this water into the matrix correction.

This is pretty much similar to what we see when adding water by difference to hydrous alkali glasses as discussed here:

https://probesoftware.com/smf/index.php?topic=922.0

The point being that if we don't include the water by difference into the matrix correction, our concentrations of the other elements will be inaccurate and our water by difference will generally be low by 20 to 30% (relative) or more.

However, no question that there is value to actually calculating the water based on the cation/anion charge balance in minerals because we would then obtain a true analytical total, which we lose whenever we perform a "by difference" calculation.

So while I think the method to perform a formula charge balance calculation of H2O is worth some effort, whether the water is calculated by charge balance or by difference, the matrix effects on the other elements are roughly the same.

Now as to the value of calculating water for specific mineral species based on site occupancy and other complex mineral considerations, I as a non-geologist cannot speak to that and I defer to other experts.
« Last Edit: October 18, 2020, 09:58:43 am by John Donovan »
John J. Donovan, Pres. 
(541) 343-3400

"Not Absolutely Certain, Yet Reliable"

BenjaminWade

  • Professor
  • ****
  • Posts: 195
Re: A different way to estimate H2O mass fraction
« Reply #12 on: October 18, 2020, 06:08:38 pm »
I have been watching this topic, and can I just say, if this gets implemented, this will be totally awesome....

Cheers

Brian Joy

  • Professor
  • ****
  • Posts: 170
Re: A different way to estimate H2O mass fraction
« Reply #13 on: October 18, 2020, 07:25:23 pm »
Let me see what I can do.  I'll probably re-program it my way first, as what I've listed above is exactly what needs to be known from the user.  So, in other words, what I've listed is essentially what would need to be extracted from the character string entered by the user in CalcZAF/PFE.  I'll need to write a subroutine to read and interpret ASCII characters (with help from what John has posted on this) in order to extract that information and to flag certain obvious errors (like sum positive charges not equal to sum negative charges, missing parenthesis, etc.).

Each cation in the formula unit could have a default charge assigned to it, and then the user would be free to modify any given value.

In some cases, the distribution of cations across specific sites absolutely must be known.  The amphiboles are a good example.  Without knowledge of this distribution, which must be guided by some geologic insight (in addition to restrictions imposed by the formula unit), it is impossible to determine Fe2O3/FeO.  The practical consequence of this is that the subroutine I mentioned above would need to be able to recognize certain minerals based on characteristics of the formula unit.  This would then allow an appropriate model for the distribution of cations across the various sites to be applied.  If no appropriate model can be identified, then the user could choose to proceed based simply on general constraints.  I need to think about this some more.

In my personal opinion (for what it's worth), I think that every effort should be made to avoid having to rely on element or oxide by difference, regardless of the impact (or lack of it) on the matrix correction factors.
Brian Joy
Queen's University
Kingston, Ontario
JEOL JXA-8230

John Donovan

  • Administrator
  • Emeritus
  • *****
  • Posts: 2631
  • Other duties as assigned...
    • Probe Software
Re: A different way to estimate H2O mass fraction
« Reply #14 on: October 19, 2020, 10:41:07 am »
I agree that calculating water or hydroxl by charge balance/stocihiometry is more ideal than simply by calculating by difference and I understand the desire to include excess oxygen from ferric iron.

I'm thinking about the coding and user interface, and without knowing the mineralogical details, it's once again starting to sound to me that we would need a separate code or at least a separate user interface for each mineral species, and maybe even different code/UI for the varieties within a single species (e.g., amphibole varieties).  And also it's my impression that various investigators don't even agree on many of these chemical substitution details...

How does this sound: we have the user specify the charge for each element (as we already do in Probe for EPMA), then specify the mineral species formula (either by drop down list or text entry), and optionally they can also calculate excess oxygen from ferric iron using the method of Droop as described here in PFE:

https://probesoftware.com/smf/index.php?topic=92.msg8593#msg8593

Since both the excess oxygen from ferric iron, and the excess water by formula would be iterated within the matrix correction, there's a chance (I'm guessing) that it would all get calculated correctly.  What do you all think of this approach?

And while we're on the topic of minerals with water, have any of you tried the biotite or amphibole calculations in Probe for EPMA as described here:

https://probesoftware.com/smf/index.php?topic=1143.0

I know Dave Adams and Heather Lowers have utilized this output in the past. In fact within the last year or so Jay Ague (who wrote the original FORTRAN code when we were both at Berkeley many decades ago) had me make a minor change to the code in PFE, so I'm guessing they also still use it at Yale.

I'd be curious to know what people think of this output/code and whether it covers any of the issues we are looking at in this topic...
John J. Donovan, Pres. 
(541) 343-3400

"Not Absolutely Certain, Yet Reliable"