Mercurial > repos > malex > gaussian
diff gaussian/gaussian.py @ 0:33301cfd5fb1 draft
Initial upload of 1.0.0
author | malex |
---|---|
date | Tue, 18 Sep 2012 23:00:40 -0400 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gaussian/gaussian.py Tue Sep 18 23:00:40 2012 -0400 @@ -0,0 +1,54 @@ +#/usr/bin/env python +""" +Copyright (C) 2012 +Ying Zhang <zhang@hpc.ufl.edu> and Oleksandr Moskalenko <om@hpc.ufl.edu> +University of Florida Research Computing + +This script checks the user permission for using gaussian software. +If permission is granted, it runs g09 with inputfile. + +It takes 2 command line options: + $name: the $__user_name__ template preset that corresponds to the real +username. + $inputfile: a input file for g09 +""" +import sys, os, shutil +from subprocess import Popen, PIPE + +if len(sys.argv) == 3: + name = sys.argv[1] + ginput = sys.argv[2] +else: + msg = "Error: wrong number of parameters provided.\n" + sys.stderr.write(msg) + sys.exit(1) + +command = "groups " + name + " | grep gaussian" +result = Popen([command], shell=True, stdout=PIPE, stderr=PIPE, close_fds=True) +stdout, stderr = result.communicate() +return_code = result.returncode +if return_code: + errmsg = "Error: only users in the gaussian group can use this software.\n" + sys.stdout.write(stdout) + sys.stderr.write(errmsg) + sys.stderr.write(stderr) + sys.stderr.write("Return error code %i from command:\n" % return_code) + sys.stderr.write("%s\n" % command) + sys.exit(2) +else: + if not os.path.exists('gaussian.com'): + shutil.copyfile(ginput, 'gaussian.com') + cmd = 'source /galaxy/run/dev/tools/chemistry/env.sh; g09 gaussian.com' + result = Popen([cmd], shell=True, stdout=PIPE, stderr=PIPE, close_fds=True) + stdout, stderr = result.communicate() + return_code = result.returncode + if return_code: + sys.stdout.write(stdout) + sys.stderr.write(stderr) + sys.stderr.write("Return error code %i from command:\n" % return_code) + sys.stderr.write("%s\n" % result) + sys.exit(1) + else: + sys.stdout.write(stdout) + sys.stdout.write(stderr) + sys.exit(0)