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

Lazy merge #589

Merged
merged 8 commits into from
May 1, 2024
Merged

Lazy merge #589

merged 8 commits into from
May 1, 2024

Conversation

csbrasnett
Copy link
Collaborator

Lazy merging of chains as per #587. Instead of specifying groups of chains to merge, users can just give -merge all and all chains get merged.

vermouth/processors/merge_chains.py Outdated Show resolved Hide resolved
vermouth/processors/merge_chains.py Outdated Show resolved Hide resolved
vermouth/processors/merge_chains.py Outdated Show resolved Hide resolved
@csbrasnett
Copy link
Collaborator Author

If/once you've merged the codecov update in #565 I'll merge main into here and I guess that'll fix the tests

bin/martinize2 Outdated
Comment on lines 980 to 981
elif "all" in args.merge_chains and len(args.merge_chains) == 1:
vermouth.MergeChains(chains=None, all_chains=True).run_system(system)
Copy link
Member

Choose a reason for hiding this comment

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

args.merge_chains cannot be 'all' and have a length of 1 right? Since the split only happens in the if

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this is defending against multiple arguments though, eg. if you give both -merge all -merge A,B then args.merge_chains = ['all, 'A,B'], so really you need to make sure there really is only one argument

Copy link
Member

Choose a reason for hiding this comment

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

Good catch! Needs a comment though.

bin/martinize2 Outdated Show resolved Hide resolved
vermouth/processors/merge_chains.py Outdated Show resolved Hide resolved
vermouth/processors/merge_chains.py Outdated Show resolved Hide resolved
Comment on lines 87 to 89
def __init__(self, chains=None, all_chains=False):
self.chains = chains
self.all_chains = all_chains
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def __init__(self, chains=None, all_chains=False):
self.chains = chains
self.all_chains = all_chains
def __init__(self, chains=None, all_chains=False):
self.chains = chains or []
self.all_chains = all_chains

- made stronger warnings in martinize2
- clarified conditions for merging in merge_chains
- improved warnings and exceptions in merge_chains
- changed tests to reflect abovex
Copy link
Member

@pckroon pckroon left a comment

Choose a reason for hiding this comment

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

Small nitpicks left :)

Comment on lines 84 to 86
def __init__(self, chains=[], all_chains=False):
self.chains = chains
self.all_chains = all_chains
Copy link
Member

Choose a reason for hiding this comment

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

It's generally a bad idea to give a mutable type as default argument, since it will be created only once and shared among all calls/instances. Here it's probably fine since chains is not modified anywhere, but still, something like this is preferred:

def __init__(self, chains=None, all_chains=False):
    self.chains = chains or []
    self.all_chains = all_chains.

As an example of what can go wrong:

def a(x=[]):
    x.append(1)
    print(x)

a()
a()

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks!

vermouth/tests/test_merge_chains.py Outdated Show resolved Hide resolved
_chains = set()
for molecule in system.molecules:
# Molecules can contain multiple chains
_chains.update(node.get('chain') for node in molecule.nodes.values())
else:
LOGGER.warning('Conflicting merging arguments have been given. Will abort merging.')
return
raise ValueError
Copy link
Member

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?

Copy link
Collaborator Author

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!

Copy link
Member

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

@pckroon
Copy link
Member

pckroon commented May 1, 2024

Excellent work, thanks!

@pckroon pckroon merged commit e9bf1c9 into marrink-lab:master May 1, 2024
8 checks passed
@csbrasnett csbrasnett deleted the lazy-merge branch May 1, 2024 11:42
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.

2 participants