Changeset 2ead7e2 in sasmodels for sasmodels


Ignore:
Timestamp:
Sep 5, 2017 10:08:03 AM (7 years ago)
Author:
GitHub <noreply@…>
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
142a8e2
Parents:
573ffab (diff), 133103b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
Paul Butler <butlerpd@…> (09/05/17 10:08:03)
git-committer:
GitHub <noreply@…> (09/05/17 10:08:03)
Message:

Merge pull request #47 from rprospero/sesans_tof

Sesans tof

Location:
sasmodels
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/sesans.py

    r94d13f1 r9f91afe  
    4141    _H0 = None # type: np.ndarray 
    4242 
    43     def __init__(self, z, SElength, zaccept, Rmax): 
     43    def __init__(self, z, SElength, lam, zaccept, Rmax): 
    4444        # type: (np.ndarray, float, float) -> None 
    4545        #import logging; logging.info("creating SESANS transform") 
    4646        self.q = z 
    47         self._set_hankel(SElength, zaccept, Rmax) 
     47        self._set_hankel(SElength, lam, zaccept, Rmax) 
    4848 
    4949    def apply(self, Iq): 
     
    5454        return P 
    5555 
    56     def _set_hankel(self, SElength, zaccept, Rmax): 
     56    def _set_hankel(self, SElength, lam, zaccept, Rmax): 
    5757        # type: (np.ndarray, float, float) -> None 
    5858        # Force float32 arrays, otherwise run into memory problems on some machines 
     
    7171        H = np.float32(dq/(2*pi)) * j0(repSE*repq) * repq 
    7272 
     73        replam = np.tile(lam, (q.size, 1)) 
     74        reptheta = np.arcsin(repq*replam/2*np.pi) 
     75        mask = reptheta > zaccept 
     76        H[mask] = 0 
     77 
    7378        self.q_calc = q 
    7479        self._H, self._H0 = H, H0 
  • sasmodels/alignment.py

    r7ae2b7f r870a2f4  
    4242    view[:] = x 
    4343    return view 
    44  
  • sasmodels/core.py

    r650c6d2 r2e66ef5  
    117117    Load model info and build model. 
    118118 
    119     *model_name* is the name of the model as used by :func:`load_model_info`. 
    120     Additional keyword arguments are passed directly to :func:`build_model`. 
     119    *model_name* is the name of the model, or perhaps a model expression 
     120    such as sphere*hardsphere or sphere+cylinder. 
     121 
     122    *dtype* and *platform* are given by :func:`build_model`. 
    121123    """ 
    122124    return build_model(load_model_info(model_name), 
     
    128130    """ 
    129131    Load a model definition given the model name. 
     132 
     133    *model_name* is the name of the model, or perhaps a model expression 
     134    such as sphere*hardsphere or sphere+cylinder. 
    130135 
    131136    This returns a handle to the module defining the model.  This can be 
     
    227232 
    228233    Possible types include 'half', 'single', 'double' and 'quad'.  If the 
    229     type is 'fast', then this is equivalent to dtype 'single' with the 
    230     fast flag set to True. 
     234    type is 'fast', then this is equivalent to dtype 'single' but using 
     235    fast native functions rather than those with the precision level guaranteed 
     236    by the OpenCL standard. 
     237 
     238    Platform preference can be specfied ("ocl" vs "dll"), with the default 
     239    being OpenCL if it is availabe.  If the dtype name ends with '!' then 
     240    platform is forced to be DLL rather than OpenCL. 
     241 
     242    This routine ignores the preferences within the model definition.  This 
     243    is by design.  It allows us to test models in single precision even when 
     244    we have flagged them as requiring double precision so we can easily check 
     245    the performance on different platforms without having to change the model 
     246    definition. 
    231247    """ 
    232248    # Assign default platform, overriding ocl with dll if OpenCL is unavailable 
  • sasmodels/generate.py

    rbb4b509 r573ffab  
    210210 
    211211# Conversion from units defined in the parameter table for each model 
    212 # to units displayed in the sphinx documentation. 
     212# to units displayed in the sphinx documentation.  
     213# This section associates the unit with the macro to use to produce the LaTex 
     214# code.  The macro itself needs to be defined in sasmodels/doc/rst_prolog. 
     215# 
     216# NOTE: there is an RST_PROLOG at the end of this file which is NOT 
     217# used for the bundled documentation. Still as long as we are defining the macros 
     218# in two places any new addition should define the macro in both places.  
    213219RST_UNITS = { 
    214220    "Ang": "|Ang|", 
     
    216222    "1/Ang^2": "|Ang^-2|", 
    217223    "Ang^3": "|Ang^3|", 
     224    "Ang^2": "|Ang^2|", 
    218225    "1e15/cm^3": "|1e15cm^3|", 
    219226    "Ang^3/mol": "|Ang^3|/mol", 
  • sasmodels/model_test.py

    rbb4b509 rbedb9b0  
    4747import sys 
    4848import unittest 
     49 
     50try: 
     51    from StringIO import StringIO 
     52except ImportError: 
     53    # StringIO.StringIO renamed to io.StringIO in Python 3 
     54    # Note: io.StringIO exists in python 2, but using unicode instead of str 
     55    from io import StringIO 
    4956 
    5057import numpy as np  # type: ignore 
     
    337344 
    338345def run_one(model): 
    339     # type: (str) -> None 
     346    # type: (str) -> str 
    340347    """ 
    341348    Run the tests for a single model, printing the results to stdout. 
     
    350357 
    351358    # Build a object to capture and print the test results 
    352     stream = _WritelnDecorator(sys.stdout)  # Add writeln() method to stream 
     359    stream = _WritelnDecorator(StringIO())  # Add writeln() method to stream 
    353360    verbosity = 2 
    354361    descriptions = True 
     
    388395    else: 
    389396        stream.writeln("Note: no test suite created --- this should never happen") 
     397 
     398    output = stream.getvalue() 
     399    stream.close() 
     400    return output 
    390401 
    391402 
  • sasmodels/models/multilayer_vesicle.py

    r5d23de2 r870a2f4  
    7171  sufficiently fine grained in certain cases. Please report any such occurences 
    7272  to the SasView team. Generally, for the best possible experience: 
    73  * Start with the best possible guess 
    74  * Using a priori knowledge, hold as many parameters fixed as possible 
    75  * if N=1, tw (water thickness) must by definition be zero. Both N and tw should 
     73 
     74 - Start with the best possible guess 
     75 - Using a priori knowledge, hold as many parameters fixed as possible 
     76 - if N=1, tw (water thickness) must by definition be zero. Both N and tw should 
    7677   be fixed during fitting. 
    77  * If N>1, use constraints to keep N > 1 
    78  * Because N only really moves in integer steps, it may get "stuck" if the 
     78 - If N>1, use constraints to keep N > 1 
     79 - Because N only really moves in integer steps, it may get "stuck" if the 
    7980   optimizer step size is too small so care should be taken 
    8081   If you experience problems with this please contact the SasView team and let 
  • sasmodels/models/star_polymer.py

    r40a87fa rd439007  
    11r""" 
    2 The Benoit model for a simple star polymer, with Gaussian coils arms from 
    3 a common point. 
    4  
    52Definition 
    63---------- 
     4 
     5Calcuates the scattering from a simple star polymer with f equal Gaussian coil 
     6arms. A star being defined as a branched polymer with all the branches 
     7emanating from a common central (in the case of this model) point.  It is 
     8derived as a special case of on the Benoit model for general branched 
     9polymers\ [#CITBenoit]_ as also used by Richter ''et. al.''\ [#CITRichter]_ 
    710 
    811For a star with $f$ arms the scattering intensity $I(q)$ is calculated as 
     
    1518where 
    1619 
    17 .. math:: v=\frac{u^2f}{(3f-2)} 
     20.. math:: v=\frac{uf}{(3f-2)} 
    1821 
    1922and 
     
    2124.. math:: u = \left\langle R_{g}^2\right\rangle q^2 
    2225 
    23 contains the square of the ensemble average radius-of-gyration of an arm. 
     26contains the square of the ensemble average radius-of-gyration of the full 
     27polymer while v contains the radius of gyration of a single arm $R_{arm}$. 
     28The two are related as: 
     29 
     30.. math:: R_{arm}^2 = \frac{f}{3f-2} R_{g}^2 
     31 
    2432Note that when there is only one arm, $f = 1$, the Debye Gaussian coil 
    25 equation is recovered. Star polymers in solutions tend to have strong 
    26 interparticle and osmotic effects, so the Benoit equation may not work well. 
    27 At small $q$ the Guinier term and hence $I(q=0)$ is the same as for $f$ arms 
    28 of radius of gyration $R_g$, as described for the :ref:`mono-gauss-coil` model. 
     33equation is recovered. 
     34 
     35.. note:: 
     36   Star polymers in solutions tend to have strong interparticle and osmotic 
     37   effects. Thus the Benoit equation may not work well for many real cases. 
     38   At small $q$ the Guinier term and hence $I(q=0)$ is the same as for $f$ arms 
     39   of radius of gyration $R_g$, as described for the :ref:`mono-gauss-coil` 
     40   model. A newer model for star polymer incorporating excluded volume has been 
     41   developed by Li et al in arXiv:1404.6269 [physics.chem-ph]. 
    2942 
    3043References 
    3144---------- 
    3245 
    33 H Benoit *J. Polymer Science*, 11, 596-599 (1953) 
     46.. [#CITBenoit] H Benoit *J. Polymer Science*, 11, 507-510 (1953) 
     47.. [#CITRichter] D Richter, B. Farago, J. S. Huang, L. J. Fetters, 
     48   B Ewen *Macromolecules*, 22, 468-472 (1989) 
     49 
     50Authorship and Verification 
     51---------------------------- 
     52 
     53* **Author:** Kieran Campbell **Date:** July 24, 2012 
     54* **Last Modified by:** Paul Butler **Date:** Auguts 26, 2017 
     55* **Last Reviewed by:** Ziang Li and Richard Heenan **Date:** May 17, 2017 
    3456""" 
    3557 
     
    4567        - v = u^2f/(3f-2) 
    4668        - u = <R_g^2>q^2, where <R_g^2> is the ensemble average radius of 
    47         gyration squared of an arm 
     69        gyration squared of the entire polymer 
    4870        - f is the number of arms on the star 
     71        - the radius of gyration of an arm is given b 
     72        Rg_arm^2 = R_g^2 * f/(3f-2) 
    4973        """ 
    5074category = "shape-independent" 
     
    5276# pylint: disable=bad-whitespace, line-too-long 
    5377#             ["name", "units", default, [lower, upper], "type","description"], 
    54 parameters = [["rg_squared", "Ang^2", 100.0, [0.0, inf], "", "Ensemble radius of gyration SQUARED of an arm"], 
     78parameters = [["rg_squared", "Ang^2", 100.0, [0.0, inf], "", "Ensemble radius of gyration SQUARED of the full polymer"], 
    5579              ["arms",    "",      3,   [1.0, 6.0], "", "Number of arms in the model"], 
    5680             ] 
  • sasmodels/resolution.py

    rb32caab r990d8df  
    437437    .. math:: 
    438438 
    439          \log \Delta q = (\log q_n - log q_1) / (n - 1) 
     439         \log \Delta q = (\log q_n - \log q_1) / (n - 1) 
    440440 
    441441    From this we can compute the number of steps required to extend $q$ 
     
    451451 
    452452         n_\text{extend} = (n-1) (\log q_\text{max} - \log q_n) 
    453             / (\log q_n - log q_1) 
     453            / (\log q_n - \log q_1) 
    454454    """ 
    455455    q = np.sort(q) 
     
    459459        log_delta_q = log(10.) / points_per_decade 
    460460    if q_min < q[0]: 
    461         if q_min < 0: q_min = q[0]*MINIMUM_ABSOLUTE_Q 
     461        if q_min < 0: 
     462            q_min = q[0]*MINIMUM_ABSOLUTE_Q 
    462463        n_low = log_delta_q * (log(q[0])-log(q_min)) 
    463464        q_low = np.logspace(log10(q_min), log10(q[0]), np.ceil(n_low)+1)[:-1] 
  • sasmodels/rst2html.py

    rf2f5413 r870a2f4  
    3838    - mathml 
    3939    - mathjax 
    40     See `http://docutils.sourceforge.net/docs/user/config.html#math-output`_ 
     40    See `<http://docutils.sourceforge.net/docs/user/config.html#math-output>`_ 
    4141    for details. 
    4242 
     
    176176        from PyQt5.QtCore import QUrl 
    177177    except ImportError: 
    178         from PyQt4.QtWebkit import QWebView 
     178        from PyQt4.QtWebKit import QWebView 
    179179        from PyQt4.QtCore import QUrl 
    180180    helpView = QWebView() 
     
    204204        from PyQt5.QtCore import QUrl 
    205205    except ImportError: 
    206         from PyQt4.QtWebkit import QWebView 
     206        from PyQt4.QtWebKit import QWebView 
    207207        from PyQt4.QtCore import QUrl 
    208208    frame = QWebView() 
     
    211211    sys.exit(app.exec_()) 
    212212 
     213def can_use_qt(): 
     214    """ 
     215    Return True if QWebView exists. 
     216 
     217    Checks first in PyQt5 then in PyQt4 
     218    """ 
     219    try: 
     220        from PyQt5.QtWebKitWidgets import QWebView 
     221        return True 
     222    except ImportError: 
     223        try: 
     224            from PyQt4.QtWebKit import QWebView 
     225            return True 
     226        except ImportError: 
     227            return False 
     228 
    213229def view_help(filename, qt=False): 
    214230    import os 
    215     url="file:///"+os.path.abspath(filename).replace("\\","/") 
     231 
     232    if qt: 
     233        qt = can_use_qt() 
     234 
     235    url = "file:///"+os.path.abspath(filename).replace("\\", "/") 
    216236    if filename.endswith('.rst'): 
    217237        html = load_rst_as_html(filename) 
Note: See TracChangeset for help on using the changeset viewer.