• 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

37.1
/pymatgen/command_line/tests/test_mcsqs_caller.py
1
from __future__ import annotations
1✔
2

3
import os
1✔
4
import unittest
1✔
5
from shutil import which
1✔
6

7
import pytest
1✔
8
from monty.serialization import loadfn
1✔
9

10
from pymatgen.command_line.mcsqs_caller import run_mcsqs
1✔
11
from pymatgen.core.structure import Structure
1✔
12
from pymatgen.util.testing import PymatgenTest
1✔
13

14
__author__ = "Handong Ling, Rachel Woods-Robinson"
1✔
15
__maintainer__ = "Handong Ling, Rachel Woods-Robinson"
1✔
16
__email__ = "handongling@berkeley.edu, rwoodsrobinson@lbl.gov"
1✔
17

18

19
test_dir = os.path.join(PymatgenTest.TEST_FILES_DIR, "mcsqs")
1✔
20

21

22
@unittest.skipIf(not (which("mcsqs") and which("str2cif")), "mcsqs executable not present")
1✔
23
class McsqsCallerTest(PymatgenTest):
1✔
24
    def setUp(self):
1✔
25
        self.pztstructs = loadfn(os.path.join(test_dir, "pztstructs.json"))
×
26
        self.pztstructs2 = loadfn(os.path.join(test_dir, "pztstructs2.json"))
×
27
        self.struct = self.get_structure("Pb2TiZrO6")
×
28
        self.perfect_match_zzn_rs = loadfn(os.path.join(test_dir, "perfect_match_zzn_rs.json"))
×
29

30
    def test_mcsqs_caller_supercell(self):
1✔
31
        struct = self.struct.copy()
×
32
        struct.replace_species({"Ti": {"Ti": 0.5, "Zr": 0.5}, "Zr": {"Ti": 0.5, "Zr": 0.5}})
×
33
        sqs = run_mcsqs(struct, {2: 6, 3: 4}, scaling=[2, 1, 1], search_time=0.01, instances=1)
×
34

35
        matches = [sqs.bestsqs.matches(s) for s in self.pztstructs]
×
36
        assert True in matches
×
37

38
        assert isinstance(sqs.bestsqs, Structure)
×
39

40
        # ensures specific keys are present in cluster parsing for use in atomate
41
        assert set(sqs.clusters[0]) == {
×
42
            "multiplicity",
43
            "coordinates",
44
            "longest_pair_length",
45
            "num_points_in_cluster",
46
        }
47
        assert set(sqs.clusters[0]["coordinates"][0]) == {"cluster_function", "coordinates", "num_possible_species"}
×
48

49
    def test_mcsqs_caller_total_atoms(self):
1✔
50
        struct = self.struct.copy()
×
51
        struct.replace_species({"Ti": {"Ti": 0.5, "Zr": 0.5}, "Zr": {"Ti": 0.5, "Zr": 0.5}})
×
52
        sqs = run_mcsqs(struct, {2: 6, 3: 4}, scaling=2, search_time=0.01, instances=1)
×
53

54
        matches = [sqs.bestsqs.matches(s) for s in self.pztstructs2]
×
55
        assert True in matches
×
56

57
    def test_mcsqs_caller_total_atoms_auto_instances(self):
1✔
58
        struct = self.struct.copy()
×
59
        struct.replace_species({"Ti": {"Ti": 0.5, "Zr": 0.5}, "Zr": {"Ti": 0.5, "Zr": 0.5}})
×
60
        sqs = run_mcsqs(struct, {2: 6, 3: 4}, scaling=2, search_time=0.01, instances=None)
×
61

62
        matches = [sqs.bestsqs.matches(s) for s in self.pztstructs2]
×
63
        assert True in matches
×
64

65
    def test_mcsqs_caller_parallel(self):
1✔
66
        # explicitly test with four instances
67

68
        struct = self.struct.copy()
×
69
        struct.replace_species({"Ti": {"Ti": 0.5, "Zr": 0.5}, "Zr": {"Ti": 0.5, "Zr": 0.5}})
×
70
        sqs = run_mcsqs(struct, {2: 6, 3: 4}, scaling=2, search_time=0.01, instances=4)
×
71

72
        matches = [sqs.bestsqs.matches(s) for s in self.pztstructs2]
×
73
        assert True in matches
×
74

75
    def test_mcsqs_perfect_match_error(self):
1✔
76
        scale = 32 / self.perfect_match_zzn_rs.num_sites
×
77
        sqs = run_mcsqs(
×
78
            self.perfect_match_zzn_rs,
79
            {2: 6, 3: 4},
80
            scaling=scale,
81
            search_time=1,
82
            instances=1,
83
        )
84

85
        assert sqs.objective_function == "Perfect_match"
×
86

87
    def test_mcsqs_perfect_match_error_parallel(self):
1✔
88
        scale = 32 / self.perfect_match_zzn_rs.num_sites
×
89
        sqs = run_mcsqs(
×
90
            self.perfect_match_zzn_rs,
91
            {2: 6, 3: 4},
92
            scaling=scale,
93
            search_time=1,
94
            instances=4,
95
        )
96

97
        assert sqs.objective_function == "Perfect_match"
×
98

99
    def test_mcsqs_caller_runtime_error(self):
1✔
100
        struct = self.struct.copy()
×
101
        struct.replace_species({"Ti": {"Ti": 0.5, "Zr": 0.5}, "Zr": {"Ti": 0.5, "Zr": 0.5}})
×
102
        struct.replace_species({"Pb": {"Ti": 0.2, "Pb": 0.8}})
×
103
        struct.replace_species({"O": {"F": 0.8, "O": 0.2}})
×
104
        with pytest.raises(RuntimeError):
×
105
            run_mcsqs(struct, {2: 6, 3: 4}, 10, 0.000001)
×
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