Exemplo n.º 1
0
import os, sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import os
from copy import copy
import numpy as np
import fswig_hklgen as H
import hkl_model as Mod

np.seterr(divide="ignore", invalid="ignore")

DATAPATH = os.path.dirname(os.path.abspath(__file__))
backgFile = None
observedFile = os.path.join(DATAPATH, r"Mn025_4K.dat")
infoFile = os.path.join(DATAPATH, r"LFO.cfl")
(spaceGroup, crystalCell, magAtomList, symmetry) = H.readMagInfo(infoFile)
atomList = H.readInfo(infoFile)[2]
wavelength = 1.540000
ttMin = 3.0
ttMax = 167.750
ttStep = 0.05
exclusions = [[0.00, 5.00], [38.25, 39.00], [44.00, 45.50], [64.75, 65.75],
              [77.5, 79.00], [81.75, 83.10], [97.00, 100.00], [111.50, 113.00],
              [116.00, 118.00], [135.50, 139.50], [161.00, 169.00]]
tt, observed = H.readData(observedFile,
                          kind="y",
                          skiplines=3,
                          start=ttMin,
                          stop=ttMax,
                          step=ttStep,
                          exclusions=exclusions,
                          colstep=2)
Exemplo n.º 2
0
def diffPattern(infoFile=None, backgroundFile=None, wavelength=1.5403,
                ttMin=0, ttMax=180, ttStep=0.05, exclusions=None,
                spaceGroup=None, cell=None, atomList=None,
                symmetry=None, basisSymmetry=None, magAtomList=None,
                uvw=[0,0,1], scale=1,
                magnetic=False, info=False, plot=False, saveFile=None,
                observedData=(None,None), labels=None, base=0, residuals=False, error=None, muR=None):
    background = H.LinSpline(backgroundFile)
    sMin, sMax = H.getS(ttMin, wavelength), H.getS(ttMax, wavelength)
    if magnetic:
        if (infoFile != None):
            infofile = H.readMagInfo(infoFile)
            if (spaceGroup == None): spaceGroup = infofile[0]
            if (cell == None): cell = infofile[1]
            if (magAtomList == None): magAtomList = infofile[2]
            if (symmetry == None): symmetry = infofile[3]
        if (basisSymmetry == None): basisSymmetry = symmetry
        ## magnetic peaks
        # convert magnetic symmetry to space group
        latt = H.getMagsymmK_latt(basisSymmetry)
        if basisSymmetry.get_magsymm_k_mcentred() == 1: 
            latt+= " -1" 
        else:
            latt += " 1"
        spg = _SpaceGroup()
        FortFuncs().set_spacegroup(latt, spg)
        refList = H.hklGen(spaceGroup, cell, sMin, sMax, True, xtal=False)
        refList2 = H.hklGen(spg, cell, sMin, np.sin(179.5/2)/wavelength, True, xtal=True)
        magRefList = H.satelliteGen(cell, symmetry, sMax, hkls=refList2)#satelliteGen_python(cell, sMax, None)#
        print "length of reflection list " + str(len(magRefList))
        magIntensities = H.calcIntensity(magRefList, magAtomList, basisSymmetry,
                                       wavelength, cell, True, muR=muR)
        # add in structural peaks
        if (atomList == None): atomList = H.readInfo(infoFile)[2]
        #refList = hklGen(spaceGroup, cell, sMin, sMax, True, xtal=xtal)
        intensities = H.calcIntensity(refList, atomList, spaceGroup, wavelength, muR=muR)
        reflections = magRefList[:] + refList[:]
        intensities = np.append(magIntensities, intensities)
    else:
        if (infoFile != None):
            infofile = H.readInfo(infoFile)
            if (spaceGroup == None): spaceGroup = infofile[0]
            if (cell == None): cell = infofile[1]
            if (atomList == None): atomList = infofile[2]     
        print "length of atom list is", len(atomList)
        print(spaceGroup.number)
        refList = H.hklGen(spaceGroup, cell, sMin, sMax, True, xtal=False)
        reflections = refList[:]
        intensities = H.calcIntensity(refList, atomList, spaceGroup, wavelength, muR=muR)
    peaks = H.makePeaks(reflections, uvw, intensities, scale, wavelength, base=base)
    numPoints = int(floor((ttMax-ttMin)/ttStep)) + 1
    tt = np.linspace(ttMin, ttMax, numPoints)
    intensity = H.getIntensity(peaks, background, tt, base=base)

    if info:
        if magnetic:
            H.printInfo(cell, spaceGroup, (atomList, magAtomList), (refList, magRefList),
                      wavelength, basisSymmetry, muR=muR)
        else:
            H.printInfo(cell, spaceGroup, atomList, refList, wavelength, muR=muR)
    if plot:
        H.plotPattern(peaks, background, observedData[0], observedData[1],
                    ttMin, ttMax, ttStep, exclusions, labels=labels, base=base, residuals=residuals, error=error)
        H.pylab.show()
        H.pylab.savefig(os.path.join('/tmp/bland',str('plot.jpg')), dpi=2000)
    if saveFile:
        np.savetxt(saveFile, (tt, intensity), delimiter=" ")
    tt1 = ["%.3f" % H.twoTheta(ref.s, wavelength) for ref in refList]   
    for atom in atomList:
            print atom.label(), "element:", atom.element(), "iso:", atom.BIso(), "multip:", atom.multip(), "coords:", atom.coords(), "occupancy:", atom.occupancy()    
    h, k, l = tuple([str(ref.hkl[i]) for ref in refList] for i in xrange(3))
    return (tt1, tt, intensities, [h,k,l], peaks, background)
Exemplo n.º 3
0
import numpy as np
import fswig_hklgen as H
import hkl_model as Mod
import sxtal_model as S
#import bumps.parameter
#def dont(self, *args, **kw): raise Exception("don't")
#bumps.parameter.OperatorAdd.__init__ = dont

np.seterr(divide="ignore", invalid="ignore")

DATAPATH = os.path.dirname(os.path.abspath(__file__))
observedFile = os.path.join(DATAPATH,r"MnWO4_nuclear_5K.int")
infoFile = os.path.join(DATAPATH,r"AF4_5k.cfl")
magfile = os.path.join(DATAPATH, r"MnWO4_magneticAF4_5K.int")

(spaceGroup, crystalCell, magAtomList, symmetry) = H.readMagInfo(infoFile)
spaceGroup, crystalCell, atomList = H.readInfo(infoFile)
exclusions = []
# return wavelength, refList, sfs2, error, two-theta, and four-circle parameters
wavelength, refList, sfs2, error = S.readIntFile(observedFile, kind="int", cell=crystalCell)
magrefList, magsfs2, magerror = S.readMagIntFile(magfile, cell=crystalCell)
tt = [H.twoTheta(H.calcS(crystalCell, ref.hkl), wavelength) for ref in refList]
sfs2 = list(sfs2)
sfs2.extend(magsfs2)
sfs2 = np.array(sfs2)
tt.extend([H.twoTheta(H.calcS(crystalCell, ref.hkl), wavelength) for ref in magrefList])
error = list(error)
error.extend(list(magerror))
error2 = [item for item in error]
backg = None
basisSymmetry = copy(symmetry)
Exemplo n.º 4
0
def diffPattern(infoFile=None,
                backgroundFile=None,
                wavelength=1.5403,
                ttMin=0,
                ttMax=180,
                ttStep=0.05,
                exclusions=None,
                spaceGroup=None,
                cell=None,
                atomList=None,
                symmetry=None,
                basisSymmetry=None,
                magAtomList=None,
                uvw=[0, 0, 1],
                scale=1,
                magnetic=False,
                info=False,
                plot=False,
                saveFile=None,
                observedData=(None, None),
                labels=None,
                base=0,
                residuals=False,
                error=None,
                muR=None):
    background = H.LinSpline(backgroundFile)
    sMin, sMax = H.getS(ttMin, wavelength), H.getS(ttMax, wavelength)
    if magnetic:
        if (infoFile != None):
            infofile = H.readMagInfo(infoFile)
            if (spaceGroup == None): spaceGroup = infofile[0]
            if (cell == None): cell = infofile[1]
            if (magAtomList == None): magAtomList = infofile[2]
            if (symmetry == None): symmetry = infofile[3]
        if (basisSymmetry == None): basisSymmetry = symmetry
        ## magnetic peaks
        # convert magnetic symmetry to space group
        latt = H.getMagsymmK_latt(basisSymmetry)
        if basisSymmetry.get_magsymm_k_mcentred() == 1:
            latt += " -1"
        else:
            latt += " 1"
        spg = _SpaceGroup()
        FortFuncs().set_spacegroup(latt, spg)
        refList = H.hklGen(spaceGroup, cell, sMin, sMax, True, xtal=False)
        refList2 = H.hklGen(spg,
                            cell,
                            sMin,
                            np.sin(179.5 / 2) / wavelength,
                            True,
                            xtal=True)
        magRefList = H.satelliteGen(
            cell, symmetry, sMax,
            hkls=refList2)  #satelliteGen_python(cell, sMax, None)#
        print "length of reflection list " + str(len(magRefList))
        magIntensities = H.calcIntensity(magRefList,
                                         magAtomList,
                                         basisSymmetry,
                                         wavelength,
                                         cell,
                                         True,
                                         muR=muR)
        # add in structural peaks
        if (atomList == None): atomList = H.readInfo(infoFile)[2]
        #refList = hklGen(spaceGroup, cell, sMin, sMax, True, xtal=xtal)
        intensities = H.calcIntensity(refList,
                                      atomList,
                                      spaceGroup,
                                      wavelength,
                                      muR=muR)
        reflections = magRefList[:] + refList[:]
        intensities = np.append(magIntensities, intensities)
    else:
        if (infoFile != None):
            infofile = H.readInfo(infoFile)
            if (spaceGroup == None): spaceGroup = infofile[0]
            if (cell == None): cell = infofile[1]
            if (atomList == None): atomList = infofile[2]
        print "length of atom list is", len(atomList)
        print(spaceGroup.number)
        refList = H.hklGen(spaceGroup, cell, sMin, sMax, True, xtal=False)
        reflections = refList[:]
        intensities = H.calcIntensity(refList,
                                      atomList,
                                      spaceGroup,
                                      wavelength,
                                      muR=muR)
    peaks = H.makePeaks(reflections,
                        uvw,
                        intensities,
                        scale,
                        wavelength,
                        base=base)
    numPoints = int(floor((ttMax - ttMin) / ttStep)) + 1
    tt = np.linspace(ttMin, ttMax, numPoints)
    intensity = H.getIntensity(peaks, background, tt, base=base)

    if info:
        if magnetic:
            H.printInfo(cell,
                        spaceGroup, (atomList, magAtomList),
                        (refList, magRefList),
                        wavelength,
                        basisSymmetry,
                        muR=muR)
        else:
            H.printInfo(cell,
                        spaceGroup,
                        atomList,
                        refList,
                        wavelength,
                        muR=muR)
    if plot:
        H.plotPattern(peaks,
                      background,
                      observedData[0],
                      observedData[1],
                      ttMin,
                      ttMax,
                      ttStep,
                      exclusions,
                      labels=labels,
                      base=base,
                      residuals=residuals,
                      error=error)
        H.pylab.show()
        H.pylab.savefig(os.path.join('/tmp/bland', str('plot.jpg')), dpi=2000)
    if saveFile:
        np.savetxt(saveFile, (tt, intensity), delimiter=" ")
    tt1 = ["%.3f" % H.twoTheta(ref.s, wavelength) for ref in refList]
    for atom in atomList:
        print atom.label(), "element:", atom.element(), "iso:", atom.BIso(
        ), "multip:", atom.multip(), "coords:", atom.coords(
        ), "occupancy:", atom.occupancy()
    h, k, l = tuple([str(ref.hkl[i]) for ref in refList] for i in xrange(3))
    return (tt1, tt, intensities, [h, k, l], peaks, background)