Author Topic: Exporting electron density etc to XYZ file for plotting in other software  (Read 32689 times)

0 Members and 1 Guest are viewing this topic.

Offline Nordland

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 812
  • Reputation: 18
    • View Profile
Hey everyone.

Alot of people have asked for getting the data of the real space properties like the electron density, effective potential etc
printed to a file. I have always used this little script which does the job.

I have attached the script to this post and the usage is pretty easy.
Quote
from export3d import *
export3D(electron_density)
And whola! you get the following output to your screen
Quote
# -----------------------------------------------------
#   x(bohr)      y(bohr)      z(bohr)      G(1/Bohr**3)
# -----------------------------------------------------
           0            0   0.25031613     0.0086930653
           0            0   0.50063226     0.0077889859
           0            0   0.75094839     0.0068486091
           0            0   1.0012645       0.0059856004
........

Enjoy!
« Last Edit: December 28, 2008, 09:20 by Nordland »

Offline serhan

  • Heavy QuantumATK user
  • ***
  • Posts: 98
  • Reputation: 1
    • View Profile
Dear Nordland, Thank you very much for this script also ;D. Unfortunately I could not get it work:
Code
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:
Quote
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
« Last Edit: December 27, 2008, 20:47 by serhan »

Offline Nordland

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 812
  • Reputation: 18
    • View Profile
You must run ATK from the place you placed the script? Are you doing that?

Edit: It appears you are running ATK from inside VNL. Then it is a little tricky to use custom scripts.
However it is doable and this is the way you do it.

1) Create a directory for collecting all the scripts you want to use within ATK - for instance a folder for the good scripts you can find here on the forum.
    On my machine I called it "C:\atk_addons"
2) In all my scripts that I run from within VNL, I have to inset this command which will extend the path of ATK.
Quote
import sys; sys.path.append("C:\atk_addons")
After this command you should be able to write from export3d import *, if the file export3d.py is placed in the C:\atk_addons\ directory.
« Last Edit: December 28, 2008, 00:19 by Nordland »

Offline serhan

  • Heavy QuantumATK user
  • ***
  • Posts: 98
  • Reputation: 1
    • View Profile
Dear Nordland,

Thank you again. The problem is that the script "export3d" was not attached to your first post I think  ;)

This was also happenned to my another post once before, I think it is a problem with the forum's web coding  ???

If you could attach the script "export3d" again, I would be grateful  :D

Regards,

Serhan

Offline Nordland

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 812
  • Reputation: 18
    • View Profile
Doh! I will attach it to my first post :)

Infinite stupid I am...  ::)

Offline serhan

  • Heavy QuantumATK user
  • ***
  • Posts: 98
  • Reputation: 1
    • View Profile
Very thanks for the script, Nordland  ;D

Serhan

Offline carbn9

  • Regular QuantumATK user
  • **
  • Posts: 24
  • Reputation: 0
    • View Profile
Dear sirs, I tried to modify the script export3d in order to make it write the z-coordinate first like

z(Bohr)     x(Bohr)     y(Bohr)    Value
--------------------------------------
0               0              0           some value
0               0.00121     0           some value
0               0.00124     0           some value


......

I could not make it work. Could you help me how to modify the script to do this?

Maresh

Offline Nordland

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 812
  • Reputation: 18
    • View Profile
Hey !

There is a slightly modifed version with the z-axis first.

Cheers :)

Edit:
This is the correct one :)
« Last Edit: February 19, 2009, 16:24 by Nordland »

Offline carbn9

  • Regular QuantumATK user
  • **
  • Posts: 24
  • Reputation: 0
    • View Profile
Hello Nordland, vey thanks but  I tried the new script but it still gives the x coordinate first :( Can you post it again please ? :)

Offline Nordland

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 812
  • Reputation: 18
    • View Profile
Reposted above, in the correct version.

Offline carbn9

  • Regular QuantumATK user
  • **
  • Posts: 24
  • Reputation: 0
    • View Profile
Hi again. Thanks for yur post.
When I extract the real space electron density, I get 126 z-coordinate points. How can I increase this number in simulation, i.e. how can we increase the number of mesh in the z-axis?
Maresh

Offline Nordland

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 812
  • Reputation: 18
    • View Profile
If you increase the mesh cutoff, then you will have more points along all axises, so it is the correct way.

I suggest that you converge the system at the normal mesh cutoff, and then make a new calculation that you restart using this density with a higher mesh cutoff.

Offline carbn9

  • Regular QuantumATK user
  • **
  • Posts: 24
  • Reputation: 0
    • View Profile
Thanks.

Offline serhan

  • Heavy QuantumATK user
  • ***
  • Posts: 98
  • Reputation: 1
    • View Profile
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):
Code
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:
Code
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
« Last Edit: April 30, 2009, 07:16 by serhan »

Offline Anders Blom

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 5576
  • Country: dk
  • Reputation: 96
    • View Profile
    • QuantumATK at Synopsys
The sort order is actually just controlled by permuting the order of the lines
Code
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
Code
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.
« Last Edit: April 30, 2009, 09:22 by Anders Blom »