def test_return_ranked_list(self): # list of structures pztstructs2 = loadfn( os.path.join(PymatgenTest.TEST_FILES_DIR, "mcsqs/pztstructs2.json")) trans = SQSTransformation(scaling=2, search_time=0.01, instances=8, wd=0) struc = self.get_structure("Pb2TiZrO6").copy() struc.replace_species({ "Ti": { "Ti": 0.5, "Zr": 0.5 }, "Zr": { "Ti": 0.5, "Zr": 0.5 } }) ranked_list_out = trans.apply_transformation(struc, return_ranked_list=True) matches = [ ranked_list_out[0]["structure"].matches(s) for s in pztstructs2 ] self.assertIn(True, matches)
def test_apply_transformation(self): # non-sensical example just for testing purposes self.pztstrings = np.load(os.path.join(test_dir, "mcsqs/pztstrings.npy"), allow_pickle=True) self.struct = self.get_structure('Pb2TiZrO6') trans = SQSTransformation({ 2: 6, 3: 4 }, supercell=[2, 1, 1], total_atoms=None, search_time=0.01) struct = self.struct.copy() struct.replace_species({ 'Ti': { 'Ti': 0.5, 'Zr': 0.5 }, 'Zr': { 'Ti': 0.5, 'Zr': 0.5 } }) sqs = trans.apply_transformation(struct) self.assertEqual(atat.Mcsqs(sqs).to_string() in self.pztstrings, True) os.remove('sqscell.out') os.remove('rndstrgrp.out') os.remove('bestcorr.out') os.remove('rndstr.in') os.remove('sym.out') os.remove('mcsqs.log') os.remove('bestsqs.out') os.remove('clusters.out')
def test_apply_transformation(self): pztstructs = loadfn(os.path.join(PymatgenTest.TEST_FILES_DIR, "mcsqs/pztstructs.json")) trans = SQSTransformation(scaling=[2, 1, 1], search_time=0.01, instances=1, wd=0) # nonsensical example just for testing purposes struc = self.get_structure("Pb2TiZrO6").copy() struc.replace_species({"Ti": {"Ti": 0.5, "Zr": 0.5}, "Zr": {"Ti": 0.5, "Zr": 0.5}}) struc_out = trans.apply_transformation(struc) matches = [struc_out.matches(s) for s in pztstructs] self.assertIn(True, matches)
def test_spin(self): trans = SQSTransformation(scaling=[2, 1, 1], search_time=0.01, instances=1, wd=0) # nonsensical example just for testing purposes struc = self.get_structure("Pb2TiZrO6").copy() struc.replace_species({"Ti": {"Ti,spin=5": 0.5, "Ti,spin=-5": 0.5}}) struc_out = trans.apply_transformation(struc) struc_out_specie_strings = [site.species_string for site in struc_out] self.assertIn("Ti,spin=-5", struc_out_specie_strings) self.assertIn("Ti,spin=5", struc_out_specie_strings)
def solid_solution_sqs(structure, elem_frac_site, elem_frac_comp, sqs_scaling): ''' Use pymatgen SQSTransformation (which call ATAT mcsqs program) to generate disordered structure. Args: structure: pymatgen structure elem_frac_site: the factional occupy site in the original structure, e.g. 'Ti' elem_frac_comp: solid solution composition, e.g. 'Ti0.25Zr0.25Hf0.25Nb0.25' sqs_scaling (int or list): (same as pymatgen scaling in SQSTransformation) Scaling factor to determine supercell. Two options are possible: a. (preferred) Scales number of atoms, e.g., for a structure with 8 atoms, scaling=4 would lead to a 32 atom supercell b. A sequence of three scaling factors, e.g., [2, 1, 1], which specifies that the supercell should have dimensions 2a x b x c Return: pymatgen structure, SQS ''' # build another pymatgen structure structure[elem_frac_site] = elem_frac_comp ts = TransformedStructure(structure, []) # the directory must be set in SQSTransformation, otherwise the work dir # will be changed by this function workdir = os.getcwd() ts.append_transformation( SQSTransformation(scaling=sqs_scaling, search_time=1, directory=workdir, reduction_algo=False)) return ts.structures[-1]