pymatgen
pymatgen copied to clipboard
Bug on DiscretizeOccupanciesTransformation
Python version
Python 3.11.5
Pymatgen version
2023.12.18
Operating system version
No response
Current behavior
Class DiscretizeOccupanciesTransformation in transformation/standard_transformation doesn't work correctly. discretize is not performed.
Expected Behavior
It return the input structure including old species species = [dict(sp) for sp in structure.species_and_occu]
for sp in species:
for k in sp:
old_occ = sp[k]
new_occ = float(Fraction(old_occ).limit_denominator(self.max_denominator))
if self.fix_denominator:
new_occ = around(old_occ * self.max_denominator) / self.max_denominator
if round(abs(old_occ - new_occ), 6) > self.tol:
raise RuntimeError("Cannot discretize structure within tolerance!")
sp[k] = new_occ
return Structure(structure.lattice, species, structure.frac_coords)
Below code might return the structure as expected species = [dict(sp) for sp in structure.species_and_occu] new_species = [] for sp in species: for k in sp: old_occ = sp[k] new_occ = float(Fraction(old_occ).limit_denominator(self.max_denominator)) if self.fix_denominator: print('aaa') new_occ = around(old_occ * self.max_denominator) / self.max_denominator if round(abs(old_occ - new_occ), 6) > self.tol: raise RuntimeError("Cannot discretize structure within tolerance!") sp[k] = new_occ new_species.append(sp)
return Structure(structure.lattice, new_species, structure.frac_coords)
Minimal example
No response
Relevant files to reproduce this bug
No response