def test1(self):
     'GridSQE'
     sqe = createSqe()
     gridsqe = ms.gridsqe( sqe )
     
     cgridsqe = mh.scattererEngine( gridsqe )
     
     Q, E = 5.05, 10.5
     self.assertAlmostEqual( sqe[ Q,E ][0], sqe_f(Q,E) )
     self.assertAlmostEqual( cgridsqe( Q,E ), sqe_f(Q,E) )
     return
 def test1(self):
     'SQEkernel'
     sqe = createSqe()
     gridsqe = ms.gridsqe( sqe )
     sqekernel = ms.sqekernel(
         1., 1., 1.,
         SQE=gridsqe,
         Qrange=(0, 12.), Erange=(-50, 50) )
     
     csqekernel = mh.scattererEngine( sqekernel )
     
     ev = mcni.neutron( r = (-5,0,0), v = (3000,0,0) )
     self.assertAlmostEqual( csqekernel.scattering_coefficient(ev), 1 )
     self.assertAlmostEqual( csqekernel.absorption_coefficient(ev), 2200./3000. )
     return
Example #3
0
    def elementFactory(self, **kwds):
        datapath = kwds.get("idf-data-path")
        hdfpath = kwds.get("histogram-hdf-path")
        if datapath:
            from mccomponents.sample.idf import readSQE

            sqe = readSQE(datapath)
            pass
        elif hdfpath:
            from histogram.hdf import load

            try:
                sqe = load(hdfpath)
            except:
                import os, traceback

                f = os.path.dirname(hdfpath)
                e = os.path.basename(hdfpath)
                t = traceback.format_exc()
                raise IOError, "unable to load histogram from hdf5 file %s, entry %s. Original traceback:\n%s" % (
                    f,
                    e,
                    t,
                )
            pass
        else:
            raise ValueError, "GridSQE needs path to " "idf data files or " "histogram hdf5 file "

        auto_normalization = kwds.get("auto-normalization")
        if auto_normalization:
            auto_normalization = bool(auto_normalization)

        norm = _calcNorm(sqe)
        if abs(norm - 1) > 0.2:
            if auto_normalization:
                sqe.I /= norm
            else:
                raise RuntimeError, "S(Q,E) should average to ~1, got %s" % norm

        from mccomponents.sample import gridsqe

        return gridsqe(sqe)
 
 import histogram as H, histogram.hdf as hh
 sqehist = H.histogram(
     'S',
     [('Q', q, 'angstrom**-1'),
      ('energy', e, 'meV')],
     s)
 # usually only a subset of sqe is necessary 
 if Emax:
     sqehist = sqehist[(), (None, Emax)].copy()
 hh.dump(sqehist, 'mp-sqe-%d.h5' % mpi.rank)
 journal.debug("phonon").log("computed multiphonon sqe")
 
 from mccomponents import sample
 # grid sqe
 gsqe = sample.gridsqe(sqehist)
 # q and e range
 qrange = q[0]/units.angstrom, q[-1]/units.angstrom
 erange = e[0]*units.meV, sqehist.energy[-1]*units.meV
 # kernel
 sqekernel = sample.sqekernel(
     # XXX: we may want to support more options
     # XXX: like absorption_cross_section and scattering_cross_section
     # XXX: or absorption_coefficient ...
     SQE = gsqe,
     Qrange = qrange, Erange = erange,
     absorption_cross_section = kernel.absorption_xs,
     scattering_cross_section = kernel.scattering_xs,
     )
 sqekernel.scatterer_origin = scatterer
 #