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

Solvation plots #67

Merged
merged 36 commits into from Feb 13, 2023
Merged

Solvation plots #67

merged 36 commits into from Feb 13, 2023

Conversation

laurlee
Copy link
Contributor

@laurlee laurlee commented Jul 27, 2022

Description

Provide a brief description of the PR's purpose here.

Todos

Notable points that this PR has either accomplished or will accomplish.

  • TODO 1

Questions

  • Question1

Status

  • Ready to go

orionarcher and others added 24 commits May 18, 2022 14:10
# Conflicts:
#	requirements.txt
#	solvation_analysis/solution.py
#	solvation_analysis/tests/test_analysis_library.py
# Conflicts:
#	solvation_analysis/tests/test_analysis_library.py
# Conflicts:
#	solvation_analysis/tests/conftest.py
# Conflicts:
#	solvation_analysis/tests/conftest.py
@pep8speaks
Copy link

pep8speaks commented Jul 27, 2022

Hello @laurlee! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

Line 30:53: E231 missing whitespace after ','
Line 30:56: E231 missing whitespace after ','
Line 37:1: E302 expected 2 blank lines, found 1
Line 41:1: E302 expected 2 blank lines, found 1
Line 59:1: E302 expected 2 blank lines, found 1
Line 76:120: E501 line too long (120 > 119 characters)
Line 179:1: E302 expected 2 blank lines, found 1
Line 192:13: E128 continuation line under-indented for visual indent
Line 194:1: E302 expected 2 blank lines, found 1
Line 235:1: E302 expected 2 blank lines, found 1
Line 256:1: E302 expected 2 blank lines, found 1
Line 291:1: E302 expected 2 blank lines, found 1
Line 304:1: W391 blank line at end of file

Line 261:1: W391 blank line at end of file

Line 20:1: E302 expected 2 blank lines, found 1
Line 25:1: E302 expected 2 blank lines, found 1
Line 31:1: E302 expected 2 blank lines, found 1
Line 32:40: E231 missing whitespace after ','
Line 37:1: E302 expected 2 blank lines, found 1
Line 38:40: E231 missing whitespace after ','
Line 43:1: E302 expected 2 blank lines, found 1
Line 49:1: E302 expected 2 blank lines, found 1
Line 54:1: E302 expected 2 blank lines, found 1
Line 59:1: E302 expected 2 blank lines, found 1
Line 63:1: W391 blank line at end of file

Comment last updated at 2022-08-17 19:38:59 UTC

@laurlee laurlee mentioned this pull request Jul 27, 2022
1 task
Copy link
Member

@hmacdope hmacdope left a comment

Choose a reason for hiding this comment

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

Thanks for opening a new PR @laurlee!

Just a few comments. :) Are you planning to finish off the plotting functionality all in this PR?

solvation_analysis/tests/test_plotting.py Show resolved Hide resolved
# histogram of what?
return

def format_graph(fig, title, x_axis, y_axis):
Copy link
Member

Choose a reason for hiding this comment

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

This feels a little bit unnecessary. I would just update these in the graph when required. :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

What do you think of the idea of a general templating function? I am thinking each function could return a fairly bare bones plot that could then be prettied up with some formatting function.

def format_plot(fig)
    # format fig
    return fig

fig = plot_something(data)
pretty_fig = format_plot(fig)

This might be overly complicated, but we could also make it a decorator.

def pretty_plot(plotting_func):
    def pretty_plotting_func(data):
        fig = plotting_func(data)
        # format fig
        return fig
    return pretty_plotting_func

we could then add the formatting decorator to our definition of each plot. This would allow solvation_analysis to standardize a particular plotting style (I have become quite opinionated on the subject) with maximum code reuse.

@pretty_plot
def plotting_func(data)
    # make fig
    return fig 

To be clear, this is a bit different from what's currently in the code.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds like a good idea to me!

def plot_speciation(solution):
# square area
# should be doable with plotly.express.imshow and go.add_annotations
return
Copy link
Member

Choose a reason for hiding this comment

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

Reminder to fill these out :)

solvation_analysis/plotting.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@orionarcher orionarcher left a comment

Choose a reason for hiding this comment

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

Nice progress @laulee! A few comments, some of which we have already discussed.

solvation_analysis/plotting.py Outdated Show resolved Hide resolved
solvation_analysis/tests/test_plotting.py Show resolved Hide resolved
solvation_analysis/plotting.py Show resolved Hide resolved
solvation_analysis/plotting.py Outdated Show resolved Hide resolved
solvation_analysis/plotting.py Outdated Show resolved Hide resolved
solvation_analysis/plotting.py Outdated Show resolved Hide resolved
solvation_analysis/plotting.py Outdated Show resolved Hide resolved
solvation_analysis/plotting.py Show resolved Hide resolved

def test_plot_network_size_histogram(networking):
fig = plot_network_size_histogram(networking)
fig.show()
Copy link
Member

Choose a reason for hiding this comment

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

I don't think you ever need to have show() in library code (and certainly not in the tests): either you can return the fig object and then the user can do what they want (including show) or your code plot to files and generates files (and then it slows you down a lot to run show).

def test_plot_network_size_histogram(networking):
fig = plot_network_size_histogram(networking)
fig.show()
assert True
Copy link
Member

Choose a reason for hiding this comment

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

I'd always assert something meaningful, e.g., that this is the correct instance, or you can dig into the figure object and check that it has the right labels, or that the data is what you expect it to be. But do a tiny bit more than flushing code paths.

Copy link
Collaborator

@orionarcher orionarcher left a comment

Choose a reason for hiding this comment

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

Just a few small things. This is coming along nicely!

solvation_analysis/plotting.py Outdated Show resolved Hide resolved
solvation_analysis/plotting.py Outdated Show resolved Hide resolved
fig : Plotly.Figure

"""
fig.update_layout(xaxis_title_text=x_axis.title(), yaxis_title_text=y_axis.title(), title=title.title())
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd favor removing the format_graph function and just moving this to plot_pairing, plot_coordination etc. That will reduce the number of kwargs to compare_solvent_dicts and reduce the number of functions.

"""
# catch_different_solvents(solutions)
residence = [solution.residence.residence_times for solution in solutions]
residence = set(residence) - set(ignore)
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this an old implementation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I'll update it to reflect the current implementation when I next push the code.

…rmatting, added implementation to coordination and residence, and added more tests
Copy link
Collaborator

@orionarcher orionarcher left a comment

Choose a reason for hiding this comment

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

Nice work @laurlee! I have a few comments mostly related to variable naming and readability. I think the implementation all looks good.

The main remaining challenge before merging this will be updating to v0.1.4 which has a number of API changes.

solvation_analysis/plotting.py Outdated Show resolved Hide resolved
solvation_analysis/plotting.py Outdated Show resolved Hide resolved
solvation_analysis/plotting.py Outdated Show resolved Hide resolved
solvation_analysis/plotting.py Outdated Show resolved Hide resolved
solvation_analysis/plotting.py Outdated Show resolved Hide resolved
solvation_analysis/plotting.py Outdated Show resolved Hide resolved
Comment on lines 149 to 157
if keep_solvents:
for solution in properties:
try:
properties[solution] = {keep: properties[solution][keep] for keep in keep_solvents}
except KeyError:
# if argument for keep_solvents is invalid
raise Exception("Invalid value of keep_solvents. \n keep_solvents: " +
str(keep_solvents) + "\n Valid options for keep_solvents: " +
str(list(properties[solution].keys()))) from None
Copy link
Collaborator

Choose a reason for hiding this comment

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

If possible, let's try to avoid the try except loop.

Look into Dict.get() which returns the item if it exists and returns None if not. It's a very convenient function!

Comment on lines 284 to 289
if res_type == "residence_times":
res_time = {solution: solutions[solution].residence.residence_times for solution in solutions}
elif res_type == "residence_times_fit":
res_time = {solution: solutions[solution].residence.residence_times_fit for solution in solutions}
else:
raise ValueError("res_type must be either \"residence_times\" or \"residence_times_fit\"")
Copy link
Collaborator

Choose a reason for hiding this comment

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

lets use Solution.hasattr("residence") to check if residence is present.

@orionarcher orionarcher merged commit d857bae into MDAnalysis:main Feb 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants