1

I am trying to plot DOS (density of states) with pymatgen but I can't make it work. First time encountering self and class functions in python so I am at a loss.

This link explains the package that has the function I need (I need to use get_site_t2g_eg_resolved_dos(site) part of the class CompleteDos ). This link has the source code for those functions. Looking at the examples found online I have made this code

from pymatgen.electronic_structure.dos import CompleteDos
from pymatgen.electronic_structure.plotter import DosPlotter
from pymatgen.electronic_structure.core import Spin, Orbital

data = CompleteDos.get_site_t2g_eg_resolved_dos
plot = DosPlotter(data)
plot.get_plot(-5,5).show()

That code returns an error and I am sure it's because the function get_site_t2g_eg_resolved_dos is not used correctly.

Even if you don't know pymatgen with the links provided I think you could help me in the proper way of using the functions, I'd highly appreciate it. Thanks in advance!


Edit: How the code I am trying looks like now, leave both because I am not sure if I am doing things correctly.

from pymatgen.electronic_structure.dos import CompleteDos
from pymatgen.electronic_structure.plotter import DosPlotter
from pymatgen.electronic_structure.core import Spin, Orbital
from pymatgen.io.vasp.outputs import Vasprun, Procar
from pymatgen.core.ion import Ion

vasprun = Vasprun("./vasprun.xml")

pdos = vasprun.pdos
tdos = vasprun.tdos
efermi = vasprun.efermi
energy = vasprun.eigenvalues
structure = vasprun.structures



a = CompleteDos(structure, tdos, pdos)
data = a.get_site_t2g_eg_resolved_dos(structure)
plot = DosPlotter(data)
plot.get_plot().show()

Error in output:

Traceback (most recent call last):
  File "t2g2g.py", line 21, in <module>
    data= a.get_site_t2g_eg_resolved_dos(structure)
  File "/usr/local/lib/python2.7/dist-packages/pymatgen/electronic_structure/dos.py", line 351, in get_site_t2g_eg_resolved_dos
    for s, atom_dos in self.pdos.items():
AttributeError: 'list' object has no attribute 'items'
M.O.
  • 476
  • 7
  • 19
  • The source code you reference says about the CompleteDos class: "You are unlikely to try to generate this object manually.". That does not mean you can omit object creation (as you have), but it means that unless you know what you're doing, you probably shouldn't use it in the first place. Further, since you are not calling the get_site_[...] function, but assigning it to a variable, I'm guessing you're not very familiar with python or programming to start. You may want to handle that first. – jonaslb Feb 21 '17 at 21:16
  • I am not familiar with `classes` or `self` but very familiar with numpy and matplotlib, and that's why I am asking for help. Pymatgen has everything done, I am not trying to create a code just trying to use an already existing one. I just don't know how to call the functions for python to use and can't find anywhere online to explain it simply. – M.O. Feb 21 '17 at 21:45

1 Answers1

2

If you haven't given up here is the solution

from pymatgen.electronic_structure.dos import CompleteDos
from pymatgen.electronic_structure.plotter import DosPlotter
from pymatgen.electronic_structure.core import Spin, Orbital
from pymatgen.io.vasp.outputs import Vasprun, Procar
from pymatgen.core.ion import Ion

vasprun = Vasprun("./vasprun.xml")

pdos = vasprun.pdos
tdos = vasprun.tdos
efermi = vasprun.efermi
energy = vasprun.eigenvalues
structure = vasprun.structures




data = vasprun.complete_dos.get_site_t2g_eg_resolved_dos(vasprun.structures[0][0])
plot = DosPlotter()
plot.add_dos("t2g",data['t2g'])

plot.show()

You need to specify the site and mode (t2g/eg) in order to plot.

IHaveAProblem
  • 43
  • 1
  • 9