Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Anders Blom

Pages: 1 ... 332 333 [334] 335 336 ... 362
4996
Scripts, Tutorials and Applications / Relaxation under bias
« on: July 30, 2009, 13:13 »
As many have noticed, the latest version of ATK do not support geometry optimization of a two-probe system under bias. Here is a solution that enables this feature!

First of all, let us point out one thing. The reason the functionality to relax under bias was removed in the first place (or more specifically, the reason why two-probes are relaxed as equivalent bulk systems; that's why you cannot use bias, since a bulk system cannot be biased), was that we found out that there was an ambiguity regarding the configuration that minimized the forces vs. the configuration that minimized the total energy. That is, the force minimum and the energy minimum did not coincide.

Now, some experts maintain that this is to be expected. Since the two-probe boundary conditions are open, the total energy is not a well-defined quantity, one should rather probably use the free energy.

However, the forces as computed by ATK should still be correct. Therefore, it should be possible to use the force-based Steepest Descent method to relax a two-probe system, even under bias. Now, all we need to do to enable this feature, is to tweak ATK a little bit, and this is what the attached script does.

An example is provided to show you how to use it. It's just a simple Li-H2-Li system, with constraints applied so that only the hydrogen atoms can move. It should converge in 9 steps or so.

The following things need to be observed:

1) Only the Steepest Descent method is supported, for the reason mentioned above. The default in ATK is actually QuasiNewton, however if you forget to specify Steepest Descent the script will not complain, it will just silently use it anyway (and use the default "time_step").

For details on the relaxation method itself, and how to specify parameters to it, see http://quantumwise.com/documents/manuals/ATK-2008.10/ref.geometricoptimizationparameters.html and the example provided there.

2) Unlike the built-in method for relaxation, the new function calculateOptimizedTwoProbeGeometry() (note that the function has a different name, to separate it from the native one) returns BOTH the optimized geometry AND the final self-consistent object. This saves you the hassle of re-calculating the last step, as is otherwise necessary if you wish to follow up with some analysis in the same script.

3) A bug regarding verbosity level was fixed, so now the same verbosity level applies to the whole run (the native version reverts to zero after the first step).

4) This is not an officially released version of this functionality, so please use it a bit carefully, and at your own risk :)

5) There is also support for initializing the relaxation from an already converged density matrix (in the form of an SCF object). This can be used to boot-strap a finite bias relaxation from a converged calculation, e.g. for the same bias or a lower one.

6) Finally, I would recommend you place the module script CalculateOptimizedTwoProbeGeometry.py centrally in your ATK installation, i.e. in lib/python2.4/site-packages (on Linux, use lib/site-packages on Windows). That way it will work in parallel just as well as in serial, and you don't have to worry about setting the Python path etc.

Attached files are:
  • The module script
  • An example NanoLanguage script
  • The VNL file needed by the example

Comments, feedback etc is always welcome!

Update, after the original post: Added support for "initial_calculation".

4997
Please note the previous post was heavily modified after I posted it, so make sure to use the latest version of it!

4998
There are two ways. Either modify the script to contain the NC filename and sample explicitly, so you don't have to enter them when you run. Or, use "write" instead of "print". I will present both, although the "write" solution is probably best; there is a complete script for that at the end!

(Btw, do you really have a star * in the file name? It's a bad idea, it might screw things up here and there; better use "4x4x100" :) )

Method 1
Pipe the output to a file when you run it, like

Quote
atk extract_transmission_from_vnl_file.py > trans.dat

To modify the script for this is quite easy, just replace

Code
filename = raw_input('Please enter VNL file name: ')

by

Code
filename = "Au100-Au8-Au100_Transmission_4*4*100.vnl"

Then, replace

Code
sname = raw_input('Please enter sample name to extract (default=first sample): ')

by

Code
sname = ""

This only works if the sample we want is the first/only one in the file, but that is the case at hand, so we're good!

Method 2
Write a file from within the script, by replacing the "print" statements by "write" statements. This involved a few more lines to modify, so I'll just post the ready script.

Code
import zipfile, cPickle, sys

filename = raw_input('Please enter VNL file name: ')
try:
    f = zipfile.ZipFile(filename,'r')
except:
    print 'Unable to locate VNL file "%s"' % filename
    sys.exit(1)

# Restore the samples from the VNL file into a dict
samples = {}
for zinfo in f.infolist():
    s = f.read(zinfo.filename)
    try:
        obj = cPickle.loads(s)
        samples[obj.name()] = {}
        for h in obj.history():
            samples[obj.name()][h.name] = h.resultsample.properties()
    except:
        pass

print 'The following samples are present in this VNL file:'
print samples.keys()

sname = raw_input('Please enter sample name to extract (default=first sample): ')
if sname.strip()=="":
    data = samples[samples.keys()[0]]['NanoLanguage']
else:
    data = samples[sname]['NanoLanguage']   

print 'The following properties are present for this sample:'
print data.keys()

# Write the transmission data to a file
f = open("trans_"+filename+"_"+sname+".dat","w")
f.write('# Energy (eV)\tTotal transmission\n')
f.write('# ----------------------------------\n')

# Some older versions used "Transmission Spectrum" or "TransmissionSpectrum"
trans = data['Transmission Spectrum']
energies = trans.energy()._dataarray_
# Check for energy unit, if you want to be sure
# e_unit = t.energy().units()
T = trans.average_transmission()

# Write the transmission data to a file
for i in range(len(energies)):
    f.write('%g\t%g\n' % (energies[i],T[i]))
f.close()

Note that I use the VNL file name to label the output file, so in case you run several times, with different samples or VNL files, you will not overwrite the output files.

4999
Ok, this is because you (or whoever generated the script) made a customized label for this quantity when it was added to the VNL file. So, the only thing we need to change (after removing the "print" statement) is this line:

Code
trans = data['Transmission Spectrum Transmission Spectrum']

to

Code
trans = data['Transmission Spectrum T(E)']

Hope this works out for you now!

5000
Ok, time for some troubleshooting :)

You could just email me the VNL file, if it isn't too huge (usually it isn't unless you saved any 3D grids into it), and I can quickly figure it out. Or (if it is too big, or you just don't want to share it), you can insert a print statement

Code
print data.keys()

before the statement "trans = ...", and let us know the output, and we'll take it from there.

5001
Hmm, good news and bad news...

The script is not correctly set up, for many reasons.

First, although there is a loop over the voltages, each voltage uses the same checkpoint file, so each voltage overwrites the result of the previous one. To fix this, the line

Code
checkpoint_filename = 'C:/Users/617/Desktop/lih2li1.nc'

needs to be replaced by something like

Code
checkpoint_filename = 'C:/Users/617/Desktop/lih2li1_%g.nc' % voltage

This will make one checkpoint file for each bias.

So, unfortunately you have wasted some time computing the scf loop for each bias.

At the same time, the computation of the current is not part of the loop. Therefore, the current has only be computed for the last bias point, and thus you didn't waste any time on this part (that was the good news...).

By the way, I don't imagine you will be able to converge the calculation for as high bias as 5 V. You should probably limit the range, in the first run, from 0 to 1.5 V or so.

To get the current calculation into the loop, you should simply indent those lines one stop (4 spaces), and then also make sure each current is stored in the VNL file under a unique label. Thus, again, something like

Code
if processIsMaster(): file.addToSample(current, 'twoprobe_configuration', 'Current at %g V bias' % voltage)

Oh, and do pipe the output of the calculation to a log file, so you have the printed current values. Since these will be intermixed with all the output from the SCF loop, it might be a bit hard to locate them later. Therefore, I would change the line

Code
if processIsMaster(): nlPrint(current)

to something like

Code
if processIsMaster(): print "Voltage: %g V, Current: %g A" % (voltage.inUnitsOf(Volt), current.inUnitsOf(Ampere))

Then, later, you can "grep" for "Voltage" to get the values from the log file.

Actually, you may want to consider splitting the SCF part and the current calculation. That is, just run the loop over voltages but skip the current for now. Then, later, just restore all the checkpoint files and compute the current separately.

If you're ok making these changes by yourself, it will be a good exercise :-) But I suggest you post the script before you run it, and then we can verify that you will not be wasting your time again.

5002
A small correction: you can actually compute the forces under bias. However it is correct that you cannot use the built-in functionality to run a geometry optimization for a two-probe system under bias.

It is however possible to do "manually", and I have recently written such a module, which thus allows relaxation under bias, and thus facilitates computation of the quantities sought in the original question (more or less). I will post it here later today.

The authors used TranSIESTA, which at that time could be considered the "academic pre-cursor" to ATK. ATK has similar but not identical capabilities as TranSIESTA; most notably ATK is not based on SIESTA, it just uses the same LCAO method for the electronic structure.

5003
If you have the log file from the calculation, it should contain the transmission spectrum data as two columns (energy E, T(E)) somewhere towards the end.

If you don't have the log file any more (or, if you encounter the problem that there are too few decimals in the spectrum in the log file...), you can extract it from the VNL file using the method described here: http://quantumwise.com/forum/index.php?topic=3.0. Then, you can plot it in any software you prefer.

You may want to modify the script to load the VNL file internally (instead of prompting for it, interactively), and the same for the sample name (you know this from the Result Browser). Then, when you run the script, just pipe the output to a file, and you will have the spectrum in this file, ready for plotting in e.g. GNUPlot.

Hope you are able to figure this out, otherwise let us know if we need to post more detailed instructions.

5004
General Questions and Answers / Re: From crystalmaker to VNL
« on: July 30, 2009, 07:32 »
Can you attach the file, then we can have a look? It should be quite easy to write a small script to convert it (provided it's a text file).

5005
These files are provided in the file "transmission_scripts.zip" on the Tutorials page, just next to where to download the PDF file from (right-most column of the table). Please use the Monkhorst-Pack script from the ZIP file, as it's substantially updated compared to the older one in the Examples.

5006
General Questions and Answers / Re: Python Files in VNL
« on: July 29, 2009, 12:59 »
The concepts of surface layers are a bit different from the respective perspectives of the Python configuration and the Atomic Manipulator, so this is nothing to worry too much about.

If the geometry becomes distorted, it might however be an indication that it's not entirely correctly set up. In particular, pay special attention to the "alignment atoms". One way to check is to instead drop the Python file on the Nanosope. If it also looks weird there, then you can be quite sure there is some error in the setup.

5007
General Questions and Answers / Re: Python Files in VNL
« on: July 29, 2009, 10:00 »
If you have the geometry already defined in the Python script, there isn't really any need to save it as a VNL file, you can just drag the geometry directly to the NanoLanguage Scripter, as ZH mentions. Having the geometry in a VNL file can however be convenient if you want to reuse it several times, or import it into another script, without having to drag along the original Python code.

Thus, if you're anyway playing with the Python code, you can just add a few lines of code to generate a VNL file:

Code
f = VNLFile("/home/user/my_geometry.vnl")
f.addToSample(my_configuration,"My nice geometry")

(obviously you have to change the filename and variable name, and the label, to match your specific script and conditions).


5008
Yes, you can certainly use the checkpoint file for this purpose!

If you are writing scripts by hand, have a look at the manual entry for restoreSelfConsistentCalculation().

In VNL, drop the original geometry on the NanoLanguage Scripter (to make it understand which system you are using). Then go to the "Self-Consistent Calculation" tab and tick "Restore calculation from checkpoint file", enter the NC filename, and UNCHECK "Only use initial density".

Then, set up the analysis as you would otherwise.


5009
To zoom out in the Result Browser plots, right-click the plot and choose "Zoom Out" from the context menu. The context menu also allows you to zoom in, but it's easier to just make a box with the mouse to zoom in.

The best strategy to get the plot you want is to zoom out very far (using the context menu), and then zoom in on the specific area of interest.

5010
General Questions and Answers / Re: DOS for bulk
« on: July 27, 2009, 14:47 »
For jiangning198511:

I have re-engineered the 1D DOS module to handle spin. Try the attached script instead of the original "dos1d.py". You use it exactly like the original; the script will internally determine if the calculation was spin-polarized or not. The two spin components will be plotted red and blue, but it's simple to modifiy the script to change this, or any other plotting preferences.

Note that Nordland's method, which is really simple and straightforward, works quite well too, although you need to fiddle with the script each time you want to change the spin component, of course. But it's still easier, perhaps, if you want separate plots of the up and down spins.

Pages: 1 ... 332 333 [334] 335 336 ... 362