Coverage for gpaw/test/lcao/test_generate_ngto.py: 100%
66 statements
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-14 00:18 +0000
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-14 00:18 +0000
1import pytest
2import numpy as np
4from gpaw.basis_data import Basis
5from gpaw.mpi import world
6from gpaw.lcao.generate_ngto_augmented import \
7 create_GTO_dictionary as GTO, create_CGTO_dictionary as CGTO, \
8 generate_nao_ngto_basis, read_gaussian_basis_file
10pytestmark = pytest.mark.skipif(world.size > 1,
11 reason='world.size > 1')
14def test_read_gaussian(in_tmp_dir):
15 atom = 'Au'
16 description = 'test description\nline2'
17 gtos = [GTO(0, 0.2),
18 GTO('s', 0.1),
19 GTO(1, 0.05),
20 CGTO(1, [9.2, 2.1, 0.54, 0.15], [0.02, 0.18, 0.3, 0.5]),
21 CGTO(2, [0.05], [1.0])]
23 with open('gbs.txt', 'w') as f:
24 def w(s):
25 f.write('%s\n' % s)
26 w('****')
27 for desc in description.split('\n'):
28 w(f'! {desc}')
29 w(f'{atom} 0')
30 w('S 1 1.00')
31 w(' 0.2000000 1.000000D+00')
32 w('S 1 1.00')
33 w(' 0.1000000 1.0000000')
34 w('P 1 1.00')
35 w(' 0.0500000 1.0000000')
36 w('P 4 1.00')
37 w(' 9.200000D+00 2.000000E-02')
38 w(' 2.100000E+00 1.800000D-01')
39 w(' 5.400000e-01 3.000000D-01')
40 w(' 1.500000D-01 5.000000e-01')
41 w('D 1 1.00')
42 w(' 0.500000D-01 1.0000000')
43 w('****')
44 w('This line is never read')
46 gbs_atom, gbs_description, gbs_gtos = read_gaussian_basis_file('gbs.txt')
47 assert gbs_atom == atom
48 assert gbs_description == description
49 assert len(gbs_gtos) == len(gtos)
50 for gbs_gto, gto in zip(gbs_gtos, gtos):
51 for key in gto:
52 assert np.allclose(gbs_gto[key], gto[key])
55def test_generate(in_tmp_dir):
56 with open('gbs.txt', 'w') as f:
57 def w(s):
58 f.write('%s\n' % s)
59 w('C 0')
60 w('S 1 1.00')
61 w(' 1.596000D-01 1.000000D+00')
62 w('S 1 1.00')
63 w(' 0.0469000 1.0000000')
64 w('P 4 1.00')
65 w(' 9.439000D+00 3.810900D-02')
66 w(' 2.002000D+00 2.094800D-01')
67 w(' 5.456000D-01 5.085570D-01')
68 w(' 1.517000D-01 4.688420D-01')
69 w('P 1 1.00')
70 w(' 1.517000D-01 1.000000D+00')
71 w('P 1 1.00')
72 w(' 0.0404100 1.0000000')
73 w('D 1 1.00')
74 w(' 5.500000D-01 1.0000000')
75 w('D 1 1.00')
76 w(' 0.1510000 1.0000000')
78 gbs_atom, gbs_description, gtos = read_gaussian_basis_file('gbs.txt')
80 assert gbs_atom == 'C'
81 generate_nao_ngto_basis('C', xc='LDA', nao='dzp', name='NAO+NGTO',
82 gtos=gtos, gto_description=gbs_description)
84 basis = Basis.read_path('C', 'NAO+NGTO', 'C.NAO+NGTO.dzp.basis')
85 assert len(basis.bf_j) == 5 + 7