mcell4_converter.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 LIBMCELL_API_MCELL4_CONVERTER_H_
  12. #define LIBMCELL_API_MCELL4_CONVERTER_H_
  13. #include <vector>
  14. #include "defines.h"
  15. #include "mol_or_rxn_count_event.h"
  16. #include "api/bng_converter.h"
  17. namespace BNG {
  18. class ComponentType;
  19. class Component;
  20. class ElemMolType;
  21. class ElemMol;
  22. class Cplx;
  23. class Species;
  24. }
  25. namespace MCell {
  26. class World;
  27. class Partition;
  28. class InitialSurfaceReleases;
  29. class GeometryObject;
  30. class RegionExprNode;
  31. class ReleaseEvent;
  32. class MolOrRxnCountTerm;
  33. class MolOrRxnCountItem;
  34. class Region;
  35. namespace API {
  36. class Model;
  37. class ComponentType;
  38. class Component;
  39. class ElementaryMoleculeType;
  40. class ElementaryMolecule;
  41. class Complex;
  42. class SurfaceProperty;
  43. class InitialSurfaceRelease;
  44. class Region;
  45. class SurfaceRegion;
  46. class GeometryObject;
  47. class MoleculeReleaseInfo;
  48. class ReleaseSite;
  49. class Count;
  50. class CountTerm;
  51. class Species;
  52. class SurfaceClass;
  53. class RngState;
  54. class MCell4Converter {
  55. public:
  56. MCell4Converter(Model* model_, World* world_);
  57. // convert all items in Model into the World representation
  58. // throws exception if anything went wrong
  59. // modifies model as well where it stores information for cases
  60. // when a value such a reaction rate was updated by the user
  61. void convert_before_init();
  62. void convert_after_init();
  63. // converter can be also used to convert individual objects
  64. // throws exception if anything went wrong
  65. MCell::ReleaseEvent* convert_single_release_event(
  66. const std::shared_ptr<API::ReleaseSite>& r);
  67. private:
  68. species_id_t get_species_id(API::Species& s, const std::string class_name, const std::string object_name);
  69. species_id_t get_species_id_for_complex(API::Complex& ci, const std::string error_msg, const bool check_orientation = true);
  70. void get_geometry_bounding_box(Vec3& llf, Vec3& urb);
  71. void convert_simulation_setup();
  72. void convert_elementary_molecule_types();
  73. void convert_species();
  74. void convert_surface_class_rxn(API::SurfaceProperty& sp, const BNG::Species& surface_reactant);
  75. void convert_surface_classes();
  76. void check_surface_compartments(const BNG::RxnRule& r, BNG::compartment_id_t& surf_comp_id);
  77. void set_vol_rxn_substance_orientation_from_compartment(
  78. BNG::RxnRule& r, const BNG::Compartment& surf_comp, BNG::Cplx& substance);
  79. void check_intermembrane_surface_reaction(const BNG::RxnRule& rxn);
  80. void convert_rxns();
  81. MCell::wall_index_t convert_wall_and_add_to_geom_object(
  82. const API::GeometryObject& src_obj, const uint side,
  83. MCell::Partition& p, MCell::GeometryObject& dst_obj
  84. );
  85. void convert_initial_surface_releases(
  86. const std::vector<std::shared_ptr<API::InitialSurfaceRelease>>& api_releases,
  87. std::vector<MCell::InitialSurfaceReleases>& mcell_releases
  88. );
  89. void convert_concentration_clamp_release(
  90. const partition_id_t partition_id, const API::SurfaceClass& surface_class, const MCell::Region& mcell_region);
  91. MCell::region_index_t convert_surface_region(
  92. MCell::Partition& p,
  93. API::SurfaceRegion& surface_region, API::GeometryObject& o,
  94. MCell::GeometryObject& obj
  95. );
  96. void convert_geometry_objects();
  97. void check_surface_compartment_name_collision(const std::string& surface_compartment_name);
  98. void convert_compartments();
  99. MCell::RegionExprNode* convert_region_expr_recursively(
  100. const std::shared_ptr<API::Region>& region,
  101. const bool is_vol,
  102. const bool release_not_count,
  103. MCell::RegionExpr& region_expr
  104. );
  105. void convert_rel_site_region_expr(API::ReleaseSite& rel_site, MCell::ReleaseEvent* rel_event);
  106. void convert_molecule_list(
  107. const std::vector<std::shared_ptr<MoleculeReleaseInfo>>& molecule_list,
  108. const std::string& rel_site_name,
  109. MCell::ReleaseEvent* rel_event);
  110. void convert_release_events();
  111. void convert_count_term_leaf_and_init_counting_flags(
  112. const std::shared_ptr<API::CountTerm> ct, const int sign,
  113. MolOrRxnCountTermVector& terms
  114. );
  115. void convert_count_terms_recursively(
  116. const std::shared_ptr<API::Count> count, // only for warning printouts
  117. const std::shared_ptr<API::CountTerm> ct,
  118. const int sign,
  119. MCell::MolOrRxnCountItem& info
  120. );
  121. void convert_mol_or_rxn_count_events_and_init_counting_flags();
  122. void init_species_counting_flags();
  123. void convert_viz_output_events();
  124. void convert_initial_iteration_and_time_and_move_scheduler_time();
  125. void add_ctrl_c_termination_event();
  126. void check_all_mol_types_have_diffusion_const();
  127. // after init
  128. void convert_rng_state();
  129. void convert_checkpointed_molecules();
  130. Model* model;
  131. World* world;
  132. BNGConverter bng_converter;
  133. };
  134. } // namespace API
  135. } // namespace MCell
  136. #endif /* LIBMCELL_API_MCELL4_CONVERTER_H_ */