def test(self):
        E_Q = "Q*Q/3."
        S_Q = "1"
        Qmin = 0; Qmax = 10
        absorption_coefficient = scattering_coefficient = 1.
        kernel = mccomponentsbp.create_E_Q_Kernel(
            E_Q, S_Q,
            Qmin, Qmax,
            absorption_coefficient,
            scattering_coefficient,
            )

        ei = 500 # meV
        from mcni.utils import conversion
        vil = conversion.e2v(ei)
        vi = (0,0,vil)

        import numpy.linalg as nl
        import numpy as np
        for i in range(10):
            event = mcni.neutron( 
                r = (0,0,0), v = vi, 
                prob = 1, time = 0 )
            kernel.scatter( event );
            vf = np.array(event.state.velocity)
            diffv = vi - vf
            Q = conversion.v2k(nl.norm(diffv))
            ef = conversion.v2e(nl.norm(vf))
            E = ei - ef
            # print E, Q, event
            E1 = eval(E_Q)
            self.assertAlmostEqual(E, E1)
            continue

        return
    def test1(self):
        'mccomponents.sample: ConstantQEKernel'
        # momentum and energy transfer. defined in the scatterer xml file
        Q0 = 3
        E0 = 30

        import mcni
        from mcni.utils import conversion
        
        ei = 60
        vi = conversion.e2v(ei)
        Vi = (0,0,vi)
        neutron = mcni.neutron( r = (0,0,0), v = Vi, time = 0, prob = 1 )
        
        from mcni.components.MonochromaticSource import MonochromaticSource
        component1 = MonochromaticSource('source', neutron)
        
        from mccomponents.sample import samplecomponent
        component2 = samplecomponent( 'Al', 'sampleassemblies/Al-constantqekernel/sampleassembly.xml' )
        instrument = mcni.instrument( [component1, component2] )
        
        geometer = mcni.geometer()
        geometer.register( component1, (0,0,0), (0,0,0) )
        geometer.register( component2, (0,0,1), (0,0,0) )

        N0 = 1000
        neutrons = mcni.neutron_buffer(N0)

        mcni.simulate( instrument, geometer, neutrons )

        N = len(neutrons)

        import numpy.linalg as nl, numpy as np
        for i in range(10):
            neutron = neutrons[i]
            Vf = np.array(neutron.state.velocity)
            print Vf

            ef = conversion.v2e(nl.norm(Vf))
            E = ei-ef
            
            dV = np.array(Vf) - np.array(Vi)
            qasv = nl.norm(dV)
            Q = conversion.v2k(qasv)

            self.assertAlmostEqual(E, E0, 7)
            self.assertAlmostEqual(Q, Q0, 7)
            continue

        return
    def test1(self):
        'mccomponents.sample.samplecomponent: E_Q_Kernel'
        import mcni
        from mcni.utils import conversion

        ei = 60
        vil = conversion.e2v(ei)
        vi = (0,0,vil)
        neutron = mcni.neutron( 
            r = (0,0,0), v = vi, 
            time = 0, prob = 1 )
        
        from mcni.components.MonochromaticSource import MonochromaticSource
        component1 = MonochromaticSource('source', neutron)
        
        from mccomponents.sample import samplecomponent
        component2 = samplecomponent( 'Al', 'sampleassemblies/Al-E_Q-kernel/sampleassembly.xml' )
        E_Q = '30+5*sin(Q)' # in sampleassemblies/Al-E_Q-kernel/Al-scatterer.xml

        instrument = mcni.instrument( [component1, component2] )
        
        geometer = mcni.geometer()
        geometer.register( component1, (0,0,0), (0,0,0) )
        geometer.register( component2, (0,0,1), (0,0,0) )

        N0 = 1000
        neutrons = mcni.neutron_buffer(N0)

        mcni.simulate( instrument, geometer, neutrons )

        N = len(neutrons)

        import numpy.linalg as nl
        import numpy as np
        from math import sin
        for i in range(N):
            neutron = neutrons[i]
            vf = np.array(neutron.state.velocity)
            diffv = vi - vf
            Q = conversion.v2k(nl.norm(diffv))
            ef = conversion.v2e(nl.norm(vf))
            E = ei - ef
            # print E, Q, neutron
            E1 = eval(E_Q)
            # print E, E1
            self.assertAlmostEqual(E, E1)
            continue

        return