Changeset 808
- Timestamp:
- Dec 5, 2012 10:06:52 AM (10 years ago)
- Location:
- trunk
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIgrid.py
r807 r808 14 14 import sys 15 15 import numpy as np 16 import numpy.ma as ma 16 17 import os.path 17 18 import wx.html # could postpone this for quicker startup … … 21 22 import GSASIImath as G2mth 22 23 import GSASIIIO as G2IO 24 import GSASIIlattice as G2lat 23 25 import GSASIIplot as G2plt 24 26 import GSASIIpwdGUI as G2pdG … … 26 28 import GSASIIphsGUI as G2phG 27 29 import GSASIIstruct as G2str 30 import GSASIIspc as G2spc 28 31 import GSASIImapvars as G2mv 29 32 … … 1385 1388 phaseList.sort() 1386 1389 phaseAtNames = {} 1390 phaseAtTypes = {} 1391 TypeList = [] 1387 1392 for item in phaseList: 1388 1393 Split = item.split(':') 1389 1394 if Split[2][:2] in ['AU','Af','dA']: 1390 phaseAtNames[item] = AtomDict[int(Split[0])][int(Split[3])][0] 1395 Id = int(Split[0]) 1396 phaseAtNames[item] = AtomDict[Id][int(Split[3])][0] 1397 phaseAtTypes[item] = AtomDict[Id][int(Split[3])][1] 1398 if phaseAtTypes[item] not in TypeList: 1399 TypeList.append(phaseAtTypes[item]) 1391 1400 else: 1392 1401 phaseAtNames[item] = '' 1402 phaseAtTypes[item] = '' 1393 1403 1394 1404 hapVary,hapDict,controlDict = G2str.GetHistogramPhaseData(Phases,Histograms,Print=False) … … 1452 1462 if page[1] == 'phs': 1453 1463 atchoice = [item+' for '+phaseAtNames[item] for item in varList] 1464 atchoice += [FrstVarb+' for all'] 1465 atchoice += [FrstVarb+' for all '+atype for atype in TypeList] 1454 1466 dlg = wx.MultiChoiceDialog(G2frame,'Select more variables:'+legend, 1455 1467 'Constrain '+FrstVarb+' and...',atchoice) … … 1460 1472 if dlg.ShowModal() == wx.ID_OK: 1461 1473 sel = dlg.GetSelections() 1462 for x in sel: 1463 varbs.append(varList[x]) 1474 try: 1475 for x in sel: 1476 varbs.append(varList[x]) 1477 except IndexError: # one of the 'all' chosen - supercedes any individual selection 1478 varbs = [FrstVarb,] 1479 Atypes = [] 1480 for x in sel: 1481 item = atchoice[x] 1482 if 'all' in item: 1483 Atypes.append(item.split('all')[1].strip()) 1484 if '' in Atypes: 1485 varbs += varList 1486 else: 1487 for item in varList: 1488 if phaseAtTypes[item] in Atypes: 1489 varbs.append(item) 1464 1490 dlg.Destroy() 1465 1491 if len(varbs) > 1: … … 1876 1902 if 'Chiral' not in restrData: 1877 1903 restrData['Chiral'] = {'wtFactor':1.0,'Volumes':[],'Use':True} 1904 General = phasedata['General'] 1905 Cell = General['Cell'][1:7] #skip flag & volume 1906 Amat,Bmat = G2lat.cell2AB(Cell) 1907 SGData = General['SGData'] 1908 cx,ct = General['AtomPtrs'][:2] 1909 Atoms = phasedata['Atoms'] 1910 AtLookUp = G2mth.FillAtomLookUp(Atoms) 1911 Names = ['all '+ name for name in General['AtomTypes']] 1912 iBeg = len(Names) 1913 Types = [name for name in General['AtomTypes']] 1914 Coords = [ [] for type in Types] 1915 Ids = [ 0 for type in Types] 1916 Names += [atom[ct-1] for atom in Atoms] 1917 Types += [atom[ct] for atom in Atoms] 1918 Coords += [atom[cx:cx+3] for atom in Atoms] 1919 Ids += [atom[-1] for atom in Atoms] 1878 1920 1879 1921 def OnSelectPhase(event): … … 1889 1931 page = G2frame.dataDisplay.GetSelection() 1890 1932 if 'Bond' in G2frame.dataDisplay.GetPageText(page): 1891 AddBondRestraint() 1933 bondRestData = restrData['Bond'] 1934 AddBondRestraint(bondRestData) 1892 1935 elif 'Angle' in G2frame.dataDisplay.GetPageText(page): 1893 AddAngleRestraint() 1936 angleRestData = restrData['Angle'] 1937 AddAngleRestraint(angleRestData) 1894 1938 elif 'Plane' in G2frame.dataDisplay.GetPageText(page): 1895 1939 AddPlaneRestraint() … … 1897 1941 AddChiralRestraint() 1898 1942 1899 def AddBondRestraint(): 1900 General = phasedata['General'] 1901 cx,ct = General['AtomPtrs'][:2] 1902 Atoms = phasedata['Atoms'] 1903 radiiDict = dict(zip(General['AtomTypes'],General['BondRadii'])) 1904 Names = ['all '+ name for name in General['AtomTypes']] 1905 Types = [name for name in General['AtomTypes']] 1906 Names += [atom[ct-1] for atom in Atoms] 1907 Types += [atom[ct] for atom in Atoms] 1943 def AddBondRestraint(bondRestData): 1944 Radii = dict(zip(General['AtomTypes'],General['BondRadii'])) 1908 1945 Lists = {'origin':[],'target':[]} 1909 1946 for listName in ['origin','target']: 1910 dlg = wx.MultiChoiceDialog(G2frame,'Bond restraint '+listName+' for '+General['Name'],1947 dlg = wx.MultiChoiceDialog(G2frame,'Bond restraint '+listName+' for '+General['Name'], 1911 1948 'Select bond restraint '+listName+' atoms',Names) 1912 1949 if dlg.ShowModal() == wx.ID_OK: 1913 1950 sel = dlg.GetSelections() 1914 1951 for x in sel: 1915 Lists[listName].append([Names[x],Types[x]]) 1916 SGData = General['SGData'] 1917 Bonds = restrData['Bond']['Bonds'] 1918 1919 def AddAngleRestraint(): 1920 print 'Angle restraint' 1952 if 'all' in Names[x]: 1953 allType = Types[x] 1954 for name,Type,coords,id in zip(Names,Types,Coords,Ids): 1955 if Type == allType and 'all' not in name: 1956 Lists[listName].append([id,Type,coords]) 1957 else: 1958 Lists[listName].append([Ids[x],Types[x],Coords[x],]) 1959 Factor = .85 1960 indices = (-1,0,1) 1961 Units = np.array([[h,k,l] for h in indices for k in indices for l in indices]) 1962 origAtoms = Lists['origin'] 1963 targAtoms = Lists['target'] 1964 for Oid,Otype,Ocoord in origAtoms: 1965 for Tid,Ttype,Tcoord in targAtoms: 1966 result = G2spc.GenAtom(Tcoord,SGData,False,Move=False) 1967 BsumR = (Radii[Otype]+Radii[Ttype])*Factor 1968 for Txyz,Top,Tunit in result: 1969 Dx = (Txyz-np.array(Ocoord))+Units 1970 dx = np.inner(Amat,Dx) 1971 dist = ma.masked_less(np.sqrt(np.sum(dx**2,axis=0)),0.5) 1972 IndB = ma.nonzero(ma.masked_greater(dist-BsumR,0.)) 1973 if np.any(IndB): 1974 for indb in IndB: 1975 for i in range(len(indb)): 1976 unit = Units[indb][i]+Tunit 1977 if np.any(unit): 1978 Topstr = '%d+%d,%d,%d'%(Top,unit[0],unit[1],unit[2]) 1979 else: 1980 Topstr = str(Top) 1981 bondRestData['Bonds'].append([[Oid,Tid],['1',Topstr], \ 1982 ma.getdata(dist[indb])[i],1.54,0.01]) 1983 UpdateBondRestr(bondRestData) 1984 1985 def AddAngleRestraint(angleRestData): 1986 Radii = dict(zip(General['AtomTypes'],General['AngleRadii'])) 1987 origAtoms = [] 1988 targAtoms = [[Ids[x],Types[x],Coords[x]] for x in enumerate(Names[iBeg:])] 1989 dlg = wx.MultiChoiceDialog(G2frame,'Select atom B for angle A-B-C for '+General['Name'], 1990 'Select angle restraint origin atoms',Names) 1991 if dlg.ShowModal() == wx.ID_OK: 1992 sel = dlg.GetSelections() 1993 for x in sel: 1994 if 'all' in Names[x]: 1995 allType = Types[x] 1996 for name,Type,coords,id in zip(Names,Types,Coords,Ids): 1997 if Type == allType and 'all' not in name: 1998 origAtoms.append([id,Type,coords]) 1999 else: 2000 origAtoms.append([Ids[x],Types[x],Coords[x]]) 2001 2002 Factor = .85 2003 indices = (-1,0,1) 2004 Units = np.array([[h,k,l] for h in indices for k in indices for l in indices]) 2005 for Oid,Otype,Ocoord in origAtoms: 2006 IndBlist = [] 2007 Dist = [] 2008 Vect = [] 2009 VectA = [] 2010 angles = [] 2011 for Tid,Ttype,Tcoord in targAtoms: 2012 result = G2spc.GenAtom(Tcoord,SGData,False,Move=False) 2013 BsumR = (Radii[Otype]+Radii[Ttype])*Factor 2014 AsumR = (Radii[Otype]+Radii[Ttype])*Factor 2015 for Txyz,Top,Tunit in result: 2016 Dx = (Txyz-np.array(Ocoord))+Units 2017 dx = np.inner(Amat,Dx) 2018 dist = ma.masked_less(np.sqrt(np.sum(dx**2,axis=0)),0.5) 2019 IndB = ma.nonzero(ma.masked_greater(dist-BsumR,0.)) 2020 if np.any(IndB): 2021 for indb in IndB: 2022 for i in range(len(indb)): 2023 if str(dx.T[indb][i]) not in IndBlist: 2024 IndBlist.append(str(dx.T[indb][i])) 2025 unit = Units[indb][i]+Tunit 2026 if np.any(unit): 2027 Topstr = '%d+%d,%d,%d'%(Top,unit[0],unit[1],unit[2]) 2028 else: 2029 Topstr = str(Top) 2030 tunit = '[%2d%2d%2d]'%(unit[0]+Tunit[0],unit[1]+Tunit[1],unit[2]+Tunit[2]) 2031 Dist.append([Oatom[1],Tatom[1],tunit,Top,ma.getdata(dist[indb])[i],sig]) 2032 if (Dist[-1][-1]-AsumR) <= 0.: 2033 Vect.append(dx.T[indb][i]/Dist[-1][-2]) 2034 VectA.append([OxyzNames,np.array(Oatom[3:6]),TxyzNames,np.array(Tatom[3:6]),unit,Top]) 2035 else: 2036 Vect.append([0.,0.,0.]) 2037 VectA.append([]) 2038 Vect = np.array(Vect) 2039 angles = np.zeros((len(Vect),len(Vect))) 2040 angsig = np.zeros((len(Vect),len(Vect))) 2041 for i,veca in enumerate(Vect): 2042 if np.any(veca): 2043 for j,vecb in enumerate(Vect): 2044 if np.any(vecb): 2045 angles[i][j] = G2mth.getAngSig(VectA[i],VectA[j],Amat,SGData)[0] 2046 2047 1921 2048 1922 2049 def AddPlaneRestraint(): … … 2010 2137 2011 2138 bondList = bondRestData['Bonds'] 2139 if len(bondList[0]) == 6: #patch 2140 bondList = bondRestData['Bonds'] = [] 2012 2141 if len(bondList): 2013 2142 table = [] … … 2015 2144 colLabels = ['A+SymOp B+SymOp','d-calc','d-obs','esd'] 2016 2145 Types = [wg.GRID_VALUE_STRING,]+3*[wg.GRID_VALUE_FLOAT+':10,3',] 2017 for i,[atoms,ops,indx,dcalc,dobs,esd] in enumerate(bondList): 2146 for i,[indx,ops,dcalc,dobs,esd] in enumerate(bondList): 2147 atoms = G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,ct-1) 2018 2148 table.append([atoms[0]+'+ ('+ops[0]+') '+atoms[1]+'+ ('+ops[1]+')',dcalc,dobs,esd]) 2019 2149 rowLabels.append(str(i)) … … 2104 2234 colLabels = ['A+SymOp B+SymOp C+SymOp','calc','obs','esd'] 2105 2235 Types = [wg.GRID_VALUE_STRING,]+3*[wg.GRID_VALUE_FLOAT+':10,2',] 2106 for i,[atoms,ops,indx,dcalc,dobs,esd] in enumerate(angleList): 2236 for i,[indx,ops,dcalc,dobs,esd] in enumerate(angleList): 2237 atoms = G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,ct-1) 2107 2238 table.append([atoms[0]+'+ ('+ops[0]+') '+atoms[1]+'+ ('+ops[1]+') '+atoms[2]+ \ 2108 2239 '+ ('+ops[2]+')',dcalc,dobs,esd]) … … 2160 2291 colLabels = ['atom+SymOp','calc','obs','esd'] 2161 2292 Types = [wg.GRID_VALUE_STRING,]+3*[wg.GRID_VALUE_FLOAT+':10,2',] 2162 for i,[atoms,ops,indx,dcalc,dobs,esd] in enumerate(planeList): 2293 for i,[indx,ops,dcalc,dobs,esd] in enumerate(planeList): 2294 atoms = G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,ct-1) 2163 2295 atString = '' 2164 2296 for a,atom in enumerate(atoms): … … 2213 2345 colLabels = ['O+SymOp A+SymOp B+SymOp C+SymOp','calc','obs','esd'] 2214 2346 Types = [wg.GRID_VALUE_STRING,]+3*[wg.GRID_VALUE_FLOAT+':10,2',] 2215 for i,[atoms,ops,indx,dcalc,dobs,esd] in enumerate(volumeList): 2347 for i,[indx,ops,dcalc,dobs,esd] in enumerate(volumeList): 2348 atoms = G2mth.GetAtomItemsById(Atoms,AtLookUp,indx,ct-1) 2216 2349 table.append([atoms[0]+'+ ('+ops[0]+') '+atoms[1]+'+ ('+ops[1]+') '+atoms[2]+ \ 2217 2350 '+ ('+ops[2]+') '+atoms[3]+'+ ('+ops[3]+')',dcalc,dobs,esd]) -
trunk/GSASIImath.py
r805 r808 155 155 return vcov 156 156 157 def FindAtomIndexByIDs(atomData,IDs,Draw=True): 158 indx = [] 159 for i,atom in enumerate(atomData): 160 if Draw and atom[-3] in IDs: 161 indx.append(i) 162 elif atom[-1] in IDs: 163 indx.append(i) 164 return indx 165 166 def FillAtomLookUp(atomData): 167 atomLookUp = {} 168 for iatm,atom in enumerate(atomData): 169 atomLookUp[atom[-1]] = iatm 170 return atomLookUp 171 172 def GetAtomsById(atomData,atomLookUp,IdList): 173 atoms = [] 174 for id in IdList: 175 atoms.append(atomData[atomLookUp[id]]) 176 return atoms 177 178 def GetAtomItemsById(atomData,atomLookUp,IdList,itemLoc,numItems=1): 179 Items = [] 180 for id in IdList: 181 if numItems == 1: 182 Items.append(atomData[atomLookUp[id]][itemLoc]) 183 else: 184 Items.append(atomData[atomLookUp[id]][itemLoc:itemLoc+numItems]) 185 return Items 186 157 187 def getMass(generalData): 158 188 mass = 0. -
trunk/GSASIIphsGUI.py
r807 r808 368 368 evt.Skip() 369 369 370 def FindAtomIndexByIDs(atomData,IDs,Draw=True):371 indx = []372 for i,atom in enumerate(atomData):373 if Draw and atom[-3] in IDs:374 indx.append(i)375 elif atom[-1] in IDs:376 indx.append(i)377 return indx378 379 370 def UpdatePhaseData(G2frame,Item,data,oldPage): 380 371 … … 1546 1537 SGData = generalData['SGData'] 1547 1538 dlg = SymOpDialog(G2frame,SGData,True,True) 1539 New = False 1548 1540 try: 1549 1541 if dlg.ShowModal() == wx.ID_OK: … … 1614 1606 DisAglData['pId'] = data['pId'] 1615 1607 DisAglData['covData'] = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,G2frame.root, 'Covariance')) 1616 G2str.DistAngle(DisAglCtls,DisAglData) 1608 try: 1609 G2str.DistAngle(DisAglCtls,DisAglData) 1610 except KeyError: # inside DistAngle for missing atom types in DisAglCtls 1611 print '**** ERROR - try again but do "Reset" to fill in missing atom types ****' 1617 1612 1618 1613 ################################################################################ … … 1716 1711 IDs = [ID,] 1717 1712 atomData = drawingData['Atoms'] 1718 indx = FindAtomIndexByIDs(atomData,IDs)1713 indx = G2mth.FindAtomIndexByIDs(atomData,IDs) 1719 1714 for ind in indx: 1720 1715 atomData[ind] = MakeDrawAtom(atom,atomData[ind]) … … 1734 1729 atIndx = [] 1735 1730 for item in indx: 1736 atNames.append(atomData[item][ct-1])1737 1731 atXYZ.append(np.array(atomData[item][cx:cx+3])) 1738 1732 atSymOp.append(atomData[item][cs-1]) … … 1746 1740 restData[PhaseName]['Bond'] = bondData 1747 1741 dist = G2mth.getRestDist(atXYZ,Amat) 1748 bondData['Bonds'].append([at Names,atSymOp,atIndx,dist,1.54,0.01])1742 bondData['Bonds'].append([atIndx,atSymOp,dist,1.54,0.01]) 1749 1743 elif event.GetId() == G2gd.wxID_DRAWRESTRANGLE and len(indx) == 3: 1750 1744 try: … … 1755 1749 restData[PhaseName]['Angle'] = angleData 1756 1750 angle = G2mth.getRestAngle(atXYZ,Amat) 1757 angleData['Angles'].append([at Names,atSymOp,atIndx,angle,109.5,1.0])1751 angleData['Angles'].append([atIndx,atSymOp,angle,109.5,1.0]) 1758 1752 elif event.GetId() == G2gd.wxID_DRAWRESTRPLANE and len(indx) > 3: 1759 1753 try: … … 1764 1758 restData[PhaseName]['Plane'] = planeData 1765 1759 plane = G2mth.getRestPlane(atXYZ,Amat) 1766 planeData['Planes'].append([at Names,atSymOp,atIndx,plane,0.0,0.01])1760 planeData['Planes'].append([atIndx,atSymOp,plane,0.0,0.01]) 1767 1761 elif event.GetId() == G2gd.wxID_DRAWRESTRCHIRAL and len(indx) == 4: 1768 1762 try: … … 1773 1767 restData[PhaseName]['Chiral'] = chiralData 1774 1768 volume = G2mth.getRestChiral(atXYZ,Amat) 1775 chiralData['Volumes'].append([at Names,atSymOp,atIndx,volume,2.5,0.1])1769 chiralData['Volumes'].append([atIndx,atSymOp,volume,2.5,0.1]) 1776 1770 else: 1777 1771 print '**** ERROR wrong number of atoms selected for this restraint' … … 2402 2396 event.StopPropagation() 2403 2397 2404 def FindAtomIndexByIDs(atomData,IDs,Draw=True):2405 indx = []2406 for i,atom in enumerate(atomData):2407 if Draw and atom[-3] in IDs:2408 indx.append(i)2409 elif atom[-1] in IDs:2410 indx.append(i)2411 return indx2412 2413 2398 def DrawAtomsDeleteByIDs(IDs): 2414 2399 atomData = data['Drawing']['Atoms'] 2415 indx = FindAtomIndexByIDs(atomData,IDs)2400 indx = G2mth.FindAtomIndexByIDs(atomData,IDs) 2416 2401 indx.reverse() 2417 2402 for ind in indx: … … 2427 2412 elif colName == 'I/A': 2428 2413 col = cs 2429 indx = FindAtomIndexByIDs(atomData,IDs)2414 indx = G2mth.FindAtomIndexByIDs(atomData,IDs) 2430 2415 for ind in indx: 2431 2416 atomData[ind][col] = value … … 2494 2479 atom = atomDData[i] 2495 2480 xyz.append([i,]+atom[cn:cn+2]+atom[cx:cx+4]) #also gets Sym Op 2496 id = FindAtomIndexByIDs(atomData,[atom[cid],],False)[0]2481 id = G2mth.FindAtomIndexByIDs(atomData,[atom[cid],],False)[0] 2497 2482 Oxyz.append([id,]+atomData[id][cx+1:cx+4]) 2498 2483 DATData['Datoms'] = xyz … … 3164 3149 hist = Indx[Obj.GetId()] 3165 3150 sourceDict = UseList[hist] 3166 copyNames = ['Scale','Pref.Ori.','Size','Mustrain','HStrain','Extinction' ]3151 copyNames = ['Scale','Pref.Ori.','Size','Mustrain','HStrain','Extinction','Babinet'] 3167 3152 copyDict = {} 3168 3153 for name in copyNames: … … 3192 3177 sourceDict = UseList[hist] 3193 3178 copyDict = {} 3194 copyNames = ['Scale','Pref.Ori.','Size','Mustrain','HStrain','Extinction'] 3179 copyNames = ['Scale','Pref.Ori.','Size','Mustrain','HStrain','Extinction','Babinet'] 3180 babNames = ['BabA','BabU'] 3195 3181 for name in copyNames: 3196 3182 if name in ['Scale','Extinction','HStrain']: … … 3205 3191 for item in SHterms: 3206 3192 SHflags[item] = SHterms[item][1] 3207 copyDict[name].append(SHflags) 3193 copyDict[name].append(SHflags) 3194 elif name == 'Babinet': 3195 copyDict[name] = {} 3196 for bab in babNames: 3197 copyDict[name][bab] = sourceDict[name][bab][1] 3208 3198 keyList = ['All',]+UseList.keys() 3209 3199 if UseList: … … 3235 3225 SHterms = copy.copy(sourceDict[name][5]) 3236 3226 for item in SHflags: 3237 SHterms[item][1] = copy.copy(SHflags[item]) 3227 SHterms[item][1] = copy.copy(SHflags[item]) 3228 elif name == 'Babinet': 3229 for bab in babNames: 3230 UseList[item][name][bab][1] = copy.copy(copyDict[name][bab]) 3238 3231 wx.CallAfter(UpdateDData) 3239 3232 finally: … … 3448 3441 pass 3449 3442 Obj.SetValue("%.2f"%(UseList[Indx[Obj.GetId()]]['Extinction'][0])) 3450 3443 3444 def OnBabRef(event): 3445 Obj = event.GetEventObject() 3446 item,bab = Indx[Obj.GetId()] 3447 UseList[item]['Babinet']['Bab'+bab][1] = Obj.GetValue() 3448 3449 def OnBabVal(event): 3450 Obj = event.GetEventObject() 3451 item,bab = Indx[Obj.GetId()] 3452 try: 3453 val = float(Obj.GetValue()) 3454 if val >= 0: 3455 UseList[item]['Babinet']['Bab'+bab][0] = val 3456 except ValueError: 3457 pass 3458 Obj.SetValue("%.3f"%(UseList[item]['Babinet']['Bab'+bab][0])) 3459 3451 3460 def OnTbarVal(event): 3452 3461 Obj = event.GetEventObject() … … 3746 3755 return extSizer 3747 3756 3757 def BabSizer(): 3758 babSizer = wx.BoxSizer(wx.HORIZONTAL) 3759 for bab in ['A','U']: 3760 babRef = wx.CheckBox(DData,-1,label=' Babinet '+bab+': ') 3761 babRef.SetValue(UseList[item]['Babinet']['Bab'+bab][1]) 3762 Indx[babRef.GetId()] = [item,bab] 3763 babRef.Bind(wx.EVT_CHECKBOX, OnBabRef) 3764 babSizer.Add(babRef,0,wx.ALIGN_CENTER_VERTICAL) 3765 babVal = wx.TextCtrl(DData,wx.ID_ANY, 3766 '%.3f'%(UseList[item]['Babinet']['Bab'+bab][0]),style=wx.TE_PROCESS_ENTER) 3767 Indx[babVal.GetId()] = [item,bab] 3768 babVal.Bind(wx.EVT_TEXT_ENTER,OnBabVal) 3769 babVal.Bind(wx.EVT_KILL_FOCUS,OnBabVal) 3770 babSizer.Add(babVal,0,wx.ALIGN_CENTER_VERTICAL) 3771 babSizer.Add((5,5),0) 3772 return babSizer 3773 3748 3774 if DData.GetSizer(): 3749 3775 DData.GetSizer().Clear(True) … … 3757 3783 if 'Use' not in UseList[item]: #patch 3758 3784 UseList[item]['Use'] = True 3785 if 'Babinet' not in UseList[item]: 3786 UseList[item]['Babinet'] = {'BabA':[0.0,False],'BabU':[0.0,False]} 3759 3787 showSizer = wx.BoxSizer(wx.HORIZONTAL) 3760 3788 showData = wx.CheckBox(DData,-1,label=' Show '+item) … … 3854 3882 mainSizer.Add(ExtSizer()) 3855 3883 mainSizer.Add((0,5),0) 3884 mainSizer.Add(BabSizer()) 3885 mainSizer.Add((0,5),0) 3856 3886 elif item[:4] == 'HKLF' and UseList[item]['Show']: 3857 3887 mainSizer.Add((0,5),0) 3858 3888 mainSizer.Add(SCExtSizer()) 3889 mainSizer.Add((0,5),0) 3890 mainSizer.Add(BabSizer()) 3859 3891 mainSizer.Add((0,5),0) 3860 3892 pass … … 3889 3921 histoName = TextList[i] 3890 3922 UseList[histoName] = {'Histogram':histoName,'Show':False,'Scale':[1.0,True], 3923 'Babinet':{'BabA':[0.0,False],'BabU':[0.0,False]}, 3891 3924 'Extinction':['Lorentzian','Secondary Type I', 3892 3925 {'Tbar':0.0,'Eg':[0.0,False],'Es':[0.0,False],'Ep':[0.0,False]},]} … … 3944 3977 NShkl*[0.01,],NShkl*[False,]], 3945 3978 'HStrain':[NDij*[0.0,],NDij*[False,]], 3946 'Extinction':[0.0,False] }3979 'Extinction':[0.0,False],'Babinet':{'BabA':[0.0,False],'BabU':[0.0,False]}} 3947 3980 refList = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,pId,'Reflection Lists')) 3948 3981 refList[generalData['Name']] = [] -
trunk/GSASIIplot.py
r807 r808 798 798 elif G2frame.PatternTree.GetItemText(PickId) in ['Reflection Lists'] or \ 799 799 'PWDR' in G2frame.PatternTree.GetItemText(PickId): 800 refColors=['b','r','c','g','m','k'] 800 801 Phases = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,PatternId,'Reflection Lists')) 801 802 for pId,phase in enumerate(Phases): … … 806 807 pos = G2frame.refOffset-pId*Ymax*G2frame.refDelt*np.ones_like(peak) 807 808 if G2frame.qPlot: 808 Plot.plot(2*np.pi/peak.T[0],pos, colors[pId%6]+'|',mew=1,ms=8,picker=3.,label=phase)809 Plot.plot(2*np.pi/peak.T[0],pos,refColors[pId%6]+'|',mew=1,ms=8,picker=3.,label=phase) 809 810 else: 810 Plot.plot(peak.T[1],pos, colors[pId%6]+'|',mew=1,ms=8,picker=3.,label=phase)811 Plot.plot(peak.T[1],pos,refColors[pId%6]+'|',mew=1,ms=8,picker=3.,label=phase) 811 812 if len(Phases): 812 813 handles,legends = Plot.get_legend_handles_labels() #got double entries in the legends for some reason -
trunk/GSASIIpwd.py
r803 r808 522 522 iD += 1 523 523 except KeyError: 524 break 525 except ValueError: 526 print '**** WARNING - backround peak '+str(iD)+' sigma is negative; fix & try again ****' 524 527 break 525 528 return yb … … 616 619 except KeyError: 617 620 break 621 except ValueError: 622 print '**** WARNING - backround peak '+str(iD)+' sigma is negative; fix & try again ****' 623 break 618 624 return dydb,dyddb,dydpk 619 625 -
trunk/GSASIIpwdGUI.py
r802 r808 675 675 def inst2data(inst,ref,data): 676 676 for item in data: 677 data[item] = [data[item][0],inst[item],ref[item]] 677 try: 678 data[item] = [data[item][0],inst[item],ref[item]] 679 except KeyError: 680 pass #skip 'Polariz.' for N-data 678 681 return data 679 682 … … 722 725 RefreshInstrumentGrid(event,doAnyway=True) #to get peaks updated 723 726 UpdateInstrumentGrid(G2frame,data) 727 G2plt.PlotPeakWidths(G2frame) 724 728 finally: 725 729 dlg.Destroy() … … 749 753 RefreshInstrumentGrid(event,doAnyway=True) #to get peaks updated 750 754 UpdateInstrumentGrid(G2frame,data) 755 G2plt.PlotPeakWidths(G2frame) 751 756 752 757 def OnInstFlagCopy(event): … … 769 774 for item in copyList: 770 775 Id = G2gd.GetPatternTreeItemId(G2frame,G2frame.root,item) 771 instData = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Id,'Instrument Parameters')) 776 instData = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Id,'Instrument Parameters'))[0] 772 777 if len(data) == len(instData) and instType == instData['Type'][0]: #don't mix data types or lam & lam1/lam2 parms! 773 774 instData[2] = copy.copy(flags)778 for item in instData: 779 instData[item][2] = copy.copy(flags[item]) 775 780 else: 776 781 print item+' not copied - instrument parameters not commensurate' … … 796 801 for item in copyList: 797 802 Id = G2gd.GetPatternTreeItemId(G2frame,G2frame.root,item) 798 instData = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Id,'Instrument Parameters')) 803 instData = G2frame.PatternTree.GetItemPyData(G2gd.GetPatternTreeItemId(G2frame,Id,'Instrument Parameters'))[0] 799 804 if len(data) == len(instData) and instType == instData['Type'][0]: #don't mix data types or lam & lam1/lam2 parms! 800 for i,item in enumerate(data[1:]): #skip default values in tuple 801 instData[i+1][:-1] = copy.copy(item[:-1]) #skip azimuth at end 805 instData.update(data) 802 806 else: 803 807 print item+' not copied - instrument parameters not commensurate' … … 863 867 Obj.SetValue(fmt%(value)) 864 868 data = updateData(insVal,insRef) 869 G2plt.PlotPeakWidths(G2frame) 865 870 866 871 def OnItemRef(event): -
trunk/GSASIIspc.py
r762 r808 988 988 'P m 3 n','P n 3 m',), 989 989 'Im3m':('I 2 3','I 21 3','I m -3','I a -3', 'I 4 3 2','I 41 3 2', 990 'I -4 3 m', 'I -4 3 d','I m -3 m','I a -3 d',),990 'I -4 3 m', 'I -4 3 d','I m -3 m','I m 3 m','I a -3 d',), 991 991 'Fm3m':('F 2 3','F m -3','F d -3','F 4 3 2','F 41 3 2','F -4 3 m', 992 'F -4 3 c','F m -3 m','F m -3 c','F d -3 m','F d -3 c',),992 'F -4 3 c','F m -3 m','F m 3 m','F m -3 c','F d -3 m','F d -3 c',), 993 993 } 994 994 'A few non-standard space groups for test use' -
trunk/GSASIIstruct.py
r803 r808 543 543 544 544 def PrintAtoms(General,Atoms): 545 cx,ct,cs,cia = General['AtomPtrs'] 545 546 print >>pFile,'\n Atoms:' 546 547 line = ' name type refine? x y z '+ \ … … 549 550 line += ' Mx My Mz' 550 551 elif General['Type'] == 'macromolecular': 551 line = ' res no residue chain'+line552 line = ' res no residue chain'+line 552 553 print >>pFile,line 553 554 if General['Type'] == 'nuclear': 554 555 print >>pFile,135*'-' 555 556 for i,at in enumerate(Atoms): 556 line = '%7s'%(at[ 0])+'%7s'%(at[1])+'%7s'%(at[2])+'%10.5f'%(at[3])+'%10.5f'%(at[4])+ \557 '%10.5f'%(at[ 5])+'%8.3f'%(at[6])+'%7s'%(at[7])+'%5d'%(at[8])+'%5s'%(at[9])558 if at[ 9] == 'I':559 line += '%8.4f'%(at[ 10])+48*' '557 line = '%7s'%(at[ct-1])+'%7s'%(at[ct])+'%7s'%(at[ct+1])+'%10.5f'%(at[cx])+'%10.5f'%(at[cx+1])+ \ 558 '%10.5f'%(at[cx+2])+'%8.3f'%(at[cx+3])+'%7s'%(at[cs])+'%5d'%(at[cs+1])+'%5s'%(at[cia]) 559 if at[cia] == 'I': 560 line += '%8.4f'%(at[cia+1])+48*' ' 560 561 else: 561 562 line += 8*' ' 562 563 for j in range(6): 563 line += '%8.4f'%(at[11+j]) 564 line += '%8.4f'%(at[cia+1+j]) 565 print >>pFile,line 566 elif General['Type'] == 'macromolecular': 567 print >>pFile,135*'-' 568 for i,at in enumerate(Atoms): 569 line = '%7s'%(at[0])+'%7s'%(at[1])+'%7s'%(at[2])+'%7s'%(at[ct-1])+'%7s'%(at[ct])+'%7s'%(at[ct+1])+'%10.5f'%(at[cx])+'%10.5f'%(at[cx+1])+ \ 570 '%10.5f'%(at[cx+2])+'%8.3f'%(at[cx+3])+'%7s'%(at[cs])+'%5d'%(at[cs+1])+'%5s'%(at[cia]) 571 if at[cia] == 'I': 572 line += '%8.4f'%(at[cia+1])+48*' ' 573 else: 574 line += 8*' ' 575 for j in range(6): 576 line += '%8.4f'%(at[cia+1+j]) 564 577 print >>pFile,line 565 578 … … 639 652 Natoms[pfx] = 0 640 653 if Atoms and not General.get('doPawley'): 641 if General['Type'] == 'nuclear': 654 cx,ct,cs,cia = General['AtomPtrs'] 655 if General['Type'] in ['nuclear','macromolecular']: 642 656 Natoms[pfx] = len(Atoms) 643 657 for i,at in enumerate(Atoms): 644 658 atomIndx[at[-1]] = [pfx,i] #lookup table for restraints 645 phaseDict.update({pfx+'Atype:'+str(i):at[ 1],pfx+'Afrac:'+str(i):at[6],pfx+'Amul:'+str(i):at[8],646 pfx+'Ax:'+str(i):at[ 3],pfx+'Ay:'+str(i):at[4],pfx+'Az:'+str(i):at[5],659 phaseDict.update({pfx+'Atype:'+str(i):at[ct],pfx+'Afrac:'+str(i):at[cx+3],pfx+'Amul:'+str(i):at[cs+1], 660 pfx+'Ax:'+str(i):at[cx],pfx+'Ay:'+str(i):at[cx+1],pfx+'Az:'+str(i):at[cx+2], 647 661 pfx+'dAx:'+str(i):0.,pfx+'dAy:'+str(i):0.,pfx+'dAz:'+str(i):0., #refined shifts for x,y,z 648 pfx+'AI/A:'+str(i):at[ 9],})649 if at[ 9] == 'I':650 phaseDict[pfx+'AUiso:'+str(i)] = at[ 10]662 pfx+'AI/A:'+str(i):at[cia],}) 663 if at[cia] == 'I': 664 phaseDict[pfx+'AUiso:'+str(i)] = at[cia+1] 651 665 else: 652 phaseDict.update({pfx+'AU11:'+str(i):at[ 11],pfx+'AU22:'+str(i):at[12],pfx+'AU33:'+str(i):at[13],653 pfx+'AU12:'+str(i):at[ 14],pfx+'AU13:'+str(i):at[15],pfx+'AU23:'+str(i):at[16]})654 if 'F' in at[ 2]:666 phaseDict.update({pfx+'AU11:'+str(i):at[cia+2],pfx+'AU22:'+str(i):at[cia+3],pfx+'AU33:'+str(i):at[cia+4], 667 pfx+'AU12:'+str(i):at[cia+5],pfx+'AU13:'+str(i):at[cia+6],pfx+'AU23:'+str(i):at[cia+7]}) 668 if 'F' in at[ct+1]: 655 669 phaseVary.append(pfx+'Afrac:'+str(i)) 656 if 'X' in at[ 2]:657 xId,xCoef = G2spc.GetCSxinel(at[ 7])670 if 'X' in at[ct+1]: 671 xId,xCoef = G2spc.GetCSxinel(at[cs]) 658 672 names = [pfx+'dAx:'+str(i),pfx+'dAy:'+str(i),pfx+'dAz:'+str(i)] 659 673 equivs = [[],[],[]] … … 667 681 for eqv in equiv[1:]: 668 682 G2mv.StoreEquivalence(name,(eqv,)) 669 if 'U' in at[ 2]:683 if 'U' in at[ct+1]: 670 684 if at[9] == 'I': 671 685 phaseVary.append(pfx+'AUiso:'+str(i)) 672 686 else: 673 uId,uCoef = G2spc.GetCSuinel(at[ 7])[:2]687 uId,uCoef = G2spc.GetCSuinel(at[cs])[:2] 674 688 names = [pfx+'AU11:'+str(i),pfx+'AU22:'+str(i),pfx+'AU33:'+str(i), 675 689 pfx+'AU12:'+str(i),pfx+'AU13:'+str(i),pfx+'AU23:'+str(i)] … … 1085 1099 print >>pFile,ptstr 1086 1100 1101 def PrintBabinet(hapData): 1102 print >>pFile,'\n Babinet form factor modification: ' 1103 ptlbls = ' names :' 1104 ptstr = ' values:' 1105 varstr = ' refine:' 1106 for name in ['BabA','BabU']: 1107 ptlbls += '%12s' % (name) 1108 ptstr += '%12.6f' % (hapData[name][0]) 1109 varstr += '%12s' % (str(hapData[name][1])) 1110 print >>pFile,ptlbls 1111 print >>pFile,ptstr 1112 print >>pFile,varstr 1113 1114 1087 1115 hapDict = {} 1088 1116 hapVary = [] … … 1144 1172 for item in ['Mustrain','Size']: 1145 1173 controlDict[pfx+item+'Type'] = hapData[item][0] 1146 hapDict[pfx+item+' :mx'] = hapData[item][1][2]1174 hapDict[pfx+item+';mx'] = hapData[item][1][2] 1147 1175 if hapData[item][2][2]: 1148 hapVary.append(pfx+item+' :mx')1176 hapVary.append(pfx+item+';mx') 1149 1177 if hapData[item][0] in ['isotropic','uniaxial']: 1150 hapDict[pfx+item+' :i'] = hapData[item][1][0]1178 hapDict[pfx+item+';i'] = hapData[item][1][0] 1151 1179 if hapData[item][2][0]: 1152 hapVary.append(pfx+item+' :i')1180 hapVary.append(pfx+item+';i') 1153 1181 if hapData[item][0] == 'uniaxial': 1154 1182 controlDict[pfx+item+'Axis'] = hapData[item][3] 1155 hapDict[pfx+item+' :a'] = hapData[item][1][1]1183 hapDict[pfx+item+';a'] = hapData[item][1][1] 1156 1184 if hapData[item][2][1]: 1157 hapVary.append(pfx+item+' :a')1185 hapVary.append(pfx+item+';a') 1158 1186 else: #generalized for mustrain or ellipsoidal for size 1159 1187 Nterms = len(hapData[item][4]) … … 1170 1198 if hapData[item][5][i]: 1171 1199 hapVary.append(pfx+item+sfx) 1200 for bab in ['BabA','BabU']: 1201 hapDict[pfx+bab] = hapData['Babinet'][bab][0] 1202 if hapData['Babinet'][bab][1]: 1203 hapVary.append(pfx+bab) 1172 1204 1173 1205 if Print: … … 1185 1217 PrintMuStrain(hapData['Mustrain'],SGData) 1186 1218 PrintHStrain(hapData['HStrain'],SGData) 1219 PrintBabinet(hapData['Babinet']) 1187 1220 HKLd = np.array(G2lat.GenHLaue(dmin,SGData,A)) 1188 1221 refList = [] … … 1210 1243 if hapData['Scale'][1]: 1211 1244 hapVary.append(pfx+'Scale') 1245 1212 1246 extApprox,extType,extParms = hapData['Extinction'] 1213 1247 controlDict[pfx+'EType'] = extType … … 1225 1259 if extParms[eKey][1]: 1226 1260 hapVary.append(pfx+eKey) 1261 for bab in ['BabA','BabU']: 1262 hapDict[pfx+bab] = hapData['Babinet'][bab][0] 1263 if hapData['Babinet'][bab][1]: 1264 hapVary.append(pfx+bab) 1227 1265 if Print: 1228 1266 print >>pFile,'\n Phase: ',phase,' in histogram: ',histogram … … 1234 1272 text += ' %4s : %10.3g Refine? '%(eKey,extParms[eKey][0])+str(extParms[eKey][1]) 1235 1273 print >>pFile,text 1274 PrintBabinet(hapData['Babinet']) 1236 1275 Histogram['Reflection Lists'] = phase 1237 1276 … … 1343 1382 print >>pFile,sigstr 1344 1383 1345 def PrintSHPOAndSig(p dx,hapData,POsig):1384 def PrintSHPOAndSig(pfx,hapData,POsig): 1346 1385 print >>pFile,'\n Spherical harmonics preferred orientation: Order:'+str(hapData[4]) 1347 1386 ptlbls = ' names :' … … 1358 1397 print >>pFile,ptstr 1359 1398 print >>pFile,sigstr 1399 1400 def PrintBabinetAndSig(pfx,hapData,BabSig): 1401 print >>pFile,'\n Babinet form factor modification: ' 1402 ptlbls = ' names :' 1403 ptstr = ' values:' 1404 sigstr = ' sig :' 1405 for item in hapData: 1406 ptlbls += '%12s'%(item) 1407 ptstr += '%12.3f'%(hapData[item][0]) 1408 if pfx+item in BabSig: 1409 sigstr += '%12.3f'%(BabSig[pfx+item]) 1410 else: 1411 sigstr += 12*' ' 1412 print >>pFile,ptlbls 1413 print >>pFile,ptstr 1414 print >>pFile,sigstr 1360 1415 1361 1416 PhFrExtPOSig = {} 1362 1417 SizeMuStrSig = {} 1363 1418 ScalExtSig = {} 1419 BabSig = {} 1364 1420 wtFrSum = {} 1365 1421 for phase in Phases: … … 1400 1456 pfx+'HStrain':{}}) 1401 1457 for item in ['Mustrain','Size']: 1402 hapData[item][1][2] = parmDict[pfx+item+' :mx']1458 hapData[item][1][2] = parmDict[pfx+item+';mx'] 1403 1459 hapData[item][1][2] = min(1.,max(0.1,hapData[item][1][2])) 1404 if pfx+item+' :mx' in sigDict:1405 SizeMuStrSig[pfx+item][0][2] = sigDict[pfx+item+' :mx']1460 if pfx+item+';mx' in sigDict: 1461 SizeMuStrSig[pfx+item][0][2] = sigDict[pfx+item+';mx'] 1406 1462 if hapData[item][0] in ['isotropic','uniaxial']: 1407 hapData[item][1][0] = parmDict[pfx+item+' :i']1463 hapData[item][1][0] = parmDict[pfx+item+';i'] 1408 1464 if item == 'Size': 1409 1465 hapData[item][1][0] = min(10.,max(0.001,hapData[item][1][0])) 1410 if pfx+item+' :i' in sigDict:1411 SizeMuStrSig[pfx+item][0][0] = sigDict[pfx+item+' :i']1466 if pfx+item+';i' in sigDict: 1467 SizeMuStrSig[pfx+item][0][0] = sigDict[pfx+item+';i'] 1412 1468 if hapData[item][0] == 'uniaxial': 1413 hapData[item][1][1] = parmDict[pfx+item+' :a']1469 hapData[item][1][1] = parmDict[pfx+item+';a'] 1414 1470 if item == 'Size': 1415 1471 hapData[item][1][1] = min(10.,max(0.001,hapData[item][1][1])) 1416 if pfx+item+' :a' in sigDict:1417 SizeMuStrSig[pfx+item][0][1] = sigDict[pfx+item+' :a']1472 if pfx+item+';a' in sigDict: 1473 SizeMuStrSig[pfx+item][0][1] = sigDict[pfx+item+';a'] 1418 1474 else: #generalized for mustrain or ellipsoidal for size 1419 1475 Nterms = len(hapData[item][4]) … … 1428 1484 if pfx+name in sigDict: 1429 1485 SizeMuStrSig[pfx+'HStrain'][name] = sigDict[pfx+name] 1486 for name in ['BabA','BabU']: 1487 hapData['Babinet'][name][0] = parmDict[pfx+name] 1488 if pfx+name in sigDict: 1489 BabSig[pfx+name] = sigDict[pfx+name] 1430 1490 1431 1491 elif 'HKLF' in histogram: … … 1435 1495 if pfx+item in sigDict: 1436 1496 ScalExtSig[pfx+item] = sigDict[pfx+item] 1497 for name in ['BabA','BabU']: 1498 hapData['Babinet'][name][0] = parmDict[pfx+name] 1499 if pfx+name in sigDict: 1500 BabSig[pfx+name] = sigDict[pfx+name] 1437 1501 1438 1502 if Print: … … 1474 1538 PrintMuStrainAndSig(hapData['Mustrain'],SizeMuStrSig[pfx+'Mustrain'],SGData) 1475 1539 PrintHStrainAndSig(hapData['HStrain'],SizeMuStrSig[pfx+'HStrain'],SGData) 1540 PrintBabinetAndSig(pfx,hapData['Babinet'],BabSig) 1476 1541 1477 1542 elif 'HKLF' in histogram: … … 1481 1546 if 'Scale' in ScalExtSig: 1482 1547 print >>pFile,' Scale factor : %10.4f, sig %10.4f'%(hapData['Scale'][0],ScalExtSig[pfx+'Scale']) 1548 PrintBabinetAndSig(pfx,hapData['Babinet'],BabSig) 1483 1549 1484 1550 # fix after it runs! … … 1971 2037 twopi = 2.0*np.pi 1972 2038 twopisq = 2.0*np.pi**2 2039 phfx = pfx.split(':')[0]+hfx 1973 2040 ast = np.sqrt(np.diag(G)) 1974 2041 Mast = twopisq*np.multiply.outer(ast,ast) … … 1989 2056 H = refl[:3] 1990 2057 SQ = 1./(2.*refl[4])**2 2058 SQfactor = 4.0*SQ*twopisq 2059 Bab = parmDict[phfx+'BabA']*np.exp(-parmDict[phfx+'BabU']*SQfactor) 1991 2060 if not len(refl[-1]): #no form factors 1992 2061 if 'N' in parmDict[hfx+'Type']: … … 1996 2065 for i,El in enumerate(Tdata): 1997 2066 FF[i] = refl[-1][El] 1998 SQfactor = 4.0*SQ*twopisq1999 2067 Uniq = refl[11] 2000 2068 phi = refl[12] … … 2008 2076 Tuij = np.where(HbH<1.,np.exp(HbH),1.0) 2009 2077 Tcorr = Tiso*Tuij 2010 fa = np.array([(FF+FP )*occ*cosp*Tcorr,-FPP*occ*sinp*Tcorr])2078 fa = np.array([(FF+FP-Bab)*occ*cosp*Tcorr,-FPP*occ*sinp*Tcorr]) 2011 2079 fas = np.sum(np.sum(fa,axis=1),axis=1) #real 2012 2080 if not SGData['SGInv']: 2013 fb = np.array([(FF+FP )*occ*sinp*Tcorr,FPP*occ*cosp*Tcorr])2081 fb = np.array([(FF+FP-Bab)*occ*sinp*Tcorr,FPP*occ*cosp*Tcorr]) 2014 2082 fbs = np.sum(np.sum(fb,axis=1),axis=1) 2015 2083 fasq = fas**2 … … 2022 2090 twopi = 2.0*np.pi 2023 2091 twopisq = 2.0*np.pi**2 2092 phfx = pfx.split(':')[0]+hfx 2024 2093 ast = np.sqrt(np.diag(G)) 2025 2094 Mast = twopisq*np.multiply.outer(ast,ast) … … 2042 2111 dFdui = np.zeros((len(refList),len(Mdata))) 2043 2112 dFdua = np.zeros((len(refList),len(Mdata),6)) 2113 dFdbab = np.zeros((len(refList),2)) 2044 2114 for iref,refl in enumerate(refList): 2045 2115 H = np.array(refl[:3]) 2046 2116 SQ = 1./(2.*refl[4])**2 # or (sin(theta)/lambda)**2 2117 SQfactor = 8.0*SQ*np.pi**2 2118 dBabdA = np.exp(-parmDict[phfx+'BabU']*SQfactor) 2119 Bab = parmDict[phfx+'BabA']*dBabdA 2047 2120 for i,El in enumerate(Tdata): 2048 2121 FF[i] = refl[-1][El] 2049 SQfactor = 8.0*SQ*np.pi**22050 2122 Uniq = refl[11] 2051 2123 phi = refl[12] … … 2061 2133 Tuij = np.where(HbH<1.,np.exp(HbH),1.0) 2062 2134 Tcorr = Tiso*Tuij 2063 fot = (FF+FP )*occ*Tcorr2135 fot = (FF+FP-Bab)*occ*Tcorr 2064 2136 fotp = FPP*occ*Tcorr 2065 2137 fa = np.array([fot[:,np.newaxis]*cosp,fotp[:,np.newaxis]*cosp]) #non positions … … 2075 2147 dfadui = np.sum(-SQfactor*fa,axis=2) 2076 2148 dfadua = np.sum(-Hij*fa[:,:,:,np.newaxis],axis=2) 2149 dfadba = np.sum(-cosp*(occ*Tcorr)[:,np.newaxis],axis=1) 2077 2150 #NB: the above have been checked against PA(1:10,1:2) in strfctr.for 2078 2151 dFdfr[iref] = 2.*(fas[0]*dfadfr[0]+fas[1]*dfadfr[1])*Mdata/len(Uniq) … … 2080 2153 dFdui[iref] = 2.*(fas[0]*dfadui[0]+fas[1]*dfadui[1]) 2081 2154 dFdua[iref] = 2.*(fas[0]*dfadua[0]+fas[1]*dfadua[1]) 2155 dFdbab[iref] = np.array([np.sum(dfadba*dBabdA),np.sum(-dfadba*parmDict[phfx+'BabA']*SQfactor*dBabdA)]).T 2082 2156 if not SGData['SGInv']: 2083 2157 dfbdfr = np.sum(fb/occ[:,np.newaxis],axis=2) #problem here if occ=0 for some atom … … 2085 2159 dfbdui = np.sum(-SQfactor*fb,axis=2) 2086 2160 dfbdua = np.sum(-Hij*fb[:,:,:,np.newaxis],axis=2) 2161 dfbdba = np.sum(-sinp*(occ*Tcorr)[:,np.newaxis],axis=1) 2087 2162 dFdfr[iref] += 2.*(fbs[0]*dfbdfr[0]-fbs[1]*dfbdfr[1])*Mdata/len(Uniq) 2088 2163 dFdx[iref] += 2.*(fbs[0]*dfbdx[0]+fbs[1]*dfbdx[1]) 2089 2164 dFdui[iref] += 2.*(fbs[0]*dfbdui[0]-fbs[1]*dfbdui[1]) 2090 2165 dFdua[iref] += 2.*(fbs[0]*dfbdua[0]+fbs[1]*dfbdua[1]) 2166 dFdbab[iref] += np.array([np.sum(dfbdba*dBabdA),np.sum(-dfbdba*parmDict[phfx+'BabA']*SQfactor*dBabdA)]).T 2091 2167 #loop over atoms - each dict entry is list of derivatives for all the reflections 2092 2168 for i in range(len(Mdata)): … … 2102 2178 dFdvDict[pfx+'AU13:'+str(i)] = 2.*dFdua.T[4][i] 2103 2179 dFdvDict[pfx+'AU23:'+str(i)] = 2.*dFdua.T[5][i] 2180 dFdvDict[pfx+'BabA'] = dFdbab.T[0] 2181 dFdvDict[pfx+'BabU'] = dFdbab.T[1] 2104 2182 return dFdvDict 2105 2183 … … 2316 2394 #crystallite size 2317 2395 if calcControls[phfx+'SizeType'] == 'isotropic': 2318 Sgam = 1.8*wave/(np.pi*parmDict[phfx+'Size :i']*costh)2396 Sgam = 1.8*wave/(np.pi*parmDict[phfx+'Size;i']*costh) 2319 2397 elif calcControls[phfx+'SizeType'] == 'uniaxial': 2320 2398 H = np.array(refl[:3]) 2321 2399 P = np.array(calcControls[phfx+'SizeAxis']) 2322 2400 cosP,sinP = G2lat.CosSinAngle(H,P,G) 2323 Sgam = (1.8*wave/np.pi)/(parmDict[phfx+'Size :i']*parmDict[phfx+'Size:a']*costh)2324 Sgam *= np.sqrt((sinP*parmDict[phfx+'Size :a'])**2+(cosP*parmDict[phfx+'Size:i'])**2)2401 Sgam = (1.8*wave/np.pi)/(parmDict[phfx+'Size;i']*parmDict[phfx+'Size;a']*costh) 2402 Sgam *= np.sqrt((sinP*parmDict[phfx+'Size;a'])**2+(cosP*parmDict[phfx+'Size;i'])**2) 2325 2403 else: #ellipsoidal crystallites 2326 2404 Sij =[parmDict[phfx+'Size:%d'%(i)] for i in range(6)] … … 2330 2408 #microstrain 2331 2409 if calcControls[phfx+'MustrainType'] == 'isotropic': 2332 Mgam = 0.018*parmDict[phfx+'Mustrain :i']*tand(refl[5]/2.)/np.pi2410 Mgam = 0.018*parmDict[phfx+'Mustrain;i']*tand(refl[5]/2.)/np.pi 2333 2411 elif calcControls[phfx+'MustrainType'] == 'uniaxial': 2334 2412 H = np.array(refl[:3]) 2335 2413 P = np.array(calcControls[phfx+'MustrainAxis']) 2336 2414 cosP,sinP = G2lat.CosSinAngle(H,P,G) 2337 Si = parmDict[phfx+'Mustrain :i']2338 Sa = parmDict[phfx+'Mustrain :a']2415 Si = parmDict[phfx+'Mustrain;i'] 2416 Sa = parmDict[phfx+'Mustrain;a'] 2339 2417 Mgam = 0.018*Si*Sa*tand(refl[5]/2.)/(np.pi*np.sqrt((Si*cosP)**2+(Sa*sinP)**2)) 2340 2418 else: #generalized - P.W. Stephens model … … 2344 2422 sum += parmDict[phfx+'Mustrain:'+str(i)]*refl[0]**pwr[0]*refl[1]**pwr[1]*refl[2]**pwr[2] 2345 2423 Mgam = 0.018*refl[4]**2*tand(refl[5]/2.)*sum 2346 gam = Sgam*parmDict[phfx+'Size :mx']+Mgam*parmDict[phfx+'Mustrain:mx']2347 sig = (Sgam*(1.-parmDict[phfx+'Size :mx']))**2+(Mgam*(1.-parmDict[phfx+'Mustrain:mx']))**22424 gam = Sgam*parmDict[phfx+'Size;mx']+Mgam*parmDict[phfx+'Mustrain;mx'] 2425 sig = (Sgam*(1.-parmDict[phfx+'Size;mx']))**2+(Mgam*(1.-parmDict[phfx+'Mustrain;mx']))**2 2348 2426 sig /= ateln2 2349 2427 return sig,gam … … 2356 2434 #crystallite size derivatives 2357 2435 if calcControls[phfx+'SizeType'] == 'isotropic': 2358 Sgam = 1.8*wave/(np.pi*parmDict[phfx+'Size :i']*costh)2359 gamDict[phfx+'Size :i'] = -900.*wave*parmDict[phfx+'Size:mx']/(np.pi*costh)2360 sigDict[phfx+'Size :i'] = -1800.*Sgam*wave*(1.-parmDict[phfx+'Size:mx'])**2/(np.pi*costh*ateln2)2436 Sgam = 1.8*wave/(np.pi*parmDict[phfx+'Size;i']*costh) 2437 gamDict[phfx+'Size;i'] = -900.*wave*parmDict[phfx+'Size;mx']/(np.pi*costh) 2438 sigDict[phfx+'Size;i'] = -1800.*Sgam*wave*(1.-parmDict[phfx+'Size;mx'])**2/(np.pi*costh*ateln2) 2361 2439 elif calcControls[phfx+'SizeType'] == 'uniaxial': 2362 2440 H = np.array(refl[:3]) 2363 2441 P = np.array(calcControls[phfx+'SizeAxis']) 2364 2442 cosP,sinP = G2lat.CosSinAngle(H,P,G) 2365 Si = parmDict[phfx+'Size :i']2366 Sa = parmDict[phfx+'Size :a']2443 Si = parmDict[phfx+'Size;i'] 2444 Sa = parmDict[phfx+'Size;a'] 2367 2445 gami = (1.8*wave/np.pi)/(Si*Sa) 2368 2446 sqtrm = np.sqrt((sinP*Sa)**2+(cosP*Si)**2) … … 2371 2449 dsi = (gami*Si*cosP**2/(sqtrm*costh)-gam/Si) 2372 2450 dsa = (gami*Sa*sinP**2/(sqtrm*costh)-gam/Sa) 2373 gamDict[phfx+'Size :i'] = dsi*parmDict[phfx+'Size:mx']2374 gamDict[phfx+'Size :a'] = dsa*parmDict[phfx+'Size:mx']2375 sigDict[phfx+'Size :i'] = 2.*dsi*Sgam*(1.-parmDict[phfx+'Size:mx'])**2/ateln22376 sigDict[phfx+'Size :a'] = 2.*dsa*Sgam*(1.-parmDict[phfx+'Size:mx'])**2/ateln22451 gamDict[phfx+'Size;i'] = dsi*parmDict[phfx+'Size;mx'] 2452 gamDict[phfx+'Size;a'] = dsa*parmDict[phfx+'Size;mx'] 2453 sigDict[phfx+'Size;i'] = 2.*dsi*Sgam*(1.-parmDict[phfx+'Size;mx'])**2/ateln2 2454 sigDict[phfx+'Size;a'] = 2.*dsa*Sgam*(1.-parmDict[phfx+'Size;mx'])**2/ateln2 2377 2455 else: #ellipsoidal crystallites 2378 2456 const = 1.8*wave/(np.pi*costh) … … 2382 2460 Sgam = 1.8*wave/(np.pi*costh*lenR) 2383 2461 for i,item in enumerate([phfx+'Size:%d'%(j) for j in range(6)]): 2384 gamDict[item] = -(const/lenR**2)*dRdS[i]*parmDict[phfx+'Size :mx']2385 sigDict[item] = -2.*Sgam*(const/lenR**2)*dRdS[i]*(1.-parmDict[phfx+'Size :mx'])**2/ateln22386 gamDict[phfx+'Size :mx'] = Sgam2387 sigDict[phfx+'Size :mx'] = -2.*Sgam**2*(1.-parmDict[phfx+'Size:mx'])/ateln22462 gamDict[item] = -(const/lenR**2)*dRdS[i]*parmDict[phfx+'Size;mx'] 2463 sigDict[item] = -2.*Sgam*(const/lenR**2)*dRdS[i]*(1.-parmDict[phfx+'Size;mx'])**2/ateln2 2464 gamDict[phfx+'Size;mx'] = Sgam 2465 sigDict[phfx+'Size;mx'] = -2.*Sgam**2*(1.-parmDict[phfx+'Size;mx'])/ateln2 2388 2466 2389 2467 #microstrain derivatives 2390 2468 if calcControls[phfx+'MustrainType'] == 'isotropic': 2391 Mgam = 0.018*parmDict[phfx+'Mustrain :i']*tand(refl[5]/2.)/np.pi2392 gamDict[phfx+'Mustrain :i'] = 0.018*tanth*parmDict[phfx+'Mustrain:mx']/np.pi2393 sigDict[phfx+'Mustrain :i'] = 0.036*Mgam*tanth*(1.-parmDict[phfx+'Mustrain:mx'])**2/(np.pi*ateln2)2469 Mgam = 0.018*parmDict[phfx+'Mustrain;i']*tand(refl[5]/2.)/np.pi 2470 gamDict[phfx+'Mustrain;i'] = 0.018*tanth*parmDict[phfx+'Mustrain;mx']/np.pi 2471 sigDict[phfx+'Mustrain;i'] = 0.036*Mgam*tanth*(1.-parmDict[phfx+'Mustrain;mx'])**2/(np.pi*ateln2) 2394 2472 elif calcControls[phfx+'MustrainType'] == 'uniaxial': 2395 2473 H = np.array(refl[:3]) 2396 2474 P = np.array(calcControls[phfx+'MustrainAxis']) 2397 2475 cosP,sinP = G2lat.CosSinAngle(H,P,G) 2398 Si = parmDict[phfx+'Mustrain :i']2399 Sa = parmDict[phfx+'Mustrain :a']2476 Si = parmDict[phfx+'Mustrain;i'] 2477 Sa = parmDict[phfx+'Mustrain;a'] 2400 2478 gami = 0.018*Si*Sa*tanth/np.pi 2401 2479 sqtrm = np.sqrt((Si*cosP)**2+(Sa*sinP)**2) … … 2403 2481 dsi = -gami*Si*cosP**2/sqtrm**3 2404 2482 dsa = -gami*Sa*sinP**2/sqtrm**3 2405 gamDict[phfx+'Mustrain :i'] = (Mgam/Si+dsi)*parmDict[phfx+'Mustrain:mx']2406 gamDict[phfx+'Mustrain :a'] = (Mgam/Sa+dsa)*parmDict[phfx+'Mustrain:mx']2407 sigDict[phfx+'Mustrain :i'] = 2*(Mgam/Si+dsi)*Mgam*(1.-parmDict[phfx+'Mustrain:mx'])**2/ateln22408 sigDict[phfx+'Mustrain :a'] = 2*(Mgam/Sa+dsa)*Mgam*(1.-parmDict[phfx+'Mustrain:mx'])**2/ateln22483 gamDict[phfx+'Mustrain;i'] = (Mgam/Si+dsi)*parmDict[phfx+'Mustrain;mx'] 2484 gamDict[phfx+'Mustrain;a'] = (Mgam/Sa+dsa)*parmDict[phfx+'Mustrain;mx'] 2485 sigDict[phfx+'Mustrain;i'] = 2*(Mgam/Si+dsi)*Mgam*(1.-parmDict[phfx+'Mustrain;mx'])**2/ateln2 2486 sigDict[phfx+'Mustrain;a'] = 2*(Mgam/Sa+dsa)*Mgam*(1.-parmDict[phfx+'Mustrain;mx'])**2/ateln2 2409 2487 else: #generalized - P.W. Stephens model 2410 2488 pwrs = calcControls[phfx+'MuPwrs'] … … 2414 2492 term = refl[0]**pwr[0]*refl[1]**pwr[1]*refl[2]**pwr[2] 2415 2493 sum += parmDict[phfx+'Mustrain:'+str(i)]*term 2416 gamDict[phfx+'Mustrain:'+str(i)] = const*term*parmDict[phfx+'Mustrain :mx']2494 gamDict[phfx+'Mustrain:'+str(i)] = const*term*parmDict[phfx+'Mustrain;mx'] 2417 2495 sigDict[phfx+'Mustrain:'+str(i)] = \ 2418 2.*const*term*(1.-parmDict[phfx+'Mustrain :mx'])**2/ateln22496 2.*const*term*(1.-parmDict[phfx+'Mustrain;mx'])**2/ateln2 2419 2497 Mgam = 0.018*refl[4]**2*tand(refl[5]/2.)*sum 2420 2498 for i in range(len(pwrs)): 2421 2499 sigDict[phfx+'Mustrain:'+str(i)] *= Mgam 2422 gamDict[phfx+'Mustrain :mx'] = Mgam2423 sigDict[phfx+'Mustrain :mx'] = -2.*Mgam**2*(1.-parmDict[phfx+'Mustrain:mx'])/ateln22500 gamDict[phfx+'Mustrain;mx'] = Mgam 2501 sigDict[phfx+'Mustrain;mx'] = -2.*Mgam**2*(1.-parmDict[phfx+'Mustrain;mx'])/ateln2 2424 2502 return sigDict,gamDict 2425 2503 … … 2706 2784 return [[pfx+'A0',dpdA[0]],[pfx+'A1',dpdA[1]],[pfx+'A2',dpdA[2]]] 2707 2785 elif SGData['SGLaue'] in ['4/m','4/mmm']: 2708 # return [[pfx+'A0',dpdA[0]+dpdA[1]],[pfx+'A2',dpdA[2]]]2709 2786 return [[pfx+'A0',dpdA[0]],[pfx+'A2',dpdA[2]]] 2710 2787 elif SGData['SGLaue'] in ['6/m','6/mmm','3m1', '31m', '3']: 2711 # return [[pfx+'A0',dpdA[0]+dpdA[1]+dpdA[3]],[pfx+'A2',dpdA[2]]]2712 2788 return [[pfx+'A0',dpdA[0]],[pfx+'A2',dpdA[2]]] 2713 2789 elif SGData['SGLaue'] in ['3R', '3mR']: 2714 2790 return [[pfx+'A0',dpdA[0]+dpdA[1]+dpdA[2]],[pfx+'A3',dpdA[3]+dpdA[4]+dpdA[5]]] 2715 2791 elif SGData['SGLaue'] in ['m3m','m3']: 2716 # return [[pfx+'A0',dpdA[0]+dpdA[1]+dpdA[2]]]2717 2792 return [[pfx+'A0',dpdA[0]]] 2718 2793 # create a list of dependent variables and set up a dictionary to hold their derivatives … … 2789 2864 dMdpk = np.zeros(shape=(6,lenBF)) 2790 2865 dMdipk = G2pwd.getdFCJVoigt3(refl[5],refl[6],refl[7],shl,x[iBeg:iFin]) 2791 for i in range( 1,5):2866 for i in range(5): 2792 2867 dMdpk[i] += 100.*cw[iBeg:iFin]*refl[13]*refl[9]*dMdipk[i] 2793 dMdpk[0] += 100.*cw[iBeg:iFin]*refl[13]*refl[9]*dMdipk[0]2794 2868 dervDict = {'int':dMdpk[0],'pos':dMdpk[1],'sig':dMdpk[2],'gam':dMdpk[3],'shl':dMdpk[4],'L1/L2':np.zeros_like(dMdpk[0])} 2795 2869 if Ka2: … … 2801 2875 dMdpk2 = np.zeros(shape=(6,lenBF2)) 2802 2876 dMdipk2 = G2pwd.getdFCJVoigt3(pos2,refl[6],refl[7],shl,x[iBeg2:iFin2]) 2803 for i in range( 1,5):2877 for i in range(5): 2804 2878 dMdpk2[i] = 100.*cw[iBeg2:iFin2]*refl[13]*refl[9]*kRatio*dMdipk2[i] 2805 dMdpk2[0] = 100.*cw[iBeg2:iFin2]*refl[13]*refl[9]*kRatio*dMdipk2[0]2806 2879 dMdpk2[5] = 100.*cw[iBeg2:iFin2]*refl[13]*dMdipk2[0] 2807 2880 dervDict2 = {'int':dMdpk2[0],'pos':dMdpk2[1],'sig':dMdpk2[2],'gam':dMdpk2[3],'shl':dMdpk2[4],'L1/L2':dMdpk2[5]*refl[9]} … … 2901 2974 if Ka2: 2902 2975 depDerivDict[name][iBeg2:iFin2] += sigDict[name]*dervDict2['sig'] 2903 2976 for name in ['BabA','BabU']: 2977 if phfx+name in varylist: 2978 dMdv[varylist.index(phfx+name)][iBeg:iFin] += dFdvDict[pfx+name][iref]*dervDict['int']*cw[iBeg:iFin] 2979 if Ka2: 2980 dMdv[varylist.index(phfx+name)][iBeg2:iFin2] += dFdvDict[pfx+name][iref]*dervDict2['int']*cw[iBeg2:iFin2] 2981 elif phfx+name in dependentVars: 2982 depDerivDict[phfx+name][iBeg:iFin] += dFdvDict[pfx+name][iref]*dervDict['int']*cw[iBeg:iFin] 2983 if Ka2: 2984 depDerivDict[phfx+name][iBeg2:iFin2] += dFdvDict[pfx+name][iref]*dervDict2['int']*cw[iBeg2:iFin2] 2904 2985 elif 'T' in calcControls[hfx+'histType']: 2905 2986 print 'TOF Undefined at present' -
trunk/imports/G2pwd_fxye.py
r803 r808 32 32 if i==0: # first line is always a comment 33 33 continue 34 if i==1 and line[:4].lower() == 'inst' and ':' in line: 34 # if i==1 and line[:4].lower() == 'inst' and ':' in line: 35 if i==1 and line[:4].lower() == 'inst': 35 36 # 2nd line is optional instrument parameter file 36 37 continue
Note: See TracChangeset
for help on using the changeset viewer.