def test_apply_transformation_fast(self): t = PartialRemoveSpecieTransformation("Li+", 0.5) 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]) coords.append([0.1, 0.1, 0.1]) coords.append([0.3, 0.75, 0.3]) lattice = Lattice([[10, 0.00, 0.00], [0, 10, 0.00], [0.00, 0, 10]]) struct = Structure(lattice, ["Li+"] * 6, coords) fast_opt_s = t.apply_transformation(struct) t = PartialRemoveSpecieTransformation( "Li+", 0.5, PartialRemoveSpecieTransformation.ALGO_COMPLETE) slow_opt_s = t.apply_transformation(struct) self.assertAlmostEqual( EwaldSummation(fast_opt_s).total_energy, EwaldSummation(slow_opt_s).total_energy, 4, ) self.assertEqual(fast_opt_s, slow_opt_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 = PartialRemoveSpecieTransformation("Li+", 1.0 / 3, 3) 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+", "Li+", "O2-"], coords) self.assertEqual(len(t.apply_transformation(struct, 100)), 2) d = t.as_dict() self.assertEqual( type(PartialRemoveSpecieTransformation.from_dict(d)), PartialRemoveSpecieTransformation, )
structure.add_oxidation_state_by_guess() len = structure.composition.as_dict()[ion] if len > 26 : print(" WARNING !! .. too many combinations, might take a long time") elif len < 3: print('Not enough combinations. Consider converting into a supercell') fact = structure.composition.get_reduced_composition_and_factor()[1] print(f'The given compound has {fact} formula units.') os.chdir(file) try: print(f"{file} with {len} {ion} has initiated.") for i in np.arange(0,len+1,1): trans = PartialRemoveSpecieTransformation(ion,i/len) substructures = trans.apply_transformation(structure,return_ranked_list=1) # change this number to get multiple configurations with higher ewald summation. substructures[0]['structure'].to(fmt='poscar', filename=str('POSCAR'+str(int(i)))) data.append([i,(1-i/len),substructures[0]['energy'],substructures[0]['energy']/fact]) # the last term is the normatised ewald summation with number of formula units df=pd.DataFrame(data,columns=['file','composition','Ewald_energy','Norm ( Ewald_energy / '+str(fact)+')' ]) df.to_csv(file+'.csv') print(f'{file} saved') except: print(' Operation failed to find possible structures.') except: print('Operation failed to recognise oxidation states of the elements. The CIF file should contain oxidation states.')