-
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
Specify individual axes to constrain within PACKMOL in packing.py #734
base: main
Are you sure you want to change the base?
Conversation
Also, I think it is worth mentioning that after talking with Jenny a bit about this change, she offered an alternative approach that greatly reduced the amount of if/else statements. I decided to keep my original changes because its a bit easier to read what is happening, but it is probably worth considering a more efficient approach given below:
|
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.
This is a great addition! Thanks @chrisjonesBSU ! The next steps are the unit tests. Im not entirely sure the best way to validate this. Aside from asserting that the expected strings are written out for a variety of cases, and packmol successfully fills the box. A minimal example of a system with this applied might be useful to post here too. But that would be more for GitHub viewing rather than something we can test.
I also included a possible suggestion for the logic to reduce some of the needed conditionals, but we can choose however we want to do that as this is fleshed out with tests.
mbuild/packing.py
Outdated
PACKMOL_CONSTRAIN = CONSTRAIN.format(constraints[0], constraints[2], "") | ||
if fix_orientation[1] and fix_orientation[2]: # Only y and z are fixed | ||
PACKMOL_CONSTRAIN = CONSTRAIN.format(constraints[1], constraints[2], "") | ||
return PACKMOL_CONSTRAIN |
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.
One other option that might be aligned with jenny's suggestion
final_constraints = list()
for i,val in enumerate(fix_orientation):
if val:
final_constraints.append(constraints[i])
else:
final_constraints.append("")
PACKMOL_CONSTRAIN = CONSTRAIN.format(final_constraints**)
Yours is more readable, but this removes all of the conditionals from line 74 onwards i think
Right now |
@justinGilmer Since this involves a slight API change, should I add behaviour to handle the original case of |
I think this should still be supported. If the user passes Also, double check that your code will give the expected behavior for multiple compounds. There is an |
…atting; lowers the amount of if/else statements
This pull request introduces 2 alerts and fixes 1 when merging 7f068d8 into 4b60ced - view on LGTM.com new alerts:
fixed alerts:
|
This pull request introduces 1 alert when merging 41669bc into 4b60ced - view on LGTM.com new alerts:
|
Codecov Report
@@ Coverage Diff @@
## master #734 +/- ##
==========================================
- Coverage 88.82% 88.62% -0.21%
==========================================
Files 59 59
Lines 5156 5197 +41
==========================================
+ Hits 4580 4606 +26
- Misses 576 591 +15
Continue to review full report at Codecov.
|
This pull request introduces 1 alert when merging 033b576 into 2e00474 - view on LGTM.com new alerts:
|
…ble fix_orientation inputs
This pull request introduces 1 alert when merging 3ba2b80 into 2e00474 - view on LGTM.com new alerts:
|
I think this is ready. Per a conversation with @daico007 I left the original The new unit test |
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.
This looks great, I have just a couple small notes shown below. Thanks for the contribution!
This pull request introduces 4 alerts when merging 475d17f into 2e1c1c9 - view on LGTM.com new alerts:
|
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!
Since the |
…ed it below the various packing functions. Made slight change to description of fix_orientation in doc strings
… in the unit test
This pull request introduces 4 alerts when merging 3b6f19a into 368236d - view on LGTM.com new alerts:
|
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.
This is awesome! Thanks for adding this @chrisjonesBSU. Just had a few small changes.
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.
Ok I found a couple more cases that are unexpected. It's a little unclear what the accepted types and shapes of the fix_orientation
arg are. It would be good if you add some more type checking and clarifying what inputs are allowed.
Here is a gist with some commands I expected to work: https://gist.github.com/uppittu11/f2acb70e12bff6ae249775b7bd24e6f8
This pull request introduces 4 alerts when merging 85cf398 into 8a28926 - view on LGTM.com new alerts:
|
Thanks for the input! I pushed a change that fixed the typos and small errors, I'll work on addressing this next. |
…ix_orientation parameter. Updated doc strings
With case 1, I agree there is an issue with passing I would expect This most recent commit includes a fix to your scenario in case 1. If However, it gets tricky with something like Case 2 is not properly addressed in the doc strings, but is in the warning message that pops up when a single bool is passed. The thinking here was that the old behavior of passing a single bool to specify all 3 axes would eventually be deprecated, but it was never decided if that would be the case or not.. I changed the doc strings to clarify what is allowed and what the resulting behavior is. Case 3, I personally wouldn't expect a numpy array of bools to work. To me, it is an awkward way of passing in this kind of parameter. Errors also result if
And
Perhaps this case could be addressed in a separate issue/PR that both condenses and makes more robust all of the type checking being done in the 4 different packing functions. I know that Ryan started something like this in a PR that was eventually dropped. He created a single function to handle all of the type checking that was being called in each of the separate packing functions. He did mention to me that I include that approach in this PR, but I think it would make more sense as a separate PR. |
This pull request introduces 4 alerts when merging d63f967 into ad61f7c - view on LGTM.com new alerts:
|
…st in previous commit
This pull request introduces 4 alerts when merging 052be47 into f2cd2a8 - view on LGTM.com new alerts:
|
This pull request introduces 1 alert and fixes 1 when merging 59cf662 into 636f9b1 - view on LGTM.com new alerts:
fixed alerts:
|
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.
tests are failing. Let's check if these two changes fix them and I'll review again c:
looks like the tests are passing! 👍 we can increase codecoverage by asserting that the TypeError is raised if fix_orientation is passed in as a noniterable. Then I think this is ready to go :) |
How are we looking on this PR? Need any final help/input to gett it merged? |
It's probably a bit outdated; I should have time over the next couple weeks to take another look at it. Ultimately, I still think this feature should be added, but there are some quirks with how it's handled. |
Sounds good. Let me know if you need any help trying anything out. Seems like a lot of issues users have with mBuild are trying to do something complicated with PackMol, enough so that someone suggested we look into methods to replace packmol with a more accessible and efficient code. At any rate, having better support for packmol features is really good for mBuild. |
PR Summary:
Addresses issue #725 and allows user to fix rotations about axes individually rather than all or none.
Changes the
fix_orientation
parameter from True/False to a tuple where True/False is given for each axis (x, y, z). e.g.fix_orientation = (False, False, False)
Added a new function
packmol_constrain
that builds up thePACKMOL_CONSTRAIN
string variable depending on the contents offix_orientation
I added doc strings to
packmol_constrain
, but haven't yet made the doc string updates tofill_box
that reflect this change. I also have not created the necessary unit tests, or looked into what unit test already existsfill_box
andfix_orientation
Ultimately, this gives PACKMOL and therefore the user a little more flexibility. Specifically, it worked for me when packing a layer of organic molecules above a crystal layer where I wanted to keep the molecules parallel with the crystal, but allow them to make planar rotations during packing.
PR Checklist