Thanks for your reply. However I need the following format (xyz format) to export:
x y z value (e.g. electron density)
0 0 1 1E-4
0 0 2 1.1E-4
. . . .
. . . .
The script given in the old post is as follows:
"""
Moedule for export grid data into xyz format.
"""
import numpy
def export3D(grid):
"""
Function for exporting grid into xyz format.
"""
# Fetch the cell.
cell = grid._cell()
# Fetch the raw numbers.
data = grid.toArray()
# Fetch the shape of the data.
shape = data.shape
# Get grid samplling vectors.
# Check the dimension of the grid.
spin_polarized = (len(shape) == 4)
# Plot the data to the screen
if (not spin_polarized):
i = numpy.array((cell.a().x(),cell.a().y(),cell.a().z()))/shape[0]
j = numpy.array((cell.b().x(),cell.b().y(),cell.b().z()))/shape[1]
k = numpy.array((cell.c().x(),cell.c().y(),cell.c().z()))/shape[2]
print '# -----------------------------------------------------'
print '# z(bohr) y(bohr) x(bohr) G(%s)'%(grid.toUnit())
print '# -----------------------------------------------------'
for ii in range(shape[0]):
for jj in range(shape[1]):
for kk in range(shape[2]):
xyz = ii*i + jj*j + kk*k
print '%12.8g %12.8g %12.8g %16.8g'%(xyz[2],xyz[1],xyz[0],data[ii,jj,kk])
else:
i = numpy.array((cell.a().x(),cell.a().y(),cell.a().z()))/shape[1]
j = numpy.array((cell.b().x(),cell.b().y(),cell.b().z()))/shape[2]
k = numpy.array((cell.c().x(),cell.c().y(),cell.c().z()))/shape[3]
print '# -----------------------------------------------------'
print '# z(bohr) y(bohr) z(bohr) G(up)(%s) G(down)(%s)'%(grid.toUnit(),grid.toUnit())
print '# -----------------------------------------------------'
for ii in range(shape[1]):
for jj in range(shape[2]):
for kk in range(shape[3]):
xyz = ii*i + jj*j + kk*k
print '%12.8g %12.8g %12.8g %16.8g %16.8g'%(xyz[2],xyz[1],xyz[0],data[0,ii,jj,kk],data[1,ii,jj,kk])
In ATK 2014
# Fetch the cell.
cell = grid._cell()
part doesn't work. How can I make a modification to get it work in new version?
Thanks.