82 return {std::min(types[0], types[1]), std::max(types[0], types[1])};
95 if (method ==
"reset") {
96 if (not
context()->is_head_node()) {
99 auto const max_type = m_handle->get_max_seen_particle_type();
100 auto const obj_params =
VariantMap{{
"notify",
false}};
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);
109 call_method(
"internal_global_on_non_bonded_ia_change", {});
112 if (method ==
"get_handle") {
114 auto const [type_min, type_max] = get_key(params.at(
"key"));
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()) {
121 auto const key = m_handle->get_ia_param_key(type_min, type_max);
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;
128 call_method(
"internal_attach", {{
"key", params.at(
"key")}, {
"obj", so}});
131 if (method ==
"internal_set_max_type") {
132 m_handle->make_particle_type_exist(
get_value<int>(params,
"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"));
139 auto const cb_register =
140 [
this, i, j](std::shared_ptr<::IA_parameters>
const &core_ia) {
141 m_handle->set_ia_param(i, j, core_ia);
143 so->attach(cb_register, m_notify_cutoff_change);
146 if (method ==
"internal_global_on_non_bonded_ia_change") {
156 auto const max_type = m_handle->get_max_seen_particle_type();
157 std::vector<std::string> object_states;
159 for (
int i = 0; i <= max_type; i++) {
160 for (
int j = 0; j <= i; j++) {
161 auto const key = m_handle->get_ia_param_key(i, j);
162 if (m_nonbonded_ia_params.contains(key)) {
163 object_states.emplace_back(
164 m_nonbonded_ia_params.at(key)->serialize());
166 object_states.emplace_back(
"");
177 call_method(
"internal_set_max_type", {{
"max_type", max_type}});
178 auto const end = object_states.end();
179 auto it = object_states.begin() + 1;
180 for (
int i = 0; i <= max_type; i++) {
181 for (
int j = 0; j <= i; j++) {
182 auto const key = m_handle->get_ia_param_key(i, j);
183 auto const &buffer = *it;
184 if (not buffer.empty()) {
185 auto so = std::dynamic_pointer_cast<NonBondedInteractionHandle>(
187 m_nonbonded_ia_params[key] = so;
189 {{
"key", std::vector<int>{{j, i}}}, {
"obj", so}});