Author Topic: SET: IndexError: index 2 is out of bounds for axis 1 with size 2  (Read 11884 times)

0 Members and 1 Guest are viewing this topic.

Offline Gaurav

  • Regular QuantumATK user
  • **
  • Posts: 11
  • Country: in
  • Reputation: 0
    • View Profile
Good Morning to all,

I am using ATK-VNL version 2016.0 for Single_electron transistor based on different molecule as per Benzene Single-Electron Transistor Tutorial Version 2015.2.
Till Gate voltage scan,I havn't got any error.But,For read total energy and total Vs gate voltage earlier i got intended block error for python script but i sorted it out by proper
Tab positioning.
Now,For total energy Vs gate voltage script iam getting following error:

C:\Users\HPi7007\Desktop\Pentacene_SET\readTotalEnergy.py:16: FutureWarning: comparison to `None` will result in an elementwise object comparison in the future.
  if file_data == None:
Traceback (most recent call last):
  File "TEvsVg.py", line 13, in <module>
    voltage,energy = readTotalEnergy('pentacene_set'+str(q)+'.nc')
  File "C:\Users\HPi7007\Desktop\Pentacene_SET\readTotalEnergy.py", line 39, in readTotalEnergy
    return gate_voltage_list[index_list], total_energy_list[index_list]
IndexError: index 2 is out of bounds for axis 1 with size 2

I am attaching .py file for both script.

Thanking you!
« Last Edit: September 10, 2017, 07:33 by Kumar Gaurav »

Offline Ulrik G. Vej-Hansen

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 426
  • Country: dk
  • Reputation: 9
    • View Profile
Re: SET: IndexError: index 2 is out of bounds for axis 1 with size 2
« Reply #1 on: September 12, 2017, 10:02 »
It seems that one of those two lists are shorter than expected, but it is impossible to say why without seeing the log-file and/or the .nc file. Please provide these, and also the script used to calculate them.

Offline Gaurav

  • Regular QuantumATK user
  • **
  • Posts: 11
  • Country: in
  • Reputation: 0
    • View Profile
Re: SET: IndexError: index 2 is out of bounds for axis 1 with size 2
« Reply #2 on: September 12, 2017, 12:55 »
Dear Sir/Madam,

I am attaching .log file for both functional block of python script.

Offline Gaurav

  • Regular QuantumATK user
  • **
  • Posts: 11
  • Country: in
  • Reputation: 0
    • View Profile
Re: SET: IndexError: index 2 is out of bounds for axis 1 with size 2
« Reply #3 on: September 13, 2017, 06:53 »
Script used for calculation is mentioned below

read Total Energy script.
---

from NL.IO.NLSaveUtilities import nlinspect
from NanoLanguage import *

#define function for reading in total energy and gate voltage data from a file
def readTotalEnergy(filename):
    """
    function for reading a list of total energies and gate voltages from a file
        @param filename : filename of the netcdf file
        @return voltages, energies : list of gate voltages and energies
                                    found in filename
    """
    if filename == None:
        return
    #get list of data in file
    file_data = nlinspect(filename)
    if file_data == None:
        raise ValueError, "Wrong file format"
       
    total_energy_list = numpy.array([])
    gate_voltage_list = numpy.array([])
       
    for id in file_data:
        if (id[0] == 'TotalEnergy'):
            total_energy=nlread(filename, object_id = id[1])[0]
            total_energy_list = numpy.append(total_energy_list,
                                            total_energy.evaluate().inUnitsOf(eV))
            #extract the gate voltage from the id of the data
        if id[1][0:3] == 'gID':
            gate_voltage = 0.0
        else:
            gate_voltage = float(id[1].strip(
                            "abcdefghijklmnopqrstuvxyzABCDEFGHIJKLMNOPQRSTUVXYZ"))
        gate_voltage_list = numpy.append(gate_voltage_list,gate_voltage)
       
    if len(total_energy_list) ==0:
        raise ValueError, "No total energy in NC file"
    #sort the data
    index_list = numpy.argsort(gate_voltage_list)
    return gate_voltage_list[index_list], total_energy_list[index_list]

------------


Total Energy VS gate voltage script


-------

from readTotalEnergy import readTotalEnergy

# define the work function of gold
w = 5.28

#read in the total energy data from the files: pentacene_set[-2,-1,0,1,2].nc
voltage_list= []
energy_list = []

#loop over the charge states
charge_states = [-2,-1,0,1,2]
for q in charge_states:
    voltage,energy = readTotalEnergy('pentacene_set'+str(q)+'.nc')
    voltage_list = voltage_list + [voltage]
    # add energy of additional/missing electrons on benzene
    energy = energy -q*w
    energy_list = energy_list + [energy]
   
#plot the total energies
import pylab
pylab.figure()
for i in range(len(voltage_list)):
    pylab.plot(voltage_list,energy_list)
   
pylab.xlabel("Gate voltage (Volt)")
pylab.ylabel("Total Energy (eV)")
pylab.show()

---

I was facing problem in attaching script file that's why copying script in reply tab.

Thanking you!

Offline Ulrik G. Vej-Hansen

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 426
  • Country: dk
  • Reputation: 9
    • View Profile
Re: SET: IndexError: index 2 is out of bounds for axis 1 with size 2
« Reply #4 on: September 13, 2017, 09:41 »
The script that fails is reading from an .nc file. Please provide this file as specified above. The script used to produce the .nc file and the log-file from that calculation will also be very helpful.