QuantumATK Forum

QuantumATK => General Questions and Answers => Topic started by: hejun8035 on March 4, 2011, 08:37

Title: Why "numpy.ndarray" object has no attribute 'inUnitsOf'
Post by: hejun8035 on March 4, 2011, 08:37
Hello,everyone!
     I meet a probem when i plan to improve the accuracy of transimssion coefficient .
the error is that(http://)
Title: Re: Why "numpy.ndarray" object has no attribute 'inUnitsOf'
Post by: hejun8035 on March 4, 2011, 08:39

My script is that:

######################################################################                   
# Calculate physical properties                                                           
######################################################################                   
from numpy import arange                                                                 
import numpy                                                                             
transmission_spectrum = calculateTransmissionSpectrum(                                   
    self_consistent_calculation = scf,                                                   
    energies = numpy.arange(-2.0, 2.0+0.001, 0.01)*electronVolt,                         
    brillouin_zone_integration_parameters = brillouinZoneIntegrationParameters((1, 1)),   
    green_function_infinitesimal = 1.0e-5*electronVolt                                   
)                                                                                         
                                                                                         
energies = transmission_spectrum.energies()                                               
coefficients = transmission_spectrum.coefficients()                                       
print 'Energy (eV)     Transmission'                                                     
print '-----------------------------------'                                               
for i in range(len(energies)):                                                           
    print "%g\t%g" % ( energies.inUnitsOf(eV),coefficients )                             
Title: Re: Why "numpy.ndarray" object has no attribute 'inUnitsOf'
Post by: Anders Blom on March 4, 2011, 10:01
You may be confused because ATK 10.8 and 2008.10 use slightly different ways to handle units. The script you show is valid for 2008.10 - until the point you ask for energies.inUnitsOf(), which could work in 10.8, but not in 2008.10.

However, you don't really want to have the whole list of energies inside the loop, you just want one value. So you should instead use

Code: python
for j in range(len(energies)):                                                           
    print "%g\t%g" % ( energies[j].inUnitsOf(eV),coefficients[j] )      
Title: Re: Why "numpy.ndarray" object has no attribute 'inUnitsOf'
Post by: Anders Blom on March 4, 2011, 10:05
I now see what causes problems!!! In my script posted at http://quantumwise.com/forum/index.php?topic=103.msg494#msg494 I actually have energies[j] - but I used i instead of j, which this webpage interprets as ITALIC text!

So the lesson is: don't use "i" as an index variable in code posted on the Forum!
Title: Re: Why "numpy.ndarray" object has no attribute 'inUnitsOf'
Post by: hejun8035 on March 4, 2011, 11:26
I have completed the calculations, but there is no data in output file,why?
Title: Re: Why "numpy.ndarray" object has no attribute 'inUnitsOf'
Post by: Anders Blom on March 4, 2011, 11:30
Which output file? It's kind of impossible to help without seeing the scripts and all the full details of how you run, command line, etc. Please post all information.
Title: Re: Why "numpy.ndarray" object has no attribute 'inUnitsOf'
Post by: hejun8035 on March 4, 2011, 14:07
It's ok now, thank you very much!