One of the fundamentally important applications of ATK is to produce an I-V curve for a two-probe system. There is, however, no simple way to do it without quite a bit of scripting, as noted in
another post on this Forum.
Here is a script/module
ivcurve.py (attached) that takes care of that, at least in a quick-and-dirty way. The script is not a masterpiece of software design, and does no error checking etc, but ... it works :-)
The idea is to minimize the code the user has to write in his own script. The only required code to add is something along the lines of
import ivcurve
voltages=[0.0,0.1,0.2,0.3]*Volt
ivcurve.runIVcurve (
twoprobe_configuration,
two_probe_method,
runtime_parameters,
voltages,
vnl_filename='myfile.vnl', sample_name='mysample',
current_k_point_sampling = (1,1),
current_number_of_points = 100
)
iv = ivcurve.extractIVcurveFromVNLFile('myfile.vnl','mysample')
ivcurve.plotIVCurve(iv,'iv.png')
Hopefully the above is relatively self-explanatory, but we'll review some details below. Note how the variable names above are chosen to match those used by Virtual NanoLab when it produces NanoLanguage code for a two-probe system. Therefore it is very easy to just include the code above at the end of a script produced by Virtual NanoLab to obtain an I-V curve.
For a more complete example, see the attached script
lih2li_iv.py. It is based on the Li-H2-Li system from the manual, just because it's relatively quick to compute, so it's easy to test the I-V curve script using this system. To run the example you should have the geometry file
lih2li.vnl too; for simplicity it is also attached.
The code above should be inserted into a script, after the usual part which defines the
TwoProbeConfiguration and the
TwoProbeMethod, and also the run-time parameters. Then, insert the code snipped above at the bottom of the script, replacing the execution statement (
executeSelfConsistentCalculation()) if present. If you used your own variable names for the configuration, method and run-time parameters, adjust accordingly.
The code snippet above
- defines the voltages for which to compute the current
- runs a sweep with one calculation for each voltage bias
- produces a plot, stored in "iv.png" of the I-V curve
Important notes:- The bias values should come in sequence and start with 0 V, since for each bias, the previous converged calculation is used to initialize the calculation.
- An alternative way to set up the bias is to use numpy; to sweep from 0.0 to 1.0 V in steps of 0.1 V, use
import numpy
voltages = numpy.arange(0.,1.01,0.1)*Volt
- If the runtime parameters contain a checkpoint filename, the value of the bias will be added before the extension to create a unique NetCDF file for each bias. Thus, if you specified file.nc for a run with bias 0.0, 0.1 and 0.2 V, you will get three nc files file-0.0.nc, file-0.1.nc, and file-0.2.nc.
- The runtime parameters argument is required, but you can give None if you don't want any NetCDF files.
- All the computed values of the current will be stored in the VNL file specified, under the given sample name. You can inspect these values in Virtual NanoLab afterwards too.
- Remember to provide the correct integration parameters for the current (k-point sampling, in particular!).
- The plot can be customized to your liking. ATK actually has a built-in plotting engine (matplotlib), and you can produce very beautiful plots directly in NanoLanguage by using it. I'll make a separate post on that below!
- You can change the extension of the image file from "png" to any other supported file format (such as "eps").
- To print the I-V values, add this code to the end of the script:
print 'Bias (V)\tCurrent (A)\n' + '-'*40
for i in iv:
print i[0],'\t\t',i[1]
It's not unlikely that I overlooked some detail in this script, which causes it not to work in a particular situation... But please try it out, and together we can update it to make it a powerful NanoLanguage tool!
Edit: Updated version of script, which is safe for running in parallel.