elementary_molecule.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #include "api/elementary_molecule.h"
  12. #include "api/elementary_molecule_type.h"
  13. #include "api/component_type.h"
  14. #include "api/component.h"
  15. #include "api/complex.h"
  16. using namespace std;
  17. namespace MCell {
  18. namespace API {
  19. bool ElementaryMolecule::__eq__(const ElementaryMolecule& other) const {
  20. // do we have the same mol type?
  21. if (!eq_nonarray_attributes(other)) {
  22. return false;
  23. }
  24. string c1 = is_set(compartment_name) ? compartment_name : "";
  25. string c2 = is_set(other.compartment_name) ? other.compartment_name : "";
  26. if (c1 != c2) {
  27. return false;
  28. }
  29. // are components the same (order does not matter)
  30. std::set<Component> s1;
  31. for (auto& c: components) {
  32. s1.insert(*c);
  33. }
  34. std::set<Component> s2;
  35. for (auto& c: other.components) {
  36. s2.insert(*c);
  37. }
  38. return s1 == s2;
  39. }
  40. std::string ElementaryMolecule::to_bngl_str(const bool with_compartment) const {
  41. std::string res;
  42. res = elementary_molecule_type->name;
  43. if (!components.empty()) {
  44. res += "(";
  45. for (size_t i = 0; i < components.size(); i++) {
  46. res += components[i]->to_bngl_str();
  47. if (i + 1 != components.size()) {
  48. res += ",";
  49. }
  50. }
  51. res += ")";
  52. }
  53. if (with_compartment && is_set(compartment_name)) {
  54. res += "@" + compartment_name;
  55. }
  56. return res;
  57. }
  58. bool ElementaryMolecule::is_surf() const {
  59. assert(is_set(elementary_molecule_type));
  60. return is_set(elementary_molecule_type->diffusion_constant_2d);
  61. }
  62. } // namespace API
  63. } // namespace MCell