Skip to content

Instantly share code, notes, and snippets.

@henriquemiranda
Created August 4, 2022 13:50
Show Gist options
  • Save henriquemiranda/e4a1b616693aac339ef011af6484f890 to your computer and use it in GitHub Desktop.
Save henriquemiranda/e4a1b616693aac339ef011af6484f890 to your computer and use it in GitHub Desktop.
Read a POSCAR file and write both primitive and conventional symmetrized POSCAR
#read structure from file
from pymatgen.core import Structure
struct = Structure.from_file("POSCAR")
#get symmetrized primitive and conventional cell
from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
sga = SpacegroupAnalyzer(struct,symprec=1e-5)
struct_symm_conv = sga.get_refined_structure()
struct_symm_prim = sga.find_primitive()
#write primitive and conventional cells
from pymatgen.io.vasp import Poscar
poscar = Poscar(struct_symm_conv)
poscar.write_file(filename="POSCAR-conv",significant_figures=16)
poscar = Poscar(struct_symm_prim)
poscar.write_file(filename="POSCAR-prim",significant_figures=16)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment