1# Copyright 2014-2018 The PySCF Developers. All Rights Reserved. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15import unittest 16import numpy as np 17from pyscf import lib 18from pyscf.pbc import gto, scf 19from pyscf.pbc.tools import k2gamma 20 21cell = gto.Cell() 22cell.a = ''' 23 1.755000 1.755000 -1.755000 24 1.755000 -1.755000 1.755000 25 -1.755000 1.755000 1.755000''' 26cell.atom = '''Li 0.00000 0.00000 0.00000''' 27#same type of basis for different elements 28cell.basis = 'gth-szv' 29cell.pseudo = {'Li': 'GTH-PBE-q3'} 30cell.mesh = [20]*3 31cell.verbose = 6 32cell.output = '/dev/null' 33cell.build() 34 35kpts = cell.make_kpts([2,2,2]) 36 37mf = scf.KUKS(cell, kpts) 38mf.xc = 'lda,vwn' 39mf.kernel() 40 41def tearDownModule(): 42 global cell, mf 43 del cell, mf 44 45 46class KnownValues(unittest.TestCase): 47 def test_k2gamma(self): 48 popa, popb = mf.mulliken_meta()[0] 49 self.assertAlmostEqual(lib.finger(popa).sum(), 1.5403023058, 7) 50 self.assertAlmostEqual(lib.finger(popb).sum(), 1.5403023058, 7) 51 52 popa, popb = k2gamma.k2gamma(mf).mulliken_meta()[0] 53 self.assertAlmostEqual(lib.finger(popa), 0.8007278745, 7) 54 self.assertAlmostEqual(lib.finger(popb), 0.8007278745, 7) 55 56 def test_double_translation_indices(self): 57 idx2 = k2gamma.translation_map(2) 58 idx3 = k2gamma.translation_map(3) 59 idx4 = k2gamma.translation_map(4) 60 61 ref = np.empty((2, 3, 4, 2, 3, 4), dtype=int) 62 for ix in range(2): 63 for iy in range(3): 64 for iz in range(4): 65 for jx in range(2): 66 for jy in range(3): 67 for jz in range(4): 68 ref[ix,iy,iz,jx,jy,jz] = idx2[ix,jx] * 12 + idx3[iy,jy] * 4 + idx4[iz,jz] 69 70 result = k2gamma.double_translation_indices([2,3,4]) 71 self.assertEqual(abs(ref.reshape(24,24) - result).max(), 0) 72 73 74if __name__ == '__main__': 75 print("Full Tests for pbc.tools.k2gamma") 76 unittest.main() 77