Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support neutral charges in the reaction ensemble #2378

Merged
merged 2 commits into from
Nov 30, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/python/espressomd/reaction_ensemble.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ cdef class ReactionAlgorithm(object):
"No dictionary for relation between types and default charges provided.")
#check electroneutrality of the provided reaction
if(self._params["check_for_electroneutrality"]):
charges = np.array(list(self._params["default_charges"].values()))
if(np.count_nonzero(charges) == 0):
# all partices have zero charge
# no need to check electroneutrality
return
total_charge_change = 0.0
for i in range(len(self._params["reactant_coefficients"])):
type_here = self._params["reactant_types"][i]
Expand All @@ -235,7 +240,6 @@ cdef class ReactionAlgorithm(object):
type_here = self._params["product_types"][j]
total_charge_change += self._params["product_coefficients"][
j] * self._params["default_charges"][type_here]
charges = np.array(list(self._params["default_charges"].values()))
min_abs_nonzero_charge = np.min(
np.abs(charges[np.nonzero(charges)[0]]))
if abs(total_charge_change) / min_abs_nonzero_charge > 1e-10:
Expand Down