diff --git a/src/python/espressomd/particle_data.pyx b/src/python/espressomd/particle_data.pyx index 756b9ceb585..14459c359f1 100644 --- a/src/python/espressomd/particle_data.pyx +++ b/src/python/espressomd/particle_data.pyx @@ -40,7 +40,7 @@ COORDS_ALL_FIXED = COORD_FIXED(0) & COORD_FIXED(1) & COORD_FIXED(2) PARTICLE_EXT_TORQUE = 16 # List of particle attributes for pickle and the like -# Autogenerated from the class. Everything whic is of the same +# Autogenerated from the class. Everything which is of the same # type as ParticleHandle.pos (getter_wrapper) particle_attributes = [] for d in dir(ParticleHandle): @@ -84,12 +84,20 @@ cdef class ParticleHandle: # Particle Type property type: - """Particle type""" + """Particle type. + + The particle type is used to set interactions between different + particles. + + .. note:: + Type has to be :math:`\geq 0`. + + """ def __set__(self, _type): if isinstance(_type, int) and _type >= 0: if set_particle_type(self.id, _type) == 1: - raise Exception("set particle position first") + raise Exception("Set particle position first.") else: raise ValueError("type must be an integer >= 0") @@ -136,8 +144,9 @@ cdef class ParticleHandle: # Velocity property v: - """Particle velocity""" - + """Particle velocity. + The velocity remains variable and will be changed during integration. + """ def __set__(self, _v): global time_step cdef double myv[3] @@ -147,7 +156,7 @@ cdef class ParticleHandle: myv[i] = _v[i] myv[i] *= time_step if set_particle_v(self.id, myv) == 1: - raise Exception("set particle position first") + raise Exception("Set particle position first.") def __get__(self): global time_step, smaller_time_step @@ -169,7 +178,12 @@ cdef class ParticleHandle: # Force property f: - """Particle force""" + """Particle force. + + Whereas the velocity is modified with respect to the velocity you set + upon integration, the force it recomputed during the integration step and any + force set in this way is lost during the integration step. + """ def __set__(self, _f): global time_step @@ -179,7 +193,7 @@ cdef class ParticleHandle: myf[i] = _f[i] myf[i] *= (0.5 * time_step**2) if set_particle_f(self.id, myf) == 1: - raise Exception("set particle position first") + raise Exception("Set particle position first.") def __get__(self): global time_step @@ -190,13 +204,18 @@ cdef class ParticleHandle: # Bonds property bonds: - """Bond partners with respect to bonded interactions.""" + """Bond partners with respect to bonded interactions. + + .. note:: + Bond ids have to be :math:`\geq 0`. + + """ def __set__(self, _bonds): # First, we check that we got a list/tuple. if not hasattr(_bonds, "__getitem__"): raise ValueError( - "bonds have to specified as a tuple of tuples. (Lists can also be used)") + "Bonds have to specified as a tuple of tuples. (Lists can also be used).") bonds = list(_bonds) # as we modify it # Assigning to the bond property means replacing the existing value @@ -235,7 +254,8 @@ cdef class ParticleHandle: # MULTI_TIMESTEP IF MULTI_TIMESTEP == 1: property smaller_timestep: - """Particle flag specifying whether particle trajectory should be integrated with time_step of small_time_step""" + """Particle flag specifying whether particle trajectory should be + integrated with time_step of small_time_step.""" def __set__(self, _smaller_timestep): check_type_or_throw_except( @@ -251,14 +271,14 @@ cdef class ParticleHandle: # MASS property mass: - """Particle mass""" + """Particle mass.""" def __set__(self, _mass): IF MASS == 1: check_type_or_throw_except( _mass, 1, float, "Mass has to be 1 floats") if set_particle_mass(self.id, _mass) == 1: - raise Exception("set particle position first") + raise Exception("Set particle position first.") ELSE: raise Exception("You are trying to set the particle mass \ but the mass feature is not compiled in.") @@ -268,18 +288,31 @@ cdef class ParticleHandle: return self.particle_data.p.mass IF ROTATION == 1: - # Omega (angular velocity) lab frame property omega_lab: - """Angular velocity in lab frame""" + """Angular velocity in lab frame. + + .. note:: + + If you set the angular velocity of the particle in the lab + frame, the orientation of the particle + (:attr:`espressomd.particle_data.ParticleHandle.quat`) must be + set before setting omega_lab, otherwise the conversion from + lab to body frame will not be handled properly. + + .. seealso:: + + :attr:`espressomd.particle_data.ParticleHandle.omega_body` + + """ def __set__(self, _o): cdef double myo[3] check_type_or_throw_except( - _o, 3, float, "Omega_lab has to be 3 floats") + _o, 3, float, "Omega_lab has to be 3 floats.") for i in range(3): myo[i] = _o[i] if set_particle_omega_lab(self.id, myo) == 1: - raise Exception("set particle position first") + raise Exception("Set particle position first.") def __get__(self): self.update_particle_data() @@ -287,18 +320,21 @@ cdef class ParticleHandle: convert_omega_body_to_space( & (self.particle_data), o) return np.array([o[0], o[1], o[2]]) -# Quaternion property quat: - """Quaternions""" + """Quaternions. + + Sets the quaternion representation of the rotational position of + this particle. + """ def __set__(self, _q): cdef double myq[4] check_type_or_throw_except( - _q, 4, float, "Quaternions has to be 4 floats") + _q, 4, float, "Quaternions has to be 4 floats.") for i in range(4): myq[i] = _q[i] if set_particle_quat(self.id, myq) == 1: - raise Exception("set particle position first") + raise Exception("Set particle position first.") def __get__(self): self.update_particle_data() @@ -308,17 +344,17 @@ cdef class ParticleHandle: # Director ( z-axis in body fixed frame) property director: - """Director""" + """Director.""" def __set__(self, _q): raise Exception( - "Setting the director is not implemented in the c++-core of Espresso") + "Setting the director is not implemented in the c++-core of Espresso.") # cdef double myq[3] # check_type_or_throw_except(_q,3,float,"Director has to be 3 floats") # for i in range(3): # myq[i]=_q[i] # if set_particle_quatu(self.id, myq) == 1: -# raise Exception("set particle position first") +# raise Exception("Set particle position first.") def __get__(self): self.update_particle_data() @@ -327,18 +363,20 @@ cdef class ParticleHandle: return np.array([x[0], x[1], x[2]]) # ROTATIONAL_INERTIA -# Omega (angular velocity) body frame property omega_body: - """Angular velocity in body frame""" + """Angular velocity in body frame. + This property sets the angular momentum of this particle in the + particle’s co-rotating frame (or body frame). + """ def __set__(self, _o): cdef double myo[3] check_type_or_throw_except( - _o, 3, float, "Omega_body has to be 3 floats") + _o, 3, float, "Omega_body has to be 3 floats.") for i in range(3): myo[i] = _o[i] if set_particle_omega_body(self.id, myo) == 1: - raise Exception("set particle position first") + raise Exception("Set particle position first.") def __get__(self): self.update_particle_data() @@ -347,18 +385,32 @@ cdef class ParticleHandle: return np.array([o[0], o[1], o[2]]) -# Torque in lab frame property torque_lab: - """Torque in lab frame""" + """Torque in lab frame. + + This property defines the torque of this particle + in the fixed frame (or laboratory frame). + + .. note:: + + The orientation of the particle (:attr:`espressomd.particle_data.ParticleHandle.quat`) must be set + before setting this property, otherwise the conversion from lab to body frame + will not be handled properly. + + .. seealso:: + + :attr:`espressomd.particle_data.ParticleHandle.torque_body` + + """ def __set__(self, _t): cdef double myt[3] check_type_or_throw_except( - _t, 3, float, "Torque has to be 3 floats") + _t, 3, float, "Torque has to be 3 floats.") for i in range(3): myt[i] = _t[i] if set_particle_torque_lab(self.id, myt) == 1: - raise Exception("set particle position first") + raise Exception("Set particle position first.") def __get__(self): self.update_particle_data() @@ -368,16 +420,23 @@ cdef class ParticleHandle: IF ROTATIONAL_INERTIA == 1: property rinertia: - """Rotational inertia""" + """Rotational inertia. + + Sets the diagonal elements of this particles rotational inertia + tensor. These correspond with the inertial moments along the + coordinate axes in the particle’s co-rotating coordinate system. + When the particle’s quaternions are set to 1 0 0 0, the co-rotating + and the fixed (lab) frame are co-aligned. + """ def __set__(self, _rinertia): cdef double rinertia[3] check_type_or_throw_except( - _rinertia, 3, float, "Rotation_inertia has to be 3 floats") + _rinertia, 3, float, "Rotation_inertia has to be 3 floats.") for i in range(3): rinertia[i] = _rinertia[i] if set_particle_rotational_inertia(self.id, rinertia) == 1: - raise Exception("set particle position first") + raise Exception("Set particle position first.") def __get__(self): self.update_particle_data() @@ -388,15 +447,15 @@ cdef class ParticleHandle: # Charge IF ELECTROSTATICS == 1: property q: - """particle charge""" + """Particle charge.""" def __set__(self, _q): cdef double myq check_type_or_throw_except( - _q, 1, float, "Charge has to be floats") + _q, 1, float, "Charge has to be floats.") myq = _q if set_particle_q(self.id, myq) == 1: - raise Exception("set particle position first") + raise Exception("Set particle position first.") def __get__(self): self.update_particle_data() @@ -405,23 +464,22 @@ cdef class ParticleHandle: return x[0] def delete(self): - """Delete the particle""" + """Delete the particle.""" if remove_particle(self.id): - raise Exception("Could not delete particle") + raise Exception("Could not delete particle.") del self IF VIRTUAL_SITES == 1: - # virtual flag property virtual: - """virtual flag""" + """Virtual flag.""" def __set__(self, _v): if isinstance(_v, int): if set_particle_virtual(self.id, _v) == 1: - raise Exception("set particle position first") + raise Exception("Set particle position first.") else: - raise ValueError("virtual must be an integer >= 0") + raise ValueError("virtual must be an integer >= 0.") def __get__(self): self.update_particle_data() @@ -431,12 +489,12 @@ cdef class ParticleHandle: IF VIRTUAL_SITES_RELATIVE == 1: property vs_relative: - """virtual sites relative parameters""" + """Virtual sites relative parameters.""" def __set__(self, x): if len(x) != 3: raise ValueError( - "vs_relative needs input like id,distance,(q1,q2,q3,q4)") + "vs_relative needs input like id,distance,(q1,q2,q3,q4).") _relto = x[0] _dist = x[1] q = x[2] @@ -448,7 +506,7 @@ cdef class ParticleHandle: if isinstance(_relto, int) and isinstance(_dist, float): if set_particle_vs_relative(self.id, _relto, _dist, _q) == 1: - raise Exception("set particle position first") + raise Exception("Set particle position first.") else: raise ValueError( "vs_relative takes one int and one float as parameters.") @@ -463,37 +521,36 @@ cdef class ParticleHandle: # vs_auto_relate_to def vs_auto_relate_to(self, _relto): - """Setup this particle as virtual site relative to the particle with the given id""" + """Setup this particle as virtual site relative to the particle with the given id.""" if isinstance(_relto, int): if vs_relate_to(self.id, _relto): handle_errors("Vs_relative setup failed.") else: raise ValueError( - "Argument of vs_auto_relate_to has to be of type int") + "Argument of vs_auto_relate_to has to be of type int.") # Virtual sites relative parameters # vs_auto_relate_to def vs_auto_relate_to(self, _relto): - """Setup this particle as virtual site relative to the particle with the given id""" + """Setup this particle as virtual site relative to the particle with the given id.""" check_type_or_throw_except( - _relto, 1, int, "Argument of vs_auto_relate_to has to be of type int") + _relto, 1, int, "Argument of vs_auto_relate_to has to be of type int.") if vs_relate_to(self.id, _relto): handle_errors("vs_relative setup failed.") IF DIPOLES: - # Vector dipole moment property dip: - """Dipole moment as vector""" + """Dipole moment as vector.""" def __set__(self, _q): cdef double myq[3] check_type_or_throw_except( - _q, 3, float, "Dipole moment vector has to be 3 floats") + _q, 3, float, "Dipole moment vector has to be 3 floats.") for i in range(3): myq[i] = _q[i] if set_particle_dip(self.id, myq) == 1: - raise Exception("set particle position first") + raise Exception("Set particle position first.") def __get__(self): self.update_particle_data() @@ -503,13 +560,13 @@ cdef class ParticleHandle: # Scalar magnitude of dipole moment property dipm: - """Dipole moment (magnitude)""" + """Dipole moment (magnitude).""" def __set__(self, _q): check_type_or_throw_except( - _q, 1, float, "Magnitude of dipole moment has to be 1 floats") + _q, 1, float, "Magnitude of dipole moment has to be 1 floats.") if set_particle_dipm(self.id, _q) == 1: - raise Exception("set particle position first") + raise Exception("Set particle position first.") def __get__(self): self.update_particle_data() @@ -519,13 +576,13 @@ cdef class ParticleHandle: IF EXTERNAL_FORCES: property ext_force: - """External force on a particle defined by a vector""" + """External force on a particle defined by a vector.""" def __set__(self, _ext_f): cdef double ext_f[3] cdef int ext_flag = 0 check_type_or_throw_except( - _ext_f, 3, float, "External force vector has to be 3 floats") + _ext_f, 3, float, "External force vector has to be 3 floats.") for i in range(3): ext_f[i] = _ext_f[i] if (ext_f[0] == 0 and ext_f[1] == 0 and ext_f[2] == 0): @@ -533,7 +590,7 @@ cdef class ParticleHandle: else: ext_flag = PARTICLE_EXT_FORCE if set_particle_ext_force(self.id, ext_flag, ext_f) == 1: - raise Exception("set particle position first") + raise Exception("Set particle position first.") def __get__(self): self.update_particle_data() @@ -546,17 +603,27 @@ cdef class ParticleHandle: return np.array([0.0, 0.0, 0.0]) property fix: - """Fix the particle at current position""" + """Fix the particle at current position. + + Fixes the particle in space. By supplying a set of 3 integers as + ar- guments it is possible to fix motion in x, y, or z coordinates + independently. For example:: + + part[].fix = [0, 0, 1] + + will fix motion for particle with id ``ID`` only in z. + + """ def __set__(self, _fixed_coord_flag): cdef int ext_flag = 0 check_type_or_throw_except( - _fixed_coord_flag, 3, int, "Fix has to be 3 ints") + _fixed_coord_flag, 3, int, "Fix has to be 3 ints.") for i in map(long, range(3)): if (_fixed_coord_flag[i]): ext_flag |= COORD_FIXED(i) if set_particle_fix(self.id, ext_flag) == 1: - raise Exception("set particle position first") + raise Exception("Set particle position first.") def __get__(self): self.update_particle_data() @@ -570,13 +637,18 @@ cdef class ParticleHandle: IF ROTATION: property ext_torque: - """External torque on a particle defined by a vector""" + """External torque on a particle defined by a vector. + + .. note:: + + This torque is specified in the laboratory frame! + """ def __set__(self, _ext_t): cdef double ext_t[3] cdef int ext_flag check_type_or_throw_except( - _ext_t, 3, float, "External force vector has to be 3 floats") + _ext_t, 3, float, "External force vector has to be 3 floats.") for i in range(3): ext_t[i] = _ext_t[i] if (ext_t[0] == 0 and ext_t[1] == 0 and ext_t[2] == 0): @@ -584,7 +656,7 @@ cdef class ParticleHandle: else: ext_flag = PARTICLE_EXT_TORQUE if set_particle_ext_torque(self.id, ext_flag, ext_t) == 1: - raise Exception("set particle position first") + raise Exception("Set particle position first.") def __get__(self): self.update_particle_data() @@ -599,16 +671,16 @@ cdef class ParticleHandle: IF LANGEVIN_PER_PARTICLE: IF PARTICLE_ANISOTROPY: property gamma: - """Rotational friction coefficient per particle in Langevin""" + """Rotational friction coefficient per particle in Langevin.""" def __set__(self, _gamma): cdef double gamma[3] check_type_or_throw_except( - _gamma, 3, float, "Friction has to be 3 floats") + _gamma, 3, float, "Friction has to be 3 floats.") for i in range(3): gamma[i] = _gamma[i] if set_particle_gamma(self.id, gamma) == 1: - raise Exception("set particle position first") + raise Exception("Set particle position first.") def __get__(self): self.update_particle_data() @@ -617,13 +689,13 @@ cdef class ParticleHandle: return np.array([gamma[0], gamma[1], gamma[2]]) ELSE: property gamma: - """Friction coefficient per particle in Langevin""" + """Friction coefficient per particle in Langevin.""" def __set__(self, _gamma): check_type_or_throw_except( - _gamma, 1, float, "gamma has to be a float") + _gamma, 1, float, "Gamma has to be a float.") if set_particle_gamma(self.id, _gamma) == 1: - raise Exception("set particle position first") + raise Exception("Set particle position first.") def __get__(self): self.update_particle_data() @@ -633,16 +705,16 @@ cdef class ParticleHandle: IF ROTATION: IF ROTATIONAL_INERTIA: property gamma_rot: - """Rotational friction coefficient per particle in Langevin""" + """Rotational friction coefficient per particle in Langevin.""" def __set__(self, _gamma_rot): cdef double gamma_rot[3] check_type_or_throw_except( - _gamma_rot, 3, float, "Rotational friction has to be 3 floats") + _gamma_rot, 3, float, "Rotational friction has to be 3 floats.") for i in range(3): gamma_rot[i] = _gamma_rot[i] if set_particle_gamma_rot(self.id, gamma_rot) == 1: - raise Exception("set particle position first") + raise Exception("Set particle position first.") def __get__(self): self.update_particle_data() @@ -651,13 +723,13 @@ cdef class ParticleHandle: return np.array([gamma_rot[0], gamma_rot[1], gamma_rot[2]]) ELSE: property gamma_rot: - """Friction coefficient per particle in Langevin""" + """Rotational friction coefficient per particle in Langevin.""" def __set__(self, _gamma_rot): check_type_or_throw_except( - _gamma_rot, 1, float, "gamma_rot has to be a float") + _gamma_rot, 1, float, "gamma_rot has to be a float.") if set_particle_gamma_rot(self.id, _gamma_rot) == 1: - raise Exception("set particle position first") + raise Exception("Set particle position first.") def __get__(self): self.update_particle_data() @@ -666,13 +738,13 @@ cdef class ParticleHandle: return gamma_rot[0] property temp: - """Temperature per particle in Langevin""" + """Temperature per particle in Langevin.""" def __set__(self, _temp): check_type_or_throw_except( - _temp, 1, float, "temp has to be a float") + _temp, 1, float, "temp has to be a float.") if set_particle_temperature(self.id, _temp) == 1: - raise Exception("set particle position first") + raise Exception("Set particle position first.") def __get__(self): self.update_particle_data() @@ -682,7 +754,7 @@ cdef class ParticleHandle: IF ROTATION_PER_PARTICLE: property rotation: - """Friction coefficient per particle in Langevin""" + """Friction coefficient per particle in Langevin.""" def __set__(self, _rot): cdef int rot @@ -691,7 +763,7 @@ cdef class ParticleHandle: else: rot = 0 if set_particle_rotation(self.id, rot) == 1: - raise Exception("set particle position first") + raise Exception("Set particle position first.") def __get__(self): self.update_particle_data() @@ -705,7 +777,7 @@ cdef class ParticleHandle: IF EXCLUSIONS: property exclude: - """Exclude particle from interaction""" + """Exclude particle from interaction.""" def __set__(self, _partners): if isinstance(_partners, int): @@ -717,12 +789,12 @@ cdef class ParticleHandle: return for partner in _partners: check_type_or_throw_except( - partner, 1, int, "PID of partner has to be an int") + partner, 1, int, "PID of partner has to be an int.") if self.id == partner: raise Exception( - "Cannot exclude of a particle with itself!\n->particle id %i, partner %i" % (self.id, partner)) + "Cannot exclude of a particle with itself!\n->particle id %i, partner %i." % (self.id, partner)) if change_exclusion(self.id, partner, 0) == 1: - raise Exception("set particle position first") + raise Exception("Set particle position first.") def __get__(self): self.update_particle_data() @@ -735,26 +807,27 @@ cdef class ParticleHandle: return np.array(py_partners) def add_exclusion(self, *_partners): + """Excluding interaction with given partners.""" self.exclude = _partners def delete_exclusion(self, *_partners): for partner in _partners: check_type_or_throw_except( - partner, 1, int, "PID of partner has to be an int") + partner, 1, int, "PID of partner has to be an int.") if change_exclusion(self.id, partner, 1) == 1: - raise Exception("set particle position first") + raise Exception("Set particle position first.") def delete_exclusions(self): _partners = self.exclude for partner in _partners: check_type_or_throw_except( - partner, 1, int, "PID of partner has to be an int") + partner, 1, int, "PID of partner has to be an int.") if change_exclusion(self.id, partner, 1) == 1: - raise Exception("set particle position first") + raise Exception("Set particle position first.") IF ENGINE: property swimming: - """Set swimming parameters""" + """Set swimming parameters.""" def __set__(self, _params): cdef particle_parameters_swimming swim @@ -769,21 +842,21 @@ cdef class ParticleHandle: if type(_params) == type(True): if _params == True: raise Exception( - "To enable swimming supply a dictionary of parameters") + "To enable swimming supply a dictionary of parameters.") else: if 'f_swim' in _params and 'v_swim' in _params: if _params["f_swim"] == 0 or _params["v_swim"] == 0: pass else: raise Exception( - "You can't set v_swim and f_swim at the same time") + "You can't set v_swim and f_swim at the same time.") if 'f_swim' in _params: check_type_or_throw_except( - _params['f_swim'], 1, float, "f_swim has to be a float") + _params['f_swim'], 1, float, "f_swim has to be a float.") swim.f_swim = _params['f_swim'] if 'v_swim' in _params: check_type_or_throw_except( - _params['v_swim'], 1, float, "v_swim has to be a float") + _params['v_swim'], 1, float, "v_swim has to be a float.") swim.v_swim = _params['v_swim'] IF LB or LB_GPU: @@ -796,21 +869,21 @@ cdef class ParticleHandle: swim.push_pull = 0 else: raise Exception( - "'mode' has to be either 'pusher' or 'puller'") + "'mode' has to be either 'pusher' or 'puller'.") if 'dipole_length' in _params: check_type_or_throw_except( - _params['dipole_length'], 1, float, "dipole_length has to be a float") + _params['dipole_length'], 1, float, "dipole_length has to be a float.") swim.dipole_length = _params['dipole_length'] if 'rotational_friction' in _params: check_type_or_throw_except( - _params['rotational_friction'], 1, float, "rotational_friction has to be a float") + _params['rotational_friction'], 1, float, "rotational_friction has to be a float.") swim.rotational_friction = _params[ 'rotational_friction'] if set_particle_swimming(self.id, swim) == 1: - raise Exception("set particle position first") + raise Exception("Set particle position first.") def __get__(self): self.update_particle_data() @@ -838,15 +911,15 @@ cdef class ParticleHandle: return swim def remove(self): - """Delete the particle""" + """Delete the particle.""" if remove_particle(self.id): - raise Exception("Could not delete particle") + raise Exception("Could not delete particle.") del self # Bond related methods # Does not work properly with 3 or more partner bonds! def add_verified_bond(self, bond): - """Add a bond, the validity of which has already been verified""" + """Add a bond, the validity of which has already been verified.""" # If someone adds bond types with more than four partners, this has to # be changed cdef int bond_info[5] @@ -866,17 +939,18 @@ cdef class ParticleHandle: def check_bond_or_throw_exception(self, bond): """Checks the validity of the given bond: - * if the bondtype is given as an object or a numerical id - * if all partners are of type int - * if the number of partners satisfies the bond - * If the bond type used exists (is lower than n_bonded_ia) - * If the number of bond partners fits the bond type - Throw an exception if any of these are not met""" + + - If the bondtype is given as an object or a numerical id + - If all partners are of type int + - If the number of partners satisfies the bond + - If the bond type used exists (is lower than n_bonded_ia) + - If the number of bond partners fits the bond type + Throws an exception if any of these are not met.""" # Has it []-access if not hasattr(bond, "__getitem__"): raise ValueError( - "Bond needs to be a tuple or list containing bond type and partners") + "Bond needs to be a tuple or list containing bond type and partners.") # Bond type or numerical bond id if not isinstance(bond[0], BondedInteraction): @@ -890,7 +964,7 @@ cdef class ParticleHandle: # 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") + "The bonded interaction has not yet been added to the list of active bonds in Espresso.") # Validity of the numeric id if bond[0]._bond_id >= n_bonded_ia: @@ -912,18 +986,19 @@ cdef class ParticleHandle: bond[i] = bond[i].id def add_bond(self, _bond): - """Add a single bond to the particle""" + """Add a single bond to the particle.""" bond = list(_bond) # As we will modify it self.check_bond_or_throw_exception(bond) self.add_verified_bond(bond) def delete_bond(self, _bond): - """Delete a single bond from the particle""" + """Delete a single bond from the particle.""" bond = list(_bond) # as we modify it self.check_bond_or_throw_exception(bond) self.delete_verified_bond(bond) def delete_all_bonds(self): + """Delete all bonds from the particle.""" if change_particle_bond(self.id, NULL, 1): handle_errors("Deleting all bonds failed.") @@ -959,13 +1034,14 @@ cdef class ParticleSlice: utils.realloc_intlist(& (self.particle_data.bl), 0) if get_particle_data(id, & self.particle_data): - raise Exception("Error updating particle data") + raise Exception("Error updating particle data.") else: return 0 # Particle Type property type: - + """Particle type. + """ def __get__(self): type_list = [] for id in self.id_selection: @@ -978,7 +1054,7 @@ cdef class ParticleSlice: ParticleHandle(id).type = _type_list return if len(self.id_selection) != len(_type_list): - raise Exception("Input list size (%i) does not match slice size (%i)" % ( + raise Exception("Input list size (%i) does not match slice size (%i)." % ( len(_type_list), len(self.id_selection))) for i in range(len(self.id_selection)): ParticleHandle(self.id_selection[i]).type = _type_list[i] @@ -986,10 +1062,9 @@ cdef class ParticleSlice: # Position property pos: """Particle position (not folded into central image).""" - def __set__(self, _pos_array): if len(self.id_selection) != len(_pos_array): - raise Exception("Input list size (%i) does not match slice size (%i)" % ( + raise Exception("Input list size (%i) does not match slice size (%i)." % ( len(_pos_array), len(self.id_selection))) cdef double mypos[3] @@ -1006,7 +1081,7 @@ cdef class ParticleSlice: """Particle position (folded into central image).""" def __set__(self, d): - raise Exception("setting a folded position is not implemented") + raise Exception("setting a folded position is not implemented.") def __get__(self): pos_array = np.zeros((len(self.id_selection), 3)) @@ -1017,7 +1092,7 @@ cdef class ParticleSlice: # Velocity property v: - """Particle velocity""" + """Particle velocity.""" def __set__(self, _v_array): if len(np.array(_v_array).shape) == 1: @@ -1026,7 +1101,7 @@ cdef class ParticleSlice: return if len(self.id_selection) != len(_v_array): - raise Exception("Input list size (%i) does not match slice size (%i)" % ( + raise Exception("Input list size (%i) does not match slice size (%i)." % ( len(_v_array), len(self.id_selection))) for i in range(len(self.id_selection)): @@ -1040,7 +1115,7 @@ cdef class ParticleSlice: # Force property f: - """Particle force""" + """Particle force.""" def __set__(self, _f_array): if len(np.array(_f_array).shape) == 1: @@ -1049,7 +1124,7 @@ cdef class ParticleSlice: return if len(self.id_selection) != len(_f_array): - raise Exception("Input list size (%i) does not match slice size (%i)" % ( + raise Exception("Input list size (%i) does not match slice size (%i)." % ( len(_f_array), len(self.id_selection))) for i in range(len(_f_array)): ParticleHandle(self.id_selection[i]).f = _f_array[i] @@ -1061,7 +1136,14 @@ cdef class ParticleSlice: return f_array property mass: - """Particle mass""" + """Particle mass. + + .. note:: + + If not set the particle mass is ``1`` in reduced units. + + """ + def __set__(self, _mass_array): IF MASS: if isinstance(_mass_array, int) or isinstance(_mass_array, float): @@ -1069,7 +1151,7 @@ cdef class ParticleSlice: ParticleHandle(self.id_selection[i]).mass = _mass_array return if len(self.id_selection) != len(_mass_array): - raise Exception("Input list size (%i) does not match slice size (%i)" % ( + raise Exception("Input list size (%i) does not match slice size (%i)." % ( len(_mass_array), len(self.id_selection))) for i in range(len(_mass_array)): ParticleHandle(self.id_selection[i]).mass = _mass_array[i] @@ -1085,7 +1167,7 @@ cdef class ParticleSlice: IF ELECTROSTATICS == 1: property q: - """particle charge""" + """Particle charge.""" def __set__(self, _q_array): if isinstance(_q_array, int) or isinstance(_q_array, float): @@ -1094,7 +1176,7 @@ cdef class ParticleSlice: return if len(self.id_selection) != len(_q_array): - raise Exception("Input list size (%i) does not match slice size (%i)" % ( + raise Exception("Input list size (%i) does not match slice size (%i)." % ( len(_q_array), len(self.id_selection))) for i in range(len(self.id_selection)): ParticleHandle(self.id_selection[i]).q = _q_array[i] @@ -1107,7 +1189,7 @@ cdef class ParticleSlice: IF EXTERNAL_FORCES: property ext_force: - """External force on a particle defined by a vector""" + """External force on a particle defined by a vector.""" def __set__(self, _ext_f_array): if len(np.array(_ext_f_array).shape) == 1: @@ -1117,7 +1199,7 @@ cdef class ParticleSlice: return if len(self.id_selection) != len(_ext_f_array): - raise Exception("Input list size (%i) does not match slice size (%i)" % ( + raise Exception("Input list size (%i) does not match slice size (%i)." % ( len(_ext_f_array), len(self.id_selection))) for i in range(len(self.id_selection)): @@ -1134,12 +1216,12 @@ cdef class ParticleSlice: IF EXCLUSIONS: property exclude: - """Exclude particle from interaction""" + """Exclude particle from interaction.""" def __set__(self, _partners): if not isinstance(_partners, list): raise Exception( - "list object expected for exclusion partners") + "List object expected for exclusion partners.") if isinstance(_partners[0], list): for i in range(len(self.id_selection)): ParticleHandle(self.id_selection[ @@ -1149,7 +1231,7 @@ cdef class ParticleSlice: ParticleHandle(self.id_selection[ i]).exclude = _partners else: - raise TypeError("unexpected exclusion partner type") + raise TypeError("Unexpected exclusion partner type.") def __get__(self): _exclude_array = [] @@ -1163,7 +1245,7 @@ cdef class ParticleSlice: def delete_exclusion(self, _partners): if not isinstance(_partners, list): - raise Exception("list object expected") + raise Exception("List object expected.") if isinstance(_partners[0], list): for i in range(len(self.id_selection)): ParticleHandle(self.id_selection[ @@ -1173,7 +1255,7 @@ cdef class ParticleSlice: ParticleHandle(self.id_selection[ i]).delete_exclusion(_partners) else: - raise TypeError("unexpected exclusion partner type") + raise TypeError("Unexpected exclusion partner type.") def delete_exclusions(self): for _id in self.id_selection: @@ -1197,7 +1279,7 @@ cdef class ParticleSlice: # Bond related methods def add_bond(self, _bond): - """Add a single bond to the particles""" + """Add a single bond to the particles.""" bond = list(_bond) # As we will modify it for i in range(len(self.id_selection)): partners = [] @@ -1206,7 +1288,7 @@ cdef class ParticleSlice: ParticleHandle(self.id_selection[i]).add_bond((bond[0], *partners)) def delete_bond(self, _bond): - """Delete a single bond from the particles""" + """Delete a single bond from the particles.""" bond = list(_bond) # as we modify it for i in range(len(self.id_selection)): partners = [] @@ -1219,7 +1301,7 @@ cdef class ParticleSlice: ParticleHandle(self.id_selection[i]).delete_all_bonds() def remove(self): - """Delete the particles""" + """Delete the particles.""" for id in self.id_selection: ParticleHandle(id).remove() @@ -1245,15 +1327,15 @@ cdef class ParticleList: # __getstate__ and __setstate__ define the pickle interaction def __getstate__(self): - # Attributes to pickle. - # Content of particle_attributes, minus a few exceptions - # dip, director: Setting only the director will overwrite - # the orientation of the particle around the axis parallel - # to dipole moment/director. Quaternions contain the full info - # id: The particle id is used as the storage key when pickling - # all particles via ParticleList, and the interface - # (rightly) does not support changing of the id after the particle - # was created. + """ Attributes to pickle. + Content of particle_attributes, minus a few exceptions + dip, director: Setting only the director will overwrite + the orientation of the particle around the axis parallel + to dipole moment/director. Quaternions contain the full info + id: The particle id is used as the storage key when pickling + all particles via ParticleList, and the interface + (rightly) does not support changing of the id after the particle + was created.""" pickle_attr = copy(particle_attributes) for i in ["director", "dip", "id"]: if i in pickle_attr: @@ -1287,7 +1369,7 @@ cdef class ParticleList: # Check for presence of pos attribute if not "pos" in args[0]: raise ValueError( - "pos attribute must be specified for new particle") + "pos attribute must be specified for new particle.") if len(np.array(args[0]["pos"]).shape) == 2: self._place_new_particles(args[0]) @@ -1298,7 +1380,7 @@ cdef class ParticleList: # Check for presence of pos attribute if not "pos" in kwargs: raise ValueError( - "pos attribute must be specified for new particle") + "pos attribute must be specified for new particle.") if len(np.array(kwargs["pos"]).shape) == 2: return self._place_new_particles(kwargs) @@ -1306,7 +1388,7 @@ cdef class ParticleList: return self._place_new_particle(kwargs) else: raise ValueError( - "add() takes either a dictionary or a bunch of keyword args") + "add() takes either a dictionary or a bunch of keyword args.") def _place_new_particle(self, P): @@ -1323,11 +1405,11 @@ cdef class ParticleList: # done here. the code is from the pos:property of ParticleHandle cdef double mypos[3] check_type_or_throw_except( - P["pos"], 3, float, "Postion must be 3 floats") + P["pos"], 3, float, "Postion must be 3 floats.") for i in range(3): mypos[i] = P["pos"][i] if place_particle(P["id"], mypos) == -1: - raise Exception("particle could not be set") + raise Exception("particle could not be set.") # Pos is taken care of del P["pos"] id = P["id"] @@ -1354,7 +1436,7 @@ cdef class ParticleList: for i in range(3): mypos[i] = P["pos"][j][i] if place_particle(ids[j], mypos) == -1: - raise Exception("particle could not be set") + raise Exception("Particle could not be set.") del P["pos"] @@ -1390,6 +1472,9 @@ cdef class ParticleList: return res[:-1] def writevtk(self, fname, types='all'): + """ + :todo: `Documentation missing.` + """ global box_l if not hasattr(types, '__iter__'): types = [types] @@ -1420,14 +1505,17 @@ cdef class ParticleList: vtk.write("{} {} {}\n".format(*p.v)) property highest_particle_id: + """Largest particle id.""" def __get__(self): return max_seen_particle property n_part_types: + """Number of particle types.""" def __get__(self): return n_particle_types property n_rigidbonds: + """Number of rigid bonds.""" def __get__(self): return n_rigidbonds @@ -1440,7 +1528,7 @@ cdef class ParticleList: # return n_part def pairs(self): - """Generator returns all pairs of particles""" + """Generator returns all pairs of particles.""" for i in range(max_seen_particle + 1): for j in range(i + 1, max_seen_particle + 1, 1): if not (self.exists(i) and self.exists(j)):