/
help.py
82 lines (64 loc) · 2.1 KB
/
help.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
"""Get help with VASP parameters from VASP wiki."""
from __future__ import annotations
import re
import requests
from bs4 import BeautifulSoup
class VaspDoc:
"""A VASP documentation helper."""
def __init__(self):
"""Init for VaspDoc."""
self.url_template = "http://www.vasp.at/wiki/index.php/%s"
def print_help(self, tag):
"""
Print the help for a TAG.
Args:
tag (str): Tag used in VASP.
"""
print(self.get_help(tag))
def print_jupyter_help(self, tag):
"""
Display HTML help in ipython notebook.
Args:
tag (str): Tag used in VASP.
"""
html_str = self.get_help(tag, "html")
from IPython.core.display import HTML, display
display(HTML(html_str))
@classmethod
def get_help(cls, tag, fmt="text"):
"""
Get help on a VASP tag.
Args:
tag (str): VASP tag, e.g., ISYM.
Returns:
Help text.
"""
tag = tag.upper()
r = requests.get(f"https://www.vasp.at/wiki/index.php/{tag}", verify=False)
soup = BeautifulSoup(r.text)
main_doc = soup.find(id="mw-content-text")
if fmt == "text":
output = main_doc.text
output = re.sub("\n{2,}", "\n\n", output)
else:
output = str(main_doc)
return output
@classmethod
def get_incar_tags(cls):
"""Returns: All incar tags."""
tags = []
for page in [
"https://www.vasp.at/wiki/index.php/Category:INCAR",
"https://www.vasp.at/wiki/index.php?title=Category:INCAR&pagefrom=ML+FF+LCONF+DISCARD#mw-pages",
]:
r = requests.get(page, verify=False)
soup = BeautifulSoup(r.text)
for div in soup.findAll("div", {"class": "mw-category-group"}):
children = div.findChildren("li")
for child in children:
tags.append(child.text.strip())
return tags
if __name__ == "__main__":
doc = VaspDoc()
doc.print_help("ISYM")
print(doc.get_incar_tags())