• 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.59
/pymatgen/core/tests/test_interface.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

8
import numpy as np
1✔
9

10
from pymatgen.core.interface import Interface
1✔
11
from pymatgen.core.surface import SlabGenerator
1✔
12
from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
1✔
13
from pymatgen.util.testing import PymatgenTest
1✔
14

15

16
class InterfaceTest(PymatgenTest):
1✔
17
    def setUp(self):
1✔
18
        self.interface: Interface = self.get_structure("Si_SiO2_Interface")
1✔
19

20
    def test_basic_props(self):
1✔
21
        interface = self.interface
1✔
22
        assert isinstance(interface, Interface)
1✔
23

24
        assert len(interface.substrate_indices) == 14
1✔
25
        assert len(interface.film_indices) == 36
1✔
26
        assert len(interface.film_sites) == len(interface.film_indices)
1✔
27
        assert len(interface.substrate_sites) == len(interface.substrate_indices)
1✔
28
        assert interface.gap == 2.0
1✔
29
        assert np.allclose(interface.in_plane_offset, [0, 0])
1✔
30
        assert interface.vacuum_over_film == 20.0
1✔
31
        assert interface.film_termination == "O2_P6/mmm_4"
1✔
32
        assert interface.substrate_termination == "Si_P6/mmm_7"
1✔
33
        assert interface.film_layers == 6
1✔
34
        assert interface.substrate_layers == 2
1✔
35

36
        iface_dict = interface.as_dict()
1✔
37
        for k in [
1✔
38
            "lattice",
39
            "sites",
40
            "in_plane_offset",
41
            "gap",
42
            "vacuum_over_film",
43
            "interface_properties",
44
        ]:
45
            assert k in iface_dict
1✔
46
        assert isinstance(interface.from_dict(iface_dict), Interface)
1✔
47

48
    def test_gap_setter(self):
1✔
49
        interface = self.interface
1✔
50

51
        assert np.allclose(interface.gap, 2.0)
1✔
52

53
        max_sub_c = np.max(np.array([s.frac_coords for s in interface.substrate])[:, 2])
1✔
54
        min_film_c = np.min(np.array([f.frac_coords for f in interface.film])[:, 2])
1✔
55
        gap = (min_film_c - max_sub_c) * interface.lattice.c
1✔
56
        assert np.allclose(interface.gap, gap)
1✔
57

58
        interface.gap += 1
1✔
59

60
        assert np.allclose(interface.gap, 3.0)
1✔
61

62
        max_sub_c = np.max(np.array([s.frac_coords for s in interface.substrate])[:, 2])
1✔
63
        min_film_c = np.min(np.array([f.frac_coords for f in interface.film])[:, 2])
1✔
64
        gap = (min_film_c - max_sub_c) * interface.lattice.c
1✔
65
        assert np.allclose(interface.gap, gap)
1✔
66

67
    def test_in_plane_offset_setter(self):
1✔
68
        interface = self.interface
1✔
69
        init_coords = np.array(self.interface.frac_coords)
1✔
70
        interface.in_plane_offset = np.array([0.2, 0.2])
1✔
71

72
        assert np.allclose(interface.in_plane_offset, np.array([0.2, 0.2]))
1✔
73

74
        test_coords = np.array(init_coords)
1✔
75
        for i in interface.film_indices:
1✔
76
            test_coords[i] += [0.2, 0.2, 0]
1✔
77
        assert np.allclose(np.mod(test_coords, 1.0), np.mod(interface.frac_coords, 1.0))
1✔
78

79
    def test_vacuum_over_film_setter(self):
1✔
80
        interface = self.interface
1✔
81
        init_coords = self.interface.cart_coords
1✔
82

83
        assert interface.vacuum_over_film == 20
1✔
84

85
        interface.vacuum_over_film += 10
1✔
86

87
        assert interface.vacuum_over_film == 30
1✔
88
        assert np.allclose(init_coords, interface.cart_coords)
1✔
89

90
    def test_get_shifts_based_on_adsorbate_sites(self):
1✔
91
        # Only testing two tolerances as there appears to be significant numerical noise in this method
92
        assert len(self.interface.get_shifts_based_on_adsorbate_sites()) == 42
1✔
93
        assert len(self.interface.get_shifts_based_on_adsorbate_sites(tolerance=20.0)) == 1
1✔
94

95
    def test_from_slabs(self):
1✔
96
        si_struct = self.get_structure("Si")
1✔
97
        sio2_struct = self.get_structure("SiO2")
1✔
98
        si_conventional = SpacegroupAnalyzer(si_struct).get_conventional_standard_structure()
1✔
99
        sio2_conventional = SpacegroupAnalyzer(sio2_struct).get_conventional_standard_structure()
1✔
100

101
        si_slab = SlabGenerator(si_conventional, (1, 1, 1), 5, 10, reorient_lattice=True).get_slab()
1✔
102
        sio2_slab = SlabGenerator(sio2_conventional, (1, 0, 0), 5, 10, reorient_lattice=True).get_slab()
1✔
103

104
        interface = Interface.from_slabs(film_slab=si_slab, substrate_slab=sio2_slab)
1✔
105
        assert isinstance(interface, Interface)
1✔
106

107

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