forked from nglviewer/ngl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsymop_lib.py
executable file
·70 lines (55 loc) · 1.8 KB
/
symop_lib.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
#!/usr/bin/env python
import shlex
import json
from json import encoder
from collections import OrderedDict, defaultdict
encoder.FLOAT_REPR = lambda o: format(o, '.2f')
def main(argv=None):
symop_dict = OrderedDict()
HM = ""
with open("data/symop.lib", "r") as fp:
for line in fp:
if line.strip() == "":
continue
if line.startswith(" "):
symop_dict[HM].append(line.strip().replace(" ", ""))
else:
ls = shlex.split(line.split("!")[0])
HM = ls[6]
symop_dict[HM] = []
op_dict = defaultdict(int)
part_dict = defaultdict(int)
code_dict = {}
decode_dict = OrderedDict()
symop_dict2 = OrderedDict()
i = 32
for k, v in symop_dict.items():
v2 = []
for op in v:
op_dict[op] += 1
for part in op.split(","):
part_dict[part] += 1
if part not in code_dict:
code_dict[part] = chr(i)
decode_dict[chr(i)] = part
i += 1
if i == 34: # avoid " character
i += 1
if i == 92: # avoid \ character
i += 1
v2.append(code_dict[part])
symop_dict2[k] = "".join(v2)
print(json.dumps(code_dict, indent=4))
print(len(code_dict))
print(json.dumps(decode_dict, indent=4))
print(len(decode_dict))
# print(json.dumps(op_dict, indent=4))
# print(len(op_dict))
# print(max(op_dict.values()))
# print(json.dumps(part_dict, indent=4))
# print(len(part_dict))
# print(max(part_dict.values()))
# print(json.dumps(symop_dict, indent=4))
print(json.dumps(symop_dict2, indent=4))
if __name__ == "__main__":
main()