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

add function to create a minimal network with redundancy for all nodes #559

Merged
merged 24 commits into from
Oct 10, 2023

Conversation

JenkeScheen
Copy link
Contributor

@JenkeScheen JenkeScheen commented Sep 15, 2023

Developers certificate of origin


I'm building a function that will generate a LigandNetwork where each node is connected to two edges. This will increase performance during analysis by introducing redundancy: if one of the two edges has a high error associated with it, the other edge (hopefully with much lower error) will be weighted to contribute more to the DG estimation.

The basic algorithm will be based on openfe.setup.ligand_network_planning.generate_minimal_spanning_network, but will also add the 'second-best-scoring` edge for each node.

@richardjgowers
Copy link
Contributor

This sounds handy. I'm curious if doubly connected MST is rigorously defined, but I'm sure there's ways to approximate it. One hacky way would be to run MST, set the chosen edges to bad values then rerun the MST alg to get the "2nd best" network.

@codecov
Copy link

codecov bot commented Sep 15, 2023

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (ab0ae26) 91.29% compared to head (578b7a1) 91.38%.
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #559      +/-   ##
==========================================
+ Coverage   91.29%   91.38%   +0.08%     
==========================================
  Files         117      117              
  Lines        7287     7357      +70     
==========================================
+ Hits         6653     6723      +70     
  Misses        634      634              
Files Coverage Δ
openfe/tests/setup/test_network_planning.py 100.00% <100.00%> (ø)
openfecli/commands/gather.py 85.98% <100.00%> (+0.73%) ⬆️
openfecli/tests/commands/test_gather.py 100.00% <100.00%> (ø)
openfe/setup/ligand_network_planning.py 99.30% <95.00%> (-0.70%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@JenkeScheen
Copy link
Contributor Author

This sounds handy. I'm curious if doubly connected MST is rigorously defined, but I'm sure there's ways to approximate it. One hacky way would be to run MST, set the chosen edges to bad values then rerun the MST alg to get the "2nd best" network.

doing something like this. I'm currently just running an MST, then removing those edges from the fully-connected network, then running MST again, then adding the two MSTs together.

@JenkeScheen
Copy link
Contributor Author

@richardjgowers this is working for me locally, so ready for review. I'm not familiar with how you've set up testing, should I add tests for this function somewhere?

A simple test would be to assert that all nodes are connected to n edges, but I'm not sure how to expose the networkx object from a LigandNetwork?

@richardjgowers
Copy link
Contributor

@JenkeScheen LigandNetwork.graph should give you a nx.MultiDiGraph. This file has the relevant tests: https://github.com/OpenFreeEnergy/openfe/blob/main/openfe/tests/setup/test_network_planning.py

@JenkeScheen
Copy link
Contributor Author

added a test that all nodes are connected to at least two edges. @richardjgowers please fiddle with the tests as you see fit, the copy-pasting from test_minimal_spanning_network isn't very elegant. Other than that this is ready to be reviewed fully.

@JenkeScheen JenkeScheen changed the title [WIP] add function to create a minimal network with redundancy for all nodes add function to create a minimal network with redundancy for all nodes Sep 20, 2023
Copy link
Member

@dwhswenson dwhswenson left a comment

Choose a reason for hiding this comment

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

Thanks! This is a great contribution.

One definite fix needed: looks like a test isn't being prefaced by test_, so it isn't running.

Other suggestions are mainly potential improvements to the tests.

openfe/setup/ligand_network_planning.py Outdated Show resolved Hide resolved
openfe/tests/setup/test_network_planning.py Outdated Show resolved Hide resolved
openfe/tests/setup/test_network_planning.py Outdated Show resolved Hide resolved
openfe/tests/setup/test_network_planning.py Outdated Show resolved Hide resolved
@pep8speaks
Copy link

pep8speaks commented Sep 20, 2023

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

Line 241:1: W293 blank line contains whitespace
Line 242:78: W291 trailing whitespace
Line 243:68: W291 trailing whitespace
Line 284:80: E501 line too long (80 > 79 characters)

Line 258:80: E501 line too long (86 > 79 characters)
Line 267:80: E501 line too long (81 > 79 characters)
Line 292:80: E501 line too long (92 > 79 characters)
Line 293:80: E501 line too long (89 > 79 characters)
Line 343:80: E501 line too long (90 > 79 characters)

Comment last updated at 2023-10-10 08:28:18 UTC

@JenkeScheen
Copy link
Contributor Author

Thanks for the review @dwhswenson, should be ready for another look now.

@mikemhenry
Copy link
Contributor

@JenkeScheen looks like CI is unhappy

@JenkeScheen
Copy link
Contributor Author

thanks @mikemhenry, should be good now.

@mikemhenry
Copy link
Contributor

now mypy needs some tlc https://github.com/OpenFreeEnergy/openfe/actions/runs/6271512074/job/17031266889?pr=559#step:6:13
openfe/tests/setup/test_network_planning.py:299: error: Name "test_minimal_redundant_network" already defined on line 267 [no-redef]

@mikemhenry
Copy link
Contributor

mikemhenry commented Sep 26, 2023

Thanks @JenkeScheen

This week most of us are busy at the MDAnalysis UGM, so if this doesn't get a review this week, I will be sure to get some eyes on it next Wednesday (10/04)

@richardjgowers richardjgowers self-assigned this Oct 2, 2023
@mikemhenry
Copy link
Contributor

These mypy errors are coming in from files not in in this PR, so I am guessing that something got merged in either without mypy passing, or there was an update to mypy so we have a new error to fix...

openfe/protocols/openmm_utils/multistate_analysis.py:77: error: Item "SubFigure" of "Union[Figure, SubFigure, None]" has no attribute "savefig"  [union-attr]
openfe/protocols/openmm_utils/multistate_analysis.py:77: error: Item "None" of "Union[Figure, SubFigure, None]" has no attribute "savefig"  [union-attr]
openfe/protocols/openmm_utils/multistate_analysis.py:86: error: Item "SubFigure" of "Union[Figure, SubFigure, None]" has no attribute "savefig"  [union-attr]
openfe/protocols/openmm_utils/multistate_analysis.py:86: error: Item "None" of "Union[Figure, SubFigure, None]" has no attribute "savefig"  [union-attr]
openfe/protocols/openmm_utils/multistate_analysis.py:95: error: Item "SubFigure" of "Union[Figure, SubFigure, None]" has no attribute "savefig"  [union-attr]
openfe/protocols/openmm_utils/multistate_analysis.py:95: error: Item "None" of "Union[Figure, SubFigure, None]" has no attribute "savefig"  [union-attr]
openfe/protocols/openmm_utils/multistate_analysis.py:105: error: Item "SubFigure" of "Union[Figure, SubFigure, None]" has no attribute "savefig"  [union-attr]
openfe/protocols/openmm_utils/multistate_analysis.py:105: error: Item "None" of "Union[Figure, SubFigure, None]" has no attribute "savefig"  [union-attr]

@IAlibay
Copy link
Member

IAlibay commented Oct 5, 2023

These mypy errors are coming in from files not in in this PR, so I am guessing that something got merged in either without mypy passing, or there was an update to mypy so we have a new error to fix...

openfe/protocols/openmm_utils/multistate_analysis.py:77: error: Item "SubFigure" of "Union[Figure, SubFigure, None]" has no attribute "savefig"  [union-attr]
openfe/protocols/openmm_utils/multistate_analysis.py:77: error: Item "None" of "Union[Figure, SubFigure, None]" has no attribute "savefig"  [union-attr]
openfe/protocols/openmm_utils/multistate_analysis.py:86: error: Item "SubFigure" of "Union[Figure, SubFigure, None]" has no attribute "savefig"  [union-attr]
openfe/protocols/openmm_utils/multistate_analysis.py:86: error: Item "None" of "Union[Figure, SubFigure, None]" has no attribute "savefig"  [union-attr]
openfe/protocols/openmm_utils/multistate_analysis.py:95: error: Item "SubFigure" of "Union[Figure, SubFigure, None]" has no attribute "savefig"  [union-attr]
openfe/protocols/openmm_utils/multistate_analysis.py:95: error: Item "None" of "Union[Figure, SubFigure, None]" has no attribute "savefig"  [union-attr]
openfe/protocols/openmm_utils/multistate_analysis.py:105: error: Item "SubFigure" of "Union[Figure, SubFigure, None]" has no attribute "savefig"  [union-attr]
openfe/protocols/openmm_utils/multistate_analysis.py:105: error: Item "None" of "Union[Figure, SubFigure, None]" has no attribute "savefig"  [union-attr]

Yeah this one just suddenly appeared it seems.

@IAlibay
Copy link
Member

IAlibay commented Oct 5, 2023

Looks like it came along with matplotlib 3.8.0 matplotlib/matplotlib#26812

@richardjgowers richardjgowers merged commit dc666ea into OpenFreeEnergy:main Oct 10, 2023
6 of 7 checks passed
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.

6 participants