Created
February 7, 2020 15:17
-
-
Save Asif-Iqbal-Bhatti/a2c7358f46df85d676ad6a9dccd96b6b to your computer and use it in GitHub Desktop.
Read hessian matrix from VASP output file and calculate Eigenvalues and Eigenvectors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import numpy as np | |
import os, sys, subprocess | |
from scipy import linalg as LA | |
import matplotlib.pyplot as plt | |
''' The complication that arises by parsing the data from the file is | |
the trailing empty lines and tabs that need to be deleted before it | |
can be read. In the case of a simple file format, there is no need for | |
it. But if the file contains irregular data entry such as empty lines | |
with commas and spaces then it needs to be formatted. | |
In my case, I have only leading empty lines and spaces and in between | |
columns there are white spaces of different sizes. | |
''' | |
filename = sys.argv[1] | |
######################################################################### | |
#os.system(' grep "\S" input.txt') | |
#os.system(" sed -e '/^\s*$/d' input.txt ") | |
#os.system(" sed -i '/^[[:space:]]*$/d' $filename ") | |
subprocess.call(['sed','-i','/^[[:space:]]*$/d',sys.argv[1]], shell = False) | |
######################################################################### | |
#---------------------------------'''METHOD 1''' | |
#a = np.loadtxt("new.dat") | |
#print(a) | |
#---------------------------------'''METHOD 2''' | |
a = [] ; l=0 | |
f = open(filename, 'r') | |
for line in f.readlines(): | |
a.append([]) | |
print (line[0]) | |
if (line[0] == '#'): | |
continue | |
for i in line.strip().split(): | |
a[-1].append(float(i)) | |
l+=1 | |
#print (a) | |
f.close() | |
#------------------------------------------------------------------------ | |
#a = np.random.random((900, 900)) | |
s = np.shape(a); print('size of a Matrix', s) | |
a = np.matrix(a) | |
#print(a) | |
print ('--------------------------------EIG VAL AND EIG VECTORS ARE:') | |
w, v = LA.eigh(a) | |
print (w); | |
print (v) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment