-
Notifications
You must be signed in to change notification settings - Fork 230
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
Reverse kinetics for sticking coefficient #2080
Conversation
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.
Try to assume default values as little as possible.
In the context of the website, some surface site density must be assumed (which should be reported on the website), but otherwise we should have it specified in the reaction simulation, and should use that value. By putting default values in the method definitions, we risk forgetting to use the actual value.
But the fact that we didn't need these methods suggests we won't actually use them during a simulation, so it's perhaps a moot point. Although if we do end up using it, as you suggest in the PR comment, for reversing training reactions, then getting the surface site density from the metal attributes database would presumably be the right thing to do 🤷 Although perhaps doing it per site would be better than per square centimeter anyway.
Anyway, in cases where you do need to use an assumed default, please make sure to specify it in the docstrings that this is happening.
rmgpy/reaction.py
Outdated
@@ -677,7 +679,7 @@ def get_rate_coefficient(self, T, P=0): | |||
else: | |||
return self.kinetics.get_rate_coefficient(T, P) | |||
|
|||
def get_surface_rate_coefficient(self, T, surface_site_density): | |||
def get_surface_rate_coefficient(self, T, surface_site_density=2.5e-05): |
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 think this one is required, because it's set by the calling functions? I'm not very happy with having a default, in general, as it increases the chance of someone forgetting to pass it when they should. (There's no current bug, I'm just anticipating future bugs..)
Codecov Report
@@ Coverage Diff @@
## master #2080 +/- ##
==========================================
+ Coverage 47.54% 47.60% +0.06%
==========================================
Files 89 89
Lines 23565 23565
Branches 6131 6131
==========================================
+ Hits 11204 11219 +15
+ Misses 11177 11166 -11
+ Partials 1184 1180 -4
Continue to review full report at Codecov.
|
Thanks for your review Richard! Sounds good, I can take the default values out. One of the reasons for the default is that for all of the kinetics types except Sticking Coeff in ‘generate_reverse_rate_constant’, we don’t need the surface site density (so I don’t want to force the user to specify one). In that case, maybe I should remove Sticking Coeff from that function and we should just call ‘ reverse_sticking_coeff_rate’. It makes sense to have a separate function for this since it’s the only one dependent on surface site density. As for training reactions, I think most if not all of our families are in the surface adsorption direction (rather than the desorption direction) so we haven’t needed to reverse a sticking coeff yet, but if we do, I think it makes the most sense to use the surface densities in the Metal DB since we are also using atomic binding energies from there. |
Agree that requiring a parameter that is not used would be bad. Could do something like have it default to zero and raise an exception (ValueError?) if it's needed and is zero. But not complain if it's not needed. |
8be14db
to
f34f0c1
Compare
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 looks good to me! I like richard's suggestion of not having a default value.
With the last push, I added docstings and changed the default surface_site_density to 0 for methods that don't require a surface site density. That way, the user doesn't need to provide it, but if it is needed in the function to calc Surface Coefficient rate constant, we will raise a value error if a nonzero (and non negative) surface site density is not provided. We would just need to provide a surface site density for the website for |
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.
Looking good! thanks david. I just noticed one last thing.
rmgpy/reaction.py
Outdated
cython.declare(Tlist=np.ndarray, klist=np.ndarray, i=cython.int) | ||
kf = k_forward | ||
if not isinstance(kf, StickingCoefficient): # Only reverse StickingCoefficient rates | ||
raise TypeError(f'Expected a StickingCoefficient object for k_forward but received {kf}') |
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.
Probably this type check with a nice polite TypeError should check k_forward before we assign it to kf which has already been declared a StickingCoefficient in cython. Currently, if k_forward is not StickingCoefficient I guess it'll crash on line 866 and never reach 867 ?
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.
ah yes, good catch. I'll fix this
f34f0c1
to
dcf656a
Compare
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 still looks good to me
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 think I can understand this. Thanks, David! It looks good to me.
So that we can call this method regardless of what type the kinetics is
This method fits a SurfaceArrhenius model to the reverse rate by evaluating the forward stickingcoeff rate for a surface site density (default 2.5e-05 mol/m^2) over a temperature range
7588b2a
dcf656a
to
7588b2a
Compare
Motivation or Problem
RMG had no method to reverse Sticking Coefficient kinetics. I believe this is related to this website issue #2079. Adding a method to reverse Sticking Coeffs could be useful to compare Sticking Coeff kinetics with literature rates that are expressed as Arrhenius in the reverse direction. This method could also be useful if we need to reverse sticking coefficient kinetics in training reactions.
Description of Changes
Added StickingCoefficient kinetics handling to reaction
get_rate_coefficient
method so that we can use this method for all types of kinetics.Added a method to reverse StickingCoefficient kinetics with default surface site density.
Testing
Added a unit test for reversing StickingCoefficient kinetics