|
| 1 | +# perform a DIFFaX computation using the GSAS-II interface to the |
| 2 | +# pydiffax.so/.pyd module |
| 3 | + |
| 4 | +import os |
| 5 | +import sys |
| 6 | +import tempfile |
| 7 | +import numpy as np |
| 8 | +import numpy.testing as npt |
| 9 | +home = os.path.dirname(__file__) |
| 10 | +work = tempfile.gettempdir() |
| 11 | + |
| 12 | +import importlib.util |
| 13 | +G2loc = None |
| 14 | +try: |
| 15 | + G2loc = importlib.util.find_spec('GSASII.GSASIIpwd') |
| 16 | +except ModuleNotFoundError: |
| 17 | + print('ModuleNotFound for GSASII.GSASIIpwd') |
| 18 | + |
| 19 | +if G2loc is None: # fixup path if GSASII not installed into Python |
| 20 | + print('GSAS-II not installed in Python; Hacking sys.path') |
| 21 | + sys.path.append(os.path.dirname(home)) |
| 22 | + |
| 23 | +import GSASII |
| 24 | +#import GSASII.GSASIIscriptable as G2sc # sets up access to binaries |
| 25 | +import GSASII.GSASIIpwd as G2pwd |
| 26 | + |
| 27 | +def test_diffax(): |
| 28 | + print('test_diffax(): test a small DIFFaX computation') |
| 29 | + # define input needed for computation |
| 30 | + layerinfo = { |
| 31 | + 'Layers': [{'SameAs': '','Name': 'layer 1','Symm': '-1', |
| 32 | + 'Atoms': [['C1','C',-1./3.,-3./18.,-1/8,1.0, 0.01]]}, |
| 33 | + {'SameAs': '','Name': 'layer 2','Symm': '-1', |
| 34 | + 'Atoms': [['C1','C', 1./3., 3./18.,-1/8,1.0, 0.01]]},], |
| 35 | + 'AtInfo': {'C': {'Isotopes': { |
| 36 | + '13': {'SA': 0.00137,'Mass': 13.003,'SL': [0.619, 0]}, |
| 37 | + '12': {'SA': 0.00353, 'Mass': 12.0, 'SL': [0.6654, 0]}, |
| 38 | + 'Nat. Abund.': {'SA': 0.0035, 'Mass': 12.011, 'SL': [0.6648, 0]}}, |
| 39 | + 'Vdrad': 1.95, 'Color': (144, 144, 144), 'Symbol': 'C', 'Lande g': 2.0, |
| 40 | + 'Drad': 1.12, 'Mass': 12.011, 'Arad': 0.92, 'Z': 6, 'Hbrad': 0}}, |
| 41 | + 'allowedTrans': [['1', '1'], ['1', '2'], ['2', '1'], ['2', '2']], |
| 42 | + 'seqCodes': ('TransP;0;0', [0.0, 1.0], 10), |
| 43 | + 'SymTrans': True, |
| 44 | + 'Stacking': ['recursive', 'infinite', ''], |
| 45 | + 'Laue': '6/mmm', |
| 46 | + 'Cell': [False, 2.522, 2.522, 2.059, 90.0, 90.0, 120.0, 11.341673551466423], |
| 47 | + 'Width': [[1.0, 1.0], [False, False]], |
| 48 | + 'Sadp': {}, |
| 49 | + 'seqResults': [], |
| 50 | + 'Toler': 0.01, |
| 51 | + 'Transitions': [ |
| 52 | + [[0.7, 2./3., 1./3., 1.0, '', False], |
| 53 | + [0.3, 0.0, 0.0, 1.0, '', False]], |
| 54 | + [[0.3, 0.0, 0.0, 1.0, '', False], |
| 55 | + [0.7, -2./3., -1./3., 1.0, '', False]]], |
| 56 | + 'selInst': 'Gaussian'} |
| 57 | + bkg = [['chebyschev', True, 3, 50.0, 0.0, 0.0], |
| 58 | + {'peaksList': [], |
| 59 | + 'debyeTerms': [], |
| 60 | + 'nPeaks': 0, |
| 61 | + 'background PWDR': ['', -1.0], |
| 62 | + 'nDebye': 0}] |
| 63 | + profile=[ |
| 64 | + np.linspace(10,150,7001), |
| 65 | + np.zeros(7001), np.zeros(7001), np.zeros(7001), |
| 66 | + np.zeros(7001), np.zeros(7001),] |
| 67 | + inst = {'I(L2)/I(L1)': [0.5, 0.5, False], |
| 68 | + 'SH/L': [0.002, 0.002, False], |
| 69 | + 'V': [-2.0, -2.0, False], |
| 70 | + 'Lam2': [1.5443, 1.5443, False], |
| 71 | + 'Source': ['CuKa', '?'], |
| 72 | + 'Zero': [0.0, 0.0, False], |
| 73 | + 'Lam1': [1.5405, 1.5405, False], |
| 74 | + 'U': [2.0, 2.0, False], |
| 75 | + 'W': [5.0, 5.0, False], |
| 76 | + 'Azimuth': [0.0, 0.0, False], |
| 77 | + 'Y': [0.0, 0.0, False], |
| 78 | + 'X': [0.0, 0.0, False], |
| 79 | + 'Type': ['PXC', 'PXC', False], |
| 80 | + 'Bank': [1.0, 1.0, False], |
| 81 | + 'Polariz.': [0.7, 0.7, False]} |
| 82 | + |
| 83 | + G2pwd.CalcStackingPWDR(layerinfo,1000.,bkg,[10.,150.],inst,profile,False) |
| 84 | + #import matplotlib.pyplot as plt |
| 85 | + #plt.plot(profile[0],profile[3]) |
| 86 | + #plt.show() |
| 87 | + assert abs(profile[3][:7000].max()-5230.06) < 0.1, 'Max value off' |
| 88 | + assert abs(profile[3][:7000].min()-50.03) < 0.1, 'Min value off' |
| 89 | + msg = 'deviations in 42-43 deg section' |
| 90 | + npt.assert_allclose(profile[3][1600:1651], |
| 91 | + np.array([200.48310247, 200.63761559, 200.8637708 , 201.15861368, |
| 92 | + 201.51951493, 201.94413305, 202.43038195, 202.97640301, |
| 93 | + 203.58054064, 204.24132092, 204.95743283, 205.72771164, |
| 94 | + 206.55112422, 207.42675591, 208.35379877, 209.33154098, |
| 95 | + 210.35935728, 211.43670024, 212.56309224, 213.73811812, |
| 96 | + 214.96141832, 216.23268245, 217.55164331, 218.91807113, |
| 97 | + 220.33176811, 221.79256313, 223.30030665, 224.85486568, |
| 98 | + 226.45611886, 228.10395155, 229.79825094, 231.53890116, |
| 99 | + 233.32577831, 235.15874548, 237.03764759, 238.96230622, |
| 100 | + 240.93251424, 242.94803037, 245.00857357, 247.11381723, |
| 101 | + 249.26338327, 251.45683604, 253.69367607, 255.97333369, |
| 102 | + 258.29516247, 260.6584326 , 263.06232408, 265.50591998, |
| 103 | + 267.98819954, 270.5080314 , 273.06416684]), rtol=0.0001, err_msg=msg) |
| 104 | + |
| 105 | +if __name__ == '__main__': |
| 106 | + #import time |
| 107 | + #start = time.time() |
| 108 | + test_diffax() |
| 109 | + #print('elapsed=',time.time()-start) |
0 commit comments