Skip to content

Commit

Permalink
Re-implement vs_relative cutoff override check
Browse files Browse the repository at this point in the history
  • Loading branch information
RudolfWeeber committed Aug 1, 2023
1 parent c7ec4ee commit 1a16a32
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
10 changes: 8 additions & 2 deletions src/python/espressomd/particle_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ def propagation(self):
def propagation(self, value):
self.set_parameter("propagation", int(value))

def vs_auto_relate_to(self, rel_to):
def vs_auto_relate_to(self, rel_to, override_cutoff_check=False):
"""
Setup this particle as virtual site relative to the particle
in argument ``rel_to``. A particle cannot relate to itself.
Expand All @@ -570,14 +570,20 @@ def vs_auto_relate_to(self, rel_to):
-----------
rel_to : :obj:`int` or :obj:`ParticleHandle`
Particle to relate to (either particle id or particle object).
override_cutoff_check : :obj:`bool`
If True, does not check whether the cell system cutoffs
are consistent with the distance between virtual and no-virtual particle.
"""
if isinstance(rel_to, ParticleHandle):
rel_to = rel_to.id
else:
check_type_or_throw_except(
rel_to, 1, int, "Argument of 'vs_auto_relate_to' has to be of type ParticleHandle or int")
self.call_method("vs_relate_to", pid=rel_to)
self.call_method(
"vs_relate_to",
pid=rel_to,
override_cutoff_check=override_cutoff_check)
handle_errors("vs_auto_relate_to")

def add_verified_bond(self, bond):
Expand Down
6 changes: 4 additions & 2 deletions src/script_interface/particle_data/ParticleHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,8 @@ Variant ParticleHandle::do_call_method(std::string const &name,
return {};
}
auto const other_pid = get_value<int>(params, "pid");
bool const override_cutoff_check =
get_value_or<bool>(params, "override_cutoff_check", false);
if (m_pid == other_pid) {
throw std::invalid_argument("A virtual site cannot relate to itself");
}
Expand All @@ -610,8 +612,8 @@ Variant ParticleHandle::do_call_method(std::string const &name,
*/
auto const &p_current = get_particle_data(m_pid);
auto const &p_relate_to = get_particle_data(other_pid);
auto const [quat, dist] =
calculate_vs_relate_to_params(p_current, p_relate_to);
auto const [quat, dist] = calculate_vs_relate_to_params(
p_current, p_relate_to, override_cutoff_check);
set_parameter("propagation", PropagationMode::TRANS_VS_RELATIVE);
set_parameter("vs_relative", Variant{std::vector<Variant>{
{other_pid, dist, quat2vector(quat)}}});
Expand Down
2 changes: 1 addition & 1 deletion testsuite/python/virtual_sites_relative.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def test_vs_exceptions(self):
with self.assertRaisesRegex(Exception, r"The distance between virtual and non-virtual particle \([0-9\.]+\) is larger than the minimum global cutoff"):
p2.vs_auto_relate_to(p1)
# If overridden this check should not raise an exception
p2.vs_auto_relate_to(p1)
p2.vs_auto_relate_to(p1, override_cutoff_check=True)

def test_pos_vel_forces(self):
system = self.system
Expand Down

0 comments on commit 1a16a32

Please sign in to comment.