Dear Nordland,
Thank you very much for this script also ;D. Unfortunately I could not get it work:
from ATK.TwoProbe import *
# Enter the filename of the calculation.
filename = 'D:\Atomistix_works\Tut6\lih2li-scf.nc'
scf = restoreSelfConsistentCalculation(filename)
# Calculate the electron density.
electron_density = calculateElectronDensity(scf)
potential = calculateEffectivePotential(scf)
from export3d import *
export3D(electron_density)
gives:
Running: C:\Program Files\QuantumWise\Virtual NanoLab 2008.10.0\atk\bin\atk.exe c:/docume~1/atomis~1/locals~1/temp/tmpsqhecq.nl
Traceback (most recent call last):
File "c:/docume~1/atomis~1/locals~1/temp/tmpsqhecq.nl", line 9, in ?
from export3d import *
ImportError: No module named export3d
Terminated Abnormally
I'm using ATK 2008.10.0 in Windows.
Serhan
Hi Nordland,
The new_export3D exports the coordinates as this sort (if z=[z0,z4], x=[x0, x4], y=[y0, y4] and p is the physical quantity to be extracted):
z0 x0 y0 p000
z1 x0 y0 p100
z2 x0 y0 p200
z3 x0 y0 p300
z4 x0 y0 p400
z0 x1 y0 p010
z1 x1 y0 p110
z2 x1 y0 p210
z3 x1 y0 p310
z4 x1 y0 p410
....................
....................
z3 x4 y4 p344
z4 x4 y4 p444
However, I need to export it as sorted in the z-axis coordinate such as:
z0 x0 y0 p000
z0 x1 y0 p010
z0 x2 y0 p020
z0 x3 y0 p030
z0 x4 y0 p040
z0 x0 y1 p001
z0 x1 y1 p011
z0 x2 y1 p021
z0 x3 y1 p031
z0 x4 y1 p041
....................
....................
z0 x3 y4 p034
z0 x4 y4 p044
z1 x0 y0 p100
z1 x1 y0 p110
....................
....................
z4 x4 y3 p443
z4 x4 y4 p444
I could not success modifying the new_export3D.py to write in this sort. Could you please help?
Cheers,
Serhan
The sort order is actually just controlled by permuting the order of the lines
for ii in range(shape[0]):
for jj in range(shape[1]):
for kk in range(shape[2]):
To sort as you wish, the only change needed is to instead write
for kk in range(shape[2]):
for jj in range(shape[1]):
for ii in range(shape[0]):
Don't forget to change in two places, for spin-polarized and not!
The rule is simple: the coordinate to sort primarily by, comes first (Z is kk in shape[2]), then the next-level sorting (Y, in your case, jj in shape[1]), and finally the third-level (the coordinate which changes immediately, in your case X, ii in shape[0]).
However, I also note that the print order is a bit different in your example; the script prints Z, Y, X, so if you really want the order Z, X, Y, you also must modify the print statement.
Hi all,
I'm trying to export electron density to file using the script given in this thread. I need to extract electron densities of lots of .nc files.
If the exportED.py is like this
scf=restoreSelfConsistenCalculation('/home/master/atk/1.nc')
electron_density=calculateElectronDensity(scf)
from export3d import *
export3D(electron_density)
And I execute this file as
/home/master/atk/atk /home/master/atk/exportED.py > /home/master/atk/electronDensity1.dat &
then, a file named electrondensity1.dat is successfully created in the directory. The code is excellent. However, I have dozens of .nc files of which the electron densities are to be extracted as:
1.nc -> electronDensity1.dat
2.nc -> electronDensity2.dat
.
.
.
etc. How can I achieve this as a batch mode instead of executing
/home/master/atk/atk /home/master/atk/exportED.py > /home/master/atk/electronDensity1.dat & (when 1.nc is pointed in exportED.py)
/home/master/atk/atk /home/master/atk/exportED.py > /home/master/atk/electronDensity2.dat & (when 2.nc is pointed in exportED.py)
.
.
etc. Any help is greatly appreciated ;)
Cheers,
Serhan
There are a couple of ways to approach this.
You can handle the many files within the script itself, using the "glob" module. This is a bit more complex, however, so I'd recommend using simple bash looping.
To do this, first we need to modify the code slightly, so that we can pass the name of the NC file on the command line:
import sys
scf=restoreSelfConsistenCalculation(sys.argv[2])
Then, we execute the script as
for i in *.nc ; do atk exportED.py $i > electronDensity$i.dat ; done
You need to add paths etc. This has the slight disadvantage that the files will be called "electronDensity1.nc.dat". If you can live with that, all ok. If you prefer the filename "electronDensity1.dat", we just need to change it a bit:
for i in *.nc ; do j=`echo $i | sed 's/.nc//g'` ; atk exportED.py $i > $j.dat ; done