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.
# 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)
Thanks. It worked. But if I save the configurations in separate files, by using
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?
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
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):
# 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.