QuantumATK Forum

QuantumATK => General Questions and Answers => Topic started by: Hasan Sahin on December 1, 2009, 12:30

Title: How to recalculate data from nc file with float
Post by: Hasan Sahin 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.
Title: Re: How to recalculate data from nc file with float
Post by: Anders Blom 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)
    ...
Title: Re: How to recalculate data from nc file with float
Post by: Hasan Sahin on December 1, 2009, 13:11
Thank you for your time Anders...
Title: Re: How to recalculate data from nc file with float
Post by: Hasan Sahin 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.
Title: Re: How to recalculate data from nc file with float
Post by: Anders Blom 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.

Title: Re: How to recalculate data from nc file with float
Post by: Hasan Sahin 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
Title: Re: How to recalculate data from nc file with float
Post by: Anders Blom 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.