-
Notifications
You must be signed in to change notification settings - Fork 1
/
flattenZ.py
78 lines (61 loc) · 2.1 KB
/
flattenZ.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
"""
/******************************************************************************
This source file is part of the Avogadro project.
This source code is released under the New BSD License, (the "License").
******************************************************************************/
"""
import argparse
import json
import sys
def getOptions():
return {}
def flattenZ(opts, mol):
coords = mol['atoms']['coords']['3d']
# check if the user has any atoms selected
any_selected = False
if 'selected' in mol['atoms']:
for item in mol['atoms']['selected']:
if item:
any_selected = True
break # we have *some* atoms selected
indices = []
atomic_numbers = mol['atoms']['elements']['number']
for i in range(len(atomic_numbers)):
if not any_selected:
indices.append(i)
# or only do selected atoms
elif mol['atoms']['selected'][i]:
indices.append(i)
j = 0
for i in range(0, len(coords), 3):
if j in indices:
coords[i+2] = 0.0
j = j+1
return mol
def runCommand():
# Read options from stdin
stdinStr = sys.stdin.read()
# Parse the JSON strings
opts = json.loads(stdinStr)
# Prepare the result
result = {}
result['cjson'] = flattenZ(opts, opts['cjson'])
return result
if __name__ == "__main__":
parser = argparse.ArgumentParser('Flatten Z axis.')
parser.add_argument('--debug', action='store_true')
parser.add_argument('--print-options', action='store_true')
parser.add_argument('--run-command', action='store_true')
parser.add_argument('--display-name', action='store_true')
parser.add_argument('--menu-path', action='store_true')
parser.add_argument('--lang', nargs='?', default='en')
args = vars(parser.parse_args())
debug = args['debug']
if args['display_name']:
print("Flatten Z-Axis")
if args['menu_path']:
print("&Build")
if args['print_options']:
print(json.dumps(getOptions()))
elif args['run_command']:
print(json.dumps(runCommand()))