35#include <unordered_map>
40namespace Interactions {
48 using container_type =
49 std::unordered_map<int, std::shared_ptr<BondedInteraction>>;
52 using key_type =
typename container_type::key_type;
56 container_type m_bonds;
57 std::shared_ptr<::BondedInteractionsMap> m_handle;
58 std::unique_ptr<VariantMap> m_params;
61 m_handle = std::make_shared<::BondedInteractionsMap>();
62 m_params = std::make_unique<VariantMap>(
params);
67 m_handle->bind_system(m_system.lock());
68 m_handle->on_ia_change();
69 if (m_params and not m_params->empty()) {
77 context()->parallel_try_catch(
78 [&]() { key = m_handle->insert(obj_ptr->bonded_ia()); });
79 m_bonds[key] = std::move(obj_ptr);
85 context()->parallel_try_catch(
86 [&]() { m_handle->insert(key, obj_ptr->bonded_ia()); });
87 m_bonds[key] = std::move(obj_ptr);
98 if (name ==
"get_size") {
99 return {
static_cast<int>(m_handle->size())};
102 if (name ==
"get_bond_ids") {
103 std::vector<int> bond_ids;
104 for (
auto const &kv : *m_handle)
105 bond_ids.push_back(kv.first);
109 if (name ==
"has_bond") {
111 return {m_bonds.contains(bond_id)};
114 if (name ==
"get_bond") {
117 assert(m_bonds.count(bond_id) == m_handle->count(bond_id));
118 if (not context()->is_head_node())
121 if (not m_bonds.contains(bond_id)) {
122 throw std::out_of_range(
"The bond with id " + std::to_string(bond_id) +
123 " is not yet defined.");
125 return {m_bonds.at(bond_id)};
128 if (name ==
"get_zero_based_type") {
130 return m_handle->get_zero_based_type(bond_id);
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 insert_in_core(key_type const &key, mapped_type const &obj_ptr) override
Variant do_call_method(std::string const &name, VariantMap const ¶ms) override
typename container_type::key_type key_type
void erase_in_core(key_type const &key) override
void do_construct(VariantMap const ¶ms) override
void on_bind_system(::System::System &system) override
key_type insert_in_core(mapped_type const &obj_ptr) override
typename container_type::mapped_type mapped_type
Owning map of ObjectHandles.
KeyType get_key(Variant const &key) const
void restore_from_checkpoint(VariantMap const ¶ms)
Variant do_call_method(std::string const &method, VariantMap const ¶meters) override
Script interface wrapper for a component of the system class.
std::shared_ptr< BondedInteractionsMap > bonded_ias
ObjectMap< BondedInteraction, AutoParameters< ObjectMap< BondedInteraction, System::Leaf >, System::Leaf > > BondedInteractionsBase_t
std::unordered_map< std::string, Variant > VariantMap
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.
static SteepestDescentParameters params
Currently active steepest descent instance.