species_reader.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. """
  2. This is free and unencumbered software released into the public domain.
  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. In jurisdictions that recognize copyright laws, the author or authors
  8. of this software dedicate any and all copyright interest in the
  9. software to the public domain. We make this dedication for the benefit
  10. of the public at large and to the detriment of our heirs and
  11. successors. We intend this dedication to be an overt act of
  12. relinquishment in perpetuity of all present and future rights to this
  13. software under copyright law.
  14. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15. EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  17. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. OTHER DEALINGS IN THE SOFTWARE.
  21. For more information, please refer to [http://unlicense.org]
  22. """
  23. import sys
  24. import os
  25. import pandas as pd
  26. MCELL_PATH = os.environ.get('MCELL_PATH', '')
  27. if MCELL_PATH:
  28. sys.path.append(os.path.join(MCELL_PATH, 'lib'))
  29. else:
  30. print("Error: variable MCELL_PATH that is used to find the mcell library was not set.")
  31. sys.exit(1)
  32. import mcell as m
  33. def read_species_file(file_name):
  34. # load the .species file as a list of pairs (mcell.Complex, int), the second item is count
  35. res = []
  36. with open(file_name, 'r') as f:
  37. for line in f:
  38. if not line.strip():
  39. continue
  40. items = line.split()
  41. assert len(items) == 2, "Invalid input file contents " + line
  42. # constructor m.Complex parses the BNGL representaion into
  43. # a MCell4 API representation
  44. # (see https://cnl.salk.edu/~ahusar/mcell4_documentation/generated/subsystem.html#complex
  45. cplx = m.Complex(items[0])
  46. res.append((cplx, str(items[1])))
  47. return res