-
Notifications
You must be signed in to change notification settings - Fork 3
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
Added functionality and some fixes #1
Conversation
Add missing unit conversion in pickle output
Sure, thanks for the contribution, @hejamu ! Please ping me when you need a review. Generally speaking, smaller/focused PRs are easier to handle than big ones. |
Thanks @orbeckst. Yeah, it's a bit of a mess with my commits... I didn't think about contributing my changes back when I started it... I guess I will just open the PR to initiate the discussion about it. The majority of the changes are just small additions and documentation. |
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.
@hejamu I had a few minutes to look over your PR. I am not an expert on flamel but apparently I am the only person looking at things at the moment so here we go.
The docs changes all look very good.
New output plugins are also good. I am happy to see that the plugin system works.
My primary concern is with code duplication, including how constants are sprinkled throughout the code. It would help a lot if you could come up with a way to collect all unit-conversion related code (including constants) in a separate module that is just imported in the other modules.
Similarly, at first glance there seems duplicated code in the plugins. If that's not the case then let me know. Otherwise this should all go into a plugin base class or you derive your class from another class that already has these (but it's cleaner to have a common base class so that changes in one class do not affect the other).
output/pickle.py
Outdated
|
||
class Pickle: | ||
name = 'pickle' | ||
k_b = 8.3144621E-3 |
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.
If we need constants then we should have them all in one place.
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 would be possible to use scipy.constants
since scipy is a dependency of alchemlyb anyway?
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.
Yes, good idea.
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'll still have to add it to flamel's setup.py to be explicit.)
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.
Er, sorry... there's no setup.py. In fact there's no installation at all... see #3
output/simple.py
Outdated
if args.unit == 'kT': | ||
conversion = 1.0 | ||
args.unit = 'kT' | ||
elif args.unit == 'kJ' or args.unit == 'kJ/mol': | ||
conversion = t * self.k_b | ||
args.unit = 'kJ/mol' | ||
elif args.unit == 'kcal' or args.unit == 'kcal/mol': | ||
conversion = 0.239006 * t * self.k_b | ||
args.unit = 'kcal/mol' | ||
|
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.
duplication of conversion code
output/alchemical_analysis.py
Outdated
|
||
if args.unit == 'kT': | ||
conversion = 1.0 | ||
args.unit = 'kT' | ||
elif args.unit == 'kJ' or args.unit == 'kJ/mol': | ||
conversion = 1.0 * t * self.k_b | ||
args.unit = 'kJ/mol' | ||
elif args.unit == 'kcal' or args.unit == 'kcal/mol': | ||
conversion = 0.239006 * t * self.k_b | ||
args.unit = 'kcal/mol' | ||
|
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.
duplication of conversion code — can this be put into a separate, reusable function ?
(There's some discussion on units in alchemlyb alchemistry/alchemlyb#125 but it will be a while until that is ready so in the meantime, flanel should certainly provide a way for unit conversion.)
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.
Putting this code and its duplicates in a separate function is definitely the best way. The linked discussion is very interesting though.
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.
By all means, contribute to the discussion! Contributors are very welcome.
output/text.py
Outdated
|
||
class Text: | ||
name = 'text' | ||
k_b = 8.3144621E-3 |
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.
keep constants in one place
output/text.py
Outdated
def ls(cls, estimators): | ||
""" | ||
Return a list of lambda values | ||
:param estimators: Series | ||
List of estimator plugins | ||
:return: | ||
The list of lambda values | ||
""" | ||
ls = [] | ||
if estimators: | ||
if estimators[0].needs_dhdls: | ||
means = estimators[0].dhdls.mean(level=estimators[0].dhdls.index.names[1:]) | ||
ls = np.array(means.reset_index()[means.index.names[:]]) | ||
elif estimators[0].needs_u_nks: | ||
means = estimators[0].u_nks.mean(level=estimators[0].u_nks.index.names[1:]) | ||
ls = np.array(means.reset_index()[means.index.names[:]]) | ||
|
||
return ls |
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 code as in Pickle plugin?
output/text.py
Outdated
return l_types | ||
|
||
@classmethod | ||
def segments(cls, estimators): |
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.
duplicate code?
output/text.py
Outdated
if args.unit == 'kT': | ||
conversion = 1.0 | ||
args.unit = 'kT' | ||
elif args.unit == 'kJ' or args.unit == 'kJ/mol': | ||
conversion = t * self.k_b | ||
args.unit = 'kJ/mol' | ||
elif args.unit == 'kcal' or args.unit == 'kcal/mol': | ||
conversion = 0.239006 * t * self.k_b | ||
args.unit = 'kcal/mol' |
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.
duplicated code... with lots of hard-coded constants :-p
ind = np.array(ind, dtype=int) | ||
dhdl_sum = dhdl_.dot(ind) | ||
uncorrelated_dfs.append(alchemlyb.preprocessing.statistical_inefficiency(df, dhdl_sum, lower, conservative=False)) | ||
uncorrelated_dfs.append(alchemlyb.preprocessing.statistical_inefficiency(df, lower=lower)) |
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.
Set explicitly conservative=True
.
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.
See below.
ind = np.array(l, dtype=bool) | ||
ind = np.array(ind, dtype=int) | ||
dhdl_sum = dhdl_.dot(ind) |
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's the rationale for not using dhdl_sum
?
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 can't recall why this change was made.... I will have to look into this.
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 was a temporary change due to alchemistry/alchemlyb#166. We identified the cause just now. I reverted the change.
@orbeckst Thanks for looking into this so thoroughly. The units really are a mess... I hope to get to the changes soon :) |
@hejamu are you still interested in finalizing the PR? About constants: use scipy.constants (alchemlyb switched to using it, too). |
Main changes: - make the `energy_unit` attribute propagate through the `uncorrelate` plugins. - use alchemlybs new conversion feature to facilitate easy unit conversion. - Removed `text` output plugin. This was just a file version of the `alchemical-analysis` output. Moved into the `alchemical-analysis` plugin
Sorry, this was low priority for me in the last months. I think these change are a step in the right direction. |
Overall I like the code clean-up and how much @xiki-tempula 's new units system improved the code here! In the absence of any tests (see #9 ) I am going to just say "ok". My feeling is that adding CI with tests (#9) is the next important milestone to give flamel a chance to grow and gain a user base. |
@xiki-tempula @harlor do you want to have a look at this PR before a merge? |
I manually merged this branch into master in 91d1cc4 so the code is in the retroactive 0.2.0. I'll also merge into develop so that the branch shows up merged but we are not using develop anymore. |
Hi all,
I use this modified version of flamel in my research. Maybe this is interesting for others.