<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/env python
'''
-------------------
Copyright (c) 2016 Computational Biomechanics (CoBi) Core, Department of
Biomedical Engineering, Cleveland Clinic

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to permit
persons to whom the Software is furnished to do so, subject to the
following conditions:

The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
USE OR OTHER DEALINGS IN THE SOFTWARE.
-------------------

submit_simulation.py

Written by Craig Bennetts.

Contact: 
 Ahmet Erdemir, PhD
 Computational Biomodeling (CoBi) Core
 Department of Biomedical Engineering
 Lerner Research Institute
 Cleveland Clinic
 Cleveland, OH 44195, USA
 erdemira@ccf.org

'''

import os
import sys
import glob

def usage(argv):
	print
	print 'USAGE: ' + argv[0] + ' &lt;path/to/febio&gt; &lt;model.feb&gt; &lt;path/to/post_process.py&gt; [&lt;path/to/modify_model.py&gt; &lt;modify_model.cfg&gt;]'
	print
	print '       [.] = optional arguments (must be provided together)'
	print


def main(argv):

	# Check for appropriate usage
	if not (len(argv)==4 or len(argv)==6):
		usage(argv)
		sys.exit(1)

	febio_path = argv[1]
	input_model_filename = argv[2]

	model_filename_to_run = input_model_filename

	# Modify the model if arguments are provided to do so
	if len(argv)==6:

		modify_model_script = argv[4]
		modify_model_cfg = argv[5]

		modified_model_filename = input_model_filename[:-4] + '_MOD.feb'

		modify_model_command = modify_model_script + ' ' + input_model_filename + ' ' + modify_model_cfg + ' ' + modified_model_filename

		print
		print 'MODIFYING MODEL:'
		print modify_model_command
		print

		os.system( modify_model_command )

		# check to see if model was succesfully modified
		if len(glob.glob(modified_model_filename))==0:
			print 'ERROR: model was not successfully modified, check options in configuration file!'
			print
			sys.exit(1)
		
		# update the filename of the model to run to the modified model
		model_filename_to_run = modified_model_filename


	# Run the simulation
	febio_command = febio_path + ' -i ' + model_filename_to_run

	print 'RUNNING SIMULATION:'
	print febio_command
	print

	os.system( febio_command )

	# Post process the simulation results
	post_process_script = argv[3]

	post_process_command = post_process_script

	print 'POST-PROCESSING:'
	print post_process_command
	print

	os.system( post_process_command )

	print 'SIMULATION COMPLETE'
	print

# END OF main()


if __name__ == "__main__":
    main(sys.argv)
</pre></body></html>