QuantumATK Forum

QuantumATK => General Questions and Answers => Topic started by: Shan on July 13, 2012, 11:37

Title: single electron transistor: setting an array element with a sequenc
Post by: Shan on July 13, 2012, 11:37
Dear Experts,
when i am running the last script in benzene SET manual for self-consistent charge stability diagram. i got an error  "ValueError: setting an array element with a sequence."


please help me...


+------------------------------------------------------------------------------+
| NanoLanguageScript execution started                                         |
+------------------------------------------------------------------------------+
+------------------------------------------------------------------------------+
|                                                                              |
| Atomistix ToolKit 11.2.2 [Build 3069]                                        |
|                                                                              |
+------------------------------------------------------------------------------+
Traceback (most recent call last):
  File "c:\users\bhushan\appdata\local\temp\6043628770183943.py", line 31, in <module>
    voltage_list = numpy.array(voltage_list)
ValueError: setting an array element with a sequence.
NanoLanguageScript execution failure
+------------------------------------------------------------------------------+
| NanoLanguageScript execution finished                                        |
+------------------------------------------------------------------------------+
Title: Re: single electron transistor: setting an array element with a sequenc
Post by: Anders Blom on July 13, 2012, 12:44
This is a "typical" numpy error message, simple to solve, but we'd need to see your input Python script to know how and why it's wrong.
Title: Re: single electron transistor: setting an array element with a sequenc
Post by: Shan on July 13, 2012, 12:51
from readTotalEnergy import readTotalEnergy
import pylab
# define the work function of gold
w = 5.28
#gate bias interval
v_g_interval = numpy.linspace(-10,10,201)
#source-drain bias interval
v_sd_interval = numpy.linspace(-15,15,301)
#----------finished define parameters ----------#
#read in the total energy data from the files: benzene_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('benzene_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]
# make numpy arrays instead of lists
voltage_list = numpy.array(voltage_list)
energy_list = numpy.array(energy_list)
#make function that can return the charging energies
charging_energy = []
for i in range(len(charge_states)-1):
    f = SplineInterpolation1D(voltage_list,energy_list[i+1]-energy_list)
    charging_energy = charging_energy + [f]
#calculate number of charge states in the bias window
def conductionChannels(v_g,v_sd):
    channels = 0
    for f in charging_energy:
        channels = channels + (abs(f(v_g)) <= abs(v_sd/2) )
    return channels
#Generate the mesh points of the contour plot
X, Y = numpy.meshgrid(v_g_interval,v_sd_interval)
#evaluate number of charge states for each mesh point
Z = [ conductionChannels(X[i,j],Y[i,j])
     for i in range(numpy.shape(X)[0])
          for j in range(numpy.shape(X)[1])]
Z = numpy.array(Z).reshape(numpy.shape(X))
#make the plot
pylab.contour(X,Y,Z)
pylab.contourf(X,Y,Z)
pylab.xlabel("Gate voltage (Volt)")
pylab.ylabel("Source-Drain bias (Volt)")
pylab.show()
Title: Re: single electron transistor: setting an array element with a sequenc
Post by: Anders Blom on July 13, 2012, 13:19
Remember to post code as [ code=python ]code here[ / code ] (without the spaces) to make it easier to read.

I can't solve this immediately; in principle if you follow the tutorial exactly, all the scripts should work, but if you deviate a bit, then small changes can mean that the specific analysis scripts receive some input they were not precisely designed for. In that case you may need to do a bit of Python troubleshooting, like inserting "print voltage_list" before line 31.
Title: Re: single electron transistor: setting an array element with a sequenc
Post by: Shan on July 13, 2012, 13:26
 I am following the manual as it is. But still getting errors.

some errors are:
1. as mentioned in a post today i got some different charging energies than given in manual for SET phase.
2. for total energy vs gate voltage in SET phase, graph is coming from -8 to 0v of gate voltage instead of -8 to8v gate voltage.

 
Title: Re: single electron transistor: setting an array element with a sequenc
Post by: Anders Blom on July 13, 2012, 13:41
1. The different number can probably be explained by the fact that you are running 11.2 and the numbers in the tutorial are from 11.8. We upgraded the multigrid solver from 11.2 to 11.8.

2. Do you have results for all gate voltages from -8 to 8 V in the NC files?
Title: Re: single electron transistor: setting an array element with a sequenc
Post by: Shan on July 13, 2012, 13:47
yes, i have values for all the gate voltages from -8 to 8v.
 namely -8,-6,-4,-2,0,2,4,6,8v.
Title: Re: single electron transistor: setting an array element with a sequenc
Post by: Anders Blom on July 13, 2012, 13:52
1. For all charge states?

2. Try inserting "print voltage_list" before the line "voltage_list = numpy.array(voltage_list)". You need to see what the problem is there.

PS: I'm on holiday, and will not be able to answer quickly, perhaps. So if I disappear for a few days, that's why.
Title: Re: single electron transistor: setting an array element with a sequenc
Post by: Shan on July 13, 2012, 14:14
yes all the charge states namely -2,-1,0,1,2 there are values for gate voltages -8,-6,-4,-2,0,2,
Title: Re: single electron transistor: setting an array element with a sequenc
Post by: Shan on July 13, 2012, 14:15
gate voltage 4,6,8v missed in above reply post.
Title: Re: single electron transistor: setting an array element with a sequenc
Post by: Shan on July 13, 2012, 14:22
Anders sir,
After inserting the command print voltage_list i got same error, with some extra data as below.



+------------------------------------------------------------------------------+
| NanoLanguageScript execution started                                         |
+------------------------------------------------------------------------------+
+------------------------------------------------------------------------------+
|                                                                              |
| Atomistix ToolKit 11.2.2 [Build 3069]                                        |
|                                                                              |
+------------------------------------------------------------------------------+
[array([-8.,  0.,  0.]), array([-8.,  0.,  0.,  0.]), array([-8.,  0.]), array([-8.,  0.,  0.]), array([-8.,  0.])]
Traceback (most recent call last):
  File "c:\users\bhushan\appdata\local\temp\6999651209991004.py", line 25, in <module>
    voltage_list = numpy.array(voltage_list)
ValueError: setting an array element with a sequence.
NanoLanguageScript execution failure
+------------------------------------------------------------------------------+
| NanoLanguageScript execution finished                                        |
+------------------------------------------------------------------------------+
Title: Re: single electron transistor: setting an array element with a sequenc
Post by: Anders Blom on July 13, 2012, 14:28
Yeah, that's wrong... What you should have is 5 identical arrays in a list:

[array([-8.,  -6.,  -4., -2., 0., 2., 4., 6., 8.]), array([-8.,  -6.,  -4., -2., 0., 2., 4., 6., 8.]), array([-8.,  -6.,  -4., -2., 0., 2., 4., 6., 8.]), array([-8.,  -6.,  -4., -2., 0., 2., 4., 6., 8.]), array([-8.,  -6.,  -4., -2., 0., 2., 4., 6., 8.])]

So, somehow readTotalEnergy doesn't like the object IDs in the NetCDF files perhaps... There is a risk the indentation got mangled when you saved the script (as would be indicated by your other error, about "return"). Try to download the script again, not by copy/pasting it, but just clicking the link to it in the tutorial HTML page, and then save it directly. Otherwise attach readTotalEnergy.py as a file to your Forum post so I can check this point.

Title: Re: single electron transistor: setting an array element with a sequenc
Post by: Shan on July 13, 2012, 14:38
here is the attachment of readTotalEnergy.py file.
Title: Re: single electron transistor: setting an array element with a sequenc
Post by: Anders Blom on July 13, 2012, 15:12
That looks fine.

Ok, let's troubleshoot a bit more.

Make a copy of your current "readTotalEnergy.py", let's say "readTotalEnergy_realone.py". This is just a backup. Then insert two lines into readTotalEnergy.py:

Code: python
print file_data
return [1],[1]
right after the line "file_data = nlinspect(filename)".

Remember these two lines must be indented to the same level as "file_data = ", i.e. 4 spaces first on the line. Do not use TAB.

Run the command again (atkpython charge_stability_diagram_full.py) and let's see what it prints.
Title: Re: single electron transistor: setting an array element with a sequenc
Post by: Shan on July 13, 2012, 15:47
Anders sir,
After inserting the commands print file_data and return [1],[1] in the specified we got another error.
"unsupported operand type(s) for -: 'list' and 'float'".

please check it...
thank you



+------------------------------------------------------------------------------+
| NanoLanguageScript execution started                                         |
+------------------------------------------------------------------------------+
+------------------------------------------------------------------------------+
|                                                                              |
| Atomistix ToolKit 11.2.2 [Build 3069]                                        |
|                                                                              |
+------------------------------------------------------------------------------+
[['BulkConfiguration' 'gID000']
 ['BulkConfiguration' 'gID004']
 ['ElectrostaticDifferencePotential' 'gID001']
 ['ElectrostaticDifferencePotential' 'gID005']
 ['ElectrostaticDifferencePotential' 'pot-2.0 V']
 ['ElectrostaticDifferencePotential' 'pot-4.0 V']
 ['ElectrostaticDifferencePotential' 'pot-6.0 V']
 ['ElectrostaticDifferencePotential' 'pot-8.0 V']
 ['ElectrostaticDifferencePotential' 'pot2.0 V']
 ['ElectrostaticDifferencePotential' 'pot4.0 V']
 ['ElectrostaticDifferencePotential' 'pot6.0 V']
 ['ElectrostaticDifferencePotential' 'pot8.0 V']
 ['MolecularEnergySpectrum' 'gID002']
 ['MolecularEnergySpectrum' 'gID006']
 ['MolecularEnergySpectrum' 'spec-8.0 V']
 ['TotalEnergy' 'energy-8.0 V']
 ['TotalEnergy' 'gID003']
 ['TotalEnergy' 'gID007']]
Traceback (most recent call last):
  File "c:\users\bhushan\appdata\local\temp\0450131338016601.py", line 21, in <module>
    energy = energy -q*w
TypeError: unsupported operand type(s) for -: 'list' and 'float'
NanoLanguageScript execution failure
+------------------------------------------------------------------------------+
| NanoLanguageScript execution finished                                        |
+------------------------------------------------------------------------------+
Title: Re: single electron transistor: setting an array element with a sequenc
Post by: Anders Blom on July 13, 2012, 16:11
The error is to be expected (sort of), it's just because we return something wrong. The important thing is the output from the print statement. I had hoped to see it for all 5 NC files, however, and because of the error we only got it for the first one.

That's partly enough, however, because we can clearly see some problem here, I think. This file (presumably benzene_set-2.nc) contains only 3 TotalEnergy objects, instead of one for each gate voltage as it should. And the object_id is also wrong for 2 of them; only the -8 is correct. There are however potentials for all gate voltages...

Somehow the script gatescan0.py (or similar for -2 charge state etc) have not been run correctly. If you attach gatescan-2.py perhaps I can spot the error.
Title: Re: single electron transistor: setting an array element with a sequenc
Post by: Shan on July 13, 2012, 18:37
here is the copy of gatescan-2.py
Title: Re: single electron transistor: setting an array element with a sequenc
Post by: Anders Blom on July 13, 2012, 19:09
Exactly as I suspected - the indentation is wrong. This is not the file you get if you download gatescan0.py from the tutorial HTML pages (and then change to -2 for the charge state). The difference is the last 5 lines should be indented one step (by 4 spaces). Without that indentation, those lines are only executed once, when the for-loop has finished (i.e. for the last gate voltage only, -8 V).

Title: Re: single electron transistor: setting an array element with a sequenc
Post by: Shan on July 13, 2012, 19:39
ok. I will rerun all the scripts from gatescan0.py onwards by providing the 4 spaces to last 5 lines. I will report if any problem.
Title: Re: single electron transistor: setting an array element with a sequenc
Post by: Anders Blom on July 13, 2012, 22:33
You need to remove those special lines in readTotalEnergy.py which we inserted ;)
Title: Re: single electron transistor: setting an array element with a sequenc
Post by: Shan on July 13, 2012, 22:54
Anders sir,
yes it worked for the total energy vs gate voltage script. i got the plot.
But in charge stability diagram script the same previous error is coming."ValueError: setting an array element with a sequence."

please suggest me...


+------------------------------------------------------------------------------+
| NanoLanguageScript execution started                                         |
+------------------------------------------------------------------------------+
+------------------------------------------------------------------------------+
|                                                                              |
| Atomistix ToolKit 11.2.2 [Build 3069]                                        |
|                                                                              |
+------------------------------------------------------------------------------+
[array([-8., -6., -4., -2.,  0.,  0.,  2.,  4.,  6.,  8.]), array([-8., -6., -4., -2.,  0.,  0.,  0.,  2.,  4.,  6.,  8.]), array([-8., -6., -4., -2.,  0.,  2.,  4.,  6.,  8.]), array([-8., -6., -4., -2.,  0.,  0.,  2.,  4.,  6.,  8.]), array([-8., -6., -4., -2.,  0.,  2.,  4.,  6.,  8.])]
Traceback (most recent call last):
  File "c:\users\bhushan\appdata\local\temp\4304438298526839.py", line 25, in <module>
    voltage_list = numpy.array(voltage_list)
ValueError: setting an array element with a sequence.
NanoLanguageScript execution failure
+------------------------------------------------------------------------------+
| NanoLanguageScript execution finished                                        |
+------------------------------------------------------------------------------+
 
Title: Re: single electron transistor: setting an array element with a sequenc
Post by: Shan on July 13, 2012, 22:56
here is the code for charge stability diagram. this is the last script in Benzene SET manual.
Title: Re: single electron transistor: setting an array element with a sequenc
Post by: Anders Blom on July 13, 2012, 23:18
I was half expecting this... It is caused by the fact that in some of the NC files you have 1 or 2 (but different amount in the different files!) TotalEnergy objects without the proper object id. As I understand it, these are the values for zero gate voltage. It's a weakness of the scripts in the tutorial, in a sense, but basically it's just not designed to be run twice.

Since it's a bit hard to delete stuff in a NetCDF file (it's possible only by copying the file to a new one, and including only what you want), the solution will have to be to somehow ignore the extra data...

Try the attached version instead. Since I don't have test data, I can't verify it myself.
Title: Re: single electron transistor: setting an array element with a sequenc
Post by: Shan on July 13, 2012, 23:40
Yes , Anders the code you posted worked.i got the plot. manual practice is completed. now i will go onto my ideas.
Thank you very very very much.
thank you again Anders sir.

Regards..
Bhushan