There are two ways. Either modify the script to contain the NC filename and sample explicitly, so you don't have to enter them when you run. Or, use "write" instead of "print". I will present both, although the "write" solution is probably best; there is a complete script for that at the end!
(Btw, do you really have a star * in the file name? It's a bad idea, it might screw things up here and there; better use "4x4x100"
)
Method 1
Pipe the output to a file when you run it, like
atk extract_transmission_from_vnl_file.py > trans.dat
To modify the script for this is quite easy, just replace
filename = raw_input('Please enter VNL file name: ')
by
filename = "Au100-Au8-Au100_Transmission_4*4*100.vnl"
Then, replace
sname = raw_input('Please enter sample name to extract (default=first sample): ')
by
This only works if the sample we want is the first/only one in the file, but that is the case at hand, so we're good!
Method 2
Write a file from within the script, by replacing the "print" statements by "write" statements. This involved a few more lines to modify, so I'll just post the ready script.
import zipfile, cPickle, sys
filename = raw_input('Please enter VNL file name: ')
try:
f = zipfile.ZipFile(filename,'r')
except:
print 'Unable to locate VNL file "%s"' % filename
sys.exit(1)
# Restore the samples from the VNL file into a dict
samples = {}
for zinfo in f.infolist():
s = f.read(zinfo.filename)
try:
obj = cPickle.loads(s)
samples[obj.name()] = {}
for h in obj.history():
samples[obj.name()][h.name] = h.resultsample.properties()
except:
pass
print 'The following samples are present in this VNL file:'
print samples.keys()
sname = raw_input('Please enter sample name to extract (default=first sample): ')
if sname.strip()=="":
data = samples[samples.keys()[0]]['NanoLanguage']
else:
data = samples[sname]['NanoLanguage']
print 'The following properties are present for this sample:'
print data.keys()
# Write the transmission data to a file
f = open("trans_"+filename+"_"+sname+".dat","w")
f.write('# Energy (eV)\tTotal transmission\n')
f.write('# ----------------------------------\n')
# Some older versions used "Transmission Spectrum" or "TransmissionSpectrum"
trans = data['Transmission Spectrum']
energies = trans.energy()._dataarray_
# Check for energy unit, if you want to be sure
# e_unit = t.energy().units()
T = trans.average_transmission()
# Write the transmission data to a file
for i in range(len(energies)):
f.write('%g\t%g\n' % (energies[i],T[i]))
f.close()
Note that I use the VNL file name to label the output file, so in case you run several times, with different samples or VNL files, you will not overwrite the output files.