You are here: Home / Tools & Utilities / Python / Sample python script for batch MESA runs

Sample python script for batch MESA runs

a sample python script for batch processing multiple MESA runs. can be adopted to the work_pms_rotation lab in the 2013 summer school.

BatchRunMESA.py — Python Source, 1 kB (1188 bytes)

File contents

import os

def ReviseInlistFile(filename,inlist_projectname):
	tmp_filename='.'+filename+'.tmp'
	fr=open(filename, 'r')
	fw=open(tmp_filename,'w')
	for line in fr:
		if '_inlist1_name' in line:
			if '_star_job_' in line:
				new_content='      extra_star_job_inlist1_name = \'%s\'\n' % inlist_projectname
			elif '_controls_' in line:
				new_content='      extra_controls_inlist1_name = \'%s\'\n' % inlist_projectname
			elif '_pgstar_' in line:
				new_content='      extra_pgstar_inlist1_name = \'%s\'\n' % inlist_projectname
			fw.write(new_content)
		else:
			fw.write(line)
	fr.close()
	fw.close()
	command_mv='mv %s %s' % (tmp_filename,filename)
	os.system(command_mv)
	return

def BatchRun(inlist_namelist):
	for inlist_name in inlist_namelist:
		ReviseInlistFile('inlist',inlist_name)
		command_rn=os.path.abspath('.')+'/rn'
		os.system(command_rn)

my_inlist_namelist=['inlist_pms_startrot','inlist_pms_rotation']

# The namelist above works for pms_rotation problem, or you could put your own namelist as followings:

#my_inlist_namelist=[]
#for i in range(0,100):
#	inlist_name='inlist_project_%03d' % i
#	my_inlist_namelist.append(inlist_name)

BatchRun(my_inlist_namelist)