Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bond breakage #4995

Open
wants to merge 6 commits into
base: python
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions src/core/bond_breakage/bond_breakage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,40 @@ void BondBreakage::process_queue_impl(System::System &system) {
}
}

bool bond_handler(BondBreakage &bond_breakage, Particle &p,
std::span<Particle *> partners, int bond_id,
BoxGeometry const &box_geo) {

if (partners.size() == 1u) { // pair bonds
auto d = box_geo.get_mi_vector(p.pos(), partners[0]->pos()).norm();
return bond_breakage.check_and_handle_breakage(
p.id(), {{partners[0]->id(), std::nullopt}}, bond_id, d);
}
if (partners.size() == 2u) { // angle bond
auto d =
box_geo.get_mi_vector(partners[0]->pos(), partners[1]->pos()).norm();
return bond_breakage.check_and_handle_breakage(
p.id(), {{partners[0]->id(), partners[1]->id()}}, bond_id, d);
}
return false;
}

void execute_bond_breakage(System::System &system,
BondBreakage &bond_breakage) {
// Clear the bond breakage queue
bond_breakage.clear_queue();

// Create the bond kernel function (the bond handler)
auto bond_kernel = [&](Particle &p, int bond_id,
std::span<Particle *> partners) {
return bond_handler(bond_breakage, p, partners, bond_id, *system.box_geo);
};

// Use the CellStructure::bond_loop to process bonds
system.cell_structure->bond_loop(bond_kernel);

// Process the bond breakage queue
bond_breakage.process_queue(system);
}

} // namespace BondBreakage
2 changes: 2 additions & 0 deletions src/core/bond_breakage/bond_breakage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,6 @@ class BondBreakage {
int bond_type);
};

void execute_bond_breakage(System::System &system, BondBreakage &bond_breakage);

} // namespace BondBreakage
16 changes: 16 additions & 0 deletions src/python/espressomd/bond_breakage.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,19 @@ def __getitem__(self, key):

def __setitem__(self, key, value):
return super().__setitem__(self._get_key(key), value)


@script_interface_register
class BondBreakage(ScriptInterfaceHelper):
"""Bond breakage interface.

This class provides methods to manage and manipulate bond breakage.

Methods
-------
execute(parameters)
Executes the bond breakage with the given parameters.
"""

_so_name = "BondBreakage::BondBreakage"
_so_bind_methods = ("execute",)
29 changes: 29 additions & 0 deletions src/script_interface/bond_breakage/BondBreakage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "BondBreakage.hpp"

#include "script_interface/Variant.hpp"
#include "script_interface/get_value.hpp"

#include "core/bond_breakage/bond_breakage.hpp"
#include "core/system/System.hpp"

#include <string>

namespace ScriptInterface {
namespace BondBreakage {

Variant BondBreakage::do_call_method(std::string const &name,
VariantMap const &) {
if (name == "execute") {

context()->parallel_try_catch([]() {
execute_bond_breakage(System::get_system(),
*System::get_system().bond_breakage);
});

return {};
}
return {};
}

} // namespace BondBreakage
} // namespace ScriptInterface
17 changes: 17 additions & 0 deletions src/script_interface/bond_breakage/BondBreakage.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once

#include "script_interface/ScriptInterface.hpp"
#include "script_interface/auto_parameters/AutoParameters.hpp"
#include <string>

namespace ScriptInterface {
namespace BondBreakage {

class BondBreakage : public AutoParameters<BondBreakage> {
public:
Variant do_call_method(std::string const &name,
VariantMap const &parameters) override;
};

} // namespace BondBreakage
} // namespace ScriptInterface
6 changes: 4 additions & 2 deletions src/script_interface/bond_breakage/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#

target_sources(espresso_script_interface
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/initialize.cpp)
target_sources(
espresso_script_interface
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/initialize.cpp
${CMAKE_CURRENT_SOURCE_DIR}/BondBreakage.cpp)
2 changes: 2 additions & 0 deletions src/script_interface/bond_breakage/initialize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

#include "initialize.hpp"
#include "BondBreakage.hpp"
#include "BreakageSpec.hpp"
#include "BreakageSpecs.hpp"

Expand All @@ -26,6 +27,7 @@ namespace BondBreakage {
void initialize(Utils::Factory<ObjectHandle> *f) {
f->register_new<BreakageSpec>("BondBreakage::BreakageSpec");
f->register_new<BreakageSpecs>("BondBreakage::BreakageSpecs");
f->register_new<BondBreakage>("BondBreakage::BondBreakage");
}
} // namespace BondBreakage
} // namespace ScriptInterface