QuantumATK > Scripts, Tutorials and Applications

Script for making data files to plot k-resolved transmission with gnuplot

(1/3) > >>

nori:
Dear all,

I'd like to share the script for calculating k-resolved transmission coefficients and making data files to plot them with gnuplot.

Converged 2probe NetCDF file is needed in order to use it.
In addition, you have to set three parameters in the script:
-line 16, NetCDF file name
-line 20, the number of k points
-line 23, the energy for which the transmission coefficients are to be calculated

Usage:
1. execute SCF calculation for your interesting system and save the result in NetCDF file
2. store "k_resolved_transmission.py" and the ncfile in the same directory
3. set-up three parameters mentioned above
4. execute "k_resolved_transmission.py"

After the task 4, you can get "xxxx.dat" for plotting.
(If the system is spin-polarized, "xxxx_up.dat" and "xxxx_dn.dat" are output.)

If you apply "k_resolved_transmission.py" to the system fe/mgo/fe (fe_mgo_fe.png),
you can obtain the picture like "fe_mgo_fe_parallel_0eV.GIF".

Nordland:
Very nice! I will try it out....

ugglebot:
Nori, could you please share also the GNUPlot plot commands you used to make the beautiful plot, from the data file?

nori:
Hi ugglebot,

"pm3d" is used to plot "fe_mgo_fe_parallel_0eV.GIF".
So, If you get the error after executing command "set pm3d", please install the latest version of Gnuplot.

In the following, I show the commands:
gnuplot> set pm3d
gnuplot> set ticslevel 0
gnuplot> splot ‘xxxx.dat’ w pm3d

If you want 2D plot like "2d_plot.GIF", please input the commands as follows:
gnuplot> set pm3d map
gnuplot> set size square
gnuplot> splot ‘xxxx.dat’

Anders Blom:
The ability to plot the transmission coefficients in various ways is an important addition to the basic functionality in VNL, so Nori has started a very relevant topic here!

I would like to offer a second version, with focus on a few key points:

The k-point grid. I hereby provide a Monkhorst-Pack class that can be used very generally. The main benefit is that the k-point generation is indepedent of the geometrical structure, so there is no need for complicated reading of the NetCDF file, and moreover there is a well-defined method to integrate over the k-points to obtain the total transmission.

I will not document the Monkhorst-Pack class in this post; see the file, it should be quite self-explanatory.

The plotting. I very much like Nori's plots, 3D plots are always nice. In case you are ok with the contour plot version only, it is however possible to do the plot with ATK itself, thus reducing the need for exporting the data to an external file, and use an external plotting program.

Now, because the Monkhorst-Pack class is so general, the final user script becomes very small. Here is the part which does the calculations:


--- Code: ---from ATK.TwoProbe import *
from MonkhorstPack import MonkhorstPackGrid

nc_filename = 'femgofe_antipara.nc'
Npoints = 35
energy = 0.*eV

scf = restoreSelfConsistentCalculation(nc_filename)

kgrid = MonkhorstPackGrid((Npoints,Npoints),False)
K = kgrid.getFractionalKPoints()

trans_coeff = calculateTransmissionCoefficients(scf,energy,(K,Spin.Up))

--- End code ---

Modify the code as needed for number of points, the energy, the NetCDF file name, and the spin component (the other one is Spin.Down). If you have an un-polarized calculation, replace the tuple (K,Spin.Up) with just plain K.

Next, we prepare the data for plotting:


--- Code: ---Kxy = K[0:Npoints,1]
T = abs(trans_coeff.reshape(Npoints,Npoints))

--- End code ---

Finally, the plotting part:


--- Code: ---import pylab as P
fig = P.figure()
P.xlabel('kx')
P.ylabel('ky')
P.contourf(Kxy,Kxy,T,40,cmap=P.cm.Spectral)
P.colorbar()
P.axis([-.5,.5,-.5,.5])
P.yticks(numpy.arange(-0.5,0.51,0.1))
P.xticks(numpy.arange(-0.5,0.51,0.1))
P.title('FeMgO, anti-parallel config, majority spin')
P.savefig('femgo_antipara_trans_up.png',dpi=100)

--- End code ---

Play around with the plot parameters as you want (title, file name, etc)! The resulting plot of the example above is attached.

(A side-comment: A subtle but hard-to-catch error will occur if you name the Monkhorst-Pack grid variable "grid", which seems like a natural thing to do, and then, instead of import pylab you think, "hey, why not do from pylab import * to make it simpler". The script will then fail, because the pylab import statement overwrites the name "grid" (it's a pylab function). This demonstrates the danger of from X import * statements; we generally recommend the use of import X instead (except I guess for from ATK.KohnSham import * :) !)

The above script is simpler than Nori's (because I have hidden all the dirty stuff in the Monkhorst-Pack class), and therefore a bit easier to use. I think it is also a benefit to use a well-defined Monkhorst-Pack grid, for the reasons mentioned above. Note also that you don't really need the unit cell data to construct the k-point grid for the transmission, since we always use fractional coordinates for that.

The disadvantage is that I did not consider time-reversal symmetry, as Nori did. So, mine is slower by a factor of 2, which probably is not be very critical in many cases, but it might be in some. I will, therefore, show in a separate post how we can take advantage of symmetries in the transmission spectrum, including also mirror planes etc, in a very powerful and time-consuming way.

So, stay tuned - there is more to come!

Navigation

[0] Message Index

[#] Next page

Go to full version