Changeset b2f0e5d in sasmodels for sasmodels/modelinfo.py


Ignore:
Timestamp:
Mar 29, 2019 8:14:32 AM (5 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
ticket-1257-vesicle-product
Children:
98c045a
Parents:
830cf6b
Message:

Fix handling of volfraction in vesicle@hardsphere. Refs 1257.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/modelinfo.py

    ra34b811 rb2f0e5d  
    7070        processed.append(parse_parameter(*p)) 
    7171    partable = ParameterTable(processed) 
    72     partable.check_angles() 
     72    partable.check_angles(strict=True) 
    7373    return partable 
    7474 
     
    446446        # properties, such as default=0.0 for structure factor backgrounds. 
    447447        self.common_parameters = [Parameter(*p) for p in COMMON_PARAMETERS] 
    448  
    449448        self.kernel_parameters = parameters 
    450449        self._set_vector_lengths() 
     
    459458        #self._name_table= dict((p.id, p) for p in parameters) 
    460459 
     460 
    461461        # Set the kernel parameters.  Assumes background and scale are the 
    462462        # first two parameters in the parameter list, but these are not sent 
     
    495495        self.pd_2d = set(p.name for p in self.call_parameters if p.polydisperse) 
    496496 
     497        # Final checks 
     498        self.check_duplicates() 
     499        self.check_angles() 
     500 
    497501    def set_zero_background(self): 
    498502        """ 
     
    506510        self.defaults = self._get_defaults() 
    507511 
    508     def check_angles(self): 
     512    def check_angles(self, strict=False): 
    509513        """ 
    510514        Check that orientation angles are theta, phi and possibly psi. 
     515 
     516        *strict* should be True when checking a parameter table defined 
     517        in a model file, but False when checking from mixture models, etc., 
     518        where the parameters aren't being passed to a calculator directly. 
    511519        """ 
    512520        theta = phi = psi = -1 
     
    524532                if p.type != 'orientation': 
    525533                    raise TypeError("psi must be an orientation parameter") 
    526             elif p.type == 'orientation': 
     534            elif p.type == 'orientation' and strict: 
    527535                raise TypeError("only theta, phi and psi can be orientation parameters") 
    528536        if theta >= 0 and phi >= 0: 
     
    532540            if psi >= 0 and psi != phi+1: 
    533541                raise TypeError("psi must follow phi") 
     542            # TODO: Why must theta/phi/psi be at the end?  Consistency only? 
    534543            if (psi >= 0 and psi != last_par) or (psi < 0 and phi != last_par): 
    535                 raise TypeError("orientation parameters must appear at the " 
    536                                 "end of the parameter table") 
     544                if strict: 
     545                    raise TypeError("orientation parameters must appear at the " 
     546                                    "end of the parameter table") 
    537547        elif theta >= 0 or phi >= 0 or psi >= 0: 
    538548            raise TypeError("oriented shapes must have both theta and phi and maybe psi") 
     549 
     550    def check_duplicates(self): 
     551        """ 
     552        Check for duplicate parameter names 
     553        """ 
     554        checked, dups = set(), set() 
     555        for p in self.call_parameters: 
     556            if p.id in checked: 
     557                dups.add(p.id) 
     558            else: 
     559                checked.add(p.id) 
     560        if dups: 
     561            raise TypeError("Duplicate parameters: {}" 
     562                            .format(", ".join(sorted(dups)))) 
    539563 
    540564    def __getitem__(self, key): 
Note: See TracChangeset for help on using the changeset viewer.