Skip to content

Instantly share code, notes, and snippets.

@galjos
Last active June 6, 2024 18:28
Show Gist options
  • Save galjos/5d1d38c345e991ec82563631dd31066a to your computer and use it in GitHub Desktop.
Save galjos/5d1d38c345e991ec82563631dd31066a to your computer and use it in GitHub Desktop.
Creates a bandstructure path from a cif file to convert it to a d3 crystal input file. (c) @freedatensuppe
#!/usr/bin/env python3
import sys
from pymatgen.core import Structure
from pymatgen.symmetry.bandstructure import HighSymmKpath
# ingore warnings
import warnings
warnings.filterwarnings("ignore")
# Check if input file is given
if len(sys.argv) < 2:
print("Usage: get_bs_path.py <cif-inputfile>")
print(
"Usage: get_bs_path.py <cif-inputfile> convention (0,1,2) for high symmpath"
)
print(
"convention types = setyawan_curtarolo (default), hinuma, latimer_munro"
)
sys.exit(1)
# Read input file
inputfile = sys.argv[1]
path_types = ["setyawan_curtarolo", "hinuma", "latimer_munro"]
if len(sys.argv) == 2:
path_type = path_types[0]
if len(sys.argv) > 2:
conv = int(sys.argv[2])
path_type = path_types[conv]
# Read structure from input file
struc = Structure.from_file(inputfile, 0)
kplm = HighSymmKpath(struc, path_type=path_type)
path_kpath = kplm.kpath
struc2 = struc.get_primitive_structure()
kplm2 = HighSymmKpath(struc2, path_type=path_type)
path_kpath2 = kplm2.kpath
new_labels = kplm2.kpath["path"]
kpoints = kplm2.kpath["kpoints"]
segments = [[kpoints[i] for i in s] for s in new_labels]
k_vector = 12
length = sum([len(s) - 1 for s in new_labels])
labelraw = " | ".join(['–'.join(l) for l in new_labels])
labelstring = labelraw.replace("\\Gamma", "G")
printlabels = [[i if i != "\\Gamma" else "G" for i in l] for l in new_labels]
print("BAND") # header
print("# ", labelstring) # labels
print(length, k_vector, 300, 1, 100, 1, 0)
for a, s in enumerate(segments):
for i in range(len(s) - 1):
for j in s[i]:
print("% 5.5f" % (j * k_vector), end=" ")
print(" ", end="")
for k in s[i + 1]:
print("% 5.5f" % (k * k_vector), end=" ")
print(" # % 3s " % printlabels[a][i], end=" ")
print("% 3s " % printlabels[a][i + 1], end="\n")
print("END") # end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment