Index: calculatorview/perspectives/calculator/sld_panel.py
===================================================================
--- calculatorview/perspectives/calculator/sld_panel.py	(revision edb3a5d0510cc6410116e5b3f252b0d227f96fe5)
+++ calculatorview/perspectives/calculator/sld_panel.py	(revision 810f196fd1b147a38b926adc3e1bda37eb7429cb)
@@ -9,6 +9,13 @@
 from sans.guiframe.utils import format_number, check_float
 from sans.guicomm.events import StatusEvent  
-from sans.calculator.sld_calculator import SldCalculator
-
+
+# the calculator default value for wavelength is 6
+import periodictable
+from periodictable import formula
+from periodictable.xsf import xray_energy, xray_sld_from_atoms
+from periodictable.constants import avogadro_number
+from  periodictable.nsf import neutron_scattering
+       
+WAVELENGTH = 6.0
 _BOX_WIDTH = 76
 _STATICBOX_WIDTH = 350
@@ -35,19 +42,16 @@
     ## Flag to tell the AUI manager to put this panel in the center pane
     CENTER_PANE = True
-    def __init__(self, parent,base=None, id = -1):
+    def __init__(self, parent, base=None, id=-1):
         wx.Panel.__init__(self, parent, id = id)
         #Font size 
         self.SetWindowVariant(variant=FONT_VARIANT)
-        
         # Object that receive status event
         self.base = base
-        self.calculator = SldCalculator()
-        self.wavelength = self.calculator.wavelength
-        
+        self.wavelength = WAVELENGTH
+        #Draw the panel
         self._do_layout()
         self.SetAutoLayout(True)
         self.Layout()
        
-
     def _do_layout(self):
         """
@@ -146,7 +150,5 @@
         self.neutron_inc_ctl.SetToolTipString("Neutron Inc. Xs")
         neutron_inc_units_txt = wx.StaticText(self, -1,  unit_cm1)
-        neutron_inc_txt.Hide()
-        self.neutron_inc_ctl.Hide()
-        neutron_inc_units_txt.Hide()
+       
         neutron_abs_txt = wx.StaticText(self, -1, 'Neutron Abs. Xs')     
         self.neutron_abs_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1))
@@ -154,7 +156,5 @@
         self.neutron_abs_ctl.SetToolTipString("Neutron Abs. Xs")
         neutron_abs_units_txt = wx.StaticText(self, -1,  unit_cm1)
-        neutron_abs_txt.Hide()
-        self.neutron_abs_ctl.Hide()
-        neutron_abs_units_txt.Hide()
+      
         neutron_length_txt = wx.StaticText(self, -1, 'Neutron 1/e length')
         self.neutron_length_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1))
@@ -162,7 +162,5 @@
         self.neutron_length_ctl.SetToolTipString("Neutron 1/e length")
         neutron_length_units_txt = wx.StaticText(self, -1,  unit_cm)
-        neutron_length_txt.Hide()
-        self.neutron_length_ctl.Hide()
-        neutron_length_units_txt.Hide()
+      
         iy = 0
         ix = 0
@@ -263,5 +261,19 @@
         self.SetSizer(vbox)
         
-        
+    def calculate_xray_sld(self, element):
+        """
+        Get an element and compute the corresponding SLD for a given formula
+        :param element:  elements a string of existing atom
+        """
+        myformula = formula(str(element))
+        if len(myformula.atoms) != 1:
+            return 
+        element = myformula.atoms.keys()[0] 
+        energy = xray_energy(element.K_alpha)
+        
+        self.sld_formula = formula(str(user_formula), density=self.density)
+        atom = self.sld_formula.atoms
+        return xray_sld_from_atoms(atom, density=self.density, energy= energy)
+    
     def check_inputs(self):
         """Check validity user inputs"""
@@ -276,5 +288,5 @@
         self.wavelength = self.wavelength_ctl.GetValue()
         if self.wavelength.lstrip().rstrip() == "":
-            self.wavelength = self.calculator.wavelength
+            self.wavelength = WAVELENGTH
         else:
             if check_float(self.wavelength_ctl):
@@ -282,8 +294,8 @@
             else:
                 flag = False
-                raise ValueError,"Error for wavelenth value :expect float"
+                raise ValueError,"Error for wavelength value :expect float"
                 
-        self.formulata_text = self.compound_ctl.GetValue().lstrip().rstrip()
-        if self.formulata_text != "":
+        self.compound = self.compound_ctl.GetValue().lstrip().rstrip()
+        if self.compound != "":
             self.compound_ctl.SetBackgroundColour(wx.WHITE)
             self.compound_ctl.Refresh()
@@ -295,4 +307,20 @@
         return flag 
         
+    def calculate_sld_helper(self, element, density, molecule_formula):
+        """
+        Get an element and compute the corresponding SLD for a given formula
+        
+        :param element:  elements a string of existing atom
+        
+        """
+        element_formula = formula(str(element))
+        if len(element_formula.atoms) != 1:
+            return 
+        element = element_formula.atoms.keys()[0] 
+        energy = xray_energy(element.K_alpha)
+        atom = molecule_formula.atoms
+        return xray_sld_from_atoms(atom, density=density, energy=energy)
+
+
     def calculateSld(self, event):
         """
@@ -304,6 +332,5 @@
                 #get ready to compute
                 try:
-                    self.calculator.set_value(self.formulata_text,
-                                              self.density, self.wavelength)
+                    self.sld_formula = formula(self.compound, density=self.density)
                 except:
                     if self.base is not None:
@@ -314,23 +341,25 @@
                     return
                 
+                
+                (sld_real, sld_im, sld_inc), (coh,absorp,incoh), \
+                            length = neutron_scattering(self.compound,
+                                       self.density, self.wavelength) 
+                Cu_reel, Cu_im = self.calculate_sld_helper(element="Cu",
+                                                     density=self.density,
+                                            molecule_formula=self.sld_formula)
+                Mo_reel, Mo_im = self.calculate_sld_helper(element="Mo", 
+                                                           density=self.density,
+                                         molecule_formula=self.sld_formula)
+                # set neutron sld values
+                self.neutron_sld_reel_ctl.SetValue(format_number(sld_real * _SCALE))
+                self.neutron_sld_im_ctl.SetValue(format_number(sld_im * _SCALE))
                 # Compute the Cu SLD
-                Cu_reel, Cu_im = self.calculator.calculate_xray_sld( "Cu")
                 self.cu_ka_sld_reel_ctl.SetValue(format_number(Cu_reel *_SCALE))
                 self.cu_ka_sld_im_ctl.SetValue(format_number(Cu_im * _SCALE))
-                
                 # Compute the Mo SLD
-                Mo_reel, Mo_im = self.calculator.calculate_xray_sld( "Mo")
                 self.mo_ka_sld_reel_ctl.SetValue(format_number(Mo_reel *_SCALE))
                 self.mo_ka_sld_im_ctl.SetValue(format_number(Mo_im * _SCALE))
-               
-                sld_real, sld_im, inc = self.calculator.calculate_neutron_sld()
-                length = self.calculator.calculate_length()
-                # Neutron SLD
-                #need to be compute by element package
-                absorp = 1.0 
-                length = 1.0
-                self.neutron_sld_reel_ctl.SetValue(format_number(sld_real * _SCALE))
-                self.neutron_sld_im_ctl.SetValue(format_number(sld_im * _SCALE))
-                self.neutron_inc_ctl.SetValue(format_number(inc))
+                # set incoherence and absorption
+                self.neutron_inc_ctl.SetValue(format_number(incoh))
                 self.neutron_abs_ctl.SetValue(format_number(absorp))
                 # Neutron length
@@ -347,11 +376,4 @@
 
    
-        
-  
-    
-   
- 
-        
-               
 class SldWindow(wx.Frame):
     def __init__(self, parent=None, id=1, title="SLD Calculator",base=None):
Index: calculatorview/test/utest_sld.py
===================================================================
--- calculatorview/test/utest_sld.py	(revision 810f196fd1b147a38b926adc3e1bda37eb7429cb)
+++ calculatorview/test/utest_sld.py	(revision 810f196fd1b147a38b926adc3e1bda37eb7429cb)
@@ -0,0 +1,148 @@
+
+import unittest
+
+_SCALE = 1e-6
+
+# the calculator default value for wavelength is 6
+import periodictable
+from periodictable import formula
+from periodictable.xsf import xray_energy, xray_sld_from_atoms
+from periodictable.constants import avogadro_number
+from  periodictable.nsf import neutron_scattering, neutron_sld
+       
+
+def calculate_xray_sld(element, density, molecule_formula):
+    """
+    Get an element and compute the corresponding SLD for a given formula
+    :param element:  elements a string of existing atom
+    """
+    element_formula = formula(str(element))
+    if len(element_formula.atoms) != 1:
+        return 
+    element = element_formula.atoms.keys()[0] 
+    energy = xray_energy(element.K_alpha)
+    atom = molecule_formula.atoms
+    return xray_sld_from_atoms(atom, density=density, energy=energy)
+
+
+class TestH2O(unittest.TestCase):
+    """
+    Sld calculator test for H2O
+    """
+    
+    def setUp(self):
+        """Inititialze variables"""
+        
+        self.compound = "H2O"
+        self.density = 1.0
+        self.wavelength = 6.0
+        self.sld_formula = formula(self.compound, density=self.density)
+    
+    def test_neutron_sld(self):
+        """
+        test sld 
+        """
+        #Compute incoherence , absorption, and incoherence
+        (sld_real,sld_im,sld_inc), (coh,abs,incoh), length = neutron_scattering(self.compound,
+                                       self.density, self.wavelength) 
+        cu_reel, cu_im = calculate_xray_sld(element="Cu", density=self.density,
+                                  molecule_formula=self.sld_formula)
+        mo_reel, mo_im = calculate_xray_sld(element="Mo", density=self.density,
+                                  molecule_formula=self.sld_formula)
+        #test sld 
+        self.assertAlmostEquals(sld_real * _SCALE, -5.6e-7, 1)
+        self.assertAlmostEquals(sld_im * _SCALE, 0)
+        #test absorption value
+        self.assertAlmostEquals(abs, 0.0741, 2)
+        self.assertAlmostEquals(incoh, 5.62, 2)
+        #Test length
+        self.assertAlmostEquals(length, 0.1755, 3)
+        #test Cu sld
+        self.assertAlmostEquals(cu_reel * _SCALE, 9.46e-6, 1)
+        self.assertAlmostEquals(cu_im * _SCALE, 3.01e-8)
+        # test Mo sld
+        self.assertAlmostEquals(mo_reel * _SCALE, 9.43e-6)
+        self.assertAlmostEquals(mo_im * _SCALE, 5.65e-7,1)
+    
+    
+class TestD2O(unittest.TestCase):
+    """
+    Sld calculator test for D2O
+    """
+    
+    def setUp(self):
+        """Inititialze variables"""
+        
+        self.compound = "D2O"
+        self.density = 1.1
+        self.wavelength = 6.0
+        self.sld_formula = formula(self.compound, density=self.density)
+    
+    def test_neutron_sld(self):
+        """
+        test sld 
+        """
+        #Compute incoherence , absorption, and incoherence
+        (sld_real,sld_im,sld_inc), (coh,abs,incoh), length = neutron_scattering(self.compound,
+                                       self.density, self.wavelength) 
+        cu_reel, cu_im = calculate_xray_sld(element="Cu", density=self.density,
+                                  molecule_formula=self.sld_formula)
+        mo_reel, mo_im = calculate_xray_sld(element="Mo", density=self.density,
+                                  molecule_formula=self.sld_formula)
+        #test sld 
+        self.assertAlmostEquals(sld_real * _SCALE, 6.33e-6, 1)
+        self.assertAlmostEquals(sld_im * _SCALE, 0)
+        #test absorption value
+        self.assertAlmostEquals(abs, 1.35e-4, 2)
+        self.assertAlmostEquals(incoh, 0.138, 2)
+        #Test length
+        self.assertAlmostEquals(length, 1.549, 3)
+        #test Cu sld
+        self.assertAlmostEquals(cu_reel * _SCALE, 9.36e-6, 1)
+        self.assertAlmostEquals(cu_im * _SCALE, 2.98e-8)
+        # test Mo sld
+        self.assertAlmostEquals(mo_reel * _SCALE, 9.33e-6)
+        self.assertAlmostEquals(mo_im * _SCALE, 5.59e-9,1)
+    
+        
+class TestCd(unittest.TestCase):
+    """
+    Sld calculator test for Cd
+    """
+    
+    def setUp(self):
+        """Inititialze variables"""
+        # the calculator default value for wavelength is 6
+        self.compound = "Cd"
+        self.density = 4.0
+        self.wavelength = 6.0
+        self.sld_formula = formula(self.compound, density=self.density)
+       
+    def test_neutron_sld(self):
+        """
+        test sld 
+        """
+        #Compute incoherence , absorption, and incoherence
+        (sld_real,sld_im,sld_inc), (coh,abs,incoh), length = neutron_scattering(self.compound,
+                                       self.density, self.wavelength) 
+        cu_reel, cu_im = calculate_xray_sld(element="Cu", density=self.density,
+                                  molecule_formula=self.sld_formula)
+        mo_reel, mo_im = calculate_xray_sld(element="Mo", density=self.density,
+                                  molecule_formula=self.sld_formula)
+        #test sld 
+        self.assertAlmostEquals(sld_real * _SCALE, 1.04e-6, 1)
+        self.assertAlmostEquals(sld_im * _SCALE, -1.5e-7, 1)
+        #test absorption value
+        self.assertAlmostEquals(abs, 180.0,0)
+        self.assertAlmostEquals(incoh, 0.0754, 2)
+        #Test length
+        self.assertAlmostEquals(length, 0.005551, 4)
+        #test Cu sld
+        self.assertAlmostEquals(cu_reel * _SCALE, 2.89e-5, 1)
+        self.assertAlmostEquals(cu_im * _SCALE, 2.81e-6)
+        # test Mo sld
+        self.assertAlmostEquals(mo_reel * _SCALE, 2.84e-5, 1)
+        self.assertAlmostEquals(mo_im * _SCALE, 7.26e-7,1)
+  
+if __name__ == '__main__':
+    unittest.main()
