Author Topic: How to recalculate data from nc file with float  (Read 6500 times)

0 Members and 1 Guest are viewing this topic.

Offline Hasan Sahin

  • Heavy QuantumATK user
  • ***
  • Posts: 44
  • Reputation: 0
    • View Profile
How to recalculate data from nc file with float
« on: December 1, 2009, 12:30 »
Hello,

I want to read datas from nc files named as ,for example,  a1.5.nc, a1.6.nc, a1.7.nc, a1.8.nc, a1.9.nc,

How can I restore these scf calcualtions for reading datas with float command.

Offline Anders Blom

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 5576
  • Country: dk
  • Reputation: 96
    • View Profile
    • QuantumATK at Synopsys
Re: How to recalculate data from nc file with float
« Reply #1 on: December 1, 2009, 13:08 »
There are several ways. If you have a sequence of files, then look how you generated the sequence in the first place, probably you used some numpy.arange or numpy.linspace() command. Then use the same command to re-generate the names. If you just have 4-5 files, it's also easy to just do a list
Code
for i in [1.5, 1.6, 1.7, 1.8, 1.9]:
    scf = restoreSelfConsistentCalculation("a%g.nc" % i)
    ...
For your example, probably this would be better:
Code
import numpy
for i in numpy.arange(1.5,1.91,0.1):
    scf = restoreSelfConsistentCalculation("a%g.nc" % i)
    ...
« Last Edit: December 1, 2009, 13:09 by Anders Blom »

Offline Hasan Sahin

  • Heavy QuantumATK user
  • ***
  • Posts: 44
  • Reputation: 0
    • View Profile
Re: How to recalculate data from nc file with float
« Reply #2 on: December 1, 2009, 13:11 »
Thank you for your time Anders...

Offline Hasan Sahin

  • Heavy QuantumATK user
  • ***
  • Posts: 44
  • Reputation: 0
    • View Profile
Re: How to recalculate data from nc file with float
« Reply #3 on: December 1, 2009, 13:43 »
BAD NEWS...

scf = restoreSelfConsistentCalculation("a%g.nc" % i)
NLValueError: Invalid NetCDFFile.
Traceback (most recent call last):
  File "<string>", line 12, in ?
NLValueError: Invalid NetCDFFile.

Offline Anders Blom

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 5576
  • Country: dk
  • Reputation: 96
    • View Profile
    • QuantumATK at Synopsys
Re: How to recalculate data from nc file with float
« Reply #4 on: December 1, 2009, 13:45 »
It's hard to know, but actually "Invalid NetCDFFile" can mean "file not found". My example only works if the files are in the same directory as you run ATK from. If you are running from VNL's Job Manager, you also need to specify the full path. For trouble-shooting, you may also want to add
Code
print "a%g.nc" % i
before the "scf=" statement. Also, if these are you exact filenames in this case, a slightly safer version is ("a%.1f.nc" % i) to avoid 1.5 becoming 1.50.
« Last Edit: December 1, 2009, 13:47 by Anders Blom »

Offline Hasan Sahin

  • Heavy QuantumATK user
  • ***
  • Posts: 44
  • Reputation: 0
    • View Profile
Re: How to recalculate data from nc file with float
« Reply #5 on: December 1, 2009, 14:32 »
It is ok now... following script works :)


from ATK.MPI import processIsMaster

import numpy


for i in numpy.arange(0.00, 1.01, 0.01):
   
    energy=calculateTotalEnergy(restoreSelfConsistentCalculation("21-%.2f.nc" % i)).inUnitsOf(eV)   
    if processIsMaster(): print 'TOTALENERGY', i, energy

Offline Anders Blom

  • QuantumATK Staff
  • Supreme QuantumATK Wizard
  • *****
  • Posts: 5576
  • Country: dk
  • Reputation: 96
    • View Profile
    • QuantumATK at Synopsys
Re: How to recalculate data from nc file with float
« Reply #6 on: December 1, 2009, 14:38 »
Right, my example was naturally based on your specification of your NetCDF files being named "a1.5.nc" etc :)

Note that arange() has a peculiarity to sometimes include the last element in the list and sometimes not. See http://quantumwise.com/forum/index.php?topic=110.0. So, in your case, arange(0.00, 1.01, 0.01) might include the point 1.01, and might not. A safer bet is arange(0.00, 1.001, 0.01) if you don't want 1.01, and arange(0.00, 1.011, 0.01) if you do.