3
0
mirror of https://github.com/triqs/dft_tools synced 2024-06-29 16:34:53 +02:00
dft_tools/test/plovasp/proj_group/test_block_map.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

102 lines
3.5 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
################################################################################
#
# TestBlockMap
#
################################################################################
class TestBlockMap(mytest.MyTestCase):
"""
Function:
def ProjectorGroup.get_block_matrix_map()
Scenarios:
- **test** block matrix for NORMION = False
- **test** block matrix for NORMION = True
"""
def setUp(self):
# Mock data
self.mock_eigvals = np.zeros((1, 11, 1))
nproj = 16
self.mock_plo = np.zeros((nproj, 1, 1, 11), dtype=np.complex128)
self.mock_proj_params = [{} for i in xrange(nproj)]
ip = 0
# Mock d-sites
for isite in xrange(2):
for im in xrange(5):
self.mock_proj_params[ip]['label'] = 'd-orb'
self.mock_proj_params[ip]['isite'] = isite + 1
self.mock_proj_params[ip]['l'] = 2
self.mock_proj_params[ip]['m'] = im
ip += 1
# Mock p-sites
for isite in xrange(2, 4):
for im in xrange(3):
self.mock_proj_params[ip]['label'] = 'p-orb'
self.mock_proj_params[ip]['isite'] = isite + 1
self.mock_proj_params[ip]['l'] = 1
self.mock_proj_params[ip]['m'] = im
ip += 1
# Scenario 1
def test_normion_false(self):
conf_file = _rpath + 'block_matrix.cfg'
self.pars = ConfigParameters(conf_file)
self.pars.parse_input()
shells = []
for sh_par in self.pars.shells:
shells.append(ProjectorShell(sh_par, self.mock_plo, self.mock_proj_params, 0))
proj_gr = ProjectorGroup(self.pars.groups[0], shells, self.mock_eigvals)
proj_gr.normion = False
block_maps, ndim = proj_gr.get_block_matrix_map()
ndim_exp = 16
block_maps_exp = [[{'bmat_range': (0, 5), 'shell_ion': (0, 0)},
{'bmat_range': (5, 10), 'shell_ion': (0, 1)},
{'bmat_range': (10, 13), 'shell_ion': (1, 0)},
{'bmat_range': (13, 16), 'shell_ion': (1, 1)}]]
self.assertEqual(ndim, ndim_exp)
self.assertEqual(block_maps, block_maps_exp)
# Scenario 2
def test_normion_true(self):
conf_file = _rpath + 'block_matrix.cfg'
self.pars = ConfigParameters(conf_file)
self.pars.parse_input()
shells = []
for sh_par in self.pars.shells:
shells.append(ProjectorShell(sh_par, self.mock_plo, self.mock_proj_params, 0))
proj_gr = ProjectorGroup(self.pars.groups[0], shells, self.mock_eigvals)
proj_gr.normion = True
block_maps, ndim = proj_gr.get_block_matrix_map()
ndim_exp = 5
block_maps_exp = [[{'bmat_range': (0, 5), 'shell_ion': (0, 0)}],
[{'bmat_range': (0, 5), 'shell_ion': (0, 1)}],
[{'bmat_range': (0, 3), 'shell_ion': (1, 0)}],
[{'bmat_range': (0, 3), 'shell_ion': (1, 1)}]]
self.assertEqual(ndim, ndim_exp)
self.assertEqual(block_maps, block_maps_exp)