Changeset 32e3c9b in sasmodels for sasmodels/modelinfo.py


Ignore:
Timestamp:
Jul 21, 2016 2:08:04 PM (8 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
b966a96
Parents:
42356c8
Message:

dll version of magnetic sld

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/modelinfo.py

    rce176ca r32e3c9b  
    414414        self.kernel_parameters = parameters 
    415415        self._set_vector_lengths() 
     416 
     417        self.npars = sum(p.length for p in self.kernel_parameters) 
     418        self.num_magnetic = sum(p.length for p in self.kernel_parameters 
     419                                if p.type=='sld') 
     420 
    416421        self.call_parameters = self._get_call_parameters() 
    417422        self.defaults = self._get_defaults() 
     
    441446        num_pd = sum(p.length for p in self.kernel_parameters if p.polydisperse) 
    442447        # Don't use more polydisperse parameters than are available in the model 
    443         # Note: we can do polydispersity on arbitrary parameters, so it is not 
    444         # clear that this is a good idea; it does however make the poly_details 
    445         # code easier to write, so we will leave it in for now. 
    446448        self.max_pd = min(num_pd, MAX_PD) 
    447  
    448         self.npars = sum(p.length for p in self.kernel_parameters) 
    449449 
    450450        # true if has 2D parameters 
    451451        self.has_2d = any(p.type in ('orientation', 'magnetic') 
    452452                          for p in self.kernel_parameters) 
     453        self.magnetism_index = [k for k,p in enumerate(self.call_parameters) 
     454                                if p.id.startswith('M0:')] 
    453455 
    454456        self.pd_1d = set(p.name for p in self.call_parameters 
    455457                         if p.polydisperse and p.type not in ('orientation', 'magnetic')) 
    456         self.pd_2d = set(p.name for p in self.call_parameters 
    457                          if p.polydisperse and p.type != 'magnetic') 
     458        self.pd_2d = set(p.name for p in self.call_parameters if p.polydisperse) 
    458459 
    459460    def _set_vector_lengths(self): 
     
    519520                    pk.relative_pd = p.relative_pd 
    520521                    full_list.append(pk) 
     522 
     523        # Add the magnetic parameters to the end of the call parameter list. 
     524        if self.num_magnetic > 0: 
     525            full_list.extend([ 
     526                Parameter('up:frac_i', '', 0., [0., 1.], 
     527                          'magnetic', 'fraction of spin up incident'), 
     528                Parameter('up:frac_f', '', 0., [0., 1.], 
     529                          'magnetic', 'fraction of spin up final'), 
     530                Parameter('up:angle', 'degress', 0., [0., 360.], 
     531                          'magnetic', 'spin up angle'), 
     532            ]) 
     533            slds = [p for p in full_list if p.type == 'sld'] 
     534            for p in slds: 
     535                full_list.extend([ 
     536                    Parameter('M0:'+p.id, '1e-6/Ang^2', 0., [-np.inf, np.inf], 
     537                              'magnetic', 'magnetic amplitude for '+p.description), 
     538                    Parameter('mtheta:'+p.id, 'degrees', 0., [-90., 90.], 
     539                               'magnetic', 'magnetic latitude for '+p.description), 
     540                    Parameter('mphi:'+p.id, 'degrees', 0., [-180., 180.], 
     541                               'magnetic', 'magnetic longitude for '+p.description), 
     542                ]) 
     543        #print("call parameters", full_list) 
    521544        return full_list 
    522545 
     
    553576        parameter is always returned first since the GUI will want to set it 
    554577        early, and rerender the table when it is changed. 
     578 
     579        Parameters marked as sld will automatically have a set of associated 
     580        magnetic parameters (m0:p, mtheta:p, mphi:p), as well as polarization 
     581        information (up:theta, up:frac_i, up:frac_f). 
    555582        """ 
    556583        # control parameters go first 
     
    565592 
    566593        # Gather entries such as name[4] into groups of the same length 
    567         fixed = {}  # type: Dict[int, List[Parameter]] 
     594        fixed_length = {}  # type: Dict[int, List[Parameter]] 
    568595        for p in self.kernel_parameters: 
    569596            if p.length > 1 and p.length_control is None: 
    570                 fixed.setdefault(p.length, []).append(p) 
     597                fixed_length.setdefault(p.length, []).append(p) 
    571598 
    572599        # Using the call_parameters table, we already have expanded forms 
    573600        # for each of the vector parameters; put them in a lookup table 
    574601        expanded_pars = dict((p.name, p) for p in self.call_parameters) 
     602 
     603        def append_group(name): 
     604            """add the named parameter, and related magnetic parameters if any""" 
     605            result.append(expanded_pars[name]) 
     606            if is2d: 
     607                for tag in 'M0:', 'mtheta:', 'mphi:': 
     608                    if tag+name in expanded_pars: 
     609                        result.append(expanded_pars[tag+name]) 
    575610 
    576611        # Gather the user parameters in order 
     
    589624                    for k in range(1, table_length+1): 
    590625                        for entry in table: 
    591                             result.append(expanded_pars[entry.id+str(k)]) 
     626                            append_group(entry.id+str(k)) 
    592627                else: 
    593628                    pass # already processed all entries 
    594629            elif p.length > 1: 
    595                 table = fixed.get(p.length, []) 
     630                table = fixed_length.get(p.length, []) 
    596631                if table: 
    597632                    table_length = p.length 
    598                     del fixed[p.length] 
     633                    del fixed_length[p.length] 
    599634                    for k in range(1, table_length+1): 
    600635                        for entry in table: 
    601                             result.append(expanded_pars[entry.id+str(k)]) 
     636                            append_group(entry.id+str(k)) 
    602637                else: 
    603638                    pass # already processed all entries 
    604639            else: 
    605                 result.append(p) 
     640                append_group(p.id) 
     641 
     642        if is2d and 'up:angle' in expanded_pars: 
     643            result.extend([ 
     644                expanded_pars['up:frac_i'], 
     645                expanded_pars['up:frac_f'], 
     646                expanded_pars['up:angle'], 
     647            ]) 
    606648 
    607649        return result 
     
    634676    if (model_info.Iq is None 
    635677        and model_info.Iqxy is None 
     678        and model_info.Imagnetic is None 
    636679        and model_info.form_volume is None): 
    637680        return 
     
    643686        return 
    644687    for k, v in enumerate(source.split('\n')): 
    645         if v.startswith('Iqxy'): 
     688        if v.startswith('Imagnetic'): 
     689            model_info._Imagnetic_line = k+1 
     690        elif v.startswith('Iqxy'): 
    646691            model_info._Iqxy_line = k+1 
    647692        elif v.startswith('Iq'): 
     
    692737    info.Iq = getattr(kernel_module, 'Iq', None) # type: ignore 
    693738    info.Iqxy = getattr(kernel_module, 'Iqxy', None) # type: ignore 
     739    info.Imagnetic = getattr(kernel_module, 'Imagnetic', None) # type: ignore 
    694740    info.profile = getattr(kernel_module, 'profile', None) # type: ignore 
    695741    info.sesans = getattr(kernel_module, 'sesans', None) # type: ignore 
     
    843889    #: Returns *I(qx, qy, a, b, ...)*.  The interface follows :attr:`Iq`. 
    844890    Iqxy = None             # type: Union[None, str, Callable[[np.ndarray], np.ndarray]] 
     891    #: Returns *I(qx, qy, a, b, ...)*.  The interface follows :attr:`Iq`. 
     892    Imagnetic = None        # type: Union[None, str, Callable[[np.ndarray], np.ndarray]] 
    845893    #: Returns a model profile curve *x, y*.  If *profile* is defined, this 
    846894    #: curve will appear in response to the *Show* button in SasView.  Use 
     
    857905    # line numbers within the python file for bits of C source, if defined 
    858906    # NB: some compilers fail with a "#line 0" directive, so default to 1. 
     907    _Imagnetic_line = 1 
    859908    _Iqxy_line = 1 
    860909    _Iq_line = 1 
Note: See TracChangeset for help on using the changeset viewer.