Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/perspectives/calculator/model_editor.py

    rc6dfb9f r9bf40e7  
    4343if sys.platform.count("win32") > 0: 
    4444    FONT_VARIANT = 0 
    45     PNL_WIDTH = 450 
     45    PNL_WIDTH = 500 
    4646    PNL_HEIGHT = 320 
    4747else: 
    4848    FONT_VARIANT = 1 
    49     PNL_WIDTH = 590 
     49    PNL_WIDTH = 500 
    5050    PNL_HEIGHT = 350 
    5151M_NAME = 'Model' 
     
    495495        Choose the equation to use depending on whether we now have 
    496496        a sum or multiply model then create the appropriate string 
     497         
     498        for the sum model the result will be: 
     499        scale_factor * (scale1 * model_1 + scale2 * model_2) + background 
     500        while for the multiply model it will just be: 
     501        scale_factor * (model_1* model_2) + background 
    497502        """ 
    498503        name = '' 
    499504        if operator == '*': 
    500505            name = 'Multi' 
    501             factor = 'background' 
     506            factor_1 = '' 
     507            factor_2 = '' 
    502508        else: 
    503509            name = 'Sum' 
    504             factor = 'scale_factor' 
     510            factor_1 = 'scale_1 * ' 
     511            factor_2 = 'scale_2 * ' 
    505512 
    506513        self._operator = operator 
    507         self.explanation = ("  Plugin_model = scale_factor * (model_1 {} " 
    508             "model_2) + background").format(operator) 
     514        self.explanation = ("  Plugin_model = scale_factor * ({}model_1 {} " 
     515            "{}model_2) + background").format(factor_1,operator,factor_2) 
    509516        self.explanationctr.SetLabel(self.explanation) 
    510517        self.name = name + M_NAME 
     
    663670        Do the layout for parameter related widgets 
    664671        """ 
    665         param_txt = wx.StaticText(self, -1, 'Fit Parameters NOT requiring' + \ 
    666                                   ' polydispersity (if any): ') 
    667  
    668         param_tip = "#Set the parameters NOT requiring polydispersity " + \ 
    669         "and their initial values.\n" 
     672        param_txt = wx.StaticText(self, -1, 'Fit Parameters: ') 
     673 
     674        param_tip = "#Set the parameters and their initial values.\n" 
    670675        param_tip += "#Example:\n" 
    671676        param_tip += "A = 1\nB = 1" 
     
    681686                                  (self.param_tcl, 1, wx.EXPAND | wx.ALL, 10)]) 
    682687 
    683         # Parameters with polydispersity 
    684         pd_param_txt = wx.StaticText(self, -1, 'Fit Parameters requiring ' + \ 
    685                                      'polydispersity (if any): ') 
    686  
    687         pd_param_tip = "#Set the parameters requiring polydispersity and " + \ 
    688         "their initial values.\n" 
    689         pd_param_tip += "#Example:\n" 
    690         pd_param_tip += "C = 2\nD = 2" 
    691         newid = wx.NewId() 
    692         self.pd_param_tcl = EditWindow(self, newid, wx.DefaultPosition, 
    693                                     wx.DefaultSize, 
    694                                     wx.CLIP_CHILDREN | wx.SUNKEN_BORDER) 
    695         self.pd_param_tcl.setDisplayLineNumbers(True) 
    696         self.pd_param_tcl.SetToolTipString(pd_param_tip) 
    697  
    698         self.param_sizer.AddMany([(pd_param_txt, 0, wx.LEFT, 10), 
    699                                   (self.pd_param_tcl, 1, wx.EXPAND | wx.ALL, 10)]) 
    700688 
    701689    def _layout_function(self): 
     
    899887            description = self.desc_tcl.GetValue() 
    900888            param_str = self.param_tcl.GetText() 
    901             pd_param_str = self.pd_param_tcl.GetText() 
    902889            func_str = self.function_tcl.GetText() 
    903890            # No input for the model function 
     
    905892                if func_str.count('return') > 0: 
    906893                    self.write_file(self.fname, name, description, param_str, 
    907                                     pd_param_str, func_str) 
     894                                    func_str) 
    908895                    try: 
    909896                        result, msg = check_model(self.fname), None 
     
    945932        self.warning = msg 
    946933 
    947     def write_file(self, fname, name, desc_str, param_str, pd_param_str, func_str): 
     934    def write_file(self, fname, name, desc_str, param_str, func_str): 
    948935        """ 
    949936        Write content in file 
     
    952939        :param desc_str: content of the description strings 
    953940        :param param_str: content of params; Strings 
    954         :param pd_param_str: content of params requiring polydispersity; Strings 
    955941        :param func_str: content of func; Strings 
    956942        """ 
     
    966952        # Write out parameters 
    967953        param_names = []    # to store parameter names 
    968         pd_params = [] 
    969954        out_f.write('parameters = [ \n') 
    970955        out_f.write('#   ["name", "units", default, [lower, upper], "type", "description"],\n') 
     
    973958            out_f.write("    ['%s', '', %s, [-inf, inf], '', '%s'],\n" 
    974959                        % (pname, pvalue, desc)) 
    975         for pname, pvalue, desc in self.get_param_helper(pd_param_str): 
    976             param_names.append(pname) 
    977             pd_params.append(pname) 
    978             out_f.write("    ['%s', '', %s, [-inf, inf], 'volume', '%s'],\n" 
    979                         % (pname, pvalue, desc)) 
    980960        out_f.write('    ]\n') 
    981961 
    982962        # Write out function definition 
     963        out_f.write('\n') 
    983964        out_f.write('def Iq(%s):\n' % ', '.join(['x'] + param_names)) 
    984965        out_f.write('    """Absolute scattering"""\n') 
     
    990971            out_f.write('    import numpy as np') 
    991972        for func_line in func_str.split('\n'): 
    992             out_f.write('%s%s\n' % (spaces4, func_line)) 
     973            out_f.write('%s%s\n' % ('    ', func_line)) 
    993974        out_f.write('## uncomment the following if Iq works for vector x\n') 
    994975        out_f.write('#Iq.vectorized = True\n') 
    995  
    996         # If polydisperse, create place holders for form_volume, ER and VR 
    997         if pd_params: 
    998             out_f.write('\n') 
    999             out_f.write(CUSTOM_TEMPLATE_PD % {'args': ', '.join(pd_params)}) 
    1000976 
    1001977        # Create place holder for Iqxy 
     
    11281104description = """%(description)s""" 
    11291105 
    1130 ''' 
    1131  
    1132 CUSTOM_TEMPLATE_PD = '''\ 
    1133 def form_volume(%(args)s): 
    1134     """ 
    1135     Volume of the particles used to compute absolute scattering intensity 
    1136     and to weight polydisperse parameter contributions. 
    1137     """ 
    1138     return 0.0 
    1139  
    1140 def ER(%(args)s): 
    1141     """ 
    1142     Effective radius of particles to be used when computing structure factors. 
    1143  
    1144     Input parameters are vectors ranging over the mesh of polydispersity values. 
    1145     """ 
    1146     return 0.0 
    1147  
    1148 def VR(%(args)s): 
    1149     """ 
    1150     Volume ratio of particles to be used when computing structure factors. 
    1151  
    1152     Input parameters are vectors ranging over the mesh of polydispersity values. 
    1153     """ 
    1154     return 1.0 
    11551106''' 
    11561107 
Note: See TracChangeset for help on using the changeset viewer.