48namespace Interactions {
50class NonBondedInteractionHandle;
52template <
class CoreIA>
83 [
this, ptr]() {
return m_handle.get()->*ptr; }};
88 return {
vec.begin(),
vec.end()};
96 throw std::runtime_error(
"Parameter '" +
key +
"' is missing");
101 throw std::runtime_error(
"Parameter '" +
key +
"' is not recognized");
109 if (
name ==
"set_params") {
111 check_valid_parameters(
params);
119 if (
name ==
"deactivate") {
120 m_handle = std::make_shared<CoreInteraction>();
129 m_handle = std::make_shared<CoreInteraction>();
133 m_handle = std::make_shared<CoreInteraction>();
136 check_valid_parameters(
params);
173 params,
"epsilon",
"sigma");
179 if (
name ==
"get_cutoff") {
188#ifdef ESPRESSO_LENNARD_JONES
213 throw std::invalid_argument(
214 "LJ parameter 'shift' has to be 'auto' or a float");
220 new_params,
"epsilon",
"sigma",
"cutoff",
"offset",
"min",
"shift");
228#ifdef ESPRESSO_LENNARD_JONES_GENERIC
244#ifdef ESPRESSO_LJGEN_SOFTCORE
261 throw std::invalid_argument(
262 "Generic LJ parameter 'shift' has to be 'auto' or a float");
268#ifdef ESPRESSO_LJGEN_SOFTCORE
272 new_params,
"epsilon",
"sigma",
"cutoff",
"shift",
"offset",
273#ifdef ESPRESSO_LJGEN_SOFTCORE
276 "e1",
"e2",
"b1",
"b2");
306 params,
"epsilon",
"sigma",
"cutoff",
"offset");
311#ifdef ESPRESSO_LJCOS2
336 params,
"epsilon",
"sigma",
"offset",
"width");
342 if (
name ==
"get_cutoff") {
351#ifdef ESPRESSO_HERTZIAN
377#ifdef ESPRESSO_GAUSSIAN
397 params,
"eps",
"sig",
"cutoff");
402#ifdef ESPRESSO_BMHTF_NACL
426 params,
"a",
"b",
"c",
"d",
"sig",
"cutoff");
453 params,
"eps",
"alpha",
"rmin",
"cutoff");
458#ifdef ESPRESSO_BUCKINGHAM
483 params,
"a",
"b",
"c",
"d",
"cutoff",
"discont",
"shift");
488#ifdef ESPRESSO_SOFT_SPHERE
510 params,
"a",
"n",
"cutoff",
"offset");
533 params,
"F_max",
"cutoff");
538#ifdef ESPRESSO_GAY_BERNE
565 params,
"eps",
"sig",
"cut",
"k1",
"k2",
"mu",
"nu");
570#ifdef ESPRESSO_TABULATED
593 std::vector<double>, std::vector<double>>(
594 params,
"min",
"max",
"force",
"energy");
600 if (
name ==
"get_cutoff") {
620 [
this]() {
return m_handle.get()->radial.wf; }},
622 [
this]() {
return m_handle.get()->radial.gamma; }},
624 [
this]() {
return m_handle.get()->radial.k; }},
626 [
this]() {
return m_handle.get()->radial.cutoff; }},
628 [
this]() {
return m_handle.get()->trans.wf; }},
630 [
this]() {
return m_handle.get()->trans.gamma; }},
632 [
this]() {
return m_handle.get()->trans.cutoff; }},
643 params,
"gamma",
"k",
"r_cut",
"weight_function",
"trans_gamma",
644 "trans_r_cut",
"trans_weight_function");
646 throw std::domain_error(
647 "DPDInteraction parameter 'weight_function' must be 0 or 1");
650 throw std::domain_error(
651 "DPDInteraction parameter 'trans_weight_function' must be 0 or 1");
679 params,
"scaling_coeff",
"q1q2");
684#ifdef ESPRESSO_SMOOTH_STEP
708 params,
"eps",
"sig",
"cutoff",
"d",
"n",
"k0");
715 std::shared_ptr<::IA_parameters> m_handle;
716 std::shared_ptr<NonBondedInteractionHandle *> m_self;
717 std::weak_ptr<std::function<
void()>> m_notify_cutoff_change;
719 std::shared_ptr<InteractionWCA> m_wca;
721#ifdef ESPRESSO_LENNARD_JONES
722 std::shared_ptr<InteractionLJ> m_lj;
724#ifdef ESPRESSO_LENNARD_JONES_GENERIC
725 std::shared_ptr<InteractionLJGen> m_ljgen;
728 std::shared_ptr<InteractionLJcos> m_ljcos;
730#ifdef ESPRESSO_LJCOS2
731 std::shared_ptr<InteractionLJcos2> m_ljcos2;
733#ifdef ESPRESSO_HERTZIAN
734 std::shared_ptr<InteractionHertzian> m_hertzian;
736#ifdef ESPRESSO_GAUSSIAN
737 std::shared_ptr<InteractionGaussian> m_gaussian;
739#ifdef ESPRESSO_BMHTF_NACL
740 std::shared_ptr<InteractionBMHTF> m_bmhtf;
743 std::shared_ptr<InteractionMorse> m_morse;
745#ifdef ESPRESSO_BUCKINGHAM
746 std::shared_ptr<InteractionBuckingham> m_buckingham;
748#ifdef ESPRESSO_SOFT_SPHERE
749 std::shared_ptr<InteractionSoftSphere> m_soft_sphere;
752 std::shared_ptr<InteractionHat> m_hat;
754#ifdef ESPRESSO_GAY_BERNE
755 std::shared_ptr<InteractionGayBerne> m_gay_berne;
757#ifdef ESPRESSO_TABULATED
758 std::shared_ptr<InteractionTabulated> m_tabulated;
761 std::shared_ptr<InteractionDPD> m_dpd;
764 std::shared_ptr<InteractionThole> m_thole;
766#ifdef ESPRESSO_SMOOTH_STEP
767 std::shared_ptr<InteractionSmoothStep> m_smooth_step;
772 m_self = std::make_shared<NonBondedInteractionHandle *>(
this);
773 std::vector<AutoParameter>
params;
774 apply([
this, &
params]<
typename T>(std::shared_ptr<T> &
member,
775 std::string
const &
name,
776 std::string
const &) {
779 member->attach(m_self, m_handle);
792 if (
name ==
"reset") {
797 apply([&
new_params](
auto &
so, std::string
const &, std::string
const &) {
805 if (
name ==
"on_non_bonded_ia_change") {
813 m_handle = std::make_shared<::IA_parameters>();
817 apply([
this, &
params]<
typename T>(std::shared_ptr<T>
const &,
818 std::string
const &
name,
822 : std::dynamic_pointer_cast<T>(
829 std::function<
void(std::shared_ptr<::IA_parameters>
const &)>
cb_register,
836 void apply(
auto const &&
fun) {
838 fun(m_wca,
"wca",
"Interactions::InteractionWCA");
840#ifdef ESPRESSO_LENNARD_JONES
841 fun(m_lj,
"lennard_jones",
"Interactions::InteractionLJ");
843#ifdef ESPRESSO_LENNARD_JONES_GENERIC
844 fun(m_ljgen,
"generic_lennard_jones",
"Interactions::InteractionLJGen");
847 fun(m_ljcos,
"lennard_jones_cos",
"Interactions::InteractionLJcos");
849#ifdef ESPRESSO_LJCOS2
850 fun(m_ljcos2,
"lennard_jones_cos2",
"Interactions::InteractionLJcos2");
852#ifdef ESPRESSO_HERTZIAN
853 fun(m_hertzian,
"hertzian",
"Interactions::InteractionHertzian");
855#ifdef ESPRESSO_GAUSSIAN
856 fun(m_gaussian,
"gaussian",
"Interactions::InteractionGaussian");
858#ifdef ESPRESSO_BMHTF_NACL
859 fun(m_bmhtf,
"bmhtf",
"Interactions::InteractionBMHTF");
862 fun(m_morse,
"morse",
"Interactions::InteractionMorse");
864#ifdef ESPRESSO_BUCKINGHAM
865 fun(m_buckingham,
"buckingham",
"Interactions::InteractionBuckingham");
867#ifdef ESPRESSO_SOFT_SPHERE
868 fun(m_soft_sphere,
"soft_sphere",
"Interactions::InteractionSoftSphere");
871 fun(m_hat,
"hat",
"Interactions::InteractionHat");
873#ifdef ESPRESSO_GAY_BERNE
874 fun(m_gay_berne,
"gay_berne",
"Interactions::InteractionGayBerne");
876#ifdef ESPRESSO_TABULATED
877 fun(m_tabulated,
"tabulated",
"Interactions::InteractionTabulated");
880 fun(m_dpd,
"dpd",
"Interactions::InteractionDPD");
883 fun(m_thole,
"thole",
"Interactions::InteractionThole");
885#ifdef ESPRESSO_SMOOTH_STEP
886 fun(m_smooth_step,
"smooth_step",
"Interactions::InteractionSmoothStep");
892 if (
auto callback = m_notify_cutoff_change.lock()) {
898template <
class CoreIA>
904 if (
auto si_struct = m_si_struct.lock()) {
905 (**si_struct).on_non_bonded_ia_change();
Bind parameters in the script interface.
std::vector< std::string_view > valid_parameters() const final
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 get_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.
virtual double get_inactive_cutoff() const
Which magic value indicates the potential is inactive.
std::set< std::string > get_valid_parameters() const
void attach(std::weak_ptr< NonBondedInteractionHandle * > si_struct, std::weak_ptr<::IA_parameters > core_struct)
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
double get_inactive_cutoff() const override
void make_new_instance(VariantMap const ¶ms) override
std::string inactive_parameter() const override
std::string inactive_parameter() const override
double get_inactive_cutoff() const override
CoreInteraction IA_parameters::* get_ptr_offset() const override
Variant do_call_method(std::string const &name, VariantMap const ¶ms) 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()
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.
std::string_view name() const
constexpr double inactive_cutoff
Special cutoff value for an inactive interaction.
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.
Various procedures concerning interactions between particles.
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
Recursive variant implementation.
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.