source: trunk/testGSASIIstruct.py @ 737

Last change on this file since 737 was 709, checked in by vondreele, 13 years ago

add testGSASIIstruct.py
a fix to the data window restore after Refine
make getMass & getDensity routines in GSASIImath.py
update atom mass info after Refine

File size: 2.4 KB
Line 
1#testGSASIIstruct.py
2
3import GSASIIpath
4import GSASIIstruct as G2st
5import numpy as np
6import pytexture as ptx
7ptx.pyqlmninit()            #initialize fortran arrays for spherical harmonics
8
9#testing data
10NeedTestData = True
11def TestData():
12    import cPickle
13    file = open('structTestdata.dat','rb')
14    global parmDict
15    parmDict = cPickle.load(file)
16    global varylist
17    varylist = cPickle.load(file)
18    global Histogram
19    Histogram = cPickle.load(file)
20    global Phases
21    Phases = cPickle.load(file)
22    global calcControls
23    calcControls = cPickle.load(file)
24    global pawleyLookup
25    pawleyLookup = cPickle.load(file)
26    file.close()
27
28    global NeedTestData
29    NeedTestData = False
30   
31def test1():
32    if NeedTestData: TestData()
33    limits = Histogram['Limits'][1]
34    data = Histogram['Data']
35    xdata = data[0]
36    fplot = plotter.add('function test').gca()
37    yc,yb = G2st.getPowderProfile(parmDict,xdata,varylist,Histogram,Phases,calcControls,pawleyLookup)
38    fplot.plot(xdata,yc+yb,'r')
39
40def test2(name,delt):
41    if NeedTestData: TestData()
42    varyList = [name,]
43    limits = Histogram['Limits'][1]
44    data = Histogram['Data']
45    xdata = data[0]
46    hplot = plotter.add('derivatives test for '+name).gca()
47    ya = G2st.getPowderProfileDerv(parmDict,xdata,varyList,Histogram,Phases,calcControls,pawleyLookup)[0]
48    hplot.plot(xdata,ya)
49    if 'dA' in name:
50        name = ''.join(name.split('d'))
51        varyList = [name,]
52    parmDict[name] -= delt
53    y0,yb = G2st.getPowderProfile(parmDict,xdata,varyList,Histogram,Phases,calcControls,pawleyLookup)
54    y0 += yb
55    parmDict[name] += 2.*delt
56    y1,yb = G2st.getPowderProfile(parmDict,xdata,varyList,Histogram,Phases,calcControls,pawleyLookup)
57    y1 += yb
58    yn = (y1-y0)/(2.*delt)
59    hplot.plot(xdata,yn,'r+')
60    hplot.plot(xdata,ya-yn)
61   
62if __name__ == '__main__':
63    if NeedTestData: TestData()
64    import GSASIItestplot as plot
65#    parmDict['0:0:Scale'] = 1.0
66   
67    global plotter
68    plotter = plot.PlotNotebook()
69    test1()
70    for name in parmDict:
71        print name,parmDict[name]
72    names = [
73        ['0:0:Size:mx',0.001],
74        ['0:0:Mustrain:mx',0.001],
75        ['0:0:Size:i',0.001],
76        ['0:0:Mustrain:i',0.1],
77        ]
78    for [name,delt] in names:
79        test2(name,delt)
80    print "OK"
81    plotter.StartEventLoop()
Note: See TracBrowser for help on using the repository browser.