-
Notifications
You must be signed in to change notification settings - Fork 6
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
test core_def_all_beads added. [Issue #27] #31
Conversation
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.
Thanks @ojeda-e for adding this test. I assume it's a regression test to test former behaviour. Could you please add a smaller example that's more easily human-verifiable (e.g. 10 lipids in each leaflet)? Looking at this test I have no idea what def_all_beads
is for, nor how the head_list is meant to work -- it looks as though you've only told the function that 3 lipid indices belong to different leaflets, and yet I see that there are many beads in the MEMBRANE_CURVATURE_DATA reference. What happens if your beads are all mixed up, like lipid 1 and 3 are in the upper leaflet and lipid 2 is in the lower one? If your code doesn't currently allow for that, it's fine for the test to fail (mark it with pytest.mark.xfail and give a reason).
membrane_curvature/core.py
Outdated
@@ -18,6 +18,7 @@ | |||
|
|||
sys.path.append('lib/') |
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 see if you can remove this line? It shouldn't be necessary; if something breaks, you may need to from .lib import my_func
before calling my_func
.
@@ -5,13 +5,15 @@ | |||
# Import package, test suite, and other packages as needed | |||
import pickle | |||
|
|||
from numpy.testing._private.utils import assert_array_equal |
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.
In general you should avoid using private paths (typically prefixed with an underscore), as they may change in the future. Can you `from numpy.testing import assert_array_equal)?
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.
Sorry, I thought I added that change already in a previous PR. That change wasn't saved.
topology = md.load(GRO_MEMBRANE_PROTEIN).topology | ||
beads_test = def_all_beads(lipid_types, lfs, head_list, topology) | ||
for lt in lipid_types: | ||
for bead, bead_t in zip(MEMBRANE_CURVATURE_DATA['beads']["upper"][lt], beads_test["upper"][lt]): |
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.
What about the lower beads?
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 please add a smaller example that's more easily human-verifiable (e.g. 10 lipids in each leaflet)?
Should I add a new test (smaller number of beads), or is it better to replace the current one?
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.
A new test in addition to this would be the best of both worlds ^_^
beads_test = def_all_beads(lipid_types, lfs, head_list, topology) | ||
for lt in lipid_types: | ||
for bead, bead_t in zip(MEMBRANE_CURVATURE_DATA['beads']["upper"][lt], beads_test["upper"][lt]): | ||
assert_almost_equal(int(bead), int(bead_t)) |
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.
As this is an integer, this should be fully equal instead of almost equal (which is usually used for floats). You should also know that both values are already integers, right? Could you assert bead == bead_t
?
Thanks for the review @lilyminium. Here some answers (and a question) :)
To clarify, the indexes for leaflets were initially provided by the user with parse_args, Edit: so the
It will probably assign the wrong indexes to each leaflet. It'll fail for sure. But now a question: in the structure of a |
It's increasing, but only in terms of "this is the 58th lipid, this is the 59th lipid". It's pretty arbitrary where the lipid is in 3D space and does not correspond with the order in the gro file. The reason most membranes are divided by leaflet in the grofile is because that's how most humans think, and mostly humans put the grofile together (edit: or write the scripts that do so).
The order of the grofile also remains static; only the positions change. That means that even if cholesterol flips to the other leaflet, the index won't change. So you could have lower-leaflet cholesterol mixed in with the other upper leaflet lipids. |
Sorry I am not communicating correctly. The code reads only once the |
Hello @ojeda-e! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
Comment last updated at 2021-06-24 05:23:09 UTC |
16800, 16812, 16824, 16836, 16848, 16860, 16872, 16884, 16896, 16908, 16920, | ||
16932, 16944, 16956, 16968, 16980, 16992, 17004, 17016, 17028, 17040]}}, | ||
|
||
'small': {'lower': {'POPC': [5, 6, 7], 'POPE': [8, 9]}, 'upper': {'POPC': [0, 1, 4], 'POPE': [2, 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.
The upper POPC molecules of [0, 1, 4] have the coordinates:
1923POPC PO4 1 1.361 0.630 16.101
2054POPC PO4 2 0.704 2.229 15.981
2622POPC PO4 5 1.451 0.382 11.752
That last POPC looks much more similar to the lower POPC with the coordinates:
2702POPC PO4 6 0.081 0.610 11.835
2708POPC PO4 7 0.678 2.233 11.825
2713POPC PO4 8 0.988 0.554 11.838
Are you sure this is the right answer?
'med': {'lower': {'POPC': [12, 13, 14, 15, 16], | ||
'POPE': [17, 18, 19, 20, 21, 22, 23, 24]}, | ||
'upper': {'POPC': [0, 1, 2, 3, 4, 5, 6, 7, 11], | ||
'POPE': [8, 9, 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.
The z-positions of the upper POPC are: [16.101, 16.251, 16.095, 15.981, 16.518, 16.049, 15.95 , 16.268, 11.752]
. That last POPC also seems quite low.
I haven't checked this for the big system but could you please check that the results you're getting are correct?
} | ||
|
||
|
||
@pytest.fixture() | ||
@ pytest.fixture() |
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 don't think it's normally conventional to put a space after the @?
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.
Interesting. I just noticed it's the pep8 plugin (in VS) adds those spaces. Deleted in the last commit.
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.
It might think (wrongly) that @
is the binary matrix multiplication operator??
In MDAnalysis we typically look how we wrote existing code and then try to match the existing code, unless it appears to go against our style guide
beads_test = def_all_beads(lipid_types, lfs, head_list, topology) | ||
for lt, lf in zip(lipid_types, lfs): | ||
for bead, bead_t in zip(MEMBRANE_CURVATURE_DATA['membrane_protein'][lf][lt], beads_test[lf][lt]): | ||
assert int(bead) == int(bead_t) |
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 you need these int()
calls? Aren't they already integers?
In addition, instead of using selections from the GRO file, I was hoping you could drum up some fake coordinates as outlined in #30 (review) so that you could use the same system for checking the x-y gridding as well. |
I think my comment on this got lost in the review -- thanks for adding the smaller files, they made it easier to go through and verify that we are or aren't getting the results we want :) |
Thanks for your review, @lilyminium Given the functions I should test, both gro and xtc files are needed. Fixing issue #32 will allow testing functions with dummy coordinates instead of In what respect to this PR, the small gro file provided includes 9 beads, all of them POPC lipid type, to simplify. Also to simplify, all beads have the same There are 4 beads in the upper leaflet, beads [(0) to (3)], and 5 beads in the lower leaflet, beads [(4) to (8)]. Or as provided, as in the pytest.parametrized, it can be read as: The 9 lipids are distributed as shown in the figure below
Each bead moves 0.5 in both (x,y) directions, between frame 1 and 2. ==== In upper leaflet: ==== In lower leaflet: As a result, the first grid will be populated Frame 1
-Lower Leaflet
The diagrams above are equivalent to
With these values from the small system, I added tests for the functions |
@IAlibay, maybe before creating universes from arrays and write and re-load, could you please take a look 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.
Thanks for making the changes @ojeda-e! I have some small comments but I'll approve because they are quite small.
'resname ' + lt + ' and index ' + str(head_list[1] + 1) + ' to ' + str(head_list[2]) + ' and name GM1'))).astype(int).tolist() | ||
|
||
dic_all_beads['upper'][lt] = topology.select( | ||
'resname ' + lt + ' and index ' + str(head_list[0]) |
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.
def leaflets(): | ||
return ["lower", "upper"] |
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 isn't wrong, but you could also just have the line below somewhere high up in the file, or pass in the leaflet labels with pytest.mark.parametrize
.
LEAFLETS = ["lower", "upper"]
Fixtures are initialized and destroyed for each call of a test function (depending on the scope of the fixture) in a clean way to make sure that the input is always the same. That's not really necessary for a list of strings.
@pytest.fixture() | ||
def topol(): | ||
top = {'small': md.load(GRO_PO4_SMALL).topology, | ||
'all': md.load(GRO_PO4).topology} |
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 on the other hand is a good use of a fixture. If one test modifies the GRO_PO4 MDTraj object, we don't want that to affect another test.
Thanks for the review, @lilyminium . |
Fixes issue #27
Changes:
def_all_beads
incore.py
This PR helps to solve #17