def refinePeaks(peaks,ibrav,A,ifX20=True): 'needs a doc string' dmin = getDmin(peaks) smin = 1.0e10 pwr = 8 maxTries = 10 OK = False tries = 0 sgtype = G2lat.make_sgtype(ibrav) HKL = G2lat.GenHBravais(dmin,ibrav,A, sg_type=sgtype) while len(HKL) > 2 and IndexPeaks(peaks,HKL)[0]: Pwr = pwr - (tries % 2) HKL = [] tries += 1 osmin = smin oldA = A[:] Vold = G2lat.calc_V(oldA) OK,smin,A,result = FitHKL(ibrav,peaks,A,Pwr) Vnew = G2lat.calc_V(A) if Vnew > 2.0*Vold or Vnew < 2.: A = ranAbyR(ibrav,oldA,tries+1,maxTries,ran2axis) OK = False continue try: HKL = G2lat.GenHBravais(dmin,ibrav,A, sgtype) except FloatingPointError: A = oldA OK = False break if len(HKL) == 0: break #absurd cell obtained! rat = (osmin-smin)/smin if abs(rat) < 1.0e-5 or not OK: break if tries > maxTries: break if OK: OK,smin,A,result = FitHKL(ibrav,peaks,A,2) Peaks = np.array(peaks).T H = Peaks[4:7] try: Peaks[8] = 1./np.sqrt(G2lat.calc_rDsq(H,A)) peaks = Peaks.T except FloatingPointError: A = oldA M20,X20 = calc_M20(peaks,HKL,ifX20) return len(HKL),M20,X20,A
def refinePeaks(peaks,ibrav,A,ifX20=True): 'needs a doc string' dmin = getDmin(peaks) smin = 1.0e10 pwr = 8 maxTries = 10 OK = False tries = 0 HKL = G2lat.GenHBravais(dmin,ibrav,A) while len(HKL) > 2 and IndexPeaks(peaks,HKL)[0]: Pwr = pwr - (tries % 2) HKL = [] tries += 1 osmin = smin oldA = A[:] Vold = G2lat.calc_V(oldA) OK,smin,A,result = FitHKL(ibrav,peaks,A,Pwr) Vnew = G2lat.calc_V(A) if Vnew > 2.0*Vold or Vnew < 2.: A = ranAbyR(ibrav,oldA,tries+1,maxTries,ran2axis) OK = False continue try: HKL = G2lat.GenHBravais(dmin,ibrav,A) except FloatingPointError: A = oldA OK = False break if len(HKL) == 0: break #absurd cell obtained! rat = (osmin-smin)/smin if abs(rat) < 1.0e-5 or not OK: break if tries > maxTries: break if OK: OK,smin,A,result = FitHKL(ibrav,peaks,A,2) Peaks = np.array(peaks).T H = Peaks[4:7] try: Peaks[8] = 1./np.sqrt(G2lat.calc_rDsq(H,A)) peaks = Peaks.T except FloatingPointError: A = oldA M20,X20 = calc_M20(peaks,HKL,ifX20) return len(HKL),M20,X20,A
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 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 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 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 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 scaleAbyV(A,V): 'needs a doc string' v = G2lat.calc_V(A) scale = math.exp(math.log(v/V)/3.)**2 for i in range(6): A[i] *= scale
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 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 DoIndexPeaks(peaks, controls, bravais, ifX20=True): 'needs a doc string' delt = 0.005 #lowest d-spacing cushion - can be fixed? amin = 2.5 amax = 5.0 * getDmax(peaks) dmin = getDmin(peaks) - delt bravaisNames = [ 'Cubic-F', 'Cubic-I', 'Cubic-P', 'Trigonal-R', 'Trigonal/Hexagonal-P', 'Tetragonal-I', 'Tetragonal-P', 'Orthorhombic-F', 'Orthorhombic-I', 'Orthorhombic-C', 'Orthorhombic-P', 'Monoclinic-C', 'Monoclinic-P', 'Triclinic' ] tries = [ '1st', '2nd', '3rd', '4th', '5th', '6th', '7th', '8th', '9th', '10th' ] N1s = [1, 1, 1, 5, 5, 5, 5, 50, 50, 50, 50, 50, 50, 200] N2s = [1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4] Nm = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 4] Nobs = len(peaks) zero, ncno = controls[1:3] ncMax = Nobs * ncno print "%s %8.3f %8.3f" % ('lattice parameter range = ', amin, amax) print "%s %.4f %s %d %s %d" % ('Zero =', zero, 'Nc/No max =', ncno, ' Max Nc =', ncno * Nobs) cells = [] for ibrav in range(14): begin = time.time() if bravais[ibrav]: print 'cell search for ', bravaisNames[ibrav] print ' M20 X20 Nc a b c alpha beta gamma volume V-test' V1 = controls[3] bestM20 = 0 topM20 = 0 cycle = 0 while cycle < 5: dlg = wx.ProgressDialog( "Generated reflections", tries[cycle] + " cell search for " + bravaisNames[ibrav], ncMax, style=wx.PD_ELAPSED_TIME | wx.PD_AUTO_HIDE | wx.PD_REMAINING_TIME | wx.PD_CAN_ABORT) screenSize = wx.ClientDisplayRect() Size = dlg.GetSize() dlg.SetPosition( wx.Point(screenSize[2] - Size[0] - 305, screenSize[1] + 5)) try: GoOn = True while GoOn: #Loop over increment of volume N2 = 0 while N2 < N2s[ibrav]: #Table 2 step (iii) if ibrav > 2: if not N2: A = [] GoOn, Nc, M20, X20, A = findBestCell( dlg, ncMax, A, Nm[ibrav] * N1s[ibrav], ibrav, peaks, V1, ifX20) if A: GoOn, Nc, M20, X20, A = findBestCell( dlg, ncMax, A[:], N1s[ibrav], ibrav, peaks, 0, ifX20) else: GoOn, Nc, M20, X20, A = findBestCell( dlg, ncMax, 0, Nm[ibrav] * N1s[ibrav], ibrav, peaks, V1, ifX20) if Nc >= ncMax: GoOn = False break elif 3 * Nc < Nobs: N2 = 10 break else: if not GoOn: break if M20 > 1.0: bestM20 = max(bestM20, M20) A = halfCell(ibrav, A[:], peaks) if ibrav in [12]: A = monoCellReduce(ibrav, A[:]) HKL = G2lat.GenHBravais(dmin, ibrav, A) peaks = IndexPeaks(peaks, HKL)[1] a, b, c, alp, bet, gam = G2lat.A2cell(A) V = G2lat.calc_V(A) if M20 >= 2.0: print "%10.3f %3d %3d %10.5f %10.5f %10.5f %10.3f %10.3f %10.3f %10.2f %10.2f" % ( M20, X20, Nc, a, b, c, alp, bet, gam, V, V1) cells.append([ M20, X20, ibrav, a, b, c, alp, bet, gam, V, False, False ]) if not GoOn: break N2 += 1 if ibrav < 11: V1 *= 1.1 elif ibrav in range(11, 14): V1 *= 1.05 if not GoOn: if bestM20 > topM20: topM20 = bestM20 if cells: V1 = cells[0][9] else: V1 = 25 ncMax += Nobs cycle += 1 print 'Restart search, new Max Nc = ', ncMax else: cycle = 10 finally: dlg.Destroy() print '%s%s%s%s'%('finished cell search for ',bravaisNames[ibrav], \ ', elapsed time = ',G2lat.sec2HMS(time.time()-begin)) if cells: return True, dmin, cells else: return False, 0, []
def DoIndexPeaks(peaks,controls,bravais,ifX20=True): 'needs a doc string' delt = 0.005 #lowest d-spacing cushion - can be fixed? amin = 2.5 amax = 5.0*getDmax(peaks) dmin = getDmin(peaks)-delt bravaisNames = ['Cubic-F','Cubic-I','Cubic-P','Trigonal-R','Trigonal/Hexagonal-P', 'Tetragonal-I','Tetragonal-P','Orthorhombic-F','Orthorhombic-I','Orthorhombic-C', 'Orthorhombic-P','Monoclinic-C','Monoclinic-P','Triclinic'] tries = ['1st','2nd','3rd','4th','5th','6th','7th','8th','9th','10th'] N1s = [1,1,1, 5,5, 5,5, 50,50,50,50, 50,50, 200] N2s = [1,1,1, 2,2, 2,2, 2,2,2,2, 2,2, 4] Nm = [1,1,1, 1,1, 1,1, 1,1,1,1, 2,2, 4] Nobs = len(peaks) zero,ncno = controls[1:3] ncMax = Nobs*ncno print "%s %8.3f %8.3f" % ('lattice parameter range = ',amin,amax) print "%s %.4f %s %d %s %d" % ('Zero =',zero,'Nc/No max =',ncno,' Max Nc =',ncno*Nobs) cells = [] for ibrav in range(14): begin = time.time() if bravais[ibrav]: print 'cell search for ',bravaisNames[ibrav] print ' M20 X20 Nc a b c alpha beta gamma volume V-test' V1 = controls[3] bestM20 = 0 topM20 = 0 cycle = 0 while cycle < 5: dlg = wx.ProgressDialog("Generated reflections",tries[cycle]+" cell search for "+bravaisNames[ibrav],ncMax, style = wx.PD_ELAPSED_TIME|wx.PD_AUTO_HIDE|wx.PD_REMAINING_TIME|wx.PD_CAN_ABORT) screenSize = wx.ClientDisplayRect() Size = dlg.GetSize() dlg.SetPosition(wx.Point(screenSize[2]-Size[0]-305,screenSize[1]+5)) try: GoOn = True while GoOn: #Loop over increment of volume N2 = 0 while N2 < N2s[ibrav]: #Table 2 step (iii) if ibrav > 2: if not N2: A = [] GoOn,Nc,M20,X20,A = findBestCell(dlg,ncMax,A,Nm[ibrav]*N1s[ibrav],ibrav,peaks,V1,ifX20) if A: GoOn,Nc,M20,X20,A = findBestCell(dlg,ncMax,A[:],N1s[ibrav],ibrav,peaks,0,ifX20) else: GoOn,Nc,M20,X20,A = findBestCell(dlg,ncMax,0,Nm[ibrav]*N1s[ibrav],ibrav,peaks,V1,ifX20) if Nc >= ncMax: GoOn = False break elif 3*Nc < Nobs: N2 = 10 break else: if not GoOn: break if M20 > 1.0: bestM20 = max(bestM20,M20) A = halfCell(ibrav,A[:],peaks) if ibrav in [12]: A = monoCellReduce(ibrav,A[:]) HKL = G2lat.GenHBravais(dmin,ibrav,A) peaks = IndexPeaks(peaks,HKL)[1] a,b,c,alp,bet,gam = G2lat.A2cell(A) V = G2lat.calc_V(A) if M20 >= 2.0: print "%10.3f %3d %3d %10.5f %10.5f %10.5f %10.3f %10.3f %10.3f %10.2f %10.2f" % (M20,X20,Nc,a,b,c,alp,bet,gam,V,V1) cells.append([M20,X20,ibrav,a,b,c,alp,bet,gam,V,False,False]) if not GoOn: break N2 += 1 if ibrav < 11: V1 *= 1.1 elif ibrav in range(11,14): V1 *= 1.05 if not GoOn: if bestM20 > topM20: topM20 = bestM20 if cells: V1 = cells[0][9] else: V1 = 25 ncMax += Nobs cycle += 1 print 'Restart search, new Max Nc = ',ncMax else: cycle = 10 finally: dlg.Destroy() print '%s%s%s%s'%('finished cell search for ',bravaisNames[ibrav], \ ', elapsed time = ',G2lat.sec2HMS(time.time()-begin)) if cells: return True,dmin,cells else: return False,0,[]
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 DoIndexPeaks(peaks,controls,bravais,dlg,ifX20=True,timeout=None): 'needs a doc string' delt = 0.005 #lowest d-spacing cushion - can be fixed? amin = 2.5 amax = 5.0*getDmax(peaks) dmin = getDmin(peaks)-delt bravaisNames = ['Cubic-F','Cubic-I','Cubic-P','Trigonal-R','Trigonal/Hexagonal-P', 'Tetragonal-I','Tetragonal-P','Orthorhombic-F','Orthorhombic-I','Orthorhombic-A', 'Orthorhombic-B','Orthorhombic-C', 'Orthorhombic-P','Monoclinic-I','Monoclinic-C','Monoclinic-P','Triclinic'] tries = ['1st','2nd','3rd','4th','5th','6th','7th','8th','9th','10th'] N1s = [1,1,1, 5,5, 5,5, 50,50,50,50,50,50, 100,100,100, 200] N2s = [1,1,1, 2,2, 2,2, 2,2,2,2,2,2, 2,2,2, 4] Nm = [1,1,1, 1,1, 1,1, 1,1,1,1,1,1, 2,2,2, 4] notUse = 0 for peak in peaks: if not peak[2]: notUse += 1 Nobs = len(peaks)-notUse zero,ncno = controls[1:3] ncMax = Nobs*ncno print ("%s %8.3f %8.3f" % ('lattice parameter range = ',amin,amax)) print ("%s %.4f %s %d %s %d" % ('Zero =',zero,'Nc/No max =',ncno,' Max Nc =',ncno*Nobs)) cells = [] lastcell = np.zeros(7) for ibrav in range(17): begin = time.time() if bravais[ibrav]: print ('cell search for ',bravaisNames[ibrav]) print (' M20 X20 Nc a b c alpha beta gamma volume V-test') V1 = controls[3] bestM20 = 0 topM20 = 0 cycle = 0 while cycle < 5: if dlg: dlg.Raise() dlg.Update(0,newmsg=tries[cycle]+" cell search for "+bravaisNames[ibrav]) try: GoOn = True while GoOn: #Loop over increment of volume N2 = 0 while N2 < N2s[ibrav]: #Table 2 step (iii) if time.time() - begin > timeout: GoOn = False break if ibrav > 2: if not N2: A = [] GoOn,Skip,Nc,M20,X20,A = findBestCell(dlg,ncMax,A,Nm[ibrav]*N1s[ibrav],ibrav,peaks,V1,ifX20) if Skip: break if A: GoOn,Skip,Nc,M20,X20,A = findBestCell(dlg,ncMax,A[:],N1s[ibrav],ibrav,peaks,0,ifX20) else: GoOn,Skip,Nc,M20,X20,A = findBestCell(dlg,ncMax,0,Nm[ibrav]*N1s[ibrav],ibrav,peaks,V1,ifX20) if Skip: break elif Nc >= ncMax: GoOn = False break elif 3*Nc < Nobs: N2 = 10 break else: if not GoOn: break if 1.e6 > M20 > 1.0: #exclude nonsense bestM20 = max(bestM20,M20) A = halfCell(ibrav,A[:],peaks) if ibrav in [14,]: A = monoCellReduce(ibrav,A[:]) HKL = G2lat.GenHBravais(dmin,ibrav,A) peaks = IndexPeaks(peaks,HKL)[1] a,b,c,alp,bet,gam = G2lat.A2cell(A) V = G2lat.calc_V(A) if M20 >= 10.0 and X20 <= 2: cell = [M20,X20,ibrav,a,b,c,alp,bet,gam,V,False,False, Nc] newcell = np.array(cell[3:10]) if not np.allclose(newcell,lastcell): print ("%10.3f %3d %3d %10.5f %10.5f %10.5f %10.3f %10.3f %10.3f %10.2f %10.2f %s" \ %(M20,X20,Nc,a,b,c,alp,bet,gam,V,V1,bravaisNames[ibrav])) cells.append(cell) lastcell = np.array(cell[3:10]) if not GoOn: break N2 += 1 if Skip: cycle = 10 GoOn = False break if ibrav < 13: V1 *= 1.1 elif ibrav in range(13,17): V1 *= 1.025 if not GoOn: if bestM20 > topM20: topM20 = bestM20 if cells: V1 = cells[0][9] else: V1 = controls[3] ncMax += Nobs cycle += 1 print ('Restart search, new Max Nc = %d'%ncMax) else: cycle = 10 finally: pass # dlg.Destroy() print ('%s%s%s%s%s%d'%('finished cell search for ',bravaisNames[ibrav], \ ', elapsed time = ',G2lat.sec2HMS(time.time()-begin),' Vfinal ',V1)) if cells: return True,dmin,cells else: return False,0,[]
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 Readrmc6fPhase(self, filename, parent=None): '''Read a phase from a rmc6f file. ''' self.errors = 'Error opening file' fp = open(filename, 'Ur') Phase = {} Title = os.path.split(filename) G2G.SaveGPXdirectory(Title[0]) Title = os.path.splitext(Title[1])[0] Atoms = [] S = fp.readline() line = 1 SGData = None cell = None IA = 'I' Uiso = 0.01 Uij = [0. for i in range(6)] while S: self.errors = 'Error reading at line ' + str(line) Atom = [] if 'Cell' in S[:4]: cellRec = S.split(':')[1].split() abc = cellRec[:3] angles = cellRec[3:] 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 elif 'Atoms' in S[:5]: S = fp.readline()[:-1] AtRec = S.split() for ix, s in enumerate(AtRec): if '.' in s: break #is points at x while S: AtRec = S.split() Atype = AtRec[1] Aname = Atype + AtRec[0] Afrac = 1.0 x, y, z = AtRec[ix:ix + 3] XYZ = np.array([float(x), float(y), float(z)]) SytSym, Mult = '1', 1 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()[:-1] S = fp.readline() line += 1 fp.close() self.errors = 'Error after read complete' Phase = G2obj.SetNewPhase(Name='RMCProfile 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