def OnSuperGp(event): SSymbol = superGp.GetValue() SpGrp = Data['SGData']['SpGrp'] if Data['SGData']['SGGray']: SpGrp += " 1'" print('Try: %s%s' % (Data['SGData']['SpGrp'], SSymbol)) E, SSGData = G2spc.SSpcGroup(Data['SGData'], SSymbol) if SSGData: text, table = G2spc.SSGPrint(Data['SGData'], SSGData) Data['SSGData'] = SSGData Data['SuperSg'] = SSymbol msg = 'Superspace Group Information' G2G.SGMessageBox(self, msg, text, table).Show() print('Super spacegroup operators for ' + SSGData['SSpGrp']) for Op in SSGData['SSGOps']: print(G2spc.SSMT2text(Op).replace(' ', '')) if SGData['SGInv']: for Op in SSGData['SSGOps']: Op = [-Op[0], -Op[1] % 1.] print(G2spc.SSMT2text(Op).replace(' ', '')) else: text = [E + '\nSuperspace Group set to previous'] superGp.SetValue(Data['SuperSg']) msg = 'Superspace Group Error' Style = wx.ICON_EXCLAMATION Text = '\n'.join(text) wx.MessageBox(Text, caption=msg, style=Style) wx.CallAfter(self.UpdateData, Data)
def GenSGdat(spc): (E, D) = GSASIIspc.SpcGroup(spc) if E: print >> sys.stderr, "error on: ", spc else: sgdat[spc] = D sglist[spc] = GSASIIspc.SGPrint(D)
def __init__(self, parent): self._init_ctrls(parent) self.Bind(wx.EVT_CLOSE, self.ExitMain) self.dataFrame = None Data = { 'SGData': G2spc.SpcGroup('P 1')[1], 'SuperSg': '(abg)', } self.UpdateData(Data)
def OnHstrainVal(event): Snames = G2spc.HStrainNames(SGData) Obj = event.GetEventObject() hist,pid = Indx[Obj.GetId()] try: strain = float(Obj.GetValue()) UseList[G2frame.hist]['HStrain'][0][pid] = strain except ValueError: pass Obj.SetValue("%.3g"%(UseList[G2frame.hist]['HStrain'][0][pid])) #reset in case of error
def _setup_additional_phase_data(self, powder_histo_name, phase_data): """ Setup more phase data parameters in 'Phases' / 'General' and 'Phases' / 'Histograms'. @param phase_data :: from GSAS-II, the first entry in 'Phases' """ import GSASIIspc SGData = phase_data['General']['SGData'] use_list = phase_data['Histograms'] NShkl = len(GSASIIspc.MustrainNames(SGData)) NDij = len(GSASIIspc.HStrainNames(SGData)) # like 'PWDR ENGINX_ceria_1000_spectrum-0.txt' histo_name = 'PWDR ' + powder_histo_name # 'Reflection Lists' is not defined at this point: # item_id = GSASIIgrid.GetPatternTreeItemId(gs2, gs2.root, histo_name) # refList = gs2.PatternTree.GetItemPyData( # GSASIIgrid.GetPatternTreeItemId(gs2, item_id, 'Reflection Lists')) # refList[general_phase_data['Name']] = {} use_list[histo_name] = GSASII.SetDefaultDData('PWDR', histo_name, NShkl=NShkl, NDij=NDij)
def OnSpaceGroup(event): Flds = SGTxt.GetValue().split() #get rid of extra spaces between fields first for fld in Flds: fld = fld.strip() SpcGp = ' '.join(Flds) # try a lookup on the user-supplied name SpGrpNorm = G2spc.StandardizeSpcName(SpcGp) if SpGrpNorm: SGErr, SGData = G2spc.SpcGroup(SpGrpNorm) else: SGErr, SGData = G2spc.SpcGroup(SpcGp) if SGErr: text = [ G2spc.SGErrors(SGErr) + '\nSpace Group set to previous' ] SGTxt.SetValue(Data['SGData']['SpGrp']) msg = 'Space Group Error' Style = wx.ICON_EXCLAMATION Text = '\n'.join(text) wx.MessageBox(Text, caption=msg, style=Style) else: text, table = G2spc.SGPrint(SGData) Data['SGData'] = SGData SGTxt.SetValue(Data['SGData']['SpGrp']) msg = 'Space Group Information' G2G.SGMessageBox(self, msg, text, table).Show() SSChoice = G2spc.SSChoice(Data['SGData']) Data['SuperSg'] = SSChoice[0] self.UpdateData(Data)
def test(): SGData = G2spc.SpcGroup('p -3 m 1')[1] results,baseList = GetNonStdSubgroupsmag(SGData,('1/3','1/3','1/2',' ',' ',' ',' ',' ',' ',' ')) if results: for [spgp,mv,bns,gid,altList,supList] in results: if gid in baseList: print('Space group:',spgp, 'BNS:',bns) print('MV') print(mv) results,baseList = GetNonStdSubgroups(SGData,('1/3','1/3','1/2',' ',' ',' ',' ',' ',' ',' ')) if results: for [spgp,mv,gid,altList,supList] in results: if gid in baseList: print('Space group:',spgp) print('MV') print(mv)
def HstrainSizer(): hstrainSizer = wx.FlexGridSizer(0,6,5,5) Hsnames = G2spc.HStrainNames(SGData) parms = zip(Hsnames,UseList[G2frame.hist]['HStrain'][0],UseList[G2frame.hist]['HStrain'][1],range(len(Hsnames))) for Pa,val,ref,id in parms: hstrainRef = wx.CheckBox(DData,wx.ID_ANY,label=Pa) hstrainRef.thisown = False hstrainRef.SetValue(ref) Indx[hstrainRef.GetId()] = [G2frame.hist,id] hstrainRef.Bind(wx.EVT_CHECKBOX, OnHstrainRef) hstrainSizer.Add(hstrainRef,0,WACV|wx.LEFT,5) hstrainVal = wx.TextCtrl(DData,wx.ID_ANY,'%.3g'%(val),style=wx.TE_PROCESS_ENTER) Indx[hstrainVal.GetId()] = [G2frame.hist,id] hstrainVal.Bind(wx.EVT_TEXT_ENTER,OnHstrainVal) hstrainVal.Bind(wx.EVT_KILL_FOCUS,OnHstrainVal) hstrainSizer.Add(hstrainVal,0,WACV) return hstrainSizer
def OnResetStrain(event): Obj = event.GetEventObject() Obj.SetValue(False) item,name = Indx[Obj.GetId()] if name == 'isotropic': UseList[item]['Mustrain'][1][0] = 1000.0 elif name == 'uniaxial': UseList[item]['Mustrain'][1][0] = 1000.0 UseList[item]['Mustrain'][1][1] = 1000.0 elif name == 'generalized': muiso = 1000. cell = generalData['Cell'][1:7] vals = G2spc.Muiso2Shkl(muiso,SGData,cell) nTerm = len(UseList[item]['Mustrain'][4]) for i in range(nTerm): UseList[item]['Mustrain'][4][i] = vals[i] G2plt.PlotSizeStrainPO(G2frame,data,item) wx.CallLater(100,RepaintHistogramInfo)
def OnStrainVal(event): Snames = G2spc.MustrainNames(SGData) Obj = event.GetEventObject() hist,pid = Indx[Obj.GetId()] try: strain = float(Obj.GetValue()) if UseList[G2frame.hist]['Mustrain'][0] == 'generalized': if '4' in Snames[pid] and strain < 0: raise ValueError UseList[G2frame.hist]['Mustrain'][4][pid] = strain else: if strain <= 0: raise ValueError UseList[G2frame.hist]['Mustrain'][1][pid] = strain except ValueError: pass if UseList[G2frame.hist]['Mustrain'][0] == 'generalized': Obj.SetValue("%.3f"%(UseList[G2frame.hist]['Mustrain'][4][pid])) #reset in case of error else: Obj.SetValue("%.1f"%(UseList[G2frame.hist]['Mustrain'][1][pid])) #reset in case of error G2plt.PlotSizeStrainPO(G2frame,data,hist)
def GenStrainDataSizer(): Snames = G2spc.MustrainNames(SGData) numb = len(Snames) if len(UseList[G2frame.hist]['Mustrain'][4]) < numb: UseList[G2frame.hist]['Mustrain'][4] = numb*[0.0,] UseList[G2frame.hist]['Mustrain'][5] = numb*[False,] parms = zip(Snames,UseList[G2frame.hist]['Mustrain'][4],UseList[G2frame.hist]['Mustrain'][5],range(numb)) dataSizer = wx.FlexGridSizer(0,6,5,5) for Pa,val,ref,id in parms: strainRef = wx.CheckBox(DData,wx.ID_ANY,label=Pa) strainRef.thisown = False strainRef.SetValue(ref) Indx[strainRef.GetId()] = [G2frame.hist,id] strainRef.Bind(wx.EVT_CHECKBOX, OnStrainRef) dataSizer.Add(strainRef,0,WACV) strainVal = wx.TextCtrl(DData,wx.ID_ANY,'%.5f'%(val),style=wx.TE_PROCESS_ENTER) Indx[strainVal.GetId()] = [G2frame.hist,id] strainVal.Bind(wx.EVT_TEXT_ENTER,OnStrainVal) strainVal.Bind(wx.EVT_KILL_FOCUS,OnStrainVal) dataSizer.Add(strainVal,0,WACV) return dataSizer
def test(): SGData = G2spc.SpcGroup('f d -3 m')[1] print('test SUBGROUPSMAG') results,baseList = GetNonStdSubgroupsmag(SGData,('0','0','0',' ',' ',' ',' ',' ',' ',' ')) if results: for [spgp,bns,mv,gid,altList,supList] in results: if gid in baseList: print('Space group: %d %s BNS: %s'%(gid,spgp,bns)) print('MV',mv) print('altList:',altList) print('superList: ',supList) print('test SUBGROUPS') results,baseList = GetNonStdSubgroups(SGData,('1/3','1/3','1/2',' ',' ',' ',' ',' ',' ',' ')) if results: for [spgp,mv,gid,altList,supList] in results: if gid in baseList: print('Space group: %d %s'%(gid,spgp)) print('MV',mv) print('altList:',altList) print('superList: ',supList)
def ReadEXPPhase(self, G2frame, filepointer): '''Read a phase from a GSAS .EXP file. ''' shModels = ['cylindrical', 'none', 'shear - 2/m', 'rolling - mmm'] textureData = { 'Order': 0, 'Model': 'cylindrical', 'Sample omega': [False, 0.0], 'Sample chi': [False, 0.0], 'Sample phi': [False, 0.0], 'SH Coeff': [False, {}], 'SHShow': False, 'PFhkl': [0, 0, 1], 'PFxyz': [0, 0, 1], 'PlotType': 'Pole figure' } shNcof = 0 S = 1 NPhas = [] Expr = [{}, {}, {}, {}, {}, {}, {}, {}, {}] # GSAS can have at most 9 phases for line, S in enumerate(filepointer): self.errors = 'Error reading at line ' + str(line + 1) if 'EXPR NPHAS' in S[:12]: Num = S[12:-1].count('0') NPhas = S[12:-1].split() if 'CRS' in S[:3]: N = int(S[3:4]) - 1 Expr[N][S[:12]] = S[12:-1] PNames = [] if not NPhas: raise self.ImportException("No EXPR NPHAS record found") self.errors = 'Error interpreting file' for n, N in enumerate(NPhas): if N != '0': result = n key = 'CRS' + str(n + 1) + ' PNAM' PNames.append(Expr[n][key]) if len(PNames) == 0: raise self.ImportException("No phases found") elif len(PNames) > 1: dlg = wx.SingleChoiceDialog(G2frame, 'Which phase to read?', 'Read phase data', PNames, wx.CHOICEDLG_STYLE) try: if dlg.ShowModal() == wx.ID_OK: result = dlg.GetSelection( ) # I think this breaks is there are skipped phases. Cant this happen? finally: dlg.Destroy() EXPphase = Expr[result] keyList = EXPphase.keys() keyList.sort() SGData = {} if NPhas[result] == '1': Ptype = 'nuclear' elif NPhas[result] in ['2', '3']: Ptype = 'magnetic' elif NPhas[result] == '4': Ptype = 'macromolecular' elif NPhas[result] == '10': Ptype = 'Pawley' else: raise self.ImportException("Phase type not recognized") for key in keyList: if 'PNAM' in key: PhaseName = EXPphase[key].strip() elif 'ABC ' in key: abc = [ float(EXPphase[key][:10]), float(EXPphase[key][10:20]), float(EXPphase[key][20:30]) ] elif 'ANGLES' in key: angles = [ float(EXPphase[key][:10]), float(EXPphase[key][10:20]), float(EXPphase[key][20:30]) ] elif 'SG SYM' in key: SpGrp = EXPphase[key][:15].strip() E, SGData = G2spc.SpcGroup(SpGrp) if E: SGData = G2IO.SGData # P 1 -- unlikely to need this! self.warnings += '\nThe GSAS space group was not interpreted(!) and has been set to "P 1".' self.warnings += "Change this in phase's General tab." elif 'OD ' in key: SHdata = EXPphase[key].split() # may not have all 9 values SHvals = 9 * [0] for i in range(9): try: float(SHdata[i]) SHvals[i] = SHdata[i] except: pass textureData['Order'] = int(SHvals[0]) textureData['Model'] = shModels[int(SHvals[2])] textureData['Sample omega'] = [False, float(SHvals[6])] textureData['Sample chi'] = [False, float(SHvals[7])] textureData['Sample phi'] = [False, float(SHvals[8])] shNcof = int(SHvals[1]) Atoms = [] if Ptype == 'nuclear': for key in keyList: if 'AT' in key: if key[11:] == 'A': S = EXPphase[key] elif key[11:] == 'B': S += EXPphase[key] Atom = [ S[50:58].strip(), S[:10].strip().capitalize(), '', float(S[10:20]), float(S[20:30]), float(S[30:40]), float(S[40:50]), '', int(S[60:62]), S[130:131] ] if Atom[9] == 'I': Atom += [float(S[68:78]), 0., 0., 0., 0., 0., 0.] elif Atom[9] == 'A': Atom += [ 0.0, float(S[68:78]), float(S[78:88]), float(S[88:98]), float(S[98:108]), float(S[108:118]), float(S[118:128]) ] XYZ = Atom[3:6] Atom[7], Atom[8] = G2spc.SytSym(XYZ, SGData) Atom.append(ran.randint(0, sys.maxint)) Atoms.append(Atom) elif Ptype == 'macromolecular': for key in keyList: if 'AT' in key[6:8]: S = EXPphase[key] Atom = [ S[56:60], S[50:54].strip().upper(), S[54:56], S[46:51].strip(), S[:8].strip().capitalize(), '', float(S[16:24]), float(S[24:32]), float(S[32:40]), float(S[8:16]), '1', 1, 'I', float(S[40:46]), 0, 0, 0, 0, 0, 0 ] XYZ = Atom[6:9] Atom[10], Atom[11] = G2spc.SytSym(XYZ, SGData) Atom.append(ran.randint(0, sys.maxint)) Atoms.append(Atom) Volume = G2lat.calc_V(G2lat.cell2A(abc + angles)) if shNcof: shCoef = {} nRec = [i + 1 for i in range((shNcof - 1) / 6 + 1)] for irec in nRec: ODkey = keyList[0][:6] + 'OD' + '%3dA' % (irec) indx = EXPphase[ODkey].split() ODkey = ODkey[:-1] + 'B' vals = EXPphase[ODkey].split() for i, val in enumerate(vals): key = 'C(%s,%s,%s)' % (indx[3 * i], indx[3 * i + 1], indx[3 * i + 2]) shCoef[key] = float(val) textureData['SH Coeff'] = [False, shCoef] if not SGData: raise self.ImportException("No space group found in phase") if not abc: raise self.ImportException("No cell lengths found in phase") if not angles: raise self.ImportException("No cell angles found in phase") if not Atoms: raise self.ImportException("No atoms found in phase") Phase = G2IO.SetNewPhase(Name=PhaseName, SGData=SGData, cell=abc + angles + [ Volume, ]) general = Phase['General'] general['Type'] = Ptype if general['Type'] == 'macromolecular': general['AtomPtrs'] = [6, 4, 10, 12] else: general['AtomPtrs'] = [3, 1, 7, 9] general['SH Texture'] = textureData Phase['Atoms'] = Atoms return Phase
def PrintDistAngle(DisAglCtls,DisAglData,out=sys.stdout): '''Print distances and angles :param dict DisAglCtls: contains distance/angle radii usually defined using :func:`GSASIIctrlGUI.DisAglDialog` :param dict DisAglData: contains phase data: Items 'OrigAtoms' and 'TargAtoms' contain the atoms to be used for distance/angle origins and atoms to be used as targets. Item 'SGData' has the space group information (see :ref:`Space Group object<SGData_table>`) :param file out: file object for output. Defaults to sys.stdout. ''' def MyPrint(s): out.write(s+'\n') # print(s,file=out) # use in Python 3 def ShowBanner(name): MyPrint(80*'*') MyPrint(' Interatomic Distances and Angles for phase '+name) MyPrint((80*'*')+'\n') ShowBanner(DisAglCtls['Name']) SGData = DisAglData['SGData'] SGtext,SGtable = G2spc.SGPrint(SGData) for line in SGtext: MyPrint(line) if len(SGtable) > 1: for i,item in enumerate(SGtable[::2]): if 2*i+1 == len(SGtable): line = ' %s'%(item.ljust(30)) else: line = ' %s %s'%(item.ljust(30),SGtable[2*i+1].ljust(30)) MyPrint(line) else: MyPrint(' ( 1) %s'%(SGtable[0])) #triclinic case Cell = DisAglData['Cell'] Amat,Bmat = G2lat.cell2AB(Cell[:6]) covData = {} if 'covData' in DisAglData: covData = DisAglData['covData'] pfx = str(DisAglData['pId'])+'::' A = G2lat.cell2A(Cell[:6]) cellSig = G2stIO.getCellEsd(pfx,SGData,A,covData) names = [' a = ',' b = ',' c = ',' alpha = ',' beta = ',' gamma = ',' Volume = '] valEsd = [G2mth.ValEsd(Cell[i],cellSig[i],True) for i in range(7)] line = '\n Unit cell:' for name,vals in zip(names,valEsd): line += name+vals MyPrint(line) else: MyPrint('\n Unit cell: a = '+('%.5f'%Cell[0])+' b = '+('%.5f'%Cell[1])+' c = '+('%.5f'%Cell[2])+ ' alpha = '+('%.3f'%Cell[3])+' beta = '+('%.3f'%Cell[4])+' gamma = '+ ('%.3f'%Cell[5])+' Volume = '+('%.3f'%Cell[6])) AtomLabels,DistArray,AngArray = RetDistAngle(DisAglCtls,DisAglData) origAtoms = DisAglData['OrigAtoms'] for Oatom in origAtoms: i = Oatom[0] Dist = DistArray[i] nDist = len(Dist) angles = np.zeros((nDist,nDist)) angsig = np.zeros((nDist,nDist)) for k,j,tup in AngArray[i]: angles[k][j],angsig[k][j] = angles[j][k],angsig[j][k] = tup line = '' for i,x in enumerate(Oatom[3:6]): line += ('%12.5f'%x).rstrip('0') MyPrint('\n Distances & angles for '+Oatom[1]+' at '+line.rstrip()) MyPrint(80*'*') line = '' for dist in Dist[:-1]: line += '%12s'%(AtomLabels[dist[0]].center(12)) MyPrint(' To cell +(sym. op.) dist. '+line.rstrip()) for i,dist in enumerate(Dist): line = '' for j,angle in enumerate(angles[i][0:i]): sig = angsig[i][j] if angle: if sig: line += '%12s'%(G2mth.ValEsd(angle,sig,True).center(12)) else: val = '%.3f'%(angle) line += '%12s'%(val.center(12)) else: line += 12*' ' if dist[4]: #sig exists! val = G2mth.ValEsd(dist[3],dist[4]) else: val = '%8.4f'%(dist[3]) tunit = '[%2d%2d%2d]'% dist[1] MyPrint((' %8s%10s+(%4d) %12s'%(AtomLabels[dist[0]].ljust(8),tunit.ljust(10),dist[2],val.center(12)))+line.rstrip())
def RetDistAngle(DisAglCtls,DisAglData): '''Compute and return distances and angles :param dict DisAglCtls: contains distance/angle radii usually defined using :func:`GSASIIctrlGUI.DisAglDialog` :param dict DisAglData: contains phase data: Items 'OrigAtoms' and 'TargAtoms' contain the atoms to be used for distance/angle origins and atoms to be used as targets. Item 'SGData' has the space group information (see :ref:`Space Group object<SGData_table>`) :returns: AtomLabels,DistArray,AngArray where: **AtomLabels** is a dict of atom labels, keys are the atom number **DistArray** is a dict keyed by the origin atom number where the value is a list of distance entries. The value for each distance is a list containing: 0) the target atom number (int); 1) the unit cell offsets added to x,y & z (tuple of int values) 2) the symmetry operator number (which may be modified to indicate centering and center of symmetry) 3) an interatomic distance in A (float) 4) an uncertainty on the distance in A or 0.0 (float) **AngArray** is a dict keyed by the origin (central) atom number where the value is a list of angle entries. The value for each angle entry consists of three values: 0) a distance item reference for one neighbor (int) 1) a distance item reference for a second neighbor (int) 2) a angle, uncertainty pair; the s.u. may be zero (tuple of two floats) The AngArray distance reference items refer directly to the index of the items in the DistArray item for the list of distances for the central atom. ''' import numpy.ma as ma SGData = DisAglData['SGData'] Cell = DisAglData['Cell'] Amat,Bmat = G2lat.cell2AB(Cell[:6]) covData = {} if 'covData' in DisAglData: covData = DisAglData['covData'] covMatrix = covData['covMatrix'] varyList = covData['varyList'] pfx = str(DisAglData['pId'])+'::' Factor = DisAglCtls['Factors'] Radii = dict(zip(DisAglCtls['AtomTypes'],zip(DisAglCtls['BondRadii'],DisAglCtls['AngleRadii']))) indices = (-2,-1,0,1,2) Units = np.array([[h,k,l] for h in indices for k in indices for l in indices]) origAtoms = DisAglData['OrigAtoms'] targAtoms = DisAglData['TargAtoms'] AtomLabels = {} for Oatom in origAtoms: AtomLabels[Oatom[0]] = Oatom[1] for Oatom in targAtoms: AtomLabels[Oatom[0]] = Oatom[1] DistArray = {} AngArray = {} for Oatom in origAtoms: DistArray[Oatom[0]] = [] AngArray[Oatom[0]] = [] OxyzNames = '' IndBlist = [] Dist = [] Vect = [] VectA = [] angles = [] for Tatom in targAtoms: Xvcov = [] TxyzNames = '' if 'covData' in DisAglData: OxyzNames = [pfx+'dAx:%d'%(Oatom[0]),pfx+'dAy:%d'%(Oatom[0]),pfx+'dAz:%d'%(Oatom[0])] TxyzNames = [pfx+'dAx:%d'%(Tatom[0]),pfx+'dAy:%d'%(Tatom[0]),pfx+'dAz:%d'%(Tatom[0])] Xvcov = G2mth.getVCov(OxyzNames+TxyzNames,varyList,covMatrix) result = G2spc.GenAtom(Tatom[3:6],SGData,False,Move=False) BsumR = (Radii[Oatom[2]][0]+Radii[Tatom[2]][0])*Factor[0] AsumR = (Radii[Oatom[2]][1]+Radii[Tatom[2]][1])*Factor[1] for [Txyz,Top,Tunit,Spn] in result: Dx = (Txyz-np.array(Oatom[3:6]))+Units dx = np.inner(Amat,Dx) dist = ma.masked_less(np.sqrt(np.sum(dx**2,axis=0)),0.5) IndB = ma.nonzero(ma.masked_greater(dist-BsumR,0.)) if np.any(IndB): for indb in IndB: for i in range(len(indb)): if str(dx.T[indb][i]) not in IndBlist: IndBlist.append(str(dx.T[indb][i])) unit = Units[indb][i] tunit = (unit[0]+Tunit[0],unit[1]+Tunit[1],unit[2]+Tunit[2]) pdpx = G2mth.getDistDerv(Oatom[3:6],Tatom[3:6],Amat,unit,Top,SGData) sig = 0.0 if len(Xvcov): sig = np.sqrt(np.inner(pdpx,np.inner(pdpx,Xvcov))) Dist.append([Oatom[0],Tatom[0],tunit,Top,ma.getdata(dist[indb])[i],sig]) if (Dist[-1][-2]-AsumR) <= 0.: Vect.append(dx.T[indb][i]/Dist[-1][-2]) VectA.append([OxyzNames,np.array(Oatom[3:6]),TxyzNames,np.array(Tatom[3:6]),unit,Top]) else: Vect.append([0.,0.,0.]) VectA.append([]) for D in Dist: DistArray[Oatom[0]].append(D[1:]) Vect = np.array(Vect) angles = np.zeros((len(Vect),len(Vect))) angsig = np.zeros((len(Vect),len(Vect))) for i,veca in enumerate(Vect): if np.any(veca): for j,vecb in enumerate(Vect): if np.any(vecb): angles[i][j],angsig[i][j] = G2mth.getAngSig(VectA[i],VectA[j],Amat,SGData,covData) if i <= j: continue AngArray[Oatom[0]].append((i,j, G2mth.getAngSig(VectA[i],VectA[j],Amat,SGData,covData))) return AtomLabels,DistArray,AngArray
def ReadPDFPhase(self, G2frame, fp): '''Read a phase from a ICDD .str file. ''' EightPiSq = 8. * math.pi**2 self.errors = 'Error opening file' Phase = {} Atoms = [] S = fp.readline() line = 1 SGData = None cell = [] cellkey = [] while S: if 'space_group' in S: break S = fp.readline() while S: self.errors = 'Error reading at line ' + str(line) if 'phase_name' in S: Title = S.split('"')[1] elif 'Space group (HMS)' in S: SpGrp = S.split()[-1] SpGrpNorm = G2spc.StandardizeSpcName(SpGrp) E, SGData = G2spc.SpcGroup(SpGrpNorm) # space group processing failed, try to look up name in table while E: print(G2spc.SGErrors(E)) dlg = wx.TextEntryDialog( G2frame, SpGrp[:-1] + ' is invalid \nN.B.: make sure spaces separate axial fields in symbol', 'ERROR in space group symbol', '', style=wx.OK) if dlg.ShowModal() == wx.ID_OK: SpGrp = dlg.GetValue() E, SGData = G2spc.SpcGroup(SpGrp) else: SGData = G2obj.P1SGData # P 1 self.warnings += '\nThe space group was not interpreted and has been set to "P 1".' self.warnings += "Change this in phase's General tab." dlg.Destroy() G2spc.SGPrint(SGData) #silent check of space group symbol elif 'a a_' in S[:7]: data = S.split() cell.append(float(data[2])) cellkey.append(data[1]) elif 'b b_' in S[:7]: data = S.split() cell.append(float(data[2])) cellkey.append(data[1]) elif 'b =' in S[:6]: data = S.split('=') indx = cellkey.index(data[1].split(';')[0]) cell.append(cell[indx]) elif 'c c_' in S[:7]: data = S.split() cell.append(float(data[2])) elif 'c =' in S[:6]: data = S.split('=') indx = cellkey.index(data[1].split(';')[0]) cell.append(cell[indx]) elif 'al' in S[:5]: cell.append(float(S.split()[1])) elif 'be' in S[:5]: cell.append(float(S.split()[1])) elif 'ga' in S[:5]: cell.append(float(S.split()[1])) Volume = G2lat.calc_V(G2lat.cell2A(cell)) break S = fp.readline() S = fp.readline() while S: if '/*' in S[:5]: break if 'site' in S[:7]: atom = [] xyzkey = [] data = S.split() atom.append(data[1]) #name pos = data.index('occ') + 1 atom.append(data[pos]) #type atom.append('') #refine for xid in ['x =', 'y =', 'z =']: if xid in S: xpos = S.index(xid) + 3 xend = xpos + S[xpos:].index(';') if S[xpos:xend] in xyzkey: atom.append(atom[3 + xyzkey.index(S[xpos:xend])]) else: atom.append(eval(S[xpos:xend] + '.')) else: xpos = data.index(xid[0]) + 2 xyzkey.append(data[xpos - 1][1:]) atom.append(float(data[xpos])) atom.append(float(data[pos + 2])) SytSym, Mult = G2spc.SytSym(np.array(atom[3:6]), SGData)[:2] atom.append(SytSym) atom.append(Mult) if 'beq' in S: atom.append('I') upos = data.index('beq') atom.append(float(data[upos + 2]) / EightPiSq) atom += [ 0., 0., 0., 0., 0., 0., ] elif 'ADPs' in S: upos = data.index('ADPs') atom.append('A') atom.append(0.0) for uid in [ 'Bani11', 'Bani22', 'Bani33', 'Bani12', 'Bani13', 'Bani23' ]: upos = data.index(uid) + 1 atom.append(float(data[upos]) / EightPiSq) else: atom.append('I') atom += [ 0.02, 0., 0., 0., 0., 0., 0., ] atom.append(ran.randint(0, sys.maxsize)) Atoms.append(atom) S = fp.readline() fp.close() self.errors = 'Error after read complete' if not SGData: raise self.ImportException("No space group (spcgroup entry) found") if not cell: raise self.ImportException("No cell found") Phase = G2obj.SetNewPhase(Name=Title, SGData=SGData, cell=cell + [ Volume, ]) Phase['General']['Type'] = 'nuclear' Phase['General']['AtomPtrs'] = [3, 1, 7, 9] Phase['Atoms'] = Atoms return Phase
def ReadEXPPhase(self, G2frame, filepointer): '''Read a phase from a GSAS .EXP file. ''' shModels = ['cylindrical', 'none', 'shear - 2/m', 'rolling - mmm'] textureData = { 'Order': 0, 'Model': 'cylindrical', 'Sample omega': [False, 0.0], 'Sample chi': [False, 0.0], 'Sample phi': [False, 0.0], 'SH Coeff': [False, {}], 'SHShow': False, 'PFhkl': [0, 0, 1], 'PFxyz': [0, 0, 1], 'PlotType': 'Pole figure' } shNcof = 0 S = 1 NPhas = [] Expr = [{}, {}, {}, {}, {}, {}, {}, {}, {}] # GSAS can have at most 9 phases for line, S in enumerate(filepointer): self.errors = 'Error reading at line ' + str(line + 1) if 'EXPR NPHAS' in S[:12]: NPhas = S[12:-1].split() if 'CRS' in S[:3]: N = int(S[3:4]) - 1 Expr[N][S[:12]] = S[12:-1] PNames = [] if not NPhas: raise self.ImportException("No EXPR NPHAS record found") self.errors = 'Error interpreting file' for n, N in enumerate(NPhas): if N != '0': result = n key = 'CRS' + str(n + 1) + ' PNAM' PNames.append(Expr[n][key]) if len(PNames) == 0: raise self.ImportException("No phases found") elif len(PNames) > 1: dlg = wx.SingleChoiceDialog(G2frame, 'Which phase to read?', 'Read phase data', PNames, wx.CHOICEDLG_STYLE) try: if dlg.ShowModal() == wx.ID_OK: result = dlg.GetSelection( ) # I think this breaks is there are skipped phases. Cant this happen? finally: dlg.Destroy() EXPphase = Expr[result] keyList = list(EXPphase.keys()) keyList.sort() SGData = {} MPtype = '' if NPhas[result] == '1': Ptype = 'nuclear' elif NPhas[result] == '2': Ptype = 'nuclear' MPtype = 'magnetic' MagDmin = 1.0 elif NPhas[result] == '3': Ptype = 'magnetic' MagDmin = 1.0 elif NPhas[result] == '4': Ptype = 'macromolecular' elif NPhas[result] == '10': Ptype = 'Pawley' else: raise self.ImportException("Phase type not recognized") for key in keyList: if 'PNAM' in key: PhaseName = EXPphase[key].strip() elif 'ABC ' in key: abc = [ float(EXPphase[key][:10]), float(EXPphase[key][10:20]), float(EXPphase[key][20:30]) ] elif 'ANGLES' in key: angles = [ float(EXPphase[key][:10]), float(EXPphase[key][10:20]), float(EXPphase[key][20:30]) ] elif 'SG SYM' in key: SpGrp = EXPphase[key][:15].strip() E, SGData = G2spc.SpcGroup(SpGrp) if E: SGData = G2obj.P1SGData # P 1 -- unlikely to need this! self.warnings += '\nThe GSAS space group was not interpreted(!) and has been set to "P 1".' self.warnings += "Change this in phase's General tab." elif 'SPNFLP' in key: SpnFlp = np.array( [int(float(s)) for s in EXPphase[key].split()]) SpnFlp = np.where(SpnFlp == 0, 1, SpnFlp) SpnFlp = [ 1, ] + list(SpnFlp) if SGData['SpGrp'][0] in ['A', 'B', 'C', 'I', 'R', 'F']: SpnFlp = list(SpnFlp) + [1, 1, 1, 1] elif 'MXDSTR' in key: MagDmin = float(EXPphase[key][:10]) elif 'OD ' in key: SHdata = EXPphase[key].split() # may not have all 9 values SHvals = 9 * [0] for i in range(9): try: float(SHdata[i]) SHvals[i] = SHdata[i] except: pass textureData['Order'] = int(SHvals[0]) textureData['Model'] = shModels[int(SHvals[2])] textureData['Sample omega'] = [False, float(SHvals[6])] textureData['Sample chi'] = [False, float(SHvals[7])] textureData['Sample phi'] = [False, float(SHvals[8])] shNcof = int(SHvals[1]) Volume = G2lat.calc_V(G2lat.cell2A(abc + angles)) Atoms = [] MAtoms = [] Bmat = G2lat.cell2AB(abc + angles)[1] if Ptype == 'macromolecular': for key in keyList: if 'AT' in key[6:8]: S = EXPphase[key] Atom = [ S[56:60].strip(), S[50:54].strip().upper(), S[54:56], S[46:51].strip(), S[:8].strip().capitalize(), '', float(S[16:24]), float(S[24:32]), float(S[32:40]), float(S[8:16]), '1', 1, 'I', float(S[40:46]), 0, 0, 0, 0, 0, 0 ] XYZ = Atom[6:9] Atom[10], Atom[11] = G2spc.SytSym(XYZ, SGData)[:2] Atom.append(ran.randint(0, sys.maxsize)) Atoms.append(Atom) else: for key in keyList: if 'AT' in key: if key[11:] == 'A': S = EXPphase[key] elif key[11:] == 'B': S1 = EXPphase[key] Atom = [ S[50:58].strip(), S[:10].strip().capitalize(), '', float(S[10:20]), float(S[20:30]), float(S[30:40]), float(S[40:50]), '', int(S[60:62]), S1[62:63] ] #float(S[40:50]),'',int(S[60:62]),S1[130:131]] if Atom[9] == 'I': Atom += [float(S1[0:10]), 0., 0., 0., 0., 0., 0.] elif Atom[9] == 'A': Atom += [ 0.0, float(S1[0:10]), float(S1[10:20]), float(S1[20:30]), float(S1[30:40]), float(S1[40:50]), float(S1[50:60]) ] else: print('Error in line with key: ' + key) Atom += [0., 0., 0., 0., 0., 0., 0.] XYZ = Atom[3:6] Atom[7], Atom[8] = G2spc.SytSym(XYZ, SGData)[:2] Atom.append(ran.randint(0, sys.maxsize)) Atoms.append(Atom) elif key[11:] == 'M' and key[6:8] == 'AT': S = EXPphase[key] mom = np.array( [float(S[:10]), float(S[10:20]), float(S[20:30])]) mag = np.sqrt(np.sum(mom**2)) mom = np.inner(Bmat, mom) * mag MAtoms.append(Atom) MAtoms[-1] = Atom[:7] + list(mom) + Atom[7:] if shNcof: shCoef = {} nRec = [i + 1 for i in range((shNcof - 1) // 6 + 1)] for irec in nRec: ODkey = keyList[0][:6] + 'OD' + '%3dA' % (irec) indx = EXPphase[ODkey].split() ODkey = ODkey[:-1] + 'B' vals = EXPphase[ODkey].split() for i, val in enumerate(vals): key = 'C(%s,%s,%s)' % (indx[3 * i], indx[3 * i + 1], indx[3 * i + 2]) shCoef[key] = float(val) textureData['SH Coeff'] = [False, shCoef] if not SGData: raise self.ImportException("No space group found in phase") if not abc: raise self.ImportException("No cell lengths found in phase") if not angles: raise self.ImportException("No cell angles found in phase") if not Atoms: raise self.ImportException("No atoms found in phase") self.Phase['General'].update({ 'Type': Ptype, 'Name': PhaseName, 'Cell': [ False, ] + abc + angles + [ Volume, ], 'SGData': SGData }) if MPtype == 'magnetic': self.MPhase['General'].update({ 'Type': 'magnetic', 'Name': PhaseName + ' mag', 'Cell': [ False, ] + abc + angles + [ Volume, ], 'SGData': SGData }) else: self.MPhase = None if Ptype == 'macromolecular': self.Phase['General']['AtomPtrs'] = [6, 4, 10, 12] self.Phase['Atoms'] = Atoms elif Ptype == 'magnetic': self.Phase['General']['AtomPtrs'] = [3, 1, 10, 12] self.Phase['General']['SGData']['SGSpin'] = SpnFlp self.Phase['General']['MagDmin'] = MagDmin self.Phase['Atoms'] = MAtoms else: #nuclear self.Phase['General']['AtomPtrs'] = [3, 1, 7, 9] self.Phase['General']['SH Texture'] = textureData self.Phase['Atoms'] = Atoms if MPtype == 'magnetic': self.MPhase['General']['AtomPtrs'] = [3, 1, 10, 12] self.MPhase['General']['SGData']['SGSpin'] = SpnFlp self.MPhase['General']['MagDmin'] = MagDmin self.MPhase['Atoms'] = MAtoms
def findMV(peaks, controls, ssopt, Inst, dlg): def Val2Vec(vec, Vref, values): Vec = [] i = 0 for j, r in enumerate(Vref): if r: if values.size > 1: Vec.append(max(-1., min(1.0, values[i]))) else: Vec.append(max(0.0, min(1.0, values))) i += 1 else: Vec.append(vec[j]) return np.array(Vec) def ZSSfunc(values, peaks, dmin, Inst, SGData, SSGData, vec, Vref, maxH, A, wave, Z, dlg=None): Vec = Val2Vec(vec, Vref, values) HKL = G2pwd.getHKLMpeak(dmin, Inst, SGData, SSGData, Vec, maxH, A) Peaks = np.array(IndexSSPeaks(peaks, HKL)[1]).T Qo = 1. / Peaks[-2]**2 Qc = G2lat.calc_rDsqZSS(Peaks[4:8], A, Vec, Z, Peaks[0], wave) chi = np.sum((Qo - Qc)**2) if dlg: dlg.Pulse() return chi def TSSfunc(values, peaks, dmin, Inst, SGData, SSGData, vec, Vref, maxH, A, difC, Z, dlg=None): Vec = Val2Vec(vec, Vref, values) HKL = G2pwd.getHKLMpeak(dmin, Inst, SGData, SSGData, Vec, maxH, A) Peaks = np.array(IndexSSPeaks(peaks, HKL)[1]).T Qo = 1. / Peaks[-2]**2 Qc = G2lat.calc_rDsqTSS(Peaks[4:8], A, Vec, Z, Peaks[0], difC) chi = np.sum((Qo - Qc)**2) if dlg: dlg.Pulse() return chi if 'T' in Inst['Type'][0]: difC = Inst['difC'][1] else: wave = G2mth.getWave(Inst) SGData = G2spc.SpcGroup(controls[13])[1] SSGData = G2spc.SSpcGroup(SGData, ssopt['ssSymb'])[1] A = G2lat.cell2A(controls[6:12]) Z = controls[1] Vref = [True if x in ssopt['ssSymb'] else False for x in ['a', 'b', 'g']] values = [] ranges = [] dT = 0.01 #seems to be a good choice for v, r in zip(ssopt['ModVec'], Vref): if r: ranges += [ slice(dT, 1. - dT, dT), ] #NB: unique part for (00g) & (a0g); (abg)? values += [ v, ] dmin = getDmin(peaks) - 0.005 if 'T' in Inst['Type'][0]: result = so.brute(TSSfunc, ranges, finish=so.fmin_cg, full_output=True, args=(peaks, dmin, Inst, SGData, SSGData, ssopt['ModVec'], Vref, 1, A, difC, Z, dlg)) else: result = so.brute(ZSSfunc, ranges, finish=so.fmin_cg, full_output=True, args=(peaks, dmin, Inst, SGData, SSGData, ssopt['ModVec'], Vref, 1, A, wave, Z, dlg)) return Val2Vec(ssopt['ModVec'], Vref, result[0]), result
def GetNonStdSubgroupsmag(SGData, kvec,star=False,landau=False,maximal=False): '''Run Bilboa's k-Subgroupsmag for a non-standard space group. This requires doing a post to the Bilboa site, which returns all magnetic subgroups of the entered subgroup as the text of a web page with a table containing the BNS magnetic space group symbol, the transformation matrix and index for each subgroup. :params list kvec: propogation vector as a list of three numbers :params SGData: space group object (see :ref:`Space Group object<SGData_table>`) :returns: (error,text) error: if True no error or False; where text containts a possible web page text ''' print(''' For use of k-SUBGROUPSMAG, please cite: Symmetry-Based Computational Tools for Magnetic Crystallography, J.M. Perez-Mato, S.V. Gallego, E.S. Tasci, L. Elcoro, G. de la Flor, and M.I. Aroyo Annu. Rev. Mater. Res. 2015. 45,217-48. doi: 10.1146/annurev-matsci-070214-021008 ''') starmag = 'no' if star: starmag = 'yes' land = 'no' if landau: land = 'yes' celtodas = 'no' limite = 'spgroup' if maximal: limite = 'maximal' postdict = {'centrosymmetry':'0','crystalsystem':'0','landau':land, 'eleccion':'subgrmag1_k','inicio':'nostandard','celtodas':celtodas, 'limite':limite,'list':'Submit','listado':'lista','starmagnetica':starmag, 'pointgroup':'0','polarity':'0','sub':'1.1', 'super':'','tipog':'gmag','wyckoffstrain':''} text,table = G2spc.SGPrint(SGData) OpList = G2spc.TextOps(text,table,reverse=True) # GenList = G2spc.TextGen(SGData,reverse=True) for item in OpList: item += '\n' sym = "" for i in OpList: if sym: sym += '\n' #if sym: sym += ' ' # use this for testing to generate an error in place of previous sym += i.lower() postdict['generators'] = sym for j in [1,2,3]: if kvec[3*j-3] == ' ': break for i,k in zip(('x','y','z'),kvec[3*j-3:3*j]): postdict['km%d%s'%(j,i)] = k try: r = requests.post(submagSite,postdict) except: #ConnectionError? page = '' print('connection error - not on internet') return None,None if r.status_code == 200: print('request OK') page = r.text page = page.replace('<font style= "text-decoration: overline;">','<font>-') else: page = '' print('request failed. Reason=',r.reason) return None,None r.close() p = TableParser() p.feed(page) nItms = len(p.MVs) result = list(zip(p.SPGPs,p.BNSs,p.MVs,range(nItms),nItms*[[],],nItms*['[]',])) return result,range(nItms)
def GetNonStdSubgroups(SGData, kvec,star=False,landau=False,maximal=False): '''Run Bilboa's SUBGROUPS for a non-standard space group. This requires doing a post to the Bilboa site, which returns all subgroups of the entered space group as the text of a web page with a table containing the space group symbol, the transformation matrix and index for each subgroup. :params list kvec: propogation vector as a list of nine string fractions or blank :params SGData: space group object (see :ref:`Space Group object<SGData_table>`) :returns: (error,text) error: if True no error or False; where text containts a possible web page text ''' print(''' For use of SUBGROUPS, please cite: Symmetry-Based Computational Tools for Magnetic Crystallography, J.M. Perez-Mato, S.V. Gallego, E.S. Tasci, L. Elcoro, G. de la Flor, and M.I. Aroyo Annu. Rev. Mater. Res. 2015. 45,217-48. doi: 10.1146/annurev-matsci-070214-021008 ''') def getSpGrp(item): return item.replace('<i>','').replace('</i>','').replace('<sub>','').replace('</sub>','') def getMatVec(item): return item.replace('{','[').replace('}',']') starmag = 'no' if star: starmag = 'yes' land = 'no' if landau: land = 'yes' celtodas = 'no' limite = 'spgroup' if maximal: limite = 'maximal' postdict = {'centrosymmetry':'0','crystalsystem':'0','landau':land, 'eleccion':'subgrmag1_k','inicio':'nostandard','celtodas':celtodas, 'limite':limite,'list':'Submit','listado':'lista','starmagnetica':starmag, 'pointgroup':'0','polarity':'0','sub':'1', 'super':'','tipog':'gesp','wyckoffstrain':''} text,table = G2spc.SGPrint(SGData) OpList = G2spc.TextOps(text,table,reverse=True) # GenList = G2spc.TextGen(SGData,reverse=True) for item in OpList: item += '\n' sym = "" for i in OpList: if sym: sym += '\n' #if sym: sym += ' ' # use this for testing to generate an error in place of previous sym += i.lower() postdict['generators'] = sym for j in [1,2,3]: if kvec[3*j-3] == ' ': break for i,k in zip(('x','y','z'),kvec[3*j-3:3*j]): postdict['knm%d%s'%(j,i)] = k page = G2IO.postURL(submagSite,postdict) if not page: print('connection error - not on internet?') return None,None page = page.replace('<font style= "text-decoration: overline;">','<font>-') result = page.replace('&','\n') result = result.split('\n') SPGPs = [] MVs = [] baseList = [] itemList = [] superList = [] altList = [] start = 0 for line in result: #work around bug report from Bilbao start += 1 if 'yesz' in line: break for line in result[start:]: if 'GGG' in line: lines = line.split('GGG') line = lines[0] alts = [] beg = True for sline in lines: items = sline.split('z') gid = int(items[0]) if beg: baseList.append(gid) beg = False alts.append(gid) itemList.append(gid) superList.append(getMatVec(items[7])) SPGPs.append(getSpGrp(items[4])) MVs.append([getMatVec(items[5]),getMatVec(items[6])]) altList.append(alts) for sline in lines[1:]: altList.append([]) else: items = line.split('z') gid = int(items[0]) altList.append([gid,]) baseList.append(gid) itemList.append(gid) superList.append(getMatVec(items[7])) SPGPs.append(getSpGrp(items[4])) MVs.append([getMatVec(items[5]),getMatVec(items[6])]) result = list(zip(SPGPs,MVs,itemList,altList,superList)) return result,baseList
def UpdateData(self, Data): def OnExhaustive(event): SSList = G2spc.SSChoice(Data['SGData']) print(SSList) def OnSpaceGroup(event): Flds = SGTxt.GetValue().split() #get rid of extra spaces between fields first for fld in Flds: fld = fld.strip() SpcGp = ' '.join(Flds) # try a lookup on the user-supplied name SpGrpNorm = G2spc.StandardizeSpcName(SpcGp) if SpGrpNorm: SGErr, SGData = G2spc.SpcGroup(SpGrpNorm) else: SGErr, SGData = G2spc.SpcGroup(SpcGp) if SGErr: text = [ G2spc.SGErrors(SGErr) + '\nSpace Group set to previous' ] SGTxt.SetValue(Data['SGData']['SpGrp']) msg = 'Space Group Error' Style = wx.ICON_EXCLAMATION Text = '\n'.join(text) wx.MessageBox(Text, caption=msg, style=Style) else: text, table = G2spc.SGPrint(SGData) Data['SGData'] = SGData SGTxt.SetValue(Data['SGData']['SpGrp']) msg = 'Space Group Information' G2G.SGMessageBox(self, msg, text, table).Show() SSChoice = G2spc.SSChoice(Data['SGData']) Data['SuperSg'] = SSChoice[0] self.UpdateData(Data) def OnSuperGp(event): SSymbol = superGp.GetValue() SpGrp = Data['SGData']['SpGrp'] if Data['SGData']['SGGray']: SpGrp += " 1'" print('Try: %s%s' % (Data['SGData']['SpGrp'], SSymbol)) E, SSGData = G2spc.SSpcGroup(Data['SGData'], SSymbol) if SSGData: text, table = G2spc.SSGPrint(Data['SGData'], SSGData) Data['SSGData'] = SSGData Data['SuperSg'] = SSymbol msg = 'Superspace Group Information' G2G.SGMessageBox(self, msg, text, table).Show() print('Super spacegroup operators for ' + SSGData['SSpGrp']) for Op in SSGData['SSGOps']: print(G2spc.SSMT2text(Op).replace(' ', '')) if SGData['SGInv']: for Op in SSGData['SSGOps']: Op = [-Op[0], -Op[1] % 1.] print(G2spc.SSMT2text(Op).replace(' ', '')) else: text = [E + '\nSuperspace Group set to previous'] superGp.SetValue(Data['SuperSg']) msg = 'Superspace Group Error' Style = wx.ICON_EXCLAMATION Text = '\n'.join(text) wx.MessageBox(Text, caption=msg, style=Style) wx.CallAfter(self.UpdateData, Data) SGData = G2spc.SpcGroup(Data['SGData']['SpGrp'])[1] self.testSSPanel.DestroyChildren() mainSizer = wx.FlexGridSizer(0, 2, 5, 5) mainSizer.Add(wx.StaticText(self.testSSPanel, -1, ' Space group: '), 0, WACV) SpGrp = Data['SGData']['SpGrp'] if Data['SGData']['SGGray']: SpGrp += " 1'" SGTxt = wx.TextCtrl(self.testSSPanel, -1, value=SpGrp, style=wx.TE_PROCESS_ENTER) SGTxt.Bind(wx.EVT_TEXT_ENTER, OnSpaceGroup) mainSizer.Add(SGTxt, 0, WACV) mainSizer.Add( wx.StaticText(self.testSSPanel, label=' Superspace group: ' + SpGrp), 0, WACV) ssChoice = G2spc.SSChoice(Data['SGData']) ssSym = Data['SuperSg'] if ssChoice: superGp = wx.ComboBox(self.testSSPanel, value=ssSym, choices=ssChoice, style=wx.CB_DROPDOWN) #wx.CB_READONLY| superGp.Bind(wx.EVT_COMBOBOX, OnSuperGp) superGp.Bind(wx.EVT_TEXT_ENTER, OnSuperGp) else: #nonstandard space group symbol not in my dictionary superGp = wx.TextCtrl(self.testSSPanel, value=ssSym, style=wx.TE_PROCESS_ENTER) superGp.Bind(wx.EVT_TEXT_ENTER, OnSuperGp) mainSizer.Add(superGp, 0, WACV) mainSizer.Add(wx.StaticText(self.testSSPanel, -1, ' Exhaustive try: '), 0, WACV) ESStry = wx.Button(self.testSSPanel, -1, 'OK') ESStry.Bind(wx.EVT_BUTTON, OnExhaustive) mainSizer.Add(ESStry, 0, WACV) self.testSSPanel.SetSizer(mainSizer) Size = mainSizer.Fit(self.testSSPanel) Size[0] = 800 Size[1] = max(Size[1], 350) self.testSSPanel.SetSize(Size)
def Reader(self,filename,filepointer, ParentFrame=None, usedRanIdList=[], **unused): self.isodistort_warnings = '' self.Phase = G2IO.SetNewPhase(Name='new phase',SGData=G2IO.P1SGData) # create a new empty phase dict # make sure the ranId is really unique! while self.Phase['ranId'] in usedRanIdList: self.Phase['ranId'] = ran.randint(0,sys.maxint) returnstat = False cellitems = ( '_cell_length_a','_cell_length_b','_cell_length_c', '_cell_angle_alpha','_cell_angle_beta','_cell_angle_gamma',) cellwaveitems = ( '_cell_wave_vector_seq_id', '_cell_wave_vector_x','_cell_wave_vector_y','_cell_wave_vector_z') reqitems = ( '_atom_site_fract_x', '_atom_site_fract_y', '_atom_site_fract_z', ) phasenamefields = ( '_chemical_name_common', '_pd_phase_name', '_chemical_formula_sum' ) try: self.ShowBusy() # this can take a while try: cf = G2IO.ReadCIF(filename) except Exception as detail: self.errors = "Parse or reading of file failed in pyCifRW; check syntax of file in enCIFer or CheckCIF" return False finally: self.DoneBusy() # scan blocks for structural info self.errors = 'Error during scan of blocks for datasets' str_blklist = [] for blk in cf.keys(): for r in reqitems+cellitems: if r not in cf[blk].keys(): break else: str_blklist.append(blk) if not str_blklist: selblk = None # no block to choose elif len(str_blklist) == 1: # only one choice selblk = 0 else: # choose from options choice = [] for blknm in str_blklist: choice.append('') # accumumlate some info about this phase choice[-1] += blknm + ': ' for i in phasenamefields: # get a name for the phase name = cf[blknm].get(i).strip() if name is None or name == '?' or name == '.': continue else: choice[-1] += name.strip()[:20] + ', ' break na = len(cf[blknm].get("_atom_site_fract_x")) if na == 1: choice[-1] += '1 atom' else: choice[-1] += ('%d' % nd) + ' atoms' choice[-1] += ', cell: ' fmt = "%.2f," for i,key in enumerate(cellitems): if i == 3: fmt = "%.f," if i == 5: fmt = "%.f" choice[-1] += fmt % cif.get_number_with_esd( cf[blknm].get(key))[0] sg = cf[blknm].get("_symmetry_space_group_name_H-M",'') if not sg: sg = cf[blknm].get("_space_group_name_H-M_alt",'') if sg: choice[-1] += ', (' + sg.strip() + ')' selblk = self.PhaseSelector( choice, ParentFrame=ParentFrame, title= 'Select a phase from one the CIF data_ blocks below', size=(600,100) ) self.errors = 'Error during reading of selected block' if selblk is None: returnstat = False # no block selected or available else: blknm = str_blklist[selblk] blk = cf[str_blklist[selblk]] E = True Super = False SpGrp = blk.get("_symmetry_space_group_name_H-M",'') if not SpGrp: SpGrp = blk.get("_space_group_name_H-M_alt",'') if not SpGrp: sspgrp = blk.get("_space_group_ssg_name",'').split('(') SpGrp = sspgrp[0] SuperSg = '('+sspgrp[1].replace('\\','') Super = True SuperVec = [[0,0,.1],False,4] # try normalizing the space group, to see if we can pick the space group out of a table SpGrpNorm = G2spc.StandardizeSpcName(SpGrp) if SpGrpNorm: E,SGData = G2spc.SpcGroup(SpGrpNorm) # nope, try the space group "out of the Box" if E and SpGrp: E,SGData = G2spc.SpcGroup(SpGrp) if E: if not SpGrp: self.warnings += 'No space group name was found in the CIF.' self.warnings += '\nThe space group has been set to "P 1". ' self.warnings += "Change this in phase's General tab." else: self.warnings += 'ERROR in space group symbol '+SpGrp self.warnings += '\nThe space group has been set to "P 1". ' self.warnings += "Change this in phase's General tab." self.warnings += '\nAre there spaces separating axial fields?\n\nError msg: ' self.warnings += G2spc.SGErrors(E) SGData = G2IO.SGData # P 1 self.Phase['General']['SGData'] = SGData # cell parameters cell = [] for lbl in cellitems: cell.append(cif.get_number_with_esd(blk[lbl])[0]) Volume = G2lat.calc_V(G2lat.cell2A(cell)) self.Phase['General']['Cell'] = [False,]+cell+[Volume,] # read in atoms self.errors = 'Error during reading of atoms' atomlbllist = [] # table to look up atom IDs atomloop = blk.GetLoop('_atom_site_label') atomkeys = [i.lower() for i in atomloop.keys()] if not blk.get('_atom_site_type_symbol'): self.isodistort_warnings += '\nlack of atom types prevents ISODISTORT processing' if blk.get('_atom_site_aniso_label'): anisoloop = blk.GetLoop('_atom_site_aniso_label') anisokeys = [i.lower() for i in anisoloop.keys()] else: anisoloop = None anisokeys = [] self.Phase['Atoms'] = [] G2AtomDict = { '_atom_site_type_symbol' : 1, '_atom_site_label' : 0, '_atom_site_fract_x' : 3, '_atom_site_fract_y' : 4, '_atom_site_fract_z' : 5, '_atom_site_occupancy' : 6, '_atom_site_aniso_u_11' : 11, '_atom_site_aniso_u_22' : 12, '_atom_site_aniso_u_33' : 13, '_atom_site_aniso_u_12' : 14, '_atom_site_aniso_u_13' : 15, '_atom_site_aniso_u_23' : 16, } ranIdlookup = {} for aitem in atomloop: atomlist = ['','','',0,0,0,1.0,'',0,'I',0.01,0,0,0,0,0,0,0] atomlist[-1] = ran.randint(0,sys.maxint) # add a random Id while atomlist[-1] in ranIdlookup: atomlist[-1] = ran.randint(0,sys.maxint) # make it unique for val,key in zip(aitem,atomkeys): col = G2AtomDict.get(key) if col >= 3: atomlist[col] = cif.get_number_with_esd(val)[0] elif col is not None: atomlist[col] = val elif key in ('_atom_site_thermal_displace_type', '_atom_site_adp_type'): #Iso or Aniso? if val.lower() == 'uani': atomlist[9] = 'A' elif key == '_atom_site_u_iso_or_equiv': atomlist[10] =cif.get_number_with_esd(val)[0] if not atomlist[1] and atomlist[0]: for i in range(2,0,-1): typ = atomlist[0].strip()[:i] if G2elem.CheckElement(typ): atomlist[1] = typ if not atomlist[1]: atomlist[1] = 'Xe' ulbl = '_atom_site_aniso_label' if atomlist[9] == 'A' and atomlist[0] in blk.get(ulbl): for val,key in zip(anisoloop.GetKeyedPacket(ulbl,atomlist[0]), anisokeys): col = G2AtomDict.get(key) if col: atomlist[col] = cif.get_number_with_esd(val)[0] atomlist[7],atomlist[8] = G2spc.SytSym(atomlist[3:6],SGData) atomlist[1] = G2elem.FixValence(atomlist[1]) self.Phase['Atoms'].append(atomlist) ranIdlookup[atomlist[0]] = atomlist[-1] if atomlist[0] in atomlbllist: self.warnings += ' ERROR: repeated atom label: '+atomlist[0] else: atomlbllist.append(atomlist[0]) if len(atomlbllist) != len(self.Phase['Atoms']): self.isodistort_warnings += '\nRepeated atom labels prevents ISODISTORT decode' for lbl in phasenamefields: # get a name for the phase name = blk.get(lbl) if name is None: continue name = name.strip() if name == '?' or name == '.': continue else: break else: # no name found, use block name for lack of a better choice name = blknm self.Phase['General']['Name'] = name.strip()[:20] self.Phase['General']['Super'] = Super if Super: self.Phase['General']['Type'] = 'modulated' self.Phase['General']['SuperVec'] = SuperVec self.Phase['General']['SuperSg'] = SuperSg self.Phase['General']['SSGData'] = G2spc.SSpcGroup(SGData,SuperSg)[1] if not self.isodistort_warnings: if blk.get('_iso_displacivemode_label') or blk.get('_iso_occupancymode_label'): self.errors = "Error while processing ISODISTORT constraints" self.ISODISTORT_proc(blk,atomlbllist,ranIdlookup) else: self.warnings += self.isodistort_warnings returnstat = True except Exception as detail: self.errors += '\n '+str(detail) print 'CIF error:',detail # for testing print sys.exc_info()[0] # for testing import traceback print traceback.format_exc() returnstat = False return returnstat
def ImageRecalibrate(self, data, masks): 'Needs a doc string' import ImageCalibrants as calFile print 'Image recalibration:' time0 = time.time() pixelSize = data['pixelSize'] scalex = 1000. / pixelSize[0] scaley = 1000. / pixelSize[1] pixLimit = data['pixLimit'] cutoff = data['cutoff'] data['rings'] = [] data['ellipses'] = [] if not data['calibrant']: print 'no calibration material selected' return True skip = data['calibskip'] dmin = data['calibdmin'] Bravais, SGs, Cells = calFile.Calibrants[data['calibrant']][:3] HKL = [] for bravais, sg, cell in zip(Bravais, SGs, Cells): A = G2lat.cell2A(cell) if sg: SGData = G2spc.SpcGroup(sg)[1] hkl = G2pwd.getHKLpeak(dmin, SGData, A) HKL += hkl else: hkl = G2lat.GenHBravais(dmin, bravais, A) HKL += hkl HKL = G2lat.sortHKLd(HKL, True, False) varyList = [item for item in data['varyList'] if data['varyList'][item]] parmDict = { 'dist': data['distance'], 'det-X': data['center'][0], 'det-Y': data['center'][1], 'tilt': data['tilt'], 'phi': data['rotation'], 'wave': data['wavelength'], 'dep': data['DetDepth'] } Found = False wave = data['wavelength'] frame = masks['Frames'] tam = ma.make_mask_none(self.ImageZ.shape) if frame: tam = ma.mask_or(tam, MakeFrameMask(data, frame)) for iH, H in enumerate(HKL): if debug: print H dsp = H[3] tth = 2.0 * asind(wave / (2. * dsp)) if tth + abs(data['tilt']) > 90.: print 'next line is a hyperbola - search stopped' break ellipse = GetEllipse(dsp, data) Ring = makeRing(dsp, ellipse, pixLimit, cutoff, scalex, scaley, ma.array(self.ImageZ, mask=tam)) if Ring: if iH >= skip: data['rings'].append(np.array(Ring)) data['ellipses'].append(copy.deepcopy(ellipse + ('r', ))) Found = True elif not Found: #skipping inner rings, keep looking until ring found continue else: #no more rings beyond edge of detector data['ellipses'].append([]) continue # break rings = np.concatenate((data['rings']), axis=0) chisq = FitDetector(rings, varyList, parmDict) data['wavelength'] = parmDict['wave'] data['distance'] = parmDict['dist'] data['center'] = [parmDict['det-X'], parmDict['det-Y']] data['rotation'] = np.mod(parmDict['phi'], 360.0) data['tilt'] = parmDict['tilt'] data['DetDepth'] = parmDict['dep'] data['chisq'] = chisq N = len(data['ellipses']) data['ellipses'] = [] #clear away individual ellipse fits for H in HKL[:N]: ellipse = GetEllipse(H[3], data) data['ellipses'].append(copy.deepcopy(ellipse + ('b', ))) print 'calibration time = ', time.time() - time0 G2plt.PlotImage(self, newImage=True) return True
def ReadJANAPhase(self, filename, parent=None): '''Read a phase from a JANA2006 m50 & m40 files. ''' self.errors = 'Error opening file' file = open(filename, 'Ur') #contains only cell & spcgroup Phase = {} Title = os.path.basename(filename) Compnd = '' Type = 'nuclear' Atoms = [] Atypes = [] SuperVec = [[0, 0, .1], False, 4] S = file.readline() line = 1 SGData = None SuperSg = '' cell = None nqi = 0 while S: self.errors = 'Error reading at line ' + str(line) if 'title' in S and S != 'title\n': Title = S.split()[1] elif 'cell' in S[:4]: cell = S[5:].split() cell = [ float(cell[0]), float(cell[1]), float(cell[2]), float(cell[3]), float(cell[4]), float(cell[5]) ] Volume = G2lat.calc_V(G2lat.cell2A(cell)) elif 'spgroup' in S: if 'X' in S: raise self.ImportException( "Supersymmetry " + S + " too high; GSAS-II limited to (3+1) supersymmetry") SpGrp = S.split()[1] SuperSg = '' if '(' in SpGrp: #supercell symmetry - split in 2 SuperStr = SpGrp.split('(') SpGrp = SuperStr[0] SuperSg = '(' + SuperStr[1] SpGrpNorm = G2spc.StandardizeSpcName(SpGrp) E, SGData = G2spc.SpcGroup(SpGrpNorm) # space group processing failed, try to look up name in table while E: print G2spc.SGErrors(E) dlg = wx.TextEntryDialog( parent, SpGrp[:-1] + ' is invalid \nN.B.: make sure spaces separate axial fields in symbol', 'ERROR in space group symbol', '', style=wx.OK) if dlg.ShowModal() == wx.ID_OK: SpGrp = dlg.GetValue() E, SGData = G2spc.SpcGroup(SpGrp) else: SGData = G2IO.SGData # P 1 self.warnings += '\nThe space group was not interpreted and has been set to "P 1".' self.warnings += "Change this in phase's General tab." dlg.Destroy() SGlines = G2spc.SGPrint(SGData) elif 'qi' in S[:2]: if nqi: raise self.ImportException( "Supersymmetry too high; GSAS-II limited to (3+1) supersymmetry" ) Type = 'modulated' vec = S.split()[1:] SuperVec = [[float(vec[i]) for i in range(3)], False, 4] nqi += 1 elif 'atom' in S[:4]: Atypes.append(S.split()[1]) S = file.readline() line += 1 file.close() #read atoms from m40 file if not SGData: self.warnings += '\nThe space group was not read before atoms and has been set to "P 1". ' self.warnings += "Change this in phase's General tab." SGData = G2IO.SGData # P 1 waveTypes = [ 'Fourier', 'Sawtooth', 'ZigZag', ] filename2 = os.path.splitext(filename)[0] + '.m40' file2 = open(filename2, 'Ur') S = file2.readline() line = 1 self.errors = 'Error reading at line ' + str(line) nAtoms = int(S.split()[0]) for i in range(4): S = file2.readline() for i in range(nAtoms): S1 = file2.readline() S1N = S1.split()[-3:] # no. occ, no. pos waves, no. ADP waves S1N = [int(i) for i in S1N] S1T = list(S1[60:63]) waveType = waveTypes[int(S1T[1])] crenelType = '' Spos = [] Sadp = [] Sfrac = [] Smag = [] XYZ = [float(S1[27:36]), float(S1[36:45]), float(S1[45:54])] SytSym, Mult = G2spc.SytSym(XYZ, SGData) aType = Atypes[int(S1[9:11]) - 1] Name = S1[:8].strip() if S1[11:15].strip() == '1': S2 = file2.readline() Uiso = float(S2[:9]) Uij = [0, 0, 0, 0, 0, 0] IA = 'I' elif S1[11:15].strip() == '2': S2 = file2.readline() IA = 'A' Uiso = 0. Uij = [ float(S2[:9]), float(S2[9:18]), float(S2[18:27]), float(S2[27:36]), float(S2[36:45]), float(S2[45:54]) ] for i in range(S1N[0]): if not i: FS = file2.readline() Sfrac.append(FS[:9]) #'O' or 'delta' = 'length' for crenel if int( S1T[0] ): #"", "Legendre" or "Xharm" in 18:27 for "crenel"! waveType = 'Crenel/Fourier' #all waves 'Fourier' no other choice crenelType = FS[18:27] Sfrac.append( file2.readline()[:18]) #if not crenel = Osin & Ocos # else Osin & Ocos except last one is X40 = 'Center' for i in range(S1N[1]): Spos.append(file2.readline()[:54]) for i in range(S1N[2]): Sadp.append(file2.readline()[:54] + file2.readline()) if sum(S1N): #if any waves: skip mystery line? file2.readline() for i, it in enumerate(Sfrac): print i, it if not i: if 'Crenel' in waveType: vals = [float(it), float(Sfrac[-1][:9])] else: vals = [ float(it), ] else: vals = [float(it[:9]), float(it[9:18])] if 'Crenel' in waveType and i == len(Sfrac) - 1: del Sfrac[-1] break Sfrac[i] = [vals, False] print Sfrac[i] for i, it in enumerate(Spos): if waveType in ['ZigZag', 'Sawtooth'] and not i: vals = [ float(it[:9]), float(it[9:18]), float(it[18:27]), float(it[27:36]) ] else: vals = [ float(it[:9]), float(it[9:18]), float(it[18:27]), float(it[27:36]), float(it[36:45]), float(it[45:54]) ] Spos[i] = [vals, False] for i, it in enumerate(Sadp): vals = [ float(it[:9]), float(it[9:18]), float(it[18:27]), float(it[27:36]), float(it[36:45]), float(it[45:54]), float(it[54:63]), float(it[63:72]), float(it[72:81]), float(it[81:90]), float(it[90:99]), float(it[99:108]) ] Sadp[i] = [vals, False] Atom = [ Name, aType, '', XYZ[0], XYZ[1], XYZ[2], 1.0, SytSym, Mult, IA, Uiso ] Atom += Uij Atom.append(ran.randint(0, sys.maxint)) Atom.append([]) Atom.append([]) Atom.append({ 'SS1': { 'waveType': waveType, 'crenelType': crenelType, 'Sfrac': Sfrac, 'Spos': Spos, 'Sadp': Sadp, 'Smag': Smag } }) #SS2 is for (3+2), etc. Atoms.append(Atom) file2.close() self.errors = 'Error after read complete' if not SGData: raise self.ImportException("No space group (spcgroup entry) found") if not cell: raise self.ImportException("No cell found") Phase = G2IO.SetNewPhase(Name=Title, SGData=SGData, cell=cell + [ Volume, ]) Phase['General']['Type'] = Type Phase['General']['Super'] = nqi Phase['General']['SuperVec'] = SuperVec Phase['General']['SuperSg'] = SuperSg if SuperSg: Phase['General']['SSGData'] = G2spc.SSpcGroup(SGData, SuperSg)[1] Phase['General']['AtomPtrs'] = [3, 1, 7, 9] Phase['Atoms'] = Atoms return Phase
def OnExhaustive(event): SSList = G2spc.SSChoice(Data['SGData']) print(SSList)
def Exporter(self, event=None): '''Export as a SHELX .ins file ''' import re # the export process starts here self.InitExport(event) # load all of the tree into a set of dicts self.loadTree() # create a dict with refined values and their uncertainties self.loadParmDict() if self.ExportSelect(): return # set export parameters; filename = self.filename for phasenam in self.phasenam: phasedict = self.Phases[phasenam] # pointer to current phase info i = self.Phases[phasenam]['pId'] if len( self.phasenam ) > 1: # if more than one filename is included, add a phase # self.filename = os.path.splitext(filename)[1] + "_" + str( i) + self.extension fp = self.OpenFile() # title line self.Write("TITL from " + str(self.G2frame.GSASprojectfile) + ", phase " + str(phasenam)) # get & write cell parameters cell, sig = self.GetCell(phasenam) self.Write( "CELL 0.5 {:.5f} {:.5f} {:.5f} {:.3f} {:.3f} {:.3f}".format( *cell[:6])) # Shelx lattice number lattnum = { 'P': 1, 'I': 2, 'R': 2, 'F': 3, 'A': 4, 'B': 5, 'C': 6 }.get(phasedict['General']['SGData']['SGLatt'], 0) if not phasedict['General']['SGData']['SGInv']: lattnum *= -1 self.Write("LATT " + str(lattnum)) # generate symmetry operations not including centering and center of symmetry for Opr in phasedict['General']['SGData']['SGOps']: sym = G2spc.MT2text(Opr).lower().replace(" ,", ", ") self.Write('SYMM ' + G2IO.trim(sym)) # scan through atom types, count the number of times that each element occurs AtomsList = self.GetAtoms(phasenam) maxmult = 0 elemtypes = {} for lbl, typ, mult, xyz, td in AtomsList: maxmult = max(maxmult, mult) typ = re.search('[A-Za-z]+', typ).group(0) typ = typ[0:2] typ = typ[0].upper() + typ[1:].lower() if elemtypes.get(typ) is None: elemtypes[typ] = 1 else: elemtypes[typ] += 1 # create scattering factor record s = "SFAC" elemlist = sorted(elemtypes) for elem in elemlist: s += " " + elem self.Write(s) # handle atom records count = {} for lbl, typ, mult, xyz, td in AtomsList: typ = re.search('[A-Za-z]+', typ).group(0) typ = typ[0:2] typ = typ[0].upper() + typ[1:].lower() if count.get(typ) is None: count[typ] = 0 else: count[typ] += 1 # make a unique <=4 character label, if possible if elemtypes[typ] <= 99: lbl = "{:s}{:d}".format(typ, count[typ]) else: # more than 99 atoms, use hexadecimal notation lbl = typ + "{:X}".format(count[typ])[-2:] sfnum = elemlist.index( typ) + 1 # element number in scattering factor list l = lbl + " " + str(sfnum) l += " {:.5f} {:.5f} {:.5f}".format(*[x[0] for x in xyz[:3]]) if mult == maxmult: m = 1 else: m = 1. * mult / maxmult if xyz[3][0] == 1: # frac occ = 10 + m else: occ = m * xyz[3][0] l += " {:.3f}".format(occ) for val, sig in td: l += " {:.3f}".format(val) self.Write(l) self.Write('END') self.CloseFile() print('Phase ' + phasenam + ' written to file ' + self.fullpath)
def ReadPDBPhase(self, filename, parent=None): '''Read a phase from a PDB file. ''' EightPiSq = 8. * math.pi**2 self.errors = 'Error opening file' file = open(filename, 'Ur') Phase = {} Title = '' Compnd = '' Atoms = [] A = np.zeros(shape=(3, 3)) S = file.readline() line = 1 SGData = None cell = None while S: self.errors = 'Error reading at line ' + str(line) Atom = [] if 'TITLE' in S[:5]: Title = S[10:72].strip() elif 'COMPND ' in S[:10]: Compnd = S[10:72].strip() elif 'CRYST' in S[:5]: abc = S[7:34].split() angles = S[34:55].split() cell = [ float(abc[0]), float(abc[1]), float(abc[2]), float(angles[0]), float(angles[1]), float(angles[2]) ] Volume = G2lat.calc_V(G2lat.cell2A(cell)) AA, AB = G2lat.cell2AB(cell) SpGrp = S[55:65] E, SGData = G2spc.SpcGroup(SpGrp) # space group processing failed, try to look up name in table if E: SpGrpNorm = G2spc.StandardizeSpcName(SpGrp) if SpGrpNorm: E, SGData = G2spc.SpcGroup(SpGrpNorm) while E: print G2spc.SGErrors(E) dlg = wx.TextEntryDialog( parent, SpGrp[:-1] + ' is invalid \nN.B.: make sure spaces separate axial fields in symbol', 'ERROR in space group symbol', '', style=wx.OK) if dlg.ShowModal() == wx.ID_OK: SpGrp = dlg.GetValue() E, SGData = G2spc.SpcGroup(SpGrp) else: SGData = G2IO.SGData # P 1 self.warnings += '\nThe space group was not interpreted and has been set to "P 1".' self.warnings += "Change this in phase's General tab." dlg.Destroy() SGlines = G2spc.SGPrint(SGData) for l in SGlines: print l elif 'SCALE' in S[:5]: V = S[10:41].split() A[int(S[5]) - 1] = [float(V[0]), float(V[1]), float(V[2])] elif 'ATOM' in S[:4] or 'HETATM' in S[:6]: if not SGData: self.warnings += '\nThe space group was not read before atoms and has been set to "P 1". ' self.warnings += "Change this in phase's General tab." SGData = G2IO.SGData # P 1 XYZ = [float(S[31:39]), float(S[39:47]), float(S[47:55])] XYZ = np.inner(AB, XYZ) XYZ = np.where(abs(XYZ) < 0.00001, 0, XYZ) SytSym, Mult = G2spc.SytSym(XYZ, SGData) Uiso = float(S[61:67]) / EightPiSq Type = S[12:14].lower() if Type[0] in '123456789': Type = Type[1:] Atom = [ S[22:27].strip(), S[17:20].upper(), S[20:22], S[12:17].strip(), Type.strip().capitalize(), '', XYZ[0], XYZ[1], XYZ[2], float(S[55:61]), SytSym, Mult, 'I', Uiso, 0, 0, 0, 0, 0, 0 ] S = file.readline() line += 1 if 'ANISOU' in S[:6]: Uij = S[30:72].split() Uij = [ float(Uij[0]) / 10000., float(Uij[1]) / 10000., float(Uij[2]) / 10000., float(Uij[3]) / 10000., float(Uij[4]) / 10000., float(Uij[5]) / 10000. ] Atom = Atom[:14] + Uij Atom[12] = 'A' Atom.append(ran.randint(0, sys.maxint)) Atoms.append(Atom) S = file.readline() line += 1 file.close() self.errors = 'Error after read complete' if Title: PhaseName = Title elif Compnd: PhaseName = Compnd else: PhaseName = 'None' if not SGData: raise self.ImportException("No space group (CRYST entry) found") if not cell: raise self.ImportException("No cell (CRYST entry) found") Phase = G2IO.SetNewPhase(Name=PhaseName, SGData=SGData, cell=cell + [ Volume, ]) Phase['General']['Type'] = 'macromolecular' Phase['General']['AtomPtrs'] = [6, 4, 10, 12] Phase['Atoms'] = Atoms return Phase
def ReadINSPhase(self, filename, parent=None): '''Read a phase from a INS file. ''' Shelx = [ 'TITL', 'CELL', 'ZERR', 'LATT', 'SYMM', 'SFAC', 'DISP', 'UNIT', 'LAUE', 'EADP', 'MORE', 'TIME', 'HKLF', 'OMIT', 'SHEL', 'BASF', 'TWIN', 'EXTI', 'SWAT', 'HOPE', 'MERG', 'SPEC', 'RESI', 'RTAB', 'MPLA', 'HFIX', 'MOVE', 'ANIS', 'AFIX', 'FRAG', 'FEND', 'EXYZ', 'EDAP', 'EQIV', 'CONN', 'PART', 'BIND', 'FREE', 'DFIX', 'DANG', 'BUMP', 'SAME', 'SADI', 'CHIV', 'FLAT', 'DELU', 'SIMU', 'DEFS', 'ISOR', 'NCSY', 'SUMP', 'L.S.', 'CGLS', 'BLOC', 'DAMP', 'STIR', 'WGHT', 'FVAR', 'BOND', 'CONF', 'MPLA', 'HTAB', 'LIST', 'ACTA', 'SIZE', 'TEMP', 'WPDB', 'FMAP', 'GRID', 'PLAN', 'MOLE' ] self.errors = 'Error opening file' fp = open(filename, 'Ur') Phase = {} Title = '' Atoms = [] aTypes = [] S = fp.readline() line = 1 SGData = None cell = None while S: if '!' in S: S = S.split('!')[0] self.errors = 'Error reading at line ' + str(line) Atom = [] if 'TITL' in S[:4].upper(): Title = S[4:72].strip() elif not S.strip(): pass elif 'CELL' in S[:4].upper(): cellRec = S.split() abc = cellRec[2:5] angles = cellRec[5:8] cell = [ float(abc[0]), float(abc[1]), float(abc[2]), float(angles[0]), float(angles[1]), float(angles[2]) ] Volume = G2lat.calc_V(G2lat.cell2A(cell)) AA, AB = G2lat.cell2AB(cell) SGData = G2obj.P1SGData # P 1 self.warnings += '\nThe space group is not given in an ins file and has been set to "P 1".' self.warnings += "\nChange this in phase's General tab; NB: it might be in the Phase name." elif S[:4].upper() in 'SFAC': aTypes = S[4:].split() if 'H' in aTypes: self.warnings += '\n\nHydrogen atoms found; consider replacing them with stereochemically tied ones' self.warnings += '\nas Shelx constraints & HFIX commands are ignored.' self.warnings += "\nDo 'Edit/Insert H atoms' in this phase's Atoms tab after deleting the old ones." elif S[0] == 'Q': pass elif '\x1a' in S[:4]: pass elif S[:3].upper() == 'REM': pass elif S[:3].upper() == 'END': pass elif S[:4].strip().upper( ) not in Shelx: #this will find an atom record! AtRec = S.split() Atype = aTypes[int(AtRec[1]) - 1] Aname = AtRec[0] Afrac = abs(float(AtRec[5])) % 10. x, y, z = AtRec[2:5] XYZ = np.array([float(x), float(y), float(z)]) XYZ = np.where(np.abs(XYZ) < 0.00001, 0, XYZ) SytSym, Mult = G2spc.SytSym(XYZ, SGData)[:2] if '=' not in S: IA = 'I' Uiso = float(AtRec[6]) if Uiso < 0. or Uiso > 1.0: Uiso = 0.025 Uij = [0. for i in range(6)] else: IA = 'A' Uiso = 0. Ustr = AtRec[6:8] S = fp.readline() if '!' in S: S = S.split('!')[0] AtRec = S.split() line += 1 Ustr += AtRec Uij = [float(Ustr[i]) for i in range(6)] Uij = Uij[0:3] + [Uij[5], Uij[4], Uij[3]] Atom = [ Aname, Atype, '', XYZ[0], XYZ[1], XYZ[2], Afrac, SytSym, Mult, IA, Uiso ] Atom += Uij Atom.append(ran.randint(0, sys.maxsize)) Atoms.append(Atom) S = fp.readline() line += 1 fp.close() self.errors = 'Error after read complete' Phase = G2obj.SetNewPhase(Name='ShelX phase', SGData=SGData, cell=cell + [ Volume, ]) Phase['General']['Name'] = Title Phase['General']['Type'] = 'nuclear' Phase['General']['AtomPtrs'] = [3, 1, 7, 9] Phase['Atoms'] = Atoms return Phase
def ImageCalibrate(self, data): 'Needs a doc string' import copy import ImageCalibrants as calFile print 'Image calibration:' time0 = time.time() ring = data['ring'] pixelSize = data['pixelSize'] scalex = 1000. / pixelSize[0] scaley = 1000. / pixelSize[1] pixLimit = data['pixLimit'] cutoff = data['cutoff'] varyDict = data['varyList'] if varyDict['dist'] and varyDict['wave']: print 'ERROR - you can not simultaneously calibrate distance and wavelength' return False if len(ring) < 5: print 'ERROR - not enough inner ring points for ellipse' return False #fit start points on inner ring data['ellipses'] = [] data['rings'] = [] outE = FitEllipse(ring) fmt = '%s X: %.3f, Y: %.3f, phi: %.3f, R1: %.3f, R2: %.3f' fmt2 = '%s X: %.3f, Y: %.3f, phi: %.3f, R1: %.3f, R2: %.3f, chi**2: %.3f, Np: %d' if outE: print fmt % ('start ellipse: ', outE[0][0], outE[0][1], outE[1], outE[2][0], outE[2][1]) ellipse = outE else: return False #setup 360 points on that ring for "good" fit data['ellipses'].append(ellipse[:] + ('g', )) Ring = makeRing(1.0, ellipse, pixLimit, cutoff, scalex, scaley, self.ImageZ) if Ring: ellipse = FitEllipse(Ring) Ring = makeRing(1.0, ellipse, pixLimit, cutoff, scalex, scaley, self.ImageZ) #do again ellipse = FitEllipse(Ring) else: print '1st ring not sufficiently complete to proceed' return False if debug: print fmt2 % ('inner ring: ', ellipse[0][0], ellipse[0][1], ellipse[1], ellipse[2][0], ellipse[2][1], 0., len(Ring) ) #cent,phi,radii data['ellipses'].append(ellipse[:] + ('r', )) data['rings'].append(np.array(Ring)) G2plt.PlotImage(self, newImage=True) #setup for calibration data['rings'] = [] if not data['calibrant']: print 'no calibration material selected' return True skip = data['calibskip'] dmin = data['calibdmin'] #generate reflection set Bravais, SGs, Cells = calFile.Calibrants[data['calibrant']][:3] HKL = [] for bravais, sg, cell in zip(Bravais, SGs, Cells): A = G2lat.cell2A(cell) if sg: SGData = G2spc.SpcGroup(sg)[1] hkl = G2pwd.getHKLpeak(dmin, SGData, A) HKL += hkl else: hkl = G2lat.GenHBravais(dmin, bravais, A) HKL += hkl HKL = G2lat.sortHKLd(HKL, True, False)[skip:] #set up 1st ring elcent, phi, radii = ellipse #from fit of 1st ring dsp = HKL[0][3] print '1st ring: try %.4f' % (dsp) if varyDict['dist']: wave = data['wavelength'] tth = 2.0 * asind(wave / (2. * dsp)) else: #varyDict['wave']! dist = data['distance'] tth = npatan2d(radii[0], dist) data['wavelength'] = wave = 2.0 * dsp * sind(tth / 2.0) Ring0 = makeRing(dsp, ellipse, 3, cutoff, scalex, scaley, self.ImageZ) ttth = nptand(tth) stth = npsind(tth) ctth = npcosd(tth) #1st estimate of tilt; assume ellipse - don't know sign though if varyDict['tilt']: tilt = npasind(np.sqrt(max(0., 1. - (radii[0] / radii[1])**2)) * ctth) if not tilt: print 'WARNING - selected ring was fitted as a circle' print ' - if detector was tilted we suggest you skip this ring - WARNING' else: tilt = data['tilt'] #1st estimate of dist: sample to detector normal to plane if varyDict['dist']: data['distance'] = dist = radii[0]**2 / (ttth * radii[1]) else: dist = data['distance'] if varyDict['tilt']: #ellipse to cone axis (x-ray beam); 2 choices depending on sign of tilt zdisp = radii[1] * ttth * tand(tilt) zdism = radii[1] * ttth * tand(-tilt) #cone axis position; 2 choices. Which is right? #NB: zdisp is || to major axis & phi is rotation of minor axis #thus shift from beam to ellipse center is [Z*sin(phi),-Z*cos(phi)] centp = [elcent[0] + zdisp * sind(phi), elcent[1] - zdisp * cosd(phi)] centm = [elcent[0] + zdism * sind(phi), elcent[1] - zdism * cosd(phi)] #check get same ellipse parms either way #now do next ring; estimate either way & do a FitDetector each way; best fit is correct one fail = True i2 = 1 while fail: dsp = HKL[i2][3] print '2nd ring: try %.4f' % (dsp) tth = 2.0 * asind(wave / (2. * dsp)) ellipsep = GetEllipse2(tth, 0., dist, centp, tilt, phi) print fmt % ('plus ellipse :', ellipsep[0][0], ellipsep[0][1], ellipsep[1], ellipsep[2][0], ellipsep[2][1]) Ringp = makeRing(dsp, ellipsep, 3, cutoff, scalex, scaley, self.ImageZ) parmDict = { 'dist': dist, 'det-X': centp[0], 'det-Y': centp[1], 'tilt': tilt, 'phi': phi, 'wave': wave, 'dep': 0.0 } varyList = [item for item in varyDict if varyDict[item]] if len(Ringp) > 10: chip = FitDetector(np.array(Ring0 + Ringp), varyList, parmDict, True) tiltp = parmDict['tilt'] phip = parmDict['phi'] centp = [parmDict['det-X'], parmDict['det-Y']] fail = False else: chip = 1e6 ellipsem = GetEllipse2(tth, 0., dist, centm, -tilt, phi) print fmt % ('minus ellipse:', ellipsem[0][0], ellipsem[0][1], ellipsem[1], ellipsem[2][0], ellipsem[2][1]) Ringm = makeRing(dsp, ellipsem, 3, cutoff, scalex, scaley, self.ImageZ) if len(Ringm) > 10: parmDict['tilt'] *= -1 chim = FitDetector(np.array(Ring0 + Ringm), varyList, parmDict, True) tiltm = parmDict['tilt'] phim = parmDict['phi'] centm = [parmDict['det-X'], parmDict['det-Y']] fail = False else: chim = 1e6 if fail: i2 += 1 if chip < chim: data['tilt'] = tiltp data['center'] = centp data['rotation'] = phip else: data['tilt'] = tiltm data['center'] = centm data['rotation'] = phim data['ellipses'].append(ellipsep[:] + ('b', )) data['rings'].append(np.array(Ringp)) data['ellipses'].append(ellipsem[:] + ('r', )) data['rings'].append(np.array(Ringm)) G2plt.PlotImage(self, newImage=True) parmDict = { 'dist': data['distance'], 'det-X': data['center'][0], 'det-Y': data['center'][1], 'tilt': data['tilt'], 'phi': data['rotation'], 'wave': data['wavelength'], 'dep': data['DetDepth'] } varyList = [item for item in varyDict if varyDict[item]] data['rings'] = [] data['ellipses'] = [] for i, H in enumerate(HKL): dsp = H[3] tth = 2.0 * asind(wave / (2. * dsp)) if tth + abs(data['tilt']) > 90.: print 'next line is a hyperbola - search stopped' break if debug: print 'HKLD:', H[:4], '2-theta: %.4f' % (tth) elcent, phi, radii = ellipse = GetEllipse(dsp, data) data['ellipses'].append(copy.deepcopy(ellipse + ('g', ))) if debug: print fmt % ('predicted ellipse:', elcent[0], elcent[1], phi, radii[0], radii[1]) Ring = makeRing(dsp, ellipse, pixLimit, cutoff, scalex, scaley, self.ImageZ) if Ring: data['rings'].append(np.array(Ring)) rings = np.concatenate((data['rings']), axis=0) if i: chisq = FitDetector(rings, varyList, parmDict, False) data['distance'] = parmDict['dist'] data['center'] = [parmDict['det-X'], parmDict['det-Y']] data['rotation'] = parmDict['phi'] data['tilt'] = parmDict['tilt'] data['DetDepth'] = parmDict['dep'] data['chisq'] = chisq elcent, phi, radii = ellipse = GetEllipse(dsp, data) if debug: print fmt2 % ('fitted ellipse: ', elcent[0], elcent[1], phi, radii[0], radii[1], chisq, len(rings)) data['ellipses'].append(copy.deepcopy(ellipse + ('r', ))) # G2plt.PlotImage(self,newImage=True) else: if debug: print 'insufficient number of points in this ellipse to fit' # break G2plt.PlotImage(self, newImage=True) fullSize = len(self.ImageZ) / scalex if 2 * radii[1] < .9 * fullSize: print 'Are all usable rings (>25% visible) used? Try reducing Min ring I/Ib' N = len(data['ellipses']) if N > 2: FitDetector(rings, varyList, parmDict) data['wavelength'] = parmDict['wave'] data['distance'] = parmDict['dist'] data['center'] = [parmDict['det-X'], parmDict['det-Y']] data['rotation'] = parmDict['phi'] data['tilt'] = parmDict['tilt'] data['DetDepth'] = parmDict['dep'] for H in HKL[:N]: ellipse = GetEllipse(H[3], data) data['ellipses'].append(copy.deepcopy(ellipse + ('b', ))) print 'calibration time = ', time.time() - time0 G2plt.PlotImage(self, newImage=True) return True
def findMV(peaks, controls, ssopt, Inst, dlg): def Val2Vec(vec, Vref, values): Vec = [] i = 0 for j, r in enumerate(Vref): if r: if values.size > 1: Vec.append(max(0.0, min(1.0, values[i]))) else: Vec.append(max(0.0, min(1.0, values))) i += 1 else: Vec.append(vec[j]) return np.array(Vec) def ZSSfunc(values, peaks, dmin, Inst, SGData, SSGData, vec, Vref, maxH, A, wave, Z, dlg=None): Vec = Val2Vec(vec, Vref, values) HKL = G2pwd.getHKLMpeak(dmin, Inst, SGData, SSGData, Vec, maxH, A) Peaks = np.array(IndexSSPeaks(peaks, HKL)[1]).T Qo = 1. / Peaks[-2]**2 Qc = G2lat.calc_rDsqZSS(Peaks[4:8], A, Vec, Z, Peaks[0], wave) chi = np.sum((Qo - Qc)**2) if dlg: dlg.Pulse() return chi if 'C' in Inst['Type'][0]: wave = G2mth.getWave(Inst) else: difC = Inst['difC'][1] SGData = G2spc.SpcGroup(controls[13])[1] SSGData = G2spc.SSpcGroup(SGData, ssopt['ssSymb'])[1] A = G2lat.cell2A(controls[6:12]) Z = controls[1] Vref = [True if x in ssopt['ssSymb'] else False for x in ['a', 'b', 'g']] values = [] ranges = [] for v, r in zip(ssopt['ModVec'], Vref): if r: ranges += [ slice(.02, .98, .05), ] values += [ v, ] dmin = getDmin(peaks) - 0.005 Peaks = np.copy(np.array(peaks).T) result = so.brute(ZSSfunc, ranges, finish=so.fmin_cg, args=(peaks, dmin, Inst, SGData, SSGData, ssopt['ModVec'], Vref, ssopt['maxH'], A, wave, Z, dlg)) return Val2Vec(ssopt['ModVec'], Vref, result)