Example #1
0
    def test_bandsexport_single_kp(self):
        """
        Plot band for single k-point (issue #2462).
        """
        kpnts = KpointsData()
        kpnts.set_kpoints([[0., 0., 0.]])

        bands = BandsData()
        bands.set_kpointsdata(kpnts)
        bands.set_bands([[1.0, 2.0]])
        bands.store()

        # matplotlib
        options = [str(bands.id), '--format', 'mpl_singlefile']
        res = self.cli_runner.invoke(cmd_bands.bands_export,
                                     options,
                                     catch_exceptions=False)
        self.assertIn(
            b'p.scatter', res.stdout_bytes,
            'The string p.scatter was not found in the bands mpl export')

        # gnuplot
        with self.cli_runner.isolated_filesystem():
            options = [str(bands.id), '--format', 'gnuplot', '-o', 'bands.gnu']
            self.cli_runner.invoke(cmd_bands.bands_export,
                                   options,
                                   catch_exceptions=False)
            with open('bands.gnu', 'r') as gnu_file:
                res = gnu_file.read()
                self.assertIn(
                    'vectors nohead', res,
                    'The string "vectors nohead" was not found in the gnuplot script'
                )
    def test_spin_unpolarized():
        """Test the function for a non spin-polarized calculation meaning there will be a single spin channel."""
        from aiida.orm import BandsData

        occupations = numpy.array([
            [2., 2., 2., 2., 0.],
            [2., 2., 2., 2., 0.],
            [2., 2., 2., 2., 0.],
            [2., 2., 2., 2., 0.],
        ])

        bands = BandsData()
        bands.set_array('occupations', occupations)
        bands.store()
        h**o = get_highest_occupied_band(bands)
        assert h**o == 4
Example #3
0
    def test_spin_polarized(self, fixture_database):
        """Test the function for a spin-polarized calculation meaning there will be two spin channels."""
        from aiida.orm import BandsData

        occupations = numpy.array([
            [
                [2., 2., 2., 2., 0.],
                [2., 2., 2., 2., 0.],
            ],
            [
                [2., 2., 2., 2., 0.],
                [2., 2., 2., 2., 0.],
            ]
        ])

        bands = BandsData()
        bands.set_array('occupations', occupations)
        bands.store()
        h**o = get_highest_occupied_band(bands)
        assert h**o == 4
Example #4
0
    def test_threshold(self, fixture_database):
        """Test the `threshold` parameter."""
        from aiida.orm import BandsData

        threshold = 0.002

        bands = BandsData()
        bands.set_array('occupations', numpy.array([[2., 2., 2., 2., 0.001, 0.0015]]))
        bands.store()

        # All bands above the LUMO (occupation of 0.001) are below `2 * threshold`
        h**o = get_highest_occupied_band(bands, threshold=threshold)
        assert h**o == 4

        bands = BandsData()
        bands.set_array('occupations', numpy.array([[2., 2., 2., 2., 0.001, 0.003]]))
        bands.store()

        # A band above the LUMO (occupation of 0.001) has an occupation above `2 * threshold`
        with pytest.raises(ValueError):
            get_highest_occupied_band(bands, threshold=threshold)
Example #5
0
    def create_structure_bands():
        """Create bands structure object."""
        alat = 4.  # angstrom
        cell = [
            [
                alat,
                0.,
                0.,
            ],
            [
                0.,
                alat,
                0.,
            ],
            [
                0.,
                0.,
                alat,
            ],
        ]
        strct = StructureData(cell=cell)
        strct.append_atom(position=(0., 0., 0.), symbols='Fe')
        strct.append_atom(position=(alat / 2., alat / 2., alat / 2.),
                          symbols='O')
        strct.store()

        @calcfunction
        def connect_structure_bands(strct):  # pylint: disable=unused-argument
            alat = 4.
            cell = np.array([
                [alat, 0., 0.],
                [0., alat, 0.],
                [0., 0., alat],
            ])

            kpnts = KpointsData()
            kpnts.set_cell(cell)
            kpnts.set_kpoints([[0., 0., 0.], [0.1, 0.1, 0.1]])

            bands = BandsData()
            bands.set_kpointsdata(kpnts)
            bands.set_bands([[1.0, 2.0], [3.0, 4.0]])
            return bands

        bands = connect_structure_bands(strct)

        bands_isolated = BandsData()
        bands_isolated.store()

        # Create 2 groups and add the data to one of them
        g_ne = Group(label='non_empty_group')
        g_ne.store()
        g_ne.add_nodes(bands)
        g_ne.add_nodes(bands_isolated)

        g_e = Group(label='empty_group')
        g_e.store()

        return {
            DummyVerdiDataListable.NODE_ID_STR: bands.id,
            DummyVerdiDataListable.NON_EMPTY_GROUP_ID_STR: g_ne.id,
            DummyVerdiDataListable.EMPTY_GROUP_ID_STR: g_e.id
        }