User Tools

Site Tools


exercises:common:bs

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Last revisionBoth sides next revision
exercises:common:bs [2022/09/08 15:32] jglanexercises:common:bs [2022/09/22 22:16] jglan
Line 181: Line 181:
 gnuplot>plot for [i=4:23] "WO3.bs.set-1.csv" u 0:i w l t "" gnuplot>plot for [i=4:23] "WO3.bs.set-1.csv" u 0:i w l t ""
  </code>  </code>
-<file python cp2k_bs2csv.py> +<file python plt_band.py> 
-#!/usr/bin/env python +import numpy as np 
-""" +import matplotlib.pyplot as plt
-Convert the CP2K band structure output to CSV files +
-"""+
  
-import re +file=np.genfromtxt('WO3.bs')
-import argparse+
  
-SET_MATCH re.compile(r''' +bs open ('WO3.bs','r') 
-[ ]* +line = bs.readline().split() 
-  SET: [ ]* (?P<setnr>\d+[ ]* +num_points, num_k_points, num_bands = int(line[3]),int(line[6]),int(line[8]) 
-  TOTAL [ ] POINTS: [ ](?P<totalpoints>\d+) [ ]* +sp=[""]*num_points 
-  \n +i=0 
-(?P<content> +for i in range(num_points): 
-  [\s\S]*?(?=\n.*?[ ] SET|$)  # match everything until next 'SET' or EOL +    line bs.readline().split() 
-) +    sp[i] = line[7]
-''', re.VERBOSE)+
  
-SPOINTS_MATCH = re.compile(r''' 
-[ ]* 
-  POINT [ ]+ (?P<pointnr>\d+) [ ]+ (?P<a>\S+) [ ]+ (?P<b>\S+) [ ]+ (?P<c>\S+) 
-''', re.VERBOSE) 
  
-POINTS_MATCH re.compile(r''' +new=np.resize(file,(num_k_points*2,num_bands,3)) 
-[ ]* +ener=new[:,:,1:2
-  Nr\. [ ](?P<nr>\d+[ ]+ +ener=np.resize(new[:,:,1:2],(num_k_points*2,num_bands)).transpose() 
-  Spin [ ]+ (?P<spin>\d+) [ ]+num_homo = len(new[:,:,2][1][new[:,:,2][1]==1]) 
-  K-Point [ ]+ (?P<a>\S+) [ ]+ (?P<b>\S+) [ ]+ (?P<c>\S+) [ ]+num_lumo = len(new[:,:,2][1][new[:,:,2][1]==0])
-  \n +
-[ ]* (?P<npoints>\d+) [ ]* \n +
-(?P<values> +
-  [\s\S]*?(?=\n.*?Nr|$)  # match everything until next 'Nr.' or EOL +
-+
-''', re.VERBOSE)+
  
-if __name__ == '__main__'+for i in range(num_homo)
-    parser = argparse.ArgumentParser(description=__doc__+    plt.plot(ener[i,::2],color='k') 
-    parser.add_argument('bsfilename', metavar='bandstructure-file', type=str, +for i in range(num_lumo): 
-                        help="the band structure file generated by CP2K")+    plt.plot(ener[i+num_homo,::2],color='k',linestyle='-')
  
-    args = parser.parse_args(+#plt.ylim([-4,6]
- +plt.xlim([0,num_k_points-1]
-    with open(args.bsfilename'r'as fhandle: +plt.xticks(np.linspace(0,num_k_points-1,num_points),sp
-        for kpoint_set in SET_MATCH.finditer(fhandle.read()): +plt.ylabel("Energy (eV)") 
-            filename = "{}.set-{}.csv".format(args.bsfilename, +plt.show()
-                                              kpoint_set.group('setnr')) +
-            set_content = kpoint_set.group('content'+
- +
-            with open(filename'w') as csvout: +
-                print(("writing point set {}" +
-                       " (total number of k-points: {totalpoints})+
-                       .format(filename**kpoint_set.groupdict()))) +
- +
-                print("  with the following special points:"+
-                for point in SPOINTS_MATCH.finditer(set_content): +
-                    print("  {pointnr}: {a}/{b}/{c}".format( +
-                        **point.groupdict())) +
- +
-                for point in POINTS_MATCH.finditer(set_content): +
-                    results = point.groupdict() +
-                    results['values'] = ".join(results['values'].split()+
-                    csvout.write("{a} {b} {c} {values}\n".format(**results))+
  
 </file> </file>
exercises/common/bs.txt · Last modified: 2023/01/17 20:39 by jglan