/
test_vasp_import.py
83 lines (73 loc) · 3.74 KB
/
test_vasp_import.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
73
74
75
76
77
78
79
80
81
82
83
# 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 numpy as np
import os
from pyiron.project import Project
from pyiron.vasp.vasp import Vasp
from pyiron.vasp.volumetric_data import VaspVolumetricData
import warnings
class TestVaspImport(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.file_location = os.path.dirname(os.path.abspath(__file__))
cls.project = Project(os.path.join(cls.file_location, "vasp_import_testing"))
@classmethod
def tearDownClass(cls):
cls.file_location = os.path.dirname(os.path.abspath(__file__))
project = Project(os.path.join(cls.file_location, "vasp_import_testing"))
project.remove_jobs_silently(recursive=True)
project.remove(enable=True)
def test_import(self):
folder_path = os.path.join(
self.file_location, "../static/vasp_test_files/full_job_sample"
)
self.project.import_from_path(path=folder_path, recursive=False)
ham = self.project.load("full_job_sample")
self.assertTrue(isinstance(ham, Vasp))
self.assertEqual(ham.get_nelect(), 16)
self.assertTrue(
np.array_equal(ham.structure.get_initial_magnetic_moments(), [-1, -1])
)
self.assertIsInstance(ham.output.unwrapped_positions, np.ndarray)
self.assertEqual(ham["output/structure/positions"][1, 2], 2.7999999999999997 * 0.4999999999999999)
self.assertEqual(ham["output/generic/dft/e_fermi_list"][-1], 5.9788)
self.assertEqual(ham["output/generic/dft/vbm_list"][-1], 6.5823)
self.assertEqual(ham["output/generic/dft/cbm_list"][-1], 6.7396)
folder_path = os.path.join(
self.file_location, "../static/vasp_test_files/full_job_minor_glitch"
)
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
self.project.import_from_path(path=folder_path, recursive=False)
self.assertEqual(len(w), 3)
ham = self.project.load("full_job_minor_glitch")
self.assertTrue(isinstance(ham, Vasp))
self.assertEqual(ham.get_nelect(), 16)
self.assertIsInstance(ham.output.unwrapped_positions, np.ndarray)
self.assertEqual(ham["output/generic/dft/scf_energy_free"][0][1], 0.0)
self.assertEqual(ham["output/electronic_structure/occ_matrix"].shape, (1, 4, 12))
self.assertEqual(ham["output/electronic_structure/eig_matrix"].shape, (1, 4, 12))
self.assertEqual(ham._generic_input["reduce_kpoint_symmetry"], ham.reduce_kpoint_symmetry)
def test_incar_import(self):
file_path = os.path.join(
self.file_location, "../static/vasp_test_files/incar_samples/INCAR_1"
)
ham = self.project.create_job(self.project.job_type.Vasp, "incar_import")
ham.input.incar.read_input(file_path, ignore_trigger="!")
self.assertTrue(ham.input.incar["LWAVE"])
self.assertTrue(ham.input.incar["LCHARG"])
self.assertTrue(ham.input.incar["LVTOT"])
self.assertFalse(ham.input.incar["LDIPOL"])
self.assertFalse(ham.input.incar["LVHAR"])
self.assertFalse(ham.input.incar["LORBIT"])
self.assertTrue(ham.input.incar["LCORE"])
self.assertFalse(ham.input.incar["LTEST"])
self.assertEqual(ham.input.incar["POTIM"], 0.5)
def test_output(self):
ham = self.project.inspect("full_job_sample")
self.assertEqual(ham["output/generic/dft/energy_free"][-1], -17.7379867884)
self.assertIsInstance(ham["output/charge_density"].to_object(), VaspVolumetricData)
if __name__ == "__main__":
unittest.main()