bngl_generator.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /******************************************************************************
  2. *
  3. * Copyright (C) 2020 by
  4. * The Salk Institute for Biological Studies
  5. *
  6. * Use of this source code is governed by an MIT-style
  7. * license that can be found in the LICENSE file or at
  8. * https://opensource.org/licenses/MIT.
  9. *
  10. ******************************************************************************/
  11. #ifndef UTILS_DATA_MODEL_TO_PYMCELL_BNGL_GENERATOR_H_
  12. #define UTILS_DATA_MODEL_TO_PYMCELL_BNGL_GENERATOR_H_
  13. #include <string>
  14. #include <iostream>
  15. #include "json/json.h"
  16. #include "bng/bngl_names.h"
  17. namespace MCell {
  18. typedef std::map<std::string, std::set<std::string>> ParentToChildCompartmentsMap;
  19. class BNGLGenerator {
  20. public:
  21. BNGLGenerator(
  22. const std::string& bngl_filename_,
  23. std::ostream& bng_out_,
  24. SharedGenData& data_)
  25. : bngl_filename(bngl_filename_), bng_out(bng_out_), data(data_) {
  26. }
  27. void generate_units_information_header();
  28. void generate_parameters(std::ostream& python_out);
  29. void generate_mol_types(std::ostream& python_out);
  30. void generate_compartments();
  31. void open_reaction_rules_section() { bng_out << BNG::BEGIN_REACTION_RULES << "\n"; }
  32. std::string generate_single_reaction_rule(Json::Value& reaction_list_item, const bool generate_name);
  33. void close_reaction_rules_section() { bng_out << BNG::END_REACTION_RULES << "\n\n"; }
  34. bool can_express_count_with_bngl(
  35. const bool single_term,
  36. const bool rxn_not_mol,
  37. const std::string& where_to_count,
  38. const std::string& orientation,
  39. const std::string& mul_div_str,
  40. const std::string& rxn_step) const;
  41. void open_observables_section() { bng_out << BNG::BEGIN_OBSERVABLES << "\n"; }
  42. void generate_single_count(
  43. const std::string& observable_name,
  44. const std::string& what_to_count,
  45. const std::string& description,
  46. const bool molecules_not_species);
  47. void close_observables_section() { bng_out << BNG::END_OBSERVABLES << "\n\n"; }
  48. bool can_express_release_with_bngl(Json::Value& release_site_item);
  49. void open_seed_species_section() { bng_out << BNG::BEGIN_SEED_SPECIES << "\n"; }
  50. void generate_single_release_site(
  51. const std::string& bngl_cplx,
  52. const std::string& quantity,
  53. const std::string& description);
  54. void close_seed_species_section() { bng_out << BNG::END_SEED_SPECIES << "\n\n"; }
  55. void add_comment(const std::string& text) { bng_out << "# " << text << "\n"; }
  56. private:
  57. void generate_single_bngl_parameter(Json::Value& parameter);
  58. void generate_single_python_parameter(std::ostream& python_out, Json::Value& parameter);
  59. void generate_bngl_mol_type(Json::Value& molecule_list_item);
  60. void generate_python_mol_type_info(std::ostream& python_out, Json::Value& molecule_list_item);
  61. void get_compartment_volume_and_area(const std::string& name, double& volume, double& area);
  62. Json::Value& find_geometry_object(const std::string& name);
  63. void generate_single_compartment(Json::Value& model_object);
  64. const std::string bngl_filename;
  65. std::ostream& bng_out;
  66. SharedGenData& data; // owned by MCell4Generator
  67. std::map<std::string, std::pair<double, double>> compartment_name_to_volume_area_cache;
  68. ParentToChildCompartmentsMap volume_compartment_children;
  69. };
  70. } /* namespace MCell */
  71. #endif /* UTILS_DATA_MODEL_TO_PYMCELL_BNGL_GENERATOR_H_ */