[61184df] | 1 | """ |
---|
| 2 | Utilities to manage models |
---|
| 3 | """ |
---|
[d89f09b] | 4 | import wx |
---|
[b30f001] | 5 | import imp |
---|
[9466f2d6] | 6 | import os |
---|
| 7 | import sys |
---|
| 8 | import math |
---|
[d89f09b] | 9 | import os.path |
---|
[33afff7] | 10 | # Time is needed by the log method |
---|
| 11 | import time |
---|
[23ccf07] | 12 | import logging |
---|
[5d1c1f4] | 13 | import py_compile |
---|
[96814e1] | 14 | import shutil |
---|
[f32d144] | 15 | from sans.guiframe.events import StatusEvent |
---|
[33afff7] | 16 | # Explicitly import from the pluginmodel module so that py2exe |
---|
| 17 | # places it in the distribution. The Model1DPlugin class is used |
---|
| 18 | # as the base class of plug-in models. |
---|
| 19 | from sans.models.pluginmodel import Model1DPlugin |
---|
[df7a7e3] | 20 | from sans.models.BaseComponent import BaseComponent |
---|
[657e52c] | 21 | from sans.guiframe.CategoryInstaller import CategoryInstaller |
---|
[9466f2d6] | 22 | |
---|
[f32d144] | 23 | PLUGIN_DIR = 'plugin_models' |
---|
| 24 | |
---|
[df7a7e3] | 25 | def get_model_python_path(): |
---|
| 26 | return os.path.dirname(__file__) |
---|
| 27 | |
---|
[9466f2d6] | 28 | |
---|
[b30f001] | 29 | def log(message): |
---|
[5062bbf] | 30 | """ |
---|
[61184df] | 31 | Log a message in a file located in the user's home directory |
---|
[5062bbf] | 32 | """ |
---|
[94d6752] | 33 | dir = os.path.join(os.path.expanduser("~"), '.sasview', PLUGIN_DIR) |
---|
[b30ed8f] | 34 | out = open(os.path.join(dir, "plugins.log"), 'a') |
---|
[b30f001] | 35 | out.write("%10g: %s\n" % (time.clock(), message)) |
---|
| 36 | out.close() |
---|
| 37 | |
---|
[9466f2d6] | 38 | |
---|
[bfe4644] | 39 | def _check_plugin(model, name): |
---|
| 40 | """ |
---|
[5062bbf] | 41 | Do some checking before model adding plugins in the list |
---|
| 42 | |
---|
| 43 | :param model: class model to add into the plugin list |
---|
| 44 | :param name:name of the module plugin |
---|
| 45 | |
---|
| 46 | :return model: model if valid model or None if not valid |
---|
| 47 | |
---|
[bfe4644] | 48 | """ |
---|
| 49 | #Check is the plugin is of type Model1DPlugin |
---|
| 50 | if not issubclass(model, Model1DPlugin): |
---|
[61184df] | 51 | msg = "Plugin %s must be of type Model1DPlugin \n" % str(name) |
---|
[bfe4644] | 52 | log(msg) |
---|
[8d78399] | 53 | return None |
---|
[f32d144] | 54 | if model.__name__ != "Model": |
---|
| 55 | msg = "Plugin %s class name must be Model \n" % str(name) |
---|
[bfe4644] | 56 | log(msg) |
---|
[8d78399] | 57 | return None |
---|
[bfe4644] | 58 | try: |
---|
[f32d144] | 59 | new_instance = model() |
---|
[bfe4644] | 60 | except: |
---|
[f32d144] | 61 | msg = "Plugin %s error in __init__ \n\t: %s %s\n" % (str(name), |
---|
[61184df] | 62 | str(sys.exc_type), sys.exc_value) |
---|
[bfe4644] | 63 | log(msg) |
---|
[8d78399] | 64 | return None |
---|
[bfe4644] | 65 | |
---|
[f32d144] | 66 | if hasattr(new_instance, "function"): |
---|
[bfe4644] | 67 | try: |
---|
[f32d144] | 68 | value = new_instance.function() |
---|
[bfe4644] | 69 | except: |
---|
[f32d144] | 70 | msg = "Plugin %s: error writing function \n\t :%s %s\n " % (str(name), |
---|
[61184df] | 71 | str(sys.exc_type), sys.exc_value) |
---|
[f32d144] | 72 | log(msg) |
---|
| 73 | return None |
---|
[bfe4644] | 74 | else: |
---|
[f32d144] | 75 | msg = "Plugin %s needs a method called function \n" % str(name) |
---|
| 76 | log(msg) |
---|
| 77 | return None |
---|
[bfe4644] | 78 | return model |
---|
| 79 | |
---|
[f32d144] | 80 | |
---|
[5d1c1f4] | 81 | def find_plugins_dir(): |
---|
[5062bbf] | 82 | """ |
---|
[96814e1] | 83 | Find path of the plugins directory. |
---|
| 84 | The plugin directory is located in the user's home directory. |
---|
[5062bbf] | 85 | """ |
---|
[94d6752] | 86 | dir = os.path.join(os.path.expanduser("~"), '.sasview', PLUGIN_DIR) |
---|
[96814e1] | 87 | |
---|
| 88 | # If the plugin directory doesn't exist, create it |
---|
[a0986f6] | 89 | if not os.path.isdir(dir): |
---|
[96814e1] | 90 | os.makedirs(dir) |
---|
| 91 | |
---|
[8ab3302] | 92 | # Find paths needed |
---|
| 93 | try: |
---|
| 94 | # For source |
---|
| 95 | if os.path.isdir(os.path.dirname(__file__)): |
---|
[f32d144] | 96 | p_dir = os.path.join(os.path.dirname(__file__), PLUGIN_DIR) |
---|
[8ab3302] | 97 | else: |
---|
| 98 | raise |
---|
| 99 | except: |
---|
| 100 | # Check for data path next to exe/zip file. |
---|
| 101 | #Look for maximum n_dir up of the current dir to find plugins dir |
---|
| 102 | n_dir = 12 |
---|
| 103 | p_dir = None |
---|
| 104 | f_dir = os.path.join(os.path.dirname(__file__)) |
---|
| 105 | for i in range(n_dir): |
---|
| 106 | if i > 1: |
---|
| 107 | f_dir, _ = os.path.split(f_dir) |
---|
| 108 | plugin_path = os.path.join(f_dir, PLUGIN_DIR) |
---|
| 109 | if os.path.isdir(plugin_path): |
---|
| 110 | p_dir = plugin_path |
---|
| 111 | break |
---|
| 112 | if not p_dir: |
---|
| 113 | raise |
---|
[96814e1] | 114 | # Place example user models as needed |
---|
[19e614a] | 115 | if os.path.isdir(p_dir): |
---|
| 116 | for file in os.listdir(p_dir): |
---|
| 117 | file_path = os.path.join(p_dir, file) |
---|
| 118 | if os.path.isfile(file_path): |
---|
| 119 | if file.split(".")[-1] == 'py' and\ |
---|
| 120 | file.split(".")[0] != '__init__': |
---|
| 121 | if not os.path.isfile(os.path.join(dir, file)): |
---|
| 122 | shutil.copy(file_path, dir) |
---|
| 123 | |
---|
[5d1c1f4] | 124 | return dir |
---|
| 125 | |
---|
[f32d144] | 126 | |
---|
[5d1c1f4] | 127 | class ReportProblem: |
---|
| 128 | def __nonzero__(self): |
---|
| 129 | type, value, traceback = sys.exc_info() |
---|
| 130 | if type is not None and issubclass(type, py_compile.PyCompileError): |
---|
| 131 | print "Problem with", repr(value) |
---|
| 132 | raise type, value, traceback |
---|
| 133 | return 1 |
---|
| 134 | |
---|
| 135 | report_problem = ReportProblem() |
---|
| 136 | |
---|
[f32d144] | 137 | |
---|
[5d1c1f4] | 138 | def compile_file(dir): |
---|
| 139 | """ |
---|
| 140 | Compile a py file |
---|
| 141 | """ |
---|
| 142 | try: |
---|
| 143 | import compileall |
---|
[f32d144] | 144 | compileall.compile_dir(dir=dir, ddir=dir, force=1, |
---|
| 145 | quiet=report_problem) |
---|
[5d1c1f4] | 146 | except: |
---|
| 147 | type, value, traceback = sys.exc_info() |
---|
| 148 | return value |
---|
| 149 | return None |
---|
| 150 | |
---|
[f32d144] | 151 | |
---|
[5d1c1f4] | 152 | def _findModels(dir): |
---|
| 153 | """ |
---|
| 154 | """ |
---|
| 155 | # List of plugin objects |
---|
| 156 | plugins = {} |
---|
| 157 | # Go through files in plug-in directory |
---|
| 158 | #always recompile the folder plugin |
---|
| 159 | dir = find_plugins_dir() |
---|
[a0986f6] | 160 | if not os.path.isdir(dir): |
---|
| 161 | msg = "SansView couldn't locate Model plugin folder." |
---|
| 162 | msg += """ "%s" does not exist""" % dir |
---|
| 163 | logging.warning(msg) |
---|
| 164 | return plugins |
---|
| 165 | else: |
---|
| 166 | log("looking for models in: %s" % str(dir)) |
---|
[5d1c1f4] | 167 | compile_file(dir) |
---|
[a0986f6] | 168 | logging.info("pluging model dir: %s\n" % str(dir)) |
---|
[1c66bc5] | 169 | try: |
---|
| 170 | list = os.listdir(dir) |
---|
| 171 | for item in list: |
---|
| 172 | toks = os.path.splitext(os.path.basename(item)) |
---|
[f32d144] | 173 | if toks[1] == '.py' and not toks[0] == '__init__': |
---|
[1c66bc5] | 174 | name = toks[0] |
---|
| 175 | |
---|
| 176 | path = [os.path.abspath(dir)] |
---|
| 177 | file = None |
---|
| 178 | try: |
---|
| 179 | (file, path, info) = imp.find_module(name, path) |
---|
[f32d144] | 180 | module = imp.load_module(name, file, item, info) |
---|
[1c66bc5] | 181 | if hasattr(module, "Model"): |
---|
| 182 | try: |
---|
[f32d144] | 183 | if _check_plugin(module.Model, name) != None: |
---|
[b2d9826] | 184 | plugins[name] = module.Model |
---|
[1c66bc5] | 185 | except: |
---|
[f32d144] | 186 | msg = "Error accessing Model" |
---|
| 187 | msg += "in %s\n %s %s\n" % (name, |
---|
[bfe4644] | 188 | str(sys.exc_type), sys.exc_value) |
---|
| 189 | log(msg) |
---|
[1c66bc5] | 190 | except: |
---|
[f32d144] | 191 | msg = "Error accessing Model" |
---|
| 192 | msg += " in %s\n %s %s \n" % (name, |
---|
[bfe4644] | 193 | str(sys.exc_type), sys.exc_value) |
---|
| 194 | log(msg) |
---|
[1c66bc5] | 195 | finally: |
---|
[a92d51b] | 196 | |
---|
[f32d144] | 197 | if not file == None: |
---|
[1c66bc5] | 198 | file.close() |
---|
| 199 | except: |
---|
[33afff7] | 200 | # Don't deal with bad plug-in imports. Just skip. |
---|
[23ccf07] | 201 | msg = "Could not import model plugin: %s\n" % sys.exc_value |
---|
| 202 | log(msg) |
---|
[1c66bc5] | 203 | pass |
---|
| 204 | return plugins |
---|
[bb18ef1] | 205 | |
---|
[f32d144] | 206 | |
---|
[bb18ef1] | 207 | class ModelList(object): |
---|
| 208 | """ |
---|
[5062bbf] | 209 | Contains dictionary of model and their type |
---|
[bb18ef1] | 210 | """ |
---|
| 211 | def __init__(self): |
---|
[5062bbf] | 212 | """ |
---|
| 213 | """ |
---|
| 214 | self.mydict = {} |
---|
[bb18ef1] | 215 | |
---|
| 216 | def set_list(self, name, mylist): |
---|
| 217 | """ |
---|
[5062bbf] | 218 | :param name: the type of the list |
---|
| 219 | :param mylist: the list to add |
---|
| 220 | |
---|
[bb18ef1] | 221 | """ |
---|
| 222 | if name not in self.mydict.keys(): |
---|
[916f5c0] | 223 | self.reset_list(name, mylist) |
---|
[bb18ef1] | 224 | |
---|
[916f5c0] | 225 | def reset_list(self, name, mylist): |
---|
| 226 | """ |
---|
| 227 | :param name: the type of the list |
---|
| 228 | :param mylist: the list to add |
---|
| 229 | """ |
---|
[f32d144] | 230 | self.mydict[name] = mylist |
---|
[bb18ef1] | 231 | |
---|
| 232 | def get_list(self): |
---|
| 233 | """ |
---|
[5062bbf] | 234 | return all the list stored in a dictionary object |
---|
[bb18ef1] | 235 | """ |
---|
| 236 | return self.mydict |
---|
| 237 | |
---|
[f32d144] | 238 | |
---|
[bb9f322] | 239 | class ModelManagerBase: |
---|
[5062bbf] | 240 | """ |
---|
[61184df] | 241 | Base class for the model manager |
---|
[5062bbf] | 242 | """ |
---|
[bb18ef1] | 243 | ## external dict for models |
---|
| 244 | model_combobox = ModelList() |
---|
| 245 | ## Dictionary of form models |
---|
| 246 | form_factor_dict = {} |
---|
| 247 | ## dictionary of other |
---|
| 248 | struct_factor_dict = {} |
---|
| 249 | ##list of form factors |
---|
[b2d9826] | 250 | shape_list = [] |
---|
[bb18ef1] | 251 | ## independent shape model list |
---|
| 252 | shape_indep_list = [] |
---|
[f32d144] | 253 | ##list of structure factors |
---|
[b2d9826] | 254 | struct_list = [] |
---|
[376916c] | 255 | ##list of model allowing multiplication |
---|
[b2d9826] | 256 | multiplication_factor = [] |
---|
[e87f9fc] | 257 | ##list of multifunctional shapes |
---|
[b2d9826] | 258 | multi_func_list = [] |
---|
[bb18ef1] | 259 | ## list of added models |
---|
[b2d9826] | 260 | plugins = [] |
---|
[bb18ef1] | 261 | ## Event owner (guiframe) |
---|
[d89f09b] | 262 | event_owner = None |
---|
[9466f2d6] | 263 | last_time_dir_modified = 0 |
---|
[f32d144] | 264 | |
---|
[6bbeacd4] | 265 | def __init__(self): |
---|
| 266 | """ |
---|
| 267 | """ |
---|
[df7a7e3] | 268 | self.model_dictionary = {} |
---|
[b2d9826] | 269 | self.stored_plugins = {} |
---|
[6bbeacd4] | 270 | self._getModelList() |
---|
| 271 | |
---|
[9466f2d6] | 272 | def findModels(self): |
---|
| 273 | """ |
---|
| 274 | find plugin model in directory of plugin .recompile all file |
---|
| 275 | in the directory if file were modified |
---|
| 276 | """ |
---|
[23ccf07] | 277 | temp = {} |
---|
[9466f2d6] | 278 | if self.is_changed(): |
---|
[a0986f6] | 279 | return _findModels(dir) |
---|
[23ccf07] | 280 | logging.info("pluging model : %s\n" % str(temp)) |
---|
| 281 | return temp |
---|
| 282 | |
---|
[d89f09b] | 283 | def _getModelList(self): |
---|
| 284 | """ |
---|
[5062bbf] | 285 | List of models we want to make available by default |
---|
| 286 | for this application |
---|
| 287 | |
---|
| 288 | :return: the next free event ID following the new menu events |
---|
[e7b1ccf] | 289 | |
---|
[d89f09b] | 290 | """ |
---|
[df7a7e3] | 291 | |
---|
| 292 | |
---|
[7c8d3093] | 293 | # regular model names only |
---|
| 294 | self.model_name_list = [] |
---|
[442895f] | 295 | from sans.models.SphereModel import SphereModel |
---|
[df7a7e3] | 296 | self.model_dictionary[SphereModel.__name__] = SphereModel |
---|
[bb18ef1] | 297 | self.shape_list.append(SphereModel) |
---|
[376916c] | 298 | self.multiplication_factor.append(SphereModel) |
---|
[7c8d3093] | 299 | self.model_name_list.append(SphereModel.__name__) |
---|
[442895f] | 300 | |
---|
[1a395a6] | 301 | from sans.models.BinaryHSModel import BinaryHSModel |
---|
[df7a7e3] | 302 | self.model_dictionary[BinaryHSModel.__name__] = BinaryHSModel |
---|
[1a395a6] | 303 | self.shape_list.append(BinaryHSModel) |
---|
[7c8d3093] | 304 | self.model_name_list.append(BinaryHSModel.__name__) |
---|
[1a395a6] | 305 | |
---|
[ce07fa8] | 306 | from sans.models.FuzzySphereModel import FuzzySphereModel |
---|
[df7a7e3] | 307 | self.model_dictionary[FuzzySphereModel.__name__] = FuzzySphereModel |
---|
[ce07fa8] | 308 | self.shape_list.append(FuzzySphereModel) |
---|
| 309 | self.multiplication_factor.append(FuzzySphereModel) |
---|
[7c8d3093] | 310 | self.model_name_list.append(FuzzySphereModel.__name__) |
---|
[3764dbd7] | 311 | |
---|
| 312 | from sans.models.RaspBerryModel import RaspBerryModel |
---|
[df7a7e3] | 313 | self.model_dictionary[RaspBerryModel.__name__] = RaspBerryModel |
---|
[3764dbd7] | 314 | self.shape_list.append(RaspBerryModel) |
---|
| 315 | self.model_name_list.append(RaspBerryModel.__name__) |
---|
| 316 | |
---|
[442895f] | 317 | from sans.models.CoreShellModel import CoreShellModel |
---|
[df7a7e3] | 318 | self.model_dictionary[CoreShellModel.__name__] = CoreShellModel |
---|
[bb18ef1] | 319 | self.shape_list.append(CoreShellModel) |
---|
[5eb9154] | 320 | self.multiplication_factor.append(CoreShellModel) |
---|
[7c8d3093] | 321 | self.model_name_list.append(CoreShellModel.__name__) |
---|
[4523b68] | 322 | |
---|
[7289627] | 323 | from sans.models.Core2ndMomentModel import Core2ndMomentModel |
---|
[df7a7e3] | 324 | self.model_dictionary[Core2ndMomentModel.__name__] = Core2ndMomentModel |
---|
[7289627] | 325 | self.shape_list.append(Core2ndMomentModel) |
---|
| 326 | self.model_name_list.append(Core2ndMomentModel.__name__) |
---|
| 327 | |
---|
[4523b68] | 328 | from sans.models.CoreMultiShellModel import CoreMultiShellModel |
---|
[df7a7e3] | 329 | self.model_dictionary[CoreMultiShellModel.__name__] = CoreMultiShellModel |
---|
[4523b68] | 330 | self.shape_list.append(CoreMultiShellModel) |
---|
| 331 | self.multiplication_factor.append(CoreMultiShellModel) |
---|
[a1b2471] | 332 | self.multi_func_list.append(CoreMultiShellModel) |
---|
[fb59ed9] | 333 | |
---|
[eddff027] | 334 | from sans.models.VesicleModel import VesicleModel |
---|
[df7a7e3] | 335 | self.model_dictionary[VesicleModel.__name__] = VesicleModel |
---|
[eddff027] | 336 | self.shape_list.append(VesicleModel) |
---|
[5eb9154] | 337 | self.multiplication_factor.append(VesicleModel) |
---|
[7c8d3093] | 338 | self.model_name_list.append(VesicleModel.__name__) |
---|
[5eb9154] | 339 | |
---|
| 340 | from sans.models.MultiShellModel import MultiShellModel |
---|
[df7a7e3] | 341 | self.model_dictionary[MultiShellModel.__name__] = MultiShellModel |
---|
[5eb9154] | 342 | self.shape_list.append(MultiShellModel) |
---|
| 343 | self.multiplication_factor.append(MultiShellModel) |
---|
[7c8d3093] | 344 | self.model_name_list.append(MultiShellModel.__name__) |
---|
[eddff027] | 345 | |
---|
[1a395a6] | 346 | from sans.models.OnionExpShellModel import OnionExpShellModel |
---|
[df7a7e3] | 347 | self.model_dictionary[OnionExpShellModel.__name__] = OnionExpShellModel |
---|
[1a395a6] | 348 | self.shape_list.append(OnionExpShellModel) |
---|
| 349 | self.multiplication_factor.append(OnionExpShellModel) |
---|
| 350 | self.multi_func_list.append(OnionExpShellModel) |
---|
[463eb76e] | 351 | |
---|
[1a395a6] | 352 | from sans.models.SphericalSLDModel import SphericalSLDModel |
---|
[df7a7e3] | 353 | self.model_dictionary[SphericalSLDModel.__name__] = SphericalSLDModel |
---|
[1a395a6] | 354 | self.shape_list.append(SphericalSLDModel) |
---|
| 355 | self.multiplication_factor.append(SphericalSLDModel) |
---|
| 356 | self.multi_func_list.append(SphericalSLDModel) |
---|
[a8d3b4f] | 357 | |
---|
[cee6867] | 358 | |
---|
[d9547e7] | 359 | from sans.models.LinearPearlsModel import LinearPearlsModel |
---|
[df7a7e3] | 360 | self.model_dictionary[LinearPearlsModel.__name__] = LinearPearlsModel |
---|
[d9547e7] | 361 | self.shape_list.append(LinearPearlsModel) |
---|
| 362 | self.model_name_list.append(LinearPearlsModel.__name__) |
---|
| 363 | |
---|
[4ad076b] | 364 | from sans.models.PearlNecklaceModel import PearlNecklaceModel |
---|
[df7a7e3] | 365 | self.model_dictionary[PearlNecklaceModel.__name__] = PearlNecklaceModel |
---|
[4ad076b] | 366 | self.shape_list.append(PearlNecklaceModel) |
---|
[7c8d3093] | 367 | self.model_name_list.append(PearlNecklaceModel.__name__) |
---|
[4ad076b] | 368 | #self.multiplication_factor.append(PearlNecklaceModel) |
---|
| 369 | |
---|
[eddff027] | 370 | from sans.models.CylinderModel import CylinderModel |
---|
[df7a7e3] | 371 | self.model_dictionary[CylinderModel.__name__] = CylinderModel |
---|
[eddff027] | 372 | self.shape_list.append(CylinderModel) |
---|
| 373 | self.multiplication_factor.append(CylinderModel) |
---|
[7c8d3093] | 374 | self.model_name_list.append(CylinderModel.__name__) |
---|
[eddff027] | 375 | |
---|
| 376 | from sans.models.CoreShellCylinderModel import CoreShellCylinderModel |
---|
[df7a7e3] | 377 | self.model_dictionary[CoreShellCylinderModel.__name__] = CoreShellCylinderModel |
---|
[eddff027] | 378 | self.shape_list.append(CoreShellCylinderModel) |
---|
[5eb9154] | 379 | self.multiplication_factor.append(CoreShellCylinderModel) |
---|
[7c8d3093] | 380 | self.model_name_list.append(CoreShellCylinderModel.__name__) |
---|
[cee6867] | 381 | |
---|
[543d1bd] | 382 | from sans.models.CoreShellBicelleModel import CoreShellBicelleModel |
---|
[df7a7e3] | 383 | self.model_dictionary[CoreShellBicelleModel.__name__] = CoreShellBicelleModel |
---|
[543d1bd] | 384 | self.shape_list.append(CoreShellBicelleModel) |
---|
| 385 | self.multiplication_factor.append(CoreShellBicelleModel) |
---|
| 386 | self.model_name_list.append(CoreShellBicelleModel.__name__) |
---|
| 387 | |
---|
[cee6867] | 388 | from sans.models.HollowCylinderModel import HollowCylinderModel |
---|
[df7a7e3] | 389 | self.model_dictionary[HollowCylinderModel.__name__] = HollowCylinderModel |
---|
[cee6867] | 390 | self.shape_list.append(HollowCylinderModel) |
---|
[5eb9154] | 391 | self.multiplication_factor.append(HollowCylinderModel) |
---|
[7c8d3093] | 392 | self.model_name_list.append(HollowCylinderModel.__name__) |
---|
[eddff027] | 393 | |
---|
| 394 | from sans.models.FlexibleCylinderModel import FlexibleCylinderModel |
---|
[df7a7e3] | 395 | self.model_dictionary[FlexibleCylinderModel.__name__] = FlexibleCylinderModel |
---|
[eddff027] | 396 | self.shape_list.append(FlexibleCylinderModel) |
---|
[7c8d3093] | 397 | self.model_name_list.append(FlexibleCylinderModel.__name__) |
---|
[72f719b] | 398 | |
---|
[ce07fa8] | 399 | from sans.models.FlexCylEllipXModel import FlexCylEllipXModel |
---|
[df7a7e3] | 400 | self.model_dictionary[FlexCylEllipXModel.__name__] = FlexCylEllipXModel |
---|
[ce07fa8] | 401 | self.shape_list.append(FlexCylEllipXModel) |
---|
[7c8d3093] | 402 | self.model_name_list.append(FlexCylEllipXModel.__name__) |
---|
[eddff027] | 403 | |
---|
| 404 | from sans.models.StackedDisksModel import StackedDisksModel |
---|
[df7a7e3] | 405 | self.model_dictionary[StackedDisksModel.__name__] = StackedDisksModel |
---|
[eddff027] | 406 | self.shape_list.append(StackedDisksModel) |
---|
[5eb9154] | 407 | self.multiplication_factor.append(StackedDisksModel) |
---|
[7c8d3093] | 408 | self.model_name_list.append(StackedDisksModel.__name__) |
---|
[eddff027] | 409 | |
---|
| 410 | from sans.models.ParallelepipedModel import ParallelepipedModel |
---|
[df7a7e3] | 411 | self.model_dictionary[ParallelepipedModel.__name__] = ParallelepipedModel |
---|
[eddff027] | 412 | self.shape_list.append(ParallelepipedModel) |
---|
[72f719b] | 413 | self.multiplication_factor.append(ParallelepipedModel) |
---|
[7c8d3093] | 414 | self.model_name_list.append(ParallelepipedModel.__name__) |
---|
[cee6867] | 415 | |
---|
[fb59ed9] | 416 | from sans.models.CSParallelepipedModel import CSParallelepipedModel |
---|
[df7a7e3] | 417 | self.model_dictionary[CSParallelepipedModel.__name__] = CSParallelepipedModel |
---|
[fb59ed9] | 418 | self.shape_list.append(CSParallelepipedModel) |
---|
| 419 | self.multiplication_factor.append(CSParallelepipedModel) |
---|
[7c8d3093] | 420 | self.model_name_list.append(CSParallelepipedModel.__name__) |
---|
[fb59ed9] | 421 | |
---|
[442895f] | 422 | from sans.models.EllipticalCylinderModel import EllipticalCylinderModel |
---|
[df7a7e3] | 423 | self.model_dictionary[EllipticalCylinderModel.__name__] = EllipticalCylinderModel |
---|
[bb18ef1] | 424 | self.shape_list.append(EllipticalCylinderModel) |
---|
[72f719b] | 425 | self.multiplication_factor.append(EllipticalCylinderModel) |
---|
[7c8d3093] | 426 | self.model_name_list.append(EllipticalCylinderModel.__name__) |
---|
[fb59ed9] | 427 | |
---|
| 428 | from sans.models.BarBellModel import BarBellModel |
---|
[df7a7e3] | 429 | self.model_dictionary[BarBellModel.__name__] = BarBellModel |
---|
[fb59ed9] | 430 | self.shape_list.append(BarBellModel) |
---|
[7c8d3093] | 431 | self.model_name_list.append(BarBellModel.__name__) |
---|
[fb59ed9] | 432 | # not implemeted yet! |
---|
| 433 | #self.multiplication_factor.append(BarBellModel) |
---|
| 434 | |
---|
| 435 | from sans.models.CappedCylinderModel import CappedCylinderModel |
---|
[df7a7e3] | 436 | self.model_dictionary[CappedCylinderModel.__name__] = CappedCylinderModel |
---|
[fb59ed9] | 437 | self.shape_list.append(CappedCylinderModel) |
---|
[7c8d3093] | 438 | self.model_name_list.append(CappedCylinderModel.__name__) |
---|
[fb59ed9] | 439 | # not implemeted yet! |
---|
| 440 | #self.multiplication_factor.append(CappedCylinderModel) |
---|
| 441 | |
---|
[442895f] | 442 | from sans.models.EllipsoidModel import EllipsoidModel |
---|
[df7a7e3] | 443 | self.model_dictionary[EllipsoidModel.__name__] = EllipsoidModel |
---|
[bb18ef1] | 444 | self.shape_list.append(EllipsoidModel) |
---|
[376916c] | 445 | self.multiplication_factor.append(EllipsoidModel) |
---|
[7c8d3093] | 446 | self.model_name_list.append(EllipsoidModel.__name__) |
---|
[eddff027] | 447 | |
---|
| 448 | from sans.models.CoreShellEllipsoidModel import CoreShellEllipsoidModel |
---|
[df7a7e3] | 449 | self.model_dictionary[CoreShellEllipsoidModel.__name__] = CoreShellEllipsoidModel |
---|
[eddff027] | 450 | self.shape_list.append(CoreShellEllipsoidModel) |
---|
[5eb9154] | 451 | self.multiplication_factor.append(CoreShellEllipsoidModel) |
---|
[7c8d3093] | 452 | self.model_name_list.append(CoreShellEllipsoidModel.__name__) |
---|
[bb18ef1] | 453 | |
---|
[e65050e] | 454 | from sans.models.TriaxialEllipsoidModel import TriaxialEllipsoidModel |
---|
[df7a7e3] | 455 | self.model_dictionary[TriaxialEllipsoidModel.__name__] = TriaxialEllipsoidModel |
---|
[e65050e] | 456 | self.shape_list.append(TriaxialEllipsoidModel) |
---|
[9002927] | 457 | self.multiplication_factor.append(TriaxialEllipsoidModel) |
---|
[7c8d3093] | 458 | self.model_name_list.append(TriaxialEllipsoidModel.__name__) |
---|
[e65050e] | 459 | |
---|
| 460 | from sans.models.LamellarModel import LamellarModel |
---|
[df7a7e3] | 461 | self.model_dictionary[LamellarModel.__name__] = LamellarModel |
---|
[e65050e] | 462 | self.shape_list.append(LamellarModel) |
---|
[7c8d3093] | 463 | self.model_name_list.append(LamellarModel.__name__) |
---|
[e65050e] | 464 | |
---|
| 465 | from sans.models.LamellarFFHGModel import LamellarFFHGModel |
---|
[df7a7e3] | 466 | self.model_dictionary[LamellarFFHGModel.__name__] = LamellarFFHGModel |
---|
[e65050e] | 467 | self.shape_list.append(LamellarFFHGModel) |
---|
[7c8d3093] | 468 | self.model_name_list.append(LamellarFFHGModel.__name__) |
---|
[e65050e] | 469 | |
---|
| 470 | from sans.models.LamellarPSModel import LamellarPSModel |
---|
[df7a7e3] | 471 | self.model_dictionary[LamellarPSModel.__name__] = LamellarPSModel |
---|
[e65050e] | 472 | self.shape_list.append(LamellarPSModel) |
---|
[7c8d3093] | 473 | self.model_name_list.append(LamellarPSModel.__name__) |
---|
[7a69683] | 474 | |
---|
[e65050e] | 475 | from sans.models.LamellarPSHGModel import LamellarPSHGModel |
---|
[df7a7e3] | 476 | self.model_dictionary[LamellarPSHGModel.__name__] = LamellarPSHGModel |
---|
[e65050e] | 477 | self.shape_list.append(LamellarPSHGModel) |
---|
[7c8d3093] | 478 | self.model_name_list.append(LamellarPSHGModel.__name__) |
---|
[fb59ed9] | 479 | |
---|
| 480 | from sans.models.LamellarPCrystalModel import LamellarPCrystalModel |
---|
[df7a7e3] | 481 | self.model_dictionary[LamellarPCrystalModel.__name__] = LamellarPCrystalModel |
---|
[fb59ed9] | 482 | self.shape_list.append(LamellarPCrystalModel) |
---|
[7c8d3093] | 483 | self.model_name_list.append(LamellarPCrystalModel.__name__) |
---|
[fb59ed9] | 484 | |
---|
| 485 | from sans.models.SCCrystalModel import SCCrystalModel |
---|
[df7a7e3] | 486 | self.model_dictionary[SCCrystalModel.__name__] = SCCrystalModel |
---|
[fb59ed9] | 487 | self.shape_list.append(SCCrystalModel) |
---|
[7c8d3093] | 488 | self.model_name_list.append(SCCrystalModel.__name__) |
---|
[fb59ed9] | 489 | |
---|
| 490 | from sans.models.FCCrystalModel import FCCrystalModel |
---|
[df7a7e3] | 491 | self.model_dictionary[FCCrystalModel.__name__] = FCCrystalModel |
---|
[fb59ed9] | 492 | self.shape_list.append(FCCrystalModel) |
---|
[7c8d3093] | 493 | self.model_name_list.append(FCCrystalModel.__name__) |
---|
[fb59ed9] | 494 | |
---|
| 495 | from sans.models.BCCrystalModel import BCCrystalModel |
---|
[df7a7e3] | 496 | self.model_dictionary[BCCrystalModel.__name__] = BCCrystalModel |
---|
[fb59ed9] | 497 | self.shape_list.append(BCCrystalModel) |
---|
[7c8d3093] | 498 | self.model_name_list.append(BCCrystalModel.__name__) |
---|
[7a69683] | 499 | |
---|
[f32d144] | 500 | ## Structure factor |
---|
[8346667] | 501 | from sans.models.SquareWellStructure import SquareWellStructure |
---|
[df7a7e3] | 502 | self.model_dictionary[SquareWellStructure.__name__] = SquareWellStructure |
---|
[bb18ef1] | 503 | self.struct_list.append(SquareWellStructure) |
---|
[7c8d3093] | 504 | self.model_name_list.append(SquareWellStructure.__name__) |
---|
[8346667] | 505 | |
---|
| 506 | from sans.models.HardsphereStructure import HardsphereStructure |
---|
[df7a7e3] | 507 | self.model_dictionary[HardsphereStructure.__name__] = HardsphereStructure |
---|
[bb18ef1] | 508 | self.struct_list.append(HardsphereStructure) |
---|
[7c8d3093] | 509 | self.model_name_list.append(HardsphereStructure.__name__) |
---|
[bb18ef1] | 510 | |
---|
[8346667] | 511 | from sans.models.StickyHSStructure import StickyHSStructure |
---|
[df7a7e3] | 512 | self.model_dictionary[StickyHSStructure.__name__] = StickyHSStructure |
---|
[bb18ef1] | 513 | self.struct_list.append(StickyHSStructure) |
---|
[7c8d3093] | 514 | self.model_name_list.append(StickyHSStructure.__name__) |
---|
[8346667] | 515 | |
---|
| 516 | from sans.models.HayterMSAStructure import HayterMSAStructure |
---|
[df7a7e3] | 517 | self.model_dictionary[HayterMSAStructure.__name__] = HayterMSAStructure |
---|
[bb18ef1] | 518 | self.struct_list.append(HayterMSAStructure) |
---|
[7c8d3093] | 519 | self.model_name_list.append(HayterMSAStructure.__name__) |
---|
[a8d3b4f] | 520 | |
---|
| 521 | |
---|
[fb59ed9] | 522 | ##shape-independent models |
---|
[ce07fa8] | 523 | from sans.models.PowerLawAbsModel import PowerLawAbsModel |
---|
[df7a7e3] | 524 | self.model_dictionary[PowerLawAbsModel.__name__] = PowerLawAbsModel |
---|
[f32d144] | 525 | self.shape_indep_list.append(PowerLawAbsModel) |
---|
[7c8d3093] | 526 | self.model_name_list.append(PowerLawAbsModel.__name__) |
---|
[ce07fa8] | 527 | |
---|
[442895f] | 528 | from sans.models.BEPolyelectrolyte import BEPolyelectrolyte |
---|
[df7a7e3] | 529 | self.model_dictionary[BEPolyelectrolyte.__name__] = BEPolyelectrolyte |
---|
[f32d144] | 530 | self.shape_indep_list.append(BEPolyelectrolyte) |
---|
[7c8d3093] | 531 | self.model_name_list.append(BEPolyelectrolyte.__name__) |
---|
[bb18ef1] | 532 | self.form_factor_dict[str(wx.NewId())] = [SphereModel] |
---|
[fb59ed9] | 533 | |
---|
| 534 | from sans.models.BroadPeakModel import BroadPeakModel |
---|
[df7a7e3] | 535 | self.model_dictionary[BroadPeakModel.__name__] = BroadPeakModel |
---|
[fb59ed9] | 536 | self.shape_indep_list.append(BroadPeakModel) |
---|
[7c8d3093] | 537 | self.model_name_list.append(BroadPeakModel.__name__) |
---|
[fb59ed9] | 538 | |
---|
| 539 | from sans.models.CorrLengthModel import CorrLengthModel |
---|
[df7a7e3] | 540 | self.model_dictionary[CorrLengthModel.__name__] = CorrLengthModel |
---|
[fb59ed9] | 541 | self.shape_indep_list.append(CorrLengthModel) |
---|
[7c8d3093] | 542 | self.model_name_list.append(CorrLengthModel.__name__) |
---|
[fb59ed9] | 543 | |
---|
[442895f] | 544 | from sans.models.DABModel import DABModel |
---|
[df7a7e3] | 545 | self.model_dictionary[DABModel.__name__] = DABModel |
---|
[f32d144] | 546 | self.shape_indep_list.append(DABModel) |
---|
[7c8d3093] | 547 | self.model_name_list.append(DABModel.__name__) |
---|
[442895f] | 548 | |
---|
[ce07fa8] | 549 | from sans.models.DebyeModel import DebyeModel |
---|
[df7a7e3] | 550 | self.model_dictionary[DebyeModel.__name__] = DebyeModel |
---|
[f32d144] | 551 | self.shape_indep_list.append(DebyeModel) |
---|
[7c8d3093] | 552 | self.model_name_list.append(DebyeModel.__name__) |
---|
[ce07fa8] | 553 | |
---|
| 554 | from sans.models.FractalModel import FractalModel |
---|
[df7a7e3] | 555 | self.model_dictionary[FractalModel.__name__] = FractalModel |
---|
[f32d144] | 556 | self.shape_indep_list.append(FractalModel) |
---|
[7c8d3093] | 557 | self.model_name_list.append(FractalModel.__name__) |
---|
[bb18ef1] | 558 | |
---|
[fb59ed9] | 559 | from sans.models.FractalCoreShellModel import FractalCoreShellModel |
---|
[df7a7e3] | 560 | self.model_dictionary[FractalCoreShellModel.__name__] = FractalCoreShellModel |
---|
[f32d144] | 561 | self.shape_indep_list.append(FractalCoreShellModel) |
---|
[7c8d3093] | 562 | self.model_name_list.append(FractalCoreShellModel.__name__) |
---|
[fb59ed9] | 563 | |
---|
| 564 | from sans.models.GaussLorentzGelModel import GaussLorentzGelModel |
---|
[df7a7e3] | 565 | self.model_dictionary[GaussLorentzGelModel.__name__] = GaussLorentzGelModel |
---|
[f32d144] | 566 | self.shape_indep_list.append(GaussLorentzGelModel) |
---|
[7c8d3093] | 567 | self.model_name_list.append(GaussLorentzGelModel.__name__) |
---|
[fb59ed9] | 568 | |
---|
| 569 | from sans.models.GuinierModel import GuinierModel |
---|
[df7a7e3] | 570 | self.model_dictionary[GuinierModel.__name__] = GuinierModel |
---|
[f32d144] | 571 | self.shape_indep_list.append(GuinierModel) |
---|
[7c8d3093] | 572 | self.model_name_list.append(GuinierModel.__name__) |
---|
[fb59ed9] | 573 | |
---|
| 574 | from sans.models.GuinierPorodModel import GuinierPorodModel |
---|
[df7a7e3] | 575 | self.model_dictionary[GuinierPorodModel.__name__] = GuinierPorodModel |
---|
[f32d144] | 576 | self.shape_indep_list.append(GuinierPorodModel) |
---|
[7c8d3093] | 577 | self.model_name_list.append(GuinierPorodModel.__name__) |
---|
[fb59ed9] | 578 | |
---|
[ce07fa8] | 579 | from sans.models.LorentzModel import LorentzModel |
---|
[df7a7e3] | 580 | self.model_dictionary[LorentzModel.__name__] = LorentzModel |
---|
[f32d144] | 581 | self.shape_indep_list.append(LorentzModel) |
---|
[7c8d3093] | 582 | self.model_name_list.append(LorentzModel.__name__) |
---|
[51da9dc] | 583 | |
---|
| 584 | from sans.models.MassFractalModel import MassFractalModel |
---|
[df7a7e3] | 585 | self.model_dictionary[MassFractalModel.__name__] = MassFractalModel |
---|
[51da9dc] | 586 | self.shape_indep_list.append(MassFractalModel) |
---|
| 587 | self.model_name_list.append(MassFractalModel.__name__) |
---|
| 588 | |
---|
| 589 | from sans.models.MassSurfaceFractal import MassSurfaceFractal |
---|
[df7a7e3] | 590 | self.model_dictionary[MassSurfaceFractal.__name__] = MassSurfaceFractal |
---|
[51da9dc] | 591 | self.shape_indep_list.append(MassSurfaceFractal) |
---|
| 592 | self.model_name_list.append(MassSurfaceFractal.__name__) |
---|
[442895f] | 593 | |
---|
[cee6867] | 594 | from sans.models.PeakGaussModel import PeakGaussModel |
---|
[df7a7e3] | 595 | self.model_dictionary[PeakGaussModel.__name__] = PeakGaussModel |
---|
[cee6867] | 596 | self.shape_indep_list.append(PeakGaussModel) |
---|
[7c8d3093] | 597 | self.model_name_list.append(PeakGaussModel.__name__) |
---|
[cee6867] | 598 | |
---|
| 599 | from sans.models.PeakLorentzModel import PeakLorentzModel |
---|
[df7a7e3] | 600 | self.model_dictionary[PeakLorentzModel.__name__] = PeakLorentzModel |
---|
[cee6867] | 601 | self.shape_indep_list.append(PeakLorentzModel) |
---|
[f32d144] | 602 | self.model_name_list.append(PeakLorentzModel.__name__) |
---|
[cee6867] | 603 | |
---|
[ce07fa8] | 604 | from sans.models.Poly_GaussCoil import Poly_GaussCoil |
---|
[df7a7e3] | 605 | self.model_dictionary[Poly_GaussCoil.__name__] = Poly_GaussCoil |
---|
[ce07fa8] | 606 | self.shape_indep_list.append(Poly_GaussCoil) |
---|
[7c8d3093] | 607 | self.model_name_list.append(Poly_GaussCoil.__name__) |
---|
[fb59ed9] | 608 | |
---|
| 609 | from sans.models.PolymerExclVolume import PolymerExclVolume |
---|
[df7a7e3] | 610 | self.model_dictionary[PolymerExclVolume.__name__] = PolymerExclVolume |
---|
[fb59ed9] | 611 | self.shape_indep_list.append(PolymerExclVolume) |
---|
[7c8d3093] | 612 | self.model_name_list.append(PolymerExclVolume.__name__) |
---|
[fb59ed9] | 613 | |
---|
[ce07fa8] | 614 | from sans.models.PorodModel import PorodModel |
---|
[df7a7e3] | 615 | self.model_dictionary[PorodModel.__name__] = PorodModel |
---|
[f32d144] | 616 | self.shape_indep_list.append(PorodModel) |
---|
| 617 | self.model_name_list.append(PorodModel.__name__) |
---|
[442895f] | 618 | |
---|
[fb59ed9] | 619 | from sans.models.RPA10Model import RPA10Model |
---|
[df7a7e3] | 620 | self.model_dictionary[RPA10Model.__name__] = RPA10Model |
---|
[fb59ed9] | 621 | self.shape_indep_list.append(RPA10Model) |
---|
| 622 | self.multi_func_list.append(RPA10Model) |
---|
[51da9dc] | 623 | |
---|
[082c565] | 624 | from sans.models.StarPolymer import StarPolymer |
---|
[df7a7e3] | 625 | self.model_dictionary[StarPolymer.__name__] = StarPolymer |
---|
[082c565] | 626 | self.shape_indep_list.append(StarPolymer) |
---|
| 627 | self.model_name_list.append(StarPolymer.__name__) |
---|
| 628 | |
---|
[51da9dc] | 629 | from sans.models.SurfaceFractalModel import SurfaceFractalModel |
---|
[df7a7e3] | 630 | self.model_dictionary[SurfaceFractalModel.__name__] = SurfaceFractalModel |
---|
[51da9dc] | 631 | self.shape_indep_list.append(SurfaceFractalModel) |
---|
| 632 | self.model_name_list.append(SurfaceFractalModel.__name__) |
---|
[81bece4] | 633 | |
---|
[442895f] | 634 | from sans.models.TeubnerStreyModel import TeubnerStreyModel |
---|
[df7a7e3] | 635 | self.model_dictionary[TeubnerStreyModel.__name__] = TeubnerStreyModel |
---|
[f32d144] | 636 | self.shape_indep_list.append(TeubnerStreyModel) |
---|
[7c8d3093] | 637 | self.model_name_list.append(TeubnerStreyModel.__name__) |
---|
[a269378] | 638 | |
---|
[fb59ed9] | 639 | from sans.models.TwoLorentzianModel import TwoLorentzianModel |
---|
[df7a7e3] | 640 | self.model_dictionary[TwoLorentzianModel.__name__] = TwoLorentzianModel |
---|
[f32d144] | 641 | self.shape_indep_list.append(TwoLorentzianModel) |
---|
[7c8d3093] | 642 | self.model_name_list.append(TwoLorentzianModel.__name__) |
---|
[fb59ed9] | 643 | |
---|
| 644 | from sans.models.TwoPowerLawModel import TwoPowerLawModel |
---|
[df7a7e3] | 645 | self.model_dictionary[TwoPowerLawModel.__name__] = TwoPowerLawModel |
---|
[f32d144] | 646 | self.shape_indep_list.append(TwoPowerLawModel) |
---|
[7c8d3093] | 647 | self.model_name_list.append(TwoPowerLawModel.__name__) |
---|
[fb59ed9] | 648 | |
---|
| 649 | from sans.models.UnifiedPowerRgModel import UnifiedPowerRgModel |
---|
[df7a7e3] | 650 | self.model_dictionary[UnifiedPowerRgModel.__name__] = UnifiedPowerRgModel |
---|
[f32d144] | 651 | self.shape_indep_list.append(UnifiedPowerRgModel) |
---|
[fb59ed9] | 652 | self.multi_func_list.append(UnifiedPowerRgModel) |
---|
[5da3cc5] | 653 | |
---|
[eddff027] | 654 | from sans.models.LineModel import LineModel |
---|
[df7a7e3] | 655 | self.model_dictionary[LineModel.__name__] = LineModel |
---|
[eddff027] | 656 | self.shape_indep_list.append(LineModel) |
---|
[7c8d3093] | 657 | self.model_name_list.append(LineModel.__name__) |
---|
[5062bbf] | 658 | |
---|
[fb59ed9] | 659 | from sans.models.ReflectivityModel import ReflectivityModel |
---|
[df7a7e3] | 660 | self.model_dictionary[ReflectivityModel.__name__] = ReflectivityModel |
---|
[19e614a] | 661 | self.shape_indep_list.append(ReflectivityModel) |
---|
[fb59ed9] | 662 | self.multi_func_list.append(ReflectivityModel) |
---|
[1cc23fd] | 663 | |
---|
| 664 | from sans.models.ReflectivityIIModel import ReflectivityIIModel |
---|
[df7a7e3] | 665 | self.model_dictionary[ReflectivityIIModel.__name__] = ReflectivityIIModel |
---|
[19e614a] | 666 | self.shape_indep_list.append(ReflectivityIIModel) |
---|
[1cc23fd] | 667 | self.multi_func_list.append(ReflectivityIIModel) |
---|
[0da4eba] | 668 | |
---|
| 669 | from sans.models.GelFitModel import GelFitModel |
---|
[df7a7e3] | 670 | self.model_dictionary[GelFitModel.__name__] = GelFitModel |
---|
[0da4eba] | 671 | self.shape_indep_list.append(GelFitModel) |
---|
| 672 | self.model_name_list.append(GelFitModel.__name__) |
---|
[657e52c] | 673 | |
---|
[df7a7e3] | 674 | #from sans.models.FractalO_Z import FractalO_Z |
---|
| 675 | #self.model_dictionary[FractalO_Z.__name__] = FractalO_Z |
---|
| 676 | #self.shape_indep_list.append(FractalO_Z) |
---|
| 677 | #self.model_name_list.append(FractalO_Z.__name__) |
---|
| 678 | |
---|
[49b7efa] | 679 | #Looking for plugins |
---|
[9466f2d6] | 680 | self.stored_plugins = self.findModels() |
---|
[b2d9826] | 681 | self.plugins = self.stored_plugins.values() |
---|
[ea5fa58] | 682 | for name, plug in self.stored_plugins.iteritems(): |
---|
| 683 | self.model_dictionary[name] = plug |
---|
| 684 | |
---|
[b2d9826] | 685 | self._get_multifunc_models() |
---|
| 686 | |
---|
[d89f09b] | 687 | return 0 |
---|
| 688 | |
---|
[9466f2d6] | 689 | def is_changed(self): |
---|
| 690 | """ |
---|
| 691 | check the last time the plugin dir has changed and return true |
---|
| 692 | is the directory was modified else return false |
---|
| 693 | """ |
---|
| 694 | is_modified = False |
---|
[96814e1] | 695 | plugin_dir = find_plugins_dir() |
---|
| 696 | if os.path.isdir(plugin_dir): |
---|
[f32d144] | 697 | temp = os.path.getmtime(plugin_dir) |
---|
[9466f2d6] | 698 | if self.last_time_dir_modified != temp: |
---|
| 699 | is_modified = True |
---|
| 700 | self.last_time_dir_modified = temp |
---|
[bb9f322] | 701 | |
---|
[9466f2d6] | 702 | return is_modified |
---|
[d89f09b] | 703 | |
---|
[b2d9826] | 704 | def update(self): |
---|
| 705 | """ |
---|
[f32d144] | 706 | return a dictionary of model if |
---|
[9466f2d6] | 707 | new models were added else return empty dictionary |
---|
[b2d9826] | 708 | """ |
---|
[9466f2d6] | 709 | new_plugins = self.findModels() |
---|
| 710 | if len(new_plugins) > 0: |
---|
| 711 | for name, plug in new_plugins.iteritems(): |
---|
| 712 | if name not in self.stored_plugins.keys(): |
---|
| 713 | self.stored_plugins[name] = plug |
---|
| 714 | self.plugins.append(plug) |
---|
[ea5fa58] | 715 | self.model_dictionary[name] = plug |
---|
[9466f2d6] | 716 | self.model_combobox.set_list("Customized Models", self.plugins) |
---|
| 717 | return self.model_combobox.get_list() |
---|
| 718 | else: |
---|
| 719 | return {} |
---|
[5d1c1f4] | 720 | |
---|
[916f5c0] | 721 | def pulgins_reset(self): |
---|
| 722 | """ |
---|
| 723 | return a dictionary of model |
---|
| 724 | """ |
---|
| 725 | self.plugins = [] |
---|
| 726 | new_plugins = _findModels(dir) |
---|
| 727 | for name, plug in new_plugins.iteritems(): |
---|
| 728 | for stored_name, stored_plug in self.stored_plugins.iteritems(): |
---|
| 729 | if name == stored_name: |
---|
| 730 | del self.stored_plugins[name] |
---|
[ea5fa58] | 731 | del self.model_dictionary[name] |
---|
[916f5c0] | 732 | break |
---|
| 733 | self.stored_plugins[name] = plug |
---|
| 734 | self.plugins.append(plug) |
---|
[ea5fa58] | 735 | self.model_dictionary[name] = plug |
---|
[19e614a] | 736 | |
---|
[916f5c0] | 737 | self.model_combobox.reset_list("Customized Models", self.plugins) |
---|
| 738 | return self.model_combobox.get_list() |
---|
| 739 | |
---|
[d89f09b] | 740 | def populate_menu(self, modelmenu, event_owner): |
---|
| 741 | """ |
---|
[5062bbf] | 742 | Populate a menu with our models |
---|
| 743 | |
---|
| 744 | :param id: first menu event ID to use when binding the menu events |
---|
| 745 | :param modelmenu: wx.Menu object to populate |
---|
| 746 | :param event_owner: wx object to bind the menu events to |
---|
| 747 | |
---|
| 748 | :return: the next free event ID following the new menu events |
---|
| 749 | |
---|
[d89f09b] | 750 | """ |
---|
[bb18ef1] | 751 | ## Fill model lists |
---|
[d89f09b] | 752 | self._getModelList() |
---|
[bb18ef1] | 753 | ## store reference to model menu of guiframe |
---|
| 754 | self.modelmenu = modelmenu |
---|
| 755 | ## guiframe reference |
---|
[d89f09b] | 756 | self.event_owner = event_owner |
---|
[bb18ef1] | 757 | |
---|
| 758 | shape_submenu = wx.Menu() |
---|
| 759 | shape_indep_submenu = wx.Menu() |
---|
| 760 | structure_factor = wx.Menu() |
---|
[b30f001] | 761 | added_models = wx.Menu() |
---|
[376916c] | 762 | multip_models = wx.Menu() |
---|
[bb18ef1] | 763 | ## create menu with shape |
---|
[f32d144] | 764 | self._fill_simple_menu(menuinfo=["Shapes", |
---|
| 765 | shape_submenu, |
---|
| 766 | " simple shape"], |
---|
[5062bbf] | 767 | list1=self.shape_list) |
---|
[376916c] | 768 | |
---|
[f32d144] | 769 | self._fill_simple_menu(menuinfo=["Shape-Independent", |
---|
| 770 | shape_indep_submenu, |
---|
| 771 | "List of shape-independent models"], |
---|
| 772 | list1=self.shape_indep_list) |
---|
[bb18ef1] | 773 | |
---|
[f32d144] | 774 | self._fill_simple_menu(menuinfo=["Structure Factors", |
---|
| 775 | structure_factor, |
---|
| 776 | "List of Structure factors models"], |
---|
[5062bbf] | 777 | list1=self.struct_list) |
---|
[bb18ef1] | 778 | |
---|
[5062bbf] | 779 | self._fill_plugin_menu(menuinfo=["Customized Models", added_models, |
---|
[376916c] | 780 | "List of additional models"], |
---|
[5062bbf] | 781 | list1=self.plugins) |
---|
[376916c] | 782 | |
---|
[f32d144] | 783 | self._fill_menu(menuinfo=["P(Q)*S(Q)", multip_models, |
---|
[376916c] | 784 | "mulplication of 2 models"], |
---|
[f32d144] | 785 | list1=self.multiplication_factor, |
---|
| 786 | list2=self.struct_list) |
---|
[d89f09b] | 787 | return 0 |
---|
| 788 | |
---|
[5062bbf] | 789 | def _fill_plugin_menu(self, menuinfo, list1): |
---|
[bfe4644] | 790 | """ |
---|
[5062bbf] | 791 | fill the plugin menu with costumized models |
---|
[bfe4644] | 792 | """ |
---|
[f32d144] | 793 | if len(list1) == 0: |
---|
| 794 | id = wx.NewId() |
---|
| 795 | msg = "No model available check plugins.log for errors to fix problem" |
---|
| 796 | menuinfo[1].Append(int(id), "Empty", msg) |
---|
| 797 | self._fill_simple_menu(menuinfo, list1) |
---|
[bfe4644] | 798 | |
---|
[5062bbf] | 799 | def _fill_simple_menu(self, menuinfo, list1): |
---|
[bb18ef1] | 800 | """ |
---|
[5062bbf] | 801 | Fill the menu with list item |
---|
| 802 | |
---|
| 803 | :param modelmenu: the menu to fill |
---|
| 804 | :param menuinfo: submenu item for the first column of this modelmenu |
---|
| 805 | with info.Should be a list : |
---|
| 806 | [name(string) , menu(wx.menu), help(string)] |
---|
| 807 | :param list1: contains item (form factor )to fill modelmenu second column |
---|
| 808 | |
---|
[bb18ef1] | 809 | """ |
---|
[f32d144] | 810 | if len(list1) > 0: |
---|
| 811 | self.model_combobox.set_list(menuinfo[0], list1) |
---|
[e7b1ccf] | 812 | |
---|
[bb18ef1] | 813 | for item in list1: |
---|
[e7b1ccf] | 814 | try: |
---|
[f32d144] | 815 | id = wx.NewId() |
---|
| 816 | struct_factor = item() |
---|
[e7b1ccf] | 817 | struct_name = struct_factor.__class__.__name__ |
---|
| 818 | if hasattr(struct_factor, "name"): |
---|
| 819 | struct_name = struct_factor.name |
---|
| 820 | |
---|
[f32d144] | 821 | menuinfo[1].Append(int(id), struct_name, struct_name) |
---|
[e7b1ccf] | 822 | if not item in self.struct_factor_dict.itervalues(): |
---|
[f32d144] | 823 | self.struct_factor_dict[str(id)] = item |
---|
[e7b1ccf] | 824 | wx.EVT_MENU(self.event_owner, int(id), self._on_model) |
---|
| 825 | except: |
---|
[f32d144] | 826 | msg = "Error Occured: %s" % sys.exc_value |
---|
[e7b1ccf] | 827 | wx.PostEvent(self.event_owner, StatusEvent(status=msg)) |
---|
[bb18ef1] | 828 | |
---|
[f32d144] | 829 | id = wx.NewId() |
---|
| 830 | self.modelmenu.AppendMenu(id, menuinfo[0], menuinfo[1], menuinfo[2]) |
---|
[bb18ef1] | 831 | |
---|
[5062bbf] | 832 | def _fill_menu(self, menuinfo, list1, list2): |
---|
[bb18ef1] | 833 | """ |
---|
[5062bbf] | 834 | Fill the menu with list item |
---|
| 835 | |
---|
| 836 | :param menuinfo: submenu item for the first column of this modelmenu |
---|
| 837 | with info.Should be a list : |
---|
| 838 | [name(string) , menu(wx.menu), help(string)] |
---|
| 839 | :param list1: contains item (form factor )to fill modelmenu second column |
---|
[f32d144] | 840 | :param list2: contains item (Structure factor )to fill modelmenu |
---|
[5062bbf] | 841 | third column |
---|
| 842 | |
---|
[bb18ef1] | 843 | """ |
---|
[f32d144] | 844 | if len(list1) > 0: |
---|
| 845 | self.model_combobox.set_list(menuinfo[0], list1) |
---|
[bb18ef1] | 846 | |
---|
[f32d144] | 847 | for item in list1: |
---|
| 848 | form_factor = item() |
---|
[bb18ef1] | 849 | form_name = form_factor.__class__.__name__ |
---|
| 850 | if hasattr(form_factor, "name"): |
---|
| 851 | form_name = form_factor.name |
---|
[f32d144] | 852 | ### store form factor to return to other users |
---|
| 853 | newmenu = wx.Menu() |
---|
| 854 | if len(list2) > 0: |
---|
[bb18ef1] | 855 | for model in list2: |
---|
| 856 | id = wx.NewId() |
---|
| 857 | struct_factor = model() |
---|
| 858 | name = struct_factor.__class__.__name__ |
---|
| 859 | if hasattr(struct_factor, "name"): |
---|
| 860 | name = struct_factor.name |
---|
[f32d144] | 861 | newmenu.Append(id, name, name) |
---|
[bb18ef1] | 862 | wx.EVT_MENU(self.event_owner, int(id), self._on_model) |
---|
| 863 | ## save form_fact and struct_fact |
---|
[f32d144] | 864 | self.form_factor_dict[int(id)] = [form_factor, |
---|
| 865 | struct_factor] |
---|
[bb18ef1] | 866 | |
---|
[f32d144] | 867 | form_id = wx.NewId() |
---|
| 868 | menuinfo[1].AppendMenu(int(form_id), form_name, |
---|
| 869 | newmenu, menuinfo[2]) |
---|
| 870 | id = wx.NewId() |
---|
| 871 | self.modelmenu.AppendMenu(id, menuinfo[0], menuinfo[1], menuinfo[2]) |
---|
[bb18ef1] | 872 | |
---|
[d89f09b] | 873 | def _on_model(self, evt): |
---|
| 874 | """ |
---|
[5062bbf] | 875 | React to a model menu event |
---|
| 876 | |
---|
| 877 | :param event: wx menu event |
---|
| 878 | |
---|
[d89f09b] | 879 | """ |
---|
[bb18ef1] | 880 | if int(evt.GetId()) in self.form_factor_dict.keys(): |
---|
| 881 | from sans.models.MultiplicationModel import MultiplicationModel |
---|
[df7a7e3] | 882 | self.model_dictionary[MultiplicationModel.__name__] = MultiplicationModel |
---|
[bb18ef1] | 883 | model1, model2 = self.form_factor_dict[int(evt.GetId())] |
---|
[f32d144] | 884 | model = MultiplicationModel(model1, model2) |
---|
[bb18ef1] | 885 | else: |
---|
[f32d144] | 886 | model = self.struct_factor_dict[str(evt.GetId())]() |
---|
[61184df] | 887 | |
---|
| 888 | #TODO: investigate why the following two lines were left in the code |
---|
| 889 | # even though the ModelEvent class doesn't exist |
---|
| 890 | #evt = ModelEvent(model=model) |
---|
| 891 | #wx.PostEvent(self.event_owner, evt) |
---|
[d89f09b] | 892 | |
---|
[fb59ed9] | 893 | def _get_multifunc_models(self): |
---|
| 894 | """ |
---|
| 895 | Get the multifunctional models |
---|
| 896 | """ |
---|
| 897 | for item in self.plugins: |
---|
| 898 | try: |
---|
| 899 | # check the multiplicity if any |
---|
| 900 | if item.multiplicity_info[0] > 1: |
---|
| 901 | self.multi_func_list.append(item) |
---|
| 902 | except: |
---|
| 903 | # pass to other items |
---|
| 904 | pass |
---|
| 905 | |
---|
[f32d144] | 906 | def get_model_list(self): |
---|
[5062bbf] | 907 | """ |
---|
[f32d144] | 908 | return dictionary of models for fitpanel use |
---|
[5062bbf] | 909 | |
---|
| 910 | """ |
---|
[6bbeacd4] | 911 | self.model_combobox.set_list("Shapes", self.shape_list) |
---|
[f32d144] | 912 | self.model_combobox.set_list("Shape-Independent", |
---|
| 913 | self.shape_indep_list) |
---|
[6bbeacd4] | 914 | self.model_combobox.set_list("Structure Factors", self.struct_list) |
---|
| 915 | self.model_combobox.set_list("Customized Models", self.plugins) |
---|
| 916 | self.model_combobox.set_list("P(Q)*S(Q)", self.multiplication_factor) |
---|
[f32d144] | 917 | self.model_combobox.set_list("multiplication", |
---|
| 918 | self.multiplication_factor) |
---|
[e87f9fc] | 919 | self.model_combobox.set_list("Multi-Functions", self.multi_func_list) |
---|
[b2d9826] | 920 | return self.model_combobox.get_list() |
---|
[d89f09b] | 921 | |
---|
[7c8d3093] | 922 | def get_model_name_list(self): |
---|
| 923 | """ |
---|
| 924 | return regular model name list |
---|
| 925 | """ |
---|
| 926 | return self.model_name_list |
---|
[df7a7e3] | 927 | |
---|
| 928 | def get_model_dictionary(self): |
---|
| 929 | """ |
---|
| 930 | return dictionary linking model names to objects |
---|
| 931 | """ |
---|
| 932 | return self.model_dictionary |
---|
[376916c] | 933 | |
---|
[bb18ef1] | 934 | |
---|
[bb9f322] | 935 | class ModelManager(object): |
---|
| 936 | """ |
---|
[f32d144] | 937 | implement model |
---|
[bb9f322] | 938 | """ |
---|
| 939 | __modelmanager = ModelManagerBase() |
---|
[657e52c] | 940 | cat_model_list = [model_name for model_name \ |
---|
| 941 | in __modelmanager.model_dictionary.keys() \ |
---|
| 942 | if model_name not in __modelmanager.stored_plugins.keys()] |
---|
| 943 | |
---|
| 944 | CategoryInstaller.check_install(model_list=cat_model_list) |
---|
[bb9f322] | 945 | |
---|
| 946 | def findModels(self): |
---|
| 947 | return self.__modelmanager.findModels() |
---|
| 948 | |
---|
| 949 | def _getModelList(self): |
---|
| 950 | return self.__modelmanager._getModelList() |
---|
| 951 | |
---|
| 952 | def is_changed(self): |
---|
| 953 | return self.__modelmanager.is_changed() |
---|
| 954 | |
---|
| 955 | def update(self): |
---|
| 956 | return self.__modelmanager.update() |
---|
| 957 | |
---|
[916f5c0] | 958 | def pulgins_reset(self): |
---|
| 959 | return self.__modelmanager.pulgins_reset() |
---|
| 960 | |
---|
[bb9f322] | 961 | def populate_menu(self, modelmenu, event_owner): |
---|
| 962 | return self.__modelmanager.populate_menu(modelmenu, event_owner) |
---|
| 963 | |
---|
| 964 | def _on_model(self, evt): |
---|
| 965 | return self.__modelmanager._on_model(evt) |
---|
| 966 | |
---|
| 967 | def _get_multifunc_models(self): |
---|
| 968 | return self.__modelmanager._get_multifunc_models() |
---|
| 969 | |
---|
[f32d144] | 970 | def get_model_list(self): |
---|
[bb9f322] | 971 | return self.__modelmanager.get_model_list() |
---|
[bb18ef1] | 972 | |
---|
[7c8d3093] | 973 | def get_model_name_list(self): |
---|
| 974 | return self.__modelmanager.get_model_name_list() |
---|
[df7a7e3] | 975 | |
---|
| 976 | def get_model_dictionary(self): |
---|
| 977 | return self.__modelmanager.get_model_dictionary() |
---|