-
Notifications
You must be signed in to change notification settings - Fork 183
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
Corrected reaction ensemble documentation, small changes in RE syntax… #1741
Conversation
…, and corrections to teststuite and samples to comply with the current syntax.
Codecov Report
@@ Coverage Diff @@
## python #1741 +/- ##
=======================================
+ Coverage 59% 60% +<1%
=======================================
Files 416 416
Lines 28815 28965 +150
=======================================
+ Hits 17288 17386 +98
- Misses 11527 11579 +52
Continue to review full report at Codecov.
|
Note that if you provide the reaction constant :math:`K_c` | ||
as described in the user guide, this parameter should be kept at its default value. | ||
This paramater is retained for backward compatibility with earlier | ||
implementation, where the pressure-based constaht :math:`K_p` was |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The user guide only deals with a dimensionless reaction constant K (K_p is not mentioned there). Please also name it this way here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry i overlooked parts. But how is K=Exp(...) related to K_p?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see that there is a statement K=K_p although it is used in that way. After all this only holds for ideal gases but all the reaction constants which are provided in the reaction ensemble are ideal Gas reaction constants. Adding Interactions to the system effectively alters reaction constant K_c which is observed in the system then. Can we introduce a statement like this or so you see Problems with it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, K_p is not defined anywhere. At the same time, though K_p = prod_i (p_i / p_standard)^{nu_i} is well defined only if the system is a gas, and it is equal to K only if the system is an ideal gas. Regarding the message of this note, saying that standard_pressure is needed only in gas-phase reactions, I would leave it as is. I expect that most users need not bother, and those who need to study gas-phase reactions should be familiar with K_p.
@@ -400,12 +397,12 @@ cdef class WangLandauReactionEnsemble(ReactionAlgorithm): | |||
|
|||
def add_collective_variable_degree_of_association(self, *args, **kwargs): | |||
""" | |||
Adds a reaction coordinate of the type degree of association. | |||
Adds degree of association as the collective variable (reaction coordinate) for the Wang-Landau Reaction Ensemble. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can have multiple reaction coordinates of this type. Therefore it was previsously "adds a reaction coordinate of the type..." implying that you can have more than one reaction coordinates of this type.
Therefore I would explicitly state that you can have more than one reaction coordinate of this type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. I will add a note that several collective variables can be set simultaneously.
…docs_reaction_ensemble
…docs_reaction_ensemble
…ow it is implemented
…ous conventional definitions of equilibrium constant.
…docs_reaction_ensemble
* Replaced equilibrium_constant with Gamma in testsuite. * Modified the scripts such that they do not set the standard pressure but still produce the same numbers as before
… everywhere in the code.
@jonaslandsgesell and @helvrud please check my changes and comment if any further changes are needed. I think that together with #1767 this is the final fix for #1650 After these two PRs are merged, this issue can be closed. |
Looks good to me |
doc/sphinx/run.rst
Outdated
|
||
where :math:`q_i` and :math:`\Lambda_i` are the single-particle partition function and | ||
thermal wavelength of species :math:`i`. In the absence of intermolecular interactions | ||
(ideal gas or ideal solution), :math:`\Gamma` proportional to the concentration-based reaction constant |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gamma is the concentration based reaction constant in units of 1/(sigma^3)^nu_bar, if no interactions are present. Proportional is too weak for my taste.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree but I will not specify the units because these are defined by the simulation script. The units have to be consistent with other units in the simulation script. Can be mol/L or 1/sigma^3 or anything else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It all depends on the unit of the volume that is provided that is correct. However for the case that the user does not provide a volume (which is standard and V=box_l_xbox_l_ybox_l_z, V is in units of sigma^3) and then as a standard the unit of gamma is 1/(sigma^3)^nubabr
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sentence before says: "Note that the dimension of :math:\Gamma
is :math:V^{\bar\nu}
, therefore its units must be consistent with the units in which Espresso measures the box volume, i.e. :math:\sigma^3
." Isn't this precisely the same thing as you wrote, just spelled differently?
src/core/reaction_ensemble.hpp
Outdated
@@ -89,7 +89,8 @@ class ReactionAlgorithm { | |||
|
|||
std::vector<SingleReaction> reactions; | |||
std::map<int, double> charges_of_types; | |||
double standard_pressure_in_simulation_units = -10.0; | |||
//double standard_pressure_in_simulation_units = -10.0; | |||
//double standard_pressure_in_simulation_units = 1.0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove the comment
testsuite/constant_pH.py
Outdated
# avoid extreme regions in the titration curve e.g. via the choice | ||
# (np.random.random()-0.5) | ||
# target_alpha=0.5; # choose target alpha close to 0.5 to get good statistics in a small number of steps | ||
# Ka=target_alpha*target_alpha/(1.0-target_alpha)*c0; # determine Ka which corresponds to the desired c0 and alpha | ||
# pKa=-np.log10(Ka); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not choose 0.5 because this value was quite robust regarding errors from my experience for typical errors which happened during coding. But of course in principle any point on the curve should be suitable for testing, so I don't have a preference.
testsuite/constant_pH.py
Outdated
pKa_minus_pH = 1 | ||
pH = 2 # or randomly via: 4*np.random.random() | ||
pKa = pKa_minus_pH + pH | ||
# could be in this test for example anywhere in the range 0.000001 ... 9 | ||
K_HA_diss_apparent = 10**(-pKa) | ||
#K_HA_diss_apparent = 10**(-pKa)*0.00108; # first, ensure that by removing standard pressure we obtain the same hard-coded numbers as before | ||
#print("pKa:", pKa, "pk_pKa:", -np.log10(K_HA_diss_pk)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove
testsuite/reaction_ensemble.py
Outdated
exclusion_radius = 1.0 | ||
# could be in this test for example anywhere in the range 0.000001 ... 9, | ||
# chosen for example like 8.8*np.random.random()+0.2 | ||
K_HA_diss = 8.8 * 0.5 + 0.2 | ||
# FIXME choose desired alpha and then calculate Ka based on the desired alpha | ||
# use alpha close to 0.5 to get good statistics in few steps, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't leave comments.
testsuite/reaction_ensemble.py
Outdated
pK_a, pH) | ||
pK_a = -np.log10(K_HA_diss) | ||
#ideal=ReactionEnsembleTest.ideal_degree_of_association( pK_a, pH); | ||
ideal=0.05080885682460401; # hard-coded value from the original setup by Jonas |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not hard code these values but use the function that determines these values
testsuite/reaction_ensemble.py
Outdated
pK_a = -np.log10(K_HA_diss) | ||
#ideal=ReactionEnsembleTest.ideal_degree_of_association( pK_a, pH); | ||
ideal=0.05080885682460401; # hard-coded value from the original setup by Jonas | ||
target=0.05024999999999979; # hard-coded value from the original setup by Jonas |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what is target used for? It could be removed. That s where the Mac Os test is currently failing.
testsuite/constant_pH.py
Outdated
cls.type_HA], reactant_coefficients=[1], product_types=[ | ||
cls.type_A, cls.type_H], product_coefficients=[ | ||
1, 1], default_charges={cls.type_HA: 0, cls.type_A: -1, cls.type_H: +1}) | ||
cls.RE.constant_pH = cls.pH | ||
|
||
@classmethod | ||
def ideal_degree_of_association(cls, pH): | ||
def ideal_alpha(cls, pH): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the formula for the degree of association= 1-degree of dissociation=1-alpha, please dont use alpha but a more descriptive name!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks to me like exchanging the degree of association and the degree of dissociation works here because both are 0.5 here. Therefore I would choose a point in the parameter space where both are distinct.
testsuite/constant_pH.py
Outdated
pH = pKa_minus_pH # or randomly via: 4*np.random.random() | ||
pH = 2 # or randomly via: 4*np.random.random() | ||
pKa_minus_pH = 0 | ||
pH = pKa_minus_pH |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line is overwritten by the next line
testsuite/reaction_ensemble.py
Outdated
average_NA /= num_samples | ||
average_NHA /= num_samples | ||
average_alpha = average_NA / float(N0) | ||
print("average_NH:", average_NH, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please dont print in tests
testsuite/reaction_ensemble.py
Outdated
@@ -81,7 +81,8 @@ def setUpClass(cls): | |||
reactant_types=cls.reactant_types, | |||
reactant_coefficients=cls.reactant_coefficients, | |||
product_types=cls.product_types, | |||
product_coefficients=cls.product_coefficients, default_charges={cls.type_HA: 0, cls.type_A: -1, cls.type_H: +1}, check_for_electroneutrality=True) | |||
product_coefficients=cls.product_coefficients, | |||
default_charges={cls.type_HA: 0, cls.type_A: -1, cls.type_H: +1}, check_for_electroneutrality=True) | |||
|
|||
@classmethod | |||
def ideal_alpha(cls, Gamma,N0,V,nubar): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
The reaction ensemble method was moved by @KonradBreitsprecher to the appendix since it was not obvious that the code is documented. If you add a minimal example to the documentation on how to setup a reaction in the rst you can move it to the advanced methods section. |
…opefully no more failures will follow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me
Corrected reaction ensemble documentation, small changes in RE syntax…
…, and corrections to teststuite and samples to comply with the current syntax.
Partly Fixes #1650 Some issues still need to be clarified.
Description of changes:
PR Checklist