25#ifndef SCRIPT_INTERFACE_INTERACTIONS_NONBONDED_INTERACTION_HPP
26#define SCRIPT_INTERFACE_INTERACTIONS_NONBONDED_INTERACTION_HPP
47namespace Interactions {
49template <
class CoreIA>
53 std::array<int, 2> m_types = {-1, -1};
77 [
this, ptr]() {
return m_ia_si.get()->*ptr; }};
83 for (
auto const &key : keys) {
84 if (
params.count(std::string(key)) == 0) {
85 throw std::runtime_error(
"Parameter '" + key +
"' is missing");
88 for (
auto const &kv :
params) {
89 if (std::find(keys.begin(), keys.end(), kv.first) == keys.end()) {
90 throw std::runtime_error(
"Parameter '" + kv.first +
91 "' is not recognized");
99 if (
name ==
"set_params") {
101 check_valid_parameters(
params);
104 if (m_types[0] != -1) {
110 if (
name ==
"deactivate") {
111 m_ia_si = std::make_shared<CoreInteraction>();
112 if (m_types[0] != -1) {
118 if (
name ==
"is_registered") {
119 return m_types[0] != -1;
121 if (
name ==
"bind_types") {
122 auto types = get_value<std::vector<int>>(
params,
"_types");
123 if (types[0] > types[1]) {
124 std::swap(types[0], types[1]);
126 if (m_types[0] == -1 or
127 (m_types[0] == types[0] and m_types[1] == types[1])) {
128 m_types[0] = types[0];
129 m_types[1] = types[1];
132 throw std::runtime_error(
133 "Non-bonded interaction is already bound to interaction pair [" +
134 std::to_string(m_types[0]) +
", " + std::to_string(m_types[1]) +
144 if (
params.count(
"_types") != 0) {
146 m_ia_si = std::make_shared<CoreInteraction>();
151 m_ia_si = std::make_shared<CoreInteraction>();
154 check_valid_parameters(
params);
194 m_ia_si = make_shared_from_args<CoreInteraction, double, double>(
195 params,
"epsilon",
"sigma");
201 if (
name ==
"get_cutoff") {
232 auto const *shift_string = boost::get<std::string>(&
params.at(
"shift"));
233 if (shift_string !=
nullptr) {
234 if (*shift_string !=
"auto") {
235 throw std::invalid_argument(
236 "LJ parameter 'shift' has to be 'auto' or a float");
238 new_params[
"shift"] = 0.;
241 double, double,
double>(
242 new_params,
"epsilon",
"sigma",
"cutoff",
"offset",
"min",
"shift");
243 if (shift_string !=
nullptr) {
250#ifdef LENNARD_JONES_GENERIC
280 auto const *shift_string = boost::get<std::string>(&
params.at(
"shift"));
281 if (shift_string !=
nullptr) {
282 if (*shift_string !=
"auto") {
283 throw std::invalid_argument(
284 "Generic LJ parameter 'shift' has to be 'auto' or a float");
286 new_params[
"shift"] = 0.;
293 double, double, double,
double>(
294 new_params,
"epsilon",
"sigma",
"cutoff",
"shift",
"offset",
298 "e1",
"e2",
"b1",
"b2");
299 if (shift_string !=
nullptr) {
327 make_shared_from_args<CoreInteraction, double, double, double, double>(
328 params,
"epsilon",
"sigma",
"cutoff",
"offset");
357 make_shared_from_args<CoreInteraction, double, double, double, double>(
358 params,
"epsilon",
"sigma",
"offset",
"width");
364 if (
name ==
"get_cutoff") {
393 m_ia_si = make_shared_from_args<CoreInteraction, double, double>(
418 m_ia_si = make_shared_from_args<CoreInteraction, double, double, double>(
419 params,
"eps",
"sig",
"cutoff");
447 double, double,
double>(
448 params,
"a",
"b",
"c",
"d",
"sig",
"cutoff");
474 make_shared_from_args<CoreInteraction, double, double, double, double>(
475 params,
"eps",
"alpha",
"rmin",
"cutoff");
504 double, double, double,
double>(
505 params,
"a",
"b",
"c",
"d",
"cutoff",
"discont",
"shift");
531 make_shared_from_args<CoreInteraction, double, double, double, double>(
532 params,
"a",
"n",
"cutoff",
"offset");
554 m_ia_si = make_shared_from_args<CoreInteraction, double, double>(
555 params,
"F_max",
"cutoff");
586 double, double, double,
double>(
587 params,
"eps",
"sig",
"cut",
"k1",
"k2",
"mu",
"nu");
615 std::vector<double>, std::vector<double>>(
616 params,
"min",
"max",
"force",
"energy");
622 if (
name ==
"get_cutoff") {
623 return m_ia_si.get()->cutoff();
642 [
this]() {
return m_ia_si.get()->radial.wf; }},
644 [
this]() {
return m_ia_si.get()->radial.gamma; }},
646 [
this]() {
return m_ia_si.get()->radial.k; }},
648 [
this]() {
return m_ia_si.get()->radial.cutoff; }},
650 [
this]() {
return m_ia_si.get()->trans.wf; }},
652 [
this]() {
return m_ia_si.get()->trans.gamma; }},
654 [
this]() {
return m_ia_si.get()->trans.cutoff; }},
664 double, double, double,
double>(
665 params,
"gamma",
"k",
"r_cut",
"weight_function",
"trans_gamma",
666 "trans_r_cut",
"trans_weight_function");
668 throw std::domain_error(
669 "DPDInteraction parameter 'weight_function' must be 0 or 1");
672 throw std::domain_error(
673 "DPDInteraction parameter 'trans_weight_function' must be 0 or 1");
700 m_ia_si = make_shared_from_args<CoreInteraction, double, double>(
701 params,
"scaling_coeff",
"q1q2");
729 double, int,
double>(
730 params,
"eps",
"sig",
"cutoff",
"d",
"n",
"k0");
737 std::array<int, 2> m_types = {-1, -1};
738 std::shared_ptr<::IA_parameters> m_interaction;
740 std::shared_ptr<InteractionWCA> m_wca;
743 std::shared_ptr<InteractionLJ> m_lj;
745#ifdef LENNARD_JONES_GENERIC
746 std::shared_ptr<InteractionLJGen> m_ljgen;
749 std::shared_ptr<InteractionLJcos> m_ljcos;
752 std::shared_ptr<InteractionLJcos2> m_ljcos2;
755 std::shared_ptr<InteractionHertzian> m_hertzian;
758 std::shared_ptr<InteractionGaussian> m_gaussian;
761 std::shared_ptr<InteractionBMHTF> m_bmhtf;
764 std::shared_ptr<InteractionMorse> m_morse;
767 std::shared_ptr<InteractionBuckingham> m_buckingham;
770 std::shared_ptr<InteractionSoftSphere> m_soft_sphere;
773 std::shared_ptr<InteractionHat> m_hat;
776 std::shared_ptr<InteractionGayBerne> m_gay_berne;
779 std::shared_ptr<InteractionTabulated> m_tabulated;
782 std::shared_ptr<InteractionDPD> m_dpd;
785 std::shared_ptr<InteractionThole> m_thole;
788 std::shared_ptr<InteractionSmoothStep> m_smooth_step;
792 auto make_autoparameter(std::shared_ptr<T> &member,
const char *key)
const {
793 auto const setter = [
this, &member](
Variant const &v) {
794 member = get_value<std::shared_ptr<T>>(v);
795 if (m_types[0] != -1) {
796 auto const types =
Variant{std::vector<int>{{m_types[0], m_types[1]}}};
798 member->copy_si_to_core();
802 return AutoParameter{key, setter, [&member]() {
return member; }};
809 make_autoparameter(m_wca,
"wca"),
812 make_autoparameter(m_lj,
"lennard_jones"),
814#ifdef LENNARD_JONES_GENERIC
815 make_autoparameter(m_ljgen,
"generic_lennard_jones"),
818 make_autoparameter(m_ljcos,
"lennard_jones_cos"),
821 make_autoparameter(m_ljcos2,
"lennard_jones_cos2"),
824 make_autoparameter(m_hertzian,
"hertzian"),
827 make_autoparameter(m_gaussian,
"gaussian"),
830 make_autoparameter(m_bmhtf,
"bmhtf"),
833 make_autoparameter(m_morse,
"morse"),
836 make_autoparameter(m_buckingham,
"buckingham"),
839 make_autoparameter(m_soft_sphere,
"soft_sphere"),
842 make_autoparameter(m_hat,
"hat"),
845 make_autoparameter(m_gay_berne,
"gay_berne"),
848 make_autoparameter(m_tabulated,
"tabulated"),
851 make_autoparameter(m_dpd,
"dpd"),
854 make_autoparameter(m_thole,
"thole"),
857 make_autoparameter(m_smooth_step,
"smooth_step"),
864 void set_member(std::shared_ptr<T> &member, std::string key,
867 if (
params.count(key) != 0) {
868 member = get_value<std::shared_ptr<T>>(
params.at(key));
869 member->do_call_method(
"bind_types", ia_types);
870 member->copy_si_to_core();
873 member = std::dynamic_pointer_cast<T>(so_object);
874 member->copy_core_to_si();
882 if (
name ==
"get_types") {
883 return std::vector<int>{{m_types[0], m_types[1]}};
889 assert(
params.count(
"_types") != 0);
891 auto const types = get_value<std::vector<int>>(
params.at(
"_types"));
892 m_types[0] = std::min(types[0], types[1]);
893 m_types[1] = std::max(types[0], types[1]);
894 nonbonded_ias.make_particle_type_exist(m_types[1]);
897 nonbonded_ias.get_ia_param_ref_counted(m_types[0], m_types[1]);
899 set_member(m_wca,
"wca",
"Interactions::InteractionWCA",
params);
902 set_member(m_lj,
"lennard_jones",
"Interactions::InteractionLJ",
params);
904#ifdef LENNARD_JONES_GENERIC
905 set_member(m_ljgen,
"generic_lennard_jones",
906 "Interactions::InteractionLJGen",
params);
909 set_member(m_ljcos,
"lennard_jones_cos",
"Interactions::InteractionLJcos",
913 set_member(m_ljcos2,
"lennard_jones_cos2",
914 "Interactions::InteractionLJcos2",
params);
917 set_member(m_hertzian,
"hertzian",
"Interactions::InteractionHertzian",
921 set_member(m_gaussian,
"gaussian",
"Interactions::InteractionGaussian",
925 set_member(m_bmhtf,
"bmhtf",
"Interactions::InteractionBMHTF",
params);
928 set_member(m_morse,
"morse",
"Interactions::InteractionMorse",
params);
931 set_member(m_buckingham,
"buckingham",
932 "Interactions::InteractionBuckingham",
params);
935 set_member(m_soft_sphere,
"soft_sphere",
936 "Interactions::InteractionSoftSphere",
params);
939 set_member(m_hat,
"hat",
"Interactions::InteractionHat",
params);
942 set_member(m_gay_berne,
"gay_berne",
"Interactions::InteractionGayBerne",
946 set_member(m_tabulated,
"tabulated",
"Interactions::InteractionTabulated",
950 set_member(m_dpd,
"dpd",
"Interactions::InteractionDPD",
params);
953 set_member(m_thole,
"thole",
"Interactions::InteractionThole",
params);
956 set_member(m_smooth_step,
"smooth_step",
957 "Interactions::InteractionSmoothStep",
params);
961 auto get_ia()
const {
return m_interaction; }
Bind parameters in the script interface.
void add_parameters(std::vector< AutoParameter > &¶ms)
virtual void parallel_try_catch(std::function< void()> const &cb) const =0
virtual std::shared_ptr< ObjectHandle > make_shared_local(std::string const &name, VariantMap const ¶meters)=0
Get a new reference counted instance of a script interface by name.
void make_new_instance(VariantMap const ¶ms) override
CoreInteraction IA_parameters::* get_ptr_offset() const override
CoreInteraction IA_parameters::* get_ptr_offset() const override
void make_new_instance(VariantMap const ¶ms) override
std::string inactive_parameter() const override
CoreInteraction IA_parameters::* get_ptr_offset() const override
void make_new_instance(VariantMap const ¶ms) override
void make_new_instance(VariantMap const ¶ms) override
CoreInteraction IA_parameters::* get_ptr_offset() const override
std::string inactive_parameter() const override
void make_new_instance(VariantMap const ¶ms) override
CoreInteraction IA_parameters::* get_ptr_offset() const override
CoreInteraction IA_parameters::* get_ptr_offset() const override
void make_new_instance(VariantMap const ¶ms) override
void make_new_instance(VariantMap const ¶ms) override
CoreInteraction IA_parameters::* get_ptr_offset() const override
std::string inactive_parameter() const override
void make_new_instance(VariantMap const ¶ms) override
CoreInteraction IA_parameters::* get_ptr_offset() const override
CoreInteraction IA_parameters::* get_ptr_offset() const override
void make_new_instance(VariantMap const ¶ms) override
void make_new_instance(VariantMap const ¶ms) override
std::string inactive_parameter() const override
Variant do_call_method(std::string const &name, VariantMap const ¶ms) override
CoreInteraction IA_parameters::* get_ptr_offset() const override
double inactive_cutoff() const override
void make_new_instance(VariantMap const ¶ms) override
CoreInteraction IA_parameters::* get_ptr_offset() const override
CoreInteraction IA_parameters::* get_ptr_offset() const override
void make_new_instance(VariantMap const ¶ms) override
virtual void make_new_instance(VariantMap const ¶ms)=0
Create a new instance using the constructor with range checks.
virtual CoreInteraction IA_parameters::* get_ptr_offset() const =0
Pointer to the corresponding member in a handle.
std::shared_ptr< CoreInteraction > m_ia_si
Managed object.
virtual double inactive_cutoff() const
Which magic value indicates the potential is inactive.
auto make_autoparameter(T CoreInteraction::*ptr, char const *name)
Variant do_call_method(std::string const &name, VariantMap const ¶ms) override
void do_construct(VariantMap const ¶ms) final
virtual std::string inactive_parameter() const
Which parameter indicates whether the potential is inactive.
void make_new_instance(VariantMap const ¶ms) override
CoreInteraction IA_parameters::* get_ptr_offset() const override
void make_new_instance(VariantMap const ¶ms) override
CoreInteraction IA_parameters::* get_ptr_offset() const override
void make_new_instance(VariantMap const ¶ms) override
Variant do_call_method(std::string const &name, VariantMap const ¶ms) override
std::string inactive_parameter() const override
CoreInteraction IA_parameters::* get_ptr_offset() const override
CoreInteraction IA_parameters::* get_ptr_offset() const override
void make_new_instance(VariantMap const ¶ms) override
double inactive_cutoff() const override
std::string inactive_parameter() const override
std::string inactive_parameter() const override
CoreInteraction IA_parameters::* get_ptr_offset() const override
Variant do_call_method(std::string const &name, VariantMap const ¶ms) override
double inactive_cutoff() const override
void make_new_instance(VariantMap const ¶ms) override
void do_construct(VariantMap const ¶ms) override
Variant do_call_method(std::string const &name, VariantMap const ¶ms) override
NonBondedInteractionHandle()
boost::string_ref name() const
auto get_valid_parameters() const
virtual Variant do_call_method(const std::string &, const VariantMap &)
Local implementation of call_method.
Context * context() const
Responsible context.
void on_non_bonded_ia_change()
std::shared_ptr< InteractionsNonBonded > nonbonded_ias
std::unordered_map< std::string, Variant > VariantMap
std::shared_ptr< T > make_shared_from_args(VariantMap const &vals, ArgNames &&...args)
Make a new std::shared_ptr<T> with arguments extracted from a 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.
Various procedures concerning interactions between particles.
constexpr double INACTIVE_CUTOFF
Cutoff for deactivated interactions.
static SteepestDescentParameters params
Currently active steepest descent instance.
Parameters for non-bonded interactions.
Gaussian_Parameters gaussian
GayBerne_Parameters gay_berne
SoftSphere_Parameters soft_sphere
SmoothStep_Parameters smooth_step
Hertzian_Parameters hertzian
Buckingham_Parameters buckingham
Generic Lennard-Jones with shift.
Lennard-Jones with shift.
Lennard-Jones with a different Cos potential.
Lennard-Jones+Cos potential.
Description and getter/setter for a parameter.
static constexpr const ReadOnly read_only
Evaluate forces and energies using a custom potential profile.
std::vector< double > force_tab
Tabulated forces.
double maxval
Position on the x-axis of the last tabulated value.
std::vector< double > energy_tab
Tabulated energies.
double minval
Position on the x-axis of the first tabulated value.