run_tests.py 3.41 KB
Newer Older
1
2
import unittest
import os
3
import logging
4
from cp2kparser.implementation.autoparser import get_parser
5
6
import cProfile
import pstats
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


#===============================================================================
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")
45
46
47
        n_conf = forces.shape[0]
        n_particles = forces.shape[1]
        n_dim = forces.shape[2]
48
        self.assertEqual(n_conf, 201)
49
        self.assertEqual(n_particles, 2)
50
51
52
53
54
        self.assertEqual(n_dim, 3)

    def test_forces_in_outputfile_1(self):
        parser = getparser("forces/outputfile/1")
        forces = parser.get_unformatted_quantity("particle_forces")
55
56
57
        n_conf = forces.shape[0]
        n_particles = forces.shape[1]
        n_dim = forces.shape[2]
58
        self.assertEqual(n_conf, 1)
59
        self.assertEqual(n_particles, 2)
60
61
62
63
64
65
66
        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)

67
68
    def test_forces_in_singlexyzfile_n(self):
        parser = getparser("forces/singlexyzfile/n")
Lauri Himanen's avatar
Lauri Himanen committed
69
        forces = parser.get_unformatted_quantity("particle_forces")
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
        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)

92
if __name__ == '__main__':
93
94
    logger = logging.getLogger("cp2kparser")
    logger.setLevel(logging.ERROR)
Lauri Himanen's avatar
Lauri Himanen committed
95
96
    # unittest.main()
    suite = unittest.TestLoader().loadTestsFromTestCase(TestForces)
97
98
99
100
101
102

    def runtests():
        unittest.TextTestRunner().run(suite)
    s = cProfile.run("runtests()", sort="cumtime", filename="profile_file")

    # unittest.TextTestRunner(verbosity=0).run(suite)