37#include <unordered_map>
42namespace Interactions {
45 using container_type =
46 std::unordered_map<
unsigned int,
47 std::shared_ptr<NonBondedInteractionHandle>>;
50 using key_type =
typename container_type::key_type;
54 container_type m_nonbonded_ia_params;
55 std::shared_ptr<::InteractionsNonBonded> m_handle;
56 std::shared_ptr<std::function<
void()>> m_notify_cutoff_change;
59 m_handle = std::make_shared<::InteractionsNonBonded>();
60 m_notify_cutoff_change = std::make_shared<std::function<
void()>>([]() {});
64 auto const max_type = m_handle->get_max_seen_particle_type();
65 system.nonbonded_ias = m_handle;
66 m_handle->make_particle_type_exist(
max_type);
67 m_handle->bind_system(
m_system.lock());
68 m_handle->on_non_bonded_ia_change();
69 *m_notify_cutoff_change = [
this]() {
71 m_handle->on_non_bonded_ia_change();
76 std::pair<int, int> get_key(
Variant const &
key)
const {
80 throw Exception(
"need two particle types");
84 if (
context()->is_head_node()) {
85 throw std::invalid_argument(
86 "NonBondedInteractions[] expects two particle types as indices");
99 auto const max_type = m_handle->get_max_seen_particle_type();
101 for (
int i = 0; i <=
max_type; i++) {
102 for (
int j = 0;
j <= i;
j++) {
103 auto const key = m_handle->get_ia_param_key(i,
j);
104 if (m_nonbonded_ia_params.contains(
key)) {
105 m_nonbonded_ia_params.at(
key)->call_method(
"reset",
obj_params);
112 if (
method ==
"get_handle") {
115 if (
type_max > m_handle->get_max_seen_particle_type()) {
116 m_handle->make_particle_type_exist(
type_max);
118 if (
not ctx->is_head_node()) {
122 if (m_nonbonded_ia_params.contains(
key)) {
123 return m_nonbonded_ia_params.at(
key);
125 auto so = std::dynamic_pointer_cast<NonBondedInteractionHandle>(
126 ctx->make_shared(
"Interactions::NonBondedInteractionHandle", {}));
127 m_nonbonded_ia_params[
key] =
so;
131 if (
method ==
"internal_set_max_type") {
135 if (
method ==
"internal_attach") {
136 auto so = std::dynamic_pointer_cast<NonBondedInteractionHandle>(
138 auto const [i,
j] = get_key(
params.at(
"key"));
140 [
this, i,
j](std::shared_ptr<::IA_parameters>
const &
core_ia) {
141 m_handle->set_ia_param(i,
j,
core_ia);
151 auto const max_type = m_handle->get_max_seen_particle_type();
154 for (
int i = 0; i <=
max_type; i++) {
155 for (
int j = 0;
j <= i;
j++) {
156 auto const key = m_handle->get_ia_param_key(i,
j);
157 if (m_nonbonded_ia_params.contains(
key)) {
159 m_nonbonded_ia_params.at(
key)->serialize());
175 for (
int i = 0; i <=
max_type; i++) {
176 for (
int j = 0;
j <= i;
j++) {
177 auto const key = m_handle->get_ia_param_key(i,
j);
180 auto so = std::dynamic_pointer_cast<NonBondedInteractionHandle>(
182 m_nonbonded_ia_params[
key] =
so;
184 {{
"key", std::vector<int>{{
j, i}}}, {
"obj",
so}});
The ScriptInterface counterparts of the non-bonded interactions parameters structs from the core are ...
void set_internal_state(std::string const &state) override
typename container_type::mapped_type mapped_type
std::string get_internal_state() const override
typename container_type::key_type key_type
void on_bind_system(::System::System &system) override
void do_construct(VariantMap const ¶ms) override
Variant do_call_method(std::string const &method, VariantMap const ¶ms) override
Variant call_method(const std::string &name, const VariantMap ¶ms)
Call a method on the object.
Context * context() const
Responsible context.
static ObjectRef deserialize(const std::string &state, Context &ctx)
Make object from serialized state.
Script interface wrapper for a component of the system class.
auto const & get_system() const
std::weak_ptr<::System::System > m_system
T get_value(Variant const &v)
Extract value of specific type T from a Variant.
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.
std::string pack(T const &v)
Pack a serialize type into a string.
Various procedures concerning interactions between particles.
static SteepestDescentParameters params
Currently active steepest descent instance.