Changeset 481ff64 in sasmodels


Ignore:
Timestamp:
Sep 5, 2017 4:38:34 AM (7 years ago)
Author:
lewis
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
6a5ccfb
Parents:
61a4bd4
git-author:
Lewis O'Driscoll <lewis.o'driscoll@…> (09/05/17 04:38:13)
git-committer:
Lewis O'Driscoll <lewis.o'driscoll@…> (09/05/17 04:38:34)
Message:

Use '@' for structure factor product

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/core.py

    r61a4bd4 r481ff64  
    125125                       dtype=dtype, platform=platform) 
    126126 
    127  
    128 # def load_model_info(model_name, force_mixture=False): 
    129 #     # type: (str) -> modelinfo.ModelInfo 
    130 #     """ 
    131 #     Load a model definition given the model name. 
    132  
    133 #     *model_name* is the name of the model, or perhaps a model expression 
    134 #     such as sphere*hardsphere or sphere+cylinder. 
    135  
    136 #     *force_mixture* if true, MixtureModel will be used for combining models. 
    137 #     Otherwise either MixtureModel will be used for addition and ProductModel 
    138 #     will be used for multiplication 
    139  
    140 #     This returns a handle to the module defining the model.  This can be 
    141 #     used with functions in generate to build the docs or extract model info. 
    142 #     """ 
    143 #     parts = model_name.split('+') 
    144 #     if len(parts) > 1: 
    145 #         # Always use MixtureModel for addition 
    146 #         model_info_list = [load_model_info(p) for p in parts] 
    147 #         return mixture.make_mixture_info(model_info_list) 
    148  
    149 #     parts = model_name.split('*') 
    150 #     if len(parts) > 1: 
    151 #         if force_mixture: 
    152 #             # Use MixtureModel for multiplication if forced 
    153 #             model_info_list = [load_model_info(p) for p in parts] 
    154 #             return mixture.make_mixture_info(model_info_list, operation='*') 
    155 #         if len(parts) > 2: 
    156 #             raise ValueError("use P*S to apply structure factor S to model P") 
    157 #         # Use ProductModel 
    158 #         P_info, Q_info = [load_model_info(p) for p in parts] 
    159 #         return product.make_product_info(P_info, Q_info) 
    160  
    161 #     kernel_module = generate.load_kernel_module(model_name) 
    162 #     return modelinfo.make_model_info(kernel_module) 
    163  
    164127def load_model_info(model_string): 
    165128    # type: (str) -> modelinfo.ModelInfo 
     
    167130    Load a model definition given the model name. 
    168131 
    169     *model_name* is the name of the model, or perhaps a model expression 
    170     such as sphere*hardsphere or sphere+cylinder. 
     132    *model_string* is the name of the model, or perhaps a model expression 
     133    such as sphere*cylinder or sphere+cylinder. Use '@' for a structure 
     134    factor product, eg sphere@hardsphere. 
    171135 
    172136    This returns a handle to the module defining the model.  This can be 
    173137    used with functions in generate to build the docs or extract model info. 
    174138    """ 
    175     # TODO: parse an expression like form@structure to create a P(Q)*S(Q) model 
     139    if '@' in model_string: 
     140        parts = model_string.split('@') 
     141        if len(parts) != 2: 
     142            raise ValueError("Use P@S to apply a structure factor S to model P") 
     143        P_info, Q_info = [load_model_info(part) for part in parts] 
     144        return product.make_product_info(P_info, Q_info) 
     145 
    176146    product_parts = [] 
    177147    addition_parts = [] 
Note: See TracChangeset for help on using the changeset viewer.