-
Notifications
You must be signed in to change notification settings - Fork 81
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
reset_labels kwarg to force_overlap, new method reset_labels #1195
Conversation
…t label reset to a new method
Thanks for the PR! Just a note, the macOS-13 tests failing seems to be unrelated to these changes, so we can ignore those for now. It seems like adding the |
@chrisjonesBSU, separating |
The failing tests should be fixed and the codecov reported once you merge upstream/main. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1195 +/- ##
=======================================
Coverage 87.34% 87.35%
=======================================
Files 62 62
Lines 6584 6586 +2
=======================================
+ Hits 5751 5753 +2
Misses 833 833 ☔ View full report in Codecov by Sentry. 🚨 Try these New Features:
|
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.
LGTM, thanks!
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.
Test this with the code:
import mbuild as mb
from collections import OrderedDict
cpd = mb.load("CCCO", smiles=True)
particles_to_remove = list(cpd.particles())[-2:]
cpd.remove(particles_to_remove)
print(cpd.all_ports())
new_labels = OrderedDict()
for i,port in enumerate(cpd.all_ports()):
new_labels.update({f"port[{i+10}]":port})
del cpd.labels[f"port[{i}]"]
cpd.labels.update(new_labels)
print(cpd.all_ports())
particles_to_remove = list(cpd.particles())[-2:]
cpd.remove(particles_to_remove, reset_labels=False) # also test with True
print(cpd.all_ports())
And it seems to work okay.
I do get an error if I replace the code
new_labels.update({f"port[{i+10}]":port})
with
new_labels.update({f"port[{i+2}]":port})
969 label = label_pattern.format(count)
971 if not replace and label in self.labels:
--> 972 raise MBuildError(f'Label "{label}" already exists in {self}.')
973 else:
974 self.labels[label] = new_child
MBuildError: Label "port[2]" already exists in .
It looks like there's some assumed behavior with the port numbering that's the cause. Essentially, we remove a particle, so we also remove a bond. When we remove a bond, the [`add` function gets called on the port](https://github.com/mosdef-hub/mbuild/blob/8ce8049900be4c995f753fc31f8f95443ea25ace/mbuild/compound.py#L1517), and the label passed is "port[$]". This can clash with naming conventions, if the labels are not reset at all times on the ports.
Now, we could add some additional logic to handle this automatically, such as just increment until you find an unused label. Or, just add a little detail to this mBuild error to try setting `reset_labels` to True during a remove or force_overlap call. I'm in favor of that approach, but open to thoughts.
Co-authored-by: CalCraven <54594941+CalCraven@users.noreply.github.com>
Co-authored-by: CalCraven <54594941+CalCraven@users.noreply.github.com>
@CalCraven @chrisjonesBSU I would normally agree with you, except that the reset_labels feature was added to |
@jaclark5 while that's a good point I hadn't considered, I'll offer a counter point. And to your point, that PR for changing |
@CalCraven The issue was that it did change force_overlap. During force_overlap the method removed the ports to make a bond, calling ‘remove’ and relabeling the molecules. I’m attempting to restore the expected behavior of all of those resources. On Aug 17, 2024, at 10:59 AM, CalCraven ***@***.***> wrote:
@jaclark5 while that's a good point I hadn't considered, I'll offer a counter point.
force_overlap as an mBuild function is covered much more intensively in tutorials, workshops, and recipes we offer in the codebase, as opposed to remove which tends to be a bit more of the backend function for actually manually performing some of these operations one step at a time. While a change to the default behavior for remove might be less disruptive, changing the default behavior for remove_overlap has a potential to break many different pre-built recipes people are using in mBuild.
And to your point, that PR for changing remove is only 4 months old, so many people probably haven't even updated mBuild in that time frame, so even less of a chance much code will get broken.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: ***@***.***>
|
Ok, I was confused earlier, but changing labels after calling In #1173 we agreed that I think we should keep |
Hey @chrisjonesBSU I think we are on the same page now. If I understand correctly, you think the PR is the way that it should be except that the default, |
Yep, that's what I'm understanding as well. I think that sounds good to me. Sorry for the confusion, I think I may have caused that by misspeaking above. Also, just make sure the default in the doc string reflects the argument default as well, since I think in |
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.
LGTM once that remove
test is fixed to have the correct reset_labels calls!
Sorry I guess I suggested both True and False in my last comment haha. Yeah, let's set the default to I think we'll need a test now that checks for the labels correctly being changed after calling |
@CalCraven @chrisjonesBSU it should be all good! |
PR Summary:
This PR resolves #1194
This PR added the reset_labels kwarg to force_overlap with a default of False. In order to reset the labels as will, that code has been moved to a new method, Compound.reset_labels.
PR Checklist