QuantumATK Forum

QuantumATK => General Questions and Answers => Topic started by: MariaWJ on July 28, 2021, 15:15

Title: Error in tutorial - unable to convert unit
Post by: MariaWJ on July 28, 2021, 15:15
Hi there smart people. I am very new to QantumATK and not the master coder (so please dummy stuff down).  I have attempted to follow a tutorial from QATK's own webpage (https://docs.quantumatk.com/tutorials/atomic-scale_capacitance/atomic-scale_capacitance.html) but get an error when trying to run the electrostatic energy analysis to get the potential plot. I get an error saying "Unable to convert unit value V to an incompatible unit eV".

I have attached the python file I try to run and the error message as an text file. But again I am just following the tutorial and using their files.

Please can anyone help with a hopefully simple fix, is there maybe just a line I can add to convert the unit or ?
Title: Re: Error in tutorial - unable to convert unit
Post by: Anders Blom on July 29, 2021, 09:01
Sorry about the typo. Since the tutorial was published we changed the definition of the ElectrostaticDifferencePotential class to be specified in V, not eV, as is appropriate for a "potential".

Thus, all you need to do is change line 51 (which the error message complains about) to

vv = -v_z[index].inUnitsOf(V)

There was also a sign change involved, I recall, hence the leading minus sign.
Title: Re: Error in tutorial - unable to convert unit
Post by: MariaWJ on July 29, 2021, 09:37
Hi there,

I did assume that was some part of it so I have tried to just change out the unit in line 51 (did not know about the change of sign). I now ran the script again with the change you suggested and it now says "NameError: name 'V' is not defined".

I then went ahead and tried out "Volt" as that clearly is used before, but that leaves a nasty error message too (which I have attached)

Do you know what is going wrong here? If it helps, then I am pretty sure I am running the 2020 version.

So far thank you :)
Title: Re: Error in tutorial - unable to convert unit
Post by: filipr on July 29, 2021, 12:23
The output is bloated with SLURM messages, however the important part is the error message:

Code
Traceback (most recent call last):
  File "potential_plot.py", line 70, in <module>
    axarr[1].plot(z.inUnitsOf(Ang), v_z.inUnitsOf(eV))
  File "zipdir/NL/CommonConcepts/PhysicalQuantity.py", line 2173, in inUnitsOf
NL.ComputerScienceUtilities.Exceptions.NLValueError: Unable to convert unit value V to an incompatible unit eV.

So I guess you still have to use volts for the potential v_z, i.e. change line 70 in your script to:

Code
axarr[1].plot(z.inUnitsOf(Ang), v_z.inUnitsOf(Volt))
Title: Re: Error in tutorial - unable to convert unit
Post by: MariaWJ on July 29, 2021, 12:53
Oh my... IT WORKED!

Thank you so much for the help, it is very appreciated :)
Now I will continue the tutorial, hopefully without more trouble (fingers crossed).
Title: Re: Error in tutorial - unable to convert unit
Post by: Anders Blom on July 30, 2021, 00:01
Sorry for not catching these basic things, I should have checked more carefully Volt of course, and thank Filip for the plotting part - I thought we converted the unit once only.