QuantumATK Forum

QuantumATK => General Questions and Answers => Topic started by: qiuweicheng on July 6, 2017, 02:55

Title: Are there any questions in this py files?
Post by: qiuweicheng on July 6, 2017, 02:55
I get two py files:
The first: the set calculator is the same with that of BN-AP-0.3.nc
device_configuration = nlread('BN-AP-0.3.nc', DeviceConfiguration)[0]
calculator = device_configuration.calculator()
bias = 0.5*Volt
# -------------------------------------------------------------
# Initial State
# -------------------------------------------------------------
initial_spin = InitialSpin(scaled_spins=[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0])
calculator=calculator(
     electrode_voltages=(bias/2, -bias/2))
device_configuration.setCalculator(
     calculator(),
     initial_spin=initial_spin,
     initial_state=device_configuration
     )
device_configuration.update()
nlsave('BN-AP-%.1f.nc' % bias.inUnitsOf(Volt), device_configuration)
# Calculate the transmission
t = TransmissionSpectrum(
    configuration= device_configuration,
    energies = numpy.linspace(-2,2,201)*eV,
    kpoints=MonkhorstPackGrid(30,30),
    energy_zero_parameter=AverageFermiLevel,
    infinitesimal=1e-06*eV,
    self_energy_calculator=RecursionSelfEnergy(),
     ) 
nlsave('BN-AP-%.1f.nc' % bias.inUnitsOf(Volt), t)
nlprint(t)
nlprint("%8.6e %8.6e %8.6e" %(t.bias(), t.current(), t.bias()/t.current())+'\n'),
 
The second: I put BN-AP-0.3.nc into the scripter, and change the initial set.
......
......
#----------------------------------------
# Electrode Calculators
#----------------------------------------
left_electrode_calculator = LCAOCalculator(
    exchange_correlation=exchange_correlation,
    numerical_accuracy_parameters=left_electrode_numerical_accuracy_parameters,
    poisson_solver=left_electrode_poisson_solver,
    )

right_electrode_calculator = LCAOCalculator(
    exchange_correlation=exchange_correlation,
    numerical_accuracy_parameters=right_electrode_numerical_accuracy_parameters,
    poisson_solver=right_electrode_poisson_solver,
    )

#----------------------------------------
# Device Calculator
#----------------------------------------
calculator = DeviceLCAOCalculator(
    exchange_correlation=exchange_correlation,
    numerical_accuracy_parameters=device_numerical_accuracy_parameters,
    electrode_calculators=
        [left_electrode_calculator, right_electrode_calculator],
    electrode_voltages=( 0.2*Volt, -0.2*Volt)
    )

device_configuration.setCalculator(calculator)

# -------------------------------------------------------------
# Initial State
# -------------------------------------------------------------
initial_spin = InitialSpin(scaled_spins=[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0])
old_calculation = nlread('BN-AP-0.3.nc', DeviceConfiguration)[0]
device_configuration.setCalculator(
    calculator,
    initial_spin=initial_spin,
    initial_state=old_calculation,
)
device_configuration.update()
nlsave('BN-AP-0.4.nc', device_configuration)
nlprint(device_configuration)

My question:
1. The set calculator is the same with that of BN-AP-0.3.nc. Are there any difference between two py files?
2. Are there any command problem with the first py file?
Title: Re: Are there any questions in this py files?
Post by: Ulrik G. Vej-Hansen on July 7, 2017, 13:51
I am afraid that I do not understand your question. What are you trying to do, and what is the problem in doing it?
Title: Re: Are there any questions in this py files?
Post by: qiuweicheng on July 7, 2017, 14:49
We can do the calculation using the  existing result (BN-AP-0.3.nc).
But, There are two ways to use existing results.
The question is:
The first way is right?
Title: Re: Are there any questions in this py files?
Post by: Petr Khomyakov on July 8, 2017, 23:31
You may use the Initial State in the VNL to start the calculation from a converged solution (old calculation), see http://docs.quantumwise.com/tutorials/initialize_from_a_converged_state/initialize_from_a_converged_state.html.
Title: Re: Are there any questions in this py files?
Post by: qiuweicheng on July 9, 2017, 03:10
Yes, I know this tutorials by using  use the Initial State in the VNL to start the calculation from a converged solution (old calculation).  that's completely consistent with the second py file.
and the first py file also uses  use the Initial State in the VNL to start the calculation from a converged solution.
But, in the calculation, the calculation is  convergence by using the first py file.
however, the  calculation is  not convergence by using the second py file.
So, I want to verify that the first py file  are correct?
Why the situation of convergence is different?


Title: Re: Are there any questions in this py files?
Post by: Petr Khomyakov on July 10, 2017, 09:00
It is not clear what are the calculator settings in the first script. Also, the bias voltage values specified in the two scripts are different.
Title: Re: Are there any questions in this py files?
Post by: qiuweicheng on July 10, 2017, 09:25
In the first py file, we set the calculator = device_configuration.calculator() by using the calculator of ('BN-AP-0.3.nc', DeviceConfiguration)
The calculator is set the same with that of  ('BN-AP-0.3.nc', DeviceConfiguration).
Is this  py command  "calculator = device_configuration.calculator() " set right?
by the way , the calculator set in the second py file is also copyed from the BN-AP-0.3.py.
Except from the bias, are there any difference in the device calculation set between two py files?
Title: Re: Are there any questions in this py files?
Post by: Daniele Stradi on July 13, 2017, 16:33
I do not think it is necessary to set again the initial spin, unless you want to change both the initial spin and the voltage at the same time (which is something I strongly discourage).

If your target is to restart a calculation from a previously converged DeviceConfiguration and change the bias voltage, the script can be as simple as:

bias = 0.5*Volt
device_configuration = nlread('BN-AP-0.3.nc', DeviceConfiguration)[-1]
calculator = device_configuration.calculator()
calculator=calculator(electrode_voltages=(bias/2, -bias/2))
device_configuration.setCalculator(
      calculator(),
      initial_state=device_configuration)
device_configuration.update()
nlsave('output.nc', device_configuration)
Title: Re: Are there any questions in this py files?
Post by: qiuweicheng on July 19, 2017, 14:26
Thank you for your reply. But, you set the device_configuration = nlread('BN-AP-0.3.nc', DeviceConfiguration)[-1]? I think it  should be device_configuration = nlread('BN-AP-0.3.nc', DeviceConfiguration)[0]
Or what is the difference between ('BN-AP-0.3.nc', DeviceConfiguration)[-1] and ('BN-AP-0.3.nc', DeviceConfiguration)[0]?
Title: Re: Are there any questions in this py files?
Post by: Daniele Stradi on July 19, 2017, 14:58
It is just that in Python one can choose to read a list from the beginning, or from the end  :)

('BN-AP-0.3.nc', DeviceConfiguration)[0] : if you have N DeviceConfiguration objects, it takes the first one (with index = 0)
('BN-AP-0.3.nc', DeviceConfiguration)[-1] : if you have N DeviceConfiguration objects, it takes the last one (with index = N-1)