Changeset 1a6cd57 in sasmodels
- Timestamp:
- Oct 11, 2016 11:25:56 AM (8 years ago)
- Branches:
- master, core_shell_microgels, costrafo411, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- 2ccb775, 997d4eb
- Parents:
- c1904f6
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
doc/ref/gpu/gpu_computations.rst
r711f17e r1a6cd57 5 5 **************** 6 6 SasView model evaluations can run on your graphics card (GPU) or they can run 7 on the processor (CPU). 7 on the processor (CPU). In general, calculations performed on the GPU will run faster. 8 8 9 9 To run on the GPU, your computer must have OpenCL drivers installed. … … 39 39 chose to run the model. 40 40 41 If you don't want to use OpenCL, you can set*SAS_OPENCL=None*42 in the environment, and it will only use normal programs. 41 **If you don't want to use OpenCL, you can set** *SAS_OPENCL=None* 42 **in your environment settings, and it will only use normal programs.** 43 43 44 44 If you want to use one of the other devices, you can run the following -
sasmodels/compare.py
rbb2d187 r1a6cd57 80 80 -edit starts the parameter explorer 81 81 -default/-demo* use demo vs default parameters 82 -html shows the model docs instead of running the model 82 83 83 84 Any two calculation engines can be selected for comparison: … … 736 737 'linear', 'log', 'q4', 737 738 'hist', 'nohist', 738 'edit', 739 'edit', 'html', 739 740 'demo', 'default', 740 741 ]) … … 845 846 'use_demo' : True, 846 847 'zero' : False, 848 'html' : False, 847 849 } 848 850 engines = [] … … 886 888 elif arg == '-demo': opts['use_demo'] = True 887 889 elif arg == '-default': opts['use_demo'] = False 890 elif arg == '-html': opts['html'] = True 888 891 # pylint: enable=bad-whitespace 889 892 … … 961 964 return opts 962 965 966 def show_docs(opts): 967 # type: (Dict[str, Any]) -> None 968 """ 969 show html docs for the model 970 """ 971 import wx # type: ignore 972 from .generate import view_html_from_info 973 app = wx.App() if wx.GetApp() is None else None 974 view_html_from_info(opts['def']) 975 if app: app.MainLoop() 976 977 963 978 def explore(opts): 964 979 # type: (Dict[str, Any]) -> None 965 980 """ 966 Explore the model using the Bumps GUI.981 explore the model using the bumps gui. 967 982 """ 968 983 import wx # type: ignore … … 1057 1072 opts = parse_opts(argv) 1058 1073 if opts is not None: 1059 if opts['explore']: 1074 if opts['html']: 1075 show_docs(opts) 1076 elif opts['explore']: 1060 1077 explore(opts) 1061 1078 else: -
sasmodels/custom/__init__.py
r2a0c7a6 r1a6cd57 8 8 to occur without error. 9 9 """ 10 from __future__ import division, print_function 10 11 12 import sys 11 13 import os 12 14 from os.path import basename, splitext … … 26 28 def load_module_from_path(fullname, path): 27 29 """load module from *path* as *fullname*""" 30 # Clear out old definitions, if any 31 if fullname in sys.modules: 32 del sys.modules[fullname] 28 33 module = imp.load_source(fullname, os.path.expanduser(path)) 29 34 #os.unlink(path+"c") # remove the automatic pyc file -
sasmodels/generate.py
r462a115 r1a6cd57 912 912 913 913 def view_html(model_name): 914 from . import rst2html915 914 from . import modelinfo 916 915 kernel_module = load_kernel_module(model_name) 917 916 info = modelinfo.make_model_info(kernel_module) 917 view_html_from_info(info) 918 919 def view_html_from_info(info): 920 from . import rst2html 918 921 url = "file://"+dirname(info.filename)+"/" 919 922 rst2html.wxview(make_html(info), url=url) -
sasmodels/model_test.py
r897ca7f r1a6cd57 121 121 122 122 # test using dll if desired 123 if 'dll' in loaders :123 if 'dll' in loaders or not core.HAVE_OPENCL: 124 124 test_name = "Model: %s, Kernel: dll"%model_name 125 125 test_method_name = "test_%s_dll" % model_info.id … … 270 270 271 271 # Build a test suite containing just the model 272 loaders = ['opencl'] 272 loaders = ['opencl'] if core.HAVE_OPENCL else ['dll'] 273 273 models = [model] 274 274 try: … … 288 288 stream.writeln(tb) 289 289 290 # Check if there are user defined tests. 291 # Yes, it is naughty to peek into the structure of the test suite, and 292 # to assume that it contains only one test. 293 if not suite._tests[0].info.tests: 294 stream.writeln("Note: %s has no user defined tests."%model) 290 # Warn if there are no user defined tests. 291 # Note: the test suite constructed above only has one test in it, which 292 # runs through some smoke tests to make sure the model runs, then runs 293 # through the input-output pairs given in the model definition file. To 294 # check if any such pairs are defined, therefore, we just need to check if 295 # they are in the first test of the test suite. We do this with an 296 # iterator since we don't have direct access to the list of tests in the 297 # test suite. 298 for test in suite: 299 if not test.info.tests: 300 stream.writeln("Note: %s has no user defined tests."%model) 301 break 302 else: 303 stream.writeln("Note: no test suite created --- this should never happen") 295 304 296 305 … … 325 334 models = models[1:] 326 335 elif models and models[0] == 'opencl_and_dll': 327 loaders = ['opencl', 'dll'] 336 loaders = ['opencl', 'dll'] if core.HAVE_OPENCL else ['dll'] 328 337 models = models[1:] 329 338 else: 330 loaders = ['opencl', 'dll'] 339 loaders = ['opencl', 'dll'] if core.HAVE_OPENCL else ['dll'] 331 340 if not models: 332 341 print("""\ … … 357 366 Run "nosetests sasmodels" on the command line to invoke it. 358 367 """ 359 tests = make_suite(['opencl', 'dll'], ['all']) 368 loaders = ['opencl', 'dll'] if core.HAVE_OPENCL else ['dll'] 369 tests = make_suite(loaders, ['all']) 360 370 for test_i in tests: 361 yield test_i.run_all 371 # In order for nosetest to see the correct test name, need to set 372 # the description attribute of the returned function. Since we 373 # can't do this for the returned instance, wrap it in a lambda and 374 # set the description on the lambda. Otherwise we could just do: 375 # yield test_i.run_all 376 L = lambda: test_i.run_all() 377 L.description = test_i.test_name 378 yield L 362 379 363 380 -
sasmodels/models/core_shell_bicelle.py
r416f5c7 r1a6cd57 40 40 .. math:: 41 41 42 I(Q,\alpha) = \frac{\text{scale}}{V } \cdot42 I(Q,\alpha) = \frac{\text{scale}}{V_t} \cdot 43 43 F(Q,\alpha)^2 + \text{background} 44 44 -
sasmodels/models/multilayer_vesicle.py
r9a4811a r1a6cd57 5 5 This model is a trivial extension of the core_shell_sphere function to include 6 6 *N* shells where the core is filled with solvent and the shells are interleaved 7 with layers of solvent. For *N = 1*, this returns the same as the vesicle model. 8 The shell thicknessess and SLD are constant across all shells as expected for 7 with layers of solvent. For *N = 1*, this returns the same as the vesicle model, 8 except for the normalisation, which here is to outermost volume. 9 The shell thicknessess and SLD are constant for all shells as expected for 9 10 a multilayer vesicle. 10 11 … … 15 16 See the :ref:`core-shell-sphere` model for more documentation. 16 17 18 The 1D scattering intensity is calculated in the following way (Guinier, 1955) 19 20 .. math:: 21 22 P(q) = \frac{\text{scale.volfraction}}{V_t} F^2(q) + \text{background} 23 24 where 25 26 .. math:: 27 28 F(q) = (\rho_{shell}-\rho_{solv}) \sum_{i=1}^{n\_pairs} \left[ 29 3V(R_i)\frac{\sin(qR_i)-qR_i\cos(qR_i)}{(qR_i)^3} \\ 30 - 3V(R_i+t_s)\frac{\sin(q(R_i+t_s))-q(R_i+t_s)\cos(q(R_i+t_s))}{(q(R_i+t_s))^3} 31 \right] 32 33 34 where $R_i = r_c + (i-1)(t_s + t_w)$ 35 36 where $V_t$ is the volume of the whole particle, $V(R)$ is the volume of a sphere 37 of radius $R$, $r_c$ is the radius of the core, $\rho_{shell}$ is the scattering length 38 density of a shell, $\rho_{solv}$ is the scattering length density of the solvent. 39 40 17 41 The 2D scattering intensity is the same as 1D, regardless of the orientation 18 42 of the q vector which is defined as: … … 22 46 q = \sqrt{q_x^2 + q_y^2} 23 47 24 .. note: 25 The outer most radius 26 $radius + n_pairs * thicn_shell + (n_pairs - 1) * thick_solvent$ 27 is used as the effective radius for *S(Q)* when $P(Q) * S(Q)$ is applied. 48 49 The outer most radius 50 51 $radius + n\_pairs * thick\_shell + (n\_pairs- 1) * thick\_solvent$ 52 53 is used for both the volume fraction normalization and for the 54 effective radius for *S(Q)* when $P(Q) * S(Q)$ is applied. 28 55 29 56 For information about polarised and magnetic scattering, see … … 62 89 sld_solvent: solvent scattering length density 63 90 sld: shell scattering length density 64 n_pairs:number of pairs of water/shell91 n_pairs:number of "shell plus solvent" layer pairs 65 92 background: incoherent background 66 93 """ … … 71 98 parameters = [ 72 99 ["volfraction", "", 0.05, [0.0, 1], "", "volume fraction of vesicles"], 73 ["radius", "Ang", 60.0, [0.0, inf], "", " Core radius of the multishell"],74 ["thick_shell", "Ang", 10.0, [0.0, inf], "", " Shell thickness"],75 ["thick_solvent", "Ang", 10.0, [0.0, inf], "", " Water thickness"],76 ["sld_solvent", "1e-6/Ang^2", 6.4, [-inf, inf], "sld", " Corescattering length density"],100 ["radius", "Ang", 60.0, [0.0, inf], "", "radius of solvent filled core"], 101 ["thick_shell", "Ang", 10.0, [0.0, inf], "", "thickness of one shell"], 102 ["thick_solvent", "Ang", 10.0, [0.0, inf], "", "solvent thickness between shells"], 103 ["sld_solvent", "1e-6/Ang^2", 6.4, [-inf, inf], "sld", "solvent scattering length density"], 77 104 ["sld", "1e-6/Ang^2", 0.4, [-inf, inf], "sld", "Shell scattering length density"], 78 ["n_pairs", "", 2.0, [1.0, inf], "", "Number of pairs of water and shell"],105 ["n_pairs", "", 2.0, [1.0, inf], "", "Number of shell plus solvent layer pairs"], 79 106 ] 80 107 # pylint: enable=bad-whitespace, line-too-long -
sasmodels/models/vesicle.py
r42356c8 r1a6cd57 75 75 thickness: the shell thickness 76 76 sld: the shell SLD 77 sld_s lovent: the solvent (and core) SLD77 sld_solvent: the solvent (and core) SLD 78 78 background: incoherent background 79 79 volfraction: shell volume fraction -
sasmodels/sasview_model.py
r5b37fd6 r1a6cd57 115 115 Load a custom model given the model path. 116 116 """ 117 #print("load custom", path)118 117 kernel_module = custom.load_custom_kernel_module(path) 119 118 try: … … 124 123 if model.name == "": 125 124 model.name = splitext(basename(path))[0] 125 if not hasattr(model, 'filename'): 126 model.filename = kernel_module.__file__ 127 # For old models, treat .pyc and .py files interchangeably. 128 # This is needed because of the Sum|Multi(p1,p2) types of models 129 # and the convoluted way in which they are created. 130 if model.filename.endswith(".py"): 131 logging.info("Loading %s as .pyc", model.filename) 132 model.filename = model.filename+'c' 133 if not hasattr(model, 'id'): 134 model.id = splitext(basename(model.filename))[0] 126 135 except AttributeError: 127 136 model_info = modelinfo.make_model_info(kernel_module) 128 137 model = _make_model_from_info(model_info) 138 139 # If a model name already exists and we are loading a different model, 140 # use the model file name as the model name. 141 if model.name in MODELS and not model.filename == MODELS[model.name].filename: 142 _previous_name = model.name 143 model.name = model.id 144 145 # If the new model name is still in the model list (for instance, 146 # if we put a cylinder.py in our plug-in directory), then append 147 # an identifier. 148 if model.name in MODELS and not model.filename == MODELS[model.name].filename: 149 model.name = model.id + '_user' 150 logging.info("Model %s already exists: using %s [%s]", _previous_name, model.name, model.filename) 151 129 152 MODELS[model.name] = model 130 153 return model … … 154 177 attrs = _generate_model_attributes(model_info) 155 178 attrs['__init__'] = __init__ 179 attrs['filename'] = model_info.filename 156 180 ConstructedModel = type(model_info.name, (SasviewModel,), attrs) # type: SasviewModelType 157 181 return ConstructedModel … … 311 335 else: 312 336 hidden = set() 337 if self._model_info.structure_factor: 338 hidden.add('scale') 339 hidden.add('background') 340 self._model_info.parameters.defaults['background'] = 0. 313 341 314 342 self._persistency_dict = {} … … 575 603 magnetic=is_magnetic) 576 604 calculator.release() 577 try: 578 self._model.release() 579 except: 580 pass 605 self._model.release() 581 606 return result 582 607 … … 659 684 return [self.multiplicity], [1.0] 660 685 else: 661 return [np.NaN], [1.0] 686 # For hidden parameters use the default value. 687 value = self._model_info.parameters.defaults.get(par.name, np.NaN) 688 return [value], [1.0] 662 689 elif par.polydisperse: 663 690 dis = self.dispersion[par.name] … … 680 707 cylinder = Cylinder() 681 708 return cylinder.evalDistribution([0.1, 0.1]) 709 710 def test_structure_factor(): 711 # type: () -> float 712 """ 713 Test that a sasview model (cylinder) can be run. 714 """ 715 Model = _make_standard_model('hardsphere') 716 model = Model() 717 value = model.evalDistribution([0.1, 0.1]) 718 if np.isnan(value): 719 raise ValueError("hardsphere returns null") 682 720 683 721 def test_rpa():
Note: See TracChangeset
for help on using the changeset viewer.