#!/usr/bin/python
#
# run from the server2 directory
# the data directory is assumed to be ./data/PROJxx/RUNxx/CLONExx
#
# usage: ./workunittester.py <proj> <run> <clone> <gen>
# returns : '4' if the g_rms binary (below) in Tester() can't be found
#	    '3' if the WU fails the test
# 	    '2' if somehow the xvg can't be read
#	    '1' if there's some problem, "our fault"
#	    '0' if successful
# 

# cutoff in nm
cutoff = 0.09

import sys
from Tester import *

try: ( p, r, c, g ) = sys.argv[ 1:5 ]
except: sys.exit(1)

tester = Tester() # use the default g_rms  

datadir = "data/PROJ%s/RUN%s/CLONE%s" % ( p, r, c )
xtcfile = "%s/frame%s.xtc" % ( datadir, g )
tprfile = "%s/frame%s.tpr" % ( datadir, g )

try 			: result = tester.test( xtcfile, tprfile )
except GmxNoBinary 	: sys.exit(4)
except GmxFailure 	: sys.exit(1)
except CouldNotReadXvg 	: sys.exit(2) 
except 			: raise

if result <= cutoff : sys.exit(0)
else : sys.exit(3)

