3
0
mirror of https://github.com/triqs/dft_tools synced 2024-11-15 10:33:48 +01:00
dft_tools/python/vasp/test/_vaspio/test_eigenval.py
Oleg E. Peil 87b00f61b1 Added a format check for EIGENVAL to vaspio.py
Added a check to 'vaspio.py' testing that the number of columns
implies that the Fermi weights are present in EIGENVAL. This check ensures
that the new format (starting from VASP 5.4) of the file is used.

Corresponding test is added to the suite.
2015-10-16 11:59:02 +02:00

61 lines
1.7 KiB
Python

r"""
Tests for class 'Eigneval' from module 'vaspio'
"""
import os
import rpath
_rpath = os.path.dirname(rpath.__file__) + '/'
import mytest
import numpy as np
from vaspio import Eigenval
################################################################################
#
# TestEigenval
#
################################################################################
class TestEigenval(mytest.MyTestCase):
"""
Function:
def Eigenval.from_file(vasp_dir, eig_filename)
Scenarios:
- correct EIGENVAL file
- wrong EIGENVAL file from old versions of VASP
"""
# Scenario 1
def test_example(self):
filename = 'EIGENVAL.example'
eigenval = Eigenval()
eigenval.from_file(vasp_dir=_rpath, eig_filename=filename)
testout = _rpath + 'EIGENVAL.example.out.test'
with open(testout, 'w') as f:
writeline = lambda s: f.write(s + '\n')
writeprop = lambda pname: writeline("%s = %s"%(pname, eigenval.__dict__[pname]))
writeprop('nq')
writeprop('ispin')
writeprop('nelect')
writeprop('nktot')
writeprop('nband')
writeline("kpts:\n%s"%(eigenval.kpts))
writeline("kwghts:\n%s"%(eigenval.kwghts))
writeline("eigs:\n%s"%(eigenval.eigs))
writeline("ferw:\n%s"%(eigenval.ferw))
expected = _rpath + 'EIGENVAL.example.out'
self.assertFileEqual(testout, expected)
# Scenario 2
def test_bad_example(self):
filename = 'EIGENVAL.wrong'
eigenval = Eigenval()
err_mess = "EIGENVAL file is incorrect"
with self.assertRaisesRegexp(AssertionError, err_mess):
eigenval.from_file(vasp_dir=_rpath, eig_filename=filename)