예제 #1
0
 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)
예제 #2
0
파일: genselftest.py 프로젝트: isaxs/pyGSAS
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)
예제 #3
0
 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 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)
예제 #5
0
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)
예제 #6
0
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
예제 #7
0
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
예제 #8
0
파일: G2phase.py 프로젝트: isaxs/pyGSAS
 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
예제 #9
0
파일: G2phase.py 프로젝트: isaxs/pyGSAS
 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
예제 #10
0
파일: G2phase.py 프로젝트: isaxs/pyGSAS
 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
예제 #11
0
 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
예제 #12
0
    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
예제 #13
0
    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 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
예제 #15
0
파일: G2phase_CIF.py 프로젝트: isaxs/pyGSAS
 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
예제 #16
0
파일: GSASIIindex.py 프로젝트: isaxs/pyGSAS
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)