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


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

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

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

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

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