source: sasview/sansmodels/src/sans/models/PolymerExclVolume.py @ 95fe70d

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 95fe70d was a496177a, checked in by Jae Cho <jhjcho@…>, 14 years ago

added missing import (math)

  • Property mode set to 100644
File size: 4.1 KB
Line 
1#!/usr/bin/env python
2
3##############################################################################
4#       This software was developed by the University of Tennessee as part of the
5#       Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
6#       project funded by the US National Science Foundation.
7#
8#       If you use DANSE applications to do scientific research that leads to
9#       publication, we ask that you acknowledge the use of the software with the
10#       following sentence:
11#
12#       "This work benefited from DANSE software developed under NSF award DMR-0520547."
13#
14#       copyright 2008, University of Tennessee
15##############################################################################
16from sans.models.BaseComponent import BaseComponent
17from scipy.special import gammainc,gamma
18import copy   
19import math
20   
21class PolymerExclVolume(BaseComponent):
22    """
23    Class that evaluates a PolymerExclVolModel model.
24    This file was auto-generated from ..\c_extensions\polyexclvol.h.
25    Refer to that file and the structure it contains
26    for details of the model.
27    List of default parameters:
28         scale           = 0.01
29         rg              = 100.0 [A]
30         m               = 3.0
31         background      = 0.0 [1/cm]
32
33    """
34       
35    def __init__(self):
36        """ Initialization """
37       
38        # Initialize BaseComponent first, then sphere
39        BaseComponent.__init__(self)
40       
41        ## Name of the model
42        self.name = "PolymerExclVolume"
43        ## Model description
44        self.description =""" Compute the scattering intensity from polymers with excluded volume effects.
45                scale: scale factor times volume fraction,
46                or just volume fraction for absolute scale data
47                rg: radius of gyration
48                m = Porod exponent
49                background: incoherent background
50                """
51        ## Define parameters
52        self.params = {}
53        self.params['scale']        = 1.0
54        self.params['rg']           = 60.0
55        self.params['m']            = 3.0
56        self.params['background']   = 0.0
57
58       
59        ## Parameter details [units, min, max]
60        self.details = {}
61        self.details['scale'] = ['', None, None]
62        self.details['rg'] = ['[A]', None, None]
63        self.details['m'] = ['', None, None]
64        self.details['background'] = ['[1/cm]', None, None]
65
66        ## fittable parameters
67        self.fixed=[]
68       
69        ## non-fittable parameters
70        self.non_fittable=[]
71       
72        ## parameters with orientation
73        self.orientation_params =[]
74       
75    def _polymerexclvol(self, x):
76       
77        sc = self.params['scale']
78        rg = self.params['rg']
79        mm  = self.params['m']
80        bg = self.params['background']
81   
82        nu = 1.0 / mm
83   
84        Xx = x * x * rg * rg *(2.0 * nu + 1.0) * (2.0 * nu + 2.0) / 6.0
85        onu = 1.0 / nu
86        o2nu = 1.0 /(2.0 * nu)
87        Ps =(1.0 / (nu * pow(Xx,o2nu))) * (gamma(o2nu)*gammainc(o2nu,Xx) - \
88                        1.0 / pow(Xx,o2nu) * gamma(onu)*gammainc(onu,Xx))
89
90        if x == 0:
91            Ps = 1.0
92
93        return (sc * Ps + bg);
94
95    def run(self, x = 0.0):
96        """ Evaluate the model
97            @param x: input q-value (float or [float, float] as [r, theta])
98            @return: (guinier value)
99        """
100        if x.__class__.__name__ == 'list':
101            return self._guinier(x[0])
102        elif x.__class__.__name__ == 'tuple':
103            raise ValueError, "Tuples are not allowed as input to BaseComponent models"
104        else:
105            return self._polymerexclvol(x)
106   
107    def runXY(self, x = 0.0):
108        """ Evaluate the model
109            @param x: input q-value (float or [float, float] as [qx, qy])
110            @return: guinier value
111        """
112        if x.__class__.__name__ == 'list':
113            q = math.sqrt(x[0]**2 + x[1]**2)
114            return self._polymerexclvol(x)
115        elif x.__class__.__name__ == 'tuple':
116            raise ValueError, "Tuples are not allowed as input to BaseComponent models"
117        else:
118            return self._polymerexclvol(x)
119       
120
121   
122# End of file
Note: See TracBrowser for help on using the repository browser.