Exemplo n.º 1
0
def test_kpoints_modify_line(kpoints_parser_line, tmpdir):
    """Test read, modify, write and read KPOINTS in line mode.

    """

    kpoints = kpoints_parser_line.get_dict()
    assert kpoints['comment'] == 'k-points along high symmetry lines'
    kpoints_parser_line.modify('comment', 'No comment')
    point = Kpoint(np.array([0.5, 0.5, 0.25]), 1.0)
    kpoints_parser_line.modify('points', point, point_number=3)
    kpoints_parser_line.modify('points', point, point_number=4)
    temp_file = str(tmpdir.join('KPOINTSLINE'))
    kpoints_parser_line.write(file_path=temp_file)
    kpoints_parser_line_temp = Kpoints(file_path=temp_file)
    kpoints_temp = kpoints_parser_line_temp.get_dict()
    assert kpoints_temp['comment'] == 'No comment'
    points = kpoints_temp['points']
    np.testing.assert_allclose(points[0][0], np.array([0.0, 0.0, 0.0]))
    np.testing.assert_allclose(points[1][0], np.array([0.5, 0.5, 0.0]))
    np.testing.assert_allclose(points[2][0], np.array([0.5, 0.5, 0.0]))
    np.testing.assert_allclose(points[3][0], np.array([0.5, 0.5, 0.25]))
    np.testing.assert_allclose(points[4][0], np.array([0.5, 0.5, 0.25]))
    np.testing.assert_allclose(points[5][0], np.array([0.0, 0.0, 0.0]))
    assert math.isclose(points[0][1], 1.0, rel_tol=1e-07)
    assert math.isclose(points[1][1], 1.0, rel_tol=1e-07)
    assert math.isclose(points[2][1], 1.0, rel_tol=1e-07)
    assert math.isclose(points[3][1], 1.0, rel_tol=1e-07)
    assert math.isclose(points[4][1], 1.0, rel_tol=1e-07)
    assert math.isclose(points[5][1], 1.0, rel_tol=1e-07)
    assert points[0][2]
    assert points[1][2]
    assert points[2][2]
    assert points[3][2]
    assert points[4][2]
    assert points[5][2]
Exemplo n.º 2
0
    def _get_kpointsdict_explicit(self, kpointsdata):
        """Turn Aiida KpointData into an 'explicit' kpoints dictionary."""
        dictionary = {}

        kpts = []
        try:
            points, weights = kpointsdata.get_kpoints(also_weights=True)
        except AttributeError:
            points = kpointsdata.get_kpoints()
            weights = None
        for index, point in enumerate(points):
            if weights is not None:
                kpt = Kpoint(point, weight=weights[index], logger=self._logger)
            else:
                # no weights supplied, so set them to 1.0
                kpt = Kpoint(point, weight=1.0, logger=self._logger)
            kpts.append(kpt)
        dictionary['points'] = kpts
        dictionary['mode'] = 'explicit'
        dictionary['num_kpoints'] = len(kpts)

        return dictionary
Exemplo n.º 3
0
    def kpoints(self):
        """Fetch the kpoints from parsevasp an store in KpointsData."""

        kpts = self._xml.get_kpoints()
        kptsw = self._xml.get_kpointsw()
        kpoints_data = None
        if (kpts is not None) and (kptsw is not None):
            # create a KpointsData object and store k-points
            kpoints_data = {}
            kpoints_data['mode'] = 'explicit'
            kpoints_data['points'] = []
            for kpt, kptw in zip(kpts, kptsw):
                kpoints_data['points'].append(Kpoint(kpt, weight=kptw))

        return kpoints_data
Exemplo n.º 4
0
def test_kpoints_modify_explicit(kpoints_parser_explicit, tmpdir):
    """Test read, modify, write and read KPOINTS in explicit mode.

    """

    kpoints = kpoints_parser_explicit.get_dict()
    assert kpoints['comment'] == 'Example file'
    points = kpoints['points']
    assert len(points) == 4
    np.testing.assert_allclose(points[0][0], np.array([0.0, 0.0, 0.0]))
    np.testing.assert_allclose(points[1][0], np.array([0.0, 0.0, 0.5]))
    np.testing.assert_allclose(points[2][0], np.array([0.0, 0.5, 0.5]))
    np.testing.assert_allclose(points[3][0], np.array([0.5, 0.5, 0.5]))
    assert math.isclose(points[0][1], 1.0, rel_tol=1e-07)
    assert math.isclose(points[1][1], 1.0, rel_tol=1e-07)
    assert math.isclose(points[2][1], 2.0, rel_tol=1e-07)
    assert math.isclose(points[3][1], 4.0, rel_tol=1e-07)
    assert points[0][2]
    assert points[1][2]
    assert points[2][2]
    assert points[3][2]
    kpoints_parser_explicit.modify('comment', 'Nada comment')
    point = Kpoint(np.array([0.0, 0.0, 0.0]), 1.0)
    kpoints_parser_explicit.modify('points', point, point_number=3)
    temp_file = str(tmpdir.join('KPOINTSEXP'))
    kpoints_parser_explicit.write(file_path=temp_file)
    kpoints_parser_explicit_temp = Kpoints(file_path=temp_file)
    kpoints_temp = kpoints_parser_explicit_temp.get_dict()
    assert kpoints_temp['comment'] == 'Nada comment'
    points = kpoints_temp['points']
    assert len(points) == 4
    np.testing.assert_allclose(points[0][0], np.array([0.0, 0.0, 0.0]))
    np.testing.assert_allclose(points[1][0], np.array([0.0, 0.0, 0.5]))
    np.testing.assert_allclose(points[2][0], np.array([0.0, 0.5, 0.5]))
    np.testing.assert_allclose(points[3][0], np.array([0.0, 0.0, 0.0]))
    assert math.isclose(points[0][1], 1.0, rel_tol=1e-07)
    assert math.isclose(points[1][1], 1.0, rel_tol=1e-07)
    assert math.isclose(points[2][1], 2.0, rel_tol=1e-07)
    assert math.isclose(points[3][1], 1.0, rel_tol=1e-07)
    assert points[0][2]
    assert points[1][2]
    assert points[2][2]
    assert points[3][2]