class TestCoreShell(unittest.TestCase):
    """ Unit tests for calculate_ER (CoreShellModel) """
    
    def setUp(self):
        from sas.models.CoreShellModel import CoreShellModel
        self.comp = CoreShellModel()
        
    def test(self):
        """ Test 1D model for a CoreShell """
        self.comp.setParam("radius", 20)
        self.comp.setParam("thickness", 20)
        self.assertAlmostEqual(self.comp.calculate_ER(), 40)       
Пример #2
0
 def setUp(self):
     from sas.models.CoreShellModel import CoreShellModel
     self.model= CoreShellModel()
     
     self.model.setParam('scale', 1.0)
     self.model.setParam('radius', 60.0)
     self.model.setParam('thickness', 10.0)
     self.model.setParam('core_sld', 1.e-6)
     self.model.setParam('shell_sld', 2.e-6)
     self.model.setParam('solvent_sld', 3.e-6)
     self.model.setParam('background', 0.0)
Пример #3
0
    def setUp(self):
        """ Set up zero-SLD-average core-shell model """
        from sas.models.CoreShellModel import CoreShellModel
        
        radius = 15
        thickness = 5
        density = 5
        
        core_vol = 4.0/3.0*math.pi*radius*radius*radius
        self.outer_radius = radius+thickness
        shell_vol = 4.0/3.0*math.pi*self.outer_radius*self.outer_radius*self.outer_radius - core_vol
        self.shell_sld = -1.0*core_vol/shell_vol

        self.density = density
           
        # Core-shell
        sphere = CoreShellModel()
        # Core radius
        sphere.setParam('radius', radius)
        # Shell thickness
        sphere.setParam('thickness', thickness)
        sphere.setParam('core_sld', 1.0)
        sphere.setParam('shell_sld', self.shell_sld)
        sphere.setParam('solvent_sld', 0.0)
        sphere.setParam('background', 0.0)
        sphere.setParam('scale', 1.0)
        self.ana = sphere
       
        canvas = VolumeCanvas.VolumeCanvas()        
        canvas.setParam('lores_density', self.density)
        
        handle = canvas.add('sphere')
        canvas.setParam('%s.radius' % handle, self.outer_radius)
        canvas.setParam('%s.contrast' % handle, self.shell_sld)
       
        handle2 = canvas.add('sphere')
        canvas.setParam('%s.radius' % handle2, radius)
        canvas.setParam('%s.contrast' % handle2, 1.0)
               
        canvas.setParam('scale' , 1.0)
        canvas.setParam('background' , 0.0)
        self.canvas = canvas 
Пример #4
0
class TestCoreShell(unittest.TestCase):
    """
        Testing C++ Cylinder model
    """
    def setUp(self):
        from sas.models.CoreShellModel import CoreShellModel
        self.model= CoreShellModel()
        
        self.model.setParam('scale', 1.0)
        self.model.setParam('radius', 60.0)
        self.model.setParam('thickness', 10.0)
        self.model.setParam('core_sld', 1.e-6)
        self.model.setParam('shell_sld', 2.e-6)
        self.model.setParam('solvent_sld', 3.e-6)
        self.model.setParam('background', 0.0)
        
    def test_simple(self):
        """
            Test simple 1D and 2D values
            Numbers taken from model that passed validation, before
            the update to C++ underlying class.
        """
        self.assertAlmostEqual(self.model.run(0.001), 
                               381.27304697150055, 3)
        self.assertAlmostEqual(self.model.runXY([0.001,0.001]), 
                               380.93779156218682, 3)
        
    def test_dispersion(self):
        """
            Test with dispersion
        """
        from sas.models.DisperseModel import DisperseModel
        disp = DisperseModel(self.model, ['radius', 'thickness'], [10, 2])
        disp.setParam('n_pts', 10)
        self.assertAlmostEqual(disp.run(0.001), 407.344127907553, 3)
    
    def test_new_disp(self):
        from sas.models.dispersion_models import GaussianDispersion
        disp_rm = GaussianDispersion()
        self.model.set_dispersion('radius', disp_rm)
        self.model.dispersion['radius']['width'] = 0.1666666667
        self.model.dispersion['radius']['npts'] = 10
        self.model.dispersion['radius']['nsigmas'] = 2

        disp_rr = GaussianDispersion()
        self.model.set_dispersion('thickness', disp_rr)
        self.model.dispersion['thickness']['width'] = 0.2
        self.model.dispersion['thickness']['npts'] = 10
        self.model.dispersion['thickness']['nsigmas'] = 2

        self.assertAlmostEqual(self.model.run(0.001), 
                               1.16747510*407.344127907553, 3)
Пример #5
0
    def __init__(self, radius=15, thickness=5, density = 0.01):
        from sas.models.CoreShellModel import CoreShellModel
        
        self.name = 'coreshell'
        self.radius = radius
        
        core_vol = 4.0/3.0*math.pi*radius*radius*radius
        self.outer_radius = radius+thickness
        shell_vol = 4.0/3.0*math.pi*self.outer_radius*self.outer_radius*self.outer_radius - core_vol
        self.shell_sld = -1.0*core_vol/shell_vol

        self.density = density
           
        # Core-shell
        sphere = CoreShellModel()
        # Core radius
        sphere.setParam('radius', self.radius)
        # Shell thickness
        sphere.setParam('thickness', thickness)
        sphere.setParam('core_sld', 1.0)
        sphere.setParam('shell_sld', self.shell_sld)
        sphere.setParam('solvent_sld', 0.0)
        sphere.setParam('background', 0.0)
        sphere.setParam('scale', 1.0)
        self.ana = sphere
        self.create()
Пример #6
0
def test_2():
    radius = 15.0
    thickness = 5.0
    
    core_vol = 4.0/3.0*math.pi*radius*radius*radius
    outer_radius = radius+thickness
    shell_vol = 4.0/3.0*math.pi*outer_radius*outer_radius*outer_radius - core_vol
    shell_sld = -1.0*core_vol/shell_vol
    print "Shell SLD", shell_sld

    
    density = .1
    vol = 4/3*math.pi*radius*radius*radius
    npts = vol*density
     
    canvas = VolumeCanvas.VolumeCanvas()
    canvas.setParam('lores_density', density)
    handle = canvas.add('sphere')
    canvas.setParam('%s.radius' % handle, outer_radius)
    canvas.setParam('%s.contrast' % handle, shell_sld)
   
    handle2 = canvas.add('sphere')
    canvas.setParam('%s.radius' % handle2, radius)
    canvas.setParam('%s.contrast' % handle2, 1.0)
   
   
   
    # Core-shell
    sphere = CoreShellModel()
    # Core radius
    sphere.setParam('radius', radius)
    # Shell thickness
    sphere.setParam('thickness', thickness)
    sphere.setParam('core_sld', 1.0)
    
    
    sphere.setParam('shell_sld', shell_sld)
    sphere.setParam('solvent_sld',0.0)
    sphere.setParam('background',0.0)
    sphere.setParam('scale',1.0)
   
    out = open("lores_test.txt",'w')
    out.write("<q> <sim> <ana>\n")
    
    for i in range(65):
        q = 0.001 + 0.01*i
        
        # For each volume integral that we change to a sum,
        # we must multiply by 1/density = V/N
        # Since we want P(r)/V, we will need to multiply
        # the sum by 1/(N*density), where N is the number of
        # points without overlap. Since we already divide
        # by N when calculating I(q), we only need to divide
        # by the density here. We divide by N in the 
        # calculation because it is difficult to estimate it here.
        
        
        # Put the factor 2 in the simulation two...
        sim_1 = canvas.getIq(q)
        ana_1 = sphere.run(q)
        
        print "q=%g  sim=%g  ana=%g   ratio=%g" % (q, sim_1, ana_1, sim_1/ana_1)
        out.write( "%g  %g  %g\n" % (q, sim_1, ana_1))

    out.close()
Пример #7
0
def test_7():
    from sas.models.CoreShellModel import CoreShellModel
    print "Testing core-shell"
    radius = 15
    thickness = 5
    density = 5
    
    core_vol = 4.0/3.0*math.pi*radius*radius*radius
    outer_radius = radius+thickness
    shell_vol = 4.0/3.0*math.pi*outer_radius*outer_radius*outer_radius - core_vol
    shell_sld = -1.0*core_vol/shell_vol

    # Core-shell
    sphere = CoreShellModel()
    # Core radius
    sphere.setParam('radius', radius)
    # Shell thickness
    sphere.setParam('thickness', thickness)
    sphere.setParam('core_sld', 1.0)
    sphere.setParam('shell_sld', shell_sld)
    sphere.setParam('solvent_sld', 0.0)
    sphere.setParam('background', 0.0)
    sphere.setParam('scale', 1.0)
    ana = sphere
   
    canvas = VolumeCanvas.VolumeCanvas()        
    canvas.setParam('lores_density', density)
    
    handle = canvas.add('sphere')
    canvas.setParam('%s.radius' % handle, outer_radius)
    canvas.setParam('%s.contrast' % handle, shell_sld)
   
    handle2 = canvas.add('sphere')
    canvas.setParam('%s.radius' % handle2, radius)
    canvas.setParam('%s.contrast' % handle2, 1.0)
           
    canvas.setParam('scale' , 1.0)
    canvas.setParam('background' , 0.0)
    
               
    """ Testing default core-shell orientation """
    qlist = [.0001, 0.002, .01, .1, 1.0, 5.]
    for q in qlist:
        ana_val = ana.runXY([q, 0.2])
        sim_val, err = canvas.getIq2DError(q, 0.2)
        print ana_val, sim_val, sim_val/ana_val, err, (sim_val-ana_val)/err
 def setUp(self):
     from sas.models.CoreShellModel import CoreShellModel
     self.comp = CoreShellModel()
Пример #9
0
 def setUp(self):
     from sas.models.CoreShellModel import CoreShellModel
     radius = 15
     thickness = 5
     core_vol = 4.0/3.0*math.pi*radius*radius*radius
     outer_radius = radius+thickness
     shell_vol = 4.0/3.0*math.pi*outer_radius*outer_radius*outer_radius - core_vol
     self.shell_sld = -1.0*core_vol/shell_vol
     
     self.canvas = VolumeCanvas.VolumeCanvas()
     self.canvas.params['lores_density'] = 0.1
     
     # Core shell model
     sphere = CoreShellModel()
     # Core radius
     sphere.setParam('radius', radius)
     # Shell thickness
     sphere.setParam('thickness', thickness)
     sphere.setParam('core_sld', 1.0)
     sphere.setParam('shell_sld', self.shell_sld)
     sphere.setParam('solvent_sld', 0.0)
     sphere.setParam('background', 0.0)
     sphere.setParam('scale', 1.0)
     self.sphere = sphere
     self.radius = radius
     self.outer_radius = outer_radius
Пример #10
0
class TestCoreShell(unittest.TestCase):
    """
        Testing C++ Cylinder model
    """
    def setUp(self):
        from sas.models.CoreShellModel import CoreShellModel
        self.model = CoreShellModel()

        self.model.setParam('scale', 1.0)
        self.model.setParam('radius', 60.0)
        self.model.setParam('thickness', 10.0)
        self.model.setParam('core_sld', 1.e-6)
        self.model.setParam('shell_sld', 2.e-6)
        self.model.setParam('solvent_sld', 3.e-6)
        self.model.setParam('background', 0.0)

    def test_simple(self):
        """
            Test simple 1D and 2D values
            Numbers taken from model that passed validation, before
            the update to C++ underlying class.
        """
        self.assertAlmostEqual(self.model.run(0.001), 381.27304697150055, 3)
        self.assertAlmostEqual(self.model.runXY([0.001, 0.001]),
                               380.93779156218682, 3)

    def test_dispersion(self):
        """
            Test with dispersion
        """
        from sas.models.DisperseModel import DisperseModel
        disp = DisperseModel(self.model, ['radius', 'thickness'], [10, 2])
        disp.setParam('n_pts', 10)
        self.assertAlmostEqual(disp.run(0.001), 407.344127907553, 3)

    def test_new_disp(self):
        from sas.models.dispersion_models import GaussianDispersion
        disp_rm = GaussianDispersion()
        self.model.set_dispersion('radius', disp_rm)
        self.model.dispersion['radius']['width'] = 0.1666666667
        self.model.dispersion['radius']['npts'] = 10
        self.model.dispersion['radius']['nsigmas'] = 2

        disp_rr = GaussianDispersion()
        self.model.set_dispersion('thickness', disp_rr)
        self.model.dispersion['thickness']['width'] = 0.2
        self.model.dispersion['thickness']['npts'] = 10
        self.model.dispersion['thickness']['nsigmas'] = 2

        self.assertAlmostEqual(self.model.run(0.001),
                               1.16747510 * 407.344127907553, 3)
Пример #11
0
    def __init__(self, radius=15, thickness=5, density=0.01):
        from sas.models.CoreShellModel import CoreShellModel

        self.name = 'coreshell'
        self.radius = radius

        core_vol = 4.0 / 3.0 * math.pi * radius * radius * radius
        self.outer_radius = radius + thickness
        shell_vol = 4.0 / 3.0 * math.pi * self.outer_radius * self.outer_radius * self.outer_radius - core_vol
        self.shell_sld = -1.0 * core_vol / shell_vol

        self.density = density

        # Core-shell
        sphere = CoreShellModel()
        # Core radius
        sphere.setParam('radius', self.radius)
        # Shell thickness
        sphere.setParam('thickness', thickness)
        sphere.setParam('core_sld', 1.0)
        sphere.setParam('shell_sld', self.shell_sld)
        sphere.setParam('solvent_sld', 0.0)
        sphere.setParam('background', 0.0)
        sphere.setParam('scale', 1.0)
        self.ana = sphere
        self.create()
Пример #12
0
def test_2():
    radius = 15.0
    thickness = 5.0

    core_vol = 4.0 / 3.0 * math.pi * radius * radius * radius
    outer_radius = radius + thickness
    shell_vol = 4.0 / 3.0 * math.pi * outer_radius * outer_radius * outer_radius - core_vol
    shell_sld = -1.0 * core_vol / shell_vol
    print("Shell SLD", shell_sld)

    density = .1
    vol = 4 / 3 * math.pi * radius * radius * radius
    npts = vol * density

    canvas = VolumeCanvas.VolumeCanvas()
    canvas.setParam('lores_density', density)
    handle = canvas.add('sphere')
    canvas.setParam('%s.radius' % handle, outer_radius)
    canvas.setParam('%s.contrast' % handle, shell_sld)

    handle2 = canvas.add('sphere')
    canvas.setParam('%s.radius' % handle2, radius)
    canvas.setParam('%s.contrast' % handle2, 1.0)

    # Core-shell
    sphere = CoreShellModel()
    # Core radius
    sphere.setParam('radius', radius)
    # Shell thickness
    sphere.setParam('thickness', thickness)
    sphere.setParam('core_sld', 1.0)

    sphere.setParam('shell_sld', shell_sld)
    sphere.setParam('solvent_sld', 0.0)
    sphere.setParam('background', 0.0)
    sphere.setParam('scale', 1.0)

    out = open("lores_test.txt", 'w')
    out.write("<q> <sim> <ana>\n")

    for i in range(65):
        q = 0.001 + 0.01 * i

        # For each volume integral that we change to a sum,
        # we must multiply by 1/density = V/N
        # Since we want P(r)/V, we will need to multiply
        # the sum by 1/(N*density), where N is the number of
        # points without overlap. Since we already divide
        # by N when calculating I(q), we only need to divide
        # by the density here. We divide by N in the
        # calculation because it is difficult to estimate it here.

        # Put the factor 2 in the simulation two...
        sim_1 = canvas.getIq(q)
        ana_1 = sphere.run(q)

        print("q=%g  sim=%g  ana=%g   ratio=%g" %
              (q, sim_1, ana_1, sim_1 / ana_1))
        out.write("%g  %g  %g\n" % (q, sim_1, ana_1))

    out.close()
Пример #13
0
def test_7():
    from sas.models.CoreShellModel import CoreShellModel
    print("Testing core-shell")
    radius = 15
    thickness = 5
    density = 5

    core_vol = 4.0 / 3.0 * math.pi * radius * radius * radius
    outer_radius = radius + thickness
    shell_vol = 4.0 / 3.0 * math.pi * outer_radius * outer_radius * outer_radius - core_vol
    shell_sld = -1.0 * core_vol / shell_vol

    # Core-shell
    sphere = CoreShellModel()
    # Core radius
    sphere.setParam('radius', radius)
    # Shell thickness
    sphere.setParam('thickness', thickness)
    sphere.setParam('core_sld', 1.0)
    sphere.setParam('shell_sld', shell_sld)
    sphere.setParam('solvent_sld', 0.0)
    sphere.setParam('background', 0.0)
    sphere.setParam('scale', 1.0)
    ana = sphere

    canvas = VolumeCanvas.VolumeCanvas()
    canvas.setParam('lores_density', density)

    handle = canvas.add('sphere')
    canvas.setParam('%s.radius' % handle, outer_radius)
    canvas.setParam('%s.contrast' % handle, shell_sld)

    handle2 = canvas.add('sphere')
    canvas.setParam('%s.radius' % handle2, radius)
    canvas.setParam('%s.contrast' % handle2, 1.0)

    canvas.setParam('scale', 1.0)
    canvas.setParam('background', 0.0)
    """ Testing default core-shell orientation """
    qlist = [.0001, 0.002, .01, .1, 1.0, 5.]
    for q in qlist:
        ana_val = ana.runXY([q, 0.2])
        sim_val, err = canvas.getIq2DError(q, 0.2)
        print(ana_val, sim_val, sim_val / ana_val, err,
              (sim_val - ana_val) / err)
Пример #14
0
    def setUp(self):
        from sas.models.CoreShellModel import CoreShellModel
        radius = 15
        thickness = 5
        core_vol = 4.0 / 3.0 * math.pi * radius * radius * radius
        outer_radius = radius + thickness
        shell_vol = 4.0 / 3.0 * math.pi * outer_radius * outer_radius * outer_radius - core_vol
        self.shell_sld = -1.0 * core_vol / shell_vol

        self.canvas = VolumeCanvas.VolumeCanvas()
        self.canvas.params['lores_density'] = 0.1

        # Core shell model
        sphere = CoreShellModel()
        # Core radius
        sphere.setParam('radius', radius)
        # Shell thickness
        sphere.setParam('thickness', thickness)
        sphere.setParam('core_sld', 1.0)
        sphere.setParam('shell_sld', self.shell_sld)
        sphere.setParam('solvent_sld', 0.0)
        sphere.setParam('background', 0.0)
        sphere.setParam('scale', 1.0)
        self.sphere = sphere
        self.radius = radius
        self.outer_radius = outer_radius
Пример #15
0
 def setUp(self):
     from sas.models.CoreShellModel import CoreShellModel
     self.comp = CoreShellModel()
Пример #16
0
    def setUp(self):
        """ Set up zero-SLD-average core-shell model """
        from sas.models.CoreShellModel import CoreShellModel
        
        radius = 15
        thickness = 5
        density = 5
        
        core_vol = 4.0/3.0*math.pi*radius*radius*radius
        self.outer_radius = radius+thickness
        shell_vol = 4.0/3.0*math.pi*self.outer_radius*self.outer_radius*self.outer_radius - core_vol
        self.shell_sld = -1.0*core_vol/shell_vol

        self.density = density
           
        # Core-shell
        sphere = CoreShellModel()
        # Core radius
        sphere.setParam('radius', radius)
        # Shell thickness
        sphere.setParam('thickness', thickness)
        sphere.setParam('core_sld', 1.0)
        sphere.setParam('shell_sld', self.shell_sld)
        sphere.setParam('solvent_sld', 0.0)
        sphere.setParam('background', 0.0)
        sphere.setParam('scale', 1.0)
        self.ana = sphere
       
        canvas = VolumeCanvas.VolumeCanvas()        
        canvas.setParam('lores_density', self.density)
        
        handle = canvas.add('sphere')
        canvas.setParam('%s.radius' % handle, self.outer_radius)
        canvas.setParam('%s.contrast' % handle, self.shell_sld)
       
        handle2 = canvas.add('sphere')
        canvas.setParam('%s.radius' % handle2, radius)
        canvas.setParam('%s.contrast' % handle2, 1.0)
               
        canvas.setParam('scale' , 1.0)
        canvas.setParam('background' , 0.0)
        self.canvas = canvas