Surface Science and Solid State Theory Laboratory

@surface


From NetCDF to DOS

Posted on 11月 10, 2009 by kimi
1
2
#!/usr/bin/env python
from optparse import OptionParser
1
2
from Dacapo import Dacapo
from ASE.Utilities.DOS import DOS
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
cmd = OptionParser(usage = '%prog [-r] input_nc_file output_text_file')
cmd.add_option('-r', '--reverse', action = "store_true", default = False,
help = 'reverse out put for minor spin states')
(opt, argv) = cmd.parse_args()

if len(argv) != 2:
  cmd.print_help()
  raise SystemExit

  ncfile = argv[0]
  textfile = argv[1]
  sfmt0 = '%-15s %-15s\n'
  sfmt1 = '%-15s %-15s %-15s %-15s\n'
  efmt0 = '%15.7E %15.7E\n'
  efmt1 = '%15.7E %15.7E %15.7E %15.7E\n'
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
  atoms = Dacapo.ReadAtoms(ncfile)
  calc = atoms.GetCalculator()
  isSpinPolarized = calc.GetSpinPolarized()
  dos = DOS(calc)
  x0 = dos.GetEnergies()
  if isSpinPolarized:
    y0 = dos.GetDOS(0)
    y1 = dos.GetDOS(1)
    fp = open(textfile, 'w')
    if opt.reverse:
      fp.write(sfmt1 % ('Energy', 'DOS0', 'DOS1', 'DIFF'))
    else:
      fp.write(sfmt1 % ('Energy', 'DOS0', 'DOS1', 'TOTAL'))
      for i in range(len(x0)):
        if opt.reverse:
          fp.write(efmt1 % (x0[i], y0[i], -y1[i], y0[i] - y1[i]))
        else:
          fp.write(efmt1 % (x0[i], y0[i],  y1[i], y0[i] + y1[i]))
      fp.close()
  else:
    y0 = dos.GetDOS(0)
    fp = open(textfile, 'w')
    fp.write(sfmt0 % ('Energy', 'DOS'))
    for i in range(len(x0)):
      fp.write(efmt0 % (x0[i], y0[i]))
    fp.close()

Comments are closed.




↑ Top