Author Topic: NameError: name 'zero_bias_potential' is not defined  (Read 6618 times)

0 Members and 1 Guest are viewing this topic.

Offline yfchang

  • Regular QuantumATK user
  • **
  • Posts: 18
  • Country: cn
  • Reputation: 0
    • View Profile
NameError: name 'zero_bias_potential' is not defined
« on: December 19, 2011, 06:42 »
Hello, I am Ying-fei Chang from Northeast Normal University, P. R. China.
I had some trouble with the calculation of the trasmission spectrum and voltage drop, the error information is:

Traceback (most recent call last):
  File "c:\users\changyf\appdata\local\temp\9960269774839752.py", line 34, in <module>
    voltage_drop = potential - zero_bias_potential
NameError: name 'zero_bias_potential' is not defined
NanoLanguageScript execution failure.

I read the topic about http://quantumwise.com/forum/index.php?topic=1363.0, and added

biases = [float(conf.calculator().electrodeVoltages()[1]-conf.calculator().electrodeVoltages()[0]) for conf in configurations]
configurations = [configurations for i in numpy.argsort(biases)]

in my script, but it do not work yet.

I think  the defining of  "zero_bias_potential" in the input scripis is needed to be modified. Since the first calculated in not for 0V, the program can not get the  "zero_bias_potential", so it failured.

If I save the IV_SCF configurations in separate files by using the Script like

nlsave("1FS_1_IV_SCF_%g.nc" % voltage.inUnitsOf(Volt), device_configuration)

from the Tutorial, and add the following line in front of the analysis file

for voltage in [0.,0.5,1.,1.5,2.,2.5,3.,3.5,4.,4.5,5.]*Volt:
    scf_filename = ('1FS_1_IV_SCF_%g.nc' % voltage)
    analysis_filename = "1FS_1_IV_analysis.nc"

It can work, but the result is not correct, because the current from -5V to 4V is almost 0.
I think the bias maybe incorrect.

So, I hope someone to tell me how to calculate the trasmission spectrum and voltage drop form one IV_SCF file or in separate files.

The following it my modefied script.

for voltage in [0.,0.5,1.,1.5,2.,2.5,3.,3.5,4.,4.5,5.]*Volt:
    scf_filename = ('1FS_1_IV_SCF_%g.nc' % voltage)
    analysis_filename = "1FS_1_IV_analysis.nc"

    # Read all configurations from NetCDF file
    configurations = nlread(scf_filename, DeviceConfiguration)
    biases = [float(conf.calculator().electrodeVoltages()[1]-conf.calculator().electrodeVoltages()[0]) for conf in configurations]
    configurations = [configurations for i in numpy.argsort(biases)]

    for configuration in configurations:

        # For each one, extract the bias,
        calculator = configuration.calculator()
        bias = calculator.electrodeVoltages()[1]-calculator.electrodeVoltages()[0]

        # ... calculate and save the transmission spectrum,
        transmission_spectrum = TransmissionSpectrum(
            configuration=configuration,
            energies=numpy.linspace(-4,4,100)*eV,
            kpoints=MonkhorstPackGrid(1,1,1)
        )
        nlsave(analysis_filename, transmission_spectrum, object_id="Transmission %s" % bias)
        # Uncomment the line below if you want all transmission spectra in the log file
        #nlprint(transmission_spectrum)
       
        potential = EffectivePotential(configuration)
                   
        # Uncomment the line below if you want to save all potentials, and not just the voltage drops
        #nlsave(analysis_filename, potential, object_id="Potential %s" % bias)
       
        # Calculate and save the voltage drop (except for zero bias, of course)
        if float(bias)!=0.:
            voltage_drop = potential - zero_bias_potential
            nlsave(analysis_filename, voltage_drop, object_id="Voltage drop %s" % bias)
        else:
            zero_bias_potential = potential
           
    # Copy geometry to analysis file, for plotting
    zero_bias_calculation = nlread(scf_filename, DeviceConfiguration, read_state = False)[0]
    nlsave(analysis_filename, zero_bias_calculation)

Offline Anders Blom

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 5576
  • Country: dk
  • Reputation: 96
    • View Profile
    • QuantumATK at Synopsys
Re: NameError: name 'zero_bias_potential' is not defined
« Reply #1 on: December 19, 2011, 09:46 »
Your script is not correct, it's a mix of two scripts, in a sense. I suggest you take the scripts from the update tutorial at http://quantumwise.com/publications/tutorials/mini-tutorials/98, where this fix has been included.

Offline yfchang

  • Regular QuantumATK user
  • **
  • Posts: 18
  • Country: cn
  • Reputation: 0
    • View Profile
Re: NameError: name 'zero_bias_potential' is not defined
« Reply #2 on: December 19, 2011, 14:35 »
Sorry for the confused descripration. In fact, the tutorial at http://quantumwise.com/publications/tutorials/mini-tutorials/98, does not fix the problem.Here is my input script:

# Define input and output NetCDF files here
scf_filename = '1FS_1_IV_SCF.nc'
analysis_filename = "1FS_1_IV_analysis.nc"

# Read all configurations from NetCDF file
configurations = nlread(scf_filename, DeviceConfiguration)
biases = [float(conf.calculator().electrodeVoltages()[1]-conf.calculator().electrodeVoltages()[0]) for conf in configurations]
configurations = [configurations for i in numpy.argsort(biases)]

for configuration in configurations:

    # For each one, extract the bias,
    calculator = configuration.calculator()
    bias = calculator.electrodeVoltages()[1]-calculator.electrodeVoltages()[0]

    # ... calculate and save the transmission spectrum,
    transmission_spectrum = TransmissionSpectrum(
        configuration=configuration,
        energies=numpy.linspace(-4,4,100)*eV,
        kpoints=MonkhorstPackGrid(1,1,1)
    )
    nlsave(analysis_filename, transmission_spectrum, object_id="Transmission %s" % bias)
    # Uncomment the line below if you want all transmission spectra in the log file
    #nlprint(transmission_spectrum)
    
    potential = EffectivePotential(configuration)
                
    # Uncomment the line below if you want to save all potentials, and not just the voltage drops
    #nlsave(analysis_filename, potential, object_id="Potential %s" % bias)
    
    # Calculate and save the voltage drop (except for zero bias, of course)
    if float(bias)!=0.:
        voltage_drop = potential - zero_bias_potential
        nlsave(analysis_filename, voltage_drop, object_id="Voltage drop %s" % bias)
    else:
        zero_bias_potential = potential
        
# Copy geometry to analysis file, for plotting
zero_bias_calculation = nlread(scf_filename, DeviceConfiguration, read_state = False)[0]
nlsave(analysis_filename, zero_bias_calculation)


In the '1FS_1_IV_SCF.nc' file, I do a IV SCF calculation for a device form -5.0V to 5.0V, and the error information is:

Traceback (most recent call last):
  File "c:\users\changyf\appdata\local\temp\9960269774839752.py", line 34, in <module>
    voltage_drop = potential - zero_bias_potential
NameError: name 'zero_bias_potential' is not defined
NanoLanguageScript execution failure.


If we do some calculation for bias from 0V to -5.0V, or 0V to 5.0V, is OK, but it failed when the bias was from -5.0V to 5.0V. So, in my opinion,  we must do something to make the program calculate the  trasmission spectrum and voltage drop at 0V firstly, otherwise, the program can not get the  "zero_bias_potential", so it failured.

« Last Edit: December 19, 2011, 15:30 by yfchang »

Offline Anders Blom

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 5576
  • Country: dk
  • Reputation: 96
    • View Profile
    • QuantumATK at Synopsys
Re: NameError: name 'zero_bias_potential' is not defined
« Reply #3 on: December 19, 2011, 16:12 »
Ok, I see the problem. In this case it's probably best to define the zero bias potential manually. I think I will update the tutorial to do it in this way too; I didn't want to have 2 loops, but then the sorting solved the issue if the zero-bias wasn't first. But in your case it's not supposed to be first. So, I guess there's no way around the double-loop, but at least we only have to read from the NC file once anyway, plus most importantly only compute the quantities once.
Code: python
# Define input and output NetCDF files here
scf_filename = '1FS_1_IV_SCF.nc'
analysis_filename = "1FS_1_IV_analysis.nc"

# Read all configurations from NetCDF file
configurations = nlread(scf_filename, DeviceConfiguration)
biases = [float(conf.calculator().electrodeVoltages()[1]-conf.calculator().electrodeVoltages()[0]) for conf in configurations]
configurations = [configurations for i in numpy.argsort(biases)]

# First compute the zero-bias potential
for configuration in configurations:
    calculator = configuration.calculator()
    bias = calculator.electrodeVoltages()[1]-calculator.electrodeVoltages()[0]

    if float(bias)==0.:
        zero_bias_potential = EffectivePotential(configuration)
        break
        
for configuration in configurations:

    # For each one, extract the bias,
    calculator = configuration.calculator()
    bias = calculator.electrodeVoltages()[1]-calculator.electrodeVoltages()[0]

    # ... calculate and save the transmission spectrum,
    transmission_spectrum = TransmissionSpectrum(
        configuration=configuration,
        energies=numpy.linspace(-4,4,100)*eV,
        kpoints=MonkhorstPackGrid(1,1,1)
    )
    nlsave(analysis_filename, transmission_spectrum, object_id="Transmission %s" % bias)
    # Uncomment the line below if you want all transmission spectra in the log file
    #nlprint(transmission_spectrum)
    
    potential = EffectivePotential(configuration)
                
    # Uncomment the line below if you want to save all potentials, and not just the voltage drops
    #nlsave(analysis_filename, potential, object_id="Potential %s" % bias)
    
    # Calculate and save the voltage drop (except for zero bias)
    if float(bias)!=0.:
        voltage_drop = potential - zero_bias_potential
        nlsave(analysis_filename, voltage_drop, object_id="Voltage drop %s" % bias)
        
# Copy geometry to analysis file, for plotting
geometry = nlread(scf_filename, DeviceConfiguration, read_state = False)[0]
nlsave(analysis_filename, geometry)


Offline yfchang

  • Regular QuantumATK user
  • **
  • Posts: 18
  • Country: cn
  • Reputation: 0
    • View Profile
Re: NameError: name 'zero_bias_potential' is not defined
« Reply #4 on: December 20, 2011, 11:56 »
Thanks. It worked. But if I save the configurations in separate files, by using
Code
nlsave("'1FS_1_IV_SCF_%g.nc" % voltage.inUnitsOf(Volt), device_configuration)
What should I do? How can I set the script  to read the configurations back from the individual files?

Offline Anders Blom

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 5576
  • Country: dk
  • Reputation: 96
    • View Profile
    • QuantumATK at Synopsys
Re: NameError: name 'zero_bias_potential' is not defined
« Reply #5 on: December 20, 2011, 13:28 »
First of all, there is perhaps a spurious single quotation mark in your filename; not critical, just thought I'd point it out. I will assume in the following that this was a typo, i.e. your nlsave line is
Code: python
nlsave("1FS_1_IV_SCF_%g.nc" % voltage.inUnitsOf(Volt), device_configuration)
Having separate files for each bias is actually a pretty good idea, as the files can get quite large for real systems (for LiH2Li it doesn't matter). However, in this case we must also copy the bias list over to the analysis script. You only need to change the "nlread" line; or rather, change the first 6 lines to the following (i.e. keep line 7 "biases = ..." and onward from the original script):
Code: python
# Define input and output NetCDF files here  
scf_filename = "1FS_1_IV_SCF_%g.nc"
analysis_filename = "1FS_1_IV_analysis.nc"  
  
voltages = [0, 1, 2]
# Read configurations from NetCDF files
configurations = []
for voltage in voltages:
    configurations.append(nlread(scf_filename % voltage, DeviceConfiguration)[0])
You just need to supplement this with the proper "voltages" list from the I-V run script. Skip the "Volt" unit, we don't need it here. It is here assumed that each NC file contains only one DeviceConfiguration.

Offline yfchang

  • Regular QuantumATK user
  • **
  • Posts: 18
  • Country: cn
  • Reputation: 0
    • View Profile
Re: NameError: name 'zero_bias_potential' is not defined
« Reply #6 on: December 20, 2011, 15:51 »
Thank you very much. Now, it work well.
But I have another question, in the tutorial at http://quantumwise.com/publications/tutorials/mini-tutorials/98, we do a I-V SCF calculation for lih2li at [0., 0.1, 0.2, 0.3]*Volt, why the bias in I-V curve is [-0.3,-0.2,-0.1,-0.]*Volt?

Offline Anders Blom

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 5576
  • Country: dk
  • Reputation: 96
    • View Profile
    • QuantumATK at Synopsys
Re: NameError: name 'zero_bias_potential' is not defined
« Reply #7 on: December 20, 2011, 16:05 »
This system has a symmetric I-V curve, so I never noticed the script uses an opposite definition of the "bias voltage", compared to the bias() method on a TransmissionSpectrum class. I'll fix it, thanks ;) It will not change the results in this system however, only the signs.

Offline basu

  • New QuantumATK user
  • *
  • Posts: 2
  • Country: in
  • Reputation: 0
    • View Profile
Re: NameError: name 'zero_bias_potential' is not defined
« Reply #8 on: December 23, 2011, 11:01 »
i am basant , i have the same problem that i not find any resullt that i found in script generator , all the result is showing this  kind of error
can u tell me hat you sort out such kind of errors. please mail me on bsnt2008@gmail.com
plz tell me soon thank you sir

Offline Anders Blom

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 5576
  • Country: dk
  • Reputation: 96
    • View Profile
    • QuantumATK at Synopsys
Re: NameError: name 'zero_bias_potential' is not defined
« Reply #9 on: December 25, 2011, 11:47 »
Late last week I updated the mini-tutorial and made the script more robust, I think that should solve all problems.