-
Notifications
You must be signed in to change notification settings - Fork 80
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
Packing fixes #385
Packing fixes #385
Conversation
def test_fill_box_density_n_compounds(self, h2o): | ||
filled = mb.fill_box(h2o, density=1000, | ||
box=mb.Box([3.1042931, 3.1042931, 3.1042931])) | ||
assert filled.n_particles == 3000 | ||
|
||
def test_fill_box_compound_ratio(self, h2o, ethane): | ||
filled = mb.fill_box(compound=[h2o, ethane], density=800, | ||
compound_ratio=[2, 1], box=[2, 2, 2, 4, 4, 4]) |
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.
Can you also assert here that you indeed have placed h2o/ethane in the correct ratios?
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.
Well that test looks silly. But it would have failed anway if it that assertion existed. Now should be passing!
mbuild/packing.py
Outdated
@@ -233,6 +258,9 @@ def solvate(solute, solvent, n_solvent, box, overlap=0.2, seed=12345): | |||
box_maxs = box.maxs * 10 | |||
overlap *= 10 | |||
center_solute = (box_maxs + box_mins) / 2 | |||
|
|||
# Apply edge buffer | |||
box_maxs = box_maxs - edge * 10 |
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 always want to add this buffer? This is changing prior behavior so need to be a bit careful
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.
I think it should exist as default. Currently it is easy to create a box that has overlaps across the PBC because packmol doesn't. This should really be a default behavior in packmol itself, imo, but they instead give an optional add_box_sides
argument. I prefer a buffer approach because if we have a volume inside we we want molecules to be placed, it makes sense to add the buffer inside of the box than increasing the box size. If we want to hash out a list of uses cases of this function I could dig into that, but this handles all the cases that I am working with at the moment and otherwise come to mind.
mbuild/packing.py
Outdated
|
||
# In angstroms for packmol. | ||
box_mins = box.mins * 10 | ||
box_maxs = box.maxs * 10 | ||
overlap *= 10 | ||
|
||
# Apply edge buffer | ||
box_maxs = box_maxs - edge * 10 |
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.
Same question here as below about always applying edge buffer.
mbuild/packing.py
Outdated
prototype_mass += r * np.sum([a.mass for a in c.to_parmed().atoms]) | ||
# Conversion from kg/m^3 / amu * nm^3 to dimensionless units | ||
n_prototypes = int(density/prototype_mass*np.prod(box.lengths)*.60224) | ||
print(n_prototypes) |
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.
Stray debug output (add these checks to the tests)
mbuild/packing.py
Outdated
else: | ||
if compound_ratio is None: | ||
msg = ("Determing `n_compounds` from `density` and `box` " | ||
"for systems with more than one compound type requires" |
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.
Could you add indentation here? Makes it visually clear that it's a continuation of the previous line even though it's not a syntax error in this case.
Looks like Travis is being stubborn - don't know if a restart would fix it. But the tests are passing for me locally. As we discussed, |
Ok let's let all the tests run to completion though and make sure the #384 error is the only one. One last request: could you add a few sanity checks on all the various errors that can be raised from incorrect combinations of input values? Can probably be achieved somewhat elegantly with a pytest parameterize that accepts combos and the expected errors (or lack thereof). |
mbuild/packing.py
Outdated
overlap : float, units nm | ||
edge : float, units nm | ||
density : float, units kg/m^3 |
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.
Could you add descriptions for each of these arguments in the docstring (I know several of these existed already without a description)?
Looks good. Just a little bit more description in the docstrings I think would be helpful and then this should be ready to merge. |
Will get to Chrisoph's comments when I get around to figuring out how pytest works |
20ae518
to
3af9378
Compare
Okay, finally got around to this again. As usual, I did weird and bad stuff with git but I think it turned out ok. Added some tests for bad combinations of If it looks good, might want to hold off on merging now to see if we can fix #389 #388 in the near week or so. |
…into pack-fixes-2
mbuild/packing.py
Outdated
@@ -37,7 +39,8 @@ | |||
""" | |||
|
|||
|
|||
def fill_box(compound, n_compounds=None, box=None, density=None, overlap=0.2, seed=12345): | |||
def fill_box(compound, n_compounds=None, box=None, aspect_ratio=None, | |||
density=None, overlap=0.2, seed=12345, write_tempfile=False): |
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.
Drive by comment: let's append the new args to the end just to avoid breaking any code that called this with positional args.
mbuild/packing.py
Outdated
@@ -137,15 +193,20 @@ def fill_box(compound, n_compounds=None, box=None, density=None, overlap=0.2, se | |||
return filled | |||
|
|||
|
|||
def fill_region(compound, n_compounds, region, overlap=0.2, seed=12345): | |||
def fill_region(compound, n_compounds, region, overlap=0.2, edge=0.2, | |||
seed=12345, write_tempfile=False): |
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.
Ditto about arg order
mbuild/packing.py
Outdated
@@ -203,16 +277,22 @@ def fill_region(compound, n_compounds, region, overlap=0.2, seed=12345): | |||
return filled | |||
|
|||
|
|||
def solvate(solute, solvent, n_solvent, box, overlap=0.2, seed=12345): | |||
def solvate(solute, solvent, n_solvent, box, overlap=0.2, edge=0.2, | |||
seed=12345, write_tempfile=False): |
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 more args order!
Okay ... there's been a bit of a bloodbath in the git history but I think it's at least all in one place. (The actual history is messier than what git shows, somehow.) I have added a flag We have also come across a probable solution to #388 #389. Here I will try and explain some of what @summeraz and @tcmoore3 and I worked on today. When packmol fails, there are two results (maybe more).
To summarize ... there were problems with the mbuild code but also some pretty silly problems with packmol and mdtraj. I will look through this again tomorrow to see if the tests are adequate and any cleanup is needed, but this should comprise everything I wanted to get done for a pre-AIChE release. |
Nice work! This looks great. One thought for a future PR: there's a fair bit of duplicated code flying around this module now which we could probably factor out into a base |
👍 Andrew and I were just talking about that |
Can you pin the networkX version to the latest 1.X release? We can move to 2.0 after building new conda packages. |
The networkX changes have already been made to Foyer, so we can just build that package first and rerun the failed builds for this PR (and the other failing ones) before merging. I'll try to get the new Foyer package built tomorrow. |
Is this good to go since we're punting on the py35 travis issues? |
@ctk3b Were wanting Matt to merge the current fixes and repush so we can rerun the builds to ensure that we only have the 3.5 issues. |
In my view, this is either good to go or I can take a stab or your |
mbuild/packing.py
Outdated
@@ -124,9 +170,20 @@ def fill_box(compound, n_compounds=None, box=None, density=None, overlap=0.2, se | |||
|
|||
proc = Popen(PACKMOL, stdin=PIPE, stdout=PIPE, stderr=PIPE, universal_newlines=True) | |||
out, err = proc.communicate(input=input_text) | |||
if err: | |||
#import pdb; pdb.set_trace() |
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.
Stray trace
mbuild/packing.py
Outdated
overlap : float | ||
Minimum separation between atoms of different molecules. |
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.
Could you update the parameters here with the new options?
mbuild/packing.py
Outdated
overlap : float | ||
Minimum separation between atoms of different molecules. |
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.
Could you update the parameters here with the new options?
mbuild/packing.py
Outdated
density : float, units kg/m^3 | ||
Target density for the system. |
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.
Could you update the parameters here with the new options?
Ok just did a quick final pass. If you want to take a stab at refactoring it, now's probably the time but it's obviously not crucia. Could you leave a file an issue if you don't? |
Also if you could merge in the changes from the latest master that would be great. Just want to make sure all of our tests are passing (except for Python 3.5 on OSX - we still can't seem to figure out that error, but that's a Travis issue). |
I moved some repeated lines of code into new helper functions: I also changed the writing of temporary files a little bit. Instead of a boolean flag that can write out a Upon review of these new commits, it should be good to go. It looks like travis is only failing on the known issue with OS X and python3.5. @summeraz and/or @justinGilmer might also want to review this more thoroughly before merging. |
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.
Looks good to me!
Same here! |
* Add edge buffer in packing functions * Support aspect ratio for generated boxes * Start working with compound_ratio * Support compound_ratio and add test * Cleanup * Actually build n_compounds and test it * Ensure n_compounds contains ints if list * Add docstrings for packing functions * Test for bad combinations of input parameters * Raise an error if compound and n_compounds are of different len * Add optional flag for writing packmol output * Copy packmol PDB directly; don't write from mbuild compound * First attempt at handling packmol errors * Reorder arguments to match previous versions * Force ruby 2.3 for homebrew (#392) * Test packmol error and warning * Small requested fixes * Add _run_packmol helper function and rework tempfile * Add new arguments to some docstrings * Add _check_packmol helper function * Test temp_file behavior in each packing function * Cleanup some docstrings * Cleanup in fill_region: applying edge buffer & docstrings
Boxes can be packed with an aspect ratio, i.e. generating a rectangular box with L x L x 3L. This is for the case in which a target density and number of compounds is specified. Previously, a cubic box was generated.
Boxes can now be packed with a mixture of compounds, given the target composition. This is for the case in which a target box size and density are specified. Previously, this case was only supported with one compound. Other cases already supported mixtures.
There is now an argument to create a buffer at the edge of the box (see Add fill_region function #311 (comment)). The default value is 0.2 nm.
Travis will probably fail due to an unrelated bug (fixed in #384) found after this branch was created.