<commit_before>#!/usr/bin/env python
#


interactive = False

import sys, os
datadir = os.path.join(os.path.dirname(__file__), "../data")
sys.path.insert(0, datadir)

import unittest
import numpy as np, histogram.hdf as hh, histogram as H
from multiphonon.backward import sqe2dos
from dos import loadDOS


class TestCase(unittest.TestCase):


    def test1a(self):
        S = hh.load(os.path.join(datadir, "V-S1.h5"))
        DOS = sqe2dos.singlephonon_sqe2dos(
            S, T=300, Ecutoff=55., elastic_E_cutoff=(0.,0.), M=50.94)
        E = DOS.E
        g = DOS.I
        # compare to the original dos data
        E1, g1 = loadDOS()
        ginterp = np.interp(E1, E, g)
        self.assert_(np.allclose(g1, ginterp))
        # plot
        if interactive:
            import pylab
            pylab.plot(E1, g1)
            pylab.plot(E1, ginterp)
            pylab.show()
        return
        
        
    def test1b(self):
        iqehist = hh.load(os.path.join(datadir, "V-iqe.h5"))
        from multiphonon.sqe import interp
        newiqe = interp(iqehist, newE = np.arange(-50, 50, 1.))
        DOS = sqe2dos.singlephonon_sqe2dos(
            newiqe, T=300, Ecutoff=65., elastic_E_cutoff=(-20., 6.7), M=50.94)
        # plot
        if interactive:
            H.plot(DOS)
        return
        
        
    def test1b2(self):
        iqehist = hh.load(os.path.join(datadir, "V-iqe.h5"))
        from multiphonon.sqe import interp
        newiqe = interp(iqehist, newE = np.arange(-50.5, 50, 1.))
        from multiphonon.backward.singlephonon_sqe2dos import EnergyAxisMissingBinCenterAtZero
        with self.assertRaises(EnergyAxisMissingBinCenterAtZero):
            DOS = sqe2dos.singlephonon_sqe2dos(
                newiqe, T=300, Ecutoff=65., elastic_E_cutoff=(-20., 6.7), M=50.94)
        return
        
        
    def test1c(self):
        iqehist = hh.load(os.path.join(datadir, "graphite-Ei_130-iqe.h5"))
        initdos = hh.load(os.path.join(datadir, "graphite-Ei_300-dos.h5"))
        newdos = sqe2dos.singlephonon_sqe2dos(
            iqehist, T=300, Ecutoff=125., elastic_E_cutoff=(-30., 15), M=12., initdos=initdos)
        # plot
        if interactive:
            pylab.plot(initdos.E, initdos.I)
            pylab.plot(newdos.E, newdos.I)
            pylab.show()
        return
        
        
    def test2a(self):
        iqehist = hh.load(os.path.join(datadir, "V-iqe.h5"))
        from multiphonon.sqe import interp
        newiqe = interp(iqehist, newE = np.arange(-15, 80, 1.))
        hh.dump(newiqe, 'V-iqe-interped.h5')
        iterdos = sqe2dos.sqe2dos(
            newiqe, T=300, Ecutoff=55., elastic_E_cutoff=(-12., 6.7), M=50.94,
            C_ms=.2, Ei=120., workdir='work-V')
        for i, dos in enumerate(iterdos):
            # print dos
            # plot
            if interactive:
                # print '*' * 70
                pylab.plot(dos.E, dos.I, label='%d' % i)
        if interactive:
            pylab.legend()
            pylab.show()
        return
        
        
    def test2b(self):
        iqehist = hh.load(os.path.join(datadir, "Al-iqe.h5"))
        from multiphonon.sqe import interp<commit_msg>Refs #39. added a testcase for sqe2dos<commit_after>#!/usr/bin/env python
#


interactive = False

import sys, os
datadir = os.path.join(os.path.dirname(__file__), "../data")
sys.path.insert(0, datadir)

import unittest
import numpy as np, histogram.hdf as hh, histogram as H
from multiphonon.backward import sqe2dos
from dos import loadDOS


class TestCase(unittest.TestCase):


    def test1a(self):
        S = hh.load(os.path.join(datadir, "V-S1.h5"))
        DOS = sqe2dos.singlephonon_sqe2dos(
            S, T=300, Ecutoff=55., elastic_E_cutoff=(0.,0.), M=50.94)
        E = DOS.E
        g = DOS.I
        # compare to the original dos data
        E1, g1 = loadDOS()
        ginterp = np.interp(E1, E, g)
        self.assert_(np.allclose(g1, ginterp))
        # plot
        if interactive:
            import pylab
            pylab.plot(E1, g1)
            pylab.plot(E1, ginterp)
            pylab.show()
        return
        
        
    def test1b(self):
        iqehist = hh.load(os.path.join(datadir, "V-iqe.h5"))
        from multiphonon.sqe import interp
        newiqe = interp(iqehist, newE = np.arange(-50, 50, 1.))
        DOS = sqe2dos.singlephonon_sqe2dos(
            newiqe, T=300, Ecutoff=65., elastic_E_cutoff=(-20., 6.7), M=50.94)
        # plot
        if interactive:
            H.plot(DOS)
        return
        
        
    def test1b2(self):
        iqehist = hh.load(os.path.join(datadir, "V-iqe.h5"))
        from multiphonon.sqe import interp
        newiqe = interp(iqehist, newE = np.arange(-50.5, 50, 1.))
        from multiphonon.backward.singlephonon_sqe2dos import EnergyAxisMissingBinCenterAtZero
        with self.assertRaises(EnergyAxisMissingBinCenterAtZero):
            DOS = sqe2dos.singlephonon_sqe2dos(
                newiqe, T=300, Ecutoff=65., elastic_E_cutoff=(-20., 6.7), M=50.94)
        return
        
        
    def test1c(self):
        iqehist = hh.load(os.path.join(datadir, "graphite-Ei_130-iqe.h5"))
        initdos = hh.load(os.path.join(datadir, "graphite-Ei_300-dos.h5"))
        newdos = sqe2dos.singlephonon_sqe2dos(
            iqehist, T=300, Ecutoff=125., elastic_E_cutoff=(-30., 15), M=12., initdos=initdos)
        # plot
        if interactive:
            pylab.plot(initdos.E, initdos.I)
            pylab.plot(newdos.E, newdos.I)
            pylab.show()
        return
        
        
    def test2a(self):
        iqehist = hh.load(os.path.join(datadir, "V-iqe.h5"))
        from multiphonon.sqe import interp
        newiqe = interp(iqehist, newE = np.arange(-15, 80, 1.))
        hh.dump(newiqe, 'V-iqe-interped.h5')
        iterdos = sqe2dos.sqe2dos(
            newiqe, T=300, Ecutoff=55., elastic_E_cutoff=(-12., 6.7), M=50.94,
            C_ms=.2, Ei=120., workdir='work-V')
        for i, dos in enumerate(iterdos):
            # print dos
            # plot
            if interactive:
                # print '*' * 70
                pylab.plot(dos.E, dos.I, label='%d' % i)
        if interactive:
            pylab.legend()
            pylab.show()
        return
        
        
    def test2a2(self):
        iqehist = hh.load(os.path.join(datadir, "V-iqe.h5"))
        from multiphonon.sqe import interp
        newiqe = interp(iqehist, newE = np.arange(-15.5, 80, 1.))
        iterdos = sqe2dos.sqe2dos(
            newiqe, T=300, Ecutoff=55., elastic_E_cutoff=(-12., 6.7), M=50.94,
            C_ms=.2, Ei=120., workdir='work-V')
        from multiphonon.backward.singlephonon_sqe2dos import EnergyAxisMissingBinCenterAtZero
        with self.assertRaises(EnergyAxisMissingBinCenterAtZero):
            for i, dos in enumerate(iterdos):
                # print dos
                # plot
                if interactive:
                    # print '*' * 70
                    pylab.plot(dos.E, dos.I, label='%d' % i)
        return
        
        
    def test2b(self):
        iqehist = hh.load(os.path.join(datadir, "Al-iqe.h5"))
        from multiphonon.sqe import interp
{'fraction_non_alphanumeric': 0.12588874947720619, 'fraction_numerical': 0.03987174125191691, 'mean_word_length': 1.8880837359098228, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2958022', 'n_tokens_mistral': 2922, 'n_tokens_neox': 2646, 'n_words': 490}