ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
script_interface/cluster_analysis/ClusterStructure.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2010-2022 The ESPResSo project
3 * Copyright (C) 2002,2003,2004,2005,2006,2007,2008,2009,2010
4 * Max-Planck-Institute for Polymer Research, Theory Group
5 *
6 * This file is part of ESPResSo.
7 *
8 * ESPResSo is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * ESPResSo is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#pragma once
23
24#include "core/BoxGeometry.hpp"
27
33
34#include <memory>
35#include <ranges>
36#include <string>
37#include <vector>
38
39namespace ScriptInterface {
40namespace ClusterAnalysis {
41
42class ClusterStructure : public AutoParameters<ClusterStructure> {
43public:
46 {{"pair_criterion",
47 [this](Variant const &value) {
48 m_pc =
50 if (m_pc) {
51 m_cluster_structure.set_pair_criterion(m_pc->pair_criterion());
52 }
53 },
54 [this]() { return m_pc; }}});
55 }
56
57 void do_construct(VariantMap const &params) override {
58 auto local_params = params;
59 local_params.erase("system");
61 auto system_si =
64 system_si->get_parameter("part"));
65 m_cluster_structure.attach(system_si->get_system().box_geo);
66 }
67
68 Variant do_call_method(std::string const &method,
69 VariantMap const &parameters) override {
70 if (method == "get_cluster") {
71 auto const cluster_id = get_value<int>(parameters.at("id"));
72 // Note: Cluster objects are generated on the fly, to avoid having to
73 // store a script interface object for all clusters (which can be
74 // thousands)
75 auto c = std::dynamic_pointer_cast<Cluster>(
76 context()->make_shared("ClusterAnalysis::Cluster", {}));
77 c->set_cluster(m_cluster_structure.clusters.at(cluster_id));
78 c->set_particle_list(m_particle_list);
79
80 return c;
81 }
82 if (method == "cluster_ids") {
83 auto const view = std::views::elements<0>(m_cluster_structure.clusters);
84 return std::vector<int>{view.begin(), view.end()};
85 }
86 if (method == "n_clusters") {
87 return m_cluster_structure.clusters.size();
88 }
89 if (method == "cid_for_particle") {
90 return m_cluster_structure.cluster_id.at(
91 get_value<int>(parameters.at("pid")));
92 }
93 if (method == "clear") {
94 m_cluster_structure.clear();
95 }
96 if (method == "run_for_all_pairs") {
97 m_cluster_structure.run_for_all_pairs();
98 }
99 if (method == "run_for_bonded_particles") {
100 m_cluster_structure.run_for_bonded_particles();
101 }
102 return {};
103 }
104
105private:
106 ::ClusterAnalysis::ClusterStructure m_cluster_structure;
107 std::shared_ptr<PairCriteria::PairCriterion> m_pc;
108 std::weak_ptr<Particles::ParticleList> m_particle_list;
109};
110
111} /* namespace ClusterAnalysis */
112} /* namespace ScriptInterface */
Holds the result and parameters of a cluster analysis.
Bind parameters in the script interface.
void add_parameters(std::vector< AutoParameter > &&params)
Variant do_call_method(std::string const &method, VariantMap const &parameters) override
virtual void do_construct(VariantMap const &params)
Context * context() const
Responsible context.
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
std::unordered_map< std::string, Variant > VariantMap
Definition Variant.hpp:133
static SteepestDescentParameters params
Currently active steepest descent instance.
Recursive variant implementation.
Definition Variant.hpp:84