Changeset 443 for trunk/GSASIIpwd.py
- Timestamp:
- Dec 16, 2011 1:15:09 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIpwd.py
r432 r443 647 647 bakInt = si.interp1d(bakPos,bakVals,'linear') 648 648 yb = bakInt(xdata) 649 iD = 0 650 try: 651 wave = parmDict[pfx+'Lam'] 652 except KeyError: 653 wave = parmDict[pfx+'Lam1'] 654 q = 4.0*np.pi*npsind(xdata/2.0)/wave 655 SQ = (q/(4*np.pi))**2 656 FF = G2elem.GetFormFactorCoeff('Si')[0] 657 ff = np.array(G2elem.ScatFac(FF,SQ)[0])**2 658 while True: 659 try: 660 dbA = parmDict[pfx+'DebyeA:'+str(iD)] 661 dbR = parmDict[pfx+'DebyeR:'+str(iD)] 662 dbU = parmDict[pfx+'DebyeU:'+str(iD)] 663 yb += ff*dbA*np.sin(q*dbR)*np.exp(-dbU*q**2)/(q*dbR) 664 iD += 1 665 except KeyError: 666 break 649 667 return yb 650 668 … … 658 676 break 659 677 dydb = np.zeros(shape=(nBak,len(xdata))) 678 dyddb = np.zeros(shape=(3*parmDict[pfx+'nDebye'],len(xdata))) 660 679 661 680 if bakType in ['chebyschev','cosine']: … … 692 711 np.where(xdata<bakPos[i+1],(bakPos[i+1]-xdata)/(bakPos[i+1]-bakPos[i]),0.), 693 712 np.where(xdata>bakPos[i-1],(xdata-bakPos[i-1])/(bakPos[i]-bakPos[i-1]),0.)) 694 return dydb 713 iD = 0 714 try: 715 wave = parmDict[pfx+'Lam'] 716 except KeyError: 717 wave = parmDict[pfx+'Lam1'] 718 q = 4.0*np.pi*npsind(xdata/2.0)/wave 719 SQ = (q/(4*np.pi))**2 720 FF = G2elem.GetFormFactorCoeff('Si')[0] 721 ff = np.array(G2elem.ScatFac(FF,SQ)[0]) 722 while True: 723 try: 724 dbA = parmDict[pfx+'DebyeA:'+str(iD)] 725 dbR = parmDict[pfx+'DebyeR:'+str(iD)] 726 dbU = parmDict[pfx+'DebyeU:'+str(iD)] 727 sqr = np.sin(q*dbR)/(q*dbR) 728 cqr = np.cos(q*dbR) 729 temp = np.exp(-dbU*q**2) 730 dyddb[3*iD] = ff*sqr*temp 731 dyddb[3*iD+1] = ff*dbA*temp*(cqr-sqr)/dbR 732 dyddb[3*iD+2] = -ff*dbA*sqr*temp*q**2 733 iD += 1 734 except KeyError: 735 break 736 return dydb,dyddb 695 737 696 738 #use old fortran routine … … 790 832 # needs to return np.array([dMdx1,dMdx2,...]) in same order as varylist = backVary,insVary,peakVary order 791 833 dMdv = np.zeros(shape=(len(varyList),len(xdata))) 834 dMdb,dMddb = getBackgroundDerv('',parmDict,bakType,xdata) 792 835 if 'Back:0' in varyList: #background derivs are in front if present 793 dMdb = getBackgroundDerv('',parmDict,bakType,xdata)794 836 dMdv[0:len(dMdb)] = dMdb 795 837 names = ['DebyeA','DebyeR','DebyeU'] 838 for name in varyList: 839 if 'Debye' in name: 840 ih,parm,id = name.split(':') 841 ip = names.index(parm) 842 dMdv[varyList.index(name)] = dMddb[3*int(id)+ip] 796 843 dx = xdata[1]-xdata[0] 797 844 U = parmDict['U'] … … 901 948 902 949 def SetBackgroundParms(Background): 903 bakType,bakFlag = Background[:2] 904 backVals = Background[3:] 950 if len(Background) == 1: # fix up old backgrounds 951 BackGround.append({'nDebye':0,'debyeTerms':[]}) 952 bakType,bakFlag = Background[0][:2] 953 backVals = Background[0][3:] 905 954 backNames = ['Back:'+str(i) for i in range(len(backVals))] 906 if bakFlag: #returns backNames as varyList = backNames 907 return bakType,dict(zip(backNames,backVals)),backNames 908 else: #no background varied; varyList = [] 909 return bakType,dict(zip(backNames,backVals)),[] 955 Debye = Background[1] 956 backDict = dict(zip(backNames,backVals)) 957 backVary = [] 958 if bakFlag: 959 backVary = backNames 960 backDict['nDebye'] = Debye['nDebye'] 961 debyeDict = {} 962 debyeList = [] 963 for i in range(Debye['nDebye']): 964 debyeNames = ['DebyeA:'+str(i),'DebyeR:'+str(i),'DebyeU:'+str(i)] 965 debyeDict.update(dict(zip(debyeNames,Debye['debyeTerms'][i][::2]))) 966 debyeList += zip(debyeNames,Debye['debyeTerms'][i][1::2]) 967 debyeVary = [] 968 for item in debyeList: 969 if item[1]: 970 debyeVary.append(item[0]) 971 backDict.update(debyeDict) 972 backVary += debyeVary 973 return bakType,backDict,backVary 910 974 911 975 def GetBackgroundParms(parmList,Background): … … 914 978 try: 915 979 bakName = 'Back:'+str(iBak) 916 Background[ iBak+3] = parmList[bakName]980 Background[0][iBak+3] = parmList[bakName] 917 981 iBak += 1 982 except KeyError: 983 break 984 iDb = 0 985 while True: 986 names = ['DebyeA:','DebyeR:','DebyeU:'] 987 try: 988 for i,name in enumerate(names): 989 val = parmList[name+str(iDb)] 990 Background[1]['debyeTerms'][iDb][2*i] = val 991 iDb += 1 918 992 except KeyError: 919 993 break 920 994 921 995 def BackgroundPrint(Background,sigDict): 922 if Background[ 1]:923 print 'Background coefficients for',Background[0] ,'function'996 if Background[0][1]: 997 print 'Background coefficients for',Background[0][0],'function' 924 998 ptfmt = "%12.5f" 925 999 ptstr = 'values:' 926 1000 sigstr = 'esds :' 927 for i,back in enumerate(Background[ 3:]):1001 for i,back in enumerate(Background[0][3:]): 928 1002 ptstr += ptfmt % (back) 929 1003 sigstr += ptfmt % (sigDict['Back:'+str(i)]) … … 932 1006 else: 933 1007 print 'Background not refined' 934 1008 if Background[1]['nDebye']: 1009 parms = ['DebyeA','DebyeR','DebyeU'] 1010 print 'Debye diffuse scattering coefficients' 1011 ptfmt = "%12.5f" 1012 names = 'names :' 1013 ptstr = 'values:' 1014 sigstr = 'esds :' 1015 for item in sigDict: 1016 if 'Debye' in item: 1017 names += '%12s'%(item) 1018 sigstr += ptfmt%(sigDict[item]) 1019 parm,id = item.split(':') 1020 ip = parms.index(parm) 1021 ptstr += ptfmt%(Background[1]['debyeTerms'][int(id)][2*ip]) 1022 print names 1023 print ptstr 1024 print sigstr 1025 935 1026 def SetInstParms(Inst): 936 1027 insVals,insFlags,insNames = Inst[1:4]
Note: See TracChangeset
for help on using the changeset viewer.