Author Topic: An Error for calculating the current of LiH2 chain  (Read 11749 times)

0 Members and 1 Guest are viewing this topic.

Offline eastnobil

  • Regular QuantumATK user
  • **
  • Posts: 19
  • Reputation: 0
    • View Profile
An Error for calculating the current of LiH2 chain
« on: March 28, 2010, 07:36 »
According to the VNL2010.02 tutorial, I used the current.py after the calculating of transmission Spectrum for getting the current of LiH2 chain. The script of "current.py" is copied from tutorial as following:
from NanoLanguage import *

#read the transmission spectrum
transmission_spectrum = nlread("LiH2.nc",TransmissionSpectrum)[1]

#calculate current
current = transmission_spectrum.current()

#print results
print 'current = ', current

Dropping this script on the Job Manager produced the following error:
+ -------------------------------------------------------------
| NanoLanguageScript execution started
+ -------------------------------------------------------------
Traceback (most recent call last):
  File "c:\docume~1\admini~1\locals~1\temp\4130483409169978.py", line 4, in <module>
    transmission_spectrum = nlread("LiH2.nc",TransmissionSpectrum)[1]
IndexError: list index out of range
NanoLanguageScript execution failure
+ -------------------------------------------------------------
| NanoLanguageScript execution finished
+ -------------------------------------------------------------

Why did I fail in accordance with the operation of VNL2010.02 tutorial?

Offline zh

  • QuantumATK Support
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 1141
  • Reputation: 24
    • View Profile
Re: An Error for calculating the current of LiH2 chain
« Reply #1 on: March 28, 2010, 08:15 »

#read the transmission spectrum
transmission_spectrum = nlread("LiH2.nc",TransmissionSpectrum)[1]
Update the above with the following:
transmission_spectrum = nlread("LiH2.nc",TransmissionSpectrum)

Offline eastnobil

  • Regular QuantumATK user
  • **
  • Posts: 19
  • Reputation: 0
    • View Profile
Re: An Error for calculating the current of LiH2 chain
« Reply #2 on: March 28, 2010, 11:23 »

#read the transmission spectrum
transmission_spectrum = nlread("LiH2.nc",TransmissionSpectrum)[1]
Update the above with the following:
transmission_spectrum = nlread("LiH2.nc",TransmissionSpectrum)

I have tried the script changing following the suggestion above,but I fail still. This time the error as following:
+ -------------------------------------------------------------
| NanoLanguageScript execution started
+ -------------------------------------------------------------
  File "c:\docume~1\admini~1\locals~1\temp\4346177520497036.py", line 4
    transmission_spectrum = nlread("LiH2.nc",Transmission Spectrum)
                                                                 ^
SyntaxError: invalid syntax
NanoLanguageScript execution failure
+ -------------------------------------------------------------
| NanoLanguageScript execution finished

Offline nori

  • QuantumATK Guru
  • ****
  • Posts: 122
  • Reputation: 12
    • View Profile
Re: An Error for calculating the current of LiH2 chain
« Reply #3 on: March 28, 2010, 11:31 »
Probably your problem can be solved by changing the script as follows:
before)
transmission_spectrum = nlread("LiH2.nc",Transmission Spectrum)
after)
transmission_spectrum = nlread("LiH2.nc",TransmissionSpectrum)[0]


Please note that an index starts from not "1" but "0" in Python.
I guess there is only one Transmission data in your "LiH2.nc" and that's why you got the error message "IndexError: list index out of range" in the first calculation.
« Last Edit: March 28, 2010, 11:39 by nori »

Offline eastnobil

  • Regular QuantumATK user
  • **
  • Posts: 19
  • Reputation: 0
    • View Profile
Re: An Error for calculating the current of LiH2 chain
« Reply #4 on: March 28, 2010, 11:59 »
Probably your problem can be solved by changing the script as follows:
before)
transmission_spectrum = nlread("LiH2.nc",Transmission Spectrum)
after)
transmission_spectrum = nlread("LiH2.nc",TransmissionSpectrum)[0]


Please note that an index starts from not "1" but "0" in Python.
I guess there is only one Transmission data in your "LiH2.nc" and that's why you got the error message "IndexError: list index out of range" in the first calculation.

Thank you for your reply. According to your suggestion I modified the script from"[1]" to "
  • ". the error still exist as following:

+ -------------------------------------------------------------
| NanoLanguageScript execution started
+ -------------------------------------------------------------
  File "c:\docume~1\admini~1\locals~1\temp\0927007110504342.py", line 4
    transmission_spectrum = nlread("LiH2.nc",Transmission Spectrum)[0]
                                                                 ^
SyntaxError: invalid syntax
NanoLanguageScript execution failure
+ -------------------------------------------------------------
| NanoLanguageScript execution finished
+ -------------------------------------------------------------

the script of "current.py" is copied from VNL2010.02 tutorial. In addition, I normally don't think such a  simple error exist in a tutorial of famous software,like VNL. I am confused still for a error in such simple script.

Offline nori

  • QuantumATK Guru
  • ****
  • Posts: 122
  • Reputation: 12
    • View Profile
Re: An Error for calculating the current of LiH2 chain
« Reply #5 on: March 28, 2010, 12:10 »
The space key between "Transmission" and "Spectrum" isn't needed.
So, you should write "transmission_spectrum = nlread("LiH2.nc",TransmissionSpectrum)[0]".

bad: transmission_spectrum = nlread("LiH2.nc",Transmission Spectrum)[0]
right: transmission_spectrum = nlread("LiH2.nc",TransmissionSpectrum)[0]

Offline eastnobil

  • Regular QuantumATK user
  • **
  • Posts: 19
  • Reputation: 0
    • View Profile
Re: An Error for calculating the current of LiH2 chain
« Reply #6 on: March 28, 2010, 15:27 »
Thanks for your helps. The error have been  resolved already. Beyond my imagination, the error comes from the Clerical error of VNL2010.02 tutorial. And the key error is the "[1]" . It should be changed to "
  • " if the nc file has only one result of transmissionspectrum. And the numbers in square brackets is respond to the transmissionspectrum in the nc file.

Offline Anders Blom

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 5411
  • Country: dk
  • Reputation: 89
    • View Profile
    • QuantumATK at Synopsys
Re: An Error for calculating the current of LiH2 chain
« Reply #7 on: March 29, 2010, 00:55 »
It's not, strictly, an error in the tutorial, but the explanation is probably missing, which makes it easy to make a mistake. If you follow the tutorial exactly, step by step, the script is correct for reading the transmission spectrum of the 1 V bias calculation, stored in the same file as the zero bias calculation. Therefore the NC file will actually contain 2 transmission spectra, and so when you tell ATK you want to read the transmission spectra, as you do with
Code
transmission_spectrum = nlread("LiH2.nc",TransmissionSpectrum)
it will return a list with 2 entries. The first one is [ 0 ] and the second is [ 1 ]. (I write indices with spaces; as you perhaps noticed [ 0 ] without spaces has a special meaning in BB code, used for markup on the Forum.) In future versions we'll probably have some simple way to bring up the NC file in VNL, click on the TransmissionSpectrum entry (one of them), and say "calculate current". This will reduce the need for the user to write little pieces of code, but/and for those who still want to we can make some more explanatory tutorials. A way to get around the indices, which are kind of arbitrary (just by order which they were put into the file), would be to refer to the transmission spectrum by object_id which is a unique label for each quantity put into the NC file. An example:
Code
# Zero bias calculation 
...
transmission_spectrum = ...
nlsave("LiH2.nc",transmission_spectrum, object_id="zerobias")
# 1 V bias calculation 
...
transmission_spectrum = ...
nlsave("LiH2.nc",transmission_spectrum, object_id="1Vbias")
This takes some of the guesswork out of it, so that when you want to restore the transmission spectrum, you would say
Code
# Read 1 V transmission spectrum
transmission_spectrum = nlread("LiH2.nc",object_id="1Vbias")[0]
Now, you still need the [ 0 ] (at least for now, maybe not in the future, but we'll let you know in the manual about that!), but since the object_id is unique, you never need [1] in this case. Good luck and have fun with ATK!
« Last Edit: March 29, 2010, 00:58 by Anders Blom »