Skip to content

Commit

Permalink
add test into test_surface.py
Browse files Browse the repository at this point in the history
  • Loading branch information
jinlhr542 committed Aug 8, 2024
1 parent 1d04f88 commit 4cadfdd
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions tests/core/test_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from pymatgen.symmetry.groups import SpaceGroup
from pymatgen.util.testing import TEST_FILES_DIR, PymatgenTest
from pytest import approx

from pymatgen.analysis.interfaces import CoherentInterfaceBuilder, SubstrateAnalyzer

class TestSlab(PymatgenTest):
def setUp(self):
Expand Down Expand Up @@ -689,7 +689,7 @@ def test_previous_reconstructions(self):
assert any(len(match.group_structures([struct, slab])) == 1 for slab in slabs)


class MillerIndexFinderTests(PymatgenTest):
class TestMillerIndexFinder(PymatgenTest):
def setUp(self):
self.cscl = Structure.from_spacegroup("Pm-3m", Lattice.cubic(4.2), ["Cs", "Cl"], [[0, 0, 0], [0.5, 0.5, 0.5]])
self.Fe = Structure.from_spacegroup("Im-3m", Lattice.cubic(2.82), ["Fe"], [[0, 0, 0]])
Expand Down Expand Up @@ -846,3 +846,41 @@ def test_miller_index_from_sites(self):
s3 = np.array([1.1595, 0.66943764, 0.9065])
hkl = miller_index_from_sites(matrix, [s1, s2, s3])
assert hkl == (2, -1, 0)

class TestCoherentInterfaceBuilder(unittest.TestCase):

def setUp(self):
#build substrate & film structure
basis = [[0, 0, 0], [0.25, 0.25, 0.25]]
self.substrate = Structure(
Lattice.cubic(a=5.431),
["Si", "Si"],
basis)
self.film = substrate = Structure(
Lattice.cubic(a=5.658),
["Ge", "Ge"],
basis)

def test_termination_searching(self):
sub_analyzer = SubstrateAnalyzer()
matches = list(sub_analyzer.calculate(substrate = self.substrate, film = self.film))
cib = CoherentInterfaceBuilder(film_structure = self.film,
substrate_structure=self.substrate,
film_miller=matches[0].film_miller,
substrate_miller=matches[0].substrate_miller,
zslgen=sub_analyzer,termination_ftol=1e-4,label_index=True,\
filting_out_sym_slabs=False)
self.assertTrue(cib.terminations == [('1_Ge_P4/mmm_1', '1_Si_P4/mmm_1'),\
('1_Ge_P4/mmm_1', '2_Si_P4/mmm_1'),\
('2_Ge_P4/mmm_1', '1_Si_P4/mmm_1'),\
('2_Ge_P4/mmm_1', '2_Si_P4/mmm_1')], \
"""
termination results wrong; the correct list should be:
[('1_Ge_P4/mmm_1', '1_Si_P4/mmm_1'),
('1_Ge_P4/mmm_1', '2_Si_P4/mmm_1'),
('2_Ge_P4/mmm_1', '1_Si_P4/mmm_1'),
('2_Ge_P4/mmm_1', '2_Si_P4/mmm_1')].
""")

if __name__ == "__main__":
unittest.main()

0 comments on commit 4cadfdd

Please sign in to comment.