materialsproject / pymatgen

Python Materials Genomics (pymatgen) is a robust materials analysis code that defines classes for structures and molecules with support for many electronic structure codes. It powers the Materials Project.
https://pymatgen.org
Other
1.52k stars 868 forks source link

VASP KPOINTS file with Line_mode #79

Closed gVallverdu closed 10 years ago

gVallverdu commented 10 years ago

Hi ! I am new in pymatgen and I try to use it to produce KPOINTS file for band structure calculations with VASP. I use HighSymmKpath and Kpoints classes to produces the kpoints file.

Here is the source code

import pymatgen as mg
from pymatgen.symmetry.bandstructure import HighSymmKpath
from pymatgen.io.vaspio.vasp_input import Kpoints

struct = mg.read_structure("POSCAR.vasp")

# First brillouin zone
ibz = HighSymmKpath(struct)
print("ibz type     : {0}".format(ibz.name))

# suggested path
print("paths in first brillouin zone :")
for path in ibz.kpath["path"]:
    print(path)

kpoints = list()
labels = list()
for path in ibz.kpath["path"]:
    for kpts in path:
        kpoints.append(ibz.kpath["kpoints"][kpts])
        labels.append(kpts)

# print kpoints file
Kpoints(comment = "band diagram for monoclinic cell, unique axes a",
        num_kpts = 100,
        style = Kpoints.supported_modes.Line_mode,
        coord_type = "Reciprocal",
        kpts = kpoints,
        labels = labels,
        ).write_file("KPOINTS")

And this is the KPOINTS file produced

band diagram for monoclinic cell, unique axes a
100
Line_mode
0.0 0.0 0.0            ! \Gamma
0.0 0.0 0.5            ! Y
0.0 0.491941 0.525184  ! H
0.0 0.5 0.5            ! C
0.5 0.5 0.5            ! E
0.5 0.508059 0.474816  ! M_1
0.5 0.5 0.0            ! A
0.0 0.5 0.0            ! X
0.0 0.508059 0.474816  ! H_1
0.5 0.491941 0.525184  ! M
0.5 0.0 0.5            ! D
0.5 0.0 0.0            ! Z
0.0 0.0 0.5            ! Y
0.5 0.0 0.5            ! D

After the line Line_mode in the KPOINTS file, the coord_type should be written.

Looking at

http://pymatgen.org/_modules/pymatgen/io/vaspio/vasp_input.html#Kpoints

in the __str__ method there is these lines

style = self.style.lower()[0]
        if style == "Line-mode":
            lines.append(self.coord_type)

but line_mode is not written with an underscore as in the supported mode enum and I think this is the bug (or maybe the mistake for only one character ...)

supported_modes = Enum(("Gamma", "Monkhorst", "Automatic", "Line_mode",
                            "Cartesian", "Reciprocal"))

The following is maybe a request more than a bug. Using VASP, in Line_mode the KPOINTS file should be

band diagram for monoclinic cell, unique axes a
100
Line_mode
Reciprocal
0.0 0.0 0.0            ! \Gamma
0.0 0.0 0.5            ! Y

0.0 0.0 0.5            ! Y
0.0 0.491941 0.525184  ! H

0.0 0.491941 0.525184  ! H
0.0 0.5 0.5            ! C

0.0 0.5 0.5            ! C
0.5 0.5 0.5            ! E

0.5 0.5 0.5            ! E
0.5 0.508059 0.474816  ! M_1

0.5 0.508059 0.474816  ! M_1
0.5 0.5 0.0            ! A

0.5 0.5 0.0            ! A
0.0 0.5 0.0            ! X

0.0 0.5 0.0            ! X
0.0 0.508059 0.474816  ! H_1

0.5 0.491941 0.525184  ! M
0.5 0.0 0.5            ! D

0.5 0.0 0.5            ! D
0.5 0.0 0.0            ! Z

0.0 0.0 0.5            ! Y
0.5 0.0 0.5            ! D

I have ever talk about the line with "Reciprocal". Then each line of the reciprocal space is defined by 2 k-points separated by a blank line. Is there a way to obtain this directly from pymatgen without postprocessing the KPOITNS file ? A solution migth be to give the kpath attribute of the HighSymmKpath to a Kpoints class constructor or directely the HighSymmKpath object. But the __str__ method must be also slithly modified. I cloned the git repository and did the few changes. Here is a patch file created with git diff > patch.txt

www.pastebin.com/5n6aniLv

I am sorry but I am a beginner with git. I do not know how to make the development version and the stable version of pymatgen to cohabit in the same PC. Thus I did not test my changes ... If you prefer and explain I can commit and push somewhere ?

Thanks

shyuep commented 10 years ago

Hi Germain,

Thanks for reporting the issue. I have applied your fix and contributions.

As for the line-mode, I know that VASP uses Line-mode. But because of the way the Enum design pattern works, I can't use "-" in the class. In any case, VASP does not actually look for "Line-mode". They only look at the first letter of that line.

Regarding having pymatgen dev and stable versions on the same machine, one possibility is to use virtualenv. Another way is to simply fork the repo to your own Github repo and you can always work off your own fork of pymatgen. When you have some contributions that you would like to share with the community, you can submit a pull request and I can add them.

ok030320 commented 10 years ago

hi, i am new to vasp, and ran into this article http://gvallver.perso.univ-pau.fr/?p=587 it is very helpful for me, and i applied to a ge-bulk system as an example to learn band structure (L-G-X) there is an error when i get to the point of get_band_structure, and i narrowed down the error in pymatgen/electronic_structure/bandstructure.py class BandStructureSymmLine(BandStructure, MSONable): ...... self._branches.append({"start_index": b[0], "end_index": b[-1], "name": (self._kpoints[b[0]].label + "-" + self._kpoints[b[-1]].label)}) .....

and, here for my system, i have tried to None+"-" (a NoneType and a string) ----error msg-------------------------- pymatgen/electronic_structure/bandstructure.py", line 741, in init "name": (self._kpoints[b[0]].label + "-" +

TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'

so, i changed to self._branches.append({"start_index": b[0], "end_index": b[-1], "name": (str(self._kpoints[b[0]].label) + "-" + str(self._kpoints[b[-1]].label))}) and it worked. is this a bug?

hautierg commented 10 years ago

Hi,

Thanks for your report. Could you send me your vasp files? Send them to me to geoffroy.hautier@uclouvain.be . We'll take it from there.

hautierg commented 10 years ago

I have looked into the files you sent. Your KPOINTS file does not have label for each kpoint. this is mandatory for a band structure along symmetry lines.

It is: K-points L-G-X 25 Line-mode reciprocal 0.5 0.5 0.5 0 0 0

0 0 0 0.5 0.5 0

While it should be:

K-points L-G-X 25 Line-mode reciprocal 0.5 0.5 0.5 L 0 0 0 G

0 0 0 G 0.5 0.5 0 X

I have applied a patch so a clearer exception is now raised when this happens.

Geoffroy