36#include <boost/algorithm/string/predicate.hpp>
37#include <boost/variant.hpp>
52namespace Interactions {
60 std::shared_ptr<const ::Bonded_IA_Parameters>
bonded_ia()
const {
70 auto valid_keys = std::set<std::string>();
71 std::transform(vec.begin(), vec.end(),
72 std::inserter(valid_keys, valid_keys.begin()),
73 [](
auto const &key) { return std::string{key}; });
79 auto const valid_keys = get_valid_parameters();
80 for (
auto const &key : valid_keys) {
81 if (
params.count(std::string(key)) == 0) {
82 throw std::runtime_error(
"Parameter '" + key +
"' is missing");
85 for (
auto const &kv :
params) {
86 if (valid_keys.count(kv.first) == 0) {
87 throw std::runtime_error(
"Parameter '" + kv.first +
88 "' is not recognized");
96 auto const bond_id = get_value<int>(
params,
"bond_id");
97 context()->parallel_try_catch([&]() {
98 if (not ::bonded_ia_params.contains(bond_id)) {
99 throw std::runtime_error(
"No bond with id " +
100 std::to_string(bond_id) +
101 " exists in the ESPResSo core");
106 context()->parallel_try_catch([&]() {
107 check_valid_parameters(
params);
123 if (name ==
"is_same_bond") {
125 get_value<std::shared_ptr<BondedInteraction>>(
params,
"bond");
126 return *
this == *bond_so;
128 if (name ==
"get_num_partners") {
131 if (name ==
"get_zero_based_type") {
132 auto const bond_id = get_value<int>(
params,
"bond_id");
133 return ::bonded_ia_params.get_zero_based_type(bond_id);
144 return boost::get<CoreBondedInteraction>(*bonded_ia());
152 {
"k", AutoParameter::read_only, [
this]() {
return get_struct().k; }},
153 {
"d_r_max", AutoParameter::read_only,
154 [
this]() {
return get_struct().drmax; }},
155 {
"r_0", AutoParameter::read_only, [
this]() {
return get_struct().r0; }},
161 m_bonded_ia = std::make_shared<::Bonded_IA_Parameters>(
163 get_value<double>(
params,
"d_r_max"),
164 get_value<double>(
params,
"r_0")));
172 {
"k", AutoParameter::read_only, [
this]() {
return get_struct().k; }},
173 {
"r_0", AutoParameter::read_only, [
this]() {
return get_struct().r; }},
174 {
"r_cut", AutoParameter::read_only,
175 [
this]() {
return get_struct().r_cut; }},
183 get_value<double>(
params,
"k"), get_value<double>(
params,
"r_0"),
184 get_value<double>(
params,
"r_cut")));
192 {
"k0", AutoParameter::read_only, [
this]() {
return get_struct().k0; }},
193 {
"k1", AutoParameter::read_only, [
this]() {
return get_struct().k1; }},
194 {
"r", AutoParameter::read_only, [
this]() {
return get_struct().r; }},
195 {
"r_cut", AutoParameter::read_only,
196 [
this]() {
return get_struct().r_cut; }},
204 get_value<double>(
params,
"k0"), get_value<double>(
params,
"k1"),
205 get_value<double>(
params,
"r"),
206 get_value<double>(
params,
"r_cut")));
214 {
"prefactor", AutoParameter::read_only,
215 [
this]() {
return get_struct().prefactor; }},
221 m_bonded_ia = std::make_shared<::Bonded_IA_Parameters>(
230 {
"q1q2", AutoParameter::read_only,
231 [
this]() {
return get_struct().q1q2; }},
237 m_bonded_ia = std::make_shared<::Bonded_IA_Parameters>(
246 {
"bend", AutoParameter::read_only,
247 [
this]() {
return get_struct().bend; }},
248 {
"phi0", AutoParameter::read_only,
249 [
this]() {
return get_struct().phi0; }},
255 m_bonded_ia = std::make_shared<::Bonded_IA_Parameters>(
257 get_value<double>(
params,
"phi0")));
265 {
"bend", AutoParameter::read_only,
266 [
this]() {
return get_struct().bend; }},
267 {
"phi0", AutoParameter::read_only,
268 [
this]() {
return get_struct().phi0; }},
274 m_bonded_ia = std::make_shared<::Bonded_IA_Parameters>(
276 get_value<double>(
params,
"phi0")));
284 {
"bend", AutoParameter::read_only,
285 [
this]() {
return get_struct().bend; }},
286 {
"phi0", AutoParameter::read_only,
287 [
this]() {
return get_struct().phi0; }},
293 m_bonded_ia = std::make_shared<::Bonded_IA_Parameters>(
295 get_value<double>(
params,
"phi0")));
303 {
"mult", AutoParameter::read_only,
304 [
this]() {
return get_struct().mult; }},
305 {
"bend", AutoParameter::read_only,
306 [
this]() {
return get_struct().bend; }},
307 {
"phase", AutoParameter::read_only,
308 [
this]() {
return get_struct().phase; }},
316 get_value<int>(
params,
"mult"), get_value<double>(
params,
"bend"),
317 get_value<double>(
params,
"phase")));
326 {
"min", AutoParameter::read_only,
327 [
this]() {
return get_struct().pot->minval; }},
328 {
"max", AutoParameter::read_only,
329 [
this]() {
return get_struct().pot->maxval; }},
330 {
"energy", AutoParameter::read_only,
331 [
this]() {
return get_struct().pot->energy_tab; }},
332 {
"force", AutoParameter::read_only,
333 [
this]() {
return get_struct().pot->force_tab; }},
341 get_value<double>(
params,
"min"), get_value<double>(
params,
"max"),
342 get_value<std::vector<double>>(
params,
"energy"),
343 get_value<std::vector<double>>(
params,
"force")));
351 {
"min", AutoParameter::read_only,
352 [
this]() {
return get_struct().pot->minval; }},
353 {
"max", AutoParameter::read_only,
354 [
this]() {
return get_struct().pot->maxval; }},
355 {
"energy", AutoParameter::read_only,
356 [
this]() {
return get_struct().pot->energy_tab; }},
357 {
"force", AutoParameter::read_only,
358 [
this]() {
return get_struct().pot->force_tab; }},
366 get_value<double>(
params,
"min"), get_value<double>(
params,
"max"),
367 get_value<std::vector<double>>(
params,
"energy"),
368 get_value<std::vector<double>>(
params,
"force")));
377 {
"min", AutoParameter::read_only,
378 [
this]() {
return get_struct().pot->minval; }},
379 {
"max", AutoParameter::read_only,
380 [
this]() {
return get_struct().pot->maxval; }},
381 {
"energy", AutoParameter::read_only,
382 [
this]() {
return get_struct().pot->energy_tab; }},
383 {
"force", AutoParameter::read_only,
384 [
this]() {
return get_struct().pot->force_tab; }},
392 get_value<double>(
params,
"min"), get_value<double>(
params,
"max"),
393 get_value<std::vector<double>>(
params,
"energy"),
394 get_value<std::vector<double>>(
params,
"force")));
402 {
"temp_com", AutoParameter::read_only,
403 [
this]() {
return get_struct().temp_com; }},
404 {
"gamma_com", AutoParameter::read_only,
405 [
this]() {
return get_struct().gamma_com; }},
406 {
"temp_distance", AutoParameter::read_only,
407 [
this]() {
return get_struct().temp_distance; }},
408 {
"gamma_distance", AutoParameter::read_only,
409 [
this]() {
return get_struct().gamma_distance; }},
410 {
"r_cut", AutoParameter::read_only,
411 [
this]() {
return get_struct().r_cut; }},
417 m_bonded_ia = std::make_shared<::Bonded_IA_Parameters>(
419 get_value<double>(
params,
"gamma_com"),
420 get_value<double>(
params,
"temp_distance"),
421 get_value<double>(
params,
"gamma_distance"),
422 get_value<double>(
params,
"r_cut")));
430 {
"r", AutoParameter::read_only,
431 [
this]() {
return std::sqrt(get_struct().d2); }},
432 {
"ptol", AutoParameter::read_only,
433 [
this]() {
return 0.5 * get_struct().p_tol; }},
434 {
"vtol", AutoParameter::read_only,
435 [
this]() {
return get_struct().v_tol; }},
443 get_value<double>(
params,
"r"), get_value<double>(
params,
"ptol"),
444 get_value<double>(
params,
"vtol")));
452 {
"k1", AutoParameter::read_only, [
this]() {
return get_struct().k1; }},
453 {
"k2", AutoParameter::read_only, [
this]() {
return get_struct().k2; }},
454 {
"maxDist", AutoParameter::read_only,
455 [
this]() {
return get_struct().maxDist; }},
456 {
"elasticLaw", AutoParameter::read_only,
459 return std::string(
"NeoHookean");
461 return std::string(
"Skalak");
468 auto const law_name = get_value<std::string>(
params,
"elasticLaw");
470 if (law_name ==
"NeoHookean") {
472 }
else if (law_name ==
"Skalak") {
475 throw std::invalid_argument(
476 "Invalid value for parameter 'elasticLaw': '" + law_name +
"'");
480 get_value<int>(
params,
"ind1"), get_value<int>(
params,
"ind2"),
481 get_value<int>(
params,
"ind3"),
482 get_value<double>(
params,
"maxDist"), elastic_law,
483 get_value<double>(
params,
"k1"), get_value<double>(
params,
"k2")));
489 names.insert(
"ind1");
490 names.insert(
"ind2");
491 names.insert(
"ind3");
500 {
"softID", AutoParameter::read_only,
501 [
this]() {
return get_struct().softID; }},
502 {
"kappaV", AutoParameter::read_only,
503 [
this]() {
return get_struct().kappaV; }},
509 if (name ==
"current_volume") {
510 return ::immersed_boundaries.get_current_volume(get_struct().softID);
512 return BondedInteraction::do_call_method(name,
params);
517 m_bonded_ia = std::make_shared<::Bonded_IA_Parameters>(
519 get_value<double>(
params,
"kappaV")));
527 {
"kb", AutoParameter::read_only, [
this]() {
return get_struct().kb; }},
528 {
"refShape", AutoParameter::read_only,
530 return (m_flat) ? std::string(
"Flat") : std::string(
"Initial");
532 {
"theta0", AutoParameter::read_only,
533 [
this]() {
return get_struct().theta0; }},
540 auto const shape_name = get_value<std::string>(
params,
"refShape");
541 if (shape_name ==
"Flat") {
543 }
else if (shape_name ==
"Initial") {
546 throw std::invalid_argument(
"Invalid value for parameter 'refShape': '" +
551 get_value<int>(
params,
"ind1"), get_value<int>(
params,
"ind2"),
552 get_value<int>(
params,
"ind3"), get_value<int>(
params,
"ind4"),
553 get_value<double>(
params,
"kb"), m_flat));
559 names.erase(
"theta0");
560 names.insert(
"ind1");
561 names.insert(
"ind2");
562 names.insert(
"ind3");
563 names.insert(
"ind4");
573 {
"A0_g", AutoParameter::read_only,
574 [
this]() {
return get_struct().A0_g; }},
575 {
"ka_g", AutoParameter::read_only,
576 [
this]() {
return get_struct().ka_g; }},
577 {
"V0", AutoParameter::read_only, [
this]() {
return get_struct().V0; }},
578 {
"kv", AutoParameter::read_only, [
this]() {
return get_struct().kv; }},
586 get_value<double>(
params,
"A0_g"),
587 get_value<double>(
params,
"ka_g"), get_value<double>(
params,
"V0"),
588 get_value<double>(
params,
"kv")));
596 {
"r0", AutoParameter::read_only, [
this]() {
return get_struct().r0; }},
597 {
"ks", AutoParameter::read_only, [
this]() {
return get_struct().ks; }},
598 {
"kslin", AutoParameter::read_only,
599 [
this]() {
return get_struct().kslin; }},
600 {
"phi0", AutoParameter::read_only,
601 [
this]() {
return get_struct().phi0; }},
602 {
"kb", AutoParameter::read_only, [
this]() {
return get_struct().kb; }},
603 {
"A01", AutoParameter::read_only,
604 [
this]() {
return get_struct().A01; }},
605 {
"A02", AutoParameter::read_only,
606 [
this]() {
return get_struct().A02; }},
607 {
"kal", AutoParameter::read_only,
608 [
this]() {
return get_struct().kal; }},
609 {
"kvisc", AutoParameter::read_only,
610 [
this]() {
return get_struct().kvisc; }},
618 get_value<double>(
params,
"r0"), get_value<double>(
params,
"ks"),
619 get_value<double>(
params,
"kslin"),
620 get_value<double>(
params,
"phi0"), get_value<double>(
params,
"kb"),
621 get_value<double>(
params,
"A01"), get_value<double>(
params,
"A02"),
622 get_value<double>(
params,
"kal"),
623 get_value<double>(
params,
"kvisc")));
BondedInteractionsMap bonded_ia_params
Field containing the parameters of the bonded ia types.
Data structures for bonded interactions.
int number_of_partners(Bonded_IA_Parameters const &iaparams)
Return the number of bonded partners for the specified bond.
mapped_type at(key_type const &key) const
Bind parameters in the script interface.
Utils::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
std::set< std::string > get_valid_parameters() const override
std::set< std::string > get_valid_parameters() const 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.
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.