[Pw_forum] Plot phonon dispersion

Marcel Mohr marcel at physik.tu-berlin.de
Wed Dec 5 18:51:35 CET 2007


Dear list members,

i have written a small python /script-program to convert the matdyn output 
matdyn.freq into a two-column format that I want to share with you.
This can easily be plotted by xmgrace, gnuplot etc.

For simplicity I took the absolute value of the k-vector, so one has to 
modify the 1st column for non-cubic systems.

Best
Marcel


I just see, my email program is wrapping lines, so below has to be 
modified, the attachment works.



------> program starts here

# small program to convert freq-Output into two-column dat
# written by Marcel Mohr
# usage: python mat2agr.py freqfile > phonons.dat
# Caution:# in the output, the absolute value of k-vector is taken -> 1,1,1 
#->sqrt(3)
#
import sys,string
import os
import math
import re

#
def flatten(lst):
         for elem in lst:
                 if type(elem) in (tuple, list):
                         for i in flatten(elem):
                                 yield i
                 else:
                         yield elem

atom=[]
steps= 0
kk=0
input = open(sys.argv[1],'r')
line=input.readline()
#print line
bla=line.split()
if bla==[]:
         pass
elif bla[1]=="nbnd=":
# komma muss weg
         bla[2]=re.compile( "," ).sub( '', bla[2] )
         nbnd=string.atoi(bla[2])
#       print nbnd
         nkpt=string.atoi(bla[4])
#       print nkpt

# Anzahl der Lines sind jetzt nktp + nkpt *(nbnd/6)
lines=input.readlines()
for n, bla in enumerate(lines):
         dummy=0
# bloedes \n am Ende weg
for i in range(n+1):
         lines[i]=re.compile( "\n" ).sub( '' , lines[i] )
# Wir haben jetzt die Anzahl der Linien, Jetzt die Anzahl pro k-punkt 
#(nprok)
# 6 pro Spalte (also nbnd/6), falls nicht durch 6 teilbar, muss man plus 1 
#zahlen
if (nbnd%6)==0:
         nprok=nbnd/6
else:
         nprok=nbnd/6 + 1

kabslist=[]
freqlist=[]
for j in range(nkpt):
         klist=[]
         #linnum: only lines in which k-point info is stored
         linnum=j*(nprok+1)
         kptstr=lines[linnum].split()
         klist=[]
         for i in range(3):
                 k=string.atof(kptstr[i])
                 klist.append(k)
         kabslist.append( math.sqrt( klist[0]**2 + klist[1]**2 + 
klist[2]**2 ))
         freqK=[]
         for i in range(nprok):
                 freqK.append( lines[linnum+1+i].split())
         dummy=list(flatten(freqK))
         freqlist.append(dummy)

#output
for i in range(nbnd):
         for j in range(nkpt):
                 print ("%9.9f    %9.9f") %(kabslist[j],string.atof( 
freqlist[j][i]) )
         print " "
         print " "
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mat2agr.py
Type: text/x-python
Size: 1804 bytes
Desc: 
URL: <http://lists.quantum-espresso.org/pipermail/users/attachments/20071205/0d15e3c5/attachment.py>


More information about the users mailing list