Created
October 25, 2018 14:28
-
-
Save hokru/71c61f5afb2e5921b5b4955fed70f5db to your computer and use it in GitHub Desktop.
integrates density from a cube file (usually not a good idea!)
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 python | |
import sys | |
import numpy as np | |
cubefile = sys.argv[1] | |
f = open(cubefile, 'r') | |
line = f.next() | |
line = f.next() | |
line = f.next() | |
numatoms = int(line.strip().split()[0]) | |
# volume vectors | |
axvec = [] | |
for i in range(3): | |
line = f.next() | |
gdpts = int(line.strip().split()[0]) | |
vec = [float(xyz) for xyz in line.strip().split()[1:]] | |
axvec.append(vec[i]) | |
for i in range(numatoms): | |
f.next() | |
electrons = 0 | |
dV = axvec[0]*axvec[1]*axvec[2] | |
for line in f: | |
edens = [float(val) for val in line.strip().split()] | |
for thisdens in edens: | |
electrons += thisdens*dV | |
print electrons | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment