diff --git a/src/core/particle_data.hpp b/src/core/particle_data.hpp index 7a875746949..7b39c92f154 100644 --- a/src/core/particle_data.hpp +++ b/src/core/particle_data.hpp @@ -373,32 +373,6 @@ int number_of_particles_with_type(int type); // This is needed, because cython does not support conditional compilation // within a ctypedef definition -#ifdef LB_ELECTROHYDRODYNAMICS -inline Utils::Vector3d get_particle_mu_E(Particle const *p) { - return p->mu_E(); -} -#endif - -#ifdef ROTATION -inline Utils::Vector3d get_particle_omega_body(Particle const *p) { - return p->omega(); -} - -inline Utils::Vector3d get_particle_torque_body(Particle const *p) { - return p->torque(); -} - -inline Utils::Quaternion get_particle_quat(Particle const *p) { - return p->quat(); -} -#endif - -inline double get_particle_q(Particle const *p) { return p->q(); } - -#ifdef VIRTUAL_SITES -inline bool get_particle_virtual(Particle const *p) { return p->is_virtual(); } -#endif - #ifdef VIRTUAL_SITES_RELATIVE inline Utils::Quaternion get_particle_vs_quat(Particle const *p) { return p->vs_relative().quat; @@ -412,19 +386,7 @@ inline Utils::Quaternion get_particle_vs_relative(Particle const *p, } #endif -#ifdef DIPOLES -inline double get_particle_dipm(Particle const *p) { return p->dipm(); } -#endif - #ifdef EXTERNAL_FORCES -inline Utils::Vector3d get_particle_ext_force(Particle const *p) { - return p->ext_force(); -} -#ifdef ROTATION -inline Utils::Vector3d get_particle_ext_torque(Particle const *p) { - return p->ext_torque(); -} -#endif inline Utils::Vector3i get_particle_fix(Particle const *p) { return Utils::Vector3i{ {p->is_fixed_along(0), p->is_fixed_along(1), p->is_fixed_along(2)}}; @@ -452,24 +414,12 @@ inline double get_particle_gamma_rot(Particle const *p) { #endif // ROTATION #endif // THERMOSTAT_PER_PARTICLE -#ifdef ENGINE -inline ParticleParametersSwimming get_particle_swimming(Particle const *p) { - return p->swimming(); -} -#endif - -#ifdef ROTATIONAL_INERTIA -inline Utils::Vector3d get_particle_rotational_inertia(Particle const *p) { - return p->rinertia(); -} -#endif - #ifdef ROTATION inline Utils::Vector3i get_particle_rotation(Particle const *p) { return Utils::Vector3i{{p->can_rotate_around(0), p->can_rotate_around(1), p->can_rotate_around(2)}}; } -#endif +#endif // ROTATION /** * @brief Check if particle exists. diff --git a/src/python/espressomd/particle_data.pxd b/src/python/espressomd/particle_data.pxd index ea837c48f90..99b076af16f 100644 --- a/src/python/espressomd/particle_data.pxd +++ b/src/python/espressomd/particle_data.pxd @@ -25,53 +25,51 @@ include "myconfig.pxi" from .utils cimport Span + # Import particle data structures and setter functions from particle_data.hpp cdef extern from "particle_data.hpp": cppclass BondView: int bond_id() Span[const int] partner_ids() + ctypedef struct particle_parameters_swimming "ParticleParametersSwimming": + bool swimming + double f_swim + double v_swim + int push_pull + double dipole_length + # Note: Conditional compilation is not possible within ctypedef blocks. # Therefore, only member variables are imported here, which are always compiled into ESPResSo. # For all other properties, getter-functions have to be used on the c - # level. - ctypedef struct particle_properties "ParticleProperties": - int identity - int mol_id - int type - double mass - - ctypedef struct particle_position "ParticlePosition": - Vector3d p - Vector3d calc_director() - - ctypedef struct particle_force "ParticleForce": - Vector3d f - - ctypedef struct particle_momentum "ParticleMomentum": - Vector3d v - - ctypedef struct particle_local "ParticleLocal": - Vector3i i - double lees_edwards_offset - int lees_edwards_flag + # level. ctypedef struct particle "Particle": - particle_properties p - particle_position r - particle_momentum m - particle_force f - particle_local l vector[int] exclusions() except + Vector3d calc_dip() - - IF ENGINE: - ctypedef struct particle_parameters_swimming "ParticleParametersSwimming": - bool swimming - double f_swim - double v_swim - int push_pull - double dipole_length + int type() + int identity() + double mass() + int mol_id() + Vector3d pos() + Vector3d calc_director() + Vector3d force() + Vector3d v() + Vector3i image_box() + double lees_edwards_offset() + int lees_edwards_flag() + + Vector3d rinertia() + Vector3d mu_E() + double q() + Vector3d omega() + Vector3d torque() + Quaternion[double] quat() + double dipm() + bint is_virtual() + Vector3d ext_force() + Vector3d ext_torque() + particle_parameters_swimming swimming() # Setter/getter/modifier functions functions void prefetch_particle_data(vector[int] ids) @@ -88,7 +86,6 @@ cdef extern from "particle_data.hpp": IF ROTATIONAL_INERTIA: void set_particle_rotational_inertia(int part, const Vector3d & rinertia) - Vector3d get_particle_rotational_inertia(const particle * p) IF ROTATION: void set_particle_rotation(int part, const Vector3i & flag) @@ -98,7 +95,6 @@ cdef extern from "particle_data.hpp": IF LB_ELECTROHYDRODYNAMICS: void set_particle_mu_E(int part, const Vector3d & mu_E) - Vector3d get_particle_mu_E(const particle * p) void set_particle_type(int part, int type) @@ -106,22 +102,17 @@ cdef extern from "particle_data.hpp": IF ROTATION: void set_particle_quat(int part, const Quaternion[double] & quat) - Quaternion[double] get_particle_quat(const particle * p) void set_particle_director(int part, const Vector3d & director) void set_particle_omega_lab(int part, const Vector3d & omega) void set_particle_omega_body(int part, const Vector3d & omega) void set_particle_torque_lab(int part, const Vector3d & torque) - Vector3d get_particle_omega_body(const particle * p) - Vector3d get_particle_torque_body(const particle * p) IF DIPOLES: void set_particle_dip(int part, const Vector3d & dip) void set_particle_dipm(int part, double dipm) - double get_particle_dipm(const particle * p) IF VIRTUAL_SITES: void set_particle_virtual(int part, int isVirtual) - bint get_particle_virtual(const particle * p) IF THERMOSTAT_PER_PARTICLE: IF PARTICLE_ANISOTROPY: @@ -145,15 +136,11 @@ cdef extern from "particle_data.hpp": void set_particle_vs_relative(int part, int vs_relative_to, double vs_distance, const Quaternion[double] & rel_ori) void set_particle_vs_quat(int part, const Quaternion[double] & vs_quat) - double get_particle_q(const particle * p) - IF EXTERNAL_FORCES: IF ROTATION: void set_particle_ext_torque(int part, const Vector3d & torque) - Vector3d get_particle_ext_torque(const particle * p) void set_particle_ext_force(int part, const Vector3d & force) - Vector3d get_particle_ext_force(const particle * p) void set_particle_fix(int part, const Vector3i & flag) Vector3i get_particle_fix(const particle * p) @@ -168,7 +155,6 @@ cdef extern from "particle_data.hpp": IF ENGINE: void set_particle_swimming(int part, particle_parameters_swimming swim) - particle_parameters_swimming get_particle_swimming(const particle * p) int remove_particle(int part) except + diff --git a/src/python/espressomd/particle_data.pyx b/src/python/espressomd/particle_data.pyx index e433ea617b3..623ef1e439f 100644 --- a/src/python/espressomd/particle_data.pyx +++ b/src/python/espressomd/particle_data.pyx @@ -103,7 +103,7 @@ cdef class ParticleHandle: def __get__(self): self.update_particle_data() - return self._id + return self.particle_data.identity() # The individual attributes of a particle are implemented as properties. @@ -127,7 +127,7 @@ cdef class ParticleHandle: def __get__(self): self.update_particle_data() - return self.particle_data.p.type + return self.particle_data.type() # Particle MolId property mol_id: @@ -154,7 +154,7 @@ cdef class ParticleHandle: def __get__(self): self.update_particle_data() - return self.particle_data.p.mol_id + return self.particle_data.mol_id() # Position property pos: @@ -175,7 +175,7 @@ cdef class ParticleHandle: def __get__(self): self.update_particle_data() - return make_array_locked(unfolded_position(< Vector3d > self.particle_data.r.p, < Vector3i > self.particle_data.l.i, box_geo.length())) + return make_array_locked(unfolded_position( < Vector3d > self.particle_data.pos(), < Vector3i > self.particle_data.image_box(), box_geo.length())) property pos_folded: """ @@ -213,7 +213,7 @@ cdef class ParticleHandle: def __get__(self): self.update_particle_data() return make_array_locked(folded_position( - Vector3d(self.particle_data.r.p), box_geo)) + Vector3d(self.particle_data.pos()), box_geo)) property image_box: """ @@ -225,9 +225,9 @@ cdef class ParticleHandle: def __get__(self): self.update_particle_data() - return array_locked([self.particle_data.l.i[0], - self.particle_data.l.i[1], - self.particle_data.l.i[2]]) + return array_locked([self.particle_data.image_box()[0], + self.particle_data.image_box()[1], + self.particle_data.image_box()[2]]) property lees_edwards_offset: """Contains the accumulated Lees-Edwards offset to reconstruct @@ -237,7 +237,7 @@ cdef class ParticleHandle: def __get__(self): self.update_particle_data() - return self.particle_data.l.lees_edwards_offset + return self.particle_data.lees_edwards_offset() def __set__(self, value): set_particle_lees_edwards_offset(self._id, value) @@ -250,7 +250,7 @@ cdef class ParticleHandle: def __get__(self): self.update_particle_data() - return self.particle_data.l.lees_edwards_flag + return self.particle_data.lees_edwards_flag() # Velocity property v: @@ -271,7 +271,7 @@ cdef class ParticleHandle: def __get__(self): self.update_particle_data() - return make_array_locked(self.particle_data.m.v) + return make_array_locked(self.particle_data.v()) # Force property f: @@ -293,9 +293,8 @@ cdef class ParticleHandle: def __get__(self): self.update_particle_data() - return make_array_locked(self.particle_data.f.f) + return make_array_locked(self.particle_data.force()) - # Bonds property bonds: """ The bonds stored by this particle. Note that bonds are only stored by @@ -322,7 +321,7 @@ cdef class ParticleHandle: # i.e., we delete all existing bonds delete_particle_bonds(self._id) - # Empty list? ony delete + # Empty list? only delete if _bonds: nlvl = nesting_level(_bonds) if nlvl == 1: # Single item @@ -336,7 +335,6 @@ cdef class ParticleHandle: def __get__(self): bonds = [] - part_bonds = get_particle_bonds(self._id) # Go through the bond list of the particle for part_bond in part_bonds: @@ -380,7 +378,7 @@ cdef class ParticleHandle: def __get__(self): self.update_particle_data() - return self.particle_data.p.mass + return self.particle_data.mass() IF ROTATION: property omega_lab: @@ -436,7 +434,7 @@ cdef class ParticleHandle: def __get__(self): self.update_particle_data() - cdef Quaternion[double] q = get_particle_quat(self.particle_data) + cdef Quaternion[double] q = self.particle_data.quat() return array_locked([q[0], q[1], q[2], q[3]]) property director: @@ -468,7 +466,7 @@ cdef class ParticleHandle: def __get__(self): self.update_particle_data() - return make_array_locked(self.particle_data.r.calc_director()) + return make_array_locked(self.particle_data.calc_director()) property omega_body: """ @@ -491,9 +489,7 @@ cdef class ParticleHandle: def __get__(self): self.update_particle_data() - cdef Vector3d omega_body - omega_body = get_particle_omega_body(self.particle_data) - return make_array_locked(omega_body) + return make_array_locked(self.particle_data.omega()) property torque_lab: """ @@ -521,7 +517,7 @@ cdef class ParticleHandle: self.update_particle_data() cdef Vector3d torque_body cdef Vector3d torque_space - torque_body = get_particle_torque_body(self.particle_data) + torque_body = self.particle_data.torque() torque_space = convert_vector_body_to_space( dereference(self.particle_data), torque_body) @@ -553,8 +549,7 @@ cdef class ParticleHandle: def __get__(self): self.update_particle_data() - return make_array_locked( - get_particle_rotational_inertia(self.particle_data)) + return make_array_locked(self.particle_data.rinertia()) # Charge property q: @@ -575,7 +570,7 @@ cdef class ParticleHandle: def __get__(self): self.update_particle_data() - return get_particle_q(self.particle_data) + return self.particle_data.q() IF LB_ELECTROHYDRODYNAMICS: property mu_E: @@ -600,7 +595,7 @@ cdef class ParticleHandle: def __get__(self): self.update_particle_data() - return make_array_locked(get_particle_mu_E(self.particle_data)) + return make_array_locked(self.particle_data.mu_E()) property virtual: """Virtual flag. @@ -627,14 +622,8 @@ cdef class ParticleHandle: "To make a particle virtual, VIRTUAL_SITES has to be defined in myconfig.hpp") def __get__(self): - # Note: the pointoer_to... mechanism doesn't work if virtual sites - # are not compiled in, because then, in the core, p.p.is_virtual - # is constexpr. - IF VIRTUAL_SITES: - self.update_particle_data() - return get_particle_virtual(self.particle_data) - ELSE: - return False + self.update_particle_data() + return self.particle_data.is_virtual() IF VIRTUAL_SITES_RELATIVE: property vs_quat: @@ -765,7 +754,7 @@ cdef class ParticleHandle: def __get__(self): self.update_particle_data() - return get_particle_dipm(self.particle_data) + return self.particle_data.dipm() IF EXTERNAL_FORCES: property ext_force: @@ -787,7 +776,7 @@ cdef class ParticleHandle: def __get__(self): self.update_particle_data() return make_array_locked( - get_particle_ext_force(self.particle_data)) + self.particle_data.ext_force()) property fix: """ @@ -843,8 +832,7 @@ cdef class ParticleHandle: def __get__(self): self.update_particle_data() - return make_array_locked( - get_particle_ext_torque(self.particle_data)) + return make_array_locked(self.particle_data.ext_torque()) IF THERMOSTAT_PER_PARTICLE: IF PARTICLE_ANISOTROPY: @@ -1163,7 +1151,7 @@ cdef class ParticleHandle: swim = {} mode = "N/A" cdef particle_parameters_swimming _swim - _swim = get_particle_swimming(self.particle_data) + _swim = self.particle_data.swimming() if _swim.push_pull == -1: mode = 'pusher' @@ -1212,7 +1200,6 @@ cdef class ParticleHandle: if self._id in bond[1:]: raise Exception( f"Bond partners {bond[1:]} include the particle {self._id} itself.") - add_particle_bond(self._id, make_const_span[int](bond_info, len(bond))) def delete_verified_bond(self, bond): @@ -1263,30 +1250,25 @@ cdef class ParticleHandle: "Bond needs to be a tuple or list containing bond type and partners.") bond = list(bond) - # Bond type or numerical bond id if is_valid_type(bond[0], int): bond[0] = BondedInteractions()[bond[0]] elif not isinstance(bond[0], BondedInteraction): raise Exception( f"1st element of Bond has to be of type BondedInteraction or int, got {type(bond[0])}.") - # Check the bond is in the list of active bonded interactions if bond[0]._bond_id == -1: raise Exception( "The bonded interaction has not yet been added to the list of active bonds in ESPResSo.") - # Validity of the numeric id if not bonded_ia_params_zero_based_type(bond[0]._bond_id): raise ValueError( f"The bond type {bond[0]._bond_id} does not exist.") - # Number of partners expected_num_partners = bond[0].call_method('get_num_partners') if len(bond) - 1 != expected_num_partners: raise ValueError( f"Bond {bond[0]} needs {expected_num_partners} partners.") - # Type check on partners for i in range(1, len(bond)): if isinstance(bond[i], ParticleHandle): @@ -1295,7 +1277,6 @@ cdef class ParticleHandle: elif not is_valid_type(bond[i], int): raise ValueError( "Bond partners have to be of type integer or ParticleHandle.") - return tuple(bond) def add_bond(self, bond): @@ -1333,7 +1314,6 @@ cdef class ParticleHandle: >>> p1.add_bond((0, p2)) """ - _bond = self.normalize_and_check_bond_or_throw_exception(bond) if _bond in self.bonds: raise RuntimeError( diff --git a/src/python/espressomd/visualization_mayavi.pyx b/src/python/espressomd/visualization_mayavi.pyx index f4116818165..56fe68d83d4 100644 --- a/src/python/espressomd/visualization_mayavi.pyx +++ b/src/python/espressomd/visualization_mayavi.pyx @@ -213,8 +213,8 @@ cdef class mayaviLive: if not p: continue - coords[j, :] = numpy.array([p.r.p[0], p.r.p[1], p.r.p[2]]) - t = p.p.type + coords[j, :] = numpy.array([p.pos()[0], p.pos()[1], p.pos()[2]]) + t = p.type() types[j] = t + 1 radii[j] = self._determine_radius(t) @@ -244,8 +244,9 @@ cdef class mayaviLive: t = bonds[3 * n + 2] p1 = &get_particle_data(i) p2 = &get_particle_data(j) - bond_coords[n, :3] = numpy.array([p1.r.p[0], p1.r.p[1], p1.r.p[2]]) - bond_coords[n, 3:6] = make_array_locked( < const Vector3d > box_geo.get_mi_vector(Vector3d(p2.r.p), Vector3d(p1.r.p))) + bond_coords[n, :3] = numpy.array( + [p1.pos()[0], p1.pos()[1], p1.pos()[2]]) + bond_coords[n, 3:6] = make_array_locked(< const Vector3d > box_geo.get_mi_vector(Vector3d(p2.pos()), Vector3d(p1.pos()))) bond_coords[n, 6] = t boxl = self.system.box_l