1#!/usr/bin/env python
2# Copyright 2014-2020 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#
16# Author: Qiming Sun <osirpt.sun@gmail.com>
17#
18
19import unittest
20import numpy
21from pyscf import gto
22from pyscf import symm
23
24def get_so(atoms, basis, cart=False):
25    atoms = gto.mole.format_atom(atoms)
26    gpname, origin, axes = symm.detect_symm(atoms)
27    gpname, axes = symm.subgroup(gpname, axes)
28    atoms = gto.mole.format_atom(atoms, origin, axes, 'Bohr')
29    mol = gto.M(atom=atoms, basis=basis, unit='Bohr', spin=None)
30    mol.cart = cart
31    so = symm.basis.symm_adapted_basis(mol, gpname)[0]
32    n = 0
33    for c in so:
34        if c.size > 0:
35            n += c.shape[1]
36    assert(n == mol.nao_nr())
37    return n, so
38
39
40class KnowValues(unittest.TestCase):
41    def test_symm_orb_h2o(self):
42        atoms = [['O' , (1. , 0.    , 0.   ,)],
43                 [1   , (0. , -.757 , 0.587,)],
44                 [1   , (0. , 0.757 , 0.587,)] ]
45        basis = {'H': gto.basis.load('cc_pvqz', 'C'),
46                 'O': gto.basis.load('cc_pvqz', 'C'),}
47        self.assertEqual(get_so(atoms,basis  )[0], 165)
48        self.assertEqual(get_so(atoms,basis,1)[0], 210)
49
50    def test_symm_orb_d2h(self):
51        atoms = [[1, (0., 0., 0.)],
52                 [1, (1., 0., 0.)],
53                 [1, (0., 1., 0.)],
54                 [1, (0., 0., 1.)],
55                 [1, (-1, 0., 0.)],
56                 [1, (0.,-1., 0.)],
57                 [1, (0., 0.,-1.)]]
58        basis = {'H': gto.basis.load('cc_pvqz', 'C'),}
59        self.assertEqual(get_so(atoms,basis  )[0], 385)
60        self.assertEqual(get_so(atoms,basis,1)[0], 490)
61
62    def test_symm_orb_c2v(self):
63        atoms = [[1, (1., 0., 2.)],
64                 [2, (0., 1., 0.)],
65                 [1, (-2.,0.,-1.)],
66                 [2, (0.,-1., 0.)]]
67        basis = {'H' : gto.basis.load('cc_pvqz', 'C'),
68                 'He': gto.basis.load('cc_pvqz', 'C'),}
69        self.assertEqual(get_so(atoms,basis)[0], 220)
70
71    def test_symm_orb_c2h(self):
72        atoms = [[1, (1., 0., 2.)],
73                 [2, (0., 1., 0.)],
74                 [1, (-1.,0.,-2.)],
75                 [2, (0.,-1., 0.)]]
76        basis = {'H' : gto.basis.load('cc_pvqz', 'C'),
77                 'He': gto.basis.load('cc_pvqz', 'C'),}
78        self.assertEqual(get_so(atoms,basis  )[0], 220)
79        self.assertEqual(get_so(atoms,basis,1)[0], 280)
80
81        atoms = [[1, (1., 0., 1.)],
82                 [1, (1., 0.,-1.)],
83                 [2, (0., 0., 2.)],
84                 [2, (2., 0.,-2.)],
85                 [3, (1., 1., 0.)],
86                 [3, (1.,-1., 0.)]]
87        basis = {'H' : gto.basis.load('cc_pvqz', 'C'),
88                 'He': gto.basis.load('cc_pvqz', 'C'),
89                 'Li': gto.basis.load('cc_pvqz', 'C'),}
90        self.assertEqual(get_so(atoms,basis  )[0], 330)
91        self.assertEqual(get_so(atoms,basis,1)[0], 420)
92
93    def test_symm_orb_d2(self):
94        atoms = [[1, (1., 0., 1.)],
95                 [1, (1., 0.,-1.)],
96                 [2, (0., 0., 2.)],
97                 [2, (2., 0., 2.)],
98                 [2, (1., 1.,-2.)],
99                 [2, (1.,-1.,-2.)]]
100        basis = {'H' : gto.basis.load('cc_pvqz', 'C'),
101                 'He': gto.basis.load('cc_pvqz', 'C'),}
102        self.assertEqual(get_so(atoms,basis  )[0], 330)
103        self.assertEqual(get_so(atoms,basis,1)[0], 420)
104
105    def test_symm_orb_ci(self):
106        atoms = [[1, ( 1., 0., 0.)],
107                 [2, ( 0., 1., 0.)],
108                 [3, ( 0., 0., 1.)],
109                 [4, ( .5, .5, .5)],
110                 [1, (-1., 0., 0.)],
111                 [2, ( 0.,-1., 0.)],
112                 [3, ( 0., 0.,-1.)],
113                 [4, (-.5,-.5,-.5)]]
114        basis = {'H' : gto.basis.load('cc_pvqz', 'C'),
115                 'He': gto.basis.load('cc_pvqz', 'C'),
116                 'Li': gto.basis.load('cc_pvqz', 'C'),
117                 'Be': gto.basis.load('cc_pvqz', 'C'),}
118        self.assertEqual(get_so(atoms,basis)[0], 440)
119
120    def test_symm_orb_cs(self):
121        atoms = [[1, (1., 0., 2.)],
122                 [2, (1., 0., 0.)],
123                 [3, (2., 0.,-1.)],
124                 [4, (0., 0., 1.)]]
125        basis = {'H' : gto.basis.load('cc_pvqz', 'C'),
126                 'He': gto.basis.load('cc_pvqz', 'C'),
127                 'Li': gto.basis.load('cc_pvqz', 'C'),
128                 'Be': gto.basis.load('cc_pvqz', 'C'),}
129        self.assertEqual(get_so(atoms,basis)[0], 220)
130
131    def test_symm_orb_c1(self):
132        atoms = [[1, ( 1., 0., 0.)],
133                 [2, ( 0., 1., 0.)],
134                 [3, ( 0., 0., 1.)],
135                 [4, ( .5, .5, .5)]]
136        basis = {'H' : gto.basis.load('cc_pvqz', 'C'),
137                 'He': gto.basis.load('cc_pvqz', 'C'),
138                 'Li': gto.basis.load('cc_pvqz', 'C'),
139                 'Be': gto.basis.load('cc_pvqz', 'C'),}
140        self.assertEqual(get_so(atoms,basis)[0], 220)
141
142    def test_symm_orb_c3v_as_cs(self):
143        atoms = [['Fe', ( 0.000000  , 0.000000  , 0.015198 )],
144                 ['C',  ( 0.000000  , 0.000000  , -1.938396)],
145                 ['C',  ( 0.000000  , -1.394127 , -1.614155)],
146                 ['C',  ( -1.207349 , 0.697064  , -1.614155)],
147                 ['C',  ( 1.207349  , 0.697064  , -1.614155)],
148                 ['H',  ( -0.922915 , -1.965174 , -1.708739)],
149                 ['H',  ( 0.922915  , -1.965174 , -1.708739)],
150                 ['H',  ( -1.240433 , 1.781855  , -1.708739)],
151                 ['H',  ( -2.163348 , 0.183319  , -1.708739)],
152                 ['H',  ( 2.163348  , 0.183319  , -1.708739)],
153                 ['H',  ( 1.240433  , 1.781855  , -1.708739)],
154                 ['C',  ( 0.000000  , 1.558543  , 0.887110 )],
155                 ['C',  ( 1.349738  , -0.779272 , 0.887110 )],
156                 ['C',  ( -1.349738 , -0.779272 , 0.887110 )],
157                 ['O',  ( 0.000000  , 2.572496  , 1.441607 )],
158                 ['O',  ( 2.227847  , -1.286248 , 1.441607 )],
159                 ['O',  ( -2.227847 , -1.286248 , 1.441607 )],]
160        basis = {'Fe':gto.basis.load('def2svp', 'C'),
161                 'C': gto.basis.load('def2svp', 'C'),
162                 'H': gto.basis.load('def2svp', 'C'),
163                 'O': gto.basis.load('def2svp', 'C'),}
164        n, so = get_so(atoms, basis)
165        self.assertEqual([c.shape[1] for c in so], [134, 104])
166
167    def test_symm_orb_so3(self):
168        atoms = [['Si', (0, 0, 0)]]
169        basis = {'Si': gto.basis.load('ccpvtz', 'Si')}
170        n, so = get_so(atoms, basis)
171        idx, idy = numpy.where(numpy.hstack(so) != 0)
172        self.assertEqual(idy.argsort().tolist(),
173                         [0,1,2,3,4,6,9,12,15,7,10,13,16,5,8,11,14,17,22,18,23,19,24,20,25,21,26,27,28,29,30,31,32,33])
174
175
176if __name__ == "__main__":
177    print("Full Tests symm.basis")
178    unittest.main()
179