36#include <boost/algorithm/string/predicate.hpp>
37#include <boost/variant.hpp>
54namespace Interactions {
62 std::shared_ptr<const ::Bonded_IA_Parameters>
bonded_ia()
const {
73 std::transform(
vec.begin(),
vec.end(),
75 [](
auto const &
key) { return std::string{key}; });
81 auto const valid_keys = get_valid_parameters();
84 throw std::runtime_error(
"Parameter '" +
key +
"' is missing");
87 for (
auto const &kv :
params) {
89 throw std::runtime_error(
"Parameter '" + kv.first +
90 "' is not recognized");
96 context()->parallel_try_catch([&]() {
97 check_valid_parameters(
params);
106 return m_bonded_ia ==
other.m_bonded_ia;
112 if (name ==
"is_same_bond") {
117 if (name ==
"get_num_partners") {
129 return boost::get<CoreBondedInteraction>(*bonded_ia());
137 {
"k", AutoParameter::read_only, [
this]() {
return get_struct().k; }},
138 {
"d_r_max", AutoParameter::read_only,
139 [
this]() {
return get_struct().drmax; }},
140 {
"r_0", AutoParameter::read_only, [
this]() {
return get_struct().r0; }},
146 m_bonded_ia = std::make_shared<::Bonded_IA_Parameters>(
148 get_value<double>(
params,
"d_r_max"),
149 get_value<double>(
params,
"r_0")));
157 {
"k", AutoParameter::read_only, [
this]() {
return get_struct().k; }},
158 {
"r_0", AutoParameter::read_only, [
this]() {
return get_struct().r; }},
159 {
"r_cut", AutoParameter::read_only,
160 [
this]() {
return get_struct().r_cut; }},
168 get_value<double>(
params,
"k"), get_value<double>(
params,
"r_0"),
169 get_value<double>(
params,
"r_cut")));
177 {
"k0", AutoParameter::read_only, [
this]() {
return get_struct().k0; }},
178 {
"k1", AutoParameter::read_only, [
this]() {
return get_struct().k1; }},
179 {
"r", AutoParameter::read_only, [
this]() {
return get_struct().r; }},
180 {
"r_cut", AutoParameter::read_only,
181 [
this]() {
return get_struct().r_cut; }},
189 get_value<double>(
params,
"k0"), get_value<double>(
params,
"k1"),
190 get_value<double>(
params,
"r"),
191 get_value<double>(
params,
"r_cut")));
199 {
"prefactor", AutoParameter::read_only,
200 [
this]() {
return get_struct().prefactor; }},
206 m_bonded_ia = std::make_shared<::Bonded_IA_Parameters>(
215 {
"q1q2", AutoParameter::read_only,
216 [
this]() {
return get_struct().q1q2; }},
222 m_bonded_ia = std::make_shared<::Bonded_IA_Parameters>(
231 {
"bend", AutoParameter::read_only,
232 [
this]() {
return get_struct().bend; }},
233 {
"phi0", AutoParameter::read_only,
234 [
this]() {
return get_struct().phi0; }},
240 m_bonded_ia = std::make_shared<::Bonded_IA_Parameters>(
242 get_value<double>(
params,
"phi0")));
250 {
"bend", AutoParameter::read_only,
251 [
this]() {
return get_struct().bend; }},
252 {
"phi0", AutoParameter::read_only,
253 [
this]() {
return get_struct().phi0; }},
259 m_bonded_ia = std::make_shared<::Bonded_IA_Parameters>(
261 get_value<double>(
params,
"phi0")));
269 {
"bend", AutoParameter::read_only,
270 [
this]() {
return get_struct().bend; }},
271 {
"phi0", AutoParameter::read_only,
272 [
this]() {
return get_struct().phi0; }},
278 m_bonded_ia = std::make_shared<::Bonded_IA_Parameters>(
280 get_value<double>(
params,
"phi0")));
288 {
"mult", AutoParameter::read_only,
289 [
this]() {
return get_struct().mult; }},
290 {
"bend", AutoParameter::read_only,
291 [
this]() {
return get_struct().bend; }},
292 {
"phase", AutoParameter::read_only,
293 [
this]() {
return get_struct().phase; }},
301 get_value<int>(
params,
"mult"), get_value<double>(
params,
"bend"),
302 get_value<double>(
params,
"phase")));
311 {
"min", AutoParameter::read_only,
312 [
this]() {
return get_struct().pot->minval; }},
313 {
"max", AutoParameter::read_only,
314 [
this]() {
return get_struct().pot->maxval; }},
315 {
"energy", AutoParameter::read_only,
316 [
this]() {
return get_struct().pot->energy_tab; }},
317 {
"force", AutoParameter::read_only,
318 [
this]() {
return get_struct().pot->force_tab; }},
326 get_value<double>(
params,
"min"), get_value<double>(
params,
"max"),
327 get_value<std::vector<double>>(
params,
"energy"),
328 get_value<std::vector<double>>(
params,
"force")));
336 {
"min", AutoParameter::read_only,
337 [
this]() {
return get_struct().pot->minval; }},
338 {
"max", AutoParameter::read_only,
339 [
this]() {
return get_struct().pot->maxval; }},
340 {
"energy", AutoParameter::read_only,
341 [
this]() {
return get_struct().pot->energy_tab; }},
342 {
"force", AutoParameter::read_only,
343 [
this]() {
return get_struct().pot->force_tab; }},
351 get_value<double>(
params,
"min"), get_value<double>(
params,
"max"),
352 get_value<std::vector<double>>(
params,
"energy"),
353 get_value<std::vector<double>>(
params,
"force")));
362 {
"min", AutoParameter::read_only,
363 [
this]() {
return get_struct().pot->minval; }},
364 {
"max", AutoParameter::read_only,
365 [
this]() {
return get_struct().pot->maxval; }},
366 {
"energy", AutoParameter::read_only,
367 [
this]() {
return get_struct().pot->energy_tab; }},
368 {
"force", AutoParameter::read_only,
369 [
this]() {
return get_struct().pot->force_tab; }},
377 get_value<double>(
params,
"min"), get_value<double>(
params,
"max"),
378 get_value<std::vector<double>>(
params,
"energy"),
379 get_value<std::vector<double>>(
params,
"force")));
387 {
"temp_com", AutoParameter::read_only,
388 [
this]() {
return get_struct().temp_com; }},
389 {
"gamma_com", AutoParameter::read_only,
390 [
this]() {
return get_struct().gamma_com; }},
391 {
"temp_distance", AutoParameter::read_only,
392 [
this]() {
return get_struct().temp_distance; }},
393 {
"gamma_distance", AutoParameter::read_only,
394 [
this]() {
return get_struct().gamma_distance; }},
395 {
"r_cut", AutoParameter::read_only,
396 [
this]() {
return get_struct().r_cut; }},
402 m_bonded_ia = std::make_shared<::Bonded_IA_Parameters>(
404 get_value<double>(
params,
"gamma_com"),
405 get_value<double>(
params,
"temp_distance"),
406 get_value<double>(
params,
"gamma_distance"),
407 get_value<double>(
params,
"r_cut")));
415 {
"r", AutoParameter::read_only,
416 [
this]() {
return std::sqrt(get_struct().d2); }},
417 {
"ptol", AutoParameter::read_only,
418 [
this]() {
return 0.5 * get_struct().p_tol; }},
419 {
"vtol", AutoParameter::read_only,
420 [
this]() {
return get_struct().v_tol; }},
428 get_value<double>(
params,
"r"), get_value<double>(
params,
"ptol"),
429 get_value<double>(
params,
"vtol")));
437 {
"k1", AutoParameter::read_only, [
this]() {
return get_struct().k1; }},
438 {
"k2", AutoParameter::read_only, [
this]() {
return get_struct().k2; }},
439 {
"ind1", AutoParameter::read_only,
440 [
this]() {
return std::get<0>(get_struct().p_ids); }},
441 {
"ind2", AutoParameter::read_only,
442 [
this]() {
return std::get<1>(get_struct().p_ids); }},
443 {
"ind3", AutoParameter::read_only,
444 [
this]() {
return std::get<2>(get_struct().p_ids); }},
445 {
"maxDist", AutoParameter::read_only,
446 [
this]() {
return get_struct().maxDist; }},
447 {
"elasticLaw", AutoParameter::read_only,
450 return std::string(
"NeoHookean");
452 return std::string(
"Skalak");
454 {
"is_initialized", AutoParameter::read_only,
455 [
this]() {
return get_struct().is_initialized; }},
456 {
"_cache", AutoParameter::read_only,
458 auto &s = get_struct();
459 return std::vector<double>{{s.l0, s.lp0, s.sinPhi0, s.cosPhi0,
460 s.area0, s.a1, s.a2, s.b1, s.b2}};
467 auto const law_name = get_value<std::string>(
params,
"elasticLaw");
469 if (law_name ==
"NeoHookean") {
471 }
else if (law_name ==
"Skalak") {
474 throw std::invalid_argument(
475 "Invalid value for parameter 'elasticLaw': '" + law_name +
"'");
478 get_value<int>(
params,
"ind1"), get_value<int>(
params,
"ind2"),
479 get_value<int>(
params,
"ind3"), get_value<double>(
params,
"maxDist"),
480 elastic_law, get_value<double>(
params,
"k1"),
481 get_value<double>(
params,
"k2"));
482 if (get_value_or<bool>(
params,
"is_initialized",
false)) {
483 auto const cache = get_value<std::vector<double>>(
params,
"_cache");
484 assert(cache.size() == 9ul);
487 bond.sinPhi0 = cache[2];
488 bond.cosPhi0 = cache[3];
489 bond.area0 = cache[4];
494 bond.is_initialized =
true;
496 m_bonded_ia = std::make_shared<::Bonded_IA_Parameters>(std::move(bond));
504 {
"softID", AutoParameter::read_only,
505 [
this]() {
return static_cast<int>(get_struct().softID); }},
506 {
"kappaV", AutoParameter::read_only,
507 [
this]() {
return get_struct().kappaV; }},
513 if (name ==
"current_volume") {
514 return get_struct().get_current_volume();
516 return BondedInteraction::do_call_method(name,
params);
521 m_bonded_ia = std::make_shared<::Bonded_IA_Parameters>(
523 get_value<double>(
params,
"kappaV")));
531 {
"kb", AutoParameter::read_only, [
this]() {
return get_struct().kb; }},
532 {
"ind1", AutoParameter::read_only,
533 [
this]() {
return std::get<0>(get_struct().p_ids); }},
534 {
"ind2", AutoParameter::read_only,
535 [
this]() {
return std::get<1>(get_struct().p_ids); }},
536 {
"ind3", AutoParameter::read_only,
537 [
this]() {
return std::get<2>(get_struct().p_ids); }},
538 {
"ind4", AutoParameter::read_only,
539 [
this]() {
return std::get<3>(get_struct().p_ids); }},
540 {
"refShape", AutoParameter::read_only,
542 return std::string((get_struct().flat) ?
"Flat" :
"Initial");
544 {
"theta0", AutoParameter::read_only,
545 [
this]() {
return get_struct().theta0; }},
546 {
"is_initialized", AutoParameter::read_only,
547 [
this]() {
return get_struct().is_initialized; }},
553 auto const shape_name = get_value<std::string>(
params,
"refShape");
555 if (shape_name ==
"Flat") {
557 }
else if (shape_name ==
"Initial") {
560 throw std::invalid_argument(
"Invalid value for parameter 'refShape': '" +
564 get_value<int>(
params,
"ind1"), get_value<int>(
params,
"ind2"),
565 get_value<int>(
params,
"ind3"), get_value<int>(
params,
"ind4"),
566 get_value<double>(
params,
"kb"), flat);
567 if (get_value_or<bool>(
params,
"is_initialized",
false)) {
568 bond.theta0 = get_value<double>(
params,
"theta0");
569 bond.is_initialized =
true;
571 m_bonded_ia = std::make_shared<::Bonded_IA_Parameters>(std::move(bond));
580 {
"A0_g", AutoParameter::read_only,
581 [
this]() {
return get_struct().A0_g; }},
582 {
"ka_g", AutoParameter::read_only,
583 [
this]() {
return get_struct().ka_g; }},
584 {
"V0", AutoParameter::read_only, [
this]() {
return get_struct().V0; }},
585 {
"kv", AutoParameter::read_only, [
this]() {
return get_struct().kv; }},
593 get_value<double>(
params,
"A0_g"),
594 get_value<double>(
params,
"ka_g"), get_value<double>(
params,
"V0"),
595 get_value<double>(
params,
"kv")));
603 {
"r0", AutoParameter::read_only, [
this]() {
return get_struct().r0; }},
604 {
"ks", AutoParameter::read_only, [
this]() {
return get_struct().ks; }},
605 {
"kslin", AutoParameter::read_only,
606 [
this]() {
return get_struct().kslin; }},
607 {
"phi0", AutoParameter::read_only,
608 [
this]() {
return get_struct().phi0; }},
609 {
"kb", AutoParameter::read_only, [
this]() {
return get_struct().kb; }},
610 {
"A01", AutoParameter::read_only,
611 [
this]() {
return get_struct().A01; }},
612 {
"A02", AutoParameter::read_only,
613 [
this]() {
return get_struct().A02; }},
614 {
"kal", AutoParameter::read_only,
615 [
this]() {
return get_struct().kal; }},
616 {
"kvisc", AutoParameter::read_only,
617 [
this]() {
return get_struct().kvisc; }},
625 get_value<double>(
params,
"r0"), get_value<double>(
params,
"ks"),
626 get_value<double>(
params,
"kslin"),
627 get_value<double>(
params,
"phi0"), get_value<double>(
params,
"kb"),
628 get_value<double>(
params,
"A01"), get_value<double>(
params,
"A02"),
629 get_value<double>(
params,
"kal"),
630 get_value<double>(
params,
"kvisc")));
Data structures for bonded interactions.
int number_of_partners(Bonded_IA_Parameters const &iaparams)
Get the number of bonded partners for the specified bond.
Bind parameters in the script interface.
std::span< const boost::string_ref > valid_parameters() const final
void construct_bond(VariantMap const ¶ms) override
void construct_bond(VariantMap const ¶ms) override
void construct_bond(VariantMap const ¶ms) override
void construct_bond(VariantMap const ¶ms) override
void construct_bond(VariantMap const ¶ms) override
CoreBondedInteraction & get_struct()
CoreIA CoreBondedInteraction
virtual std::set< std::string > get_valid_parameters() const
std::shared_ptr<::Bonded_IA_Parameters > m_bonded_ia
bool operator==(BondedInteraction const &other) const
std::shared_ptr< const ::Bonded_IA_Parameters > bonded_ia() const
void do_construct(VariantMap const ¶ms) override
virtual void construct_bond(VariantMap const ¶ms)=0
std::shared_ptr<::Bonded_IA_Parameters > bonded_ia()
Variant do_call_method(std::string const &name, VariantMap const ¶ms) override
void construct_bond(VariantMap const ¶ms) override
void construct_bond(VariantMap const ¶ms) override
void construct_bond(VariantMap const ¶ms) override
void construct_bond(VariantMap const ¶ms) override
void construct_bond(VariantMap const ¶ms) override
Variant do_call_method(std::string const &name, VariantMap const ¶ms) override
void construct_bond(VariantMap const ¶ms) override
void construct_bond(VariantMap const ¶ms) override
void construct_bond(VariantMap const ¶ms) override
void construct_bond(VariantMap const ¶ms) override
void construct_bond(VariantMap const ¶ms) override
void construct_bond(VariantMap const ¶ms) override
void construct_bond(VariantMap const ¶ms) override
void construct_bond(VariantMap const ¶ms) override
void construct_bond(VariantMap const ¶ms) override
void construct_bond(VariantMap const &) override
Context * context() const
Responsible context.
Implementation in thermostat.cpp.
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.
static SteepestDescentParameters params
Currently active steepest descent instance.