run_tests.py 3.15 KB
Newer Older
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
import unittest
import os
from cp2kparser.implementation.autoparser import get_parser


#===============================================================================
def getparser(folder):
    path = os.path.dirname(os.path.realpath(__file__))
    path = os.path.join(path, folder)
    parser = get_parser(path)
    return parser


#===============================================================================
class TestFunctionals(unittest.TestCase):

    def getxc(self, folder, result):
        path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "functionals", folder)
        parser = get_parser(path)
        xc = parser.get_quantity("XC_functional")
        self.assertEqual(xc, result)

    def test_pade(self):
        self.getxc("pade", "LDA_XC_TETER93")

    def test_lda(self):
        self.getxc("lda", "LDA_XC_TETER93")

    def test_becke88(self):
        self.getxc("becke88", "GGA_X_B88")

    def test_blyp(self):
        self.getxc("blyp", "GGA_C_LYP_GGA_X_B88")


#===============================================================================
class TestForces(unittest.TestCase):

    def test_forces_in_outputfile_n(self):
        parser = getparser("forces/outputfile/n")
        forces = parser.get_unformatted_quantity("particle_forces")
42
43
44
        n_conf = forces.shape[0]
        n_particles = forces.shape[1]
        n_dim = forces.shape[2]
45
        self.assertEqual(n_conf, 201)
46
        self.assertEqual(n_particles, 2)
47
48
49
50
51
        self.assertEqual(n_dim, 3)

    def test_forces_in_outputfile_1(self):
        parser = getparser("forces/outputfile/1")
        forces = parser.get_unformatted_quantity("particle_forces")
52
53
54
        n_conf = forces.shape[0]
        n_particles = forces.shape[1]
        n_dim = forces.shape[2]
55
        self.assertEqual(n_conf, 1)
56
        self.assertEqual(n_particles, 2)
57
58
59
60
61
62
63
        self.assertEqual(n_dim, 3)

    def test_forces_in_outputfile_0(self):
        parser = getparser("forces/outputfile/0")
        forces = parser.get_unformatted_quantity("particle_forces")
        self.assertEqual(forces, None)

64
65
    def test_forces_in_singlexyzfile_n(self):
        parser = getparser("forces/singlexyzfile/n")
Lauri Himanen's avatar
Lauri Himanen committed
66
        forces = parser.get_unformatted_quantity("particle_forces")
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
        n_conf = forces.shape[0]
        n_particles = forces.shape[1]
        n_dim = forces.shape[2]
        self.assertEqual(n_conf, 201)
        self.assertEqual(n_particles, 2)
        self.assertEqual(n_dim, 3)

    def test_forces_in_singlexyzfile_1(self):
        parser = getparser("forces/singlexyzfile/1")
        forces = parser.get_unformatted_quantity("particle_forces")
        n_conf = forces.shape[0]
        n_particles = forces.shape[1]
        n_dim = forces.shape[2]
        self.assertEqual(n_conf, 1)
        self.assertEqual(n_particles, 2)
        self.assertEqual(n_dim, 3)

    def test_forces_in_singlexyzfile_0(self):
        parser = getparser("forces/singlexyzfile/0")
        forces = parser.get_unformatted_quantity("particle_forces")
        self.assertEqual(forces, None)

89
if __name__ == '__main__':
Lauri Himanen's avatar
Lauri Himanen committed
90
91
92
    # unittest.main()
    suite = unittest.TestLoader().loadTestsFromTestCase(TestForces)
    unittest.TextTestRunner(verbosity=0).run(suite)