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

Corrected reaction ensemble documentation, small changes in RE syntax… #1741

Merged
merged 24 commits into from
Feb 6, 2018

Conversation

kosovan
Copy link
Contributor

@kosovan kosovan commented Dec 28, 2017

…, 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:

  • fixed the description of the standard_pressure
  • rephrased documentation of several other functions and parameters
  • changed RE.add() to RE.add_reaction() to make the semantics consistent with RE.add_collective_variable..()
  • adopted the samples to the current state of Reaction Ensemble code

PR Checklist

  • Tests?
    • Interface
    • Core
  • Docs?

…, and corrections to teststuite and samples to comply with the current syntax.
@codecov
Copy link

codecov bot commented Dec 28, 2017

Codecov Report

Merging #1741 into python will increase coverage by <1%.
The diff coverage is 75%.

Impacted file tree graph

@@           Coverage Diff           @@
##           python   #1741    +/-   ##
=======================================
+ Coverage      59%     60%   +<1%     
=======================================
  Files         416     416            
  Lines       28815   28965   +150     
=======================================
+ Hits        17288   17386    +98     
- Misses      11527   11579    +52
Impacted Files Coverage Δ
src/core/reaction_ensemble.hpp 76% <ø> (ø) ⬆️
src/core/reaction_ensemble.cpp 74% <75%> (ø) ⬆️
src/core/rattle.cpp 91% <0%> (-2%) ⬇️
src/core/p3m-dipolar.cpp 79% <0%> (-2%) ⬇️
src/core/integrate.cpp 73% <0%> (-1%) ⬇️
src/core/forces_inline.hpp 64% <0%> (-1%) ⬇️
src/core/metadynamics.cpp 6% <0%> (-1%) ⬇️
src/core/energy_inline.hpp 51% <0%> (-1%) ⬇️
src/core/magnetic_non_p3m_methods.cpp 7% <0%> (-1%) ⬇️
src/core/topology.cpp 3% <0%> (-1%) ⬇️
... and 20 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f74064d...fca320a. Read the comment docs.

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
Copy link
Member

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.

Copy link
Member

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?

Copy link
Member

@jonaslandsgesell jonaslandsgesell Jan 2, 2018

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?

Copy link
Contributor Author

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.
Copy link
Member

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.

Copy link
Contributor Author

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.

…ous conventional definitions of equilibrium constant.
* 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
@kosovan
Copy link
Contributor Author

kosovan commented Jan 17, 2018

@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.

@jonaslandsgesell
Copy link
Member

Looks good to me


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
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Contributor Author

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?

@@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove the comment

# 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);
Copy link
Member

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.

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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove

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,
Copy link
Member

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.

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
Copy link
Member

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

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
Copy link
Member

@jonaslandsgesell jonaslandsgesell Jan 22, 2018

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.

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):
Copy link
Member

@jonaslandsgesell jonaslandsgesell Feb 1, 2018

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!

Copy link
Member

@jonaslandsgesell jonaslandsgesell Feb 1, 2018

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.

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
Copy link
Member

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

average_NA /= num_samples
average_NHA /= num_samples
average_alpha = average_NA / float(N0)
print("average_NH:", average_NH,
Copy link
Member

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

@@ -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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

@jonaslandsgesell
Copy link
Member

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.

Copy link
Member

@jonaslandsgesell jonaslandsgesell left a 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

@fweik
Copy link
Contributor

fweik commented Feb 6, 2018

@fweik fweik merged commit b5cf1f1 into espressomd:python Feb 6, 2018
ashreyaj pushed a commit to ashreyaj/espresso that referenced this pull request Aug 9, 2018
Corrected reaction ensemble documentation, small changes in RE syntax…
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

reaction ensemble docs need to be corrected
4 participants