Changes in sasmodels/modelinfo.py [39a06c9:4f4d3e3] in sasmodels
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/modelinfo.py
r39a06c9 r4f4d3e3 164 164 parameter.length = length 165 165 parameter.length_control = control 166 166 167 return parameter 167 168 … … 264 265 will have a magnitude and a direction, which may be different from 265 266 other sld parameters. The volume parameters are used for calls 266 to form_volume within the kernel (required for volume normalization) ,267 to shell_volume (for hollow shapes), and to effective_radius (for268 structure factor interactions)respectively.267 to form_volume within the kernel (required for volume normalization) 268 and for calls to ER and VR for effective radius and volume ratio 269 respectively. 269 270 270 271 *description* is a short description of the parameter. This will … … 290 291 example, might be used to set the value of a shape parameter. 291 292 292 These values are set by :func:`make_parameter_table` and 293 Control parameters are used for variant models such as :ref:`rpa` which 294 have different cases with different parameters, as well as models 295 like :ref:`spherical_sld` with its user defined number of shells. 296 The control parameter should appear in the parameter table along with the 297 parameters it is is controlling. For variant models, use *[CASES]* in 298 place of the parameter limits Within the parameter definition table, 299 with case names such as:: 300 301 CASES = ["diblock copolymer", "triblock copolymer", ...] 302 303 This should give *limits=[[case1, case2, ...]]*, but the model loader 304 translates it to *limits=[0, len(CASES)-1]*, and adds *choices=CASES* to 305 the :class:`Parameter` definition. Note that models can use a list of 306 cases as a parameter without it being a control parameter. Either way, 307 the parameter is sent to the model evaluator as *float(choice_num)*, 308 where choices are numbered from 0. :meth:`ModelInfo.get_hidden_parameters` 309 will determine which parameers to display. 310 311 The class contructor should not be called directly, but instead the 312 parameter table is built using :func:`make_parameter_table` and 293 313 :func:`parse_parameter` therein. 294 314 """ … … 423 443 self.kernel_parameters = parameters 424 444 self._set_vector_lengths() 445 425 446 self.npars = sum(p.length for p in self.kernel_parameters) 426 447 self.nmagnetic = sum(p.length for p in self.kernel_parameters … … 429 450 if self.nmagnetic: 430 451 self.nvalues += 3 + 3*self.nmagnetic 452 431 453 self.call_parameters = self._get_call_parameters() 432 454 self.defaults = self._get_defaults() … … 719 741 720 742 #: Set of variables defined in the model that might contain C code 721 C_SYMBOLS = ['Imagnetic', 'Iq', 'Iqxy', 'Iqac', 'Iqabc', 'form_volume', ' shell_volume', 'c_code']743 C_SYMBOLS = ['Imagnetic', 'Iq', 'Iqxy', 'Iqac', 'Iqabc', 'form_volume', 'c_code'] 722 744 723 745 def _find_source_lines(model_info, kernel_module): … … 768 790 # Custom sum/multi models 769 791 return kernel_module.model_info 770 771 792 info = ModelInfo() 772 793 #print("make parameter table", kernel_module.parameters) … … 790 811 info.category = getattr(kernel_module, 'category', None) 791 812 info.structure_factor = getattr(kernel_module, 'structure_factor', False) 792 # TODO: find Fq by inspection793 info.effective_radius_type = getattr(kernel_module, 'effective_radius_type', None)794 info.have_Fq = getattr(kernel_module, 'have_Fq', False)795 813 info.profile_axes = getattr(kernel_module, 'profile_axes', ['x', 'y']) 796 814 # Note: custom.load_custom_kernel_module assumes the C sources are defined … … 798 816 info.source = getattr(kernel_module, 'source', []) 799 817 info.c_code = getattr(kernel_module, 'c_code', None) 800 info.effective_radius = getattr(kernel_module, 'effective_radius', None)801 818 # TODO: check the structure of the tests 802 819 info.tests = getattr(kernel_module, 'tests', []) 820 info.ER = getattr(kernel_module, 'ER', None) # type: ignore 821 info.VR = getattr(kernel_module, 'VR', None) # type: ignore 803 822 info.form_volume = getattr(kernel_module, 'form_volume', None) # type: ignore 804 info.shell_volume = getattr(kernel_module, 'shell_volume', None) # type: ignore805 823 info.Iq = getattr(kernel_module, 'Iq', None) # type: ignore 806 824 info.Iqxy = getattr(kernel_module, 'Iqxy', None) # type: ignore … … 814 832 info.single = getattr(kernel_module, 'single', not callable(info.Iq)) 815 833 info.random = getattr(kernel_module, 'random', None) 816 817 # multiplicity info818 control_pars = [p.id for p in parameters.kernel_parameters if p.is_control]819 default_control = control_pars[0] if control_pars else None820 info.control = getattr(kernel_module, 'control', default_control)821 834 info.hidden = getattr(kernel_module, 'hidden', None) # type: ignore 835 836 # Set control flag for explicitly set parameters, e.g., in the RPA model. 837 control = getattr(kernel_module, 'control', None) 838 if control is not None: 839 parameters[control].is_control = True 822 840 823 841 if callable(info.Iq) and parameters.has_2d: … … 826 844 info.lineno = {} 827 845 _find_source_lines(info, kernel_module) 846 828 847 return info 829 848 … … 872 891 #: *sphere*hardsphere* or *cylinder+sphere*. 873 892 composition = None # type: Optional[Tuple[str, List[ModelInfo]]] 874 #: Name of the control parameter for a variant model such as :ref:`rpa`.875 #: The *control* parameter should appear in the parameter table, with876 #: limits defined as *[CASES]*, for case names such as877 #: *CASES = ["diblock copolymer", "triblock copolymer", ...]*.878 #: This should give *limits=[[case1, case2, ...]]*, but the879 #: model loader translates this to *limits=[0, len(CASES)-1]*, and adds880 #: *choices=CASES* to the :class:`Parameter` definition. Note that881 #: models can use a list of cases as a parameter without it being a882 #: control parameter. Either way, the parameter is sent to the model883 #: evaluator as *float(choice_num)*, where choices are numbered from 0.884 #: See also :attr:`hidden`.885 control = None # type: str886 893 #: Different variants require different parameters. In order to show 887 894 #: just the parameters needed for the variant selected by :attr:`control`, … … 918 925 #: provided in the file. 919 926 structure_factor = None # type: bool 920 #: True if the model defines an Fq function with signature921 #: void Fq(double q, double *F1, double *F2, ...)922 have_Fq = False923 #: List of options for computing the effective radius of the shape,924 #: or None if the model is not usable as a form factor model.925 effective_radius_type = None # type: List[str]926 927 #: List of C source files used to define the model. The source files 927 928 #: should define the *Iq* function, and possibly *Iqac* or *Iqabc* if the 928 929 #: model defines orientation parameters. Files containing the most basic 929 930 #: functions must appear first in the list, followed by the files that 930 #: use those functions. 931 #: use those functions. Form factors are indicated by providing 932 #: an :attr:`ER` function. 931 933 source = None # type: List[str] 932 #: inline source code, added after all elements of source 933 c_code = None # type: Optional[str] 934 #: The set of tests that must pass. The format of the tests is described 935 #: in :mod:`model_test`. 936 tests = None # type: List[TestCondition] 937 #: Returns the effective radius of the model given its volume parameters. 938 #: The presence of *ER* indicates that the model is a form factor model 939 #: that may be used together with a structure factor to form an implicit 940 #: multiplication model. 941 #: 942 #: The parameters to the *ER* function must be marked with type *volume*. 943 #: in the parameter table. They will appear in the same order as they 944 #: do in the table. The values passed to *ER* will be vectors, with one 945 #: value for each polydispersity condition. For example, if the model 946 #: is polydisperse over both length and radius, then both length and 947 #: radius will have the same number of values in the vector, with one 948 #: value for each *length X radius*. If only *radius* is polydisperse, 949 #: then the value for *length* will be repeated once for each value of 950 #: *radius*. The *ER* function should return one effective radius for 951 #: each parameter set. Multiplicity parameters will be received as 952 #: arrays, with one row per polydispersity condition. 953 ER = None # type: Optional[Callable[[np.ndarray], np.ndarray]] 954 #: Returns the occupied volume and the total volume for each parameter set. 955 #: See :attr:`ER` for details on the parameters. 956 VR = None # type: Optional[Callable[[np.ndarray], Tuple[np.ndarray, np.ndarray]]] 957 #: Arbitrary C code containing supporting functions, etc., to be inserted 958 #: after everything in source. This can include Iq and Iqxy functions with 959 #: the full function signature, including all parameters. 960 c_code = None 934 961 #: Returns the form volume for python-based models. Form volume is needed 935 962 #: for volume normalization in the polydispersity integral. If no … … 939 966 #: C code, either defined as a string, or in the sources. 940 967 form_volume = None # type: Union[None, str, Callable[[np.ndarray], float]] 941 #: Returns the shell volume for python-based models. Form volume and942 #: shell volume are needed for volume normalization in the polydispersity943 #: integral and structure interactions for hollow shapes. If no944 #: parameters are *volume* parameters, then shell volume is not needed.945 #: For C-based models, (with :attr:`sources` defined, or with :attr:`Iq`946 #: defined using a string containing C code), shell_volume must also be947 #: C code, either defined as a string, or in the sources.948 shell_volume = None # type: Union[None, str, Callable[[np.ndarray], float]]949 968 #: Returns *I(q, a, b, ...)* for parameters *a*, *b*, etc. defined 950 969 #: by the parameter table. *Iq* can be defined as a python function, or … … 981 1000 #: Line numbers for symbols defining C code 982 1001 lineno = None # type: Dict[str, int] 983 #: The set of tests that must pass. The format of the tests is described984 #: in :mod:`model_test`.985 tests = None # type: List[TestCondition]986 1002 987 1003 def __init__(self):
Note: See TracChangeset
for help on using the changeset viewer.