1 | """ |
---|
2 | Unit tests for the sans_gen |
---|
3 | """ |
---|
4 | import warnings |
---|
5 | warnings.simplefilter("ignore") |
---|
6 | |
---|
7 | import unittest |
---|
8 | from sans.calculator import sans_gen |
---|
9 | from sans.models.SphereModel import SphereModel |
---|
10 | |
---|
11 | import numpy |
---|
12 | |
---|
13 | import os.path |
---|
14 | |
---|
15 | class sans_gen_test(unittest.TestCase): |
---|
16 | |
---|
17 | def setUp(self): |
---|
18 | self.sldloader = sans_gen.SLDReader() |
---|
19 | self.pdbloader = sans_gen.PDBReader() |
---|
20 | self.omfloader = sans_gen.OMFReader() |
---|
21 | self.comp = SphereModel() |
---|
22 | |
---|
23 | def test_sldreader(self): |
---|
24 | """ |
---|
25 | Test .sld file loaded |
---|
26 | """ |
---|
27 | f = self.sldloader.read("sld_file.sld") |
---|
28 | self.assertEqual(f.pos_x[0], -40.5) |
---|
29 | self.assertEqual(f.pos_y[0], -13.5) |
---|
30 | self.assertEqual(f.pos_z[0], -13.5) |
---|
31 | |
---|
32 | def test_pdbreader(self): |
---|
33 | """ |
---|
34 | Test .pdb file loaded |
---|
35 | """ |
---|
36 | f = self.pdbloader.read("c60.pdb") |
---|
37 | self.assertEqual(f.pos_x[0], -0.733) |
---|
38 | self.assertEqual(f.pos_y[0], -1.008) |
---|
39 | self.assertEqual(f.pos_z[0], 3.326) |
---|
40 | |
---|
41 | def test_omfreader(self): |
---|
42 | """ |
---|
43 | Test .omf file loaded |
---|
44 | """ |
---|
45 | f = self.omfloader.read("A_Raw_Example-1.omf") |
---|
46 | output = sans_gen.OMF2SLD() |
---|
47 | output.set_data(f) |
---|
48 | self.assertEqual(f.mx[0], 0) |
---|
49 | self.assertEqual(f.my[0], 0) |
---|
50 | self.assertEqual(f.mz[0], 0) |
---|
51 | self.assertEqual(output.pos_x[0], 0.0) |
---|
52 | self.assertEqual(output.pos_y[0], 0.0) |
---|
53 | self.assertEqual(output.pos_z[0], 0.0) |
---|
54 | |
---|
55 | """ |
---|
56 | def test_slda_and_run(self): # Works when sld reader uses loadtxt |
---|
57 | sld_data = self.sldloader.read("sphere697_r30.sld") |
---|
58 | # Generic computation |
---|
59 | model = sans_gen.GenSAS() |
---|
60 | model.setParam('background', 0.0) |
---|
61 | model.setParam('scale', 1.0) |
---|
62 | model.setParam('Up_frac_in', 0.5) |
---|
63 | model.setParam('Up_frac_out', 0.5) |
---|
64 | model.setParam('Up_theta', 0.0) |
---|
65 | x = numpy.array([0.01]) |
---|
66 | y = numpy.array([0.01]) |
---|
67 | model.set_sld_data(sld_data) |
---|
68 | out_gen = model.runXY([x, y]) |
---|
69 | # Analytic computation |
---|
70 | analy_model = self.comp |
---|
71 | analy_model.setParam('background', 0.0) |
---|
72 | analy_model.setParam('scale', 1.0) |
---|
73 | analy_model.setParam('radius', 30.0) |
---|
74 | analy_model.setParam('sldSolv', 0.0) |
---|
75 | analy_model.setParam('sldSph', 6.97e-06) |
---|
76 | out_analy = analy_model.runXY([0.01, 0.01]) |
---|
77 | # Comparison |
---|
78 | self.assertAlmostEqual(out_gen[0], out_analy, 1) |
---|
79 | """ |
---|
80 | if __name__ == '__main__': |
---|
81 | unittest.main() |
---|
82 | |
---|