46namespace Interactions {
48class NonBondedInteractionHandle;
50template <
class CoreIA>
81 [
this, ptr]() {
return m_handle.get()->*ptr; }};
87 for (
auto const &
key : keys) {
88 if (
params.count(std::string(
key)) == 0) {
89 throw std::runtime_error(
"Parameter '" +
key +
"' is missing");
92 for (
auto const &kv :
params) {
93 if (std::ranges::find(keys, kv.first) == keys.end()) {
94 throw std::runtime_error(
"Parameter '" + kv.first +
95 "' is not recognized");
103 if (
name ==
"set_params") {
105 check_valid_parameters(
params);
113 if (
name ==
"deactivate") {
114 m_handle = std::make_shared<CoreInteraction>();
123 m_handle = std::make_shared<CoreInteraction>();
127 m_handle = std::make_shared<CoreInteraction>();
130 check_valid_parameters(
params);
167 params,
"epsilon",
"sigma");
173 if (
name ==
"get_cutoff") {
207 throw std::invalid_argument(
208 "LJ parameter 'shift' has to be 'auto' or a float");
214 new_params,
"epsilon",
"sigma",
"cutoff",
"offset",
"min",
"shift");
222#ifdef LENNARD_JONES_GENERIC
255 throw std::invalid_argument(
256 "Generic LJ parameter 'shift' has to be 'auto' or a float");
266 new_params,
"epsilon",
"sigma",
"cutoff",
"shift",
"offset",
270 "e1",
"e2",
"b1",
"b2");
300 params,
"epsilon",
"sigma",
"cutoff",
"offset");
330 params,
"epsilon",
"sigma",
"offset",
"width");
336 if (
name ==
"get_cutoff") {
391 params,
"eps",
"sig",
"cutoff");
420 params,
"a",
"b",
"c",
"d",
"sig",
"cutoff");
447 params,
"eps",
"alpha",
"rmin",
"cutoff");
477 params,
"a",
"b",
"c",
"d",
"cutoff",
"discont",
"shift");
504 params,
"a",
"n",
"cutoff",
"offset");
527 params,
"F_max",
"cutoff");
559 params,
"eps",
"sig",
"cut",
"k1",
"k2",
"mu",
"nu");
587 std::vector<double>, std::vector<double>>(
588 params,
"min",
"max",
"force",
"energy");
594 if (
name ==
"get_cutoff") {
614 [
this]() {
return m_handle.get()->radial.wf; }},
616 [
this]() {
return m_handle.get()->radial.gamma; }},
618 [
this]() {
return m_handle.get()->radial.k; }},
620 [
this]() {
return m_handle.get()->radial.cutoff; }},
622 [
this]() {
return m_handle.get()->trans.wf; }},
624 [
this]() {
return m_handle.get()->trans.gamma; }},
626 [
this]() {
return m_handle.get()->trans.cutoff; }},
637 params,
"gamma",
"k",
"r_cut",
"weight_function",
"trans_gamma",
638 "trans_r_cut",
"trans_weight_function");
640 throw std::domain_error(
641 "DPDInteraction parameter 'weight_function' must be 0 or 1");
644 throw std::domain_error(
645 "DPDInteraction parameter 'trans_weight_function' must be 0 or 1");
673 params,
"scaling_coeff",
"q1q2");
702 params,
"eps",
"sig",
"cutoff",
"d",
"n",
"k0");
709 std::shared_ptr<::IA_parameters> m_handle;
710 std::shared_ptr<NonBondedInteractionHandle *> m_self;
711 std::weak_ptr<std::function<
void()>> m_notify_cutoff_change;
713 std::shared_ptr<InteractionWCA> m_wca;
716 std::shared_ptr<InteractionLJ> m_lj;
718#ifdef LENNARD_JONES_GENERIC
719 std::shared_ptr<InteractionLJGen> m_ljgen;
722 std::shared_ptr<InteractionLJcos> m_ljcos;
725 std::shared_ptr<InteractionLJcos2> m_ljcos2;
728 std::shared_ptr<InteractionHertzian> m_hertzian;
731 std::shared_ptr<InteractionGaussian> m_gaussian;
734 std::shared_ptr<InteractionBMHTF> m_bmhtf;
737 std::shared_ptr<InteractionMorse> m_morse;
740 std::shared_ptr<InteractionBuckingham> m_buckingham;
743 std::shared_ptr<InteractionSoftSphere> m_soft_sphere;
746 std::shared_ptr<InteractionHat> m_hat;
749 std::shared_ptr<InteractionGayBerne> m_gay_berne;
752 std::shared_ptr<InteractionTabulated> m_tabulated;
755 std::shared_ptr<InteractionDPD> m_dpd;
758 std::shared_ptr<InteractionThole> m_thole;
761 std::shared_ptr<InteractionSmoothStep> m_smooth_step;
766 m_self = std::make_shared<NonBondedInteractionHandle *>(
this);
767 std::vector<AutoParameter>
params;
768 apply([
this, &
params]<
typename T>(std::shared_ptr<T> &
member,
769 std::string
const &
name,
770 std::string
const &) {
773 member->attach(m_self, m_handle);
786 if (
name ==
"reset") {
791 apply([&
new_params](
auto &
so, std::string
const &, std::string
const &) {
799 if (
name ==
"on_non_bonded_ia_change") {
807 m_handle = std::make_shared<::IA_parameters>();
811 apply([
this, &
params]<
typename T>(std::shared_ptr<T> &
member,
812 std::string
const &
name,
816 : std::dynamic_pointer_cast<T>(
823 std::function<
void(std::shared_ptr<::IA_parameters>
const &)>
cb_register,
830 void apply(
auto const &&
fun) {
832 fun(m_wca,
"wca",
"Interactions::InteractionWCA");
835 fun(m_lj,
"lennard_jones",
"Interactions::InteractionLJ");
837#ifdef LENNARD_JONES_GENERIC
838 fun(m_ljgen,
"generic_lennard_jones",
"Interactions::InteractionLJGen");
841 fun(m_ljcos,
"lennard_jones_cos",
"Interactions::InteractionLJcos");
844 fun(m_ljcos2,
"lennard_jones_cos2",
"Interactions::InteractionLJcos2");
847 fun(m_hertzian,
"hertzian",
"Interactions::InteractionHertzian");
850 fun(m_gaussian,
"gaussian",
"Interactions::InteractionGaussian");
853 fun(m_bmhtf,
"bmhtf",
"Interactions::InteractionBMHTF");
856 fun(m_morse,
"morse",
"Interactions::InteractionMorse");
859 fun(m_buckingham,
"buckingham",
"Interactions::InteractionBuckingham");
862 fun(m_soft_sphere,
"soft_sphere",
"Interactions::InteractionSoftSphere");
865 fun(m_hat,
"hat",
"Interactions::InteractionHat");
868 fun(m_gay_berne,
"gay_berne",
"Interactions::InteractionGayBerne");
871 fun(m_tabulated,
"tabulated",
"Interactions::InteractionTabulated");
874 fun(m_dpd,
"dpd",
"Interactions::InteractionDPD");
877 fun(m_thole,
"thole",
"Interactions::InteractionThole");
880 fun(m_smooth_step,
"smooth_step",
"Interactions::InteractionSmoothStep");
886 if (
auto callback = m_notify_cutoff_change.lock()) {
892template <
class CoreIA>
898 if (
auto si_struct = m_si_struct.lock()) {
899 (**si_struct).on_non_bonded_ia_change();
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
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.
std::weak_ptr< std::function< void()> > m_notify_non_bonded_ia_change
Callback to notify changes to the interaction range.
virtual CoreInteraction IA_parameters::* get_ptr_offset() const =0
Pointer to the corresponding member in a handle.
std::shared_ptr< CoreInteraction > m_handle
Managed object.
void attach(std::weak_ptr< NonBondedInteractionHandle * > si_struct, std::weak_ptr<::IA_parameters > core_struct)
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
std::weak_ptr<::IA_parameters > m_core_struct
Handle to the container whose members have to be synchronized.
std::weak_ptr< NonBondedInteractionHandle * > m_si_struct
Handle to the interface used to synchronize data members.
void do_construct(VariantMap const ¶ms) final
void update_core(bool notify=true)
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 attach(std::function< void(std::shared_ptr<::IA_parameters > const &)> cb_register, std::weak_ptr< std::function< void()> > cb_notify_cutoff_change)
void on_non_bonded_ia_change()
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
Variant call_method(const std::string &name, const VariantMap ¶ms)
Call a method on the object.
Context * context() const
Responsible context.
void set_parameter(const std::string &name, const Variant &value)
Set single parameter.
T get_value(Variant const &v)
Extract value of specific type T from a Variant.
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.