50 std::vector<int>
const &
pids,
54 for (std::size_t i = 0; i <
pids.size(); ++i) {
55 auto const pid =
pids[i];
60 if (p !=
nullptr and not p->is_ghost()) {
68 system.on_particle_change();
73#ifdef ESPRESSO_EXCLUSIONS
77 boost::mpi::communicator
const &comm,
80 for (std::size_t i = 0; i <
pids.size(); ++i) {
81 auto const pid =
pids[i];
87 if (p !=
nullptr and not p->is_ghost()) {
100 system.on_particle_change();
106 std::vector<Utils::Vector3d>
const &positions) {
107 for (std::size_t i = 0; i <
pids.size(); ++i) {
108 auto const pid =
pids[i];
109 auto const &pos = positions[i];
116 std::vector<int>
const &
types,
119 for (std::size_t i = 0; i <
pids.size(); ++i) {
120 auto const pid =
pids[i];
122 if (p !=
nullptr and not p->is_ghost()) {
125 throw std::domain_error(
error_msg(
"type",
"must be an integer >= 0"));
133#ifdef ESPRESSO_ELECTROSTATICS
135 std::vector<double>
const &charges,
138 for (std::size_t i = 0; i <
pids.size(); ++i) {
139 auto const pid =
pids[i];
141 if (p !=
nullptr and not p->is_ghost()) {
145 system.on_particle_charge_change();
150 if (params.contains(
"__cell_structure")) {
152 params,
"__cell_structure");
153 so->configure(*
this);
154 m_cell_structure =
so;
156 if (params.contains(
"__bonded_ias")) {
158 params,
"__bonded_ias");
165 for (
auto const pid : m_id_selection) {
167 throw std::out_of_range(
"Particle does not exist: " +
168 std::to_string(pid));
175 if (
name ==
"set_param_parallel") {
177 if (
not params.contains(
"values")) {
180 if (
not params.contains(
"all_bonds_ids")) {
181 throw Exception(
"Parameter 'all_bonds_ids' is missing");
183 if (
not params.contains(
"all_bonds_partner_ids")) {
184 throw Exception(
"Parameter 'all_bonds_partner_ids' is missing");
187 throw Exception(
"Parameter 'values' is missing");
192 if (m_special_parameters.contains(
param_name)) {
197 get_value<std::vector<Utils::Vector3d>>(params,
"values"));
200 get_value<std::vector<int>>(params,
"values"),
201 *get_cell_structure(), *get_system());
203#ifdef ESPRESSO_ELECTROSTATICS
205 std::vector<double> charges;
206 if (
is_type<std::vector<int>>(params.at(
"values"))) {
208 charges = std::vector<double>(
tmp.begin(),
tmp.end());
217#ifdef ESPRESSO_EXCLUSIONS
223 get_value<std::vector<std::vector<int>>>(params,
"values"),
224 context()->get_comm(), *get_cell_structure(), *get_system());
230 get_value<std::vector<std::vector<int>>>(params,
"all_bonds_ids"),
231 get_value<std::vector<std::vector<std::vector<int>>>>(
232 params,
"all_bonds_partner_ids"),
233 *get_cell_structure(), *get_system());
242 m_cell_structure.lock(),
243 m_bonded_ias.lock());
245 params.at(
"values"));
250 if (
name ==
"get_param_parallel") {
257 *get_cell_structure());
262 *get_cell_structure());
265 auto const &box_geo = *get_system()->box_geo;
267 return box_geo.unfolded_position(p.pos(), p.image_box());
273 auto const &box_geo = *get_system()->box_geo;
275 return box_geo.folded_position(p.pos());
282 if (!
context()->is_head_node()) {
285 std::vector<Variant> result;
286 result.reserve(m_id_selection.size());
288 {
"__cell_structure", m_cell_structure.lock()},
289 {
"__bonded_ias", m_bonded_ias.lock()}};
290 auto so = std::dynamic_pointer_cast<ParticleModifier>(
292 for (
int pid : m_id_selection) {
302 if (
name ==
"prefetch_particle_data") {
307 if (
name ==
"get_particle") {
309 {
"__cell_structure", m_cell_structure.lock()},
310 {
"__bonded_ias", m_bonded_ias.lock()}};
ScriptInterface::Context decorates ScriptInterface::ObjectHandle objects with a context: a creation p...
Vector implementation and trait types for boost qvm interoperability.
bool add_bond(System::System &system, int bond_id, std::vector< int > const &particle_ids)
Add a bond to a particle.
Describes a cell structure / cell system.
Particle * get_local_particle(int id)
Get a local particle by id.
virtual void parallel_try_catch(std::function< void()> const &cb) const =0
virtual std::shared_ptr< ObjectHandle > make_shared(std::string const &name, const VariantMap ¶meters)=0
Get a new reference counted instance of a script interface by name.
virtual bool is_head_node() const =0
Context * context() const
Responsible context.
std::string_view name() const
Variant do_call_method(std::string const &name, VariantMap const ¶ms) override
void do_construct(VariantMap const ¶ms) override
static void set_particles_charges(std::vector< int > const &pids, std::vector< double > const &charges, CellStructure &cell_structure, ::System::System &system)
static void set_particles_bonds(std::vector< int > const &pids, std::vector< std::vector< int > > const &all_bonds_ids, std::vector< std::vector< std::vector< int > > > const &all_bonds_partner_ids, ::CellStructure &cell_structure, ::System::System &system)
void particle_exclusion_sanity_checks(int pid1, int pid2, ::CellStructure &cell_structure, auto const &comm)
void set_from_vector_like(std::vector< int > const &pids, std::string const ¶m_name, Container const &values, Context *context, std::shared_ptr< CellSystem::CellSystem > cell_structure, std::shared_ptr< Interactions::BondedInteractions > bonded_ias)
void local_remove_exclusion(int pid1, int pid2, ::CellStructure &cell_structure)
Locally remove an exclusion to a particle.
static void set_particles_types(std::vector< int > const &pids, std::vector< int > const &types, CellStructure &cell_structure, ::System::System &system)
void particle_checks(int p_id, Utils::Vector3d const &pos)
auto error_msg(std::string const &name, std::string const &reason)
static void set_particles_exclusions(std::vector< int > const &pids, std::vector< std::vector< int > > const &exclusion_lists, boost::mpi::communicator const &comm, ::CellStructure &cell_structure, ::System::System &system)
static void set_particles_positions(std::vector< int > const &pids, std::vector< Utils::Vector3d > const &positions)
void local_add_exclusion(int pid1, int pid2, ::CellStructure &cell_structure)
Locally add an exclusion to a particle.
constexpr bool is_type(Variant const &v)
Check is a Variant holds a specific type.
T get_value(Variant const &v)
Extract value of specific type T from a Variant.
std::unordered_map< std::string, Variant > VariantMap
Various procedures concerning interactions between particles.
void set_particle_pos(int p_id, Utils::Vector3d const &pos)
Move particle to a new position.
void prefetch_particle_data(std::span< const int > in_ids)
Fetch a range of particle into the fetch cache.
bool particle_exists(int p_id)
Check if particle exists.
Particles creation and deletion.
Struct holding all information for one particle.
constexpr auto const & bonds() const
constexpr auto const & q() const
Recursive variant implementation.