def test_add_site_property(self): self.modifier.add_site_property("charge", [4.1, -2, -2, -2, -2]) s = self.modifier.modified_structure self.assertEqual(s[0].charge, 4.1) self.assertEqual(s[1].charge, -2) #test adding multiple properties. mod2 = MoleculeEditor(s) mod2.add_site_property("magmom", [3, 2, 2, 2, 2]) s = mod2.modified_structure self.assertEqual(s[0].charge, 4.1) self.assertEqual(s[0].magmom, 3)
def setUp(self): coords = [[0.000000, 0.000000, 0.000000], [0.000000, 0.000000, 1.089000], [1.026719, 0.000000, -0.363000], [-0.513360, -0.889165, -0.363000], [-0.513360, 0.889165, -0.363000]] mol = Molecule(["C", "H", "H", "H", "H"], coords) self.modifier = MoleculeEditor(mol)
class MoleculeEditorTest(unittest.TestCase): def setUp(self): coords = [[0.000000, 0.000000, 0.000000], [0.000000, 0.000000, 1.089000], [1.026719, 0.000000, -0.363000], [-0.513360, -0.889165, -0.363000], [-0.513360, 0.889165, -0.363000]] mol = Molecule(["C", "H", "H", "H", "H"], coords) self.modifier = MoleculeEditor(mol) def test_translate_sites(self): self.modifier.translate_sites([0, 1], [0.5, 0.5, 0.5]) self.assertTrue(np.array_equal(self.modifier.modified_structure .cart_coords[0], np.array([0.5, 0.5, 0.5]))) def test_append_site(self): self.modifier.append_site("Si", [0, 0.5, 0]) self.assertEqual(self.modifier.modified_structure.formula, "Si1 H4 C1", "Wrong formula!") self.assertRaises(ValueError, self.modifier.append_site, Element("Si"), np.array([0, 0.5, 0])) def test_modified_structure(self): self.modifier.insert_site(1, "Si", [0, 0.25, 0]) self.assertEqual(self.modifier.modified_structure.formula, "Si1 H4 C1", "Wrong formula!") self.modifier.delete_site(0) self.assertEqual(self.modifier.modified_structure.formula, "Si1 H4", "Wrong formula!") self.modifier.replace_site(0, "Ge") self.assertEqual(self.modifier.modified_structure.formula, "Ge1 H4", "Wrong formula!") self.modifier.append_site("Si", [0, 0.75, 0]) self.modifier.replace_species({Element("Si"): Element("Ge")}) self.assertEqual(self.modifier.modified_structure.formula, "Ge2 H4", "Wrong formula!") self.modifier.replace_species({Element("Ge"): {Element("Ge"): 0.5, Element("Si"): 0.5}}) self.assertEqual(self.modifier.modified_structure.formula, "Si1 Ge1 H4", "Wrong formula!") #this should change the .5Si .5Ge sites to .75Si .25Ge self.modifier.replace_species({Element("Ge"): {Element("Ge"): 0.5, Element("Si"): 0.5}}) self.assertEqual(self.modifier.modified_structure.formula, "Si1.5 Ge0.5 H4", "Wrong formula!") d = 0.1 pre_perturbation_sites = self.modifier.modified_structure.sites self.modifier.perturb_structure(distance=d) post_perturbation_sites = self.modifier.modified_structure.sites for i, x in enumerate(pre_perturbation_sites): self.assertAlmostEqual(x.distance(post_perturbation_sites[i]), d, 3, "Bad perturbation distance") def test_add_site_property(self): self.modifier.add_site_property("charge", [4.1, -2, -2, -2, -2]) s = self.modifier.modified_structure self.assertEqual(s[0].charge, 4.1) self.assertEqual(s[1].charge, -2) #test adding multiple properties. mod2 = MoleculeEditor(s) mod2.add_site_property("magmom", [3, 2, 2, 2, 2]) s = mod2.modified_structure self.assertEqual(s[0].charge, 4.1) self.assertEqual(s[0].magmom, 3)