@@ -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+
45214555class G2Phase (G2ObjectWrapper ):
45224556 """A wrapper object around a given phase.
45234557 The object contains these class variables:
0 commit comments