Dear all, I wanted to share with you a script that pretty much does the same thing as the Nanotube Grower in VNL, but in a much more versatile way.
Specifically, it contains easy-to-use functions to generate
- Perfect nanotubes, as bulk
- Carbon or boron-nitride tubes (or any A-B tube)
- Ideal two-probe representations of nanotubes
- Molecular nanotube segments for editing and insertion as central region in two-probes
I will make a more proper tutorial around it later, but I just wanted to let everyone get a chance to try to script.
Essentially, it's built up around a class called Nanotube which has a lot of useful methods like chiralVector(), radius(), etc. These will be documented separately later on.
Then, there are 4 high-level functions that use this class:
def createNanotubeAsPAC (n,m,reps=1,elements=(Carbon,Carbon),bondlength=1.422*Ang)
def createNanotubeAsBulk (n,m,reps=1,elements=(Carbon,Carbon),bondlength=1.422*Ang)
def createNanotubeForCentralRegion (n,m,reps=1,elements=(Carbon,Carbon),bondlength=1.422*Ang)
def createPerfectNanotubeAsTwoProbe (n,m,elec_reps,sr_reps,elements=(Carbon,Carbon),bondlength=1.422*Ang)
The parameters are almost the same for all functions.
- n and m are of course the nanotube indices, as in a (n,m)=(4,1) nanotube
- reps is a repetition factor (along the tube), by default always 1
- elements should be a tuple (or list) with 2 elements, like (Carbon,Carbon) or (Boron,Nitrogen)
- bondlength is the carbon-carbon (or whatever) distance; must be given with unit
For the two-probe function, there are 2 repetition parameters instead of one: one for the electrodes (elec_reps) and one for the scattering region (sr_reps).
The functions all return a configuration. You can use it as it is, in the script, or store it in a VNL file for manipulations in VNL or later use. For instance, running
from ATK.KohnSham import *
from Nanotube import *
# -----------------------------
# Tube parameters
# -----------------------------
aCC = 1.422*Ang
n = 12
m = 1
element1 = Boron
element2 = Nitrogen
# -----------------------------
nanotube = createNanotubeAsBulk (n,m,1,(element1,element2),aCC)
vnl_file=VNLFile("BN_nanotube.vnl")
vnl_file.addToSample(nanotube,"Boron-nitride (12,1) nanotube")
produces a file that we can visualize in VNL (attached as image) with a (12,1) B-N nanotube.
Dropping the VNL file on the NanoLanguage scripter, we can now immediately proceed to calculate its band structure, for instance, etc.
For example, let us compute the band structure of a (4,4) B-N nanotube. Now, remember that a (4,4) carbon nanotube is metallic; it turns out, the B-N is not.
Step 1: Run this script to create the geometry
from ATK.KohnSham import *
from Nanotube import *
aCC = 1.45*Ang # literature values vary from 1.43 to 1.45 Ang
n = 4
m = 4
element1 = Boron
element2 = Nitrogen
nanotube = createNanotubeAsBulk (n,m,1,(element1,element2),aCC)
vnl_file=VNLFile("bn_44.vnl")
vnl_file.addToSample(nanotube,"B-N (4,4) nanotube")
Step 2: Drop the created file on the NanoLanguage Scripter in VNL and modify the following parameters:
- Brillouin zone integration parameters: (1,1,50) is a reasonable k-point sampling
- Specify a VNL file name where to store the band structure (for instance, the same VNL file as the geometry is in). Remember to enter the full absolute file name, with path!
- Add Energy Bands to the analysis options. Delete all k-points, by right-clicking them, except the two first. Thus, we will obtain the band structure from Gamma to Z=(0,0,0.5).
Step 3: Drop the script from the NanoLanguage Scripter to the Job Manager to run it! It should take 5-10 minutes depending on your hardware.
Step 4: When the calculation finishes, drop the VNL file with the band structure on the Result Browser. Zooming in a bit, you should be able to indeed see the band gap for the (4,4) B-N nanotube as in the attached plot!
Dear all, When I tried to generate a (3,3) CNT as TwoProbe, the script gave the following error. How can I correct it? Regards, Maresh
Traceback (most recent call last):
File "c:/docume~1/master1/locals~1/temp/tmplp9jqf.nl", line 254, in ?
nanotube = createPerfectNanotubeAsTwoProbe (n,m,1,(element1,element2),aCC)
File "c:/docume~1/master1/locals~1/temp/tmplp9jqf.nl", line 232, in createPerfectNanotubeAsTwoProbe
electrode = createNanotubeAsPAC (n,m,elec_reps,elements,bondlength)
File "c:/docume~1/master1/locals~1/temp/tmplp9jqf.nl", line 187, in createNanotubeAsPAC
elements = myTube.siteCount()*[elements[0],]+myTube.siteCount()*[elements[1],]
AttributeError: PhysicalQuantity instance has no attribute '__getitem__'
Terminated Abnormally
Your statement that calls the function has a mistake, you have only one repetition argument.
The correct syntax for a (3,3) carbon nanotube should be
nanotube = createPerfectNanotubeAsTwoProbe(3,3,1,1,(Carbon,Carbon),1.422*Ang)
or shorter (relying on defaults)
nanotube = createPerfectNanotubeAsTwoProbe(3,3,1,1)
With your variable definitions, you could write
nanotube = createPerfectNanotubeAsTwoProbe (n,m,1,1,(element1,element2),aCC)
If you have further questions, please post your statement that generates the error.
Note 1: A (3,3) nanotube is on the border of being realistic...
Note 2: A single electrode / central region repetition may be too small... I would use 2 as minimum (for the electrode) to be on the safe side, and 3-4 at least for the central region. Otherwise your results may be wrong, or the calculation might not converge.
The Nanotube.py script should be in the same directory as your main script, if you are running the whole thing using ATK directly on the command line, that is.
If you, as many do, run it by dropping the script on the Job Manager or directly to the Nanoscope, you need to take care of the path a little bit. There are basically two options; this is also discussed in another post (http://), but there is a slight difference because that case primarily dealed with running a calculation while here we are generating a geometry.
So, the options are:
A) Create a special directory where you keep all "utility" scripts like Nanotube.py. Let's say this directory is c:/users/me/nlfiles (always use forward slashes / in Python, never backslash \ even on Windows).
Then, in each script that needs to access such utility files, add these two lines at the top:
import sys
sys.path.append('c:/users/me/nlfiles')
B) A simpler way is to use a special directory called site-packages in the ATK installation inside VNL. Create this directory and place any script you want to be able to import there. The exact location of this directory differs a bit in Windows and Linux.
- Windows: Create the directory site-packages in %vnl%/atk/lib
- Linux: Create the directory site-packages in %vnl%/atk/lib/python2.4
Here %vnl% symbolically denotes the VNL installation directory.
The slight disadvantage of alternative B) is that you must remember to move your utility scripts along when you upgrade to a new version of VNL. Also, the scripts will only work inside VNL, not when run with a stand-alone installation of ATK, unless you create a mirror copy of the directory in the ATK installation tree too (on Linux, this can quite conveniently be done with a softlink!).