mcell3r_pbs_run_range.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/env python
  2. import sys
  3. import os
  4. import math
  5. if __name__ == '__main__':
  6. if (len(sys.argv)<5):
  7. print ('\nUsage: %s seed_list_spec seeds_per_node rules_file mdl_file\n' % (sys.argv[0]))
  8. print ('\n Example: %s "1:100:2" 8 Scene.mdlr_rules.xml Scene.main.mdl\n' % (sys.argv[0]))
  9. print (' This would submit mcell jobs to simulate Scene.main.mdl')
  10. print (' using seeds 1 through 100 in steps of 2,')
  11. print (' with 8 individual simulations running concurrently in each job \n\n')
  12. sys.exit()
  13. else:
  14. seed_list_spec = sys.argv[1]
  15. seeds_per_node = int(sys.argv[2])
  16. rules_file = sys.argv[3]
  17. mdl_file = sys.argv[4]
  18. seed_list = []
  19. seed_list_toks = seed_list_spec.split(',')
  20. for seed_list_tok in seed_list_toks:
  21. seed_range_toks = seed_list_tok.split(':')
  22. if (len(seed_range_toks) > 1):
  23. if (len(seed_range_toks) == 2):
  24. seed_list.extend(range(int(seed_range_toks[0]),int(seed_range_toks[1])+1))
  25. else:
  26. seed_list.extend(range(int(seed_range_toks[0]),int(seed_range_toks[1])+1,int(seed_range_toks[2])))
  27. else:
  28. seed_list.append(int(seed_list_tok))
  29. mcell_exec = '$HOME/bin/mcell3.5/mcell3r.py'
  30. mcell_cmd = 'source ~/.bashrc ; %s -s $seed -r %s -m %s' % (mcell_exec,rules_file,mdl_file)
  31. job_script_template = '%s; for seed in ${seeds[@]}; do { %s & }; done; wait;'
  32. job_name_template = 'mcell_%04d_%04d'
  33. qsub_option_template = '-l nodes=1 -l walltime=48:00:00 -m n -A kennedy-lab -d ./ -S /bin/bash -N %s -o qsub_%s.out -e qsub_%s.err'
  34. for start_i in range(0,len(seed_list),seeds_per_node):
  35. end_i = start_i + seeds_per_node - 1
  36. if end_i > len(seed_list)-1:
  37. end_i = len(seed_list)-1
  38. seed_chunk = 'seeds=('
  39. for seed in seed_list[start_i:end_i+1]:
  40. seed_chunk = seed_chunk + ' ' + str(seed)
  41. seed_chunk = seed_chunk + ' )'
  42. job_script = job_script_template % (seed_chunk, mcell_cmd)
  43. job_name = job_name_template % (seed_list[start_i], seed_list[end_i])
  44. qsub_options = qsub_option_template % (job_name, job_name, job_name)
  45. cmd = "echo '%s' | qsub %s -" % (job_script, qsub_options)
  46. print(cmd)
  47. os.system(cmd)