source: sasview/sanscalculator/test/utest_sans_gen.py @ 6d4df13

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since 6d4df13 was 5917637, checked in by Jae Cho <jhjcho@…>, 12 years ago

minor corrections

  • Property mode set to 100644
File size: 2.5 KB
Line 
1"""
2Unit tests for the sans_gen
3"""
4import warnings
5warnings.simplefilter("ignore")
6
7import unittest
8from sans.calculator import sans_gen
9from sans.models.SphereModel import SphereModel
10
11import numpy
12 
13import os.path
14
15class 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"""   
80if __name__ == '__main__':
81    unittest.main()
82   
Note: See TracBrowser for help on using the repository browser.