comparison gaussian.py @ 2:ed472dc06c20 draft default tip

Uploaded 1.0.0
author malex
date Tue, 18 Sep 2012 23:03:01 -0400
parents
children
comparison
equal deleted inserted replaced
1:28ebcfcb10a2 2:ed472dc06c20
1 #/usr/bin/env python
2 """
3 Copyright (C) 2012
4 Ying Zhang <zhang@hpc.ufl.edu> and Oleksandr Moskalenko <om@hpc.ufl.edu>
5 University of Florida Research Computing
6
7 This script checks the user permission for using gaussian software.
8 If permission is granted, it runs g09 with inputfile.
9
10 It takes 2 command line options:
11 $name: the $__user_name__ template preset that corresponds to the real
12 username.
13 $inputfile: a input file for g09
14 """
15 import sys, os, shutil
16 from subprocess import Popen, PIPE
17
18 if len(sys.argv) == 3:
19 name = sys.argv[1]
20 ginput = sys.argv[2]
21 else:
22 msg = "Error: wrong number of parameters provided.\n"
23 sys.stderr.write(msg)
24 sys.exit(1)
25
26 command = "groups " + name + " | grep gaussian"
27 result = Popen([command], shell=True, stdout=PIPE, stderr=PIPE, close_fds=True)
28 stdout, stderr = result.communicate()
29 return_code = result.returncode
30 if return_code:
31 errmsg = "Error: only users in the gaussian group can use this software.\n"
32 sys.stdout.write(stdout)
33 sys.stderr.write(errmsg)
34 sys.stderr.write(stderr)
35 sys.stderr.write("Return error code %i from command:\n" % return_code)
36 sys.stderr.write("%s\n" % command)
37 sys.exit(2)
38 else:
39 if not os.path.exists('gaussian.com'):
40 shutil.copyfile(ginput, 'gaussian.com')
41 cmd = 'source /galaxy/run/dev/tools/chemistry/env.sh; g09 gaussian.com'
42 result = Popen([cmd], shell=True, stdout=PIPE, stderr=PIPE, close_fds=True)
43 stdout, stderr = result.communicate()
44 return_code = result.returncode
45 if return_code:
46 sys.stdout.write(stdout)
47 sys.stderr.write(stderr)
48 sys.stderr.write("Return error code %i from command:\n" % return_code)
49 sys.stderr.write("%s\n" % result)
50 sys.exit(1)
51 else:
52 sys.stdout.write(stdout)
53 sys.stdout.write(stderr)
54 sys.exit(0)