/
test_volumetric_data.py
72 lines (64 loc) · 3.12 KB
/
test_volumetric_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# coding: utf-8
# Copyright (c) Max-Planck-Institut für Eisenforschung GmbH - Computational Materials Design (CM) Department
# Distributed under the terms of "New BSD License", see the LICENSE file.
import unittest
import os
import posixpath
import numpy as np
from pyiron.vasp.volumetric_data import VaspVolumetricData
class TestVaspVolumetricData(unittest.TestCase):
"""
Testing routines in the vasp/structure module.
"""
@classmethod
def setUpClass(cls):
cls.file_location = os.path.dirname(os.path.abspath(__file__))
vol_directory = os.path.join(
cls.file_location, "../static/vasp_test_files/chgcar_samples"
)
file_list = os.listdir(vol_directory)
cls.file_list = [posixpath.join(vol_directory, f) for f in file_list]
cls.vd_obj = VaspVolumetricData()
def test_read_vol_data(self):
for chgcar_file in self.file_list:
if chgcar_file.split("/")[-1] == "CHGCAR_spin":
atoms, [total_data, diff_data] = self.vd_obj._read_vol_data(
chgcar_file, normalize=True
)
self.assertEqual(total_data.shape, diff_data.shape)
self.assertEqual(total_data.shape, (28, 28, 28))
self.assertEqual(
round(np.average(total_data) * atoms.get_volume(), 1), 8
)
self.vd_obj.from_file(chgcar_file, normalize=True)
self.assertTrue(np.array_equal(total_data, self.vd_obj.total_data))
self.assertTrue(np.array_equal(diff_data, self.vd_obj.diff_data))
atoms, [total_data_old, diff_data_old] = self.vd_obj._read_vol_data_old(
chgcar_file, normalize=True
)
self.assertTrue(np.array_equal(total_data_old, self.vd_obj.total_data))
self.assertTrue(np.array_equal(diff_data_old, self.vd_obj.diff_data))
if chgcar_file.split("/")[-1] == "CHGCAR_no_spin":
atoms, [total_data] = self.vd_obj._read_vol_data(
chgcar_file, normalize=True
)
self.assertEqual(total_data.shape, (28, 28, 28))
self.assertEqual(
round(np.average(total_data) * atoms.get_volume(), 1), 8
)
_, [total_data] = self.vd_obj._read_vol_data(
chgcar_file, normalize=False
)
self.assertEqual(round(np.average(total_data), 4), 8)
self.vd_obj.from_file(chgcar_file, normalize=False)
self.assertTrue(np.array_equal(total_data, self.vd_obj.total_data))
atoms, [total_data_old] = self.vd_obj._read_vol_data_old(
chgcar_file, normalize=False
)
self.assertTrue(np.array_equal(total_data_old, self.vd_obj.total_data))
if chgcar_file.split("/")[-1] == "CHGCAR_empty":
atoms, total_data = self.vd_obj._read_vol_data(
chgcar_file, normalize=True
)
self.assertIsNone(atoms)
self.assertIsNone(total_data)