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 <string>
36#include <vector>
37
38namespace ScriptInterface {
39namespace ClusterAnalysis {
40
41class ClusterStructure : public AutoParameters<ClusterStructure> {
42public:
45 {{"pair_criterion",
46 [this](Variant const &value) {
47 m_pc =
49 if (m_pc) {
50 m_cluster_structure.set_pair_criterion(m_pc->pair_criterion());
51 }
52 },
53 [this]() { return m_pc; }}});
54 }
55
56 void do_construct(VariantMap const &params) override {
57 auto local_params = params;
58 local_params.erase("system");
60 auto system_si =
63 system_si->get_parameter("part"));
64 m_cluster_structure.attach(system_si->get_system().box_geo);
65 }
66
67 Variant do_call_method(std::string const &method,
68 VariantMap const &parameters) override {
69 if (method == "get_cluster") {
70 auto const cluster_id = get_value<int>(parameters.at("id"));
71 // Note: Cluster objects are generated on the fly, to avoid having to
72 // store a script interface object for all clusters (which can be
73 // thousands)
74 auto c = std::dynamic_pointer_cast<Cluster>(
75 context()->make_shared("ClusterAnalysis::Cluster", {}));
76 c->set_cluster(m_cluster_structure.clusters.at(cluster_id));
77 c->set_particle_list(m_particle_list);
78
79 return c;
80 }
81 if (method == "cluster_ids") {
82 std::vector<int> cluster_ids;
83 for (const auto &it : m_cluster_structure.clusters) {
84 cluster_ids.push_back(it.first);
85 }
86 return cluster_ids;
87 }
88 if (method == "n_clusters") {
89 return int(m_cluster_structure.clusters.size());
90 }
91 if (method == "cid_for_particle") {
92 return m_cluster_structure.cluster_id.at(
93 get_value<int>(parameters.at("pid")));
94 }
95 if (method == "clear") {
96 m_cluster_structure.clear();
97 }
98 if (method == "run_for_all_pairs") {
99 m_cluster_structure.run_for_all_pairs();
100 }
101 if (method == "run_for_bonded_particles") {
102 m_cluster_structure.run_for_bonded_particles();
103 }
104 return {};
105 }
106
107private:
108 ::ClusterAnalysis::ClusterStructure m_cluster_structure;
109 std::shared_ptr<PairCriteria::PairCriterion> m_pc;
110 std::weak_ptr<Particles::ParticleList> m_particle_list;
111};
112
113} /* namespace ClusterAnalysis */
114} /* 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.
T get_value(Variant const &v)
Extract value of specific type T from a Variant.
std::unordered_map< std::string, Variant > VariantMap
Definition Variant.hpp:69
boost::make_recursive_variant< None, bool, int, std::size_t, double, std::string, ObjectRef, Utils::Vector3b, Utils::Vector3i, Utils::Vector2d, Utils::Vector3d, Utils::Vector4d, std::vector< int >, std::vector< double >, std::vector< boost::recursive_variant_ >, std::unordered_map< int, boost::recursive_variant_ >, std::unordered_map< std::string, boost::recursive_variant_ > >::type Variant
Possible types for parameters.
Definition Variant.hpp:67
static SteepestDescentParameters params
Currently active steepest descent instance.