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

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

added polymerexclVolume model and its test

  • Property mode set to 100644
File size: 4.1 KB
RevLine 
[ec1c554]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   
19   
20class PolymerExclVolume(BaseComponent):
21    """
22    Class that evaluates a PolymerExclVolModel model.
23    This file was auto-generated from ..\c_extensions\polyexclvol.h.
24    Refer to that file and the structure it contains
25    for details of the model.
26    List of default parameters:
27         scale           = 0.01
28         rg              = 100.0 [A]
29         m               = 3.0
30         background      = 0.0 [1/cm]
31
32    """
33       
34    def __init__(self):
35        """ Initialization """
36       
37        # Initialize BaseComponent first, then sphere
38        BaseComponent.__init__(self)
39       
40        ## Name of the model
41        self.name = "PolymerExclVolume"
42        ## Model description
43        self.description =""" Compute the scattering intensity from polymers with excluded volume effects.
44                scale: scale factor times volume fraction,
45                or just volume fraction for absolute scale data
46                rg: radius of gyration
47                m = Porod exponent
48                background: incoherent background
49                """
50        ## Define parameters
51        self.params = {}
52        self.params['scale']        = 1.0
53        self.params['rg']           = 60.0
54        self.params['m']            = 3.0
55        self.params['background']   = 0.0
56
57       
58        ## Parameter details [units, min, max]
59        self.details = {}
60        self.details['scale'] = ['', None, None]
61        self.details['rg'] = ['[A]', None, None]
62        self.details['m'] = ['', None, None]
63        self.details['background'] = ['[1/cm]', None, None]
64
65        ## fittable parameters
66        self.fixed=[]
67       
68        ## non-fittable parameters
69        self.non_fittable=[]
70       
71        ## parameters with orientation
72        self.orientation_params =[]
73       
74    def _polymerexclvol(self, x):
75       
76        sc = self.params['scale']
77        rg = self.params['rg']
78        mm  = self.params['m']
79        bg = self.params['background']
80   
81        nu = 1.0 / mm
82   
83        Xx = x * x * rg * rg *(2.0 * nu + 1.0) * (2.0 * nu + 2.0) / 6.0
84        onu = 1.0 / nu
85        o2nu = 1.0 /(2.0 * nu)
86        Ps =(1.0 / (nu * pow(Xx,o2nu))) * (gamma(o2nu)*gammainc(o2nu,Xx) - \
87                        1.0 / pow(Xx,o2nu) * gamma(onu)*gammainc(onu,Xx))
88
89        if x == 0:
90            Ps = 1.0
91
92        return (sc * Ps + bg);
93
94    def run(self, x = 0.0):
95        """ Evaluate the model
96            @param x: input q-value (float or [float, float] as [r, theta])
97            @return: (guinier value)
98        """
99        if x.__class__.__name__ == 'list':
100            return self._guinier(x[0])
101        elif x.__class__.__name__ == 'tuple':
102            raise ValueError, "Tuples are not allowed as input to BaseComponent models"
103        else:
104            return self._polymerexclvol(x)
105   
106    def runXY(self, x = 0.0):
107        """ Evaluate the model
108            @param x: input q-value (float or [float, float] as [qx, qy])
109            @return: guinier value
110        """
111        if x.__class__.__name__ == 'list':
112            q = math.sqrt(x[0]**2 + x[1]**2)
113            return self._polymerexclvol(x)
114        elif x.__class__.__name__ == 'tuple':
115            raise ValueError, "Tuples are not allowed as input to BaseComponent models"
116        else:
117            return self._polymerexclvol(x)
118       
119
120   
121# End of file
Note: See TracBrowser for help on using the repository browser.