Skip to content

Commit be8a11b

Browse files
committed
add mass fraction scripting routine from APS user e-mail (see #272)
1 parent 1df32ee commit be8a11b

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

.notes/.linenoteplus

Lines changed: 0 additions & 5 deletions
This file was deleted.

GSASII/GSASIIscriptable.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4518,6 +4518,40 @@ def calc_autobkg(self,opt=0,logLam=None):
45184518
bkgDict['autoPrms']['Mode'] = 'fixed'
45194519
return bkgdata
45204520

4521+
def ComputeMassFracs(self):
4522+
'''Computes the mass fractions (or equivalently the weight fractions)
4523+
for the phases linked to the current histogram with uncertainties
4524+
from the results of the last refinement, if the phase fractions
4525+
were refined.
4526+
4527+
:returns: a dict where the keys are phase names and the values
4528+
associated with is a tuple where the first value is the phase's
4529+
mass fraction and the second value is the s.u. on that value.
4530+
'''
4531+
errmsg, warnmsg = G2stIO.ReadCheckConstraints(self.proj.filename)
4532+
if errmsg:
4533+
G2fil.G2Print('Constraint error',errmsg)
4534+
print('ComputeMassFracs warning: uncertainties are likely wrong')
4535+
# if warnmsg:
4536+
# G2fil.G2Print('\nNote these constraint warning(s):\n'+warnmsg)
4537+
# G2fil.G2Print('Generated constraints\n'+G2mv.VarRemapShow([],True))
4538+
covMatrix = self.proj.data['Covariance']['data']['covMatrix']
4539+
varyList = self.proj.data['Covariance']['data']['varyList']
4540+
hId = self.data['data'][0]['hId']
4541+
# make a dict like the Phases dict that the GUI uses
4542+
Phases = {}
4543+
for phase in self.proj.phases():
4544+
Phases[phase.name] = phase.data
4545+
hist = self.name
4546+
from . import GSASIIstrMath
4547+
valDict,sigDict = GSASIIstrMath.calcMassFracs(varyList,covMatrix,Phases,hist,hId)
4548+
vals = {}
4549+
# reformulate the dict to be {phase-name:(val,su)}
4550+
for key in valDict:
4551+
phase = self.proj.phase(key.split(':')[0]).name
4552+
vals[phase] = (float(valDict[key]),float(sigDict[key]))
4553+
return vals
4554+
45214555
class G2Phase(G2ObjectWrapper):
45224556
"""A wrapper object around a given phase.
45234557
The object contains these class variables:

docs/source/GSASIIscriptable.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,9 @@ Scripting class name Description
206206

207207
:ref:`G2PDF <Class_G2PDF>` :class:`~GSASIIscriptable.G2PDF`: PDF histogram info
208208

209-
:ref:`G2SmallAngle <Class_G2SmallAngle>` :class:`~GSASIIscriptable.G2SmallAngle`: Small Angle scattering histogram info
209+
:ref:`G2SmallAngle <Class_G2SmallAngle>` :class:`~GSASIIscriptable.G2SmallAngle`: Small Angle scattering histogram info
210210

211-
:ref:`G2SeqRefRes <Class_G2SeqRefRes>` :class:`~GSASIIscriptable.G2SeqRefRes`:
212-
The sequential results table
211+
:ref:`G2SeqRefRes <Class_G2SeqRefRes>` :class:`~GSASIIscriptable.G2SeqRefRes`: The sequential results table
213212
======================================== ===============================================================================================================
214213

215214
Independent Functions
@@ -377,6 +376,7 @@ method Use
377376
:meth:`~GSASIIscriptable.G2PwdrData.Export_peaks` Writes the peak parameters to a text file
378377
:meth:`~GSASIIscriptable.G2PwdrData.Limits` Reads or sets the region of data used in fitting (histogram limits)
379378
:meth:`~GSASIIscriptable.G2PwdrData.Excluded` Reads or sets regions of powder data that will be ignored
379+
:meth:`~GSASIIscriptable.G2PwdrData.ComputeMassFracs` Reports mass (weight) fractions and their uncertainties
380380
======================================================= ===============================================================================================================
381381

382382
.. _Class_G2Single:

0 commit comments

Comments
 (0)