ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
script_interface/collision_detection/CollisionDetection.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2024 The ESPResSo project
3 * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010
4 * Max-Planck-Institute for Polymer Research, Theory Group
5 *
6 * This file is part of ESPResSo.
7 *
8 * ESPResSo is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * ESPResSo is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24#include <config/config.hpp>
25
26#ifdef COLLISION_DETECTION
27
28#include "Protocol.hpp"
29
35
38
39#include <memory>
40
42
44 : public AutoParameters<CollisionDetection, System::Leaf> {
45 std::shared_ptr<::CollisionDetection::CollisionDetection> m_handle;
46 std::unique_ptr<VariantMap> m_params;
47 std::shared_ptr<Protocol> m_protocol;
48 std::weak_ptr<::BondedInteractionsMap> m_bonded_ias;
49 std::weak_ptr<Interactions::BondedInteractions> m_so_bonded_ias;
50
51public:
54 {{"protocol",
55 [this](Variant const &value) {
56 if (is_none(value)) {
57 m_protocol = nullptr;
58 m_handle->unset_protocol();
59 return;
60 }
61 auto const m_protocol_backup = m_protocol;
62 try {
64 m_protocol = get_value<std::shared_ptr<Protocol>>(value);
65 m_protocol->bind_bonded_ias(m_bonded_ias, m_so_bonded_ias);
66 m_handle->set_protocol(m_protocol->protocol());
67 });
68 } catch (...) {
69 m_protocol = m_protocol_backup;
70 if (m_protocol) {
71 m_handle->set_protocol(m_protocol->protocol());
72 } else {
73 m_protocol = nullptr;
74 m_handle->unset_protocol();
75 }
76 throw;
77 }
78 },
79 [this]() {
80 if (m_protocol)
81 return make_variant(m_protocol);
82 return make_variant(none);
83 }}});
84 }
85
86 void do_construct(VariantMap const &params) override {
87 m_params = std::make_unique<VariantMap>(params);
88 }
89
90 void on_bind_system(::System::System &system) override {
91 m_handle = system.collision_detection;
92 m_handle->bind_system(m_system.lock());
93 m_bonded_ias = system.bonded_ias;
94 }
95
96 void attach(std::weak_ptr<Interactions::BondedInteractions> bonded_ias) {
97 m_so_bonded_ias = bonded_ias;
98 if (m_params) {
100 m_params.reset();
101 }
102 }
103};
104
105} // namespace ScriptInterface::CollisionDetection
106
107#endif // COLLISION_DETECTION
The ScriptInterface counterparts of the bonded interactions parameters structs from the core are defi...
Data structures for bonded interactions.
Bind parameters in the script interface.
void attach(std::weak_ptr< Interactions::BondedInteractions > bonded_ias)
virtual void parallel_try_catch(std::function< void()> const &cb) const =0
virtual void do_construct(VariantMap const &params)
Context * context() const
Responsible context.
std::weak_ptr<::System::System > m_system
Main system class.
std::shared_ptr< BondedInteractionsMap > bonded_ias
std::shared_ptr< CollisionDetection::CollisionDetection > collision_detection
This file contains the defaults for ESPResSo.
std::unordered_map< std::string, Variant > VariantMap
Definition Variant.hpp:69
Variant make_variant(const T &x)
Make a Variant from argument.
Definition Variant.hpp:77
boost::make_recursive_variant< None, bool, int, std::size_t, double, std::string, ObjectRef, Utils::Vector3b, Utils::Vector3i, Utils::Vector2d, Utils::Vector3d, Utils::Vector4d, std::vector< int >, std::vector< double >, std::vector< boost::recursive_variant_ >, std::unordered_map< int, boost::recursive_variant_ >, std::unordered_map< std::string, boost::recursive_variant_ > >::type Variant
Possible types for parameters.
Definition Variant.hpp:67
bool is_none(Variant const &v)
Definition Variant.hpp:115
constexpr const None none
None-"literal".
Definition Variant.hpp:50
static SteepestDescentParameters params
Currently active steepest descent instance.