Beispiel #1
0
 def setUp(self):
     from sas.models.BEPolyelectrolyte import BEPolyelectrolyte
     self.model= BEPolyelectrolyte()
     
     self.K = 10.0
     self.Lb = 6.5
     self.h = 11
     self.b = 13
     self.Cs = 0.1
     self.alpha = 0.05
     self.C  = .7
     self.Bkd =0.01
    
     self.model.setParam('K', self.K) 
     self.model.setParam('Lb', self.Lb) 
     self.model.setParam('H', self.h)
     self.model.setParam('B', self.b)
     self.model.setParam('Cs',self.Cs) 
     self.model.setParam('alpha', self.alpha) 
     self.model.setParam('C', self.C)
     self.model.setParam('background', self.Bkd)
Beispiel #2
0
class TestBEPolyelectrolyte(unittest.TestCase):
    """
        Unit tests for  BEPolyelectrolyte function
        
        F(x) = K*1/(4*pi()*Lb*(alpha)^(2)*(q^(2)+k2)/(1+(r02)^(2))*(q^(2)+k2)\
                       *(q^(2)-(12*h*C/b^(2)))
        
        The model has Eight parameters: 
            K        =  Constrast factor of the polymer
            Lb       =  Bjerrum length
            H        =  virial parameter
            B        =  monomer length
            Cs       =  Concentration of monovalent salt 
            alpha    =  ionazation degree 
            C        = polymer molar concentration
            bkd      = background
    """
    def _func(self, K, Lb, H, B, Cs, alpha, C, bkd, r02, k2,  x):
        return (K /( (4*math.pi *Lb*(alpha**2)*(x**2 +k2)) *( (1 +(r02**2))  \
                    *((x**2) + k2)*((x**2) -(12 * H * C/(B**2))) )))+ bkd
    
    def setUp(self):
        from sas.models.BEPolyelectrolyte import BEPolyelectrolyte
        self.model= BEPolyelectrolyte()
        
        self.K = 10.0
        self.Lb = 6.5
        self.h = 11
        self.b = 13
        self.Cs = 0.1
        self.alpha = 0.05
        self.C  = .7
        self.Bkd =0.01
       
        self.model.setParam('K', self.K) 
        self.model.setParam('Lb', self.Lb) 
        self.model.setParam('H', self.h)
        self.model.setParam('B', self.b)
        self.model.setParam('Cs',self.Cs) 
        self.model.setParam('alpha', self.alpha) 
        self.model.setParam('C', self.C)
        self.model.setParam('background', self.Bkd)
        
    def _func(self, q):
        
        Ca = self.C *6.022136e-4          
        Csa = self.Cs * 6.022136e-4        
        k2= 4*math.pi*self.Lb*(2*self.Cs+self.alpha*Ca)   

        r02 = 1./self.alpha / Ca**0.5*( self.b / (48*math.pi*self.Lb)**0.5 )
        q2 = q**2    
        Sq = self.K*1./(4*math.pi*self.Lb*self.alpha**2) * (q2 + k2)  /  (1+(r02**2) * (q2+k2) * (q2- (12*self.h*Ca/self.b**2)) ) + self.Bkd
        return Sq
       
    def test1D(self):
        
       
        q = 0.001
   
        self.assertEqual(self.model.run(q), self._func(q))
        self.assertEqual(self.model.runXY(q), self._func(q))
         
    def test2D(self):
        #self.assertAlmostEquals(self.model.runXY([1.0,2.0]), self._func(1.0)*self._func(2.0), 8)
        self.assertAlmostEquals(self.model.runXY([1.0,2.0]), self._func(math.sqrt(1.0+2.0**2)), 8)
        
    def test2Dphi(self):

        x = 1.0
        y = 2.0
        r = math.sqrt(x**2 + y**2)
        phi = math.atan2(y, x)
        
        self.assertAlmostEquals(self.model.run([r, phi]), self._func(r), 8)