• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

materialsproject / pymatgen / 4075885785

pending completion
4075885785

push

github

Shyue Ping Ong
Merge branch 'master' of github.com:materialsproject/pymatgen

96 of 96 new or added lines in 27 files covered. (100.0%)

81013 of 102710 relevant lines covered (78.88%)

0.79 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

98.53
/pymatgen/io/cp2k/tests/test_sets.py
1
# Copyright (c) Pymatgen Development Team.
2
# Distributed under the terms of the MIT License.
3

4
from __future__ import annotations
1✔
5

6
import unittest
1✔
7
from pathlib import Path
1✔
8

9
import pytest
1✔
10
from pytest import approx
1✔
11

12
from pymatgen.core.structure import Molecule, Structure
1✔
13
from pymatgen.io.cp2k.sets import (
1✔
14
    SETTINGS,
15
    Cp2kValidationError,
16
    DftSet,
17
    GaussianTypeOrbitalBasisSet,
18
    GthPotential,
19
)
20
from pymatgen.util.testing import PymatgenTest
1✔
21

22
Si_structure = Structure(
1✔
23
    lattice=[[0, 2.734364, 2.734364], [2.734364, 0, 2.734364], [2.734364, 2.734364, 0]],
24
    species=["Si", "Si"],
25
    coords=[[0, 0, 0], [0.25, 0.25, 0.25]],
26
)
27
molecule = Molecule(species=["Si"], coords=[[0, 0, 0]])
1✔
28

29

30
class SetTest(PymatgenTest):
1✔
31
    def setUp(self) -> None:
1✔
32
        self.TEST_FILES_DIR = Path.joinpath(self.TEST_FILES_DIR, "cp2k")
1✔
33
        SETTINGS["PMG_CP2K_DATA_DIR"] = self.TEST_FILES_DIR
1✔
34
        self.setkwargs = {
1✔
35
            "print_pdos": False,
36
            "print_dos": False,
37
            "print_v_hartree": False,
38
            "print_e_density": False,
39
        }
40
        return super().setUp()
1✔
41

42
    def test_dft_set(self):
1✔
43
        # Basis sets / potentials searching
44
        basis_and_potential = {"basis_type": "SZV", "potential_type": "Pseudopotential", "functional": None}
1✔
45
        ss = DftSet(Si_structure, basis_and_potential=basis_and_potential, xc_functionals="PBE")
1✔
46

47
        # Basis sets / potentials by name
48
        basis_and_potential = {"Si": {"basis": "SZV-GTH-q4", "potential": "GTH-PBE-q4"}}
1✔
49
        ss = DftSet(Si_structure, basis_and_potential=basis_and_potential, xc_functionals="PBE")
1✔
50

51
        # Basis sets / potentials by name with ADMM
52
        basis_and_potential = {"Si": {"basis": "SZV-GTH-q4", "potential": "GTH-PBE-q4", "aux_basis": "cFIT3"}}
1✔
53
        ss = DftSet(Si_structure, basis_and_potential=basis_and_potential, xc_functionals="PBE")
1✔
54
        basis_sets = ss["force_eval"]["subsys"]["Si_1"].get("basis_set")
1✔
55
        assert any("AUX_FIT" in b.values for b in basis_sets)
1✔
56
        assert any("cFIT3" in b.values for b in basis_sets)
1✔
57

58
        # Basis sets / potentials by hash value
59
        basis_and_potential = {
1✔
60
            "Si": {"basis": "30767c18f6e7e46c1b56c1d34ff6007d", "potential": "21e2f468a18404ff6119fe801da81e43"}
61
        }
62
        ss = DftSet(Si_structure, basis_and_potential=basis_and_potential, xc_functionals="PBE")
1✔
63

64
        # Basis set / potential with objects
65
        gto = """
1✔
66
         Si SZV-MOLOPT-GTH SZV-MOLOPT-GTH-q4
67
            1
68
            2 0 1 6 1 1
69
                2.693604434572  0.015333179500 -0.005800105400
70
                1.359613855428 -0.283798205000 -0.059172026000
71
                0.513245176029 -0.228939692700  0.121487149900
72
                0.326563011394  0.728834000900  0.423382421100
73
                0.139986977410  0.446205299300  0.474592116300
74
                0.068212286977  0.122025292800  0.250129397700
75
        """
76
        pot = """Si GTH-BLYP-q4 GTH-BLYP
1✔
77
                2    2
78
                0.44000000    1    -6.25958674
79
                2
80
                0.44465247    2     8.31460936    -2.33277947
81
                                                    3.01160535
82
                0.50279207    1     2.33241791"""
83
        basis_and_potential = {
1✔
84
            "Si": {"basis": GaussianTypeOrbitalBasisSet.from_string(gto), "potential": GthPotential.from_string(pot)}
85
        }
86
        ss = DftSet(Si_structure, basis_and_potential=basis_and_potential, xc_functionals="PBE", **self.setkwargs)
1✔
87
        assert ss.cutoff == approx(150)
1✔
88

89
        # Test that printing will activate sections
90
        assert not ss.check("motion")
1✔
91
        ss.activate_motion()
1✔
92
        assert ss.check("motion")
1✔
93
        assert not ss.check("force_eval/dft/print/pdos")
1✔
94
        ss.print_pdos()
1✔
95
        assert ss.check("force_eval/dft/print/pdos")
1✔
96
        assert not ss.check("force_eval/dft/print/v_hartree_cube")
1✔
97
        ss.print_v_hartree()
1✔
98
        assert ss.check("force_eval/dft/print/v_hartree_cube")
1✔
99

100
        # Test property activators
101
        assert not ss.check("force_eval/properties")
1✔
102
        ss.activate_nmr()
1✔
103
        ss.activate_epr()
1✔
104
        ss.activate_hyperfine()
1✔
105
        ss.activate_polar()
1✔
106
        ss.activate_tddfpt()
1✔
107
        assert ss.check("force_eval/properties/linres/localize")
1✔
108
        assert ss.check("force_eval/properties/linres/nmr/print/chi_tensor")
1✔
109
        assert ss.check("force_eval/properties/linres/epr/print/g_tensor")
1✔
110
        assert ss.check("force_eval/properties/tddfpt")
1✔
111
        assert ss.check("force_eval/dft/print/hyperfine_coupling_tensor")
1✔
112

113
        # For at least up to v2022.1, DOS doesn't work without kpoints
114
        assert not ss.check("force_eval/dft/print/dos")
1✔
115
        ss.print_dos()
1✔
116
        assert not ss.check("force_eval/dft/print/dos")
1✔
117

118
        assert not ss.check("force_eval/dft/xc/hf")
1✔
119
        ss.activate_hybrid()
1✔
120
        assert ss.check("force_eval/dft/xc/hf")
1✔
121
        assert ss.check("force_eval/dft/auxiliary_density_matrix_method")
1✔
122

123
        # Validator will trip for kpoints + hfx
124
        ss.update({"force_eval": {"dft": {"kpoints": {}}}})
1✔
125
        with pytest.raises(Cp2kValidationError):
1✔
126
            ss.validate()
1✔
127

128
        ss = DftSet(molecule, basis_and_potential=basis_and_potential, xc_functionals="PBE")
1✔
129
        assert ss.check("force_eval/dft/poisson")
1✔
130
        assert ss["force_eval"]["dft"]["poisson"].get("periodic").values[0].upper() == "NONE"
1✔
131

132

133
if __name__ == "__main__":
1✔
134
    unittest.main()
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc