surface_property.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 API_SURFACE_PROPERTY_H
  12. #define API_SURFACE_PROPERTY_H
  13. #include "generated/gen_surface_property.h"
  14. #include "api/api_common.h"
  15. #include "bng/bng_defines.h"
  16. #include "api/complex.h"
  17. namespace MCell {
  18. namespace API {
  19. class SurfaceProperty: public GenSurfaceProperty {
  20. public:
  21. SURFACE_PROPERTY_CTOR()
  22. void postprocess_in_ctor() override {
  23. set_all_custom_attributes_to_default();
  24. }
  25. void set_all_custom_attributes_to_default() override {
  26. rxn_rule_id = BNG::RXN_RULE_ID_INVALID;
  27. }
  28. void check_semantics() const override {
  29. GenSurfaceProperty::check_semantics();
  30. // all checks are done in SurfaceClass::check_semantics that calls
  31. // check_semantics_custom
  32. }
  33. void check_semantics_custom() const {
  34. GenSurfaceProperty::check_semantics();
  35. if (type == SurfacePropertyType::UNSET) {
  36. throw ValueError(S("Attribute '") + NAME_TYPE + "' of " +
  37. NAME_CLASS_SURFACE_PROPERTY + " objects contained in " + NAME_CLASS_SURFACE_CLASS + " must be set.");
  38. }
  39. if (!is_set(affected_complex_pattern) && type != SurfacePropertyType::REACTIVE) {
  40. throw ValueError(S("Attribute '") + NAME_AFFECTED_COMPLEX_PATTERN + "' of " +
  41. NAME_CLASS_SURFACE_PROPERTY + " objects contained in " + NAME_CLASS_SURFACE_CLASS + " must be set when " +
  42. NAME_TYPE + " is different from " + NAME_ENUM_SURFACE_PROPERTY_TYPE + "." + NAME_EV_REACTIVE + ".");
  43. }
  44. if (is_set(affected_complex_pattern) && type == SurfacePropertyType::REACTIVE) {
  45. throw ValueError(S("Attribute '") + NAME_AFFECTED_COMPLEX_PATTERN + "' of " +
  46. NAME_CLASS_SURFACE_PROPERTY + " objects contained in " + NAME_CLASS_SURFACE_CLASS + " must not be set when " +
  47. NAME_TYPE + " is " + NAME_ENUM_SURFACE_PROPERTY_TYPE + "." + NAME_EV_REACTIVE + ".");
  48. }
  49. if (is_set(affected_complex_pattern) && is_set(affected_complex_pattern->compartment_name)) {
  50. throw ValueError(S("Attribute '") + NAME_AFFECTED_COMPLEX_PATTERN + "' of " +
  51. NAME_CLASS_SURFACE_PROPERTY + " must not have a compartment specified.");
  52. }
  53. if ((type == SurfacePropertyType::CONCENTRATION_CLAMP || type == SurfacePropertyType::FLUX_CLAMP) &&
  54. !is_set(concentration)) {
  55. throw ValueError(S("When ") + NAME_TYPE + " in " + NAME_CLASS_SURFACE_PROPERTY + " is " +
  56. NAME_ENUM_SURFACE_PROPERTY_TYPE + "." + NAME_EV_CONCENTRATION_CLAMP + " or " +
  57. NAME_ENUM_SURFACE_PROPERTY_TYPE + "." + NAME_EV_FLUX_CLAMP +
  58. " then " + NAME_CONCENTRATION + " must be set.");
  59. }
  60. }
  61. // needed when defining a set of SurfaceProperty(s)
  62. bool operator < (const SurfaceProperty& other) const {
  63. if (type != other.type) {
  64. return type < other.type;
  65. }
  66. if (concentration != other.concentration) {
  67. return concentration < other.concentration;
  68. }
  69. return affected_complex_pattern->get_canonical_name() <
  70. other.affected_complex_pattern->get_canonical_name();
  71. }
  72. BNG::rxn_rule_id_t rxn_rule_id;
  73. };
  74. } // namespace API
  75. } // namespace MCell
  76. #endif // API_SURFACE_PROPERTY_H