Index: CylinderModel.py
===================================================================
--- CylinderModel.py	(revision ce27e213b076822e24ff35e97da5c4dd53eb45b0)
+++ CylinderModel.py	(revision 32c160aab45a38358aa878cf4622c2cec2d87725)
@@ -5,3 +5,4 @@
 """
 from sasmodels.sasview_model import make_class
-CylinderModel = make_class('cylinder_clone','CylinderModel')
+from sasmodels.models import cylinder_clone as cylinder
+CylinderModel = make_class(cylinder, dtype='single')
Index: sasmodels/core.py
===================================================================
--- sasmodels/core.py	(revision ce27e213b076822e24ff35e97da5c4dd53eb45b0)
+++ sasmodels/core.py	(revision 32c160aab45a38358aa878cf4622c2cec2d87725)
@@ -8,18 +8,10 @@
 import numpy as np
 
-def load_model(modelname):
-    from os.path import abspath, join as joinpath, dirname
-    from sasmodels import gen
-    modelpath = abspath(joinpath(dirname(gen.__file__), 'models',
-                                 modelname+'.c'))
-    return gen.make(modelpath)
-
-
-
-def opencl_model(modelname, dtype="single"):
-    from sasmodels import gpu
-
-    source, info, _ = load_model(modelname)
-    # for debugging, save source to a .cl file, edit it, and reload as model
+
+def opencl_model(kernel_module, dtype="single"):
+    from sasmodels import gen, gpu
+
+    source, info = gen.make(kernel_module)
+    ## for debugging, save source to a .cl file, edit it, and reload as model
     #open(modelname+'.cl','w').write(source)
     #source = open(modelname+'.cl','r').read()
@@ -42,16 +34,19 @@
 
 
-def dll_model(modelname):
+def dll_model(kernel_module):
     import os
-    from sasmodels import dll
-
-    source, info, _ = load_model(modelname)
+    import tempfile
+    from sasmodels import gen, dll
+
+    source, info = gen.make(kernel_module)
     dllpath = dll_path(info)
     if not os.path.exists(dllpath) \
             or (os.path.getmtime(dllpath) < os.path.getmtime(info['filename'])):
         # Replace with a proper temp file
-        srcfile = '/tmp/%s.c'%modelname
+        srcfile = tempfile.mkstemp(suffix=".c",prefix="sas_"+info['name'])
         open(srcfile, 'w').write(source)
         os.system(COMPILE%(srcfile, dllpath))
+        ## comment the following to keep the generated c file
+        #os.unlink(srcfile)
     return dll.DllModel(dllpath, info)
 
Index: sasmodels/gen.py
===================================================================
--- sasmodels/gen.py	(revision ce27e213b076822e24ff35e97da5c4dd53eb45b0)
+++ sasmodels/gen.py	(revision 32c160aab45a38358aa878cf4622c2cec2d87725)
@@ -316,43 +316,22 @@
     return "\n".join(lines)
 
-def make_doc(kernelfile, info, doc):
-    doc = doc%{'parameters': make_partable(info)}
-    return doc
-
-def make_model(kernelfile, info, source):
+def _search(search_path, filename):
+    """
+    Find *filename* in *search_path*.
+
+    Raises ValueError if file does not exist.
+    """
+    for path in search_path:
+        target = os.path.join(path, filename)
+        if os.path.exists(target):
+            return target
+    raise ValueError("%r not found in %s"%(filename, search_path))
+
+def make_model(search_path, info):
     kernel_Iq = make_kernel(info, is_2D=False)
     kernel_Iqxy = make_kernel(info, is_2D=True)
-    path = os.path.dirname(kernelfile)
-    extra = [open("%s/%s"%(path,f)).read() for f in info['include']]
-    kernel = "\n\n".join([KERNEL_HEADER]+extra+[source, kernel_Iq, kernel_Iqxy])
+    source = [open(_search(search_path, f)).read() for f in info['source']]
+    kernel = "\n\n".join([KERNEL_HEADER]+source+[kernel_Iq, kernel_Iqxy])
     return kernel
-
-def parse_file(kernelfile):
-    source = open(kernelfile).read()
-
-    # select parameters out of the source file
-    parts = source.split("PARAMETERS")
-    if len(parts) != 3:
-        raise ValueError("PARAMETERS block missing from %r"%kernelfile)
-    info_source = parts[1].strip()
-    try:
-        info = relaxed_loads(info_source)
-    except:
-        print "in json text:"
-        print "\n".join("%2d: %s"%(i+1,s)
-                        for i,s in enumerate(info_source.split('\n')))
-        raise
-        #raise ValueError("PARAMETERS block could not be parsed from %r"%kernelfile)
-
-    # select documentation out of the source file
-    parts = source.split("DOCUMENTATION")
-    if len(parts) == 3:
-        doc = make_doc(kernelfile, info, parts[1].strip())
-    elif len(parts) == 1:
-        raise ValueError("DOCUMENTATION block is missing from %r"%kernelfile)
-    else:
-        raise ValueError("DOCUMENTATION block incorrect from %r"%kernelfile)
-
-    return source, info, doc
 
 def categorize_parameters(pars):
@@ -408,5 +387,5 @@
     return partype
 
-def make(kernelfile):
+def make(kernel_module):
     """
     Build an OpenCL function from the source in *kernelfile*.
@@ -415,13 +394,25 @@
     will be a JSON definition containing
     """
+    # TODO: allow Iq and Iqxy to be defined in python
+    from os.path import abspath, dirname, join as joinpath
     #print kernelfile
-    source, info, doc = parse_file(kernelfile)
-    info['filename'] = kernelfile
-    info['parameters'] = COMMON_PARAMETERS + info['parameters']
+    info = dict(
+        filename = abspath(kernel_module.__file__),
+        name = kernel_module.name,
+        title = kernel_module.title,
+        source = kernel_module.source,
+        description = kernel_module.description,
+        parameters = COMMON_PARAMETERS + kernel_module.parameters,
+        ER = getattr(kernel_module, 'ER', None),
+        VR = getattr(kernel_module, 'VR', None),
+        )
+    info['limits'] = dict((p[0],p[3]) for p in info['parameters'])
     info['partype'] = categorize_parameters(info['parameters'])
-    info['limits'] = dict((p[0],p[3]) for p in info['parameters'])
-    doc = make_doc(kernelfile, info, doc)
-    model = make_model(kernelfile, info, source)
-    return model, info, doc
+
+    search_path = [ dirname(info['filename']),
+                    abspath(joinpath(dirname(__file__),'models')) ]
+    source = make_model(search_path, info)
+
+    return source, info
 
 
Index: sasmodels/models/cylinder.py
===================================================================
--- sasmodels/models/cylinder.py	(revision 32c160aab45a38358aa878cf4622c2cec2d87725)
+++ sasmodels/models/cylinder.py	(revision 32c160aab45a38358aa878cf4622c2cec2d87725)
@@ -0,0 +1,159 @@
+r"""
+CylinderModel
+=============
+
+This model provides the form factor for a right circular cylinder with uniform
+scattering length density. The form factor is normalized by the particle volume.
+
+For information about polarised and magnetic scattering, click here_.
+
+Definition
+----------
+
+The output of the 2D scattering intensity function for oriented cylinders is
+given by (Guinier, 1955)
+
+.. math::
+
+    P(q,\alpha) = \frac{\text{scale}}{V}f^2(q) + \text{bkg}
+
+where
+
+.. math::
+
+    f(q) = 2 (\Delta \rho) V
+           \frac{\sin (q L/2 \cos \alpha)}{q L/2 \cos \alpha}
+           \frac{J_1 (q r \sin \alpha)}{q r \sin \alpha}
+
+and $\alpha$ is the angle between the axis of the cylinder and $\vec q$, $V$
+is the volume of the cylinder, $L$ is the length of the cylinder, $r$ is the
+radius of the cylinder, and $d\rho$ (contrast) is the scattering length density
+difference between the scatterer and the solvent. $J_1$ is the first order
+Bessel function.
+
+To provide easy access to the orientation of the cylinder, we define the
+axis of the cylinder using two angles $\theta$ and $\phi$. Those angles
+are defined in Figure :num:`figure #CylinderModel-orientation`.
+
+.. _CylinderModel-orientation:
+
+.. figure:: img/image061.JPG
+
+    Definition of the angles for oriented cylinders.
+
+.. figure:: img/image062.JPG
+
+    Examples of the angles for oriented pp against the detector plane.
+
+NB: The 2nd virial coefficient of the cylinder is calculated based on the
+radius and length values, and used as the effective radius for $S(Q)$
+when $P(Q) \cdot S(Q)$ is applied.
+
+The returned value is scaled to units of |cm^-1| and the parameters of
+the CylinderModel are the following:
+
+%(parameters)s
+
+The output of the 1D scattering intensity function for randomly oriented
+cylinders is then given by
+
+.. math::
+
+    P(q) = \frac{\text{scale}}{V}
+        \int_0^{\pi/2} f^2(q,\alpha) \sin \alpha d\alpha + \text{background}
+
+The *theta* and *phi* parameters are not used for the 1D output. Our
+implementation of the scattering kernel and the 1D scattering intensity
+use the c-library from NIST.
+
+Validation of the CylinderModel
+-------------------------------
+
+Validation of our code was done by comparing the output of the 1D model
+to the output of the software provided by the NIST (Kline, 2006).
+Figure :num:`figure #CylinderModel-compare` shows a comparison of
+the 1D output of our model and the output of the NIST software.
+
+.. _CylinderModel-compare:
+
+.. figure:: img/image065.JPG
+
+    Comparison of the SasView scattering intensity for a cylinder with the
+    output of the NIST SANS analysis software.
+    The parameters were set to: *Scale* = 1.0, *Radius* = 20 |Ang|,
+    *Length* = 400 |Ang|, *Contrast* = 3e-6 |Ang^-2|, and
+    *Background* = 0.01 |cm^-1|.
+
+In general, averaging over a distribution of orientations is done by
+evaluating the following
+
+.. math::
+
+    P(q) = \int_0^{\pi/2} d\phi
+        \int_0^\pi p(\theta, \phi) P_0(q,\alpha) \sin \theta d\theta
+
+
+where $p(\theta,\phi)$ is the probability distribution for the orientation
+and $P_0(q,\alpha)$ is the scattering intensity for the fully oriented
+system. Since we have no other software to compare the implementation of
+the intensity for fully oriented cylinders, we can compare the result of
+averaging our 2D output using a uniform distribution $p(\theta, \phi) = 1.0$.
+Figure :num:`figure #CylinderModel-crosscheck` shows the result of
+such a cross-check.
+
+.. _CylinderModel-crosscheck:
+
+.. figure:: img/image066.JPG
+
+    Comparison of the intensity for uniformly distributed cylinders
+    calculated from our 2D model and the intensity from the NIST SANS
+    analysis software.
+    The parameters used were: *Scale* = 1.0, *Radius* = 20 |Ang|,
+    *Length* = 400 |Ang|, *Contrast* = 3e-6 |Ang^-2|, and
+    *Background* = 0.0 |cm^-1|.
+"""
+
+from numpy import pi, inf
+
+def ER(radius, length):
+    ddd = 0.75*radius*(2*radius*length + (length+radius)*(length+pi*radius))
+    return 0.5 * (ddd)**(1./3.)
+
+INFO = {
+    "name": "cylinder",
+    "title": "Cylinder with uniform scattering length density",
+    "source": [ "lib/J1.c", "lib/gauss76.c", "lib/cylkernel.c", "cylinder.c"],
+    "parameters": [
+    #   [ "name", "units", default, [lower, upper], "type",
+    #     "description" ],
+        [ "sld", "1e-6/Ang^2", 4, [-inf,inf], "",
+          "Cylinder scattering length density" ],
+        [ "solvent_sld", "1e-6/Ang^2", 1, [-inf,inf], "",
+          "Solvent scattering length density" ],
+        [ "radius", "Ang",  20, [0, inf], "volume",
+          "Cylinder radius" ],
+        [ "length", "Ang",  400, [0, inf], "volume",
+          "Cylinder length" ],
+        [ "theta", "degrees", 60, [-inf, inf], "orientation",
+          "In plane angle" ],
+        [ "phi", "degrees", 60, [-inf, inf], "orientation",
+          "Out of plane angle" ],
+        ],
+    "description": """
+         f(q)= 2*(sldCyl - sldSolv)*V*sin(qLcos(alpha/2))
+                /[qLcos(alpha/2)]*J1(qRsin(alpha/2))/[qRsin(alpha)]
+
+                P(q,alpha)= scale/V*f(q)^(2)+background
+                V: Volume of the cylinder
+                R: Radius of the cylinder
+                L: Length of the cylinder
+                J1: The bessel function
+                alpha: angle betweenthe axis of the
+                cylinder and the q-vector for 1D
+                :the ouput is P(q)=scale/V*integral
+                from pi/2 to zero of...
+                f(q)^(2)*sin(alpha)*dalpha+ bkg
+        """,
+    "ER": ER,
+    }
+
Index: sasmodels/models/cylinder_clone.c
===================================================================
--- sasmodels/models/cylinder_clone.c	(revision 1f21edfa7a55a09027b911fba80c71d4978cb876)
+++ sasmodels/models/cylinder_clone.c	(revision 32c160aab45a38358aa878cf4622c2cec2d87725)
@@ -1,148 +1,5 @@
-/* PARAMETERS
-{
-name: "CylinderModel",
-title: "Cylinder with uniform scattering length density",
-include: [ "lib/J1.c", "lib/gauss76.c", "lib/cylkernel.c"],
-parameters: [
-   // [ "name", "units", default, [lower, upper], "type", "description" ],
-   [ "sldCyl", "1e-6/Ang^2", 4e-6, [-Infinity,Infinity], "",
-     "Cylinder scattering length density" ],
-   [ "sldSolv", "1e-6/Ang^2", 1e-6, [-Infinity,Infinity], "",
-     "Solvent scattering length density" ],
-   [ "radius", "Ang",  20, [0, Infinity], "volume",
-     "Cylinder radius" ],
-   [ "length", "Ang",  400, [0, Infinity], "volume",
-     "Cylinder length" ],
-   [ "cyl_theta", "degrees", 60, [-Infinity, Infinity], "orientation",
-     "In plane angle" ],
-   [ "cyl_phi", "degrees", 60, [-Infinity, Infinity], "orientation",
-     "Out of plane angle" ],
-],
-description: "f(q)= 2*(sldCyl - sldSolv)*V*sin(qLcos(alpha/2))/[qLcos(alpha/2)]*J1(qRsin(alpha/2))/[qRsin(alpha)]",
-}
-PARAMETERS END
-
-DOCUMENTATION
-.. _CylinderModel:
-
-CylinderModel
-=============
-
-This model provides the form factor for a right circular cylinder with uniform
-scattering length density. The form factor is normalized by the particle volume.
-
-For information about polarised and magnetic scattering, click here_.
-
-Definition
-----------
-
-The output of the 2D scattering intensity function for oriented cylinders is
-given by (Guinier, 1955)
-
-.. math::
-
-    P(q,\alpha) = \frac{\text{scale}}{V}f^2(q) + \text{bkg}
-
-where
-
-.. math::
-
-    f(q) = 2 (\Delta \rho) V
-           \frac{\sin (q L/2 \cos \alpha)}{q L/2 \cos \alpha}
-           \frac{J_1 (q r \sin \alpha)}{q r \sin \alpha}
-
-and $\alpha$ is the angle between the axis of the cylinder and $\vec q$, $V$
-is the volume of the cylinder, $L$ is the length of the cylinder, $r$ is the
-radius of the cylinder, and $d\rho$ (contrast) is the scattering length density
-difference between the scatterer and the solvent. $J_1$ is the first order
-Bessel function.
-
-To provide easy access to the orientation of the cylinder, we define the
-axis of the cylinder using two angles $\theta$ and $\phi$. Those angles
-are defined in Figure :num:`figure #CylinderModel-orientation`.
-
-.. _CylinderModel-orientation:
-
-.. figure:: img/image061.JPG
-
-    Definition of the angles for oriented cylinders.
-
-.. figure:: img/image062.JPG
-
-    Examples of the angles for oriented pp against the detector plane.
-
-NB: The 2nd virial coefficient of the cylinder is calculated based on the
-radius and length values, and used as the effective radius for $S(Q)$
-when $P(Q) \cdot S(Q)$ is applied.
-
-The returned value is scaled to units of |cm^-1| and the parameters of
-the CylinderModel are the following:
-
-%(parameters)s
-
-The output of the 1D scattering intensity function for randomly oriented
-cylinders is then given by
-
-.. math::
-
-    P(q) = \frac{\text{scale}}{V}
-        \int_0^{\pi/2} f^2(q,\alpha) \sin \alpha d\alpha + \text{background}
-
-The *theta* and *phi* parameters are not used for the 1D output. Our
-implementation of the scattering kernel and the 1D scattering intensity
-use the c-library from NIST.
-
-Validation of the CylinderModel
--------------------------------
-
-Validation of our code was done by comparing the output of the 1D model
-to the output of the software provided by the NIST (Kline, 2006).
-Figure :num:`figure #CylinderModel-compare` shows a comparison of
-the 1D output of our model and the output of the NIST software.
-
-.. _CylinderModel-compare:
-
-.. figure:: img/image065.JPG
-
-    Comparison of the SasView scattering intensity for a cylinder with the
-    output of the NIST SANS analysis software.
-    The parameters were set to: *Scale* = 1.0, *Radius* = 20 |Ang|,
-    *Length* = 400 |Ang|, *Contrast* = 3e-6 |Ang^-2|, and
-    *Background* = 0.01 |cm^-1|.
-
-In general, averaging over a distribution of orientations is done by
-evaluating the following
-
-.. math::
-
-    P(q) = \int_0^{\pi/2} d\phi
-        \int_0^\pi p(\theta, \phi) P_0(q,\alpha) \sin \theta d\theta
-
-
-where $p(\theta,\phi)$ is the probability distribution for the orientation
-and $P_0(q,\alpha)$ is the scattering intensity for the fully oriented
-system. Since we have no other software to compare the implementation of
-the intensity for fully oriented cylinders, we can compare the result of
-averaging our 2D output using a uniform distribution $p(\theta, \phi) = 1.0$.
-Figure :num:`figure #CylinderModel-crosscheck` shows the result of
-such a cross-check.
-
-.. _CylinderModel-crosscheck:
-
-.. figure:: img/image066.JPG
-
-    Comparison of the intensity for uniformly distributed cylinders
-    calculated from our 2D model and the intensity from the NIST SANS
-    analysis software.
-    The parameters used were: *Scale* = 1.0, *Radius* = 20 |Ang|,
-    *Length* = 400 |Ang|, *Contrast* = 3e-6 |Ang^-2|, and
-    *Background* = 0.0 |cm^-1|.
-
-DOCUMENTATION END
-*/
 real form_volume(real radius, real length);
 real Iq(real q, real sld, real solvent_sld, real radius, real length);
 real Iqxy(real qx, real qy, real sld, real solvent_sld, real radius, real length, real theta, real phi);
-
 
 real form_volume(real radius, real length)
@@ -173,5 +30,4 @@
     return REAL(1.0e8) * form * s * s;
 }
-
 
 real Iqxy(real qx, real qy,
Index: sasmodels/models/cylinder_clone.py
===================================================================
--- sasmodels/models/cylinder_clone.py	(revision 32c160aab45a38358aa878cf4622c2cec2d87725)
+++ sasmodels/models/cylinder_clone.py	(revision 32c160aab45a38358aa878cf4622c2cec2d87725)
@@ -0,0 +1,156 @@
+r"""
+CylinderModel
+=============
+
+This model provides the form factor for a right circular cylinder with uniform
+scattering length density. The form factor is normalized by the particle volume.
+
+For information about polarised and magnetic scattering, click here_.
+
+Definition
+----------
+
+The output of the 2D scattering intensity function for oriented cylinders is
+given by (Guinier, 1955)
+
+.. math::
+
+    P(q,\alpha) = \frac{\text{scale}}{V}f^2(q) + \text{bkg}
+
+where
+
+.. math::
+
+    f(q) = 2 (\Delta \rho) V
+           \frac{\sin (q L/2 \cos \alpha)}{q L/2 \cos \alpha}
+           \frac{J_1 (q r \sin \alpha)}{q r \sin \alpha}
+
+and $\alpha$ is the angle between the axis of the cylinder and $\vec q$, $V$
+is the volume of the cylinder, $L$ is the length of the cylinder, $r$ is the
+radius of the cylinder, and $d\rho$ (contrast) is the scattering length density
+difference between the scatterer and the solvent. $J_1$ is the first order
+Bessel function.
+
+To provide easy access to the orientation of the cylinder, we define the
+axis of the cylinder using two angles $\theta$ and $\phi$. Those angles
+are defined in Figure :num:`figure #CylinderModel-orientation`.
+
+.. _CylinderModel-orientation:
+
+.. figure:: img/image061.JPG
+
+    Definition of the angles for oriented cylinders.
+
+.. figure:: img/image062.JPG
+
+    Examples of the angles for oriented pp against the detector plane.
+
+NB: The 2nd virial coefficient of the cylinder is calculated based on the
+radius and length values, and used as the effective radius for $S(Q)$
+when $P(Q) \cdot S(Q)$ is applied.
+
+The returned value is scaled to units of |cm^-1| and the parameters of
+the CylinderModel are the following:
+
+%(parameters)s
+
+The output of the 1D scattering intensity function for randomly oriented
+cylinders is then given by
+
+.. math::
+
+    P(q) = \frac{\text{scale}}{V}
+        \int_0^{\pi/2} f^2(q,\alpha) \sin \alpha d\alpha + \text{background}
+
+The *theta* and *phi* parameters are not used for the 1D output. Our
+implementation of the scattering kernel and the 1D scattering intensity
+use the c-library from NIST.
+
+Validation of the CylinderModel
+-------------------------------
+
+Validation of our code was done by comparing the output of the 1D model
+to the output of the software provided by the NIST (Kline, 2006).
+Figure :num:`figure #CylinderModel-compare` shows a comparison of
+the 1D output of our model and the output of the NIST software.
+
+.. _CylinderModel-compare:
+
+.. figure:: img/image065.JPG
+
+    Comparison of the SasView scattering intensity for a cylinder with the
+    output of the NIST SANS analysis software.
+    The parameters were set to: *Scale* = 1.0, *Radius* = 20 |Ang|,
+    *Length* = 400 |Ang|, *Contrast* = 3e-6 |Ang^-2|, and
+    *Background* = 0.01 |cm^-1|.
+
+In general, averaging over a distribution of orientations is done by
+evaluating the following
+
+.. math::
+
+    P(q) = \int_0^{\pi/2} d\phi
+        \int_0^\pi p(\theta, \phi) P_0(q,\alpha) \sin \theta d\theta
+
+
+where $p(\theta,\phi)$ is the probability distribution for the orientation
+and $P_0(q,\alpha)$ is the scattering intensity for the fully oriented
+system. Since we have no other software to compare the implementation of
+the intensity for fully oriented cylinders, we can compare the result of
+averaging our 2D output using a uniform distribution $p(\theta, \phi) = 1.0$.
+Figure :num:`figure #CylinderModel-crosscheck` shows the result of
+such a cross-check.
+
+.. _CylinderModel-crosscheck:
+
+.. figure:: img/image066.JPG
+
+    Comparison of the intensity for uniformly distributed cylinders
+    calculated from our 2D model and the intensity from the NIST SANS
+    analysis software.
+    The parameters used were: *Scale* = 1.0, *Radius* = 20 |Ang|,
+    *Length* = 400 |Ang|, *Contrast* = 3e-6 |Ang^-2|, and
+    *Background* = 0.0 |cm^-1|.
+"""
+
+from numpy import pi, inf
+
+name = "CylinderModel"
+title = "Cylinder with uniform scattering length density"
+source = [ "lib/J1.c", "lib/gauss76.c", "lib/cylkernel.c", "cylinder_clone.c"]
+parameters = [
+    #   [ "name", "units", default, [lower, upper], "type",
+    #     "description" ],
+    [ "sldCyl", "1/Ang^2", 4e-6, [-inf,inf], "",
+      "Cylinder scattering length density" ],
+    [ "sldSolv", "1/Ang^2", 1e-6, [-inf,inf], "",
+      "Solvent scattering length density" ],
+    [ "radius", "Ang",  20, [0, inf], "volume",
+      "Cylinder radius" ],
+    [ "length", "Ang",  400, [0, inf], "volume",
+      "Cylinder length" ],
+    [ "cyl_theta", "degrees", 60, [-inf, inf], "orientation",
+      "In plane angle" ],
+    [ "cyl_phi", "degrees", 60, [-inf, inf], "orientation",
+      "Out of plane angle" ],
+    ]
+description = """\
+         f(q)= 2*(sldCyl - sldSolv)*V*sin(qLcos(alpha/2))
+                /[qLcos(alpha/2)]*J1(qRsin(alpha/2))/[qRsin(alpha)]
+
+                P(q,alpha)= scale/V*f(q)^(2)+background
+                V: Volume of the cylinder
+                R: Radius of the cylinder
+                L: Length of the cylinder
+                J1: The bessel function
+                alpha: angle betweenthe axis of the
+                cylinder and the q-vector for 1D
+                :the ouput is P(q)=scale/V*integral
+                from pi/2 to zero of...
+                f(q)^(2)*sin(alpha)*dalpha+ bkg
+"""
+
+def ER(radius, length):
+    ddd = 0.75*radius*(2*radius*length + (length+radius)*(length+pi*radius))
+    return 0.5 * (ddd)**(1./3.)
+
Index: sasmodels/sasview_model.py
===================================================================
--- sasmodels/sasview_model.py	(revision 1780d5917f12726485d1b9b4d0343ac8454b6e34)
+++ sasmodels/sasview_model.py	(revision 32c160aab45a38358aa878cf4622c2cec2d87725)
@@ -4,14 +4,16 @@
 import numpy as np
 
-def make_class(name, class_name=None, dtype='single'):
+def make_class(kernel_module, dtype='single'):
     from .core import opencl_model
-    if class_name is None:
-        class_name = "".join(part.capitalize() for part in name.split('_')+['model'])
-    model =  opencl_model(name, dtype=dtype)
-    class ConstructedModel(SasviewModel):
-        kernel = model
-        def __init__(self, multfactor=1):
-            SasviewModel.__init__(self, self.kernel)
-    ConstructedModel.__name__ = class_name
+    model =  opencl_model(kernel_module, dtype=dtype)
+    def __init__(self, multfactor=1):
+        SasviewModel.__init__(self, self.kernel)
+    attrs = dict(__init__=__init__, kernel=model)
+    ConstructedModel = type(model.info['name'],  (SasviewModel,), attrs)
+    #class ConstructedModel(SasviewModel):
+    #    kernel = model
+    #    def __init__(self, multfactor=1):
+    #        SasviewModel.__init__(self, self.kernel)
+    #ConstructedModel.__name__ = model.info['name']
     return ConstructedModel
 
@@ -267,4 +269,5 @@
             values, weights = self._dispersion_mesh(vol_pars)
             fv = ER(*values)
+            #print values[0].shape, weights.shape, fv.shape
             return np.sum(weights*fv) / np.sum(weights)
 
@@ -275,5 +278,5 @@
         :return: the value of the volf ratio
         """
-        VR = self._model.info.get('ER', None)
+        VR = self._model.info.get('VR', None)
         if VR is None:
             return 1.0
@@ -323,5 +326,5 @@
         values = [v.flatten() for v in np.meshgrid(*values)]
         weights = np.vstack([v.flatten() for v in np.meshgrid(*weights)])
-        weights = np.prod(weights, axis=1)
+        weights = np.prod(weights, axis=0)
         return values, weights
 
