def test_smactStruc_comp_key(self): """Test generation of a composition key for `SmactStructure`s.""" s1 = SmactStructure(*self._gen_empty_structure([('Ba', 2, 2), ('O', -2, 1), ('F', -1, 2)])) s2 = SmactStructure(*self._gen_empty_structure([('Fe', 2, 1), ('Fe', 3, 2), ('O', -2, 4)])) Ba = Species('Ba', 2) O = Species('O', -2) F = Species('F', -1) Fe2 = Species('Fe', 2) Fe3 = Species('Fe', 3) s3 = SmactStructure(*self._gen_empty_structure([(Ba, 2), (O, 1), (F, 2)])) s4 = SmactStructure(*self._gen_empty_structure([(Fe2, 1), (Fe3, 2), (O, 4)])) Ba_2OF_2 = "Ba_2_2+F_2_1-O_1_2-" Fe_3O_4 = "Fe_2_3+Fe_1_2+O_4_2-" self.assertEqual(s1.composition(), Ba_2OF_2) self.assertEqual(s2.composition(), Fe_3O_4) self.assertEqual(s3.composition(), Ba_2OF_2) self.assertEqual(s4.composition(), Fe_3O_4)
def test_ele_stoics(self): """Test acquiring element stoichiometries.""" s1 = SmactStructure(*self._gen_empty_structure([('Fe', 2, 1), ('Fe', 3, 2), ('O', -2, 4)])) s1_stoics = {'Fe': 3, 'O': 4} s2 = SmactStructure(*self._gen_empty_structure([('Ba', 2, 2), ('O', -2, 1), ('F', -1, 2)])) s2_stoics = {'Ba': 2, 'O': 1, 'F': 2} for test, expected in [(s1, s1_stoics), (s2, s2_stoics)]: with self.subTest(species=test.species): self.assertEqual(SmactStructure._get_ele_stoics(test.species), expected)
def test_has_species(self): """Test determining whether a species is in a `SmactStructure`.""" s1 = SmactStructure(*self._gen_empty_structure([('Ba', 2, 2), ('O', -2, 1), ('F', -1, 2)])) self.assertTrue(s1.has_species(('Ba', 2))) self.assertFalse(s1.has_species(('Ba', 3))) self.assertFalse(s1.has_species(('Ca', 2)))