Changeset fb9a3b6 in sasmodels for sasmodels/core.py


Ignore:
Timestamp:
Aug 31, 2017 12:07:59 PM (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:
bcdd6c9
Parents:
573ffab
Message:

Allow mixture models to do multiplication as well as addition

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/core.py

    r2e66ef5 rfb9a3b6  
    126126 
    127127 
    128 def load_model_info(model_name): 
     128def load_model_info(model_name, force_mixture=False): 
    129129    # type: (str) -> modelinfo.ModelInfo 
    130130    """ 
     
    134134    such as sphere*hardsphere or sphere+cylinder. 
    135135 
     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 
    136140    This returns a handle to the module defining the model.  This can be 
    137141    used with functions in generate to build the docs or extract model info. 
     
    139143    parts = model_name.split('+') 
    140144    if len(parts) > 1: 
     145        # Always use MixtureModel for addition 
    141146        model_info_list = [load_model_info(p) for p in parts] 
    142147        return mixture.make_mixture_info(model_info_list) 
     
    144149    parts = model_name.split('*') 
    145150    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='*') 
    146155        if len(parts) > 2: 
    147156            raise ValueError("use P*S to apply structure factor S to model P") 
     157        # Use ProductModel 
    148158        P_info, Q_info = [load_model_info(p) for p in parts] 
    149159        return product.make_product_info(P_info, Q_info) 
Note: See TracChangeset for help on using the changeset viewer.