From 634fc7caf1e94c151e27e53a6c05c4bbc5106c4f Mon Sep 17 00:00:00 2001 From: capomav Date: Wed, 6 Dec 2023 02:53:20 +0100 Subject: [PATCH 1/3] addition of cutoff parameters to bond and energy criterion --- src/core/pair_criteria/BondCriterion.hpp | 13 +++++++++++-- src/core/pair_criteria/EnergyCriterion.hpp | 9 +++++++-- src/core/pair_criteria/PairCriterion.hpp | 2 ++ .../pair_criteria/BondCriterion.hpp | 5 ++++- .../pair_criteria/EnergyCriterion.hpp | 7 +++++-- 5 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/core/pair_criteria/BondCriterion.hpp b/src/core/pair_criteria/BondCriterion.hpp index d1bd387a1cd..b4a976384e0 100644 --- a/src/core/pair_criteria/BondCriterion.hpp +++ b/src/core/pair_criteria/BondCriterion.hpp @@ -28,14 +28,23 @@ namespace PairCriteria { class BondCriterion : public PairCriterion { public: bool decide(Particle const &p1, Particle const &p2) const override { - return pair_bond_exists_on(p1.bonds(), p2.id(), m_bond_type) || - pair_bond_exists_on(p2.bonds(), p1.id(), m_bond_type); + + auto const &box_geo = *System::get_system().box_geo; + d = box_geo.get_mi_vector(p1.pos(), p2.pos()).norm(); + + return ( pair_bond_exists_on(p1.bonds(), p2.id(), m_bond_type) || + pair_bond_exists_on(p2.bonds(), p1.id(), m_bond_type) ) && + d <= m_cut_off ; } int get_bond_type() { return m_bond_type; } void set_bond_type(int t) { m_bond_type = t; } + int get_cut_off() { return m_cut_off; } + void set_cut_off(double c) { m_cut_off = c; } + private: int m_bond_type; + double m_cut_off ; }; } // namespace PairCriteria diff --git a/src/core/pair_criteria/EnergyCriterion.hpp b/src/core/pair_criteria/EnergyCriterion.hpp index e81a59dd66b..5fc188f4228 100644 --- a/src/core/pair_criteria/EnergyCriterion.hpp +++ b/src/core/pair_criteria/EnergyCriterion.hpp @@ -46,13 +46,18 @@ class EnergyCriterion : public PairCriterion { auto const energy = calc_non_bonded_pair_energy( p1, p2, ia_params, d, d.norm(), get_ptr(coulomb_kernel)); - return energy >= m_cut_off; + return energy >= e_cut_off && d.norm() <= m_cut_off ; } double get_cut_off() { return m_cut_off; } void set_cut_off(double c) { m_cut_off = c; } + double get_e_cut_off() { return e_cut_off; } + void set_e_cut_off(double e) { e_cut_off = e; } + + + private: - double m_cut_off; + double m_cut_off,e_cut_off; System::System const &m_system; }; } // namespace PairCriteria diff --git a/src/core/pair_criteria/PairCriterion.hpp b/src/core/pair_criteria/PairCriterion.hpp index c5ac88bdf70..c611c427ca1 100644 --- a/src/core/pair_criteria/PairCriterion.hpp +++ b/src/core/pair_criteria/PairCriterion.hpp @@ -41,6 +41,8 @@ class PairCriterion { const bool res = decide(p1, p2); return res; } + + virtual double cutoff(Particle const &p1, Particle const &p2) const = 0; virtual ~PairCriterion() = default; }; } // namespace PairCriteria diff --git a/src/script_interface/pair_criteria/BondCriterion.hpp b/src/script_interface/pair_criteria/BondCriterion.hpp index b59e9303d54..bbb4e48dcd3 100644 --- a/src/script_interface/pair_criteria/BondCriterion.hpp +++ b/src/script_interface/pair_criteria/BondCriterion.hpp @@ -40,7 +40,10 @@ class BondCriterion : public PairCriterion { add_parameters( {{"bond_type", [this](Variant const &v) { m_c->set_bond_type(get_value(v)); }, - [this]() { return m_c->get_bond_type(); }}}); + [this]() { return m_c->get_bond_type(); }}, + {"cut_off", + [this](Variant const &v2) { m_c->set_cut_off(get_value(v2)); }, + [this]() { return m_c->get_cut_off(); }} }); } std::shared_ptr<::PairCriteria::PairCriterion> diff --git a/src/script_interface/pair_criteria/EnergyCriterion.hpp b/src/script_interface/pair_criteria/EnergyCriterion.hpp index e5ec3582701..99632c2b0c2 100644 --- a/src/script_interface/pair_criteria/EnergyCriterion.hpp +++ b/src/script_interface/pair_criteria/EnergyCriterion.hpp @@ -41,9 +41,12 @@ class EnergyCriterion : public PairCriterion { : m_c(std::make_shared<::PairCriteria::EnergyCriterion>( ::System::get_system())) { add_parameters( - {{"cut_off", + {{"d_cut_off", [this](Variant const &v) { m_c->set_cut_off(get_value(v)); }, - [this]() { return m_c->get_cut_off(); }}}); + [this]() { return m_c->get_cut_off(); }}, + {"e_cut_off", + [this](Variant const &v2){m_c->set_e_cut_off(get_value(v2)); }, + [this](){return m_c->get_e_cut_off(); }} }); } std::shared_ptr<::PairCriteria::PairCriterion> From ffc62c86926127bbbb2afab7e09112e9334e8a6e Mon Sep 17 00:00:00 2001 From: capomav Date: Tue, 12 Dec 2023 13:54:14 +0100 Subject: [PATCH 2/3] elimination of virtual abstract cutoff --- src/core/pair_criteria/BondCriterion.hpp | 6 ++++-- src/core/pair_criteria/PairCriterion.hpp | 1 - 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/core/pair_criteria/BondCriterion.hpp b/src/core/pair_criteria/BondCriterion.hpp index b4a976384e0..faa600b6e4c 100644 --- a/src/core/pair_criteria/BondCriterion.hpp +++ b/src/core/pair_criteria/BondCriterion.hpp @@ -22,6 +22,8 @@ #include "pair_criteria/PairCriterion.hpp" #include "BondList.hpp" +#include "BoxGeometry.hpp" +#include "system/System.hpp" namespace PairCriteria { /** @brief True if a bond of given type exists between two particles. */ @@ -30,7 +32,7 @@ class BondCriterion : public PairCriterion { bool decide(Particle const &p1, Particle const &p2) const override { auto const &box_geo = *System::get_system().box_geo; - d = box_geo.get_mi_vector(p1.pos(), p2.pos()).norm(); + auto const d = box_geo.get_mi_vector(p1.pos(), p2.pos()).norm(); return ( pair_bond_exists_on(p1.bonds(), p2.id(), m_bond_type) || pair_bond_exists_on(p2.bonds(), p1.id(), m_bond_type) ) && @@ -39,7 +41,7 @@ class BondCriterion : public PairCriterion { int get_bond_type() { return m_bond_type; } void set_bond_type(int t) { m_bond_type = t; } - int get_cut_off() { return m_cut_off; } + double get_cut_off() { return m_cut_off; } void set_cut_off(double c) { m_cut_off = c; } private: diff --git a/src/core/pair_criteria/PairCriterion.hpp b/src/core/pair_criteria/PairCriterion.hpp index c611c427ca1..dd43f26bb3b 100644 --- a/src/core/pair_criteria/PairCriterion.hpp +++ b/src/core/pair_criteria/PairCriterion.hpp @@ -42,7 +42,6 @@ class PairCriterion { return res; } - virtual double cutoff(Particle const &p1, Particle const &p2) const = 0; virtual ~PairCriterion() = default; }; } // namespace PairCriteria From 64d8c67643b0dd628559ee0f15d08d06cdeec1de Mon Sep 17 00:00:00 2001 From: capomav Date: Tue, 12 Dec 2023 14:48:54 +0100 Subject: [PATCH 3/3] clang-formatting --- src/core/pair_criteria/BondCriterion.hpp | 12 ++++++------ src/core/pair_criteria/EnergyCriterion.hpp | 6 ++---- src/core/pair_criteria/PairCriterion.hpp | 2 +- src/script_interface/pair_criteria/BondCriterion.hpp | 4 ++-- .../pair_criteria/EnergyCriterion.hpp | 8 +++++--- 5 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/core/pair_criteria/BondCriterion.hpp b/src/core/pair_criteria/BondCriterion.hpp index faa600b6e4c..aeab54e4c65 100644 --- a/src/core/pair_criteria/BondCriterion.hpp +++ b/src/core/pair_criteria/BondCriterion.hpp @@ -31,12 +31,12 @@ class BondCriterion : public PairCriterion { public: bool decide(Particle const &p1, Particle const &p2) const override { - auto const &box_geo = *System::get_system().box_geo; - auto const d = box_geo.get_mi_vector(p1.pos(), p2.pos()).norm(); + auto const &box_geo = *System::get_system().box_geo; + auto const d = box_geo.get_mi_vector(p1.pos(), p2.pos()).norm(); - return ( pair_bond_exists_on(p1.bonds(), p2.id(), m_bond_type) || - pair_bond_exists_on(p2.bonds(), p1.id(), m_bond_type) ) && - d <= m_cut_off ; + return (pair_bond_exists_on(p1.bonds(), p2.id(), m_bond_type) || + pair_bond_exists_on(p2.bonds(), p1.id(), m_bond_type)) && + d <= m_cut_off; } int get_bond_type() { return m_bond_type; } void set_bond_type(int t) { m_bond_type = t; } @@ -46,7 +46,7 @@ class BondCriterion : public PairCriterion { private: int m_bond_type; - double m_cut_off ; + double m_cut_off; }; } // namespace PairCriteria diff --git a/src/core/pair_criteria/EnergyCriterion.hpp b/src/core/pair_criteria/EnergyCriterion.hpp index 5fc188f4228..a98fb8c7882 100644 --- a/src/core/pair_criteria/EnergyCriterion.hpp +++ b/src/core/pair_criteria/EnergyCriterion.hpp @@ -46,7 +46,7 @@ class EnergyCriterion : public PairCriterion { auto const energy = calc_non_bonded_pair_energy( p1, p2, ia_params, d, d.norm(), get_ptr(coulomb_kernel)); - return energy >= e_cut_off && d.norm() <= m_cut_off ; + return energy >= e_cut_off && d.norm() <= m_cut_off; } double get_cut_off() { return m_cut_off; } void set_cut_off(double c) { m_cut_off = c; } @@ -54,10 +54,8 @@ class EnergyCriterion : public PairCriterion { double get_e_cut_off() { return e_cut_off; } void set_e_cut_off(double e) { e_cut_off = e; } - - private: - double m_cut_off,e_cut_off; + double m_cut_off, e_cut_off; System::System const &m_system; }; } // namespace PairCriteria diff --git a/src/core/pair_criteria/PairCriterion.hpp b/src/core/pair_criteria/PairCriterion.hpp index dd43f26bb3b..d2f575b9927 100644 --- a/src/core/pair_criteria/PairCriterion.hpp +++ b/src/core/pair_criteria/PairCriterion.hpp @@ -41,7 +41,7 @@ class PairCriterion { const bool res = decide(p1, p2); return res; } - + virtual ~PairCriterion() = default; }; } // namespace PairCriteria diff --git a/src/script_interface/pair_criteria/BondCriterion.hpp b/src/script_interface/pair_criteria/BondCriterion.hpp index bbb4e48dcd3..f98289431b1 100644 --- a/src/script_interface/pair_criteria/BondCriterion.hpp +++ b/src/script_interface/pair_criteria/BondCriterion.hpp @@ -41,9 +41,9 @@ class BondCriterion : public PairCriterion { {{"bond_type", [this](Variant const &v) { m_c->set_bond_type(get_value(v)); }, [this]() { return m_c->get_bond_type(); }}, - {"cut_off", + {"cut_off", [this](Variant const &v2) { m_c->set_cut_off(get_value(v2)); }, - [this]() { return m_c->get_cut_off(); }} }); + [this]() { return m_c->get_cut_off(); }}}); } std::shared_ptr<::PairCriteria::PairCriterion> diff --git a/src/script_interface/pair_criteria/EnergyCriterion.hpp b/src/script_interface/pair_criteria/EnergyCriterion.hpp index 99632c2b0c2..8994d13ef80 100644 --- a/src/script_interface/pair_criteria/EnergyCriterion.hpp +++ b/src/script_interface/pair_criteria/EnergyCriterion.hpp @@ -44,9 +44,11 @@ class EnergyCriterion : public PairCriterion { {{"d_cut_off", [this](Variant const &v) { m_c->set_cut_off(get_value(v)); }, [this]() { return m_c->get_cut_off(); }}, - {"e_cut_off", - [this](Variant const &v2){m_c->set_e_cut_off(get_value(v2)); }, - [this](){return m_c->get_e_cut_off(); }} }); + {"e_cut_off", + [this](Variant const &v2) { + m_c->set_e_cut_off(get_value(v2)); + }, + [this]() { return m_c->get_e_cut_off(); }}}); } std::shared_ptr<::PairCriteria::PairCriterion>