Beispiel #1
0
def ranAbyV(Bravais,dmin,dmax,V):
    'needs a doc string'
    cell = [0,0,0,0,0,0]
    bad = True
    while bad:
        bad = False
        cell = rancell(Bravais,dmin,dmax)
        G,g = G2lat.cell2Gmat(cell)
        A = G2lat.Gmat2A(G)
        if G2lat.calc_rVsq(A) < 1:
            scaleAbyV(A,V)
            cell = G2lat.A2cell(A)
            for i in range(3):
                bad |= cell[i] < dmin
    return A
Beispiel #2
0
def ranAbyV(Bravais,dmin,dmax,V):
    'needs a doc string'
    cell = [0,0,0,0,0,0]
    bad = True
    while bad:
        bad = False
        cell = rancell(Bravais,dmin,dmax)
        G,g = G2lat.cell2Gmat(cell)
        A = G2lat.Gmat2A(G)
        if G2lat.calc_rVsq(A) < 1:
            scaleAbyV(A,V)
            cell = G2lat.A2cell(A)
            for i in range(3):
                bad |= cell[i] < dmin
    return A
    def ReadJANAPhase(self, filename, parent=None):
        '''Read a phase from a JANA2006 m50 & m40 files.
        '''
        self.errors = 'Error opening file'
        fp = open(filename, 'Ur')  #contains only cell & spcgroup
        Phase = {}
        Title = os.path.basename(filename)
        Type = 'nuclear'
        Atoms = []
        Atypes = []
        SuperVec = [[0, 0, .1], False, 4]
        S = fp.readline()
        line = 1
        SGData = None
        SuperSg = ''
        cell = None
        nqi = 0
        version = '2000'
        while S:
            self.errors = 'Error reading at line ' + str(line)
            if 'title' in S and S != 'title\n':
                Title = S.split()[1]
            elif 'Jana2006' in S:
                self.warnings += '\nJana2006 file detected'
                version = '2006'
            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))
                G, g = G2lat.cell2Gmat(cell)
                ast = np.sqrt(np.diag(G))
                Mast = np.multiply.outer(ast, ast)

            elif 'spgroup' in S:
                if 'X' in S:
                    raise self.ImportException(
                        "Ad hoc Supersymmetry centering " + S +
                        " not allowed in GSAS-II")
                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 = 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 'qi' in S[:2]:
                if nqi:
                    raise self.ImportException(
                        "Supersymmetry too high; GSAS-II limited to (3+1) supersymmetry"
                    )
                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 = fp.readline()
            line += 1
        fp.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 = G2obj.P1SGData  # 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])]
            Spos = []
            Sadp = []
            Sfrac = []
            Smag = []
            XYZ = [float(S1[27:36]), float(S1[36:45]), float(S1[45:54])]
            SytSym, Mult = G2spc.SytSym(XYZ, SGData)[:2]
            aType = Atypes[int(S1[9:11]) - 1]
            Name = S1[:8].strip()
            if S1[11:15].strip() == '1':
                S2 = file2.readline()
                Uiso = S2[:9]
                if version == '2000':
                    Uiso = R2pisq * float(Uiso) / 4.  #Biso -> Uiso
                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])
                ]  #Uij in Jana2006!
                if version == '2000':
                    Uij = R2pisq * G2lat.UijtoU6(
                        G2lat.U6toUij(Uij) / Mast
                    )  #these things are betaij in Jana2000! need to convert to Uij
            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
                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 [
                        '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])
                ]
                #these are betaij modulations in Jana2000! need to convert to Uij modulations
                if version == '2000':
                    vals[:6] = R2pisq * G2lat.UijtoU6(
                        G2lat.U6toUij(vals[:6]) /
                        Mast)  #convert sin bij to Uij
                    vals[6:] = R2pisq * G2lat.UijtoU6(
                        G2lat.U6toUij(vals[6:]) /
                        Mast)  #convert cos bij to Uij
                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.maxsize))
            Atom.append({
                'SS1': {
                    'Sfrac': [
                        waveType,
                    ] + Sfrac,
                    'Spos': [
                        waveType,
                    ] + Spos,
                    'Sadp': [
                        'Fourier',
                    ] + Sadp,
                    'Smag': [
                        'Fourier',
                    ] + 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 = G2obj.SetNewPhase(Name=Title,
                                  SGData=SGData,
                                  cell=cell + [
                                      Volume,
                                  ])
        Phase['General']['Type'] = Type
        Phase['General']['Modulated'] = True
        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