Changeset a50da82 in sasview


Ignore:
Timestamp:
Sep 23, 2017 11:25:06 AM (7 years ago)
Author:
Paul Kienzle <pkienzle@…>
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)
Message:

enable periodictable tests

File:
1 moved

Legend:

Unmodified
Added
Removed
  • test/sascalculator/test/utest_sld.py

    r959eb01 ra50da82  
    1010from periodictable.constants import avogadro_number 
    1111from  periodictable.nsf import neutron_scattering, neutron_sld 
    12         
     12 
    1313 
    1414def calculate_xray_sld(element, density, molecule_formula): 
     
    1919    element_formula = formula(str(element)) 
    2020    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... 
    2323    energy = xray_energy(element.K_alpha) 
    2424    atom = molecule_formula.atoms 
     
    3030    Sld calculator test for H2O 
    3131    """ 
    32      
     32 
    3333    def setUp(self): 
    3434        """Inititialze variables""" 
    35          
     35 
    3636        self.compound = "H2O" 
    3737        self.density = 1.0 
    3838        self.wavelength = 6.0 
    3939        self.sld_formula = formula(self.compound, density=self.density) 
    40      
     40 
    4141    def test_neutron_sld(self): 
    4242        """ 
    43         test sld  
     43        test sld 
    4444        """ 
    4545        #Compute incoherence , absorption, and incoherence 
    4646        (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) 
    4848        cu_real, cu_im = calculate_xray_sld(element="Cu", density=self.density, 
    4949                                  molecule_formula=self.sld_formula) 
    5050        mo_real, mo_im = calculate_xray_sld(element="Mo", density=self.density, 
    5151                                  molecule_formula=self.sld_formula) 
    52         #test sld  
     52        #test sld 
    5353        self.assertAlmostEquals(sld_real * _SCALE, -5.6e-7, 1) 
    5454        self.assertAlmostEquals(sld_im * _SCALE, 0) 
     
    6464        self.assertAlmostEquals(mo_real * _SCALE, 9.43e-6) 
    6565        self.assertAlmostEquals(mo_im * _SCALE, 5.65e-7,1) 
    66      
    67      
     66 
     67 
    6868class TestD2O(unittest.TestCase): 
    6969    """ 
    7070    Sld calculator test for D2O 
    7171    """ 
    72      
     72 
    7373    def setUp(self): 
    7474        """Inititialze variables""" 
    75          
     75 
    7676        self.compound = "D2O" 
    7777        self.density = 1.1 
    7878        self.wavelength = 6.0 
    7979        self.sld_formula = formula(self.compound, density=self.density) 
    80      
     80 
    8181    def test_neutron_sld(self): 
    8282        """ 
    83         test sld  
     83        test sld 
    8484        """ 
    8585        #Compute incoherence , absorption, and incoherence 
    8686        (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) 
    8888        cu_real, cu_im = calculate_xray_sld(element="Cu", density=self.density, 
    8989                                  molecule_formula=self.sld_formula) 
    9090        mo_real, mo_im = calculate_xray_sld(element="Mo", density=self.density, 
    9191                                  molecule_formula=self.sld_formula) 
    92         #test sld  
     92        #test sld 
    9393        self.assertAlmostEquals(sld_real * _SCALE, 6.33e-6, 1) 
    9494        self.assertAlmostEquals(sld_im * _SCALE, 0) 
     
    104104        self.assertAlmostEquals(mo_real * _SCALE, 9.33e-6) 
    105105        self.assertAlmostEquals(mo_im * _SCALE, 5.59e-9,1) 
    106      
    107          
     106 
     107 
    108108class TestCd(unittest.TestCase): 
    109109    """ 
    110110    Sld calculator test for Cd 
    111111    """ 
    112      
     112 
    113113    def setUp(self): 
    114114        """Inititialze variables""" 
     
    118118        self.wavelength = 6.0 
    119119        self.sld_formula = formula(self.compound, density=self.density) 
    120         
     120 
    121121    def test_neutron_sld(self): 
    122122        """ 
    123         test sld  
     123        test sld 
    124124        """ 
    125125        #Compute incoherence , absorption, and incoherence 
    126126        (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) 
    128128        cu_real, cu_im = calculate_xray_sld(element="Cu", density=self.density, 
    129129                                  molecule_formula=self.sld_formula) 
    130130        mo_real, mo_im = calculate_xray_sld(element="Mo", density=self.density, 
    131131                                  molecule_formula=self.sld_formula) 
    132         #test sld  
     132        #test sld 
    133133        self.assertAlmostEquals(sld_real * _SCALE, 1.04e-6, 1) 
    134134        self.assertAlmostEquals(sld_im * _SCALE, -1.5e-7, 1) 
     
    144144        self.assertAlmostEquals(mo_real * _SCALE, 2.84e-5, 1) 
    145145        self.assertAlmostEquals(mo_im * _SCALE, 7.26e-7,1) 
    146    
     146 
    147147if __name__ == '__main__': 
    148148    unittest.main() 
Note: See TracChangeset for help on using the changeset viewer.