50 std::vector<int>
const &pids,
51 std::vector<std::vector<int>>
const &all_bonds_ids,
52 std::vector<std::vector<std::vector<int>>>
const &all_bonds_partner_ids,
54 for (std::size_t i = 0; i < pids.size(); ++i) {
55 auto const pid = pids[i];
56 auto const bonds_ids = all_bonds_ids[i];
57 auto const bonds_partner_ids = all_bonds_partner_ids[i];
60 if (p !=
nullptr and not p->is_ghost()) {
64 for (std::size_t j = 0; j < bonds_ids.size(); ++j) {
65 std::vector<int> particle_ids = {pid};
66 std::ranges::copy(bonds_partner_ids[j], std::back_inserter(particle_ids));
67 ::add_bond(system, bonds_ids[j], particle_ids);
73#ifdef ESPRESSO_EXCLUSIONS
76 std::vector<std::vector<int>>
const &exclusion_lists,
77 boost::mpi::communicator
const &comm,
80 for (std::size_t i = 0; i < pids.size(); ++i) {
81 auto const pid = pids[i];
82 auto const &exclusion_list = exclusion_lists[i];
83 for (
auto const excluded_pid : exclusion_list) {
87 if (p !=
nullptr and not p->is_ghost()) {
89 for (
auto const old_excluded_pid : p->exclusions()) {
93 for (
auto const excluded_pid : exclusion_list) {
94 if (not p->has_exclusion(excluded_pid)) {
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()) {
123 auto const &new_type = types[i];
125 throw std::domain_error(
error_msg(
"type",
"must be an integer >= 0"));
128 p->type() = new_type;
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()) {
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");
162 if (not
context()->is_head_node()) {
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")) {
179 if (param_name ==
"bonds") {
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)) {
194 if (param_name ==
"pos") {
197 get_value<std::vector<Utils::Vector3d>>(params,
"values"));
198 }
else if (param_name ==
"type") {
200 get_value<std::vector<int>>(params,
"values"),
203#ifdef ESPRESSO_ELECTROSTATICS
204 else if (param_name ==
"q") {
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
218 else if (param_name ==
"exclusions") {
219 auto const excluded_pids =
223 get_value<std::vector<std::vector<int>>>(params,
"values"),
227 else if (param_name ==
"bonds") {
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"),
242 m_cell_structure.lock(),
243 m_bonded_ias.lock());
245 params.at(
"values"));
250 if (
name ==
"get_param_parallel") {
254 if (param_name ==
"type") {
255 auto const getter{[](
Particle const &p) {
return p.type(); }};
259 if (param_name ==
"q") {
260 auto const getter{[](
Particle const &p) {
return p.q(); }};
264 if (param_name ==
"pos") {
265 auto const &box_geo = *get_system()->box_geo;
266 auto const getter = [&box_geo](
Particle const &p) {
267 return box_geo.unfolded_position(p.pos(), p.image_box());
272 if (param_name ==
"pos_folded") {
273 auto const &box_geo = *get_system()->box_geo;
274 auto const getter = [&box_geo](
Particle const &p) {
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>(
291 context()->make_shared(
"Particles::ParticleModifier", obj_params));
292 for (
int pid : m_id_selection) {
294 result.emplace_back(so->get_parameter(param_name));
299 if (not
context()->is_head_node()) {
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.
void make_particle_type_exist(int type)
Make sure the interaction parameter list is large enough to cover interactions for this particle type...
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.
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
Script interface wrapper for the system class.
void on_particle_change()
Called every time a particle property changes.
void on_particle_charge_change()
Called every time a particle charge changes.
std::shared_ptr< InteractionsNonBonded > nonbonded_ias
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.
auto get_particles_properties(std::vector< int > const &pids, std::function< T(Particle const &)> const &getter, Context *context, CellStructure const &cell_structure)
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.
make_recursive_variant< ObjectRef > Variant
Possible types for parameters.
T get_value(Variant const &v)
Extract value of specific type T from a Variant.
T get_value_or(VariantMap const &vals, std::string const &name, T const &default_)
Get a value from a VariantMap by name, or return a default value if it does not exist.
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.
static auto & get_cell_structure()
bool particle_exists(int p_id)
Check if particle exists.
Particles creation and deletion.
Struct holding all information for one particle.