gen_model.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /******************************************************************************
  2. *
  3. * Copyright (C) 2021 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 API_GEN_MODEL_H
  12. #define API_GEN_MODEL_H
  13. #include "api/api_common.h"
  14. #include "api/api_config.h"
  15. #include "api/mol_wall_hit_info.h"
  16. #include "api/notifications.h"
  17. #include "api/reaction_info.h"
  18. #include "api/warnings.h"
  19. #include "api/subsystem.h"
  20. #include "api/instantiation.h"
  21. #include "api/observables.h"
  22. #include "api/introspection.h"
  23. namespace MCell {
  24. namespace API {
  25. class Model;
  26. class BaseChkptMol;
  27. class Color;
  28. class Complex;
  29. class Config;
  30. class Count;
  31. class ElementaryMoleculeType;
  32. class GeometryObject;
  33. class Instantiation;
  34. class MolWallHitInfo;
  35. class Molecule;
  36. class Notifications;
  37. class Observables;
  38. class ReactionInfo;
  39. class ReactionRule;
  40. class Region;
  41. class ReleaseSite;
  42. class Species;
  43. class Subsystem;
  44. class SurfaceClass;
  45. class VizOutput;
  46. class Wall;
  47. class WallWallHitInfo;
  48. class Warnings;
  49. class PythonExportContext;
  50. class GenModel: public Subsystem, public Instantiation, public Observables, public Introspection {
  51. public:
  52. GenModel() {
  53. }
  54. GenModel(DefaultCtorArgType) {
  55. }
  56. virtual ~GenModel() {}
  57. std::shared_ptr<Model> copy_model() const;
  58. std::shared_ptr<Model> deepcopy_model(py::dict = py::dict()) const;
  59. virtual bool __eq__(const Model& other) const;
  60. virtual bool eq_nonarray_attributes(const Model& other, const bool ignore_name = false) const;
  61. bool operator == (const Model& other) const { return __eq__(other);}
  62. bool operator != (const Model& other) const { return !__eq__(other);}
  63. std::string to_str(const bool all_details=false, const std::string ind="") const ;
  64. virtual std::string export_to_python(std::ostream& out, PythonExportContext& ctx);
  65. virtual std::string export_vec_species(std::ostream& out, PythonExportContext& ctx, const std::string& parent_name);
  66. virtual std::string export_vec_reaction_rules(std::ostream& out, PythonExportContext& ctx, const std::string& parent_name);
  67. virtual std::string export_vec_surface_classes(std::ostream& out, PythonExportContext& ctx, const std::string& parent_name);
  68. virtual std::string export_vec_elementary_molecule_types(std::ostream& out, PythonExportContext& ctx, const std::string& parent_name);
  69. virtual std::string export_vec_release_sites(std::ostream& out, PythonExportContext& ctx, const std::string& parent_name);
  70. virtual std::string export_vec_geometry_objects(std::ostream& out, PythonExportContext& ctx, const std::string& parent_name);
  71. virtual std::string export_vec_checkpointed_molecules(std::ostream& out, PythonExportContext& ctx, const std::string& parent_name);
  72. virtual std::string export_vec_viz_outputs(std::ostream& out, PythonExportContext& ctx, const std::string& parent_name);
  73. virtual std::string export_vec_counts(std::ostream& out, PythonExportContext& ctx, const std::string& parent_name);
  74. // --- attributes ---
  75. Config config;
  76. virtual void set_config(const Config& new_config_) {
  77. config = new_config_;
  78. }
  79. virtual const Config& get_config() const {
  80. return config;
  81. }
  82. Warnings warnings;
  83. virtual void set_warnings(const Warnings& new_warnings_) {
  84. warnings = new_warnings_;
  85. }
  86. virtual const Warnings& get_warnings() const {
  87. return warnings;
  88. }
  89. Notifications notifications;
  90. virtual void set_notifications(const Notifications& new_notifications_) {
  91. notifications = new_notifications_;
  92. }
  93. virtual const Notifications& get_notifications() const {
  94. return notifications;
  95. }
  96. // --- methods ---
  97. virtual void initialize(const bool print_copyright = true) = 0;
  98. virtual uint64_t run_iterations(const double iterations) = 0;
  99. virtual void end_simulation(const bool print_final_report = true) = 0;
  100. virtual void add_subsystem(std::shared_ptr<Subsystem> subsystem) = 0;
  101. virtual void add_instantiation(std::shared_ptr<Instantiation> instantiation) = 0;
  102. virtual void add_observables(std::shared_ptr<Observables> observables) = 0;
  103. virtual void dump_internal_state(const bool with_geometry = false) = 0;
  104. virtual void export_data_model(const std::string& file = STR_UNSET) = 0;
  105. virtual void export_viz_data_model(const std::string& file = STR_UNSET) = 0;
  106. virtual void export_geometry(const std::string& output_files_prefix = STR_UNSET) = 0;
  107. virtual void release_molecules(std::shared_ptr<ReleaseSite> release_site) = 0;
  108. virtual std::vector<int> run_reaction(std::shared_ptr<ReactionRule> reaction_rule, const std::vector<int> reactant_ids, const double time) = 0;
  109. virtual void add_vertex_move(std::shared_ptr<GeometryObject> object, const int vertex_index, const std::vector<double> displacement) = 0;
  110. virtual std::vector<std::shared_ptr<WallWallHitInfo>> apply_vertex_moves(const bool collect_wall_wall_hits = false, const bool randomize_order = true) = 0;
  111. virtual void pair_molecules(const int id1, const int id2) = 0;
  112. virtual void unpair_molecules(const int id1, const int id2) = 0;
  113. virtual int get_paired_molecule(const int id) = 0;
  114. virtual std::map<uint, uint> get_paired_molecules() = 0;
  115. virtual void register_mol_wall_hit_callback(const std::function<void(std::shared_ptr<MolWallHitInfo>, py::object)> function, py::object context, std::shared_ptr<GeometryObject> object = nullptr, std::shared_ptr<Species> species = nullptr) = 0;
  116. virtual void register_reaction_callback(const std::function<bool(std::shared_ptr<ReactionInfo>, py::object)> function, py::object context, std::shared_ptr<ReactionRule> reaction_rule) = 0;
  117. virtual void load_bngl(const std::string& file_name, const std::string& observables_path_or_file = STR_UNSET, std::shared_ptr<Region> default_release_region = nullptr, const std::map<std::string, double>& parameter_overrides = std::map<std::string, double>(), const CountOutputFormat observables_output_format = CountOutputFormat::AUTOMATIC_FROM_EXTENSION) = 0;
  118. virtual void export_to_bngl(const std::string& file_name, const BNGSimulationMethod simulation_method = BNGSimulationMethod::ODE) = 0;
  119. virtual void save_checkpoint(const std::string& custom_dir = STR_UNSET) = 0;
  120. virtual void schedule_checkpoint(const uint64_t iteration = 0, const bool continue_simulation = false, const std::string& custom_dir = STR_UNSET) = 0;
  121. }; // GenModel
  122. class Model;
  123. py::class_<Model> define_pybinding_Model(py::module& m);
  124. } // namespace API
  125. } // namespace MCell
  126. #endif // API_GEN_MODEL_H