Index: sansmodels/src/sans/models/PearlNecklaceModel.py
===================================================================
--- sansmodels/src/sans/models/PearlNecklaceModel.py	(revision 38155f7a88cf7e01d157855b7498e2aa5718c3cd)
+++ sansmodels/src/sans/models/PearlNecklaceModel.py	(revision 38155f7a88cf7e01d157855b7498e2aa5718c3cd)
@@ -0,0 +1,174 @@
+#!/usr/bin/env python
+
+##############################################################################
+#	This software was developed by the University of Tennessee as part of the
+#	Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
+#	project funded by the US National Science Foundation.
+#
+#	If you use DANSE applications to do scientific research that leads to
+#	publication, we ask that you acknowledge the use of the software with the
+#	following sentence:
+#
+#	"This work benefited from DANSE software developed under NSF award DMR-0520547."
+#
+#	copyright 2008, University of Tennessee
+##############################################################################
+
+
+""" 
+Provide functionality for a C extension model
+
+:WARNING: THIS FILE WAS GENERATED BY WRAPPERGENERATOR.PY
+         DO NOT MODIFY THIS FILE, MODIFY c:\workspace\sans\trunk\sansmodels\src\sans\models\c_extensions\pearlnecklace.h
+         AND RE-RUN THE GENERATOR SCRIPT
+
+"""
+
+from sans.models.BaseComponent import BaseComponent
+from sans_extension.c_models import CPearlNecklaceModel
+import copy    
+
+def create_PearlNecklaceModel():
+    obj = PearlNecklaceModel()
+    #CPearlNecklaceModel.__init__(obj) is called by PearlNecklaceModel constructor
+    return obj
+
+class PearlNecklaceModel(CPearlNecklaceModel, BaseComponent):
+    """ 
+    Class that evaluates a PearlNecklaceModel model. 
+    This file was auto-generated from c:\workspace\sans\trunk\sansmodels\src\sans\models\c_extensions\pearlnecklace.h.
+    Refer to that file and the structure it contains
+    for details of the model.
+    List of default parameters:
+         scale           = 1.0 
+         radius          = 80.0 [A]
+         edge_separation = 350.0 [A]
+         thick_string    = 2.5 [A]
+         num_pearls      = 3.0 
+         sld_pearl       = 1e-006 [1/A^(2)]
+         sld_string      = 5e-006 [1/A^(2)]
+         sld_solv        = 5e-007 [1/A^(2)]
+         background      = 0.0 
+
+    """
+        
+    def __init__(self):
+        """ Initialization """
+        
+        # Initialize BaseComponent first, then sphere
+        BaseComponent.__init__(self)
+        #apply(CPearlNecklaceModel.__init__, (self,)) 
+        CPearlNecklaceModel.__init__(self)
+        
+        ## Name of the model
+        self.name = "PearlNecklaceModel"
+        ## Model description
+        self.description ="""Calculate form factor for Pearl Necklace Model
+		[Macromol. Symp. 2004, 211, 25-42]
+		Parameters:
+		background:background
+		scale: scale factor
+		sld_pearl: the SLD of the pearl spheres
+		sld_string: the SLD of the strings
+		sld_solv: the SLD of the solvent
+		num_pearls: number of the pearls
+		radius: the radius of a pearl
+		edge_separation: the length of sring segment; surface to surface
+		thick_string: thickness (ie, diameter) of the string"""
+       
+        ## Parameter details [units, min, max]
+        self.details = {}
+        self.details['scale'] = ['', None, None]
+        self.details['radius'] = ['[A]', None, None]
+        self.details['edge_separation'] = ['[A]', None, None]
+        self.details['thick_string'] = ['[A]', None, None]
+        self.details['num_pearls'] = ['', None, None]
+        self.details['sld_pearl'] = ['[1/A^(2)]', None, None]
+        self.details['sld_string'] = ['[1/A^(2)]', None, None]
+        self.details['sld_solv'] = ['[1/A^(2)]', None, None]
+        self.details['background'] = ['', None, None]
+
+        ## fittable parameters
+        self.fixed=['radius.width', 'edge_separation.width']
+        
+        ## non-fittable parameters
+        self.non_fittable = []
+        
+        ## parameters with orientation
+        self.orientation_params = []
+
+    def __setstate__(self, state):
+        """
+        restore the state of a model from pickle
+        """
+        self.__dict__, self.params, self.dispersion = state
+        
+    def __reduce_ex__(self, proto):
+        """
+        Overwrite the __reduce_ex__ of PyTypeObject *type call in the init of 
+        c model.
+        """
+        state = (self.__dict__, self.params, self.dispersion)
+        return (create_PearlNecklaceModel,tuple(), state, None, None)
+        
+    def clone(self):
+        """ Return a identical copy of self """
+        return self._clone(PearlNecklaceModel())   
+       	
+   
+    def run(self, x=0.0):
+        """ 
+        Evaluate the model
+        
+        :param x: input q, or [q,phi]
+        
+        :return: scattering function P(q)
+        
+        """
+        
+        return CPearlNecklaceModel.run(self, x)
+   
+    def runXY(self, x=0.0):
+        """ 
+        Evaluate the model in cartesian coordinates
+        
+        :param x: input q, or [qx, qy]
+        
+        :return: scattering function P(q)
+        
+        """
+        
+        return CPearlNecklaceModel.runXY(self, x)
+        
+    def evalDistribution(self, x=[]):
+        """ 
+        Evaluate the model in cartesian coordinates
+        
+        :param x: input q[], or [qx[], qy[]]
+        
+        :return: scattering function P(q[])
+        
+        """
+        return CPearlNecklaceModel.evalDistribution(self, x)
+        
+    def calculate_ER(self):
+        """ 
+        Calculate the effective radius for P(q)*S(q)
+        
+        :return: the value of the effective radius
+        
+        """       
+        return CPearlNecklaceModel.calculate_ER(self)
+        
+    def set_dispersion(self, parameter, dispersion):
+        """
+        Set the dispersion object for a model parameter
+        
+        :param parameter: name of the parameter [string]
+        :param dispersion: dispersion object of type DispersionModel
+        
+        """
+        return CPearlNecklaceModel.set_dispersion(self, parameter, dispersion.cdisp)
+        
+   
+# End of file
Index: sansmodels/src/sans/models/c_models/CPearlNecklaceModel.cpp
===================================================================
--- sansmodels/src/sans/models/c_models/CPearlNecklaceModel.cpp	(revision 38155f7a88cf7e01d157855b7498e2aa5718c3cd)
+++ sansmodels/src/sans/models/c_models/CPearlNecklaceModel.cpp	(revision 38155f7a88cf7e01d157855b7498e2aa5718c3cd)
@@ -0,0 +1,586 @@
+/**
+	This software was developed by the University of Tennessee as part of the
+	Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
+	project funded by the US National Science Foundation.
+
+	If you use DANSE applications to do scientific research that leads to
+	publication, we ask that you acknowledge the use of the software with the
+	following sentence:
+
+	"This work benefited from DANSE software developed under NSF award DMR-0520547."
+
+	copyright 2008, University of Tennessee
+ */
+
+/** CPearlNecklaceModel
+ *
+ * C extension 
+ *
+ * WARNING: THIS FILE WAS GENERATED BY WRAPPERGENERATOR.PY
+ *          DO NOT MODIFY THIS FILE, MODIFY pearlnecklace.h
+ *          AND RE-RUN THE GENERATOR SCRIPT
+ *
+ */
+#define NO_IMPORT_ARRAY
+#define PY_ARRAY_UNIQUE_SYMBOL PyArray_API_sans
+ 
+extern "C" {
+#include <Python.h>
+#include <arrayobject.h>
+#include "structmember.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <time.h>
+#include "pearlnecklace.h"
+}
+
+#include "models.hh"
+#include "dispersion_visitor.hh"
+
+/// Error object for raised exceptions
+static PyObject * CPearlNecklaceModelError = NULL;
+
+
+// Class definition
+typedef struct {
+    PyObject_HEAD
+    /// Parameters
+    PyObject * params;
+    /// Dispersion parameters
+    PyObject * dispersion;
+    /// Underlying model object
+    PearlNecklaceModel * model;
+    /// Log for unit testing
+    PyObject * log;
+} CPearlNecklaceModel;
+
+
+static void
+CPearlNecklaceModel_dealloc(CPearlNecklaceModel* self)
+{
+    Py_DECREF(self->params);
+    Py_DECREF(self->dispersion);
+    Py_DECREF(self->log);
+    delete self->model;
+    self->ob_type->tp_free((PyObject*)self);
+    
+
+}
+
+static PyObject *
+CPearlNecklaceModel_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+    CPearlNecklaceModel *self;
+    
+    self = (CPearlNecklaceModel *)type->tp_alloc(type, 0);
+   
+    return (PyObject *)self;
+}
+
+static int
+CPearlNecklaceModel_init(CPearlNecklaceModel *self, PyObject *args, PyObject *kwds)
+{
+    if (self != NULL) {
+    	
+    	// Create parameters
+        self->params = PyDict_New();
+        self->dispersion = PyDict_New();
+        self->model = new PearlNecklaceModel();
+        
+        // Initialize parameter dictionary
+        PyDict_SetItemString(self->params,"num_pearls",Py_BuildValue("d",3.000000000000));
+        PyDict_SetItemString(self->params,"scale",Py_BuildValue("d",1.000000000000));
+        PyDict_SetItemString(self->params,"thick_string",Py_BuildValue("d",2.500000000000));
+        PyDict_SetItemString(self->params,"sld_string",Py_BuildValue("d",0.000005000000));
+        PyDict_SetItemString(self->params,"edge_separation",Py_BuildValue("d",350.000000000000));
+        PyDict_SetItemString(self->params,"sld_pearl",Py_BuildValue("d",0.000001000000));
+        PyDict_SetItemString(self->params,"radius",Py_BuildValue("d",80.000000000000));
+        PyDict_SetItemString(self->params,"background",Py_BuildValue("d",0.000000000000));
+        PyDict_SetItemString(self->params,"sld_solv",Py_BuildValue("d",0.000000500000));
+        // Initialize dispersion / averaging parameter dict
+        DispersionVisitor* visitor = new DispersionVisitor();
+        PyObject * disp_dict;
+        disp_dict = PyDict_New();
+        self->model->radius.dispersion->accept_as_source(visitor, self->model->radius.dispersion, disp_dict);
+        PyDict_SetItemString(self->dispersion, "radius", disp_dict);
+        disp_dict = PyDict_New();
+        self->model->edge_separation.dispersion->accept_as_source(visitor, self->model->edge_separation.dispersion, disp_dict);
+        PyDict_SetItemString(self->dispersion, "edge_separation", disp_dict);
+
+
+         
+        // Create empty log
+        self->log = PyDict_New();
+        
+        
+
+    }
+    return 0;
+}
+
+static PyMemberDef CPearlNecklaceModel_members[] = {
+    {"params", T_OBJECT, offsetof(CPearlNecklaceModel, params), 0,
+     "Parameters"},
+	{"dispersion", T_OBJECT, offsetof(CPearlNecklaceModel, dispersion), 0,
+	  "Dispersion parameters"},     
+    {"log", T_OBJECT, offsetof(CPearlNecklaceModel, log), 0,
+     "Log"},
+    {NULL}  /* Sentinel */
+};
+
+/** Read double from PyObject
+    @param p PyObject
+    @return double
+*/
+double CPearlNecklaceModel_readDouble(PyObject *p) {
+    if (PyFloat_Check(p)==1) {
+        return (double)(((PyFloatObject *)(p))->ob_fval);
+    } else if (PyInt_Check(p)==1) {
+        return (double)(((PyIntObject *)(p))->ob_ival);
+    } else if (PyLong_Check(p)==1) {
+        return (double)PyLong_AsLong(p);
+    } else {
+        return 0.0;
+    }
+}
+/**
+ * Function to call to evaluate model
+ * @param args: input numpy array q[] 
+ * @return: numpy array object 
+ */
+ 
+static PyObject *evaluateOneDim(PearlNecklaceModel* model, PyArrayObject *q){
+    PyArrayObject *result;
+   
+    // Check validity of array q , q must be of dimension 1, an array of double
+    if (q->nd != 1 || q->descr->type_num != PyArray_DOUBLE)
+    {
+        //const char * message= "Invalid array: q->nd=%d,type_num=%d\n",q->nd,q->descr->type_num;
+        //PyErr_SetString(PyExc_ValueError , message);
+        return NULL;
+    }
+    result = (PyArrayObject *)PyArray_FromDims(q->nd, (int *)(q->dimensions), 
+										  PyArray_DOUBLE);
+	if (result == NULL) {
+        const char * message= "Could not create result ";
+        PyErr_SetString(PyExc_RuntimeError , message);
+		return NULL;
+	}
+	 for (int i = 0; i < q->dimensions[0]; i++){
+      double q_value  = *(double *)(q->data + i*q->strides[0]);
+      double *result_value = (double *)(result->data + i*result->strides[0]);
+      *result_value =(*model)(q_value);
+	}
+    return PyArray_Return(result); 
+ }
+
+ /**
+ * Function to call to evaluate model
+ * @param args: input numpy array  [x[],y[]]
+ * @return: numpy array object 
+ */
+ static PyObject * evaluateTwoDimXY( PearlNecklaceModel* model, 
+                              PyArrayObject *x, PyArrayObject *y)
+ {
+    PyArrayObject *result;
+    int i,j, x_len, y_len, dims[1];
+    //check validity of input vectors
+    if (x->nd != 1 || x->descr->type_num != PyArray_DOUBLE
+        || y->nd != 1 || y->descr->type_num != PyArray_DOUBLE
+        || y->dimensions[0] != x->dimensions[0]){
+        const char * message= "evaluateTwoDimXY  expect 2 numpy arrays";
+        PyErr_SetString(PyExc_ValueError , message); 
+        return NULL;
+    }
+   
+	if (PyArray_Check(x) && PyArray_Check(y)) {
+		
+	    x_len = dims[0]= x->dimensions[0];
+        y_len = dims[0]= y->dimensions[0];
+	    
+	    // Make a new double matrix of same dims
+        result=(PyArrayObject *) PyArray_FromDims(1,dims,NPY_DOUBLE);
+        if (result == NULL){
+	    const char * message= "Could not create result ";
+        PyErr_SetString(PyExc_RuntimeError , message);
+	    return NULL;
+	    }
+       
+        /* Do the calculation. */
+        for ( i=0; i< x_len; i++) {
+            double x_value = *(double *)(x->data + i*x->strides[0]);
+  		    double y_value = *(double *)(y->data + i*y->strides[0]);
+  			double *result_value = (double *)(result->data +
+  			      i*result->strides[0]);
+  			*result_value = (*model)(x_value, y_value);
+        }           
+        return PyArray_Return(result); 
+        
+        }else{
+		    PyErr_SetString(CPearlNecklaceModelError, 
+                   "CPearlNecklaceModel.evaluateTwoDimXY couldn't run.");
+	        return NULL;
+		}      	
+}
+/**
+ *  evalDistribution function evaluate a model function with input vector
+ *  @param args: input q as vector or [qx, qy] where qx, qy are vectors
+ *
+ */ 
+static PyObject * evalDistribution(CPearlNecklaceModel *self, PyObject *args){
+	PyObject *qx, *qy;
+	PyArrayObject * pars;
+	int npars ,mpars;
+	
+	// Get parameters
+	
+	    // Reader parameter dictionary
+    self->model->num_pearls = PyFloat_AsDouble( PyDict_GetItemString(self->params, "num_pearls") );
+    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
+    self->model->thick_string = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_string") );
+    self->model->sld_string = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_string") );
+    self->model->edge_separation = PyFloat_AsDouble( PyDict_GetItemString(self->params, "edge_separation") );
+    self->model->sld_pearl = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_pearl") );
+    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
+    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
+    self->model->sld_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solv") );
+    // Read in dispersion parameters
+    PyObject* disp_dict;
+    DispersionVisitor* visitor = new DispersionVisitor();
+    disp_dict = PyDict_GetItemString(self->dispersion, "radius");
+    self->model->radius.dispersion->accept_as_destination(visitor, self->model->radius.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "edge_separation");
+    self->model->edge_separation.dispersion->accept_as_destination(visitor, self->model->edge_separation.dispersion, disp_dict);
+
+	
+	// Get input and determine whether we have to supply a 1D or 2D return value.
+	if ( !PyArg_ParseTuple(args,"O",&pars) ) {
+	    PyErr_SetString(CPearlNecklaceModelError, 
+	    	"CPearlNecklaceModel.evalDistribution expects a q value.");
+		return NULL;
+	}
+    // Check params
+	
+    if(PyArray_Check(pars)==1) {
+		
+	    // Length of list should 1 or 2
+	    npars = pars->nd; 
+	    if(npars==1) {
+	        // input is a numpy array
+	        if (PyArray_Check(pars)) {
+		        return evaluateOneDim(self->model, (PyArrayObject*)pars); 
+		    }
+		}else{
+		    PyErr_SetString(CPearlNecklaceModelError, 
+                   "CPearlNecklaceModel.evalDistribution expect numpy array of one dimension.");
+	        return NULL;
+		}
+    }else if( PyList_Check(pars)==1) {
+    	// Length of list should be 2 for I(qx,qy)
+	    mpars = PyList_GET_SIZE(pars); 
+	    if(mpars!=2) {
+	    	PyErr_SetString(CPearlNecklaceModelError, 
+	    		"CPearlNecklaceModel.evalDistribution expects a list of dimension 2.");
+	    	return NULL;
+	    }
+	     qx = PyList_GET_ITEM(pars,0);
+	     qy = PyList_GET_ITEM(pars,1);
+	     if (PyArray_Check(qx) && PyArray_Check(qy)) {
+	         return evaluateTwoDimXY(self->model, (PyArrayObject*)qx,
+		           (PyArrayObject*)qy);
+		 }else{
+		    PyErr_SetString(CPearlNecklaceModelError, 
+                   "CPearlNecklaceModel.evalDistribution expect 2 numpy arrays in list.");
+	        return NULL;
+	     }
+	}
+	PyErr_SetString(CPearlNecklaceModelError, 
+                   "CPearlNecklaceModel.evalDistribution couln't be run.");
+	return NULL;
+	
+}
+
+/**
+ * Function to call to evaluate model
+ * @param args: input q or [q,phi]
+ * @return: function value
+ */
+static PyObject * run(CPearlNecklaceModel *self, PyObject *args) {
+	double q_value, phi_value;
+	PyObject* pars;
+	int npars;
+	
+	// Get parameters
+	
+	    // Reader parameter dictionary
+    self->model->num_pearls = PyFloat_AsDouble( PyDict_GetItemString(self->params, "num_pearls") );
+    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
+    self->model->thick_string = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_string") );
+    self->model->sld_string = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_string") );
+    self->model->edge_separation = PyFloat_AsDouble( PyDict_GetItemString(self->params, "edge_separation") );
+    self->model->sld_pearl = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_pearl") );
+    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
+    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
+    self->model->sld_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solv") );
+    // Read in dispersion parameters
+    PyObject* disp_dict;
+    DispersionVisitor* visitor = new DispersionVisitor();
+    disp_dict = PyDict_GetItemString(self->dispersion, "radius");
+    self->model->radius.dispersion->accept_as_destination(visitor, self->model->radius.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "edge_separation");
+    self->model->edge_separation.dispersion->accept_as_destination(visitor, self->model->edge_separation.dispersion, disp_dict);
+
+	
+	// Get input and determine whether we have to supply a 1D or 2D return value.
+	if ( !PyArg_ParseTuple(args,"O",&pars) ) {
+	    PyErr_SetString(CPearlNecklaceModelError, 
+	    	"CPearlNecklaceModel.run expects a q value.");
+		return NULL;
+	}
+	  
+	// Check params
+	if( PyList_Check(pars)==1) {
+		
+		// Length of list should be 2 for I(q,phi)
+	    npars = PyList_GET_SIZE(pars); 
+	    if(npars!=2) {
+	    	PyErr_SetString(CPearlNecklaceModelError, 
+	    		"CPearlNecklaceModel.run expects a double or a list of dimension 2.");
+	    	return NULL;
+	    }
+	    // We have a vector q, get the q and phi values at which
+	    // to evaluate I(q,phi)
+	    q_value = CPearlNecklaceModel_readDouble(PyList_GET_ITEM(pars,0));
+	    phi_value = CPearlNecklaceModel_readDouble(PyList_GET_ITEM(pars,1));
+	    // Skip zero
+	    if (q_value==0) {
+	    	return Py_BuildValue("d",0.0);
+	    }
+		return Py_BuildValue("d",(*(self->model)).evaluate_rphi(q_value,phi_value));
+
+	} else {
+
+		// We have a scalar q, we will evaluate I(q)
+		q_value = CPearlNecklaceModel_readDouble(pars);		
+		
+		return Py_BuildValue("d",(*(self->model))(q_value));
+	}	
+}
+/**
+ * Function to call to calculate_ER
+ * @return: effective radius value 
+ */
+static PyObject * calculate_ER(CPearlNecklaceModel *self) {
+
+	PyObject* pars;
+	int npars;
+	
+	// Get parameters
+	
+	    // Reader parameter dictionary
+    self->model->num_pearls = PyFloat_AsDouble( PyDict_GetItemString(self->params, "num_pearls") );
+    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
+    self->model->thick_string = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_string") );
+    self->model->sld_string = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_string") );
+    self->model->edge_separation = PyFloat_AsDouble( PyDict_GetItemString(self->params, "edge_separation") );
+    self->model->sld_pearl = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_pearl") );
+    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
+    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
+    self->model->sld_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solv") );
+    // Read in dispersion parameters
+    PyObject* disp_dict;
+    DispersionVisitor* visitor = new DispersionVisitor();
+    disp_dict = PyDict_GetItemString(self->dispersion, "radius");
+    self->model->radius.dispersion->accept_as_destination(visitor, self->model->radius.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "edge_separation");
+    self->model->edge_separation.dispersion->accept_as_destination(visitor, self->model->edge_separation.dispersion, disp_dict);
+
+		
+	return Py_BuildValue("d",(*(self->model)).calculate_ER());
+
+}
+/**
+ * Function to call to evaluate model in cartesian coordinates
+ * @param args: input q or [qx, qy]]
+ * @return: function value
+ */
+static PyObject * runXY(CPearlNecklaceModel *self, PyObject *args) {
+	double qx_value, qy_value;
+	PyObject* pars;
+	int npars;
+	
+	// Get parameters
+	
+	    // Reader parameter dictionary
+    self->model->num_pearls = PyFloat_AsDouble( PyDict_GetItemString(self->params, "num_pearls") );
+    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
+    self->model->thick_string = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thick_string") );
+    self->model->sld_string = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_string") );
+    self->model->edge_separation = PyFloat_AsDouble( PyDict_GetItemString(self->params, "edge_separation") );
+    self->model->sld_pearl = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_pearl") );
+    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
+    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
+    self->model->sld_solv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solv") );
+    // Read in dispersion parameters
+    PyObject* disp_dict;
+    DispersionVisitor* visitor = new DispersionVisitor();
+    disp_dict = PyDict_GetItemString(self->dispersion, "radius");
+    self->model->radius.dispersion->accept_as_destination(visitor, self->model->radius.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "edge_separation");
+    self->model->edge_separation.dispersion->accept_as_destination(visitor, self->model->edge_separation.dispersion, disp_dict);
+
+	
+	// Get input and determine whether we have to supply a 1D or 2D return value.
+	if ( !PyArg_ParseTuple(args,"O",&pars) ) {
+	    PyErr_SetString(CPearlNecklaceModelError, 
+	    	"CPearlNecklaceModel.run expects a q value.");
+		return NULL;
+	}
+	  
+	// Check params
+	if( PyList_Check(pars)==1) {
+		
+		// Length of list should be 2 for I(qx, qy))
+	    npars = PyList_GET_SIZE(pars); 
+	    if(npars!=2) {
+	    	PyErr_SetString(CPearlNecklaceModelError, 
+	    		"CPearlNecklaceModel.run expects a double or a list of dimension 2.");
+	    	return NULL;
+	    }
+	    // We have a vector q, get the qx and qy values at which
+	    // to evaluate I(qx,qy)
+	    qx_value = CPearlNecklaceModel_readDouble(PyList_GET_ITEM(pars,0));
+	    qy_value = CPearlNecklaceModel_readDouble(PyList_GET_ITEM(pars,1));
+	    return Py_BuildValue("d",(*(self->model))(qx_value,qy_value));
+
+	} else {
+
+		// We have a scalar q, we will evaluate I(q)
+		qx_value = CPearlNecklaceModel_readDouble(pars);		
+		
+		return Py_BuildValue("d",(*(self->model))(qx_value));
+	}	
+}
+
+static PyObject * reset(CPearlNecklaceModel *self, PyObject *args) {
+    
+
+    return Py_BuildValue("d",0.0);
+}
+
+static PyObject * set_dispersion(CPearlNecklaceModel *self, PyObject *args) {
+	PyObject * disp;
+	const char * par_name;
+
+	if ( !PyArg_ParseTuple(args,"sO", &par_name, &disp) ) {
+	    PyErr_SetString(CPearlNecklaceModelError,
+	    	"CPearlNecklaceModel.set_dispersion expects a DispersionModel object.");
+		return NULL;
+	}
+	void *temp = PyCObject_AsVoidPtr(disp);
+	DispersionModel * dispersion = static_cast<DispersionModel *>(temp);
+
+
+	// Ugliness necessary to go from python to C
+	    // TODO: refactor this
+    if (!strcmp(par_name, "radius")) {
+        self->model->radius.dispersion = dispersion;
+    } else    if (!strcmp(par_name, "edge_separation")) {
+        self->model->edge_separation.dispersion = dispersion;
+    } else {
+	    PyErr_SetString(CPearlNecklaceModelError,
+	    	"CPearlNecklaceModel.set_dispersion expects a valid parameter name.");
+		return NULL;
+	}
+
+	DispersionVisitor* visitor = new DispersionVisitor();
+	PyObject * disp_dict = PyDict_New();
+	dispersion->accept_as_source(visitor, dispersion, disp_dict);
+	PyDict_SetItemString(self->dispersion, par_name, disp_dict);
+    return Py_BuildValue("i",1);
+}
+
+
+static PyMethodDef CPearlNecklaceModel_methods[] = {
+    {"run",      (PyCFunction)run     , METH_VARARGS,
+      "Evaluate the model at a given Q or Q, phi"},
+    {"runXY",      (PyCFunction)runXY     , METH_VARARGS,
+      "Evaluate the model at a given Q or Qx, Qy"},
+    {"calculate_ER",      (PyCFunction)calculate_ER     , METH_VARARGS,
+      "Evaluate the model at a given Q or Q, phi"},
+      
+    {"evalDistribution",  (PyCFunction)evalDistribution , METH_VARARGS,
+      "Evaluate the model at a given Q or Qx, Qy vector "},
+    {"reset",    (PyCFunction)reset   , METH_VARARGS,
+      "Reset pair correlation"},
+    {"set_dispersion",      (PyCFunction)set_dispersion     , METH_VARARGS,
+      "Set the dispersion model for a given parameter"},
+   {NULL}
+};
+
+static PyTypeObject CPearlNecklaceModelType = {
+    PyObject_HEAD_INIT(NULL)
+    0,                         /*ob_size*/
+    "CPearlNecklaceModel",             /*tp_name*/
+    sizeof(CPearlNecklaceModel),             /*tp_basicsize*/
+    0,                         /*tp_itemsize*/
+    (destructor)CPearlNecklaceModel_dealloc, /*tp_dealloc*/
+    0,                         /*tp_print*/
+    0,                         /*tp_getattr*/
+    0,                         /*tp_setattr*/
+    0,                         /*tp_compare*/
+    0,                         /*tp_repr*/
+    0,                         /*tp_as_number*/
+    0,                         /*tp_as_sequence*/
+    0,                         /*tp_as_mapping*/
+    0,                         /*tp_hash */
+    0,                         /*tp_call*/
+    0,                         /*tp_str*/
+    0,                         /*tp_getattro*/
+    0,                         /*tp_setattro*/
+    0,                         /*tp_as_buffer*/
+    Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
+    "CPearlNecklaceModel objects",           /* tp_doc */
+    0,		               /* tp_traverse */
+    0,		               /* tp_clear */
+    0,		               /* tp_richcompare */
+    0,		               /* tp_weaklistoffset */
+    0,		               /* tp_iter */
+    0,		               /* tp_iternext */
+    CPearlNecklaceModel_methods,             /* tp_methods */
+    CPearlNecklaceModel_members,             /* tp_members */
+    0,                         /* tp_getset */
+    0,                         /* tp_base */
+    0,                         /* tp_dict */
+    0,                         /* tp_descr_get */
+    0,                         /* tp_descr_set */
+    0,                         /* tp_dictoffset */
+    (initproc)CPearlNecklaceModel_init,      /* tp_init */
+    0,                         /* tp_alloc */
+    CPearlNecklaceModel_new,                 /* tp_new */
+};
+
+
+//static PyMethodDef module_methods[] = {
+//    {NULL} 
+//};
+
+/**
+ * Function used to add the model class to a module
+ * @param module: module to add the class to
+ */ 
+void addCPearlNecklaceModel(PyObject *module) {
+	PyObject *d;
+	
+    if (PyType_Ready(&CPearlNecklaceModelType) < 0)
+        return;
+
+    Py_INCREF(&CPearlNecklaceModelType);
+    PyModule_AddObject(module, "CPearlNecklaceModel", (PyObject *)&CPearlNecklaceModelType);
+    
+    d = PyModule_GetDict(module);
+    CPearlNecklaceModelError = PyErr_NewException("CPearlNecklaceModel.error", NULL, NULL);
+    PyDict_SetItemString(d, "CPearlNecklaceModelError", CPearlNecklaceModelError);
+}
+
