• 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

97.56
/pymatgen/entries/tests/test_correction_calculator.py
1
from __future__ import annotations
1✔
2

3
import os
1✔
4
import unittest
1✔
5

6
import pytest
1✔
7

8
from pymatgen.entries.correction_calculator import CorrectionCalculator
1✔
9
from pymatgen.util.testing import PymatgenTest
1✔
10

11

12
class CorrectionCalculatorTest(unittest.TestCase):
1✔
13
    def setUp(self):
1✔
14
        self.exclude_polyanions = [
1✔
15
            "SO4",
16
            "CO3",
17
            "NO3",
18
            "OCl3",
19
            "SiO4",
20
            "SeO3",
21
            "TiO3",
22
            "TiO4",
23
        ]
24

25
        self.normal_corrections = {
1✔
26
            "oxide": (-0.74, 0.0017),
27
            "peroxide": (-0.466, 0.0186),
28
            "superoxide": (-0.16, 0.0075),
29
            "S": (-0.639, 0.0121),
30
            "F": (-0.485, 0.0025),
31
            "Cl": (-0.593, 0.0016),
32
            "Br": (-0.538, 0.0022),
33
            "I": (-0.377, 0.0059),
34
            "N": (-0.344, 0.0084),
35
            "Se": (-0.473, 0.0341),
36
            "Si": (-0.406, 0.0621),
37
            "Sb": (-0.192, 0.0089),
38
            "Te": (-0.419, 0.024),
39
            "V": (-1.602, 0.006),
40
            "Cr": (-1.893, 0.0093),
41
            "Mn": (-1.588, 0.0051),
42
            "Fe": (-2.182, 0.009),
43
            "Co": (-1.535, 0.0059),
44
            "Ni": (-2.504, 0.0105),
45
            "W": (-4.57, 0.0181),
46
            "Mo": (-3.058, 0.0085),
47
            "H": (-0.178, 0.0013),
48
            "ozonide": (0, 0),
49
        }
50

51
        self.warnings_allowed_corrections = {
1✔
52
            "oxide": (-0.589, 0.0013),
53
            "peroxide": (-0.467, 0.019),
54
            "superoxide": (-0.16, 0.0075),
55
            "S": (-0.637, 0.0123),
56
            "F": (-0.481, 0.0025),
57
            "Cl": (-0.594, 0.0016),
58
            "Br": (-0.538, 0.0022),
59
            "I": (-0.376, 0.0059),
60
            "N": (-0.042, 0.0077),
61
            "Se": (-0.378, 0.0304),
62
            "Si": (-0.09, 0.0264),
63
            "Sb": (-0.197, 0.0089),
64
            "Te": (-0.42, 0.0238),
65
            "V": (-1.914, 0.0056),
66
            "Cr": (-2.227, 0.0089),
67
            "Mn": (-1.781, 0.0048),
68
            "Fe": (-2.214, 0.0081),
69
            "Co": (-1.549, 0.0055),
70
            "Ni": (-2.294, 0.0085),
71
            "W": (-5.263, 0.0173),
72
            "Mo": (-3.49, 0.008),
73
            "H": (-0.176, 0.0013),
74
            "ozonide": (0, 0),
75
        }
76

77
        self.no_uncertainties_corrections = {
1✔
78
            "oxide": (-0.749, 0.0198),
79
            "peroxide": (-0.466, 0.0492),
80
            "superoxide": (-0.155, 0.0545),
81
            "S": (-0.639, 0.0386),
82
            "F": (-0.444, 0.0206),
83
            "Cl": (-0.518, 0.0266),
84
            "Br": (-0.439, 0.0294),
85
            "I": (-0.29, 0.0327),
86
            "N": (-0.357, 0.0617),
87
            "Se": (-0.361, 0.0546),
88
            "Si": (-0.439, 0.1048),
89
            "Sb": (-0.286, 0.0775),
90
            "Te": (-0.457, 0.0524),
91
            "V": (-1.655, 0.0782),
92
            "Cr": (-1.836, 0.0699),
93
            "Mn": (-1.58, 0.071),
94
            "Fe": (-2.168, 0.0624),
95
            "Co": (-1.605, 0.0794),
96
            "Ni": (-2.516, 0.099),
97
            "W": (-4.553, 0.1235),
98
            "Mo": (-3.032, 0.1118),
99
            "H": (-0.137, 0.0313),
100
            "ozonide": (0, 0),
101
        }
102

103
        self.test_dir = os.path.join(PymatgenTest.TEST_FILES_DIR, "correction_calculator")
1✔
104

105
    def tearDown(self):
1✔
106
        pass
1✔
107

108
    def test_normal_corrections(self):
1✔
109
        """
110
        Test that the values in MPCompatiblity.yaml are reproduced correctly.
111
        """
112
        exp_path = os.path.join(self.test_dir, "exp_compounds_norm.json.gz")
1✔
113
        calc_path = os.path.join(self.test_dir, "calc_compounds_norm.json.gz")
1✔
114

115
        calculator = CorrectionCalculator(exclude_polyanions=self.exclude_polyanions)
1✔
116
        corrs = calculator.compute_from_files(exp_path, calc_path)
1✔
117

118
        assert corrs == self.normal_corrections
1✔
119

120
    def test_warnings_options(self):
1✔
121
        """
122
        Test that compounds can be included/excluded using the allow_{warning} optional parameters.
123
        """
124
        exp_path = os.path.join(self.test_dir, "exp_compounds_norm.json.gz")
1✔
125
        calc_path = os.path.join(self.test_dir, "calc_compounds_norm.json.gz")
1✔
126

127
        calculator = CorrectionCalculator(max_error=1, exclude_polyanions=[], allow_unstable=True)
1✔
128
        corrs = calculator.compute_from_files(exp_path, calc_path)
1✔
129

130
        assert corrs == self.warnings_allowed_corrections
1✔
131

132
    def test_no_uncertainties(self):
1✔
133
        """
134
        Test that corrections can be calculated with no uncertainties.
135
        """
136
        exp_path = os.path.join(self.test_dir, "exp_no_error_compounds.json.gz")
1✔
137
        calc_path = os.path.join(self.test_dir, "calc_compounds_norm.json.gz")
1✔
138

139
        calculator = CorrectionCalculator(exclude_polyanions=self.exclude_polyanions)
1✔
140
        corrs = calculator.compute_from_files(exp_path, calc_path)
1✔
141

142
        assert corrs == self.no_uncertainties_corrections
1✔
143

144
    def test_missing_entry_response(self):
1✔
145
        """
146
        Test that correct error is raised (ValueError) if the input is missing a computed entry.
147
        """
148
        exp_path = os.path.join(self.test_dir, "exp_compounds_norm.json.gz")
1✔
149
        calc_path = os.path.join(self.test_dir, "calc_missing_compounds.json.gz")
1✔
150

151
        calculator = CorrectionCalculator(exclude_polyanions=self.exclude_polyanions)
1✔
152
        with pytest.raises(ValueError):
1✔
153
            calculator.compute_from_files(exp_path, calc_path)
1✔
154

155

156
if __name__ == "__main__":
1✔
157
    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