def test_apply_transformation(self): enum_trans = EnumerateStructureTransformation(refine_structure=True) enum_trans2 = EnumerateStructureTransformation(refine_structure=True, sort_criteria="nsites") p = Poscar.from_file(os.path.join(test_dir, 'POSCAR.LiFePO4'), check_for_POTCAR=False) struct = p.structure expected_ans = [1, 3, 1] for i, frac in enumerate([0.25, 0.5, 0.75]): trans = SubstitutionTransformation({'Fe': {'Fe': frac}}) s = trans.apply_transformation(struct) oxitrans = OxidationStateDecorationTransformation( {'Li': 1, 'Fe': 2, 'P': 5, 'O': -2}) s = oxitrans.apply_transformation(s) alls = enum_trans.apply_transformation(s, 100) self.assertEqual(len(alls), expected_ans[i]) self.assertIsInstance(trans.apply_transformation(s), Structure) for ss in alls: self.assertIn("energy", ss) alls = enum_trans2.apply_transformation(s, 100) self.assertEqual(len(alls), expected_ans[i]) self.assertIsInstance(trans.apply_transformation(s), Structure) for ss in alls: self.assertIn("num_sites", ss) # make sure it works for non-oxidation state decorated structure trans = SubstitutionTransformation({'Fe': {'Fe': 0.5}}) s = trans.apply_transformation(struct) alls = enum_trans.apply_transformation(s, 100) self.assertEqual(len(alls), 3) self.assertIsInstance(trans.apply_transformation(s), Structure) for s in alls: self.assertNotIn("energy", s)
def test_apply_transformation(self): enum_trans = EnumerateStructureTransformation(refine_structure=True) p = Poscar.from_file(os.path.join(test_dir, 'POSCAR.LiFePO4'), check_for_POTCAR=False) struct = p.structure expected_ans = [1, 3, 1] for i, frac in enumerate([0.25, 0.5, 0.75]): trans = SubstitutionTransformation({'Fe': {'Fe': frac}}) s = trans.apply_transformation(struct) oxitrans = OxidationStateDecorationTransformation({'Li': 1, 'Fe': 2, 'P': 5, 'O': -2}) s = oxitrans.apply_transformation(s) alls = enum_trans.apply_transformation(s, 100) self.assertEquals(len(alls), expected_ans[i]) self.assertIsInstance(trans.apply_transformation(s), Structure) for s in alls: self.assertIn("energy", s) #make sure it works for non-oxidation state decorated structure trans = SubstitutionTransformation({'Fe': {'Fe': 0.5}}) s = trans.apply_transformation(struct) alls = enum_trans.apply_transformation(s, 100) self.assertEquals(len(alls), 3) self.assertIsInstance(trans.apply_transformation(s), Structure) for s in alls: self.assertNotIn("energy", s)
def test_apply_transformations_best_first(self): p = Poscar.from_file(os.path.join(PymatgenTest.TEST_FILES_DIR, "POSCAR.LiFePO4"), check_for_POTCAR=False) t1 = OxidationStateDecorationTransformation({ "Li": 1, "Fe": 2, "P": 5, "O": -2 }) s = t1.apply_transformation(p.structure) t = PartialRemoveSpecieTransformation( "Li+", 0.5, PartialRemoveSpecieTransformation.ALGO_BEST_FIRST) self.assertEqual(len(t.apply_transformation(s)), 26)
def test_apply_transformation(self): t = OxidationStateDecorationTransformation({"Li": 1, "O": -2}) coords = [] coords.append([0, 0, 0]) coords.append([0.75, 0.75, 0.75]) coords.append([0.5, 0.5, 0.5]) coords.append([0.25, 0.25, 0.25]) lattice = Lattice([ [3.8401979337, 0.00, 0.00], [1.9200989668, 3.3257101909, 0.00], [0.00, -2.2171384943, 3.1355090603], ]) struct = Structure(lattice, ["Li", "Li", "O", "O"], coords) s = t.apply_transformation(struct) self.assertEqual(s[0].species_string, "Li+") self.assertEqual(s[2].species_string, "O2-") d = t.as_dict() self.assertEqual( type(OxidationStateDecorationTransformation.from_dict(d)), OxidationStateDecorationTransformation, )