1#!/usr/bin/env python
2# Copyright 2019 The PySCF Developers. All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16import unittest
17import copy
18import tempfile
19from pyscf import lib, gto, scf
20from pyscf.tools import cubegen
21
22mol = gto.Mole()
23mol.atom = '''
24O 0.00000000,  0.000000,  0.119748
25H 0.00000000,  0.761561, -0.478993
26H 0.00000000, -0.761561, -0.478993 '''
27mol.verbose = 0
28mol.build()
29mf = scf.RHF(mol).run()
30
31def tearDownModule():
32    global mol, mf
33    del mol, mf
34
35class KnownValues(unittest.TestCase):
36    def test_mep(self):
37        ftmp = tempfile.NamedTemporaryFile()
38        mep = cubegen.mep(mol, ftmp.name, mf.make_rdm1(),
39                          nx=10, ny=10, nz=10)
40        self.assertEqual(mep.shape, (10,10,10))
41        self.assertAlmostEqual(lib.finger(mep), -0.3198103636180436, 9)
42
43        mep = cubegen.mep(mol, ftmp.name, mf.make_rdm1(),
44                          nx=10, ny=10, nz=10, resolution=0.5)
45        self.assertEqual(mep.shape, (12,18,15))
46        self.assertAlmostEqual(lib.finger(mep), -4.653995909548524, 9)
47
48    def test_orb(self):
49        ftmp = tempfile.NamedTemporaryFile()
50        orb = cubegen.orbital(mol, ftmp.name, mf.mo_coeff[:,0],
51                              nx=10, ny=10, nz=10)
52        self.assertEqual(orb.shape, (10,10,10))
53        self.assertAlmostEqual(lib.finger(orb), -0.11804191128016768, 9)
54
55        orb = cubegen.orbital(mol, ftmp.name, mf.mo_coeff[:,0],
56                              nx=10, ny=10, nz=10, resolution=0.5)
57        self.assertEqual(orb.shape, (12,18,15))
58        self.assertAlmostEqual(lib.finger(orb), -0.8591778390706646, 9)
59
60        orb = cubegen.orbital(mol, ftmp.name, mf.mo_coeff[:,0],
61                              nx=10, ny=1, nz=1)
62        self.assertEqual(orb.shape, (10,1,1))
63        self.assertAlmostEqual(lib.finger(orb), 6.921008881822988e-09, 9)
64
65
66    def test_rho(self):
67        ftmp = tempfile.NamedTemporaryFile()
68        rho = cubegen.density(mol, ftmp.name, mf.make_rdm1(),
69                              nx=10, ny=10, nz=10)
70        self.assertEqual(rho.shape, (10,10,10))
71        self.assertAlmostEqual(lib.finger(rho), -0.3740462814001553, 9)
72
73        rho = cubegen.density(mol, ftmp.name, mf.make_rdm1(),
74                              nx=10, ny=10, nz=10, resolution=0.5)
75        self.assertEqual(rho.shape, (12,18,15))
76        self.assertAlmostEqual(lib.finger(rho), -1.007950007160415, 9)
77
78if __name__ == "__main__":
79    print("Full Tests for molden")
80    unittest.main()
81
82
83
84