-
Notifications
You must be signed in to change notification settings - Fork 862
/
jhu.py
91 lines (77 loc) · 2.88 KB
/
jhu.py
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# coding: utf-8
# Copyright (c) Pymatgen Development Team.
# Distributed under the terms of the MIT License.
"""
This module creates an interface to the JHU kpoints servlet,
see http://muellergroup.jhu.edu/K-Points.html.
"""
import os
import shutil
import tempfile
import requests
from pymatgen.io.vasp.inputs import Kpoints
__author__ = "Joseph Montoya"
__copyright__ = "Copyright 2017, The Materials Project"
__maintainer__ = "Joseph Montoya"
__email__ = "montoyjh@lbl.gov"
__date__ = "June 22, 2017"
def get_kpoints(
structure,
min_distance=0,
min_total_kpoints=1,
kppra=None,
gap_distance=7,
remove_symmetry=None,
include_gamma="auto",
header="simple",
incar=None,
):
"""
Get kpoints object from JHU servlet, per Wisesa-McGill-Mueller
methodology. Refer to http://muellergroup.jhu.edu/K-Points.html
and P. Wisesa, K. A. McGill, T. Mueller, Phys. Rev. B 93,
155109 (2016)
Args:
structure (Structure): structure object
min_distance (float): The minimum allowed distance
between lattice points on the real-space superlattice
min_total_kpoints (int): The minimum allowed number of
total k-points in the Brillouin zone.
kppra (float): minimum k-points per reciprocal atom.
gap_distance (float): auto-detection threshold for
non-periodicity (in slabs, nanowires, etc.)
remove_symmetry (string): optional flag to control
symmetry options, can be none, structural,
time_reversal, or all
include_gamma (string or bool): whether to include
gamma point
header (string): "verbose" or "simple", denotes
the verbosity of the header
incar (Incar): incar object to upload
"""
config = locals()
config.pop("structure", "incar")
# Generate PRECALC string
precalc = "".join(["{}={}\n".format(k, v) for k, v in config.items()])
precalc = precalc.replace("_", "").upper()
precalc = precalc.replace("REMOVESYMMETRY", "REMOVE_SYMMETRY")
precalc = precalc.replace("TIMEREVERSAL", "TIME_REVERSAL")
url = "http://muellergroup.jhu.edu:8080/PreCalcServer/PreCalcServlet"
temp_dir_name = tempfile.mkdtemp()
cwd = os.getcwd()
os.chdir(temp_dir_name)
with open("PRECALC", "w+") as precalc_file, open("POSCAR", "w+") as poscar_file, open("INCAR", "w+") as incar_file:
precalc_file.write(precalc)
poscar_file.write(structure.to("POSCAR"))
files = [("fileupload", precalc_file), ("fileupload", poscar_file)]
if incar:
incar_file.write(incar.get_string())
files.append(("fileupload", incar_file))
precalc_file.seek(0)
poscar_file.seek(0)
incar_file.seek(0)
r = requests.post(url, files=files)
kpoints = Kpoints.from_string(r.text)
os.chdir(cwd)
shutil.rmtree(temp_dir_name)
return kpoints