Skip to content

Commit

Permalink
Apply code review suggestions
Browse files Browse the repository at this point in the history
Co-authored-by: Mariano Brito <[email protected]>
  • Loading branch information
jngrad and mebrito committed Sep 6, 2024
1 parent 1ce7175 commit 8f432a7
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 29 deletions.
7 changes: 4 additions & 3 deletions doc/sphinx/advanced_methods.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ This protocol is set up with :class:`~espressomd.collision_detection.BindCenters
The parameters are as follows:

* ``distance`` is the distance between two particles at which the binding is triggered.
This cutoff distance, ``1.5`` in the example above, is typically chosen slightly larger
This cutoff distance, ``0.1`` in the example above, is typically chosen slightly larger
than the particle diameter. It is also a good choice for the equilibrium length of the bond.
* ``bond_centers`` is the bonded interaction to be created between the particles
(an instance of :class:`~espressomd.interactions.HarmonicBond` in the example above).
Expand Down Expand Up @@ -82,7 +82,7 @@ is added between the two colliding particles and the virtual particles.
In the latter case, the virtual particles are the centers of the angle potentials
(particle 2 in the description of the angle potential, see :ref:`Bond-angle interactions`).
Due to the rigid connection between each of the colliding particles and their
respective virtual sites, a sliding at the contact point is no longer possible.
respective virtual sites, sliding at the contact point is no longer possible.
See :ref:`Rigid arrangements of particles` for details. This protocol affects all particle types.

In addition to the bond between the virtual sites, a bond between the colliding
Expand All @@ -105,7 +105,7 @@ This protocol is set up with :class:`~espressomd.collision_detection.BindAtPoint
bond_centers=bond_centers,
bond_vs=bond_vs,
part_type_vs=1,
vs_placement=0.2)
vs_placement=0.5)

The parameters ``distance`` and ``bond_centers`` have the same meaning
as in the :ref:`Bind centers` protocol. The remaining parameters are as follows:
Expand Down Expand Up @@ -135,6 +135,7 @@ Glue to surface
~~~~~~~~~~~~~~~

Attach small particles to the surface of a large particle.
The bond can be made irreversible.

Several small particles can be bound to a large particle but not vice versa.
The small particles can change type after collision to become *inert*.
Expand Down
13 changes: 7 additions & 6 deletions src/core/collision_detection/BindAtPointOfCollision.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,19 @@ namespace CollisionDetection {

class BindAtPointOfCollision {
public:
/// Distance at which particle are bound
double distance;
// Square of distance at which particle are bound
/// Square of distance at which particle are bound
double distance_sq;

/// bond type used between centers of colliding particles
int bond_centers;
/// bond type used between virtual sites
int bond_vs;
/** Placement of virtual sites for MODE_VS.
* 0=on same particle as related to,
* 1=on collision partner,
* 0.5=in the middle between
/**
* @brief Barycenter of the virtual site.
* 0=on same particle as related to,
* 1=on collision partner,
* 0.5=in the middle between the two particles
*/
double vs_placement;
/// particle type for virtual sites created on collision
Expand Down
4 changes: 2 additions & 2 deletions src/core/collision_detection/BindCenters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ namespace CollisionDetection {

class BindCenters {
public:
/// Distance at which particle are bound
double distance;
// Square of distance at which particle are bound
/// Square of distance at which particle are bound
double distance_sq;

/// bond type used between centers of colliding particles
int bond_centers;

Expand Down
19 changes: 9 additions & 10 deletions src/core/collision_detection/GlueToSurface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,21 @@ namespace CollisionDetection {

class GlueToSurface {
public:
/// Distance at which particle are bound
double distance;
// Square of distance at which particle are bound
/// Square of distance at which particle are bound
double distance_sq;
/// bond type used between centers of colliding particles
int bond_centers;
/// bond type used between virtual sites
int bond_vs;
/// particle type for virtual sites created on collision
int part_type_vs;
/// For mode "glue to surface": The distance from the particle which is to be
/// glued to the new virtual site
/// Distance from the particle which is to be glued to the new virtual site
double dist_glued_part_to_vs;
/// For mode "glue to surface": The particle type being glued
/// The particle type being glued (the small particle)
int part_type_to_be_glued;
/// For mode "glue to surface": The particle type to which the virtual site is
/// attached
/// The particle type to which virtuals site are attached (the large particle)
int part_type_to_attach_vs_to;
/// Particle type to which the newly glued particle is converted
int part_type_after_glueing;
Expand All @@ -74,10 +73,10 @@ class GlueToSurface {

/** @brief Check additional criteria for the glue_to_surface collision mode */
bool glue_to_surface_criterion(Particle const &p1, Particle const &p2) const {
return (((p1.type() == part_type_to_be_glued) and
(p2.type() == part_type_to_attach_vs_to)) or
((p2.type() == part_type_to_be_glued) and
(p1.type() == part_type_to_attach_vs_to)));
return ((p1.type() == part_type_to_be_glued and
p2.type() == part_type_to_attach_vs_to) or
(p2.type() == part_type_to_be_glued and
p1.type() == part_type_to_attach_vs_to));
}

void handle_collisions(System::System &system,
Expand Down
2 changes: 1 addition & 1 deletion src/core/collision_detection/Off.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include "nonbonded_interactions/nonbonded_interaction_data.hpp"
#include "system/System.hpp"

#include <utility>
#include <vector>

namespace CollisionDetection {
Expand All @@ -43,6 +42,7 @@ class Off {
void initialize(System::System &) {}

void handle_collisions(System::System &, std::vector<CollisionPair> &) {}

bool detect_collision(Particle const &, Particle const &,
double const) const {
return false;
Expand Down
6 changes: 2 additions & 4 deletions src/core/collision_detection/common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ inline auto detect_collision_common(Particle const &p1, Particle const &p2,
return false;

// Check, if there's already a bond between the particles
if (pair_bond_exists_on(p1.bonds(), p2.id(), bond_centers))
return false;

if (pair_bond_exists_on(p2.bonds(), p1.id(), bond_centers))
if (pair_bond_exists_on(p1.bonds(), p2.id(), bond_centers) or
pair_bond_exists_on(p2.bonds(), p1.id(), bond_centers))
return false;

/* If we're still here, there is no previous bond between the particles,
Expand Down
1 change: 1 addition & 0 deletions src/script_interface/collision_detection/Off.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Off : public Protocol {
Off()
: m_protocol{std::make_shared<::CollisionDetection::ActiveProtocol>(
::CollisionDetection::Off())} {}

std::shared_ptr<::CollisionDetection::ActiveProtocol> protocol() override {
return m_protocol;
}
Expand Down
2 changes: 1 addition & 1 deletion testsuite/python/save_checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@
if espressomd.has_features("COLLISION_DETECTION"):
if espressomd.has_features("VIRTUAL_SITES_RELATIVE"):
protocol = espressomd.collision_detection.BindAtPointOfCollision(
distance=0.11, bond_centers=harmonic_bond,
distance=0.12, bond_centers=harmonic_bond,
bond_vs=strong_harmonic_bond, part_type_vs=2, vs_placement=1. / 3.)
else:
protocol = espressomd.collision_detection.BindCenters(
Expand Down
6 changes: 4 additions & 2 deletions testsuite/python/test_checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,17 +928,19 @@ def test_comfixed(self):
@utx.skipIfMissingFeatures('COLLISION_DETECTION')
def test_collision_detection(self):
protocol = system.collision_detection.protocol
self.assertAlmostEqual(protocol.distance, 0.11, delta=1E-9)
self.assertEqual(protocol.bond_centers, system.bonded_inter[0])
if espressomd.has_features("VIRTUAL_SITES_RELATIVE"):
self.assertIsInstance(
protocol, espressomd.collision_detection.BindAtPointOfCollision)
self.assertAlmostEqual(protocol.distance, 0.12, delta=1E-9)
self.assertEqual(protocol.bond_centers, system.bonded_inter[0])
self.assertEqual(protocol.bond_vs, system.bonded_inter[1])
self.assertEqual(protocol.part_type_vs, 2)
self.assertAlmostEqual(protocol.vs_placement, 1. / 3., delta=1e-6)
else:
self.assertIsInstance(
protocol, espressomd.collision_detection.BindCenters)
self.assertAlmostEqual(protocol.distance, 0.11, delta=1E-9)
self.assertEqual(protocol.bond_centers, system.bonded_inter[0])

@utx.skipIfMissingFeatures('EXCLUSIONS')
def test_exclusions(self):
Expand Down

0 comments on commit 8f432a7

Please sign in to comment.