annotate gaussian.py @ 2:ed472dc06c20 draft default tip

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