Esempio n. 1
0
    def setUp(self):
        conf_file = _rpath + 'example.cfg'
        self.pars = ConfigParameters(conf_file)
        self.pars.parse_input()
        vasp_data = VaspData(_rpath + 'one_site/')
        self.el_struct = ElectronicStructure(vasp_data)

        efermi = self.el_struct.efermi
        self.eigvals = self.el_struct.eigvals - efermi
        struct = self.el_struct.structure
        kmesh = self.el_struct.kmesh

        self.proj_sh = ProjectorShell(self.pars.shells[0], vasp_data.plocar.plo, vasp_data.plocar.proj_params, kmesh, struct, 0)
        self.proj_gr = ProjectorGroup(self.pars.groups[0], [self.proj_sh], self.eigvals)
Esempio n. 2
0
    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,
                               self.mock_kmesh, self.mock_struct, 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)
Esempio n. 3
0
class TestProjectorShell(mytest.MyTestCase):
    """
    Class:

    ProjectorShell(sh_pars, proj_raw)

    Scenarios:
    - **if** a correct input is given **compare** output files
    - **if** a correct input is given **compare** density matrices
    """
    def setUp(self):
        """
        """
        conf_file = _rpath + 'example.cfg'
        self.pars = ConfigParameters(conf_file)
        self.pars.parse_input()
        vasp_data = VaspData(_rpath + 'one_site/')
        self.el_struct = ElectronicStructure(vasp_data)

#        efermi = vasp_data.doscar.efermi
#        eigvals = vasp_data.eigenval.eigs - efermi
        efermi = self.el_struct.efermi
        eigvals = self.el_struct.eigvals - efermi
        emin, emax = self.pars.groups[0]['ewindow']
        struct = self.el_struct.structure
        kmesh = self.el_struct.kmesh

        self.proj_sh = ProjectorShell(self.pars.shells[0], vasp_data.plocar.plo, vasp_data.plocar.proj_params, kmesh, struct, 0)
        self.proj_gr = ProjectorGroup(self.pars.groups[0], [self.proj_sh], eigvals)

# Scenario 1
    def test_example(self):
        testout = _rpath + 'projshells.out.test'
        nion, ns, nk, nlm, nbtot = self.proj_sh.proj_win.shape
        with open(testout, 'wt') as f:
            f.write("pars: %s\n"%(self.pars.shells[0]))
            for ion in xrange(nion):
                for isp in xrange(ns):
                    for ik in xrange(nk):
                        ib1 = self.proj_sh.ib_win[ik, 0, 0]
                        ib2 = self.proj_sh.ib_win[ik, 0, 1]
                        f.write("%i  %i\n"%(ib1, ib2))
                        for ib in xrange(ib2 - ib1 + 1):
                            for ilm in xrange(nlm):
                                p = self.proj_sh.proj_win[ion, isp, ik, ilm, ib]
                                f.write("%5i  %f  %f\n"%(ilm+1, p.real, p.imag))

        expected_file = _rpath + 'projshells.out'
        self.assertFileEqual(testout, expected_file)

# Scenario 2
    def test_dens_mat(self):
        dens_mat, overl = self.proj_sh.density_matrix(self.el_struct)
        testout = _rpath + 'densmat.out.test'
        with open(testout, 'wt') as f:
            f.write("density matrix: %s\n"%(dens_mat))
            f.write("overlap matrix: %s\n"%(overl))

        expected_file = _rpath + 'densmat.out'
        self.assertFileEqual(testout, expected_file)
Esempio n. 4
0
    def setUp(self):
        """
        """
        conf_file = _rpath + 'example.cfg'
        self.pars = ConfigParameters(conf_file)
        self.pars.parse_input()
        vasp_data = VaspData(_rpath + 'one_site/')
        self.el_struct = ElectronicStructure(vasp_data)

        #        efermi = vasp_data.doscar.efermi
        #        eigvals = vasp_data.eigenval.eigs - efermi
        efermi = self.el_struct.efermi
        eigvals = self.el_struct.eigvals - efermi
        emin, emax = self.pars.groups[0]['ewindow']
        struct = self.el_struct.structure
        kmesh = self.el_struct.kmesh

        self.proj_sh = ProjectorShell(self.pars.shells[0],
                                      vasp_data.plocar.plo,
                                      vasp_data.plocar.proj_params, kmesh,
                                      struct, 0)
        self.proj_gr = ProjectorGroup(self.pars.groups[0], [self.proj_sh],
                                      eigvals)
Esempio n. 5
0
    def setUp(self):
        """
        """
        conf_file = _rpath + 'example.cfg'
        self.pars = ConfigParameters(conf_file)
        self.pars.parse_input()
        vasp_data = VaspData(_rpath + 'one_site/')
        self.el_struct = ElectronicStructure(vasp_data)

#        efermi = vasp_data.doscar.efermi
#        eigvals = vasp_data.eigenval.eigs - efermi
        efermi = self.el_struct.efermi
        eigvals = self.el_struct.eigvals - efermi
        emin, emax = self.pars.groups[0]['ewindow']
        struct = self.el_struct.structure
        kmesh = self.el_struct.kmesh

        self.proj_sh = ProjectorShell(self.pars.shells[0], vasp_data.plocar.plo, vasp_data.plocar.proj_params, kmesh, struct, 0)
        self.proj_gr = ProjectorGroup(self.pars.groups[0], [self.proj_sh], eigvals)
Esempio n. 6
0
class TestProjectorGroupTwoSite(mytest.MyTestCase):
    """
    Tests for a two-site problem.

    Class:

    ProjectorGroup(sh_pars, proj_raw)

    Scenarios:
    - **test** that orthogonalization with NORMION = False is correct
    - **test** that orthogonalization with NORMION = True is correct
    """
    def setUp(self):
        conf_file = _rpath + 'example_two_site.cfg'
        self.pars = ConfigParameters(conf_file)
        self.pars.parse_input()
        vasp_data = VaspData(_rpath + 'two_site/')
        self.el_struct = ElectronicStructure(vasp_data)

        efermi = self.el_struct.efermi
        self.eigvals = self.el_struct.eigvals - efermi
        struct = self.el_struct.structure
        kmesh = self.el_struct.kmesh

        self.proj_sh = ProjectorShell(self.pars.shells[0],
                                      vasp_data.plocar.plo,
                                      vasp_data.plocar.proj_params, kmesh,
                                      struct, 0)
        self.proj_gr = ProjectorGroup(self.pars.groups[0], [self.proj_sh],
                                      self.eigvals)

# Scenario 1

    def test_ortho(self):
        self.proj_gr.normion = False
        self.proj_gr.orthogonalize()

        dens_mat, overl = self.proj_sh.density_matrix(self.el_struct)

        testout = _rpath + 'projortho_2site.test.h5'
        with HDFArchive(testout, 'w') as h5test:
            h5test['density_matrix'] = dens_mat
            h5test['overlap_matrix'] = overl

# FIXME: redundant
        self.assertEqual(overl[0, 0, ...], np.eye(5))
        self.assertEqual(overl[0, 1, ...], np.eye(5))

        expected_file = _rpath + 'projortho_2site.ref.h5'
        self.assertH5FileEqual(testout, expected_file)

# Scenario 2

    def test_ortho_normion(self):
        self.proj_gr.normion = True
        self.proj_gr.orthogonalize()

        dens_mat, overl = self.proj_sh.density_matrix(self.el_struct)

        testout = _rpath + 'projortho_normion.test.h5'
        with HDFArchive(testout, 'w') as h5test:
            h5test['density_matrix'] = dens_mat
            h5test['overlap_matrix'] = overl

# FIXME: redundant
        self.assertEqual(overl[0, 0, ...], np.eye(5))
        self.assertEqual(overl[0, 1, ...], np.eye(5))

        expected_file = _rpath + 'projortho_normion.ref.h5'
        self.assertH5FileEqual(testout, expected_file)
Esempio n. 7
0
class TestProjectorGroup(mytest.MyTestCase):
    """
    Class:

    ProjectorGroup(sh_pars, proj_raw)

    Scenarios:
    - **test** that orthogonalization is correct
    - **test** that NORMION = True gives the same result
    """
    def setUp(self):
        conf_file = _rpath + 'example.cfg'
        self.pars = ConfigParameters(conf_file)
        self.pars.parse_input()
        vasp_data = VaspData(_rpath + 'one_site/')
        self.el_struct = ElectronicStructure(vasp_data)

        efermi = self.el_struct.efermi
        self.eigvals = self.el_struct.eigvals - efermi
        struct = self.el_struct.structure
        kmesh = self.el_struct.kmesh

        self.proj_sh = ProjectorShell(self.pars.shells[0], vasp_data.plocar.plo, vasp_data.plocar.proj_params, kmesh, struct, 0)
        self.proj_gr = ProjectorGroup(self.pars.groups[0], [self.proj_sh], self.eigvals)

# Scenario 1
    def test_ortho(self):
        self.proj_gr.orthogonalize()

        dens_mat, overl = self.proj_sh.density_matrix(self.el_struct)

#        testout = _rpath + 'projortho.out.test'
#        with open(testout, 'wt') as f:
#            f.write("density matrix: %s\n"%(dens_mat))
#            f.write("overlap matrix: %s\n"%(overl))
        testout = _rpath + 'projortho.test.h5'
        with HDFArchive(testout, 'w') as h5test:
            h5test['density_matrix'] = dens_mat
            h5test['overlap_matrix'] = overl

# FIXME: seems redundant, as 'overl' is written to the file anyway
        self.assertEqual(overl, np.eye(5))

#        expected_file = _rpath + 'projortho.out'
        expected_file = _rpath + 'projortho.out.h5'
#        self.assertFileEqual(testout, expected_file)
        self.assertH5FileEqual(testout, expected_file)

# Scenario 2
    def test_ortho_normion(self):
        self.proj_gr.normion = True
        self.proj_gr.orthogonalize()

        dens_mat, overl = self.proj_sh.density_matrix(self.el_struct)

#        testout = _rpath + 'projortho.out.test'
#        with open(testout, 'wt') as f:
#            f.write("density matrix: %s\n"%(dens_mat))
#            f.write("overlap matrix: %s\n"%(overl))
        testout = _rpath + 'projortho.test.h5'
        with HDFArchive(testout, 'w') as h5test:
            h5test['density_matrix'] = dens_mat
            h5test['overlap_matrix'] = overl

# FIXME: seems redundant, as 'overl' is written to the file anyway
        self.assertEqual(overl, np.eye(5))

#        expected_file = _rpath + 'projortho.out'
#        self.assertFileEqual(testout, expected_file)
        expected_file = _rpath + 'projortho.out.h5'
        self.assertH5FileEqual(testout, expected_file)
Esempio n. 8
0
class TestProjectorShell(mytest.MyTestCase):
    """
    Class:

    ProjectorShell(sh_pars, proj_raw)

    Scenarios:
    - **if** a correct input is given **compare** output files
    - **if** a correct input is given **compare** density matrices
    """
    def setUp(self):
        """
        """
        conf_file = _rpath + 'example.cfg'
        self.pars = ConfigParameters(conf_file)
        self.pars.parse_input()
        vasp_data = VaspData(_rpath + 'one_site/')
        self.el_struct = ElectronicStructure(vasp_data)

        #        efermi = vasp_data.doscar.efermi
        #        eigvals = vasp_data.eigenval.eigs - efermi
        efermi = self.el_struct.efermi
        eigvals = self.el_struct.eigvals - efermi
        emin, emax = self.pars.groups[0]['ewindow']
        struct = self.el_struct.structure
        kmesh = self.el_struct.kmesh

        self.proj_sh = ProjectorShell(self.pars.shells[0],
                                      vasp_data.plocar.plo,
                                      vasp_data.plocar.proj_params, kmesh,
                                      struct, 0)
        self.proj_gr = ProjectorGroup(self.pars.groups[0], [self.proj_sh],
                                      eigvals)

# Scenario 1

    def test_example(self):
        testout = _rpath + 'projshells.out.test'
        nion, ns, nk, nlm, nbtot = self.proj_sh.proj_win.shape
        with open(testout, 'wt') as f:
            f.write("pars: %s\n" % (self.pars.shells[0]))
            for ion in range(nion):
                for isp in range(ns):
                    for ik in range(nk):
                        ib1 = self.proj_sh.ib_win[ik, 0, 0]
                        ib2 = self.proj_sh.ib_win[ik, 0, 1]
                        f.write("%i  %i\n" % (ib1, ib2))
                        for ib in range(ib2 - ib1 + 1):
                            for ilm in range(nlm):
                                p = self.proj_sh.proj_win[ion, isp, ik, ilm,
                                                          ib]
                                f.write("%5i  %f  %f\n" %
                                        (ilm + 1, p.real, p.imag))

        expected_file = _rpath + 'projshells.out'
        self.assertFileEqual(testout, expected_file)

# Scenario 2

    def test_dens_mat(self):
        dens_mat, overl = self.proj_sh.density_matrix(self.el_struct)
        testout = _rpath + 'densmat.out.test'
        with open(testout, 'wt') as f:
            f.write("density matrix: %s\n" % (dens_mat))
            f.write("overlap matrix: %s\n" % (overl))

        expected_file = _rpath + 'densmat.out'
        self.assertFileEqual(testout, expected_file)