source: sasview/sansmodels/src/sans/models/FractalModel.py @ 0cbfaeb

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

working on model pickle

  • Property mode set to 100644
File size: 5.3 KB
RevLine 
[829eee9]1#!/usr/bin/env python
[ec658c85]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##############################################################################
[ec658c85]16
17
[79ac6f8]18"""
19Provide functionality for a C extension model
[ec658c85]20
[79ac6f8]21:WARNING: THIS FILE WAS GENERATED BY WRAPPERGENERATOR.PY
22         DO NOT MODIFY THIS FILE, MODIFY ..\c_extensions\fractal.h
23         AND RE-RUN THE GENERATOR SCRIPT
[ec658c85]24
[829eee9]25"""
26
27from sans.models.BaseComponent import BaseComponent
[ec658c85]28from sans_extension.c_models import CFractalModel
29import copy   
[96656e3]30
31def create_FractalModel():
32    obj = FractalModel()
33    #CFractalModel.__init__(obj) is called by FractalModel constructor
34    return obj
35
[ec658c85]36class FractalModel(CFractalModel, BaseComponent):
[79ac6f8]37    """
38    Class that evaluates a FractalModel model.
39    This file was auto-generated from ..\c_extensions\fractal.h.
40    Refer to that file and the structure it contains
41    for details of the model.
42    List of default parameters:
[ec658c85]43         scale           = 0.05
44         radius          = 5.0 [A]
45         fractal_dim     = 2.0
46         cor_length      = 100.0 [A]
47         sldBlock        = 2e-006 [1/A^(2)]
48         sldSolv         = 6.35e-006 [1/A^(2)]
49         background      = 0.0 [1/cm]
[829eee9]50
51    """
52       
53    def __init__(self):
54        """ Initialization """
55       
[ec658c85]56        # Initialize BaseComponent first, then sphere
[829eee9]57        BaseComponent.__init__(self)
[96656e3]58        #apply(CFractalModel.__init__, (self,))
[ec658c85]59        CFractalModel.__init__(self)
[829eee9]60       
61        ## Name of the model
[ec658c85]62        self.name = "FractalModel"
63        ## Model description
64        self.description =""" The scattering intensity  I(x) = P(|x|)*S(|x|) + background, where
65                p(x)= scale * V * delta^(2)* F(x*radius)^(2)
66                F(x) = 3*[sin(x)-x cos(x)]/x**3
67                where delta = sldBlock -sldSolv.
68                scale        =  scale factor * Volume fraction
69                radius       =  Block radius
70                fractal_dim  =  Fractal dimension
71                cor_length  =  Correlation Length
72                sldBlock    =  SDL block
73                sldSolv  =  SDL solvent
74                background   =  background"""
75       
[829eee9]76        ## Parameter details [units, min, max]
77        self.details = {}
[ec658c85]78        self.details['scale'] = ['', None, None]
79        self.details['radius'] = ['[A]', None, None]
80        self.details['fractal_dim'] = ['', None, None]
81        self.details['cor_length'] = ['[A]', None, None]
82        self.details['sldBlock'] = ['[1/A^(2)]', None, None]
83        self.details['sldSolv'] = ['[1/A^(2)]', None, None]
84        self.details['background'] = ['[1/cm]', None, None]
[36948c92]85
[ec658c85]86        ## fittable parameters
87        self.fixed=[]
[3db3895]88       
[35aface]89        ## non-fittable parameters
[96656e3]90        self.non_fittable = []
[35aface]91       
[ec658c85]92        ## parameters with orientation
[96656e3]93        self.orientation_params = []
[c7a7e1b]94
95    def __setstate__(self, state):
96        """
97        restore the state of a model from pickle
98        """
99        self.__dict__, self.params, self.dispersion = state
100       
[96656e3]101    def __reduce_ex__(self, proto):
[79ac6f8]102        """
[96656e3]103        Overwrite the __reduce_ex__ of PyTypeObject *type call in the init of
104        c model.
[79ac6f8]105        """
[c7a7e1b]106        state = (self.__dict__, self.params, self.dispersion)
107        return (create_FractalModel,tuple(), state, None, None)
[ec658c85]108       
[96656e3]109    def clone(self):
110        """ Return a identical copy of self """
111        return self._clone(FractalModel())   
[ec658c85]112       
113   
[79ac6f8]114    def run(self, x=0.0):
115        """
116        Evaluate the model
117       
118        :param x: input q, or [q,phi]
119       
120        :return: scattering function P(q)
121       
[829eee9]122        """
[ec658c85]123       
124        return CFractalModel.run(self, x)
[829eee9]125   
[79ac6f8]126    def runXY(self, x=0.0):
127        """
128        Evaluate the model in cartesian coordinates
129       
130        :param x: input q, or [qx, qy]
131       
132        :return: scattering function P(q)
133       
[ec658c85]134        """
135       
136        return CFractalModel.runXY(self, x)
137       
[79ac6f8]138    def evalDistribution(self, x=[]):
139        """
140        Evaluate the model in cartesian coordinates
141       
142        :param x: input q[], or [qx[], qy[]]
143       
144        :return: scattering function P(q[])
145       
[ec658c85]146        """
147        return CFractalModel.evalDistribution(self, x)
148       
149    def calculate_ER(self):
[79ac6f8]150        """
151        Calculate the effective radius for P(q)*S(q)
152       
153        :return: the value of the effective radius
154       
[ec658c85]155        """       
156        return CFractalModel.calculate_ER(self)
157       
158    def set_dispersion(self, parameter, dispersion):
159        """
[79ac6f8]160        Set the dispersion object for a model parameter
161       
162        :param parameter: name of the parameter [string]
163        :param dispersion: dispersion object of type DispersionModel
164       
[829eee9]165        """
[ec658c85]166        return CFractalModel.set_dispersion(self, parameter, dispersion.cdisp)
167       
168   
169# End of file
Note: See TracBrowser for help on using the repository browser.