-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathUpdateChargeModels.py
53 lines (40 loc) · 1.67 KB
/
UpdateChargeModels.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
import os
import sys
if os.path.isfile("pybel.py") or os.path.isfile("pybel.pyc"):
sys.exit("Delete pybel.pyc and move pybel.py to oldpybel.py")
from openbabel import pybel
def heading(text, symbol):
return text + "\n" + symbol*len(text)
def escape(text):
return text.replace("*", "\*")
chargenames = pybel._getpluginnames("charges")
charge_dict = pybel._getplugins(pybel.ob.OBChargeModel.FindType, chargenames)
normal = ["gasteiger", "mmff94"]
different = ["eem", "qeq", "qtpie"]
none = ["none"]
all = none + normal + different
unclassified = [charge for charge in chargenames if charge not in all]
if unclassified:
print("UNCLASSIFIED: ", unclassified)
charge_sections = [("Cheminformatics charge models", normal),
("Special charge models", different)]
text = []
for section, charges in charge_sections:
text.append(heading(section, "-"))
text.append("")
for charge in charges:
description = charge_dict[charge].Description()
broken = [x.lstrip() for x in description.split("\n")]
firstline = broken[0]
maindescription = "\n".join(broken[1:-1]) if broken[-1].endswith("is definable") else "\n".join(broken[1:])
title = "%s (%s)" % (firstline, charge)
text.append(".. rubric:: %s" % title)
text.append("")
text.append("%s" % escape(maindescription))
text.append("")
contents = open(os.path.join("Charges", "charges.rst"), "r").read()
marker = "INSERT AUTOMATICALLY GENERATED CONTENT BELOW"
idx = contents.find(marker) + len(marker)
new_contents = contents[:idx] + "\n\n" + "\n".join(text)
with open(os.path.join("Charges", "charges.rst"), "w") as f:
f.write(new_contents,'\n')