48namespace Interactions {
50class NonBondedInteractionHandle;
52template <
class CoreIA>
84 [
this, ptr]() {
return m_handle.get()->*ptr; }};
89 return {
vec.begin(),
vec.end()};
93 void check_valid_parameters(
VariantMap const ¶ms)
const {
96 if (
not params.contains(
key)) {
97 throw std::runtime_error(
"Parameter '" +
key +
"' is missing");
100 for (
auto const &
key :
std::
views::elements<0>(params)) {
102 throw std::runtime_error(
"Parameter '" +
key +
"' is not recognized");
110 if (
name ==
"set_params") {
112 check_valid_parameters(params);
120 if (
name ==
"deactivate") {
121 m_handle = std::make_shared<CoreInteraction>();
129 if (params.empty()) {
130 m_handle = std::make_shared<CoreInteraction>();
134 m_handle = std::make_shared<CoreInteraction>();
137 check_valid_parameters(params);
174 params,
"epsilon",
"sigma");
180 if (
name ==
"get_cutoff") {
189#ifdef ESPRESSO_LENNARD_JONES
211 auto const *
shift_string = std::get_if<std::string>(¶ms.at(
"shift"));
214 throw std::invalid_argument(
215 "LJ parameter 'shift' has to be 'auto' or a float");
221 new_params,
"epsilon",
"sigma",
"cutoff",
"offset",
"min",
"shift");
229#ifdef ESPRESSO_LENNARD_JONES_GENERIC
245#ifdef ESPRESSO_LJGEN_SOFTCORE
259 auto const *
shift_string = std::get_if<std::string>(¶ms.at(
"shift"));
262 throw std::invalid_argument(
263 "Generic LJ parameter 'shift' has to be 'auto' or a float");
269#ifdef ESPRESSO_LJGEN_SOFTCORE
273 new_params,
"epsilon",
"sigma",
"cutoff",
"shift",
"offset",
274#ifdef ESPRESSO_LJGEN_SOFTCORE
277 "e1",
"e2",
"b1",
"b2");
307 params,
"epsilon",
"sigma",
"cutoff",
"offset");
312#ifdef ESPRESSO_LJCOS2
337 params,
"epsilon",
"sigma",
"offset",
"width");
343 if (
name ==
"get_cutoff") {
352#ifdef ESPRESSO_HERTZIAN
373 params,
"eps",
"sig");
378#ifdef ESPRESSO_GAUSSIAN
398 params,
"eps",
"sig",
"cutoff");
403#ifdef ESPRESSO_BMHTF_NACL
427 params,
"a",
"b",
"c",
"d",
"sig",
"cutoff");
454 params,
"eps",
"alpha",
"rmin",
"cutoff");
459#ifdef ESPRESSO_BUCKINGHAM
484 params,
"a",
"b",
"c",
"d",
"cutoff",
"discont",
"shift");
489#ifdef ESPRESSO_SOFT_SPHERE
511 params,
"a",
"n",
"cutoff",
"offset");
534 params,
"F_max",
"cutoff");
539#ifdef ESPRESSO_GAY_BERNE
566 params,
"eps",
"sig",
"cut",
"k1",
"k2",
"mu",
"nu");
571#ifdef ESPRESSO_TABULATED
594 std::vector<double>, std::vector<double>>(
595 params,
"min",
"max",
"force",
"energy");
601 if (
name ==
"get_cutoff") {
621 [
this]() {
return m_handle.get()->radial.wf; }},
623 [
this]() {
return m_handle.get()->radial.gamma; }},
625 [
this]() {
return m_handle.get()->radial.k; }},
627 [
this]() {
return m_handle.get()->radial.cutoff; }},
629 [
this]() {
return m_handle.get()->trans.wf; }},
631 [
this]() {
return m_handle.get()->trans.gamma; }},
633 [
this]() {
return m_handle.get()->trans.cutoff; }},
644 params,
"gamma",
"k",
"r_cut",
"weight_function",
"trans_gamma",
645 "trans_r_cut",
"trans_weight_function");
647 throw std::domain_error(
648 "DPDInteraction parameter 'weight_function' must be 0 or 1");
651 throw std::domain_error(
652 "DPDInteraction parameter 'trans_weight_function' must be 0 or 1");
680 params,
"scaling_coeff",
"q1q2");
685#ifdef ESPRESSO_SMOOTH_STEP
709 params,
"eps",
"sig",
"cutoff",
"d",
"n",
"k0");
716 std::shared_ptr<::IA_parameters> m_handle;
717 std::shared_ptr<NonBondedInteractionHandle *> m_self;
718 std::weak_ptr<std::function<
void()>> m_notify_cutoff_change;
720 std::shared_ptr<InteractionWCA> m_wca;
722#ifdef ESPRESSO_LENNARD_JONES
723 std::shared_ptr<InteractionLJ> m_lj;
725#ifdef ESPRESSO_LENNARD_JONES_GENERIC
726 std::shared_ptr<InteractionLJGen> m_ljgen;
729 std::shared_ptr<InteractionLJcos> m_ljcos;
731#ifdef ESPRESSO_LJCOS2
732 std::shared_ptr<InteractionLJcos2> m_ljcos2;
734#ifdef ESPRESSO_HERTZIAN
735 std::shared_ptr<InteractionHertzian> m_hertzian;
737#ifdef ESPRESSO_GAUSSIAN
738 std::shared_ptr<InteractionGaussian> m_gaussian;
740#ifdef ESPRESSO_BMHTF_NACL
741 std::shared_ptr<InteractionBMHTF> m_bmhtf;
744 std::shared_ptr<InteractionMorse> m_morse;
746#ifdef ESPRESSO_BUCKINGHAM
747 std::shared_ptr<InteractionBuckingham> m_buckingham;
749#ifdef ESPRESSO_SOFT_SPHERE
750 std::shared_ptr<InteractionSoftSphere> m_soft_sphere;
753 std::shared_ptr<InteractionHat> m_hat;
755#ifdef ESPRESSO_GAY_BERNE
756 std::shared_ptr<InteractionGayBerne> m_gay_berne;
758#ifdef ESPRESSO_TABULATED
759 std::shared_ptr<InteractionTabulated> m_tabulated;
762 std::shared_ptr<InteractionDPD> m_dpd;
765 std::shared_ptr<InteractionThole> m_thole;
767#ifdef ESPRESSO_SMOOTH_STEP
768 std::shared_ptr<InteractionSmoothStep> m_smooth_step;
773 m_self = std::make_shared<NonBondedInteractionHandle *>(
this);
774 std::vector<AutoParameter> params;
775 apply([
this, ¶ms]<
typename T>(std::shared_ptr<T> &
member,
776 std::string
const &
name,
777 std::string
const &) {
780 member->attach(m_self, m_handle);
793 if (
name ==
"reset") {
798 apply([&
new_params](
auto &
so, std::string
const &, std::string
const &) {
806 if (
name ==
"on_non_bonded_ia_change") {
814 m_handle = std::make_shared<::IA_parameters>();
818 apply([
this, ¶ms]<
typename T>(std::shared_ptr<T>
const &,
819 std::string
const &
name,
821 auto so = params.contains(
name)
823 : std::dynamic_pointer_cast<T>(
830 std::function<
void(std::shared_ptr<::IA_parameters>
const &)>
cb_register,
837 void apply(
auto const &&
fun) {
839 fun(m_wca,
"wca",
"Interactions::InteractionWCA");
841#ifdef ESPRESSO_LENNARD_JONES
842 fun(m_lj,
"lennard_jones",
"Interactions::InteractionLJ");
844#ifdef ESPRESSO_LENNARD_JONES_GENERIC
845 fun(m_ljgen,
"generic_lennard_jones",
"Interactions::InteractionLJGen");
848 fun(m_ljcos,
"lennard_jones_cos",
"Interactions::InteractionLJcos");
850#ifdef ESPRESSO_LJCOS2
851 fun(m_ljcos2,
"lennard_jones_cos2",
"Interactions::InteractionLJcos2");
853#ifdef ESPRESSO_HERTZIAN
854 fun(m_hertzian,
"hertzian",
"Interactions::InteractionHertzian");
856#ifdef ESPRESSO_GAUSSIAN
857 fun(m_gaussian,
"gaussian",
"Interactions::InteractionGaussian");
859#ifdef ESPRESSO_BMHTF_NACL
860 fun(m_bmhtf,
"bmhtf",
"Interactions::InteractionBMHTF");
863 fun(m_morse,
"morse",
"Interactions::InteractionMorse");
865#ifdef ESPRESSO_BUCKINGHAM
866 fun(m_buckingham,
"buckingham",
"Interactions::InteractionBuckingham");
868#ifdef ESPRESSO_SOFT_SPHERE
869 fun(m_soft_sphere,
"soft_sphere",
"Interactions::InteractionSoftSphere");
872 fun(m_hat,
"hat",
"Interactions::InteractionHat");
874#ifdef ESPRESSO_GAY_BERNE
875 fun(m_gay_berne,
"gay_berne",
"Interactions::InteractionGayBerne");
877#ifdef ESPRESSO_TABULATED
878 fun(m_tabulated,
"tabulated",
"Interactions::InteractionTabulated");
881 fun(m_dpd,
"dpd",
"Interactions::InteractionDPD");
884 fun(m_thole,
"thole",
"Interactions::InteractionThole");
886#ifdef ESPRESSO_SMOOTH_STEP
887 fun(m_smooth_step,
"smooth_step",
"Interactions::InteractionSmoothStep");
893 if (
auto callback = m_notify_cutoff_change.lock()) {
899template <
class CoreIA>
905 if (
auto si_struct = m_si_struct.lock()) {
906 (**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
CoreInteractionIAParamsPtr get_ptr_offset() const override
CoreInteractionIAParamsPtr get_ptr_offset() const override
void make_new_instance(VariantMap const ¶ms) override
CoreInteractionIAParamsPtr get_ptr_offset() const override
std::string inactive_parameter() const override
void make_new_instance(VariantMap const ¶ms) override
CoreInteractionIAParamsPtr get_ptr_offset() const override
void make_new_instance(VariantMap const ¶ms) override
CoreInteractionIAParamsPtr get_ptr_offset() const override
std::string inactive_parameter() const override
void make_new_instance(VariantMap const ¶ms) override
void make_new_instance(VariantMap const ¶ms) override
CoreInteractionIAParamsPtr get_ptr_offset() const override
CoreInteractionIAParamsPtr get_ptr_offset() const override
void make_new_instance(VariantMap const ¶ms) override
std::string inactive_parameter() const override
void make_new_instance(VariantMap const ¶ms) override
CoreInteractionIAParamsPtr get_ptr_offset() const override
void make_new_instance(VariantMap const ¶ms) override
CoreInteractionIAParamsPtr get_ptr_offset() const override
CoreInteractionIAParamsPtr get_ptr_offset() const 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
double get_inactive_cutoff() const override
CoreInteractionIAParamsPtr get_ptr_offset() const override
void make_new_instance(VariantMap const ¶ms) override
CoreInteractionIAParamsPtr 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 CoreInteractionIAParamsPtr get_ptr_offset() const =0
Pointer to the corresponding member in a handle.
CoreInteraction IA_parameters::* CoreInteractionIAParamsPtr
std::weak_ptr< std::function< void()> > m_notify_non_bonded_ia_change
Callback to notify changes to the interaction range.
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
CoreInteractionIAParamsPtr get_ptr_offset() const override
CoreInteractionIAParamsPtr get_ptr_offset() const override
void make_new_instance(VariantMap const ¶ms) 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
CoreInteractionIAParamsPtr get_ptr_offset() const override
double get_inactive_cutoff() const override
void make_new_instance(VariantMap const ¶ms) override
CoreInteractionIAParamsPtr get_ptr_offset() const override
std::string inactive_parameter() const override
CoreInteractionIAParamsPtr get_ptr_offset() const override
std::string inactive_parameter() const override
double get_inactive_cutoff() 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
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
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.
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
Description and getter/setter for a parameter.
static constexpr const ReadOnly read_only
Recursive variant implementation.
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.