1"""
2 This source file is part of the Avogadro project.
3 This source code is released under the New BSD License, (the "License").
4"""
5
6import argparse
7import json
8import sys
9
10# Some globals:
11debug = True
12
13
14def getOptions():
15    userOptions = {}
16
17    userOptions['X Scale'] = {}
18    userOptions['X Scale']['type'] = 'float'
19    userOptions['X Scale']['default'] = 1.0
20    userOptions['X Scale']['precision'] = 3
21    userOptions['X Scale']['toolTip'] = 'Multiplier for X coordinates'
22
23    userOptions['Y Scale'] = {}
24    userOptions['Y Scale']['type'] = 'float'
25    userOptions['Y Scale']['default'] = 1.0
26    userOptions['Y Scale']['precision'] = 3
27    userOptions['Y Scale']['toolTip'] = 'Multiplier for Y coordinates'
28
29    userOptions['Z Scale'] = {}
30    userOptions['Z Scale']['type'] = 'float'
31    userOptions['Z Scale']['default'] = 1.0
32    userOptions['Z Scale']['precision'] = 3
33    userOptions['Z Scale']['toolTip'] = 'Multiplier for Z coordinates'
34
35    opts = {'userOptions': userOptions}
36
37    return opts
38
39
40def scale(opts, mol):
41    xScale = float(opts['X Scale'])
42    yScale = float(opts['Y Scale'])
43    zScale = float(opts['Z Scale'])
44
45    coords = mol['atoms']['coords']['3d']
46    for i in range(0, len(coords), 3):
47        coords[i] = coords[i] * xScale
48        coords[i + 1] = coords[i + 1] * yScale
49        coords[i + 2] = coords[i + 2] * zScale
50
51    return mol
52
53
54def runCommand():
55    # Read options from stdin
56    stdinStr = sys.stdin.read()
57
58    # Parse the JSON strings
59    opts = json.loads(stdinStr)
60
61    # Prepare the result
62    result = {}
63    result['cjson'] = scale(opts, opts['cjson'])
64    return result
65
66if __name__ == "__main__":
67    parser = argparse.ArgumentParser('Scale molecular coordinates.')
68    parser.add_argument('--debug', action='store_true')
69    parser.add_argument('--print-options', action='store_true')
70    parser.add_argument('--run-command', action='store_true')
71    parser.add_argument('--display-name', action='store_true')
72    parser.add_argument('--menu-path', action='store_true')
73    parser.add_argument('--lang', nargs='?', default='en')
74    args = vars(parser.parse_args())
75
76    debug = args['debug']
77
78    if args['display_name']:
79        print("Scale Coordinates...")
80    if args['menu_path']:
81        print("&Extensions")
82    if args['print_options']:
83        print(json.dumps(getOptions()))
84    elif args['run_command']:
85        print(json.dumps(runCommand()))
86