def test_apply_transformation(self): tl = [SubstitutionTransformation({"Li+": "Na+"}), SubstitutionTransformation({"Li+": "K+"})] t = SuperTransformation(tl) coords = list() coords.append([0, 0, 0]) coords.append([0.375, 0.375, 0.375]) coords.append([.5, .5, .5]) coords.append([0.875, 0.875, 0.875]) coords.append([0.125, 0.125, 0.125]) coords.append([0.25, 0.25, 0.25]) coords.append([0.625, 0.625, 0.625]) coords.append([0.75, 0.75, 0.75]) 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+", "Li+", "Li+", "Li+", "Li+", "O2-", "O2-"], coords) s = t.apply_transformation(struct, return_ranked_list=True) for s_and_t in s: self.assertEqual(s_and_t['transformation'] .apply_transformation(struct), s_and_t['structure'])
def test_apply_transformation_mult(self): # Test returning multiple structures from each transformation. disord = Structure(np.eye(3) * 4.209, [{"Cs+": 0.5, "K+": 0.5}, "Cl-"], [[0, 0, 0], [0.5, 0.5, 0.5]]) disord.make_supercell([2, 2, 1]) tl = [EnumerateStructureTransformation(), OrderDisorderedStructureTransformation()] t = SuperTransformation(tl, nstructures_per_trans=10) self.assertEqual(len(t.apply_transformation(disord, return_ranked_list=20)), 8) t = SuperTransformation(tl) self.assertEqual(len(t.apply_transformation(disord, return_ranked_list=20)), 2)
def test_transmuter(self): tsc = PoscarTransmuter.from_filenames( [os.path.join(self.TEST_FILES_DIR, "POSCAR")]) tsc.append_transformation(RemoveSpeciesTransformation("O")) self.assertEqual(len(tsc[0].final_structure), 8) tsc.append_transformation( SubstitutionTransformation({ "Fe": { "Fe2+": 0.25, "Mn3+": 0.75 }, "P": "P5+" })) tsc.append_transformation(OrderDisorderedStructureTransformation(), extend_collection=50) self.assertEqual(len(tsc), 4) t = SuperTransformation([ SubstitutionTransformation({"Fe2+": "Mg2+"}), SubstitutionTransformation({"Fe2+": "Zn2+"}), SubstitutionTransformation({"Fe2+": "Be2+"}), ]) tsc.append_transformation(t, extend_collection=True) self.assertEqual(len(tsc), 12) for x in tsc: # should be 4 trans + starting structure self.assertEqual( len(x), 5, "something might be wrong with the number of transformations in the history", ) # test the filter tsc.apply_filter( ContainsSpecieFilter(["Zn2+", "Be2+", "Mn4+"], strict_compare=True, AND=False)) self.assertEqual(len(tsc), 8) self.assertEqual( tsc.transformed_structures[0].as_dict()["history"][-1]["@class"], "ContainsSpecieFilter", ) tsc.apply_filter(ContainsSpecieFilter(["Be2+"])) self.assertEqual(len(tsc), 4) # Test set_parameter and add_tag. tsc.set_parameter("para1", "hello") self.assertEqual( tsc.transformed_structures[0].as_dict()["other_parameters"] ["para1"], "hello", ) tsc.add_tags(["world", "universe"]) self.assertEqual( tsc.transformed_structures[0].as_dict()["other_parameters"] ["tags"], ["world", "universe"], )
def test_transmuter(self): tsc = PoscarTransmuter.from_filenames( [os.path.join(test_dir, "POSCAR")]) tsc.append_transformation(RemoveSpeciesTransformation('O')) self.assertEqual(len(tsc[0].final_structure), 8) tsc.append_transformation( SubstitutionTransformation({ "Fe": { "Fe2+": 0.25, "Mn3+": .75 }, "P": "P5+" })) tsc.append_transformation(OrderDisorderedStructureTransformation(), extend_collection=50) self.assertEqual(len(tsc), 4) t = SuperTransformation([ SubstitutionTransformation({"Fe2+": "Mg2+"}), SubstitutionTransformation({"Fe2+": "Zn2+"}), SubstitutionTransformation({"Fe2+": "Be2+"}) ]) tsc.append_transformation(t, extend_collection=True) self.assertEqual(len(tsc), 12) for x in tsc: self.assertEqual( len(x), 5, 'something might be wrong with the number of transformations in the history' ) #should be 4 trans + starting structure #test the filter tsc.apply_filter( ContainsSpecieFilter(['Zn2+', 'Be2+', 'Mn4+'], strict_compare=True, AND=False)) self.assertEqual(len(tsc), 8) self.assertEqual( tsc.get_transformed_structures()[0].as_dict()['history'][-1] ['@class'], 'ContainsSpecieFilter') tsc.apply_filter(ContainsSpecieFilter(['Be2+'])) self.assertEqual(len(tsc), 4) #Test set_parameter and add_tag. tsc.set_parameter("para1", "hello") self.assertEqual( tsc.transformed_structures[0].as_dict()['other_parameters'] ['para1'], 'hello') tsc.add_tags(["world", "universe"]) self.assertEqual( tsc.transformed_structures[0].as_dict()['other_parameters'] ['tags'], ["world", "universe"])