Changes in sasmodels/modelinfo.py [39a06c9:4f4d3e3] in sasmodels


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/modelinfo.py

    r39a06c9 r4f4d3e3  
    164164    parameter.length = length 
    165165    parameter.length_control = control 
     166 
    166167    return parameter 
    167168 
     
    264265    will have a magnitude and a direction, which may be different from 
    265266    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 (for 
    268     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. 
    269270 
    270271    *description* is a short description of the parameter.  This will 
     
    290291    example, might be used to set the value of a shape parameter. 
    291292 
    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 
    293313    :func:`parse_parameter` therein. 
    294314    """ 
     
    423443        self.kernel_parameters = parameters 
    424444        self._set_vector_lengths() 
     445 
    425446        self.npars = sum(p.length for p in self.kernel_parameters) 
    426447        self.nmagnetic = sum(p.length for p in self.kernel_parameters 
     
    429450        if self.nmagnetic: 
    430451            self.nvalues += 3 + 3*self.nmagnetic 
     452 
    431453        self.call_parameters = self._get_call_parameters() 
    432454        self.defaults = self._get_defaults() 
     
    719741 
    720742#: 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'] 
     743C_SYMBOLS = ['Imagnetic', 'Iq', 'Iqxy', 'Iqac', 'Iqabc', 'form_volume', 'c_code'] 
    722744 
    723745def _find_source_lines(model_info, kernel_module): 
     
    768790        # Custom sum/multi models 
    769791        return kernel_module.model_info 
    770  
    771792    info = ModelInfo() 
    772793    #print("make parameter table", kernel_module.parameters) 
     
    790811    info.category = getattr(kernel_module, 'category', None) 
    791812    info.structure_factor = getattr(kernel_module, 'structure_factor', False) 
    792     # TODO: find Fq by inspection 
    793     info.effective_radius_type = getattr(kernel_module, 'effective_radius_type', None) 
    794     info.have_Fq = getattr(kernel_module, 'have_Fq', False) 
    795813    info.profile_axes = getattr(kernel_module, 'profile_axes', ['x', 'y']) 
    796814    # Note: custom.load_custom_kernel_module assumes the C sources are defined 
     
    798816    info.source = getattr(kernel_module, 'source', []) 
    799817    info.c_code = getattr(kernel_module, 'c_code', None) 
    800     info.effective_radius = getattr(kernel_module, 'effective_radius', None) 
    801818    # TODO: check the structure of the tests 
    802819    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 
    803822    info.form_volume = getattr(kernel_module, 'form_volume', None) # type: ignore 
    804     info.shell_volume = getattr(kernel_module, 'shell_volume', None) # type: ignore 
    805823    info.Iq = getattr(kernel_module, 'Iq', None) # type: ignore 
    806824    info.Iqxy = getattr(kernel_module, 'Iqxy', None) # type: ignore 
     
    814832    info.single = getattr(kernel_module, 'single', not callable(info.Iq)) 
    815833    info.random = getattr(kernel_module, 'random', None) 
    816  
    817     # multiplicity info 
    818     control_pars = [p.id for p in parameters.kernel_parameters if p.is_control] 
    819     default_control = control_pars[0] if control_pars else None 
    820     info.control = getattr(kernel_module, 'control', default_control) 
    821834    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 
    822840 
    823841    if callable(info.Iq) and parameters.has_2d: 
     
    826844    info.lineno = {} 
    827845    _find_source_lines(info, kernel_module) 
     846 
    828847    return info 
    829848 
     
    872891    #: *sphere*hardsphere* or *cylinder+sphere*. 
    873892    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, with 
    876     #: limits defined as *[CASES]*, for case names such as 
    877     #: *CASES = ["diblock copolymer", "triblock copolymer", ...]*. 
    878     #: This should give *limits=[[case1, case2, ...]]*, but the 
    879     #: model loader translates this to *limits=[0, len(CASES)-1]*, and adds 
    880     #: *choices=CASES* to the :class:`Parameter` definition. Note that 
    881     #: models can use a list of cases as a parameter without it being a 
    882     #: control parameter.  Either way, the parameter is sent to the model 
    883     #: evaluator as *float(choice_num)*, where choices are numbered from 0. 
    884     #: See also :attr:`hidden`. 
    885     control = None          # type: str 
    886893    #: Different variants require different parameters.  In order to show 
    887894    #: just the parameters needed for the variant selected by :attr:`control`, 
     
    918925    #: provided in the file. 
    919926    structure_factor = None # type: bool 
    920     #: True if the model defines an Fq function with signature 
    921     #: void Fq(double q, double *F1, double *F2, ...) 
    922     have_Fq = False 
    923     #: 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] 
    926927    #: List of C source files used to define the model.  The source files 
    927928    #: should define the *Iq* function, and possibly *Iqac* or *Iqabc* if the 
    928929    #: model defines orientation parameters. Files containing the most basic 
    929930    #: 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. 
    931933    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 
    934961    #: Returns the form volume for python-based models.  Form volume is needed 
    935962    #: for volume normalization in the polydispersity integral.  If no 
     
    939966    #: C code, either defined as a string, or in the sources. 
    940967    form_volume = None      # type: Union[None, str, Callable[[np.ndarray], float]] 
    941     #: Returns the shell volume for python-based models.  Form volume and 
    942     #: shell volume are needed for volume normalization in the polydispersity 
    943     #: integral and structure interactions for hollow shapes.  If no 
    944     #: 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 be 
    947     #: C code, either defined as a string, or in the sources. 
    948     shell_volume = None      # type: Union[None, str, Callable[[np.ndarray], float]] 
    949968    #: Returns *I(q, a, b, ...)* for parameters *a*, *b*, etc. defined 
    950969    #: by the parameter table.  *Iq* can be defined as a python function, or 
     
    9811000    #: Line numbers for symbols defining C code 
    9821001    lineno = None           # type: Dict[str, int] 
    983     #: The set of tests that must pass.  The format of the tests is described 
    984     #: in :mod:`model_test`. 
    985     tests = None            # type: List[TestCondition] 
    9861002 
    9871003    def __init__(self): 
Note: See TracChangeset for help on using the changeset viewer.