SasView / sasmodels

Package for calculation of small angle scattering models using OpenCL.
BSD 3-Clause "New" or "Revised" License
15 stars 27 forks source link

Allow pure python Fq for beta approximation. #570

Open pkienzle opened 1 year ago

pkienzle commented 1 year ago

Allow pure python F(q) functions such as the following:

def Fq(q, sld, sld_solvent, radius):
    """Calculate F(q), F^2(q) for sphere"""
    qr = q * radius
    sn, cn = sin(qr), cos(qr)
    with np.errstate(all='ignore'):
        bes = 3 * (sn - qr * cn) / qr ** 3 # may be 0/0 but we fix that next line
        bes[qr == 0] = 1
    fq = bes * (1e-2 * (sld - sld_solvent) * form_volume(radius))
    return fq, fq**2
Fq.vectorized = vectorized  # Fq accepts an array of q value

Test using:

python -m sasmodels.compare -pars -midq sphere@hardsphere,_spherepy@hardsphere radius_pd=0.1 structure_factor_mode=1
butlerpd commented 1 year ago

@yunliu01 and @smalex-z to speak with @pkienzle about this

butlerpd commented 1 year ago

Looks like it needs some unit tests.

wpotrzebowski commented 11 months ago

Not a priority for 6.0 but will be good to have