- Timestamp:
- Sep 23, 2017 11:25:06 AM (7 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- c8321cfc
- Parents:
- 1d014cb
- git-author:
- Paul Kienzle <pkienzle@…> (09/23/17 11:24:22)
- git-committer:
- Paul Kienzle <pkienzle@…> (09/23/17 11:25:06)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
test/sascalculator/test/utest_sld.py
r959eb01 ra50da82 10 10 from periodictable.constants import avogadro_number 11 11 from periodictable.nsf import neutron_scattering, neutron_sld 12 12 13 13 14 14 def calculate_xray_sld(element, density, molecule_formula): … … 19 19 element_formula = formula(str(element)) 20 20 if len(element_formula.atoms) != 1: 21 return 22 element = element_formula.atoms.keys()[0]21 return 22 element = next(iter(element_formula.atoms)) # only one element... 23 23 energy = xray_energy(element.K_alpha) 24 24 atom = molecule_formula.atoms … … 30 30 Sld calculator test for H2O 31 31 """ 32 32 33 33 def setUp(self): 34 34 """Inititialze variables""" 35 35 36 36 self.compound = "H2O" 37 37 self.density = 1.0 38 38 self.wavelength = 6.0 39 39 self.sld_formula = formula(self.compound, density=self.density) 40 40 41 41 def test_neutron_sld(self): 42 42 """ 43 test sld 43 test sld 44 44 """ 45 45 #Compute incoherence , absorption, and incoherence 46 46 (sld_real,sld_im,sld_inc), (coh,abs,incoh), length = neutron_scattering(self.compound, 47 density=self.density, wavelength=self.wavelength) 47 density=self.density, wavelength=self.wavelength) 48 48 cu_real, cu_im = calculate_xray_sld(element="Cu", density=self.density, 49 49 molecule_formula=self.sld_formula) 50 50 mo_real, mo_im = calculate_xray_sld(element="Mo", density=self.density, 51 51 molecule_formula=self.sld_formula) 52 #test sld 52 #test sld 53 53 self.assertAlmostEquals(sld_real * _SCALE, -5.6e-7, 1) 54 54 self.assertAlmostEquals(sld_im * _SCALE, 0) … … 64 64 self.assertAlmostEquals(mo_real * _SCALE, 9.43e-6) 65 65 self.assertAlmostEquals(mo_im * _SCALE, 5.65e-7,1) 66 67 66 67 68 68 class TestD2O(unittest.TestCase): 69 69 """ 70 70 Sld calculator test for D2O 71 71 """ 72 72 73 73 def setUp(self): 74 74 """Inititialze variables""" 75 75 76 76 self.compound = "D2O" 77 77 self.density = 1.1 78 78 self.wavelength = 6.0 79 79 self.sld_formula = formula(self.compound, density=self.density) 80 80 81 81 def test_neutron_sld(self): 82 82 """ 83 test sld 83 test sld 84 84 """ 85 85 #Compute incoherence , absorption, and incoherence 86 86 (sld_real,sld_im,sld_inc), (coh,abs,incoh), length = neutron_scattering(self.compound, 87 density=self.density, wavelength=self.wavelength) 87 density=self.density, wavelength=self.wavelength) 88 88 cu_real, cu_im = calculate_xray_sld(element="Cu", density=self.density, 89 89 molecule_formula=self.sld_formula) 90 90 mo_real, mo_im = calculate_xray_sld(element="Mo", density=self.density, 91 91 molecule_formula=self.sld_formula) 92 #test sld 92 #test sld 93 93 self.assertAlmostEquals(sld_real * _SCALE, 6.33e-6, 1) 94 94 self.assertAlmostEquals(sld_im * _SCALE, 0) … … 104 104 self.assertAlmostEquals(mo_real * _SCALE, 9.33e-6) 105 105 self.assertAlmostEquals(mo_im * _SCALE, 5.59e-9,1) 106 107 106 107 108 108 class TestCd(unittest.TestCase): 109 109 """ 110 110 Sld calculator test for Cd 111 111 """ 112 112 113 113 def setUp(self): 114 114 """Inititialze variables""" … … 118 118 self.wavelength = 6.0 119 119 self.sld_formula = formula(self.compound, density=self.density) 120 120 121 121 def test_neutron_sld(self): 122 122 """ 123 test sld 123 test sld 124 124 """ 125 125 #Compute incoherence , absorption, and incoherence 126 126 (sld_real,sld_im,sld_inc), (coh,abs,incoh), length = neutron_scattering(self.compound, 127 density=self.density, wavelength=self.wavelength) 127 density=self.density, wavelength=self.wavelength) 128 128 cu_real, cu_im = calculate_xray_sld(element="Cu", density=self.density, 129 129 molecule_formula=self.sld_formula) 130 130 mo_real, mo_im = calculate_xray_sld(element="Mo", density=self.density, 131 131 molecule_formula=self.sld_formula) 132 #test sld 132 #test sld 133 133 self.assertAlmostEquals(sld_real * _SCALE, 1.04e-6, 1) 134 134 self.assertAlmostEquals(sld_im * _SCALE, -1.5e-7, 1) … … 144 144 self.assertAlmostEquals(mo_real * _SCALE, 2.84e-5, 1) 145 145 self.assertAlmostEquals(mo_im * _SCALE, 7.26e-7,1) 146 146 147 147 if __name__ == '__main__': 148 148 unittest.main()
Note: See TracChangeset
for help on using the changeset viewer.