Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions GSASII/GSASIIconstrGUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ def CheckConstraints(G2frame,Phases,Histograms,data,newcons=[],reqVaryList=None,
# get Hist and HAP info
hapVary, hapDict, controlDict = G2stIO.GetHistogramPhaseData(Phases, Histograms, Print=False, resetRefList=False)
parmDict.update(hapDict)
histVary, histDict, controlDict = G2stIO.GetHistogramData(Histograms, Print=False)
histVary, histDict, histDict1, controlDict = G2stIO.GetHistogramData(Histograms, Print=False)
parmDict.update(histDict)

# TODO: twining info needed?
Expand Down Expand Up @@ -1659,7 +1659,7 @@ def OnShowISODISTORT(event):
hapList += wildList
else:
hapList = wildList
histVary,histDict,controlDict = G2stIO.GetHistogramData(histDict,Print=False)
histVary,histDict,histDict1,controlDict = G2stIO.GetHistogramData(histDict,Print=False)
histList = list(histDict.keys())
histList.sort()
if seqHistList: # convert histogram # to wildcard
Expand Down
2 changes: 1 addition & 1 deletion GSASII/GSASIIdataGUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -5179,7 +5179,7 @@ def MakeLSParmDict(self,seqHist=None):
Natoms,atomIndx,phaseVary,phaseDict,pawleyLookup,FFtable,EFtable,ORBtables,BLtable,MFtable,maxSSwave = \
G2stIO.GetPhaseData(Phases,RestraintDict=None,rbIds=rbIds,Print=False)
hapVary,hapDict,controlDict = G2stIO.GetHistogramPhaseData(Phases,histDict,Print=False,resetRefList=False)
histVary,histDict,controlDict = G2stIO.GetHistogramData(histDict,Print=False)
histVary,histDict,histDict1, controlDict = G2stIO.GetHistogramData(histDict,Print=False)
varyList = rbVary+phaseVary+hapVary+histVary
parmDict.update(rbDict)
parmDict.update(phaseDict)
Expand Down
107 changes: 98 additions & 9 deletions GSASII/GSASIIfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,55 @@ def makeInstDict(names,data,codes):
inst[item] = list(inst[item])
return inst

def makePdabcDict(pdabcString):
'''
if a pdabc entry is found in an instprm file, it will exist as a single string
each row is delineated by a newline and must contains 5 comma separated values
specifying d,TOF,alp,bet,sig.

This function will parse that string into a dictionary and then return it within
a container dictionary
'''

if type(pdabcString) != str:
raise Exception("Error interpreting pdabc entry in .instprm file. Entry must be a string")

lines = pdabcString.split("\n")

if len(lines) == 0:
print("Warning: pdabc entry found in .instprm file is empty")
return {} #no information, return empty dict

#create empty lists to hold values
d = []
TOF = []
alp = []
bet = []
sig = []
nPdabc = 0
for line in lines:
if line: #skip empty lines
entry = line.split(",")
if len(entry) != 5:
raise Exception("Error interpreting pdabc entry in .instprm file. Entries must have exactly 5 comma separated values")
d.append(float(entry[0]))
TOF.append(float(entry[1]))
alp.append(float(entry[2]))
bet.append(float(entry[3]))
sig.append(float(entry[4]))
nPdabc += 1

pdabcDict = {
"d":d,
"TOF":TOF,
"alp":alp,
"bet":bet,
"sig":sig
}

print(f"PDABC entry found and {nPdabc} lines successfully loaded")
return {"pdabc":pdabcDict}

def SetPowderInstParms(Iparm, rd):
'''extracts values from instrument parameters in rd.instdict
or in array Iparm.
Expand Down Expand Up @@ -292,16 +341,21 @@ def SetPowderInstParms(Iparm, rd):
Inst1 = makeInstDict(names,data,codes)
Inst1['Bank'] = [Bank,Bank,0]
Inst2 = {}

if pfType < 0:
Ipab = 'INS 1PAB'+str(-pfType)
key = Ipab+' '
print("looking for key: ", key)
Npab = int(Iparm[Ipab+' '].strip())
Inst2['Pdabc'] = []
Inst2['pdabc'] = []
for i in range(Npab):
k = Ipab+str(i+1).rjust(2)
s = Iparm[k].split()
Inst2['Pdabc'].append([float(t) for t in s])
Inst2['Pdabc'] = np.array(Inst2['Pdabc'])
Inst2['Pdabc'].T[3] += Inst2['Pdabc'].T[0]*Inst1['difC'][0] #turn 3rd col into TOF
Inst2['pdabc'].append([float(t) for t in s])
Inst2['pdabc'] = np.array(Inst2['pdabc'])
Inst2['pdabc'].T[3] += Inst2['pdabc'].T[0]*Inst1['difC'][0] #turn 3rd col into TOF

print(f"loaded resolution data with {Inst2['pdabc'].shape} shape" )
if 'INS 1I ITYP' in Iparm:
s = Iparm['INS 1I ITYP'].split()
Ityp = int(s[0])
Expand Down Expand Up @@ -356,7 +410,8 @@ def ReadInstprm(instLines, bank, Sample={}):
determined by instrument settings or information
from the instprm file are placed here.
:returns: bank,instdict where bank is the sample parameter set
number and instdict is the instrument parameter dict
number and instdict is a list containing the regular instrument parameter dict
and the "extended" dict, currently only containing pdabc entries (if they exist)

Note if 'Type' is set as Debye-Scherrer or Bragg-Brentano this will be used and
will set defaults in the sample parameters. Otherwise, a single-wavelength file
Expand Down Expand Up @@ -461,21 +516,33 @@ def ReadInstprm(instLines, bank, Sample={}):
Sample.update({'Type':'Debye-Scherrer','Absorption':[0.,False],'DisplaceX':[0.,False],
'DisplaceY':[0.,False]})
Sample.update(NewSample)
return bank,[makeInstDict(newItems, newVals, len(newVals)*[False]), {}]

def WriteInstprm(fp, InstPrm, Sample={}, bank=None):
#if pdabc exists, process it, then delete from original lists
if "pdabc" in newItems:
idx = newItems.index('pdabc')
iparm1 = makePdabcDict(newVals[idx]) #returns new dictionary with pdabc data
del newItems[idx]
del newVals[idx]
else:
iparm1 = {}

return bank,[makeInstDict(newItems, newVals, len(newVals)*[False]), iparm1]

def WriteInstprm(fp, InstPrm, InstPrm1, Sample={}, bank=None):
'''Write the contents of a GSAS-II (new) .instprm instrument parameter file
ToDo: use this inside G2frame.OnSave and G2frame.OnSaveAll

:param file fp: Pointer to open file to be written.
:param dict InstPrm: Instrument parameters
:param dict InstPrm1: "extended" instrument parameters
:param dict Sample: Sample parameters (optional)
:param int bank: Bank number. If not None (default), this causes
a "#Bank" heading to be placed in the file before the
parameters are written.
'''
if bank is not None:
fp.write(f"#Bank {bank}: GSAS-II instrument parameter file; do not add/delete items!\n")
#somehow, somewhere bank is becoming a float. Ensure it is an int here:
fp.write(f"#Bank {int(bank)}: GSAS-II instrument parameter file; do not add/delete items!\n")
indent = ' '
else:
fp.write("#GSAS-II instrument parameter file; do not add/delete items!\n")
Expand All @@ -490,6 +557,28 @@ def WriteInstprm(fp, InstPrm, Sample={}, bank=None):
if not Sample.get(item): continue
fp.write(f"{indent}{item}:{Sample[item]}\n")

# handle pdabc entries.
if InstPrm1:
if "pdabc" in InstPrm1:

#extract lists from InstPrm1["pdabc"] dictionary
d = InstPrm1["pdabc"]["d"]
tof = InstPrm1["pdabc"]["TOF"]
alp = InstPrm1["pdabc"]["alp"]
bet = InstPrm1["pdabc"]["bet"]
sig = InstPrm1["pdabc"]["sig"]

#build output string
i = 0
resString = f"pdabc:\"\"\"{d[i]:.4f}, {tof[i]:8.1f}, {alp[i]:8.6f}, {bet[i]:8.6f}, {sig[i]:8.6f}\n"
for i in range(1,len(d)-1):
resString+=f"{d[i]:7.4f}, {tof[i]:8.1f}, {alp[i]:8.6f}, {bet[i]:8.6f}, {sig[i]:8.6f}\n"

resString+=f"{d[-1]:7.4f}, {tof[-1]:8.1f}, {alp[-1]:8.6f}, {bet[-1]:8.6f}, {sig[-1]:8.6f}\"\"\"\n"

#write output string
fp.write(resString)

# version of LoadImportRoutines from before switch to "main"
# def _old_LoadImportRoutines(prefix, errprefix=None, traceback=False):
# '''Routine to locate GSASII importers matching a prefix string.
Expand Down Expand Up @@ -1966,7 +2055,7 @@ def loadParmDict(self,computeSU=False):
self.parmDict.update(phaseDict)
hapVary,hapDict,controlDict = G2stIO.GetHistogramPhaseData(Phases,Histograms,Print=False,resetRefList=False)
self.parmDict.update(hapDict)
histVary,histDict,controlDict = G2stIO.GetHistogramData(Histograms,Print=False)
histVary,histDict,histDict1, controlDict = G2stIO.GetHistogramData(Histograms,Print=False)
self.parmDict.update(histDict)
self.parmDict.update(zip(
covDict.get('varyList',[]),
Expand Down
11 changes: 6 additions & 5 deletions GSASII/GSASIImath.py
Original file line number Diff line number Diff line change
Expand Up @@ -5123,18 +5123,19 @@ def setPeakparms(Parms,Parms2,pos,mag,ifQ=False,useFit=False):
pos = Parms['difC']*dsp
else:
dsp = pos/Parms['difC'][1]
if 'Pdabc' in Parms2:
if 'pdabc' in Parms2 and len(Parms2['pdabc']):
for x in ['sig-0','sig-1','sig-2','sig-q','X','Y','Z']:
ins[x] = Parms.get(x,[0.0,0.0])[ind]
Pdabc = Parms2['Pdabc'].T
alp = np.interp(dsp,Pdabc[0],Pdabc[1])
bet = np.interp(dsp,Pdabc[0],Pdabc[2])
Pdabc = Parms2['pdabc']
alp = np.interp(dsp,Pdabc['d'],Pdabc['alp'])
bet = np.interp(dsp,Pdabc['d'],Pdabc['bet'])
sig = np.interp(dsp,Pdabc['d'],Pdabc['sig'])
else:
for x in ['alpha','beta-0','beta-1','beta-q','sig-0','sig-1','sig-2','sig-q','X','Y','Z']:
ins[x] = Parms.get(x,[0.0,0.0])[ind]
alp = getTOFalpha(ins,dsp)
bet = getTOFbeta(ins,dsp)
sig = getTOFsig(ins,dsp)
sig = getTOFsig(ins,dsp)
gam = getTOFgamma(ins,dsp)
XY = [pos,0,mag,1,alp,0,bet,0,sig,0,gam,0]
elif 'C' in Parms['Type'][0] or 'LF' in Parms['Type'][0]:
Expand Down
2 changes: 1 addition & 1 deletion GSASII/GSASIImiscGUI.py
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,7 @@ def mkParmDictfromTree(G2frame,sigDict=None):
parmDict.update(phaseDict)
hapVary,hapDict,controlDict = G2stIO.GetHistogramPhaseData(Phases,Histograms,Print=False,resetRefList=False)
parmDict.update(hapDict)
histVary,histDict,controlDict = G2stIO.GetHistogramData(Histograms,Print=False)
histVary,histDict,histDict1, controlDict = G2stIO.GetHistogramData(Histograms,Print=False)
parmDict.update(histDict)
parmDict.update(zip(
covDict.get('varyList',[]),
Expand Down
Loading