#!/usr/bin/python

#Python script to run the various newchg calculations

import os


#Read data file containing calculations to do
file=open('calclist','r')
text=file.readlines()
file.close()
calclist=[]
#Strip lines beginning with comments and the comments from lines
for line in text:
  if line.find('#')!=0:
    cmt=line.find('#')
    calc=line[:cmt]
    if len(calc)>2:
      calclist.append(calc)

doneligs=[]
for calc in calclist:
  #Directory to which to return
  initdir=os.getcwd()

  #Get rough estimate of ligand name for queue and to make sure we don't run the water/vacuum calcs more than once for a given ligand
  dirs=calc.split('/')
  ligname=dirs[0].replace('single_','s')
  #Calculation number
  calcnum=dirs[1].replace('ori','')

  #Submit complex calculations
  os.chdir('%s/complex_nochg%s' % (dirs[0],calcnum))
  os.system('submitseries.py -n 4 -q baton:opterons -l 100 -j %s' % ligname)
  os.chdir('../complex_restr%s' % (calcnum))
  os.system('submitseries.py -n 13 -q baton:opterons -l 100 -j %s' % ligname)
  
  #Go back to starting direcotry
  os.chdir(initdir)
  print "Done with %s; hit any key to proceed." % ligname
  raw_input()
