Changeset b3f6bc3 in sasmodels for sasmodels/generate.py


Ignore:
Timestamp:
Feb 15, 2015 4:07:00 PM (9 years ago)
Author:
pkienzle
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
f786ff3
Parents:
cb6ecf4
Message:

support pure python model Iq/Iqxy?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/generate.py

    rcb6ecf4 rb3f6bc3  
    354354""" 
    355355 
     356 
     357 
     358########################################################## 
     359#                                                        # 
     360#   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!   # 
     361#   !!                                              !!   # 
     362#   !!  KEEP THIS CODE CONSISTENT WITH PYKERNEL.PY  !!   # 
     363#   !!                                              !!   # 
     364#   !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!   # 
     365#                                                        # 
     366########################################################## 
     367 
     368 
    356369# Polydispersity loop body. 
    357370# This computes the weight, and if it is sufficient, calls the scattering 
     
    387400# to call the form_volume function from the user supplied kernel, and accumulate 
    388401# a normalized weight. 
    389 VOLUME_NORM="""const double vol_weight = %(weight)s; 
    390     vol += vol_weight*form_volume(%(pars)s); 
     402VOLUME_NORM="""const double vol_weight = %(vol_weight)s; 
     403    vol += vol_weight*form_volume(%(vol_pars)s); 
    391404    norm_vol += vol_weight;\ 
    392405""" 
     
    490503    if vol_pars: 
    491504        subst = { 
    492             'weight': "*".join(p+"_w" for p in vol_pars), 
    493             'pars': ", ".join(vol_pars), 
     505            'vol_weight': "*".join(p+"_w" for p in vol_pars), 
     506            'vol_pars': ", ".join(vol_pars), 
    494507            } 
    495508        volume_norm = VOLUME_NORM%subst 
     
    637650            } 
    638651        source.append(WORK_FUNCTION%subst) 
    639     kernel_Iq = make_kernel(info, is_2D=False) 
    640     kernel_Iqxy = make_kernel(info, is_2D=True) 
     652    kernel_Iq = make_kernel(info, is_2D=False) if not callable(info['Iq']) else "" 
     653    kernel_Iqxy = make_kernel(info, is_2D=True) if not callable(info['Iqxy']) else "" 
    641654    kernel = "\n\n".join([KERNEL_HEADER]+source+[kernel_Iq, kernel_Iqxy]) 
    642655    return kernel 
     
    718731def demo_time(): 
    719732    import datetime 
     733    from .models import cylinder 
     734    toc = lambda: (datetime.datetime.now()-tic).total_seconds() 
    720735    tic = datetime.datetime.now() 
    721     toc = lambda: (datetime.datetime.now()-tic).total_seconds() 
    722     path = os.path.dirname("__file__") 
    723     doc, c = make_model(os.path.join(path, "models", "cylinder.c")) 
     736    source, info = make(cylinder) 
    724737    print "time:",toc() 
    725738 
    726739def demo(): 
    727     from os.path import join as joinpath, dirname 
    728     c, info, doc = make_model(joinpath(dirname(__file__), "models", "cylinder.c")) 
    729     #print doc 
    730     #print c 
     740    from .models import cylinder 
     741    source, info = make(cylinder) 
     742    #print doc(cylinder) 
     743    print source 
    731744 
    732745if __name__ == "__main__": 
Note: See TracChangeset for help on using the changeset viewer.