Index: sansmodels/src/sans/models/BCCrystalModel.py
===================================================================
--- sansmodels/src/sans/models/BCCrystalModel.py	(revision d5b6a9d7cd9e26b5f9e28e55e8cf848a40de6ae9)
+++ sansmodels/src/sans/models/BCCrystalModel.py	(revision d5b6a9d7cd9e26b5f9e28e55e8cf848a40de6ae9)
@@ -0,0 +1,183 @@
+#!/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_extensions\bcc.h
+         AND RE-RUN THE GENERATOR SCRIPT
+
+"""
+
+from sans.models.BaseComponent import BaseComponent
+from sans_extension.c_models import CBCCrystalModel
+import copy    
+    
+class BCCrystalModel(CBCCrystalModel, BaseComponent):
+    """ 
+    Class that evaluates a BCCrystalModel model. 
+    This file was auto-generated from ..\c_extensions\bcc.h.
+    Refer to that file and the structure it contains
+    for details of the model.
+    List of default parameters:
+         scale           = 1.0 
+         dnn             = 220.0 [A]
+         d_factor        = 0.06 
+         radius          = 40.0 [A]
+         sldSph          = 3e-006 [1/A^(2)]
+         sldSolv         = 6.3e-006 [1/A^(2)]
+         background      = 0.0 [1/cm]
+         theta           = 0.0 [rad]
+         phi             = 0.0 [rad]
+         psi             = 0.0 [rad]
+
+    """
+        
+    def __init__(self):
+        """ Initialization """
+        
+        # Initialize BaseComponent first, then sphere
+        BaseComponent.__init__(self)
+        CBCCrystalModel.__init__(self)
+        
+        ## Name of the model
+        self.name = "BCCrystalModel"
+        ## Model description
+        self.description ="""P(q)=(scale/Vp)*V_lattice*P(q)*Z(q)+bkg where scale is the volume
+		fraction of sphere,
+		Vp = volume of the primary particle,
+		V_lattice = volume correction for
+		for the crystal structure,
+		P(q)= form factor of the sphere (normalized),
+		Z(q)= paracrystalline structure factor
+		for a face centered cubic structure.
+		[Body Centered Cubic ParaCrystal Model]
+		Parameters;
+		scale: volume fraction of spheres
+		bkg:background, R: radius of sphere
+		dnn: Nearest neighbor distance
+		d_factor: Paracrystal distortion factor
+		radius: radius of the spheres
+		sldSph: SLD of the sphere
+		sldSolv: SLD of the solvent
+		"""
+       
+        ## Parameter details [units, min, max]
+        self.details = {}
+        self.details['scale'] = ['', None, None]
+        self.details['dnn'] = ['[A]', None, None]
+        self.details['d_factor'] = ['', None, None]
+        self.details['radius'] = ['[A]', None, None]
+        self.details['sldSph'] = ['[1/A^(2)]', None, None]
+        self.details['sldSolv'] = ['[1/A^(2)]', None, None]
+        self.details['background'] = ['[1/cm]', None, None]
+        self.details['theta'] = ['[rad]', None, None]
+        self.details['phi'] = ['[rad]', None, None]
+        self.details['psi'] = ['[rad]', None, None]
+
+        ## fittable parameters
+        self.fixed=['radius.width', 'phi.width', 'psi.width', 'theta.width']
+        
+        ## non-fittable parameters
+        self.non_fittable=[]
+        
+        ## parameters with orientation
+        self.orientation_params =['phi', 'psi', 'theta', 'phi.width', 'psi.width', 'theta.width']
+   
+    def clone(self):
+        """ Return a identical copy of self """
+        return self._clone(BCCrystalModel())   
+        
+    def __getstate__(self):
+        """
+        return object state for pickling and copying
+        """
+        model_state = {'params': self.params, 'dispersion': self.dispersion, 'log': self.log}
+        
+        return self.__dict__, model_state
+        
+    def __setstate__(self, state):
+        """
+        create object from pickled state
+        
+        :param state: the state of the current model
+        
+        """
+        
+        self.__dict__, model_state = state
+        self.params = model_state['params']
+        self.dispersion = model_state['dispersion']
+        self.log = model_state['log']
+       	
+   
+    def run(self, x=0.0):
+        """ 
+        Evaluate the model
+        
+        :param x: input q, or [q,phi]
+        
+        :return: scattering function P(q)
+        
+        """
+        
+        return CBCCrystalModel.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 CBCCrystalModel.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 CBCCrystalModel.evalDistribution(self, x)
+        
+    def calculate_ER(self):
+        """ 
+        Calculate the effective radius for P(q)*S(q)
+        
+        :return: the value of the effective radius
+        
+        """       
+        return CBCCrystalModel.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 CBCCrystalModel.set_dispersion(self, parameter, dispersion.cdisp)
+        
+   
+# End of file
Index: sansmodels/src/sans/models/FCCrystalModel.py
===================================================================
--- sansmodels/src/sans/models/FCCrystalModel.py	(revision d5b6a9d7cd9e26b5f9e28e55e8cf848a40de6ae9)
+++ sansmodels/src/sans/models/FCCrystalModel.py	(revision d5b6a9d7cd9e26b5f9e28e55e8cf848a40de6ae9)
@@ -0,0 +1,183 @@
+#!/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_extensions\fcc.h
+         AND RE-RUN THE GENERATOR SCRIPT
+
+"""
+
+from sans.models.BaseComponent import BaseComponent
+from sans_extension.c_models import CFCCrystalModel
+import copy    
+    
+class FCCrystalModel(CFCCrystalModel, BaseComponent):
+    """ 
+    Class that evaluates a FCCrystalModel model. 
+    This file was auto-generated from ..\c_extensions\fcc.h.
+    Refer to that file and the structure it contains
+    for details of the model.
+    List of default parameters:
+         scale           = 1.0 
+         dnn             = 220.0 [A]
+         d_factor        = 0.06 
+         radius          = 40.0 [A]
+         sldSph          = 3e-006 [1/A^(2)]
+         sldSolv         = 6.3e-006 [1/A^(2)]
+         background      = 0.0 [1/cm]
+         theta           = 0.0 [rad]
+         phi             = 0.0 [rad]
+         psi             = 0.0 [rad]
+
+    """
+        
+    def __init__(self):
+        """ Initialization """
+        
+        # Initialize BaseComponent first, then sphere
+        BaseComponent.__init__(self)
+        CFCCrystalModel.__init__(self)
+        
+        ## Name of the model
+        self.name = "FCCrystalModel"
+        ## Model description
+        self.description ="""P(q)=(scale/Vp)*V_lattice*P(q)*Z(q)+bkg where scale is the volume
+		fraction of sphere,
+		Vp = volume of the primary particle,
+		V_lattice = volume correction for
+		for the crystal structure,
+		P(q)= form factor of the sphere (normalized),
+		Z(q)= paracrystalline structure factor
+		for a face centered cubic structure.
+		[Face Centered Cubic ParaCrystal Model]
+		Parameters;
+		scale: volume fraction of spheres
+		bkg:background, R: radius of sphere
+		dnn: Nearest neighbor distance
+		d_factor: Paracrystal distortion factor
+		radius: radius of the spheres
+		sldSph: SLD of the sphere
+		sldSolv: SLD of the solvent
+		"""
+       
+        ## Parameter details [units, min, max]
+        self.details = {}
+        self.details['scale'] = ['', None, None]
+        self.details['dnn'] = ['[A]', None, None]
+        self.details['d_factor'] = ['', None, None]
+        self.details['radius'] = ['[A]', None, None]
+        self.details['sldSph'] = ['[1/A^(2)]', None, None]
+        self.details['sldSolv'] = ['[1/A^(2)]', None, None]
+        self.details['background'] = ['[1/cm]', None, None]
+        self.details['theta'] = ['[rad]', None, None]
+        self.details['phi'] = ['[rad]', None, None]
+        self.details['psi'] = ['[rad]', None, None]
+
+        ## fittable parameters
+        self.fixed=['radius.width', 'phi.width', 'psi.width', 'theta.width']
+        
+        ## non-fittable parameters
+        self.non_fittable=[]
+        
+        ## parameters with orientation
+        self.orientation_params =['phi', 'psi', 'theta', 'phi.width', 'psi.width', 'theta.width']
+   
+    def clone(self):
+        """ Return a identical copy of self """
+        return self._clone(FCCrystalModel())   
+        
+    def __getstate__(self):
+        """
+        return object state for pickling and copying
+        """
+        model_state = {'params': self.params, 'dispersion': self.dispersion, 'log': self.log}
+        
+        return self.__dict__, model_state
+        
+    def __setstate__(self, state):
+        """
+        create object from pickled state
+        
+        :param state: the state of the current model
+        
+        """
+        
+        self.__dict__, model_state = state
+        self.params = model_state['params']
+        self.dispersion = model_state['dispersion']
+        self.log = model_state['log']
+       	
+   
+    def run(self, x=0.0):
+        """ 
+        Evaluate the model
+        
+        :param x: input q, or [q,phi]
+        
+        :return: scattering function P(q)
+        
+        """
+        
+        return CFCCrystalModel.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 CFCCrystalModel.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 CFCCrystalModel.evalDistribution(self, x)
+        
+    def calculate_ER(self):
+        """ 
+        Calculate the effective radius for P(q)*S(q)
+        
+        :return: the value of the effective radius
+        
+        """       
+        return CFCCrystalModel.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 CFCCrystalModel.set_dispersion(self, parameter, dispersion.cdisp)
+        
+   
+# End of file
Index: sansmodels/src/sans/models/LamellarPCrystalModel.py
===================================================================
--- sansmodels/src/sans/models/LamellarPCrystalModel.py	(revision d5b6a9d7cd9e26b5f9e28e55e8cf848a40de6ae9)
+++ sansmodels/src/sans/models/LamellarPCrystalModel.py	(revision d5b6a9d7cd9e26b5f9e28e55e8cf848a40de6ae9)
@@ -0,0 +1,172 @@
+#!/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_extensions\lamellarPC.h
+         AND RE-RUN THE GENERATOR SCRIPT
+
+"""
+
+from sans.models.BaseComponent import BaseComponent
+from sans_extension.c_models import CLamellarPCrystalModel
+import copy    
+    
+class LamellarPCrystalModel(CLamellarPCrystalModel, BaseComponent):
+    """ 
+    Class that evaluates a LamellarPCrystalModel model. 
+    This file was auto-generated from ..\c_extensions\lamellarPC.h.
+    Refer to that file and the structure it contains
+    for details of the model.
+    List of default parameters:
+         scale           = 1.0 
+         thickness       = 33.0 [A]
+         Nlayers         = 20.0 
+         spacing         = 250.0 [A]
+         pd_spacing      = 0.0 
+         sld_layer       = 1e-006 [1/A^(2)]
+         sld_solvent     = 6.34e-006 [1/A^(2)]
+         background      = 0.0 [1/cm]
+
+    """
+        
+    def __init__(self):
+        """ Initialization """
+        
+        # Initialize BaseComponent first, then sphere
+        BaseComponent.__init__(self)
+        CLamellarPCrystalModel.__init__(self)
+        
+        ## Name of the model
+        self.name = "LamellarPCrystalModel"
+        ## Model description
+        self.description ="""[Lamellar ParaCrystal Model] Parameter Definitions: scale = scale factor,
+		background = incoherent background
+		thickness = lamellar thickness,
+		sld_layer = layer scattering length density ,
+		sld_solvent = solvent scattering length density.
+		Nlayers = no. of lamellar layers
+		spacing = spacing between layers
+		pd_spacing = polydispersity of spacing
+		Note: This model can be used for large
+		multilamellar vesicles.
+		"""
+       
+        ## Parameter details [units, min, max]
+        self.details = {}
+        self.details['scale'] = ['', None, None]
+        self.details['thickness'] = ['[A]', None, None]
+        self.details['Nlayers'] = ['', None, None]
+        self.details['spacing'] = ['[A]', None, None]
+        self.details['pd_spacing'] = ['', None, None]
+        self.details['sld_layer'] = ['[1/A^(2)]', None, None]
+        self.details['sld_solvent'] = ['[1/A^(2)]', None, None]
+        self.details['background'] = ['[1/cm]', None, None]
+
+        ## fittable parameters
+        self.fixed=['thickness.width']
+        
+        ## non-fittable parameters
+        self.non_fittable=[]
+        
+        ## parameters with orientation
+        self.orientation_params =[]
+   
+    def clone(self):
+        """ Return a identical copy of self """
+        return self._clone(LamellarPCrystalModel())   
+        
+    def __getstate__(self):
+        """
+        return object state for pickling and copying
+        """
+        model_state = {'params': self.params, 'dispersion': self.dispersion, 'log': self.log}
+        
+        return self.__dict__, model_state
+        
+    def __setstate__(self, state):
+        """
+        create object from pickled state
+        
+        :param state: the state of the current model
+        
+        """
+        
+        self.__dict__, model_state = state
+        self.params = model_state['params']
+        self.dispersion = model_state['dispersion']
+        self.log = model_state['log']
+       	
+   
+    def run(self, x=0.0):
+        """ 
+        Evaluate the model
+        
+        :param x: input q, or [q,phi]
+        
+        :return: scattering function P(q)
+        
+        """
+        
+        return CLamellarPCrystalModel.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 CLamellarPCrystalModel.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 CLamellarPCrystalModel.evalDistribution(self, x)
+        
+    def calculate_ER(self):
+        """ 
+        Calculate the effective radius for P(q)*S(q)
+        
+        :return: the value of the effective radius
+        
+        """       
+        return CLamellarPCrystalModel.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 CLamellarPCrystalModel.set_dispersion(self, parameter, dispersion.cdisp)
+        
+   
+# End of file
Index: sansmodels/src/sans/models/SCCrystalModel.py
===================================================================
--- sansmodels/src/sans/models/SCCrystalModel.py	(revision 94a3f8f49326fa54618105cf9c371ebe39bb3dda)
+++ sansmodels/src/sans/models/SCCrystalModel.py	(revision d5b6a9d7cd9e26b5f9e28e55e8cf848a40de6ae9)
@@ -67,4 +67,5 @@
 		Z(q)= paracrystalline structure factor
 		for a simple cubic structure.
+		[Simple Cubic ParaCrystal Model]
 		Parameters;
 		scale: volume fraction of spheres
Index: sansmodels/src/sans/models/c_extensions/bcc.c
===================================================================
--- sansmodels/src/sans/models/c_extensions/bcc.c	(revision d5b6a9d7cd9e26b5f9e28e55e8cf848a40de6ae9)
+++ sansmodels/src/sans/models/c_extensions/bcc.c	(revision d5b6a9d7cd9e26b5f9e28e55e8cf848a40de6ae9)
@@ -0,0 +1,151 @@
+/*
+ * Scattering model for a BC_ParaCrystal
+ */
+#include "bcc.h"
+#include "libSphere.h"
+#include <math.h>
+
+
+/**
+ * Function to evaluate 1D scattering function
+ * @param pars: parameters of the BCC_ParaCrystal
+ * @param q: q-value
+ * @return: function value
+ */
+double bcc_analytical_1D(BCParameters *pars, double q) {
+	double dp[7];
+	double result;
+
+	dp[0] = pars->scale;
+	dp[1] = pars->dnn;
+	dp[2] = pars->d_factor;
+	dp[3] = pars->radius;
+	dp[4] = pars->sldSph;
+	dp[5] = pars->sldSolv;
+	dp[6] = pars->background;
+
+	result = BCC_ParaCrystal(dp, q);
+	// This FIXES a singualrity the kernel in libigor.
+	if ( result == INFINITY || result == NAN){
+		result = pars->background;
+	}
+	return result;
+}
+
+/**
+ * Function to evaluate 2D scattering function
+ * @param pars: parameters of the BCC_ParaCrystal
+ * @param q: q-value
+ * @return: function value
+ */
+double bc_analytical_2DXY(BCParameters *pars, double qx, double qy){
+	double q;
+	q = sqrt(qx*qx+qy*qy);
+	return bc_analytical_2D_scaled(pars, q, qx/q, qy/q);
+}
+
+double bc_analytical_2D(BCParameters *pars, double q, double phi) {
+	return bc_analytical_2D_scaled(pars, q, cos(phi), sin(phi));
+}
+
+/**
+ * Function to evaluate 2D scattering function
+ * @param pars: parameters of the BCCCrystalModel
+ * @param q: q-value
+ * @param q_x: q_x / q
+ * @param q_y: q_y / q
+ * @return: function value
+ */
+double bc_analytical_2D_scaled(BCParameters *pars, double q, double q_x, double q_y) {
+	double a3_x, a3_y, a3_z, a2_x, a2_y, a1_x, a1_y;
+	double b3_x, b3_y, b3_z, b2_x, b2_y, b1_x, b1_y;
+	double q_z;
+	double alpha, vol, cos_val_a3, cos_val_a2, cos_val_a1;
+	double a1_dot_q, a2_dot_q,a3_dot_q;
+	double answer;
+	double Pi = 4.0*atan(1.0);
+	double aa, Da, qDa_2, latticeScale, Zq, Fkq, Fkq_2;
+
+	double dp[5];
+	dp[0] = 1.0;
+	dp[1] = pars->radius;
+	dp[2] = pars->sldSph;
+	dp[3] = pars->sldSolv;
+	dp[4] = 0.0;
+
+	aa = pars->dnn;
+	Da = pars->d_factor*aa;
+	qDa_2 = pow(q*Da,2.0);
+
+	//the occupied volume of the lattice
+	latticeScale = 2.0*(4.0/3.0)*Pi*(dp[1]*dp[1]*dp[1])/pow(aa/sqrt(3.0/4.0),3.0);
+
+	/// Angles here are respect to detector coordinate
+	///  instead of against q coordinate(PRB 36(46), 3(6), 1754(3854))
+    // b3 axis orientation
+    b3_x = sin(pars->theta) * cos(pars->phi);//negative sign here???
+    b3_y = sin(pars->theta) * sin(pars->phi);
+    b3_z = cos(pars->theta);
+    // b1 axis orientation
+    b1_x = sin(pars->psi);
+    b1_y = cos(pars->psi);
+    // b2 axis orientation
+    b2_x = sqrt(1-sin(pars->theta)*cos(pars->phi))*cos(pars->psi);
+    b2_y = sqrt(1-sin(pars->theta)*cos(pars->phi))*sin(pars->psi);
+
+    // a3 axis orientation
+    a3_x = 0.5*(b2_x + b1_x - b3_x);
+    a3_y = 0.5*(b2_y + b1_y - b3_y);
+    a3_z = 0.0;
+    // a1 axis orientation
+    a1_x = 0.5*(b3_x + b2_x - b1_x);
+    a1_y = 0.5*(b3_y + b2_y - b1_y);
+    // a2 axis orientation
+    a2_x = 0.5*(b3_x + b1_x - b2_x);
+    a2_y = 0.5*(b3_y + b1_y - b2_y);
+
+    // q vector
+    q_z = 0.0; // for SANS; assuming qz is negligible
+
+    // Compute the angle btw vector q and the a3 axis
+    cos_val_a3 = a3_x*q_x + a3_y*q_y + a3_z*q_z;
+    //alpha = acos(cos_val_a3);
+    a3_dot_q = aa*q*cos_val_a3;
+
+    // a1 axis
+    cos_val_a1 = a1_x*q_x + a1_y*q_y;
+    a1_dot_q = aa*q*cos_val_a1;
+
+    // a2 axis
+    cos_val_a2 = a2_x*q_x + a2_y*q_y; //sin(acos(cos_val_a1)) ;
+    a2_dot_q = aa*q*cos_val_a2;
+
+    // The following test should always pass
+    if (fabs(cos_val_a3)>1.0) {
+    	printf("parallel_ana_2D: Unexpected error: cos(alpha)>1\n");
+     	return 0;
+    }
+    // Get Fkq and Fkq_2
+    Fkq = exp(-0.5*pow(Da/aa,2.0)*(a1_dot_q*a1_dot_q+a2_dot_q*a2_dot_q+a3_dot_q*a3_dot_q));
+    Fkq_2 = Fkq*Fkq;
+    // Call Zq=Z1*Z2*Z3
+    Zq = (1.0-Fkq_2)/(1.0-2.0*Fkq*cos(a1_dot_q)+Fkq_2);
+    Zq = Zq * (1.0-Fkq_2)/(1.0-2.0*Fkq*cos(a2_dot_q)+Fkq_2);
+    Zq = Zq * (1.0-Fkq_2)/(1.0-2.0*Fkq*cos(a3_dot_q)+Fkq_2);
+
+	// Use SphereForm directly from libigor
+	answer = SphereForm(dp,q)*Zq;
+
+	//consider scales
+	answer *= latticeScale * pars->scale;
+
+	// This FIXES a singualrity the kernel in libigor.
+	if ( answer == INFINITY || answer == NAN){
+		answer = 0.0;
+	}
+
+	// add background
+	answer += pars->background;
+
+	return answer;
+}
Index: sansmodels/src/sans/models/c_extensions/bcc.h
===================================================================
--- sansmodels/src/sans/models/c_extensions/bcc.h	(revision d5b6a9d7cd9e26b5f9e28e55e8cf848a40de6ae9)
+++ sansmodels/src/sans/models/c_extensions/bcc.h	(revision d5b6a9d7cd9e26b5f9e28e55e8cf848a40de6ae9)
@@ -0,0 +1,81 @@
+#if !defined(bcc_h)
+#define bcc_h
+
+/**
+ * Structure definition for BCC_ParaCrystal parameters
+ */
+ //[PYTHONCLASS] = BCCrystalModel
+ //[DISP_PARAMS] = radius,phi, psi, theta
+ //[DESCRIPTION] =<text>P(q)=(scale/Vp)*V_lattice*P(q)*Z(q)+bkg where scale is the volume
+ //					 fraction of sphere,
+ //				Vp = volume of the primary particle,
+ //				V_lattice = volume correction for
+ //					for the crystal structure,
+ //				P(q)= form factor of the sphere (normalized),
+ //				Z(q)= paracrystalline structure factor
+ //					for a face centered cubic structure.
+ //				[Body Centered Cubic ParaCrystal Model]
+ //				Parameters;
+ //				scale: volume fraction of spheres
+ //				bkg:background, R: radius of sphere
+ //				dnn: Nearest neighbor distance
+ //				d_factor: Paracrystal distortion factor
+ //				radius: radius of the spheres
+ //				sldSph: SLD of the sphere
+ //				sldSolv: SLD of the solvent
+ //
+ //		</text>
+ //[FIXED]=  radius.width;phi.width;psi.width; theta.width
+ //[ORIENTATION_PARAMS]= <text> phi;psi; theta; phi.width;psi.width; theta.width</text>
+
+typedef struct {
+    /// Scale factor
+    //  [DEFAULT]=scale= 1.0
+    double scale;
+
+    ///	Nearest neighbor distance [A]
+    //  [DEFAULT]=dnn=220.0 [A]
+    double dnn;
+
+    ///	Paracrystal distortion factor g
+    //  [DEFAULT]=d_factor=0.06
+    double d_factor;
+
+    ///	Radius of sphere [A]
+    //  [DEFAULT]=radius=40.0 [A]
+    double radius;
+
+    ///	sldSph [1/A^(2)]
+    //  [DEFAULT]=sldSph= 3.0e-6 [1/A^(2)]
+    double sldSph;
+
+    ///	sldSolv [1/A^(2)]
+    //  [DEFAULT]=sldSolv= 6.3e-6 [1/A^(2)]
+    double sldSolv;
+
+	/// Incoherent Background [1/cm]
+	//  [DEFAULT]=background=0 [1/cm]
+	double background;
+    /// Orientation of the a1 axis w/respect incoming beam [rad]
+    //  [DEFAULT]=theta=0.0 [rad]
+    double theta;
+    /// Orientation of the a2 in the plane of the detector [rad]
+    //  [DEFAULT]=phi=0.0 [rad]
+    double phi;
+    /// Orientation of the a3 in the plane of the detector [rad]
+    //  [DEFAULT]=psi=0.0 [rad]
+    double psi;
+
+} BCParameters;
+
+
+
+/// 1D scattering function
+double bc_analytical_1D(BCParameters *pars, double q);
+
+/// 2D scattering function
+double bc_analytical_2D(BCParameters *pars, double q, double phi);
+double bc_analytical_2DXY(BCParameters *pars, double qx, double qy);
+double bc_analytical_2D_scaled(BCParameters *pars, double q, double q_x, double q_y);
+
+#endif
Index: sansmodels/src/sans/models/c_extensions/fcc.c
===================================================================
--- sansmodels/src/sans/models/c_extensions/fcc.c	(revision d5b6a9d7cd9e26b5f9e28e55e8cf848a40de6ae9)
+++ sansmodels/src/sans/models/c_extensions/fcc.c	(revision d5b6a9d7cd9e26b5f9e28e55e8cf848a40de6ae9)
@@ -0,0 +1,149 @@
+/*
+ * Scattering model for a SC_ParaCrystal
+ */
+#include "fcc.h"
+#include "libSphere.h"
+#include <math.h>
+
+
+/**
+ * Function to evaluate 1D scattering function
+ * @param pars: parameters of the FCC_ParaCrystal
+ * @param q: q-value
+ * @return: function value
+ */
+double fcc_analytical_1D(FCParameters *pars, double q) {
+	double dp[7];
+	double result;
+
+	dp[0] = pars->scale;
+	dp[1] = pars->dnn;
+	dp[2] = pars->d_factor;
+	dp[3] = pars->radius;
+	dp[4] = pars->sldSph;
+	dp[5] = pars->sldSolv;
+	dp[6] = pars->background;
+
+	result = FCC_ParaCrystal(dp, q);
+	// This FIXES a singualrity the kernel in libigor.
+	if ( result == INFINITY || result == NAN){
+		result = pars->background;
+	}
+	return result;
+}
+
+/**
+ * Function to evaluate 2D scattering function
+ * @param pars: parameters of the FCC_ParaCrystal
+ * @param q: q-value
+ * @return: function value
+ */
+double fc_analytical_2DXY(FCParameters *pars, double qx, double qy){
+	double q;
+	q = sqrt(qx*qx+qy*qy);
+	return fc_analytical_2D_scaled(pars, q, qx/q, qy/q);
+}
+
+double fc_analytical_2D(FCParameters *pars, double q, double phi) {
+	return fc_analytical_2D_scaled(pars, q, cos(phi), sin(phi));
+}
+
+/**
+ * Function to evaluate 2D scattering function
+ * @param pars: parameters of the FCCCrystalModel
+ * @param q: q-value
+ * @param q_x: q_x / q
+ * @param q_y: q_y / q
+ * @return: function value
+ */
+double fc_analytical_2D_scaled(FCParameters *pars, double q, double q_x, double q_y) {
+	double a3_x, a3_y, a3_z, a2_x, a2_y, a1_x, a1_y;
+	double b3_x, b3_y, b3_z, b2_x, b2_y, b1_x, b1_y;
+	double q_z;
+	double alpha, vol, cos_val_a3, cos_val_a2, cos_val_a1;
+	double a1_dot_q, a2_dot_q,a3_dot_q;
+	double answer;
+	double Pi = 4.0*atan(1.0);
+	double aa, Da, qDa_2, latticeScale, Zq, Fkq, Fkq_2;
+
+	double dp[5];
+	dp[0] = 1.0;
+	dp[1] = pars->radius;
+	dp[2] = pars->sldSph;
+	dp[3] = pars->sldSolv;
+	dp[4] = 0.0;
+
+	aa = pars->dnn;
+	Da = pars->d_factor*aa;
+	qDa_2 = pow(q*Da,2.0);
+
+	latticeScale = 4.0*(4.0/3.0)*Pi*(dp[1]*dp[1]*dp[1])/pow(aa*sqrt(2.0),3.0);
+
+	/// Angles here are respect to detector coordinate
+	///  instead of against q coordinate(PRB 36(46), 3(6), 1754(3854))
+    // b3 axis orientation
+    b3_x = sin(pars->theta) * cos(pars->phi);//negative sign here???
+    b3_y = sin(pars->theta) * sin(pars->phi);
+    b3_z = cos(pars->theta);
+    // b1 axis orientation
+    b1_x = sin(pars->psi);
+    b1_y = cos(pars->psi);
+    // b2 axis orientation
+    b2_x = sqrt(1-sin(pars->theta)*cos(pars->phi))*cos(pars->psi);
+    b2_y = sqrt(1-sin(pars->theta)*cos(pars->phi))*sin(pars->psi);
+
+    // a3 axis orientation
+    a3_x = 0.5*(b2_x + b1_x);
+    a3_y = 0.5*(b2_y + b1_y);
+    a3_z = 0.0;
+    // a1 axis orientation
+    a1_x = 0.5*(b3_x + b2_x);
+    a1_y = 0.5*(b3_y + b2_y);
+    // a2 axis orientation
+    a2_x = 0.5*(b3_x + b1_x);
+    a2_y = 0.5*(b3_y + b1_y);
+
+    // q vector
+    q_z = 0.0; // for SANS; assuming qz is negligible
+
+    // Compute the angle btw vector q and the a3 axis
+    cos_val_a3 = a3_x*q_x + a3_y*q_y + a3_z*q_z;
+    a3_dot_q = aa*q*cos_val_a3;
+
+    // a1 axis
+    cos_val_a1 = a1_x*q_x + a1_y*q_y;
+    a1_dot_q = aa*q*cos_val_a1;
+
+    // a2 axis
+    cos_val_a2 = a2_x*q_x + a2_y*q_y; //sin(acos(cos_val_a1)) ;
+    a2_dot_q = aa*q*cos_val_a2;
+
+    // The following test should always pass
+    if (fabs(cos_val_a3)>1.0) {
+    	printf("parallel_ana_2D: Unexpected error: cos(alpha)>1\n");
+     	return 0;
+    }
+    // Get Fkq and Fkq_2
+    Fkq = exp(-0.5*pow(Da/aa,2.0)*(a1_dot_q*a1_dot_q+a2_dot_q*a2_dot_q+a3_dot_q*a3_dot_q));
+    Fkq_2 = Fkq*Fkq;
+    // Call Zq=Z1*Z2*Z3
+    Zq = (1.0-Fkq_2)/(1.0-2.0*Fkq*cos(a1_dot_q)+Fkq_2);
+    Zq = Zq * (1.0-Fkq_2)/(1.0-2.0*Fkq*cos(a2_dot_q)+Fkq_2);
+    Zq = Zq * (1.0-Fkq_2)/(1.0-2.0*Fkq*cos(a3_dot_q)+Fkq_2);
+
+	// Use SphereForm directly from libigor
+	answer = SphereForm(dp,q)*Zq;
+
+	//consider scales
+	answer *= latticeScale * pars->scale;
+
+	// This FIXES a singualrity the kernel in libigor.
+	if ( answer == INFINITY || answer == NAN){
+		answer = 0.0;
+	}
+
+	// add background
+	answer += pars->background;
+
+	return answer;
+}
Index: sansmodels/src/sans/models/c_extensions/fcc.h
===================================================================
--- sansmodels/src/sans/models/c_extensions/fcc.h	(revision d5b6a9d7cd9e26b5f9e28e55e8cf848a40de6ae9)
+++ sansmodels/src/sans/models/c_extensions/fcc.h	(revision d5b6a9d7cd9e26b5f9e28e55e8cf848a40de6ae9)
@@ -0,0 +1,81 @@
+#if !defined(fcc_h)
+#define fcc_h
+
+/**
+ * Structure definition for FCC_ParaCrystal parameters
+ */
+ //[PYTHONCLASS] = FCCrystalModel
+ //[DISP_PARAMS] = radius,phi, psi, theta
+ //[DESCRIPTION] =<text>P(q)=(scale/Vp)*V_lattice*P(q)*Z(q)+bkg where scale is the volume
+ //					 fraction of sphere,
+ //				Vp = volume of the primary particle,
+ //				V_lattice = volume correction for
+ //					for the crystal structure,
+ //				P(q)= form factor of the sphere (normalized),
+ //				Z(q)= paracrystalline structure factor
+ //					for a face centered cubic structure.
+ //				[Face Centered Cubic ParaCrystal Model]
+ //				Parameters;
+ //				scale: volume fraction of spheres
+ //				bkg:background, R: radius of sphere
+ //				dnn: Nearest neighbor distance
+ //				d_factor: Paracrystal distortion factor
+ //				radius: radius of the spheres
+ //				sldSph: SLD of the sphere
+ //				sldSolv: SLD of the solvent
+ //
+ //		</text>
+ //[FIXED]=  radius.width;phi.width;psi.width; theta.width
+ //[ORIENTATION_PARAMS]= <text> phi;psi; theta; phi.width;psi.width; theta.width</text>
+
+typedef struct {
+    /// Scale factor
+    //  [DEFAULT]=scale= 1.0
+    double scale;
+
+    ///	Nearest neighbor distance [A]
+    //  [DEFAULT]=dnn=220.0 [A]
+    double dnn;
+
+    ///	Paracrystal distortion factor g
+    //  [DEFAULT]=d_factor=0.06
+    double d_factor;
+
+    ///	Radius of sphere [A]
+    //  [DEFAULT]=radius=40.0 [A]
+    double radius;
+
+    ///	sldSph [1/A^(2)]
+    //  [DEFAULT]=sldSph= 3.0e-6 [1/A^(2)]
+    double sldSph;
+
+    ///	sldSolv [1/A^(2)]
+    //  [DEFAULT]=sldSolv= 6.3e-6 [1/A^(2)]
+    double sldSolv;
+
+	/// Incoherent Background [1/cm]
+	//  [DEFAULT]=background=0 [1/cm]
+	double background;
+    /// Orientation of the a1 axis w/respect incoming beam [rad]
+    //  [DEFAULT]=theta=0.0 [rad]
+    double theta;
+    /// Orientation of the a2 in the plane of the detector [rad]
+    //  [DEFAULT]=phi=0.0 [rad]
+    double phi;
+    /// Orientation of the a3 in the plane of the detector [rad]
+    //  [DEFAULT]=psi=0.0 [rad]
+    double psi;
+
+} FCParameters;
+
+
+
+/// 1D scattering function
+double fc_analytical_1D(FCParameters *pars, double q);
+
+/// 2D scattering function
+double fc_analytical_2D(FCParameters *pars, double q, double phi);
+double fc_analytical_2DXY(FCParameters *pars, double qx, double qy);
+double fc_analytical_2D_scaled(FCParameters *pars, double q, double q_x, double q_y);
+
+#endif
Index: sansmodels/src/sans/models/c_extensions/lamellarPC.c
===================================================================
--- sansmodels/src/sans/models/c_extensions/lamellarPC.c	(revision d5b6a9d7cd9e26b5f9e28e55e8cf848a40de6ae9)
+++ sansmodels/src/sans/models/c_extensions/lamellarPC.c	(revision d5b6a9d7cd9e26b5f9e28e55e8cf848a40de6ae9)
@@ -0,0 +1,40 @@
+/**
+ * Scattering model for a lamellar ParaCrystal
+ */
+
+#include "lamellarPC.h"
+#include <math.h>
+#include "libCylinder.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+
+/**
+ * Function to evaluate 1D scattering function
+ * @param pars: parameters of a lamellar ParaCrystal Model
+ * @param q: q-value
+ * @return: function value
+ */
+double lamellarPC_analytical_1D(LamellarPCParameters *pars, double q) {
+	double dp[8];
+
+	// Fill paramater array
+	dp[0] = pars->scale;
+	dp[1] = pars->thickness;
+	dp[2] = pars->Nlayers;
+	dp[3] = pars->spacing;
+	dp[4] = pars->pd_spacing;
+	dp[5] = pars->sld_layer;
+	dp[6] = pars->sld_solvent;
+	dp[7] = pars->background;
+
+	// Call library function to evaluate model
+	return Lamellar_ParaCrystal(dp, q);
+}
+
+double lamellarPC_analytical_2D(LamellarPCParameters *pars, double q, double phi){
+	return lamellarPC_analytical_1D(pars,q);
+}
+double lamellarPC_analytical_2DXY(LamellarPCParameters *pars, double qx, double qy){
+	return lamellarPC_analytical_1D(pars,sqrt(qx*qx+qy*qy));
+}
Index: sansmodels/src/sans/models/c_extensions/lamellarPC.h
===================================================================
--- sansmodels/src/sans/models/c_extensions/lamellarPC.h	(revision d5b6a9d7cd9e26b5f9e28e55e8cf848a40de6ae9)
+++ sansmodels/src/sans/models/c_extensions/lamellarPC.h	(revision d5b6a9d7cd9e26b5f9e28e55e8cf848a40de6ae9)
@@ -0,0 +1,58 @@
+#if !defined(lamellarPC_h)
+#define lamellarPC_h
+/** Structure definition for lamellar_paracrystal parameters
+ * [PYTHONCLASS] = LamellarPCrystalModel
+ * [DISP_PARAMS] =  thickness
+   [DESCRIPTION] = <text>[Lamellar ParaCrystal Model] Parameter Definitions: scale = scale factor,
+			background = incoherent background
+			thickness = lamellar thickness,
+			sld_layer = layer scattering length density ,
+			sld_solvent = solvent scattering length density.
+			Nlayers = no. of lamellar layers
+			spacing = spacing between layers
+			pd_spacing = polydispersity of spacing
+			Note: This model can be used for large
+				multilamellar vesicles.
+
+	</text>
+	[FIXED]= thickness.width;
+	[ORIENTATION_PARAMS]=
+ **/
+typedef struct {
+    /// Scale factor
+    //  [DEFAULT]=scale=1.0
+    double scale;
+    /// thickness
+    //  [DEFAULT]=thickness=33.0 [A]
+    double thickness;
+    /// Nlayers
+    //  [DEFAULT]=Nlayers=20.0
+    double Nlayers;
+    /// spacing
+    //  [DEFAULT]=spacing=250.0 [A]
+    double spacing;
+    /// poly-dispersity of spacing
+    //  [DEFAULT]=pd_spacing=0.0
+    double pd_spacing;
+    /// layer scrattering length density[1/A^(2)]
+    //  [DEFAULT]=sld_layer=1.0e-6 [1/A^(2)]
+    double sld_layer;
+	/// solvent scrattering length density[1/A^(2)]
+    //  [DEFAULT]=sld_solvent=6.34e-6 [1/A^(2)]
+    double sld_solvent;
+	/// Incoherent Background [1/cm] 0.00
+	//  [DEFAULT]=background=0.0 [1/cm]
+	double background;
+
+} LamellarPCParameters;
+
+
+
+/// 1D scattering function
+double lamellarPC_analytical_1D(LamellarPCParameters *pars, double q);
+
+/// 2D scattering function
+double lamellarPC_analytical_2D(LamellarPCParameters *pars, double q, double phi);
+double lamellarPC_analytical_2DXY(LamellarPCParameters *pars, double qx, double qy);
+
+#endif
Index: sansmodels/src/sans/models/c_extensions/sc.c
===================================================================
--- sansmodels/src/sans/models/c_extensions/sc.c	(revision 94a3f8f49326fa54618105cf9c371ebe39bb3dda)
+++ sansmodels/src/sans/models/c_extensions/sc.c	(revision d5b6a9d7cd9e26b5f9e28e55e8cf848a40de6ae9)
@@ -60,5 +60,5 @@
 	double a3_x, a3_y, a3_z, a2_x, a2_y, a1_x, a1_y, a1_z;
 	double q_z;
-	double alpha, vol, cos_val_a3, cos_val_a2, cos_val_a1, edgeA, edgeB, edgeC;
+	double alpha, vol, cos_val_a3, cos_val_a2, cos_val_a1;
 	double a1_dot_q, a2_dot_q,a3_dot_q;
 	double answer;
Index: sansmodels/src/sans/models/c_extensions/sc.h
===================================================================
--- sansmodels/src/sans/models/c_extensions/sc.h	(revision 94a3f8f49326fa54618105cf9c371ebe39bb3dda)
+++ sansmodels/src/sans/models/c_extensions/sc.h	(revision d5b6a9d7cd9e26b5f9e28e55e8cf848a40de6ae9)
@@ -15,4 +15,5 @@
  //				Z(q)= paracrystalline structure factor
  //					for a simple cubic structure.
+ //				[Simple Cubic ParaCrystal Model]
  //				Parameters;
  //				scale: volume fraction of spheres
Index: sansmodels/src/sans/models/c_models/CBCCrystalModel.cpp
===================================================================
--- sansmodels/src/sans/models/c_models/CBCCrystalModel.cpp	(revision d5b6a9d7cd9e26b5f9e28e55e8cf848a40de6ae9)
+++ sansmodels/src/sans/models/c_models/CBCCrystalModel.cpp	(revision d5b6a9d7cd9e26b5f9e28e55e8cf848a40de6ae9)
@@ -0,0 +1,617 @@
+/**
+	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
+ */
+
+/** CBCCrystalModel
+ *
+ * C extension 
+ *
+ * WARNING: THIS FILE WAS GENERATED BY WRAPPERGENERATOR.PY
+ *          DO NOT MODIFY THIS FILE, MODIFY bcc.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 "bcc.h"
+}
+
+#include "models.hh"
+#include "dispersion_visitor.hh"
+
+/// Error object for raised exceptions
+static PyObject * CBCCrystalModelError = NULL;
+
+
+// Class definition
+typedef struct {
+    PyObject_HEAD
+    /// Parameters
+    PyObject * params;
+    /// Dispersion parameters
+    PyObject * dispersion;
+    /// Underlying model object
+    BCCrystalModel * model;
+    /// Log for unit testing
+    PyObject * log;
+} CBCCrystalModel;
+
+
+static void
+CBCCrystalModel_dealloc(CBCCrystalModel* 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 *
+CBCCrystalModel_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+    CBCCrystalModel *self;
+    
+    self = (CBCCrystalModel *)type->tp_alloc(type, 0);
+   
+    return (PyObject *)self;
+}
+
+static int
+CBCCrystalModel_init(CBCCrystalModel *self, PyObject *args, PyObject *kwds)
+{
+    if (self != NULL) {
+    	
+    	// Create parameters
+        self->params = PyDict_New();
+        self->dispersion = PyDict_New();
+        self->model = new BCCrystalModel();
+        
+        // Initialize parameter dictionary
+        PyDict_SetItemString(self->params,"phi",Py_BuildValue("d",0.000000000000));
+        PyDict_SetItemString(self->params,"scale",Py_BuildValue("d",1.000000000000));
+        PyDict_SetItemString(self->params,"dnn",Py_BuildValue("d",220.000000000000));
+        PyDict_SetItemString(self->params,"sldSph",Py_BuildValue("d",0.000003000000));
+        PyDict_SetItemString(self->params,"d_factor",Py_BuildValue("d",0.060000000000));
+        PyDict_SetItemString(self->params,"psi",Py_BuildValue("d",0.000000000000));
+        PyDict_SetItemString(self->params,"radius",Py_BuildValue("d",40.000000000000));
+        PyDict_SetItemString(self->params,"background",Py_BuildValue("d",0.000000000000));
+        PyDict_SetItemString(self->params,"theta",Py_BuildValue("d",0.000000000000));
+        PyDict_SetItemString(self->params,"sldSolv",Py_BuildValue("d",0.000006300000));
+        // 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->phi.dispersion->accept_as_source(visitor, self->model->phi.dispersion, disp_dict);
+        PyDict_SetItemString(self->dispersion, "phi", disp_dict);
+        disp_dict = PyDict_New();
+        self->model->psi.dispersion->accept_as_source(visitor, self->model->psi.dispersion, disp_dict);
+        PyDict_SetItemString(self->dispersion, "psi", disp_dict);
+        disp_dict = PyDict_New();
+        self->model->theta.dispersion->accept_as_source(visitor, self->model->theta.dispersion, disp_dict);
+        PyDict_SetItemString(self->dispersion, "theta", disp_dict);
+
+
+         
+        // Create empty log
+        self->log = PyDict_New();
+        
+        
+
+    }
+    return 0;
+}
+
+static PyMemberDef CBCCrystalModel_members[] = {
+    {"params", T_OBJECT, offsetof(CBCCrystalModel, params), 0,
+     "Parameters"},
+	{"dispersion", T_OBJECT, offsetof(CBCCrystalModel, dispersion), 0,
+	  "Dispersion parameters"},     
+    {"log", T_OBJECT, offsetof(CBCCrystalModel, log), 0,
+     "Log"},
+    {NULL}  /* Sentinel */
+};
+
+/** Read double from PyObject
+    @param p PyObject
+    @return double
+*/
+double CBCCrystalModel_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(BCCrystalModel* 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( BCCrystalModel* 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(CBCCrystalModelError, 
+                   "CBCCrystalModel.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(CBCCrystalModel *self, PyObject *args){
+	PyObject *qx, *qy;
+	PyArrayObject * pars;
+	int npars ,mpars;
+	
+	// Get parameters
+	
+	    // Reader parameter dictionary
+    self->model->phi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "phi") );
+    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
+    self->model->dnn = PyFloat_AsDouble( PyDict_GetItemString(self->params, "dnn") );
+    self->model->sldSph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sldSph") );
+    self->model->d_factor = PyFloat_AsDouble( PyDict_GetItemString(self->params, "d_factor") );
+    self->model->psi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "psi") );
+    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
+    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
+    self->model->theta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "theta") );
+    self->model->sldSolv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sldSolv") );
+    // 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, "phi");
+    self->model->phi.dispersion->accept_as_destination(visitor, self->model->phi.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "psi");
+    self->model->psi.dispersion->accept_as_destination(visitor, self->model->psi.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "theta");
+    self->model->theta.dispersion->accept_as_destination(visitor, self->model->theta.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(CBCCrystalModelError, 
+	    	"CBCCrystalModel.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(CBCCrystalModelError, 
+                   "CBCCrystalModel.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(CBCCrystalModelError, 
+	    		"CBCCrystalModel.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(CBCCrystalModelError, 
+                   "CBCCrystalModel.evalDistribution expect 2 numpy arrays in list.");
+	        return NULL;
+	     }
+	}
+	PyErr_SetString(CBCCrystalModelError, 
+                   "CBCCrystalModel.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(CBCCrystalModel *self, PyObject *args) {
+	double q_value, phi_value;
+	PyObject* pars;
+	int npars;
+	
+	// Get parameters
+	
+	    // Reader parameter dictionary
+    self->model->phi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "phi") );
+    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
+    self->model->dnn = PyFloat_AsDouble( PyDict_GetItemString(self->params, "dnn") );
+    self->model->sldSph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sldSph") );
+    self->model->d_factor = PyFloat_AsDouble( PyDict_GetItemString(self->params, "d_factor") );
+    self->model->psi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "psi") );
+    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
+    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
+    self->model->theta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "theta") );
+    self->model->sldSolv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sldSolv") );
+    // 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, "phi");
+    self->model->phi.dispersion->accept_as_destination(visitor, self->model->phi.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "psi");
+    self->model->psi.dispersion->accept_as_destination(visitor, self->model->psi.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "theta");
+    self->model->theta.dispersion->accept_as_destination(visitor, self->model->theta.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(CBCCrystalModelError, 
+	    	"CBCCrystalModel.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(CBCCrystalModelError, 
+	    		"CBCCrystalModel.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 = CBCCrystalModel_readDouble(PyList_GET_ITEM(pars,0));
+	    phi_value = CBCCrystalModel_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 = CBCCrystalModel_readDouble(pars);		
+		
+		return Py_BuildValue("d",(*(self->model))(q_value));
+	}	
+}
+/**
+ * Function to call to calculate_ER
+ * @return: effective radius value 
+ */
+static PyObject * calculate_ER(CBCCrystalModel *self) {
+
+	PyObject* pars;
+	int npars;
+	
+	// Get parameters
+	
+	    // Reader parameter dictionary
+    self->model->phi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "phi") );
+    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
+    self->model->dnn = PyFloat_AsDouble( PyDict_GetItemString(self->params, "dnn") );
+    self->model->sldSph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sldSph") );
+    self->model->d_factor = PyFloat_AsDouble( PyDict_GetItemString(self->params, "d_factor") );
+    self->model->psi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "psi") );
+    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
+    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
+    self->model->theta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "theta") );
+    self->model->sldSolv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sldSolv") );
+    // 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, "phi");
+    self->model->phi.dispersion->accept_as_destination(visitor, self->model->phi.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "psi");
+    self->model->psi.dispersion->accept_as_destination(visitor, self->model->psi.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "theta");
+    self->model->theta.dispersion->accept_as_destination(visitor, self->model->theta.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(CBCCrystalModel *self, PyObject *args) {
+	double qx_value, qy_value;
+	PyObject* pars;
+	int npars;
+	
+	// Get parameters
+	
+	    // Reader parameter dictionary
+    self->model->phi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "phi") );
+    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
+    self->model->dnn = PyFloat_AsDouble( PyDict_GetItemString(self->params, "dnn") );
+    self->model->sldSph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sldSph") );
+    self->model->d_factor = PyFloat_AsDouble( PyDict_GetItemString(self->params, "d_factor") );
+    self->model->psi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "psi") );
+    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
+    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
+    self->model->theta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "theta") );
+    self->model->sldSolv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sldSolv") );
+    // 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, "phi");
+    self->model->phi.dispersion->accept_as_destination(visitor, self->model->phi.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "psi");
+    self->model->psi.dispersion->accept_as_destination(visitor, self->model->psi.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "theta");
+    self->model->theta.dispersion->accept_as_destination(visitor, self->model->theta.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(CBCCrystalModelError, 
+	    	"CBCCrystalModel.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(CBCCrystalModelError, 
+	    		"CBCCrystalModel.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 = CBCCrystalModel_readDouble(PyList_GET_ITEM(pars,0));
+	    qy_value = CBCCrystalModel_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 = CBCCrystalModel_readDouble(pars);		
+		
+		return Py_BuildValue("d",(*(self->model))(qx_value));
+	}	
+}
+
+static PyObject * reset(CBCCrystalModel *self, PyObject *args) {
+    
+
+    return Py_BuildValue("d",0.0);
+}
+
+static PyObject * set_dispersion(CBCCrystalModel *self, PyObject *args) {
+	PyObject * disp;
+	const char * par_name;
+
+	if ( !PyArg_ParseTuple(args,"sO", &par_name, &disp) ) {
+	    PyErr_SetString(CBCCrystalModelError,
+	    	"CBCCrystalModel.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, "phi")) {
+        self->model->phi.dispersion = dispersion;
+    } else    if (!strcmp(par_name, "psi")) {
+        self->model->psi.dispersion = dispersion;
+    } else    if (!strcmp(par_name, "theta")) {
+        self->model->theta.dispersion = dispersion;
+    } else {
+	    PyErr_SetString(CBCCrystalModelError,
+	    	"CBCCrystalModel.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 CBCCrystalModel_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 CBCCrystalModelType = {
+    PyObject_HEAD_INIT(NULL)
+    0,                         /*ob_size*/
+    "CBCCrystalModel",             /*tp_name*/
+    sizeof(CBCCrystalModel),             /*tp_basicsize*/
+    0,                         /*tp_itemsize*/
+    (destructor)CBCCrystalModel_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*/
+    "CBCCrystalModel objects",           /* tp_doc */
+    0,		               /* tp_traverse */
+    0,		               /* tp_clear */
+    0,		               /* tp_richcompare */
+    0,		               /* tp_weaklistoffset */
+    0,		               /* tp_iter */
+    0,		               /* tp_iternext */
+    CBCCrystalModel_methods,             /* tp_methods */
+    CBCCrystalModel_members,             /* tp_members */
+    0,                         /* tp_getset */
+    0,                         /* tp_base */
+    0,                         /* tp_dict */
+    0,                         /* tp_descr_get */
+    0,                         /* tp_descr_set */
+    0,                         /* tp_dictoffset */
+    (initproc)CBCCrystalModel_init,      /* tp_init */
+    0,                         /* tp_alloc */
+    CBCCrystalModel_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 addCBCCrystalModel(PyObject *module) {
+	PyObject *d;
+	
+    if (PyType_Ready(&CBCCrystalModelType) < 0)
+        return;
+
+    Py_INCREF(&CBCCrystalModelType);
+    PyModule_AddObject(module, "CBCCrystalModel", (PyObject *)&CBCCrystalModelType);
+    
+    d = PyModule_GetDict(module);
+    CBCCrystalModelError = PyErr_NewException("CBCCrystalModel.error", NULL, NULL);
+    PyDict_SetItemString(d, "CBCCrystalModelError", CBCCrystalModelError);
+}
+
Index: sansmodels/src/sans/models/c_models/CFCCrystalModel.cpp
===================================================================
--- sansmodels/src/sans/models/c_models/CFCCrystalModel.cpp	(revision d5b6a9d7cd9e26b5f9e28e55e8cf848a40de6ae9)
+++ sansmodels/src/sans/models/c_models/CFCCrystalModel.cpp	(revision d5b6a9d7cd9e26b5f9e28e55e8cf848a40de6ae9)
@@ -0,0 +1,617 @@
+/**
+	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
+ */
+
+/** CFCCrystalModel
+ *
+ * C extension 
+ *
+ * WARNING: THIS FILE WAS GENERATED BY WRAPPERGENERATOR.PY
+ *          DO NOT MODIFY THIS FILE, MODIFY fcc.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 "fcc.h"
+}
+
+#include "models.hh"
+#include "dispersion_visitor.hh"
+
+/// Error object for raised exceptions
+static PyObject * CFCCrystalModelError = NULL;
+
+
+// Class definition
+typedef struct {
+    PyObject_HEAD
+    /// Parameters
+    PyObject * params;
+    /// Dispersion parameters
+    PyObject * dispersion;
+    /// Underlying model object
+    FCCrystalModel * model;
+    /// Log for unit testing
+    PyObject * log;
+} CFCCrystalModel;
+
+
+static void
+CFCCrystalModel_dealloc(CFCCrystalModel* 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 *
+CFCCrystalModel_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+    CFCCrystalModel *self;
+    
+    self = (CFCCrystalModel *)type->tp_alloc(type, 0);
+   
+    return (PyObject *)self;
+}
+
+static int
+CFCCrystalModel_init(CFCCrystalModel *self, PyObject *args, PyObject *kwds)
+{
+    if (self != NULL) {
+    	
+    	// Create parameters
+        self->params = PyDict_New();
+        self->dispersion = PyDict_New();
+        self->model = new FCCrystalModel();
+        
+        // Initialize parameter dictionary
+        PyDict_SetItemString(self->params,"phi",Py_BuildValue("d",0.000000000000));
+        PyDict_SetItemString(self->params,"scale",Py_BuildValue("d",1.000000000000));
+        PyDict_SetItemString(self->params,"dnn",Py_BuildValue("d",220.000000000000));
+        PyDict_SetItemString(self->params,"sldSph",Py_BuildValue("d",0.000003000000));
+        PyDict_SetItemString(self->params,"d_factor",Py_BuildValue("d",0.060000000000));
+        PyDict_SetItemString(self->params,"psi",Py_BuildValue("d",0.000000000000));
+        PyDict_SetItemString(self->params,"radius",Py_BuildValue("d",40.000000000000));
+        PyDict_SetItemString(self->params,"background",Py_BuildValue("d",0.000000000000));
+        PyDict_SetItemString(self->params,"theta",Py_BuildValue("d",0.000000000000));
+        PyDict_SetItemString(self->params,"sldSolv",Py_BuildValue("d",0.000006300000));
+        // 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->phi.dispersion->accept_as_source(visitor, self->model->phi.dispersion, disp_dict);
+        PyDict_SetItemString(self->dispersion, "phi", disp_dict);
+        disp_dict = PyDict_New();
+        self->model->psi.dispersion->accept_as_source(visitor, self->model->psi.dispersion, disp_dict);
+        PyDict_SetItemString(self->dispersion, "psi", disp_dict);
+        disp_dict = PyDict_New();
+        self->model->theta.dispersion->accept_as_source(visitor, self->model->theta.dispersion, disp_dict);
+        PyDict_SetItemString(self->dispersion, "theta", disp_dict);
+
+
+         
+        // Create empty log
+        self->log = PyDict_New();
+        
+        
+
+    }
+    return 0;
+}
+
+static PyMemberDef CFCCrystalModel_members[] = {
+    {"params", T_OBJECT, offsetof(CFCCrystalModel, params), 0,
+     "Parameters"},
+	{"dispersion", T_OBJECT, offsetof(CFCCrystalModel, dispersion), 0,
+	  "Dispersion parameters"},     
+    {"log", T_OBJECT, offsetof(CFCCrystalModel, log), 0,
+     "Log"},
+    {NULL}  /* Sentinel */
+};
+
+/** Read double from PyObject
+    @param p PyObject
+    @return double
+*/
+double CFCCrystalModel_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(FCCrystalModel* 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( FCCrystalModel* 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(CFCCrystalModelError, 
+                   "CFCCrystalModel.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(CFCCrystalModel *self, PyObject *args){
+	PyObject *qx, *qy;
+	PyArrayObject * pars;
+	int npars ,mpars;
+	
+	// Get parameters
+	
+	    // Reader parameter dictionary
+    self->model->phi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "phi") );
+    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
+    self->model->dnn = PyFloat_AsDouble( PyDict_GetItemString(self->params, "dnn") );
+    self->model->sldSph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sldSph") );
+    self->model->d_factor = PyFloat_AsDouble( PyDict_GetItemString(self->params, "d_factor") );
+    self->model->psi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "psi") );
+    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
+    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
+    self->model->theta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "theta") );
+    self->model->sldSolv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sldSolv") );
+    // 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, "phi");
+    self->model->phi.dispersion->accept_as_destination(visitor, self->model->phi.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "psi");
+    self->model->psi.dispersion->accept_as_destination(visitor, self->model->psi.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "theta");
+    self->model->theta.dispersion->accept_as_destination(visitor, self->model->theta.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(CFCCrystalModelError, 
+	    	"CFCCrystalModel.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(CFCCrystalModelError, 
+                   "CFCCrystalModel.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(CFCCrystalModelError, 
+	    		"CFCCrystalModel.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(CFCCrystalModelError, 
+                   "CFCCrystalModel.evalDistribution expect 2 numpy arrays in list.");
+	        return NULL;
+	     }
+	}
+	PyErr_SetString(CFCCrystalModelError, 
+                   "CFCCrystalModel.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(CFCCrystalModel *self, PyObject *args) {
+	double q_value, phi_value;
+	PyObject* pars;
+	int npars;
+	
+	// Get parameters
+	
+	    // Reader parameter dictionary
+    self->model->phi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "phi") );
+    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
+    self->model->dnn = PyFloat_AsDouble( PyDict_GetItemString(self->params, "dnn") );
+    self->model->sldSph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sldSph") );
+    self->model->d_factor = PyFloat_AsDouble( PyDict_GetItemString(self->params, "d_factor") );
+    self->model->psi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "psi") );
+    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
+    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
+    self->model->theta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "theta") );
+    self->model->sldSolv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sldSolv") );
+    // 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, "phi");
+    self->model->phi.dispersion->accept_as_destination(visitor, self->model->phi.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "psi");
+    self->model->psi.dispersion->accept_as_destination(visitor, self->model->psi.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "theta");
+    self->model->theta.dispersion->accept_as_destination(visitor, self->model->theta.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(CFCCrystalModelError, 
+	    	"CFCCrystalModel.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(CFCCrystalModelError, 
+	    		"CFCCrystalModel.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 = CFCCrystalModel_readDouble(PyList_GET_ITEM(pars,0));
+	    phi_value = CFCCrystalModel_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 = CFCCrystalModel_readDouble(pars);		
+		
+		return Py_BuildValue("d",(*(self->model))(q_value));
+	}	
+}
+/**
+ * Function to call to calculate_ER
+ * @return: effective radius value 
+ */
+static PyObject * calculate_ER(CFCCrystalModel *self) {
+
+	PyObject* pars;
+	int npars;
+	
+	// Get parameters
+	
+	    // Reader parameter dictionary
+    self->model->phi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "phi") );
+    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
+    self->model->dnn = PyFloat_AsDouble( PyDict_GetItemString(self->params, "dnn") );
+    self->model->sldSph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sldSph") );
+    self->model->d_factor = PyFloat_AsDouble( PyDict_GetItemString(self->params, "d_factor") );
+    self->model->psi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "psi") );
+    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
+    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
+    self->model->theta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "theta") );
+    self->model->sldSolv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sldSolv") );
+    // 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, "phi");
+    self->model->phi.dispersion->accept_as_destination(visitor, self->model->phi.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "psi");
+    self->model->psi.dispersion->accept_as_destination(visitor, self->model->psi.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "theta");
+    self->model->theta.dispersion->accept_as_destination(visitor, self->model->theta.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(CFCCrystalModel *self, PyObject *args) {
+	double qx_value, qy_value;
+	PyObject* pars;
+	int npars;
+	
+	// Get parameters
+	
+	    // Reader parameter dictionary
+    self->model->phi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "phi") );
+    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
+    self->model->dnn = PyFloat_AsDouble( PyDict_GetItemString(self->params, "dnn") );
+    self->model->sldSph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sldSph") );
+    self->model->d_factor = PyFloat_AsDouble( PyDict_GetItemString(self->params, "d_factor") );
+    self->model->psi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "psi") );
+    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
+    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
+    self->model->theta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "theta") );
+    self->model->sldSolv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sldSolv") );
+    // 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, "phi");
+    self->model->phi.dispersion->accept_as_destination(visitor, self->model->phi.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "psi");
+    self->model->psi.dispersion->accept_as_destination(visitor, self->model->psi.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "theta");
+    self->model->theta.dispersion->accept_as_destination(visitor, self->model->theta.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(CFCCrystalModelError, 
+	    	"CFCCrystalModel.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(CFCCrystalModelError, 
+	    		"CFCCrystalModel.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 = CFCCrystalModel_readDouble(PyList_GET_ITEM(pars,0));
+	    qy_value = CFCCrystalModel_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 = CFCCrystalModel_readDouble(pars);		
+		
+		return Py_BuildValue("d",(*(self->model))(qx_value));
+	}	
+}
+
+static PyObject * reset(CFCCrystalModel *self, PyObject *args) {
+    
+
+    return Py_BuildValue("d",0.0);
+}
+
+static PyObject * set_dispersion(CFCCrystalModel *self, PyObject *args) {
+	PyObject * disp;
+	const char * par_name;
+
+	if ( !PyArg_ParseTuple(args,"sO", &par_name, &disp) ) {
+	    PyErr_SetString(CFCCrystalModelError,
+	    	"CFCCrystalModel.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, "phi")) {
+        self->model->phi.dispersion = dispersion;
+    } else    if (!strcmp(par_name, "psi")) {
+        self->model->psi.dispersion = dispersion;
+    } else    if (!strcmp(par_name, "theta")) {
+        self->model->theta.dispersion = dispersion;
+    } else {
+	    PyErr_SetString(CFCCrystalModelError,
+	    	"CFCCrystalModel.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 CFCCrystalModel_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 CFCCrystalModelType = {
+    PyObject_HEAD_INIT(NULL)
+    0,                         /*ob_size*/
+    "CFCCrystalModel",             /*tp_name*/
+    sizeof(CFCCrystalModel),             /*tp_basicsize*/
+    0,                         /*tp_itemsize*/
+    (destructor)CFCCrystalModel_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*/
+    "CFCCrystalModel objects",           /* tp_doc */
+    0,		               /* tp_traverse */
+    0,		               /* tp_clear */
+    0,		               /* tp_richcompare */
+    0,		               /* tp_weaklistoffset */
+    0,		               /* tp_iter */
+    0,		               /* tp_iternext */
+    CFCCrystalModel_methods,             /* tp_methods */
+    CFCCrystalModel_members,             /* tp_members */
+    0,                         /* tp_getset */
+    0,                         /* tp_base */
+    0,                         /* tp_dict */
+    0,                         /* tp_descr_get */
+    0,                         /* tp_descr_set */
+    0,                         /* tp_dictoffset */
+    (initproc)CFCCrystalModel_init,      /* tp_init */
+    0,                         /* tp_alloc */
+    CFCCrystalModel_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 addCFCCrystalModel(PyObject *module) {
+	PyObject *d;
+	
+    if (PyType_Ready(&CFCCrystalModelType) < 0)
+        return;
+
+    Py_INCREF(&CFCCrystalModelType);
+    PyModule_AddObject(module, "CFCCrystalModel", (PyObject *)&CFCCrystalModelType);
+    
+    d = PyModule_GetDict(module);
+    CFCCrystalModelError = PyErr_NewException("CFCCrystalModel.error", NULL, NULL);
+    PyDict_SetItemString(d, "CFCCrystalModelError", CFCCrystalModelError);
+}
+
Index: sansmodels/src/sans/models/c_models/CLamellarPCrystalModel.cpp
===================================================================
--- sansmodels/src/sans/models/c_models/CLamellarPCrystalModel.cpp	(revision d5b6a9d7cd9e26b5f9e28e55e8cf848a40de6ae9)
+++ sansmodels/src/sans/models/c_models/CLamellarPCrystalModel.cpp	(revision d5b6a9d7cd9e26b5f9e28e55e8cf848a40de6ae9)
@@ -0,0 +1,568 @@
+/**
+	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
+ */
+
+/** CLamellarPCrystalModel
+ *
+ * C extension 
+ *
+ * WARNING: THIS FILE WAS GENERATED BY WRAPPERGENERATOR.PY
+ *          DO NOT MODIFY THIS FILE, MODIFY lamellarPC.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 "lamellarPC.h"
+}
+
+#include "models.hh"
+#include "dispersion_visitor.hh"
+
+/// Error object for raised exceptions
+static PyObject * CLamellarPCrystalModelError = NULL;
+
+
+// Class definition
+typedef struct {
+    PyObject_HEAD
+    /// Parameters
+    PyObject * params;
+    /// Dispersion parameters
+    PyObject * dispersion;
+    /// Underlying model object
+    LamellarPCrystalModel * model;
+    /// Log for unit testing
+    PyObject * log;
+} CLamellarPCrystalModel;
+
+
+static void
+CLamellarPCrystalModel_dealloc(CLamellarPCrystalModel* 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 *
+CLamellarPCrystalModel_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+    CLamellarPCrystalModel *self;
+    
+    self = (CLamellarPCrystalModel *)type->tp_alloc(type, 0);
+   
+    return (PyObject *)self;
+}
+
+static int
+CLamellarPCrystalModel_init(CLamellarPCrystalModel *self, PyObject *args, PyObject *kwds)
+{
+    if (self != NULL) {
+    	
+    	// Create parameters
+        self->params = PyDict_New();
+        self->dispersion = PyDict_New();
+        self->model = new LamellarPCrystalModel();
+        
+        // Initialize parameter dictionary
+        PyDict_SetItemString(self->params,"Nlayers",Py_BuildValue("d",20.000000000000));
+        PyDict_SetItemString(self->params,"spacing",Py_BuildValue("d",250.000000000000));
+        PyDict_SetItemString(self->params,"sld_solvent",Py_BuildValue("d",0.000006340000));
+        PyDict_SetItemString(self->params,"thickness",Py_BuildValue("d",33.000000000000));
+        PyDict_SetItemString(self->params,"scale",Py_BuildValue("d",1.000000000000));
+        PyDict_SetItemString(self->params,"pd_spacing",Py_BuildValue("d",0.000000000000));
+        PyDict_SetItemString(self->params,"background",Py_BuildValue("d",0.000000000000));
+        PyDict_SetItemString(self->params,"sld_layer",Py_BuildValue("d",0.000001000000));
+        // Initialize dispersion / averaging parameter dict
+        DispersionVisitor* visitor = new DispersionVisitor();
+        PyObject * disp_dict;
+        disp_dict = PyDict_New();
+        self->model->thickness.dispersion->accept_as_source(visitor, self->model->thickness.dispersion, disp_dict);
+        PyDict_SetItemString(self->dispersion, "thickness", disp_dict);
+
+
+         
+        // Create empty log
+        self->log = PyDict_New();
+        
+        
+
+    }
+    return 0;
+}
+
+static PyMemberDef CLamellarPCrystalModel_members[] = {
+    {"params", T_OBJECT, offsetof(CLamellarPCrystalModel, params), 0,
+     "Parameters"},
+	{"dispersion", T_OBJECT, offsetof(CLamellarPCrystalModel, dispersion), 0,
+	  "Dispersion parameters"},     
+    {"log", T_OBJECT, offsetof(CLamellarPCrystalModel, log), 0,
+     "Log"},
+    {NULL}  /* Sentinel */
+};
+
+/** Read double from PyObject
+    @param p PyObject
+    @return double
+*/
+double CLamellarPCrystalModel_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(LamellarPCrystalModel* 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( LamellarPCrystalModel* 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(CLamellarPCrystalModelError, 
+                   "CLamellarPCrystalModel.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(CLamellarPCrystalModel *self, PyObject *args){
+	PyObject *qx, *qy;
+	PyArrayObject * pars;
+	int npars ,mpars;
+	
+	// Get parameters
+	
+	    // Reader parameter dictionary
+    self->model->Nlayers = PyFloat_AsDouble( PyDict_GetItemString(self->params, "Nlayers") );
+    self->model->spacing = PyFloat_AsDouble( PyDict_GetItemString(self->params, "spacing") );
+    self->model->sld_solvent = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solvent") );
+    self->model->thickness = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thickness") );
+    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
+    self->model->pd_spacing = PyFloat_AsDouble( PyDict_GetItemString(self->params, "pd_spacing") );
+    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
+    self->model->sld_layer = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_layer") );
+    // Read in dispersion parameters
+    PyObject* disp_dict;
+    DispersionVisitor* visitor = new DispersionVisitor();
+    disp_dict = PyDict_GetItemString(self->dispersion, "thickness");
+    self->model->thickness.dispersion->accept_as_destination(visitor, self->model->thickness.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(CLamellarPCrystalModelError, 
+	    	"CLamellarPCrystalModel.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(CLamellarPCrystalModelError, 
+                   "CLamellarPCrystalModel.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(CLamellarPCrystalModelError, 
+	    		"CLamellarPCrystalModel.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(CLamellarPCrystalModelError, 
+                   "CLamellarPCrystalModel.evalDistribution expect 2 numpy arrays in list.");
+	        return NULL;
+	     }
+	}
+	PyErr_SetString(CLamellarPCrystalModelError, 
+                   "CLamellarPCrystalModel.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(CLamellarPCrystalModel *self, PyObject *args) {
+	double q_value, phi_value;
+	PyObject* pars;
+	int npars;
+	
+	// Get parameters
+	
+	    // Reader parameter dictionary
+    self->model->Nlayers = PyFloat_AsDouble( PyDict_GetItemString(self->params, "Nlayers") );
+    self->model->spacing = PyFloat_AsDouble( PyDict_GetItemString(self->params, "spacing") );
+    self->model->sld_solvent = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solvent") );
+    self->model->thickness = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thickness") );
+    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
+    self->model->pd_spacing = PyFloat_AsDouble( PyDict_GetItemString(self->params, "pd_spacing") );
+    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
+    self->model->sld_layer = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_layer") );
+    // Read in dispersion parameters
+    PyObject* disp_dict;
+    DispersionVisitor* visitor = new DispersionVisitor();
+    disp_dict = PyDict_GetItemString(self->dispersion, "thickness");
+    self->model->thickness.dispersion->accept_as_destination(visitor, self->model->thickness.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(CLamellarPCrystalModelError, 
+	    	"CLamellarPCrystalModel.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(CLamellarPCrystalModelError, 
+	    		"CLamellarPCrystalModel.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 = CLamellarPCrystalModel_readDouble(PyList_GET_ITEM(pars,0));
+	    phi_value = CLamellarPCrystalModel_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 = CLamellarPCrystalModel_readDouble(pars);		
+		
+		return Py_BuildValue("d",(*(self->model))(q_value));
+	}	
+}
+/**
+ * Function to call to calculate_ER
+ * @return: effective radius value 
+ */
+static PyObject * calculate_ER(CLamellarPCrystalModel *self) {
+
+	PyObject* pars;
+	int npars;
+	
+	// Get parameters
+	
+	    // Reader parameter dictionary
+    self->model->Nlayers = PyFloat_AsDouble( PyDict_GetItemString(self->params, "Nlayers") );
+    self->model->spacing = PyFloat_AsDouble( PyDict_GetItemString(self->params, "spacing") );
+    self->model->sld_solvent = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solvent") );
+    self->model->thickness = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thickness") );
+    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
+    self->model->pd_spacing = PyFloat_AsDouble( PyDict_GetItemString(self->params, "pd_spacing") );
+    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
+    self->model->sld_layer = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_layer") );
+    // Read in dispersion parameters
+    PyObject* disp_dict;
+    DispersionVisitor* visitor = new DispersionVisitor();
+    disp_dict = PyDict_GetItemString(self->dispersion, "thickness");
+    self->model->thickness.dispersion->accept_as_destination(visitor, self->model->thickness.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(CLamellarPCrystalModel *self, PyObject *args) {
+	double qx_value, qy_value;
+	PyObject* pars;
+	int npars;
+	
+	// Get parameters
+	
+	    // Reader parameter dictionary
+    self->model->Nlayers = PyFloat_AsDouble( PyDict_GetItemString(self->params, "Nlayers") );
+    self->model->spacing = PyFloat_AsDouble( PyDict_GetItemString(self->params, "spacing") );
+    self->model->sld_solvent = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_solvent") );
+    self->model->thickness = PyFloat_AsDouble( PyDict_GetItemString(self->params, "thickness") );
+    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
+    self->model->pd_spacing = PyFloat_AsDouble( PyDict_GetItemString(self->params, "pd_spacing") );
+    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
+    self->model->sld_layer = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sld_layer") );
+    // Read in dispersion parameters
+    PyObject* disp_dict;
+    DispersionVisitor* visitor = new DispersionVisitor();
+    disp_dict = PyDict_GetItemString(self->dispersion, "thickness");
+    self->model->thickness.dispersion->accept_as_destination(visitor, self->model->thickness.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(CLamellarPCrystalModelError, 
+	    	"CLamellarPCrystalModel.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(CLamellarPCrystalModelError, 
+	    		"CLamellarPCrystalModel.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 = CLamellarPCrystalModel_readDouble(PyList_GET_ITEM(pars,0));
+	    qy_value = CLamellarPCrystalModel_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 = CLamellarPCrystalModel_readDouble(pars);		
+		
+		return Py_BuildValue("d",(*(self->model))(qx_value));
+	}	
+}
+
+static PyObject * reset(CLamellarPCrystalModel *self, PyObject *args) {
+    
+
+    return Py_BuildValue("d",0.0);
+}
+
+static PyObject * set_dispersion(CLamellarPCrystalModel *self, PyObject *args) {
+	PyObject * disp;
+	const char * par_name;
+
+	if ( !PyArg_ParseTuple(args,"sO", &par_name, &disp) ) {
+	    PyErr_SetString(CLamellarPCrystalModelError,
+	    	"CLamellarPCrystalModel.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, "thickness")) {
+        self->model->thickness.dispersion = dispersion;
+    } else {
+	    PyErr_SetString(CLamellarPCrystalModelError,
+	    	"CLamellarPCrystalModel.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 CLamellarPCrystalModel_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 CLamellarPCrystalModelType = {
+    PyObject_HEAD_INIT(NULL)
+    0,                         /*ob_size*/
+    "CLamellarPCrystalModel",             /*tp_name*/
+    sizeof(CLamellarPCrystalModel),             /*tp_basicsize*/
+    0,                         /*tp_itemsize*/
+    (destructor)CLamellarPCrystalModel_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*/
+    "CLamellarPCrystalModel objects",           /* tp_doc */
+    0,		               /* tp_traverse */
+    0,		               /* tp_clear */
+    0,		               /* tp_richcompare */
+    0,		               /* tp_weaklistoffset */
+    0,		               /* tp_iter */
+    0,		               /* tp_iternext */
+    CLamellarPCrystalModel_methods,             /* tp_methods */
+    CLamellarPCrystalModel_members,             /* tp_members */
+    0,                         /* tp_getset */
+    0,                         /* tp_base */
+    0,                         /* tp_dict */
+    0,                         /* tp_descr_get */
+    0,                         /* tp_descr_set */
+    0,                         /* tp_dictoffset */
+    (initproc)CLamellarPCrystalModel_init,      /* tp_init */
+    0,                         /* tp_alloc */
+    CLamellarPCrystalModel_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 addCLamellarPCrystalModel(PyObject *module) {
+	PyObject *d;
+	
+    if (PyType_Ready(&CLamellarPCrystalModelType) < 0)
+        return;
+
+    Py_INCREF(&CLamellarPCrystalModelType);
+    PyModule_AddObject(module, "CLamellarPCrystalModel", (PyObject *)&CLamellarPCrystalModelType);
+    
+    d = PyModule_GetDict(module);
+    CLamellarPCrystalModelError = PyErr_NewException("CLamellarPCrystalModel.error", NULL, NULL);
+    PyDict_SetItemString(d, "CLamellarPCrystalModelError", CLamellarPCrystalModelError);
+}
+
Index: sansmodels/src/sans/models/c_models/CSCCrystalModel.cpp
===================================================================
--- sansmodels/src/sans/models/c_models/CSCCrystalModel.cpp	(revision d5b6a9d7cd9e26b5f9e28e55e8cf848a40de6ae9)
+++ sansmodels/src/sans/models/c_models/CSCCrystalModel.cpp	(revision d5b6a9d7cd9e26b5f9e28e55e8cf848a40de6ae9)
@@ -0,0 +1,617 @@
+/**
+	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
+ */
+
+/** CSCCrystalModel
+ *
+ * C extension 
+ *
+ * WARNING: THIS FILE WAS GENERATED BY WRAPPERGENERATOR.PY
+ *          DO NOT MODIFY THIS FILE, MODIFY sc.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 "sc.h"
+}
+
+#include "models.hh"
+#include "dispersion_visitor.hh"
+
+/// Error object for raised exceptions
+static PyObject * CSCCrystalModelError = NULL;
+
+
+// Class definition
+typedef struct {
+    PyObject_HEAD
+    /// Parameters
+    PyObject * params;
+    /// Dispersion parameters
+    PyObject * dispersion;
+    /// Underlying model object
+    SCCrystalModel * model;
+    /// Log for unit testing
+    PyObject * log;
+} CSCCrystalModel;
+
+
+static void
+CSCCrystalModel_dealloc(CSCCrystalModel* 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 *
+CSCCrystalModel_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+    CSCCrystalModel *self;
+    
+    self = (CSCCrystalModel *)type->tp_alloc(type, 0);
+   
+    return (PyObject *)self;
+}
+
+static int
+CSCCrystalModel_init(CSCCrystalModel *self, PyObject *args, PyObject *kwds)
+{
+    if (self != NULL) {
+    	
+    	// Create parameters
+        self->params = PyDict_New();
+        self->dispersion = PyDict_New();
+        self->model = new SCCrystalModel();
+        
+        // Initialize parameter dictionary
+        PyDict_SetItemString(self->params,"phi",Py_BuildValue("d",0.000000000000));
+        PyDict_SetItemString(self->params,"scale",Py_BuildValue("d",1.000000000000));
+        PyDict_SetItemString(self->params,"dnn",Py_BuildValue("d",220.000000000000));
+        PyDict_SetItemString(self->params,"sldSph",Py_BuildValue("d",0.000003000000));
+        PyDict_SetItemString(self->params,"d_factor",Py_BuildValue("d",0.060000000000));
+        PyDict_SetItemString(self->params,"psi",Py_BuildValue("d",0.000000000000));
+        PyDict_SetItemString(self->params,"radius",Py_BuildValue("d",40.000000000000));
+        PyDict_SetItemString(self->params,"background",Py_BuildValue("d",0.000000000000));
+        PyDict_SetItemString(self->params,"theta",Py_BuildValue("d",0.000000000000));
+        PyDict_SetItemString(self->params,"sldSolv",Py_BuildValue("d",0.000006300000));
+        // 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->phi.dispersion->accept_as_source(visitor, self->model->phi.dispersion, disp_dict);
+        PyDict_SetItemString(self->dispersion, "phi", disp_dict);
+        disp_dict = PyDict_New();
+        self->model->psi.dispersion->accept_as_source(visitor, self->model->psi.dispersion, disp_dict);
+        PyDict_SetItemString(self->dispersion, "psi", disp_dict);
+        disp_dict = PyDict_New();
+        self->model->theta.dispersion->accept_as_source(visitor, self->model->theta.dispersion, disp_dict);
+        PyDict_SetItemString(self->dispersion, "theta", disp_dict);
+
+
+         
+        // Create empty log
+        self->log = PyDict_New();
+        
+        
+
+    }
+    return 0;
+}
+
+static PyMemberDef CSCCrystalModel_members[] = {
+    {"params", T_OBJECT, offsetof(CSCCrystalModel, params), 0,
+     "Parameters"},
+	{"dispersion", T_OBJECT, offsetof(CSCCrystalModel, dispersion), 0,
+	  "Dispersion parameters"},     
+    {"log", T_OBJECT, offsetof(CSCCrystalModel, log), 0,
+     "Log"},
+    {NULL}  /* Sentinel */
+};
+
+/** Read double from PyObject
+    @param p PyObject
+    @return double
+*/
+double CSCCrystalModel_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(SCCrystalModel* 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( SCCrystalModel* 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(CSCCrystalModelError, 
+                   "CSCCrystalModel.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(CSCCrystalModel *self, PyObject *args){
+	PyObject *qx, *qy;
+	PyArrayObject * pars;
+	int npars ,mpars;
+	
+	// Get parameters
+	
+	    // Reader parameter dictionary
+    self->model->phi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "phi") );
+    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
+    self->model->dnn = PyFloat_AsDouble( PyDict_GetItemString(self->params, "dnn") );
+    self->model->sldSph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sldSph") );
+    self->model->d_factor = PyFloat_AsDouble( PyDict_GetItemString(self->params, "d_factor") );
+    self->model->psi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "psi") );
+    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
+    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
+    self->model->theta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "theta") );
+    self->model->sldSolv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sldSolv") );
+    // 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, "phi");
+    self->model->phi.dispersion->accept_as_destination(visitor, self->model->phi.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "psi");
+    self->model->psi.dispersion->accept_as_destination(visitor, self->model->psi.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "theta");
+    self->model->theta.dispersion->accept_as_destination(visitor, self->model->theta.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(CSCCrystalModelError, 
+	    	"CSCCrystalModel.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(CSCCrystalModelError, 
+                   "CSCCrystalModel.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(CSCCrystalModelError, 
+	    		"CSCCrystalModel.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(CSCCrystalModelError, 
+                   "CSCCrystalModel.evalDistribution expect 2 numpy arrays in list.");
+	        return NULL;
+	     }
+	}
+	PyErr_SetString(CSCCrystalModelError, 
+                   "CSCCrystalModel.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(CSCCrystalModel *self, PyObject *args) {
+	double q_value, phi_value;
+	PyObject* pars;
+	int npars;
+	
+	// Get parameters
+	
+	    // Reader parameter dictionary
+    self->model->phi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "phi") );
+    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
+    self->model->dnn = PyFloat_AsDouble( PyDict_GetItemString(self->params, "dnn") );
+    self->model->sldSph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sldSph") );
+    self->model->d_factor = PyFloat_AsDouble( PyDict_GetItemString(self->params, "d_factor") );
+    self->model->psi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "psi") );
+    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
+    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
+    self->model->theta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "theta") );
+    self->model->sldSolv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sldSolv") );
+    // 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, "phi");
+    self->model->phi.dispersion->accept_as_destination(visitor, self->model->phi.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "psi");
+    self->model->psi.dispersion->accept_as_destination(visitor, self->model->psi.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "theta");
+    self->model->theta.dispersion->accept_as_destination(visitor, self->model->theta.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(CSCCrystalModelError, 
+	    	"CSCCrystalModel.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(CSCCrystalModelError, 
+	    		"CSCCrystalModel.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 = CSCCrystalModel_readDouble(PyList_GET_ITEM(pars,0));
+	    phi_value = CSCCrystalModel_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 = CSCCrystalModel_readDouble(pars);		
+		
+		return Py_BuildValue("d",(*(self->model))(q_value));
+	}	
+}
+/**
+ * Function to call to calculate_ER
+ * @return: effective radius value 
+ */
+static PyObject * calculate_ER(CSCCrystalModel *self) {
+
+	PyObject* pars;
+	int npars;
+	
+	// Get parameters
+	
+	    // Reader parameter dictionary
+    self->model->phi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "phi") );
+    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
+    self->model->dnn = PyFloat_AsDouble( PyDict_GetItemString(self->params, "dnn") );
+    self->model->sldSph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sldSph") );
+    self->model->d_factor = PyFloat_AsDouble( PyDict_GetItemString(self->params, "d_factor") );
+    self->model->psi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "psi") );
+    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
+    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
+    self->model->theta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "theta") );
+    self->model->sldSolv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sldSolv") );
+    // 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, "phi");
+    self->model->phi.dispersion->accept_as_destination(visitor, self->model->phi.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "psi");
+    self->model->psi.dispersion->accept_as_destination(visitor, self->model->psi.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "theta");
+    self->model->theta.dispersion->accept_as_destination(visitor, self->model->theta.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(CSCCrystalModel *self, PyObject *args) {
+	double qx_value, qy_value;
+	PyObject* pars;
+	int npars;
+	
+	// Get parameters
+	
+	    // Reader parameter dictionary
+    self->model->phi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "phi") );
+    self->model->scale = PyFloat_AsDouble( PyDict_GetItemString(self->params, "scale") );
+    self->model->dnn = PyFloat_AsDouble( PyDict_GetItemString(self->params, "dnn") );
+    self->model->sldSph = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sldSph") );
+    self->model->d_factor = PyFloat_AsDouble( PyDict_GetItemString(self->params, "d_factor") );
+    self->model->psi = PyFloat_AsDouble( PyDict_GetItemString(self->params, "psi") );
+    self->model->radius = PyFloat_AsDouble( PyDict_GetItemString(self->params, "radius") );
+    self->model->background = PyFloat_AsDouble( PyDict_GetItemString(self->params, "background") );
+    self->model->theta = PyFloat_AsDouble( PyDict_GetItemString(self->params, "theta") );
+    self->model->sldSolv = PyFloat_AsDouble( PyDict_GetItemString(self->params, "sldSolv") );
+    // 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, "phi");
+    self->model->phi.dispersion->accept_as_destination(visitor, self->model->phi.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "psi");
+    self->model->psi.dispersion->accept_as_destination(visitor, self->model->psi.dispersion, disp_dict);
+    disp_dict = PyDict_GetItemString(self->dispersion, "theta");
+    self->model->theta.dispersion->accept_as_destination(visitor, self->model->theta.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(CSCCrystalModelError, 
+	    	"CSCCrystalModel.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(CSCCrystalModelError, 
+	    		"CSCCrystalModel.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 = CSCCrystalModel_readDouble(PyList_GET_ITEM(pars,0));
+	    qy_value = CSCCrystalModel_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 = CSCCrystalModel_readDouble(pars);		
+		
+		return Py_BuildValue("d",(*(self->model))(qx_value));
+	}	
+}
+
+static PyObject * reset(CSCCrystalModel *self, PyObject *args) {
+    
+
+    return Py_BuildValue("d",0.0);
+}
+
+static PyObject * set_dispersion(CSCCrystalModel *self, PyObject *args) {
+	PyObject * disp;
+	const char * par_name;
+
+	if ( !PyArg_ParseTuple(args,"sO", &par_name, &disp) ) {
+	    PyErr_SetString(CSCCrystalModelError,
+	    	"CSCCrystalModel.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, "phi")) {
+        self->model->phi.dispersion = dispersion;
+    } else    if (!strcmp(par_name, "psi")) {
+        self->model->psi.dispersion = dispersion;
+    } else    if (!strcmp(par_name, "theta")) {
+        self->model->theta.dispersion = dispersion;
+    } else {
+	    PyErr_SetString(CSCCrystalModelError,
+	    	"CSCCrystalModel.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 CSCCrystalModel_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 CSCCrystalModelType = {
+    PyObject_HEAD_INIT(NULL)
+    0,                         /*ob_size*/
+    "CSCCrystalModel",             /*tp_name*/
+    sizeof(CSCCrystalModel),             /*tp_basicsize*/
+    0,                         /*tp_itemsize*/
+    (destructor)CSCCrystalModel_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*/
+    "CSCCrystalModel objects",           /* tp_doc */
+    0,		               /* tp_traverse */
+    0,		               /* tp_clear */
+    0,		               /* tp_richcompare */
+    0,		               /* tp_weaklistoffset */
+    0,		               /* tp_iter */
+    0,		               /* tp_iternext */
+    CSCCrystalModel_methods,             /* tp_methods */
+    CSCCrystalModel_members,             /* tp_members */
+    0,                         /* tp_getset */
+    0,                         /* tp_base */
+    0,                         /* tp_dict */
+    0,                         /* tp_descr_get */
+    0,                         /* tp_descr_set */
+    0,                         /* tp_dictoffset */
+    (initproc)CSCCrystalModel_init,      /* tp_init */
+    0,                         /* tp_alloc */
+    CSCCrystalModel_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 addCSCCrystalModel(PyObject *module) {
+	PyObject *d;
+	
+    if (PyType_Ready(&CSCCrystalModelType) < 0)
+        return;
+
+    Py_INCREF(&CSCCrystalModelType);
+    PyModule_AddObject(module, "CSCCrystalModel", (PyObject *)&CSCCrystalModelType);
+    
+    d = PyModule_GetDict(module);
+    CSCCrystalModelError = PyErr_NewException("CSCCrystalModel.error", NULL, NULL);
+    PyDict_SetItemString(d, "CSCCrystalModelError", CSCCrystalModelError);
+}
+
Index: sansmodels/src/sans/models/c_models/bcc.cpp
===================================================================
--- sansmodels/src/sans/models/c_models/bcc.cpp	(revision d5b6a9d7cd9e26b5f9e28e55e8cf848a40de6ae9)
+++ sansmodels/src/sans/models/c_models/bcc.cpp	(revision d5b6a9d7cd9e26b5f9e28e55e8cf848a40de6ae9)
@@ -0,0 +1,209 @@
+/**
+	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
+ */
+
+/**
+ * Scattering model classes
+ * The classes use the IGOR library found in
+ *   sansmodels/src/libigor
+ *
+ */
+
+#include <math.h>
+#include "models.hh"
+#include "parameters.hh"
+#include <stdio.h>
+using namespace std;
+
+extern "C" {
+	#include "libSphere.h"
+	#include "bcc.h"
+}
+
+BCCrystalModel :: BCCrystalModel() {
+	scale      = Parameter(1.0);
+	dnn		= Parameter(220.0);
+	d_factor = Parameter(0.06);
+	radius     = Parameter(40.0, true);
+	radius.set_min(0.0);
+	sldSph   = Parameter(3.0e-6);
+	sldSolv   = Parameter(6.3e-6);
+	background = Parameter(0.0);
+	theta  = Parameter(0.0, true);
+	phi    = Parameter(0.0, true);
+	psi    = Parameter(0.0, true);
+}
+
+/**
+ * Function to evaluate 1D scattering function
+ * The NIST IGOR library is used for the actual calculation.
+ * @param q: q-value
+ * @return: function value
+ */
+double BCCrystalModel :: operator()(double q) {
+	double dp[7];
+
+	// Fill parameter array for IGOR library
+	// Add the background after averaging
+	dp[0] = scale();
+	dp[1] = dnn();
+	dp[2] = d_factor();
+	dp[3] = radius();
+	dp[4] = sldSph();
+	dp[5] = sldSolv();
+	dp[6] = 0.0;
+
+	// Get the dispersion points for the radius
+	vector<WeightPoint> weights_rad;
+	radius.get_weights(weights_rad);
+
+	// Perform the computation, with all weight points
+	double sum = 0.0;
+	double norm = 0.0;
+	double vol = 0.0;
+	double result;
+
+	// Loop over radius weight points
+	for(int i=0; i<weights_rad.size(); i++) {
+		dp[3] = weights_rad[i].value;
+
+		//Un-normalize SphereForm by volume
+		result = BCC_ParaCrystal(dp, q) * pow(weights_rad[i].value,3);
+		// This FIXES a singualrity in the kernel in libigor.
+		if ( result == INFINITY || result == NAN){
+			result = 0.0;
+		}
+		sum += weights_rad[i].weight
+			* result;
+		//Find average volume
+		vol += weights_rad[i].weight
+			* pow(weights_rad[i].value,3);
+
+		norm += weights_rad[i].weight;
+	}
+
+	if (vol != 0.0 && norm != 0.0) {
+		//Re-normalize by avg volume
+		sum = sum/(vol/norm);}
+	return sum/norm + background();
+}
+
+/**
+ * Function to evaluate 2D scattering function
+ * @param q_x: value of Q along x
+ * @param q_y: value of Q along y
+ * @return: function value
+ */
+double BCCrystalModel :: operator()(double qx, double qy) {
+	BCParameters dp;
+	double q = sqrt(qx*qx + qy*qy);
+	dp.scale      = scale();
+	dp.dnn   = dnn();
+	dp.d_factor   = d_factor();
+	dp.radius  = radius();
+	dp.sldSph   = sldSph();
+	dp.sldSolv   = sldSolv();
+	dp.background = 0.0;
+	dp.theta  = theta();
+	dp.phi    = phi();
+	dp.psi    = psi();
+
+	// Get the dispersion points for the radius
+	vector<WeightPoint> weights_rad;
+	radius.get_weights(weights_rad);
+
+	// Get angular averaging for theta
+	vector<WeightPoint> weights_theta;
+	theta.get_weights(weights_theta);
+
+	// Get angular averaging for phi
+	vector<WeightPoint> weights_phi;
+	phi.get_weights(weights_phi);
+
+	// Get angular averaging for psi
+	vector<WeightPoint> weights_psi;
+	psi.get_weights(weights_psi);
+
+	// Perform the computation, with all weight points
+	double sum = 0.0;
+	double norm = 0.0;
+	double norm_vol = 0.0;
+	double vol = 0.0;
+
+	// Loop over radius weight points
+	for(int i=0; i<weights_rad.size(); i++) {
+		dp.radius = weights_rad[i].value;
+		// Average over theta distribution
+		for(int j=0; j< weights_theta.size(); j++) {
+			dp.theta = weights_theta[j].value;
+			// Average over phi distribution
+			for(int k=0; k< weights_phi.size(); k++) {
+				dp.phi = weights_phi[k].value;
+				// Average over phi distribution
+				for(int l=0; l< weights_psi.size(); l++) {
+					dp.psi = weights_psi[l].value;
+					//Un-normalize SphereForm by volume
+					double _ptvalue = weights_rad[i].weight
+										* weights_theta[j].weight
+										* weights_phi[k].weight
+										* weights_psi[l].weight
+										* bc_analytical_2DXY(&dp, qx, qy);
+										//* pow(weights_rad[i].value,3.0);
+					// Consider when there is infinity or nan.
+					// Actual value for this singular point are typically zero.
+					if ( _ptvalue == INFINITY || _ptvalue == NAN){
+						_ptvalue = 0.0;
+					}
+					if (weights_theta.size()>1) {
+						_ptvalue *= sin(weights_theta[j].value);
+					}
+					sum += _ptvalue;
+					// This model dose not need the volume of spheres correction!!!
+					norm += weights_rad[i].weight
+							* weights_theta[j].weight
+							* weights_phi[k].weight
+							* weights_psi[l].weight;
+				}
+			}
+		}
+	}
+	// Averaging in theta needs an extra normalization
+	// factor to account for the sin(theta) term in the
+	// integration (see documentation).
+	if (weights_theta.size()>1) norm = norm / asin(1.0);
+
+	if (vol != 0.0 && norm_vol != 0.0) {
+		//Re-normalize by avg volume
+		sum = sum/(vol/norm_vol);}
+
+	return sum/norm + background();
+}
+
+/**
+ * Function to evaluate 2D scattering function
+ * @param pars: parameters of the BCCCrystal
+ * @param q: q-value
+ * @param phi: angle phi
+ * @return: function value
+ */
+double BCCrystalModel :: evaluate_rphi(double q, double phi) {
+	return (*this).operator()(q);
+}
+
+/**
+ * Function to calculate effective radius
+ * @return: effective radius value
+ */
+double BCCrystalModel :: calculate_ER() {
+	//NOT implemented yet!!!
+}
Index: sansmodels/src/sans/models/c_models/c_models.cpp
===================================================================
--- sansmodels/src/sans/models/c_models/c_models.cpp	(revision 94a3f8f49326fa54618105cf9c371ebe39bb3dda)
+++ sansmodels/src/sans/models/c_models/c_models.cpp	(revision d5b6a9d7cd9e26b5f9e28e55e8cf848a40de6ae9)
@@ -21,4 +21,6 @@
 void addCStickyHSStructure(PyObject *module);
 void addCSCCrystalModel(PyObject *module);
+void addCFCCrystalModel(PyObject *module);
+void addCBCCrystalModel(PyObject *module);
 void addCSquareWellStructure(PyObject *module);
 void addCHayterMSAStructure(PyObject *module);
@@ -34,4 +36,5 @@
 void addCLamellarPSModel(PyObject *module);
 void addCLamellarPSHGModel(PyObject *module);
+void addCLamellarPCrystalModel(PyObject *module);
 void addCCoreShellEllipsoidModel(PyObject *module);
 void addCDiamEllipFunc(PyObject *module);
@@ -231,4 +234,6 @@
 	addCStickyHSStructure(m);
 	addCSCCrystalModel(m);
+	addCFCCrystalModel(m);
+	addCBCCrystalModel(m);
 	addCSquareWellStructure(m);
 	addCHayterMSAStructure(m);
@@ -240,4 +245,5 @@
 	addCLamellarPSModel(m);
 	addCLamellarPSHGModel(m);
+	addCLamellarPCrystalModel(m);
 	addCCoreShellEllipsoidModel(m);
 	addCDiamEllipFunc(m);
Index: sansmodels/src/sans/models/c_models/fcc.cpp
===================================================================
--- sansmodels/src/sans/models/c_models/fcc.cpp	(revision d5b6a9d7cd9e26b5f9e28e55e8cf848a40de6ae9)
+++ sansmodels/src/sans/models/c_models/fcc.cpp	(revision d5b6a9d7cd9e26b5f9e28e55e8cf848a40de6ae9)
@@ -0,0 +1,208 @@
+/**
+	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
+ */
+
+/**
+ * Scattering model classes
+ * The classes use the IGOR library found in
+ *   sansmodels/src/libigor
+ *
+ */
+
+#include <math.h>
+#include "models.hh"
+#include "parameters.hh"
+#include <stdio.h>
+using namespace std;
+
+extern "C" {
+	#include "libSphere.h"
+	#include "fcc.h"
+}
+
+FCCrystalModel :: FCCrystalModel() {
+	scale      = Parameter(1.0);
+	dnn		= Parameter(220.0);
+	d_factor = Parameter(0.06);
+	radius     = Parameter(40.0, true);
+	radius.set_min(0.0);
+	sldSph   = Parameter(3.0e-6);
+	sldSolv   = Parameter(6.3e-6);
+	background = Parameter(0.0);
+	theta  = Parameter(0.0, true);
+	phi    = Parameter(0.0, true);
+	psi    = Parameter(0.0, true);
+}
+
+/**
+ * Function to evaluate 1D scattering function
+ * The NIST IGOR library is used for the actual calculation.
+ * @param q: q-value
+ * @return: function value
+ */
+double FCCrystalModel :: operator()(double q) {
+	double dp[7];
+
+	// Fill parameter array for IGOR library
+	// Add the background after averaging
+	dp[0] = scale();
+	dp[1] = dnn();
+	dp[2] = d_factor();
+	dp[3] = radius();
+	dp[4] = sldSph();
+	dp[5] = sldSolv();
+	dp[6] = 0.0;
+
+	// Get the dispersion points for the radius
+	vector<WeightPoint> weights_rad;
+	radius.get_weights(weights_rad);
+
+	// Perform the computation, with all weight points
+	double sum = 0.0;
+	double norm = 0.0;
+	double vol = 0.0;
+	double result;
+
+	// Loop over radius weight points
+	for(int i=0; i<weights_rad.size(); i++) {
+		dp[3] = weights_rad[i].value;
+
+		//Un-normalize SphereForm by volume
+		result = FCC_ParaCrystal(dp, q) * pow(weights_rad[i].value,3);
+		// This FIXES a singualrity the kernel in libigor.
+		if ( result == INFINITY || result == NAN){
+			result = 0.0;
+		}
+		sum += weights_rad[i].weight
+			* result;
+		//Find average volume
+		vol += weights_rad[i].weight
+			* pow(weights_rad[i].value,3);
+
+		norm += weights_rad[i].weight;
+	}
+
+	if (vol != 0.0 && norm != 0.0) {
+		//Re-normalize by avg volume
+		sum = sum/(vol/norm);}
+	return sum/norm + background();
+}
+
+/**
+ * Function to evaluate 2D scattering function
+ * @param q_x: value of Q along x
+ * @param q_y: value of Q along y
+ * @return: function value
+ */
+double FCCrystalModel :: operator()(double qx, double qy) {
+	FCParameters dp;
+	double q = sqrt(qx*qx + qy*qy);
+	dp.scale      = scale();
+	dp.dnn   = dnn();
+	dp.d_factor   = d_factor();
+	dp.radius  = radius();
+	dp.sldSph   = sldSph();
+	dp.sldSolv   = sldSolv();
+	dp.background = 0.0;
+	dp.theta  = theta();
+	dp.phi    = phi();
+	dp.psi    = psi();
+
+	// Get the dispersion points for the radius
+	vector<WeightPoint> weights_rad;
+	radius.get_weights(weights_rad);
+
+	// Get angular averaging for theta
+	vector<WeightPoint> weights_theta;
+	theta.get_weights(weights_theta);
+
+	// Get angular averaging for phi
+	vector<WeightPoint> weights_phi;
+	phi.get_weights(weights_phi);
+
+	// Get angular averaging for psi
+	vector<WeightPoint> weights_psi;
+	psi.get_weights(weights_psi);
+
+	// Perform the computation, with all weight points
+	double sum = 0.0;
+	double norm = 0.0;
+	double norm_vol = 0.0;
+	double vol = 0.0;
+
+	// Loop over radius weight points
+	for(int i=0; i<weights_rad.size(); i++) {
+		dp.radius = weights_rad[i].value;
+		// Average over theta distribution
+		for(int j=0; j< weights_theta.size(); j++) {
+			dp.theta = weights_theta[j].value;
+			// Average over phi distribution
+			for(int k=0; k< weights_phi.size(); k++) {
+				dp.phi = weights_phi[k].value;
+				// Average over phi distribution
+				for(int l=0; l< weights_psi.size(); l++) {
+					dp.psi = weights_psi[l].value;
+					//Un-normalize SphereForm by volume
+					double _ptvalue = weights_rad[i].weight
+										* weights_theta[j].weight
+										* weights_phi[k].weight
+										* weights_psi[l].weight
+										* fc_analytical_2DXY(&dp, qx, qy);
+										//* pow(weights_rad[i].value,3.0);
+					// Consider when there is infinte or nan.
+					if ( _ptvalue == INFINITY || _ptvalue == NAN){
+						_ptvalue = 0.0;
+					}
+					if (weights_theta.size()>1) {
+						_ptvalue *= sin(weights_theta[j].value);
+					}
+					sum += _ptvalue;
+					// This model dose not need the volume of spheres correction!!!
+					norm += weights_rad[i].weight
+							* weights_theta[j].weight
+							* weights_phi[k].weight
+							* weights_psi[l].weight;
+				}
+			}
+		}
+	}
+	// Averaging in theta needs an extra normalization
+	// factor to account for the sin(theta) term in the
+	// integration (see documentation).
+	if (weights_theta.size()>1) norm = norm / asin(1.0);
+
+	if (vol != 0.0 && norm_vol != 0.0) {
+		//Re-normalize by avg volume
+		sum = sum/(vol/norm_vol);}
+
+	return sum/norm + background();
+}
+
+/**
+ * Function to evaluate 2D scattering function
+ * @param pars: parameters of the FCCCrystal
+ * @param q: q-value
+ * @param phi: angle phi
+ * @return: function value
+ */
+double FCCrystalModel :: evaluate_rphi(double q, double phi) {
+	return (*this).operator()(q);
+}
+
+/**
+ * Function to calculate effective radius
+ * @return: effective radius value
+ */
+double FCCrystalModel :: calculate_ER() {
+	//NOT implemented yet!!!
+}
Index: sansmodels/src/sans/models/c_models/models.hh
===================================================================
--- sansmodels/src/sans/models/c_models/models.hh	(revision 94a3f8f49326fa54618105cf9c371ebe39bb3dda)
+++ sansmodels/src/sans/models/c_models/models.hh	(revision d5b6a9d7cd9e26b5f9e28e55e8cf848a40de6ae9)
@@ -303,4 +303,54 @@
 	// Constructor
 	SCCrystalModel();
+
+	// Operators to get I(Q)
+	double operator()(double q);
+	double operator()(double qx, double qy);
+	double calculate_ER();
+	double evaluate_rphi(double q, double phi);
+};
+
+
+class FCCrystalModel{
+public:
+	// Model parameters
+	Parameter scale;
+	Parameter dnn;
+	Parameter d_factor;
+	Parameter radius;
+	Parameter sldSph;
+	Parameter sldSolv;
+	Parameter background;
+	Parameter theta;
+	Parameter phi;
+	Parameter psi;
+
+	// Constructor
+	FCCrystalModel();
+
+	// Operators to get I(Q)
+	double operator()(double q);
+	double operator()(double qx, double qy);
+	double calculate_ER();
+	double evaluate_rphi(double q, double phi);
+};
+
+
+class BCCrystalModel{
+public:
+	// Model parameters
+	Parameter scale;
+	Parameter dnn;
+	Parameter d_factor;
+	Parameter radius;
+	Parameter sldSph;
+	Parameter sldSolv;
+	Parameter background;
+	Parameter theta;
+	Parameter phi;
+	Parameter psi;
+
+	// Constructor
+	BCCrystalModel();
 
 	// Operators to get I(Q)
@@ -736,4 +786,27 @@
 };
 
+
+class LamellarPCrystalModel{
+public:
+	// Model parameters
+	Parameter scale;
+	Parameter thickness;
+	Parameter Nlayers;
+	Parameter spacing;
+	Parameter pd_spacing;
+	Parameter sld_layer;
+	Parameter sld_solvent;
+	Parameter background;
+
+	// Constructor
+	LamellarPCrystalModel();
+
+	// Operators to get I(Q)
+	double operator()(double q);
+	double operator()(double qx, double qy);
+	double calculate_ER();
+	double evaluate_rphi(double q, double phi);
+};
+
 class CoreShellEllipsoidModel{
 public:
