visualize.py 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # This is free and unencumbered software released into the public domain.
  2. #
  3. # Anyone is free to copy, modify, publish, use, compile, sell, or
  4. # distribute this software, either in source code form or as a compiled
  5. # binary, for any purpose, commercial or non-commercial, and by any
  6. # means.
  7. #
  8. # In jurisdictions that recognize copyright laws, the author or authors
  9. # of this software dedicate any and all copyright interest in the
  10. # software to the public domain. We make this dedication for the benefit
  11. # of the public at large and to the detriment of our heirs and
  12. # successors. We intend this dedication to be an overt act of
  13. # relinquishment in perpetuity of all present and future rights to this
  14. # software under copyright law.
  15. #
  16. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  19. # IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  20. # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  21. # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  22. # OTHER DEALINGS IN THE SOFTWARE.
  23. #
  24. # For more information, please refer to [http://unlicense.org]
  25. import sys
  26. import os
  27. import platform
  28. import subprocess
  29. MCELL_PATH = os.environ.get('MCELL_PATH', '')
  30. if MCELL_PATH:
  31. lib_path = os.path.join(MCELL_PATH, 'lib')
  32. if os.path.exists(os.path.join(lib_path, 'mcell.so')) or \
  33. os.path.exists(os.path.join(lib_path, 'mcell.pyd')):
  34. sys.path.append(lib_path)
  35. else:
  36. print("Error: Python module mcell.so or mcell.pyd was not found in "
  37. "directory '" + lib_path + "' constructed from system variable "
  38. "MCELL_PATH.")
  39. sys.exit(1)
  40. else:
  41. print("Error: system variable MCELL_PATH that is used to find the mcell "
  42. "library was not set.")
  43. sys.exit(1)
  44. if len(sys.argv) != 2:
  45. sys.exit("Expecing one argument that is the path to the viz output directory, e.g. viz_data/seed_00001/")
  46. REL_BLENDER_PATH = None
  47. if platform.system() == 'Darwin':
  48. REL_BLENDER_PATH = os.path.join(MCELL_PATH, '..', '..', '..', '..', '..', '..', '..', '..', '..')
  49. else:
  50. REL_BLENDER_PATH = os.path.join(MCELL_PATH, '..', '..', '..', '..', '..', '..')
  51. ABS_BLENDER_PATH = os.path.abspath(REL_BLENDER_PATH)
  52. if platform.system() == 'Darwin':
  53. VIZ_MCELL_SCRIPT = \
  54. os.path.join(ABS_BLENDER_PATH, 'blender.app', 'Contents', 'Resources', '2.93', 'scripts', 'addons', 'cellblender', 'developer_utilities', 'mol_viz_scripts', 'viz_mcell_run.py')
  55. else:
  56. VIZ_MCELL_SCRIPT = \
  57. os.path.join(ABS_BLENDER_PATH, '2.93', 'scripts', 'addons', 'cellblender', 'developer_utilities', 'mol_viz_scripts', 'viz_mcell_run.py')
  58. if 'Windows' in platform.system():
  59. CMD = os.path.join(ABS_BLENDER_PATH, 'blender.exe')
  60. else:
  61. CMD = 'bash ' + os.path.join(ABS_BLENDER_PATH, 'my_blender')
  62. CMD += ' -P ' + VIZ_MCELL_SCRIPT + ' -- ' + sys.argv[1]
  63. subprocess.run(CMD, shell=True)