2015-08-10 11:32:08 +02:00
|
|
|
r"""
|
|
|
|
Tests for class 'Eigneval' from module 'vaspio'
|
|
|
|
"""
|
2015-10-16 11:52:33 +02:00
|
|
|
import os
|
|
|
|
import rpath
|
|
|
|
_rpath = os.path.dirname(rpath.__file__) + '/'
|
|
|
|
|
2015-08-10 11:32:08 +02:00
|
|
|
import mytest
|
|
|
|
import numpy as np
|
2018-01-22 23:34:20 +01:00
|
|
|
from converters.plovasp.vaspio import Eigenval
|
2015-08-10 11:32:08 +02:00
|
|
|
|
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# TestEigenval
|
|
|
|
#
|
|
|
|
################################################################################
|
|
|
|
class TestEigenval(mytest.MyTestCase):
|
|
|
|
"""
|
|
|
|
Function:
|
|
|
|
|
|
|
|
def Eigenval.from_file(vasp_dir, eig_filename)
|
|
|
|
|
|
|
|
Scenarios:
|
|
|
|
- correct EIGENVAL file
|
2015-10-16 11:59:02 +02:00
|
|
|
- wrong EIGENVAL file from old versions of VASP
|
2015-08-10 11:32:08 +02:00
|
|
|
|
|
|
|
"""
|
|
|
|
# Scenario 1
|
|
|
|
def test_example(self):
|
|
|
|
filename = 'EIGENVAL.example'
|
|
|
|
eigenval = Eigenval()
|
2015-10-16 11:52:33 +02:00
|
|
|
eigenval.from_file(vasp_dir=_rpath, eig_filename=filename)
|
2015-08-10 11:32:08 +02:00
|
|
|
|
2015-10-16 11:52:33 +02:00
|
|
|
testout = _rpath + 'EIGENVAL.example.out.test'
|
2015-08-10 11:32:08 +02:00
|
|
|
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))
|
2015-10-16 11:52:33 +02:00
|
|
|
writeline("ferw:\n%s"%(eigenval.ferw))
|
2015-08-10 11:32:08 +02:00
|
|
|
|
2015-10-16 11:52:33 +02:00
|
|
|
expected = _rpath + 'EIGENVAL.example.out'
|
2015-08-10 11:32:08 +02:00
|
|
|
self.assertFileEqual(testout, expected)
|
|
|
|
|
2015-10-16 11:59:02 +02:00
|
|
|
# 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)
|
|
|
|
|