-
Notifications
You must be signed in to change notification settings - Fork 46
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
Lazy merge #589
Merged
Merged
Lazy merge #589
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6d3afd1
first pass at lazy merge
csbrasnett 964050a
added some more info to the help
csbrasnett 52836f4
addressed comments, added tests
csbrasnett 7234f08
Merge branch 'master' into lazy-merge
pckroon 444719f
addressed comments
csbrasnett e0a9c0a
changed suggestions
csbrasnett d5ee2dd
missed one
csbrasnett b85f024
Merge branch 'master' into lazy-merge
csbrasnett File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
# Copyright 2018 University of Groningen | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
""" | ||
Contains unittests for vermouth.processors.merge_chains. | ||
""" | ||
|
||
import networkx as nx | ||
import pytest | ||
from vermouth.system import System | ||
from vermouth.molecule import Molecule | ||
from vermouth.forcefield import ForceField | ||
from vermouth.processors.merge_chains import ( | ||
MergeChains | ||
) | ||
from vermouth.tests.datafiles import ( | ||
FF_UNIVERSAL_TEST, | ||
) | ||
|
||
@pytest.mark.parametrize('node_data, edge_data, merger, expected', [ | ||
( | ||
[ | ||
{'chain': 'A', 'resname': 'ALA', 'resid': 1}, | ||
{'chain': 'A', 'resname': 'ALA', 'resid': 2}, | ||
{'chain': 'A', 'resname': 'ALA', 'resid': 3}, | ||
{'chain': 'B', 'resname': 'ALA', 'resid': 1}, | ||
{'chain': 'B', 'resname': 'ALA', 'resid': 2}, | ||
{'chain': 'B', 'resname': 'ALA', 'resid': 3} | ||
], | ||
[(0, 1), (1, 2), (3, 4), (4, 5)], | ||
{"chains": ["A", "B"], "all_chains": False}, | ||
False | ||
), | ||
( | ||
[ | ||
{'chain': 'A', 'resname': 'ALA', 'resid': 1}, | ||
{'chain': 'A', 'resname': 'ALA', 'resid': 2}, | ||
{'chain': 'A', 'resname': 'ALA', 'resid': 3}, | ||
{'chain': 'B', 'resname': 'ALA', 'resid': 1}, | ||
{'chain': 'B', 'resname': 'ALA', 'resid': 2}, | ||
{'chain': 'B', 'resname': 'ALA', 'resid': 3} | ||
], | ||
[(0, 1), (1, 2), (3, 4), (4, 5)], | ||
{"chains": [], "all_chains": True}, | ||
False | ||
), | ||
( | ||
[ | ||
{'chain': 'A', 'resname': 'ALA', 'resid': 1}, | ||
{'chain': 'A', 'resname': 'ALA', 'resid': 2}, | ||
{'chain': 'A', 'resname': 'ALA', 'resid': 3}, | ||
{'chain': None, 'resname': 'ALA', 'resid': 1}, | ||
{'chain': None, 'resname': 'ALA', 'resid': 2}, | ||
{'chain': None, 'resname': 'ALA', 'resid': 3} | ||
], | ||
[(0, 1), (1, 2), (3, 4), (4, 5)], | ||
{"chains": [], "all_chains": True}, | ||
True | ||
), | ||
|
||
]) | ||
def test_merge(caplog, node_data, edge_data, merger, expected): | ||
""" | ||
Tests that the merging works as expected. | ||
""" | ||
system = System(force_field=ForceField(FF_UNIVERSAL_TEST)) | ||
mol = Molecule(force_field=system.force_field) | ||
mol.add_nodes_from(enumerate(node_data)) | ||
mol.add_edges_from(edge_data) | ||
|
||
mols = nx.connected_components(mol) | ||
for nodes in mols: | ||
system.add_molecule(mol.subgraph(nodes)) | ||
|
||
processor = MergeChains() | ||
processor.chains = merger["chains"] | ||
processor.all_chains = merger["all_chains"] | ||
|
||
caplog.clear() | ||
processor.run_system(system) | ||
|
||
if expected: | ||
assert any(rec.levelname == 'WARNING' for rec in caplog.records) | ||
else: | ||
assert caplog.records == [] | ||
|
||
def test_too_many_args(): | ||
""" | ||
Tests that error is raised when too many arguments are given. | ||
""" | ||
node_data = [ | ||
{'chain': 'A', 'resname': 'ALA', 'resid': 1}, | ||
{'chain': 'A', 'resname': 'ALA', 'resid': 2}, | ||
{'chain': 'A', 'resname': 'ALA', 'resid': 3}, | ||
{'chain': 'B', 'resname': 'ALA', 'resid': 1}, | ||
{'chain': 'B', 'resname': 'ALA', 'resid': 2}, | ||
{'chain': 'B', 'resname': 'ALA', 'resid': 3} | ||
] | ||
edge_data = [(0, 1), (1, 2), (3, 4), (4, 5)] | ||
|
||
system = System(force_field=ForceField(FF_UNIVERSAL_TEST)) | ||
mol = Molecule(force_field=system.force_field) | ||
mol.add_nodes_from(enumerate(node_data)) | ||
mol.add_edges_from(edge_data) | ||
|
||
mols = nx.connected_components(mol) | ||
for nodes in mols: | ||
system.add_molecule(mol.subgraph(nodes)) | ||
|
||
merger = {"chains": ["A", "B"], "all_chains": True} | ||
|
||
processor = MergeChains() | ||
processor.chains = merger["chains"] | ||
processor.all_chains = merger["all_chains"] | ||
csbrasnett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
with pytest.raises(ValueError): | ||
processor.run_system(system) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do we want an informative message here?
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.
Have put one, but probably not necessary. Martinize2 will raise its ArgumentError before it gets here if both have been given, so this would have to be someone using the processor on its own for some reason!
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.
Exactly that, but that is a possibility we want to enable/encourage/support