3
0
mirror of https://github.com/triqs/dft_tools synced 2024-06-26 15:12:18 +02:00
dft_tools/test/plovasp/proj_group/test_select_bands.py
Oleg E. Peil f86038a7fd Fixed tests to make them runnable with build pytriqs
All imports inside the test cases refer now to paths relative
to TRIQS python library path. For example,

`import vaspio`

is replaced with

`import applications.dft.converters.plovasp.vasio`

In this way all tests can be executed wtih `build_pytriqs` provided
that the package is installed (the same practice as with other
'dft_tools' tests).

Also, the underscore can now be removed from subdirectory names
because there is no more conflict with module names.
2016-03-10 12:24:05 +01:00

70 lines
2.4 KiB
Python

import os
import rpath
_rpath = os.path.dirname(rpath.__file__) + '/'
import numpy as np
import applications.dft.converters.plovasp.vaspio
import applications.dft.converters.plovasp.elstruct
from applications.dft.converters.plovasp.inpconf import ConfigParameters
from applications.dft.converters.plovasp.proj_shell import ProjectorShell
from applications.dft.converters.plovasp.proj_group import ProjectorGroup
import mytest
################################################################################
#
# TestSelectBands
#
################################################################################
class TestSelectBands(mytest.MyTestCase):
"""
Function:
def ProjectorGroup.select_bands(eigvals)
Scenarios:
- compare output for a correct input
- **if** emin > max(eigvals) **raise** Exception
- **if** emax > min(eigvals) **raise** Exception
"""
def setUp(self):
conf_file = _rpath + 'simple.cfg'
self.pars = ConfigParameters(conf_file)
self.pars.parse_input()
vasp_data = vaspio.VaspData(_rpath + 'simple/')
self.el_struct = elstruct.ElectronicStructure(vasp_data)
efermi = vasp_data.doscar.efermi
self.eigvals = vasp_data.eigenval.eigs - efermi
self.proj_sh = ProjectorShell(self.pars.shells[0], vasp_data.plocar.plo, vasp_data.plocar.proj_params, 0)
self.proj_gr = ProjectorGroup(self.pars.groups[0], [self.proj_sh], self.eigvals)
# Scenario 1
def test_correct(self):
ib_win, nb_min, nb_max = self.proj_gr.select_bands(self.eigvals)
nb_min_exp = 3
nb_max_exp = 8
ib_win_exp = np.array([[[3, 8]], [[3, 7]], [[3, 7]], [[3, 7]], [[3, 7]], [[3, 7]], [[3, 7]], [[3, 4]]])
self.assertEqual(nb_min, nb_min_exp)
self.assertEqual(nb_max, nb_max_exp)
self.assertEqual(ib_win, ib_win_exp)
# Scenario 2
def test_emin_too_large(self):
self.proj_gr.emin = 20.0
self.proj_gr.emax = 25.0
with self.assertRaisesRegexp(Exception, "No bands inside the window"):
ib_win, nb_min, nb_max = self.proj_gr.select_bands(self.eigvals)
# Scenario 3
def test_emax_too_small(self):
self.proj_gr.emin = -50.0
self.proj_gr.emax = -55.0
with self.assertRaisesRegexp(Exception, "Energy window does not overlap"):
ib_win, nb_min, nb_max = self.proj_gr.select_bands(self.eigvals)