Example #1
0
def test_h5():
    try:
        import h5py
        dct1 = \
            {'/a': 'abcgs',
             '/b/c/x1': 3,
             '/b/c/x2': rand(2,3),
             }
        # writing a dct w/o leading slash will always be read back in *with*
        # leading slash
        dct2 = \
            {'a': 'abciqo4iki',
             'b/c/x1': 3,
             'b/c/x2': rand(2,3),
             }
        for idx, dct in enumerate([dct1, dct2]):
            h5fn = os.path.join(testdir, 'test_%i.h5' % idx)
            io.write_h5(h5fn, dct)
            read_dct = io.read_h5(h5fn)
            for kk in list(read_dct.keys()):
                assert kk.startswith('/')
            for kk in list(dct.keys()):
                key = '/' + kk if not kk.startswith('/') else kk
                tools.assert_all_types_equal(dct[kk], read_dct[key])

        # write mode='a', test appending
        h5fn = os.path.join(testdir, 'test_append.h5')
        io.write_h5(h5fn, {'/a': 1.0})
        read_dct = io.read_h5(h5fn)
        assert list(read_dct.keys()) == ['/a']
        assert read_dct['/a'] == 1.0
        # append '/b', using {'/a': 1.0, '/b': 2.0} would be an error since /a
        # already exists, use mode='w' then, but this overwrites all!
        io.write_h5(h5fn, {'/b': 2.0}, mode='a')
        read_dct2 = io.read_h5(h5fn)
        # sort(...): sort possible [/b, /a] -> [/a, /b]
        assert np.sort(np.array(list(
            read_dct2.keys()))).tolist() == ['/a', '/b']
        assert read_dct2['/a'] == 1.0
        assert read_dct2['/b'] == 2.0
        # overwrite
        io.write_h5(h5fn, {'/b': 22.0, '/c': 33.0}, mode='w')
        read_dct3 = io.read_h5(h5fn)
        assert np.sort(np.array(list(
            read_dct3.keys()))).tolist() == ['/b', '/c']

    except ImportError:
        tools.skip("skipping test_h5, no h5py importable")
Example #2
0
def test_h5():
    try:
        import h5py
        dct1 = \
            {'/a': 'abcgs',
             '/b/c/x1': 3,
             '/b/c/x2': rand(2,3),
             }
        # writing a dct w/o leading slash will always be read back in *with*
        # leading slash             
        dct2 = \
            {'a': 'abciqo4iki',
             'b/c/x1': 3,
             'b/c/x2': rand(2,3),
             }
        for idx,dct in enumerate([dct1, dct2]):             
            h5fn = os.path.join(testdir, 'test_%i.h5' %idx)
            io.write_h5(h5fn, dct)
            read_dct = io.read_h5(h5fn)
            for kk in read_dct.keys():
                assert kk.startswith('/')
            for kk in dct.keys():
                key = '/'+kk if not kk.startswith('/') else kk
                tools.assert_all_types_equal(dct[kk], read_dct[key])
        
        # write mode='a', test appending
        h5fn = os.path.join(testdir, 'test_append.h5')
        io.write_h5(h5fn, {'/a': 1.0})
        read_dct = io.read_h5(h5fn)
        assert read_dct.keys() == ['/a']
        assert read_dct['/a'] == 1.0
        # append '/b', using {'/a': 1.0, '/b': 2.0} would be an error since /a
        # already exists, use mode='w' then, but this overwrites all!
        io.write_h5(h5fn, {'/b': 2.0}, mode='a')
        read_dct2 = io.read_h5(h5fn)
        # sort(...): sort possible [/b, /a] -> [/a, /b]
        assert np.sort(np.array(read_dct2.keys())).tolist() == ['/a', '/b']
        assert read_dct2['/a'] == 1.0
        assert read_dct2['/b'] == 2.0
        # overwrite
        io.write_h5(h5fn, {'/b': 22.0, '/c': 33.0}, mode='w')
        read_dct3 = io.read_h5(h5fn)
        assert np.sort(np.array(read_dct3.keys())).tolist() == ['/b', '/c']

    except ImportError:
        tools.skip("skipping test_h5, no h5py importable")
Example #3
0
        phdos.append(np.array([freq, gauss(freq - fc, 100) * 0.01]).T)

    gibbs = Gibbs(T=T,
                  P=P,
                  etot=etot,
                  phdos=phdos,
                  axes_flat=axes_flat,
                  volfunc_ax=volfunc_ax,
                  case=case,
                  dosarea=None)
    gibbs.set_fitfunc('C',
                      lambda x, y: num.Spline(x, y, s=None, k=5, eps=1e-5))
    g = gibbs.calc_G(calc_all=True)
    common.makedirs('../files/gibbs/2d')
    io.write_h5('../files/gibbs/2d/%s.h5' % gethostname(),
                filt_dct(g),
                mode='w')

    # 1d case
    case = '1d'
    V = np.linspace(10, 20, nax)
    axes_flat = V**(1 / 3.)  # cubic
    volfunc_ax = lambda x: x[0]**3.0
    etot = (V - V.mean())**2
    fcenter = 450 + 100 * (axes_flat - axes_flat.min())
    # fake phonon dos data (Gaussian), shift to lower freq for higher volume
    phdos = [np.array([freq, gauss(freq - fc, 100)]).T for fc in fcenter[::-1]]

    gibbs = Gibbs(T=T,
                  P=P,
                  etot=etot,
Example #4
0
etot = np.array([(a-cell_a_mean)**2.0 + (c-cell_c_mean)**2.0 for a,c in axes_flat])
phdos = []
Vmax = V.max()
# phonon dos (just a gaussian) shifted to lower (higher) freqs for higher
# (lower) volume
for ii in range(axes_flat.shape[0]):
    a,c = axes_flat[ii,:]
    fc = 550 - 50 * V[ii] / Vmax
    phdos.append(np.array([freq,gauss(freq-fc,100)*0.01]).T)

gibbs = Gibbs(T=T, P=P, etot=etot, phdos=phdos, axes_flat=axes_flat,
              volfunc_ax=volfunc_ax, case=case, dosarea=None)
gibbs.set_fitfunc('C', lambda x,y: num.Spline(x,y,s=None,k=5, eps=1e-5))
g = gibbs.calc_G(calc_all=True)
common.makedirs('../files/gibbs/2d')
io.write_h5('../files/gibbs/2d/%s.h5' %gethostname(), filt_dct(g), mode='w')


# 1d case
case = '1d'
V = np.linspace(10,20,nax)
axes_flat = V**(1/3.) # cubic
volfunc_ax = lambda x: x[0]**3.0
etot = (V-V.mean())**2
fcenter = 450 + 100*(axes_flat - axes_flat.min())
# fake phonon dos data (Gaussian), shift to lower freq for higher volume
phdos = [np.array([freq,gauss(freq-fc, 100)]).T for fc in
         fcenter[::-1]]

gibbs = Gibbs(T=T, P=P, etot=etot, phdos=phdos, axes_flat=axes_flat,
              volfunc_ax=volfunc_ax, case=case, dosarea=None)