Author Topic: Why "numpy.ndarray" object has no attribute 'inUnitsOf'  (Read 6661 times)

0 Members and 1 Guest are viewing this topic.

Offline hejun8035

  • Heavy QuantumATK user
  • ***
  • Posts: 47
  • Reputation: 0
    • View Profile
Hello,everyone!
     I meet a probem when i plan to improve the accuracy of transimssion coefficient .
the error is that

Offline hejun8035

  • Heavy QuantumATK user
  • ***
  • Posts: 47
  • Reputation: 0
    • View Profile
Re: Why "numpy.ndarray" object has no attribute 'inUnitsOf'
« Reply #1 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 )                             

Offline Anders Blom

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 5576
  • Country: dk
  • Reputation: 96
    • View Profile
    • QuantumATK at Synopsys
Re: Why "numpy.ndarray" object has no attribute 'inUnitsOf'
« Reply #2 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] )      
« Last Edit: March 4, 2011, 11:32 by Anders Blom »

Offline Anders Blom

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 5576
  • Country: dk
  • Reputation: 96
    • View Profile
    • QuantumATK at Synopsys
Re: Why "numpy.ndarray" object has no attribute 'inUnitsOf'
« Reply #3 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!

Offline hejun8035

  • Heavy QuantumATK user
  • ***
  • Posts: 47
  • Reputation: 0
    • View Profile
Re: Why "numpy.ndarray" object has no attribute 'inUnitsOf'
« Reply #4 on: March 4, 2011, 11:26 »
I have completed the calculations, but there is no data in output file,why?

Offline Anders Blom

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 5576
  • Country: dk
  • Reputation: 96
    • View Profile
    • QuantumATK at Synopsys
Re: Why "numpy.ndarray" object has no attribute 'inUnitsOf'
« Reply #5 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.

Offline hejun8035

  • Heavy QuantumATK user
  • ***
  • Posts: 47
  • Reputation: 0
    • View Profile
Re: Why "numpy.ndarray" object has no attribute 'inUnitsOf'
« Reply #6 on: March 4, 2011, 14:07 »
It's ok now, thank you very much!