QuantumATK Forum

QuantumATK => Scripts, Tutorials and Applications => Topic started by: Nordland on December 18, 2008, 14:24

Title: Script for calculate the bandgap.
Post by: Nordland on December 18, 2008, 14:24
If you want to calculate the bandgap of a semi-conductor or an insulator I have created a small script
that does it for you and I have attached it to this post.

Simple perform a calculation, and store the results in a NetCDF file,
and edit the script bandgap.py to point at this netcdf file, and the run it as normal:
atk bandgap.py

It will produced the following output ( based on ZnSe calculation ):
Quote
Band Gap =  1.18165139396 eV

For test purposes I have also attached the script for performing calculation on znse

Edit:
Updated the scripted in a slight faster version, but it also calculates the indirect band gap now.
Title: Re: Script for calculate the bandgap.
Post by: xian on February 15, 2009, 03:59
Hi,
thanks for the providing the code. i just like to ask you some questions if you don't mind.
1) What 'precision' means in this context?  2 choices are : precision in k-point or precision in energy.  I need to know the difference because i'm using your bandgap code

2) There are two type of bandgap for semiconductor: Direct and Indirect.  Can this code differentiate the two cases?  If not, which case does this code calculate? 

thanks and best regards
Andrew
Title: Re: Script for calculate the bandgap.
Post by: Nordland on February 15, 2009, 10:33
Hey Andrew.

The original script was the direct band gap, however I have updated the script and now it calculates both at the same time
and no extra cost in time. I also tweaked it a bit, so it is faster.

Quote
Direct Band Gap =  2.50778840825 eV
Indirect Band Gap = 0.472641034718 eV

In order to determine the band gap, the scripts samples the brillouin zone to determine the exact location of the band gap, and the precision
parameter in this script determines the density of this sampling.

I am glad that you are using the script :) Please let me know if you have any suggestions for improvement....
Title: Re: Script for calculate the bandgap.
Post by: voves on February 16, 2009, 12:00
Hi, thanks for the script. But 1.18 eV is far from 2.82 eV reported in literature. Could you, please, explain the difference, or recommend the settings?

Jan


Title: Re: Script for calculate the bandgap.
Post by: Nordland on February 16, 2009, 13:04
Hey Jan.

I don't how familiar you are with density functional theory, or if the 2.82 eV reported is a experimental result or calculation,
so I will try to explain the best way I can. Under the assumption that it is a experimental value, then the reason is clear:

The density functional theory (DFT) underestimates the band gap of semiconductors and insulators by 30–50% (A reference paper) (http://prola.aps.org/abstract/RMP/v64/i4/p1045_1),
and if you ask me, this is the main flaw of DFT. There are some ways to try to compensate for this problem, but there is no goal solution. This discrepancy can be overcome by introducing many-body GW and/or DFT+U schemes (Quasi-particle approach) (http://scitation.aip.org/getabs/servlet/GetabsServlet?prog=normal&id=PRBMDO000074000024245213000001&idtype=cvips&gifs=yes). However, this type of calculations is extremely computing-time consumer, and very hard to combine with supercell models. Therefore it is not supported in ATK, and in general I have not seen any application of GW on any relevant system that was not a small molecule or single crystal.

Hence there is not any reason to despair, since the underestimated band gap does not effect the geometry optimization and almost all the other physical observable, it is normally not a problem,
however if you have a physical property that depends directly on the band gap ( like the refractive index or so ) one of the best, but also a brute force methods, is a scissor operation.
This is pretty standard trick to do in DFT, and I have found an example of it in this paper (Another reference) (http://linkinghub.elsevier.com/retrieve/pii/S0026269207001826).
And you gets a good results as in GW, without extra calculation time, but it is of course not 100% pure ab-initio.

If you need help applying a scissor operator, please feel free to ask - then I can try my best :)

Title: Re: Script for calculate the bandgap.
Post by: voves on February 16, 2009, 13:43
Thanks for the valuable reference. My idea was to calculate the eff. masses for the strained layer from the bandstructure. The DFT will not be the best solution, I am afraid.

Jan
Title: Re: Script for calculate the bandgap.
Post by: Nordland on February 16, 2009, 13:54
Hey Jan.

If you are trying to study the effective mass DFT is quite a good choice. Since the effective mass depends on the curvature of the bands, and not the band gap itself.
My thesis on optical surfaces states in ZnO nanowires were tight-binding models based on a effective mass, which was obtained from DFT calculations.
So in short, the curvature of the bands is very accurate (valcens bands are close to exact, conducting bands can sometimes be a little to steep), hence the the effective mass are very exact.
Title: Re: Script for calculate the bandgap.
Post by: voves on February 16, 2009, 13:58
Hey, thats sounds good. Holes are important for me!

Jan
Title: Re: Script for calculate the bandgap.
Post by: Nordland on February 16, 2009, 14:20
 :P
Title: Re: Script for calculate the bandgap.
Post by: Nordland on February 17, 2009, 00:16
Hej Jan.

Digging through my old files I found this script, that I wrote some time ago, for calculating the effective mass of electrons and holes using ATK.

I have created a new post about it, and it can be found  here! (http://quantumwise.com/forum/index.php?topic=97.msg443#msg443)
Title: Re: Script for calculate the bandgap.
Post by: privador on April 17, 2009, 22:56
Hi,i tried to use standard 4,4 nanotube with this script and it resulted 0.06eV Direct and Indirect bandgap.
In theory it shoud be zero.Whats wrong?

What is "Direct" and "Indirect" band gaps?
Title: Re: Script for calculate the bandgap.
Post by: Nordland on April 18, 2009, 05:03
There are two sides of it:
1) The precision of the estimation of the band gap is determined by the parameter N in the script, and If you made the correction I suggested in the other post to the script, then try to use N = 1000, and see what you get. If it remains the same, then 0.06 eV is most likely the correct result.
2) I assume that when you say theory, it is the analytical expression for the band structure for Carbon nanotubes, you are taking about.
The analytic expression for the band structure (band gap) is based on a folding of the brillouin zone for the 2D energy band structure for graphene sheets, however for the analytical expression to be correct, it is assumed that atoms sitting the the carbon nanotube, is not affected by atoms across the tube, and the atoms is not affected by the curvature of the graphene sheet, that arises for when folding it into a carbon nanotube. It means that the analytical expressions is incorrect for small carbon nanotubes, and (4,4) is a very small carbon nanotubes. ( The nature of a (4,4) CNT is more like that of atomic carbon chain than analytical carbon nanotube of size (20,20) ).

This is the reason why it is needed to perform DFT calculation on a system like this one.

In short the difference between a direct band gap and indirect band gap, is that a band gap is smallest energy of that is required to excite a electron from the valence band to the conducting band. If this band gap requires an phonon interaction in order to be possible, it is called indirect, if it does not require a phonon interaction it is called direct. Therefore you often give both values, since the mechanics behind exciting atoms in the material is quite different if there is a need for phonon in order to allow the excitation.
The indirect band gap is always smaller or equal to the direct band gap, and if they are equal, it is due to the fact that a phonon is allowed to have the zero momentum.
For details on the direct and indirect band gap, I have found this wikipedia page (http://en.wikipedia.org/wiki/Direct_bandgap).
Title: Re: Script for calculate the bandgap.
Post by: privador on May 12, 2009, 19:23
Actually i tried to calculate C nanotubes band gaps
For A-type(n,n) nanotubes there wasnt much problems.Bandgaps were close to the zero
But when i calculated Z-type(n,0) nanotubes i met serious problems
For example (6,0) nanotube DG and IG were accordingly 7.02eV,-0.46eV
And (7,0) nanotubes DG and IG were both around 0,45eV

In theory (6,0) should be semimetallic close to zero and (7,0) must be semiconductor
I tried also nanoribbons and there was same problems

I used N=10..100 but actually it doesnt change result must,mayby 20%
So i think problem is not there

Mayby i have messed  up creating nc file?(k=1,1,50) ,other default parametres
By the way when Indirect Gap is negative,what it means?
Title: Re: Script for calculate the bandgap.
Post by: Anders Blom on May 15, 2009, 13:16
The value for (7,0) seems fine, while the negative value for (6,0) probably is due to the fact that it's semi-metallic.

I suggest you look at a plot of band structure and try to relate it to the numbers you get. If you attach those plots (properly zoomed in around the Fermi energy), we can understand the situation better.
Title: Re: Script for calculate the bandgap.
Post by: privador on May 25, 2009, 03:23
I have got some picture,where is single E(k) line around the Fermi level
And seemed that bandgap script consider that line as valence band
  band gap is calculated around 1Ev not 4Ev
Is that line could be error and real bandgap is 4EV?
http://www.hot.ee/suurfail//BN5-5-1.JPG (http://www.hot.ee/suurfail//BN5-5-1.JPG)
Title: Re: Script for calculate the bandgap.
Post by: Anders Blom on May 25, 2009, 09:13
The way the picture looks, this system is metallic and hence there is no band gap. The script assumes a band gap exists; if it doesn't you may indeed get weird results. This is a good example of the importance of not just applying a script like this and trust the results blindly, but one must always investigate the results in detail.
Title: Re: Script for calculate the bandgap.
Post by: privador on May 26, 2009, 00:43
Quote
The way the picture looks, this system is metallic and hence there is no band gap. The script assumes a band gap exists; if it doesn't you may indeed get weird results. This is a good example of the importance of not just applying a script like this and trust the results blindly, but one must always investigate the results in detail.
Do u consider any  single line around Fermi level as 0 bandgap?Should it be between "somehing"
Title: Re: Script for calculate the bandgap.
Post by: Nordland on May 26, 2009, 07:31
Judging from the bandstructure you have plotted, I am sure this is a metallic system per definition. If one fills the energy bands of a material with available electrons and ends up with a top band partly filled then the material is a metal.
The band that twist around the fermi level and hences it is only partly filled. If this material was subjected to a optics study, you would find that  it was a metallic system with intraband absorption.
Title: Re: Script for calculate the bandgap.
Post by: Nordland on May 26, 2009, 07:32
On a note: Yes - the script I wrote, does assume, that if the system is metallic, it is not caused by a partly filled band.
Title: Re: Script for calculate the bandgap.
Post by: esp on February 7, 2012, 07:08
i tried this script and it gives me an error: cannot find "ATK.KohnSham" library ..

also, what file is the input?  it is not an nc file?

Title: Re: Script for calculate the bandgap.
Post by: Nordland on February 7, 2012, 09:45
This script is very old :) at least 2008.10 very old :)

This script does not work in the newer version of ATK. I think there is another way for getting the bandgap somewhere on the forum. Let me look.
Title: Re: Script for calculate the bandgap.
Post by: Anders Blom on February 7, 2012, 10:25
You can try the script in http://quantumwise.com/forum/index.php?topic=1013.0 instead, although I generally warn against treating the calculation of the band gap as a black box - you have to inspect the band structure and make sure you ask for the right thing. Ideally you should use the DOS with a dense enough k-point sampling, and then get the gap from there. If on the other hand you want the specific gap at a particular k-point, you can use a very simple approach:

Code: python
import sys
b = nlread(sys.argv[1], BulkConfiguration)[0]
t = Bandstructure(b, route=['G','G'], points_per_segment=2)
vbmax_ix = numpy.where(t.evaluate()[0]<=0.*eV)[0][-1]
cbmin_ix = numpy.where(t.evaluate()[0]>=0.*eV)[0][0]
bandgap = t.evaluate()[0][cbmin_ix]-t.evaluate()[0][vbmax_ix]
print "Direct band gap at Gamma point", bandgap

Save as bandgap.py and use as "atkpython bandgap.py file.nc", assuming the first BulkConfiguration in the NC file is the relevant one (else modify the script as needed).

This is for the Gamma point, but if you want another k-point just change the route.
Title: Re: Script for calculate the bandgap.
Post by: esp on February 7, 2012, 19:15
Thank you
Title: Re: Script for calculate the bandgap.
Post by: esp on February 21, 2012, 10:34
i am working with degenerately doped regions and need the bandgap, and distance from Ec and Ev to Ef ... how can I do this?  I don't see information on how the bandstructure object is constructed ..

i see a conversion of 1 HArtree to 27.211396132 eV .. is there a way to do this in atk automatically?  i need the fermi level in eV
Title: Re: Script for calculate the bandgap.
Post by: Nordland on February 21, 2012, 12:46
There is several options.


If you have an energy E, you can write:

# Convert the energy E to a float.
print E.inUnitsOf(eV)

# Conver the energy E to another unit.
print E.convertTo(eV)
Title: Re: Script for calculate the bandgap.
Post by: esp on February 26, 2012, 02:25
I could really use a solution to my question above about Ec, Ev, Ef calculations .. any ideas?
Title: Re: Script for calculate the bandgap.
Post by: Nordland on February 26, 2012, 14:06
All you need is to find the band gap of your graphene 1d systems?
Title: Re: Script for calculate the bandgap.
Post by: esp on February 26, 2012, 21:11
No, I need the bandgap, and Ec and Ev (or distance from Ef) for heavily doped (n+/p+) graphene regions ... the scripts i have seen so far assume no doping and do not give Ec and Ev, only bandgap
Title: Re: Script for calculate the bandgap.
Post by: esp on February 26, 2012, 21:14
what i need to do is this:  given a bandstructure, i want to programmatically set the bias voltages for transmission calcs, ... i cannot arbitrarily set bias to say 0.4V because when making a TFET i need to line up the band correctly for maximum current ... since transmission calcs take a whole day to complete, i need to speed up the time by selecting the bias window properly .. the only way to do that is by knowing the Ec and Ev values beforehand, then setting the bias appropriately ... if calcs were fast enough i could just run many biases, but they take so long i cannot be productive without some technique to speed things up .. this is the idea
Title: Re: Script for calculate the bandgap.
Post by: Anders Blom on February 26, 2012, 21:22
But if you are able to compute the band gap Eg=Ec-Ev then by definition you know Ec and Ev - otherwise you wouldn't be able to subtract them. So look in the script for Eg, and you're sure to have Ec and Ev.
Title: Re: Script for calculate the bandgap.
Post by: Nordland on February 26, 2012, 22:10
... since transmission calcs take a whole day to complete, i need to speed up the time by selecting the bias window properly ..

Do you mean the self consistent calculation or the transmission calculation?
Title: Re: Script for calculate the bandgap.
Post by: esp on February 26, 2012, 22:12
but the bandgap can only be found if it is not heavily doped right?  in other words, if i have a n+ or p+ region where Ef is above Ec or below Ev ... then the scripts that have been posted do not work (they cannot find the bandgap) ... unless i am mistaken but i tried and it did not work
Title: Re: Script for calculate the bandgap.
Post by: Nordland on February 27, 2012, 01:36
Hey.

Sorry for the many counter questions, but I am not certain that what you desire exactly. If it was a semi-conductor you were talking about, everything
would be clear. Your electrode is p/n node semi-conductor to such a degree it becomes metallic, and therefore there is no band gap.
The definition of the valence band and conducting band in metals is not set in stone when it comes to metals.

One definition of the conducting band could be the lowest lying band that is completely free for electrons around the entire Brillouin zone, and the energy would E_c would then be the lowest energy point for this band. However by this definition the band crossing the fermi level will not be labeled the conduction band.

The same goes for the valence band, likewise the band crossing the fermi level will not be label the valence band. E_v would the be the highest energy for this band.

If you want to go with the usual definition of valence/conduction bands from semi-conductors, then you know the answer straight away E_g = 0, E_v = E_c = E_f


Title: Re: Script for calculate the bandgap.
Post by: esp on February 27, 2012, 01:55
well maybe i am not explaining well enough, or maybe i am not accurate in what i am saying, but maybe a picture will help ...

attached is a picture i posted in another post .. it is a p+-i-n+ tfet type design ... as you can see in the source and drain, the fermi level is above Ec or below Ev ... i need to know the gap, Ec and Ev .. given this information, i can set bias appropriately .. does that make sense? 

the scripts for bandgap posted here cannot find this gap and i dont believe they give the Ec and Ev levels ... I understand what you are saying, but just because it is heavily doped doesnt mean Ec and Ev don't exist does it?  they are just shifted by the doping

Title: Re: Script for calculate the bandgap.
Post by: Anders Blom on February 27, 2012, 12:52
To some extent this is a semantic issue. Actually Ec and Ev do not exist in the heavily doped case, if by Ec we mean the lowest occupied state which is separated from another available state by a gap in energy, and opposite for Ev. But you come from a more pragmatic viewpoint and you say you know what the original Ec and Ev are before the doping, so you want to track these particular states as doping is introduced. My suggestion would be to figure out the quantum labels of these states, which simply means the band index of the Ec and Ev states (at a particular k-point). This is actually trivial, since you will have as many levels under the Fermi level as electrons in the system / 2 (for spin). This quantum number is not likely to change when doping is introduced, so you can ask for the energy of this same band index in the doped structure.
Title: Re: Script for calculate the bandgap.
Post by: esp on February 27, 2012, 19:55
Ok, and is there a way to find out how the bandstructure object is constructed and how to get to that information?
Title: Re: Script for calculate the bandgap.
Post by: Anders Blom on February 27, 2012, 20:46
In general in Python you can find out a lot of information about objects by using "dir". For example,

Code: python
dir(Bandstructure)

in Python produces a list of all methods and properties on the object. Then, if you want more information on a method, you can type e.g.

Code: python
help Bandstructure.evaluate

The best way to explore these things is by using ATK interactively, i.e. just start "atkpython" from the command line (without any script argument), then you can type Python commands manually, like those above, or any other ones that would normally appear in a script. It's a great way to develop a new script, to prototype something. This also allow you to do the "dir" thing above in a cool way: if you type something like

Code: python
config = nlread("file.nc",BulkConfiguration)[0]
config.

Note where this stops - with a ".". Now, hit the TAB key - and you will see all possible things you can continue this statement with. And it will autocomplete them, if you start typing "e" and hit TAB, you see only two choices: "elements" and "externalPotential". Saves a lot of typing!

Now, the information contained in this is actually given in the Reference Manual (http://quantumwise.com/documents/manuals/latest/ReferenceManual) as well, there is no difference, except that with "dir" you also see "hidden" or "private" functionality, methods and properties that the object has, but which we haven't made public yet. These can be utilized for many things, just don't trust them to work 100% the same way in future versions on ATK. It can also be faster to look things up interactively than browse the html manual.
Title: Re: Script for calculate the bandgap.
Post by: Anders Blom on February 27, 2012, 20:54
More specifically, about the band structure, if you use "evaluate", it returns a matrix of all the energies, with Npoints rows and Nbands columns, where Npoints is how many points are on the route (20 per segment, by default) and Nbands is the total number of bands.

So, after
Code: python
b = nlread('silver.nc', BulkConfiguration)[0]
bs  = Bandstructure(b, route=['G','X'])
E = bs.evaluate()
we could use E[0] to get all band energies at the Gamma point, and E[20] for those at the X point. If, instead, we want all energies for the 4th lowest band, as a function of k, we would use E[:,3] for the energies, and bs.kpoints() for the k-points.

Note that in this case there are 21 k-points; this is because there are 20 per segment + the final end-point.
Title: Re: Script for calculate the bandgap.
Post by: esp on February 27, 2012, 21:14
thank you very helpful i will try it
Title: Re: Script for calculate the bandgap.
Post by: esp on July 29, 2012, 09:23
I came back to this to try what you suggested ... i am not understanding it at all ... what i mean is, the values read dont seem to match the picture, or i can not reading it correctly ... attached is a zoomed out image of bands .. now there is some more complex thing i want to do, but let me explain the issue with a simple calculation:

Code
objid = "bulkUndoped"
bandstructures = nlread('file_bands.nc', Bandstructure, object_id=objid+"bands")
E = bandstructures[0].evaluate()
numPts = len(E)
numBands = len(E[0])

Now, I set the variables above numPts and numBands as above, because when I ran len(E) I got 22, and len(E[0]) i got 184, which seems to mean that the first index is the point index, and the 2nd is the band index ... is this correct?

Now the question is then, if that is true, then why dont't the values from E[0][0] to E[21][0] match the first band? I dont understand it ...

What I want to do is index each value on the band in order, how can I do that please?
Title: Re: Script for calculate the bandgap.
Post by: esp on July 29, 2012, 09:55
Nevermind ... that works perfectly well .. i was looking at the wrong objid

thank you
Title: Re: Script for calculate the bandgap.
Post by: yogita on January 20, 2013, 12:53
hi Nordland,

i am very new in ATK, using 11.8.2,
want to calculate bandgap of Cu2o, but got the following error message,
can u help me to know about module..... and some more details in script to analyse the bandstructure...


thanks



Traceback (most recent call last):
  File "c:\users\skf1f5~1.sha\appdata\local\temp\6465418687460360.py", line 20, in <module>
    from ATK.KohnSham import *; import numpy
ImportError: No module named ATK.KohnSham
+-------------------------------------------------
Title: Re: Script for calculate the bandgap.
Post by: Anders Blom on January 20, 2013, 21:51
This is a very old thread, but if you had read all posts you would find the reason - and the solution. The script posted originally was for ATK 2008.10, but a new one can be found in http://quantumwise.com/forum/index.php?topic=1013.0 (the second post). It's an Analyzer, you should drop the script on the Analyzer icon.
Title: Re: Script for calculate the bandgap.
Post by: Nordland on January 21, 2013, 10:53
And therefore I lock it to prevent it getting resurrected from time to time.