10
0
mirror of https://gitlab.com/scemama/eplf synced 2024-10-31 19:23:55 +01:00
eplf/bin/to_cube.py
2009-12-04 16:14:23 +01:00

47 lines
1.4 KiB
Python
Executable File

#!/usr/bin/env python
import sys
import common
# Check command line
try:
x, filename, grid_type = sys.argv
except ValueError:
print "usage: "+sys.argv[0]+" filename grid_type"
sys.exit(2)
from ezfio import ezfio
def main():
ezfio.set_file(filename)
file = open("%s_%s.cube"%(filename,grid_type),"w")
print >>file, " Cube File"
print >>file, filename, grid_type
data = [ ezfio.nuclei_nucl_num ]+ezfio.grid_origin
print >>file, "%5d%12.6f%12.6f%12.6f" % tuple(data)
data = [ ezfio.grid_num_x, ezfio.grid_step_size[0],0.,0. ]
print >>file, "%5d%12.6f%12.6f%12.6f" % tuple(data)
data = [ ezfio.grid_num_y, 0., ezfio.grid_step_size[1],0. ]
print >>file, "%5d%12.6f%12.6f%12.6f" % tuple(data)
data = [ ezfio.grid_num_z, 0.,0., ezfio.grid_step_size[2] ]
print >>file, "%5d%12.6f%12.6f%12.6f" % tuple(data)
charge = ezfio.nuclei_nucl_charge
coord = ezfio.nuclei_nucl_coord
for i in range(ezfio.nuclei_nucl_num):
data = [ charge[i], charge[i], coord[0][i], coord[1][i], coord[2][i] ]
print >>file, "%5d%12.6f%12.6f%12.6f%12.6f" % tuple(data)
data = getattr(ezfio,"grid_data_%s"%grid_type)
for i in xrange(0,ezfio.grid_num_x):
for j in xrange(0,ezfio.grid_num_y):
for k in xrange(0,ezfio.grid_num_z,6):
for l in xrange(k,min(ezfio.grid_num_z,k+6)):
file.write (" %12.5E"%data[l][j][i])
file.write ("\n")
file.close()
main()