source: sasview/sansmodels/src/sans/models/CoreShellCylinderModel.py @ 5d2b35a

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 5d2b35a was c7a7e1b, checked in by Gervaise Alina <gervyh@…>, 14 years ago

working on model pickle

  • Property mode set to 100644
File size: 6.3 KB
RevLine 
[ae3ce4e]1#!/usr/bin/env python
[95986b5]2
[79ac6f8]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##############################################################################
[95986b5]16
17
[79ac6f8]18"""
19Provide functionality for a C extension model
[ae3ce4e]20
[79ac6f8]21:WARNING: THIS FILE WAS GENERATED BY WRAPPERGENERATOR.PY
22         DO NOT MODIFY THIS FILE, MODIFY ..\c_extensions\core_shell_cylinder.h
23         AND RE-RUN THE GENERATOR SCRIPT
[ae3ce4e]24
25"""
26
27from sans.models.BaseComponent import BaseComponent
28from sans_extension.c_models import CCoreShellCylinderModel
29import copy   
[96656e3]30
31def create_CoreShellCylinderModel():
32    obj = CoreShellCylinderModel()
33    #CCoreShellCylinderModel.__init__(obj) is called by CoreShellCylinderModel constructor
34    return obj
35
[ae3ce4e]36class CoreShellCylinderModel(CCoreShellCylinderModel, BaseComponent):
[79ac6f8]37    """
38    Class that evaluates a CoreShellCylinderModel model.
39    This file was auto-generated from ..\c_extensions\core_shell_cylinder.h.
40    Refer to that file and the structure it contains
41    for details of the model.
42    List of default parameters:
[ae3ce4e]43         scale           = 1.0
[1ed3834]44         radius          = 20.0 [A]
45         thickness       = 10.0 [A]
46         length          = 400.0 [A]
[27972c1d]47         core_sld        = 1e-006 [1/A^(2)]
48         shell_sld       = 4e-006 [1/A^(2)]
49         solvent_sld     = 1e-006 [1/A^(2)]
[0824909]50         background      = 0.0 [1/cm]
[4628e31]51         axis_theta      = 90.0 [deg]
52         axis_phi        = 0.0 [deg]
[ae3ce4e]53
54    """
55       
56    def __init__(self):
57        """ Initialization """
58       
59        # Initialize BaseComponent first, then sphere
60        BaseComponent.__init__(self)
[96656e3]61        #apply(CCoreShellCylinderModel.__init__, (self,))
[ae3ce4e]62        CCoreShellCylinderModel.__init__(self)
63       
64        ## Name of the model
65        self.name = "CoreShellCylinderModel"
[836fe6e]66        ## Model description
[1ed3834]67        self.description ="""P(q,alpha)= scale/Vs*f(q)^(2) + bkg,  where: f(q)= 2(core_sld
68                - solvant_sld)* Vc*sin[qLcos(alpha/2)]
69                /[qLcos(alpha/2)]*J1(qRsin(alpha))
70                /[qRsin(alpha)]+2(shell_sld-solvent_sld)
71                *Vs*sin[q(L+T)cos(alpha/2)][[q(L+T)
72                *cos(alpha/2)]*J1(q(R+T)sin(alpha))
73                /q(R+T)sin(alpha)]
74               
75                alpha:is the angle between the axis of
76                the cylinder and the q-vector
[9316609]77                Vs: the volume of the outer shell
78                Vc: the volume of the core
79                L: the length of the core
[1ed3834]80                shell_sld: the scattering length density
81                of the shell
82                solvent_sld: the scattering length density
83                of the solvent
[9316609]84                bkg: the background
85                T: the thickness
86                R+T: is the outer radius
87                L+2T: The total length of the outershell
88                J1: the first order Bessel function
89                theta: axis_theta of the cylinder
[9bd69098]90                phi: the axis_phi of the cylinder..."""
[836fe6e]91       
[fe9c19b4]92        ## Parameter details [units, min, max]
[ae3ce4e]93        self.details = {}
94        self.details['scale'] = ['', None, None]
[1ed3834]95        self.details['radius'] = ['[A]', None, None]
96        self.details['thickness'] = ['[A]', None, None]
97        self.details['length'] = ['[A]', None, None]
[27972c1d]98        self.details['core_sld'] = ['[1/A^(2)]', None, None]
99        self.details['shell_sld'] = ['[1/A^(2)]', None, None]
100        self.details['solvent_sld'] = ['[1/A^(2)]', None, None]
[0824909]101        self.details['background'] = ['[1/cm]', None, None]
[4628e31]102        self.details['axis_theta'] = ['[deg]', None, None]
103        self.details['axis_phi'] = ['[deg]', None, None]
[836fe6e]104
[fe9c19b4]105        ## fittable parameters
[9bd69098]106        self.fixed=['axis_phi.width', 'axis_theta.width', 'length.width', 'radius.width', 'thickness.width']
[25a608f5]107       
[35aface]108        ## non-fittable parameters
[96656e3]109        self.non_fittable = []
[35aface]110       
[25a608f5]111        ## parameters with orientation
[96656e3]112        self.orientation_params = ['axis_phi', 'axis_theta', 'axis_phi.width', 'axis_theta.width']
[c7a7e1b]113
114    def __setstate__(self, state):
115        """
116        restore the state of a model from pickle
117        """
118        self.__dict__, self.params, self.dispersion = state
119       
[96656e3]120    def __reduce_ex__(self, proto):
[79ac6f8]121        """
[96656e3]122        Overwrite the __reduce_ex__ of PyTypeObject *type call in the init of
123        c model.
[79ac6f8]124        """
[c7a7e1b]125        state = (self.__dict__, self.params, self.dispersion)
126        return (create_CoreShellCylinderModel,tuple(), state, None, None)
[fe9c19b4]127       
[96656e3]128    def clone(self):
129        """ Return a identical copy of self """
130        return self._clone(CoreShellCylinderModel())   
[fe9c19b4]131       
[ae3ce4e]132   
[79ac6f8]133    def run(self, x=0.0):
134        """
135        Evaluate the model
136       
137        :param x: input q, or [q,phi]
138       
139        :return: scattering function P(q)
140       
[ae3ce4e]141        """
142       
143        return CCoreShellCylinderModel.run(self, x)
144   
[79ac6f8]145    def runXY(self, x=0.0):
146        """
147        Evaluate the model in cartesian coordinates
148       
149        :param x: input q, or [qx, qy]
150       
151        :return: scattering function P(q)
152       
[ae3ce4e]153        """
154       
155        return CCoreShellCylinderModel.runXY(self, x)
[95986b5]156       
[79ac6f8]157    def evalDistribution(self, x=[]):
158        """
159        Evaluate the model in cartesian coordinates
160       
161        :param x: input q[], or [qx[], qy[]]
162       
163        :return: scattering function P(q[])
164       
[9bd69098]165        """
[f9a1279]166        return CCoreShellCylinderModel.evalDistribution(self, x)
[9bd69098]167       
[5eb9154]168    def calculate_ER(self):
[79ac6f8]169        """
170        Calculate the effective radius for P(q)*S(q)
171       
172        :return: the value of the effective radius
173       
[5eb9154]174        """       
175        return CCoreShellCylinderModel.calculate_ER(self)
176       
[95986b5]177    def set_dispersion(self, parameter, dispersion):
178        """
[79ac6f8]179        Set the dispersion object for a model parameter
180       
181        :param parameter: name of the parameter [string]
182        :param dispersion: dispersion object of type DispersionModel
183       
[95986b5]184        """
185        return CCoreShellCylinderModel.set_dispersion(self, parameter, dispersion.cdisp)
186       
[ae3ce4e]187   
188# End of file
Note: See TracBrowser for help on using the repository browser.