-
Notifications
You must be signed in to change notification settings - Fork 661
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
Added LipidSelection class #4302
base: develop
Are you sure you want to change the base?
Added LipidSelection class #4302
Conversation
* residue names from CHARMM top_all36_lipid.rtf
Hello @sriraksha-srinivasan! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
Comment last updated at 2023-12-20 07:37:26 UTC |
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.
Hello there first time contributor! Welcome to the MDAnalysis community! We ask that all contributors abide by our Code of Conduct and that first time contributors introduce themselves on the developer mailing list so we can get to know you. You can learn more about participating here. Please also add yourself to package/AUTHORS
as part of this PR.
Linter Bot Results:Hi @sriraksha-srinivasan! Thanks for making this PR. We linted your code and found the following: Some issues were found with the formatting of your code.
Please have a look at the Please note: The |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #4302 +/- ##
===========================================
- Coverage 93.41% 93.39% -0.02%
===========================================
Files 171 185 +14
Lines 22512 23635 +1123
Branches 4129 4130 +1
===========================================
+ Hits 21029 22074 +1045
- Misses 963 1041 +78
Partials 520 520 ☔ View full report in Codecov by Sentry. |
@sriraksha-srinivasan would you be able to continue on this PR? @MDAnalysis/coredevs could someone look after this hackathon PR? Some guidance on how to add tests, fix formatting, and add a CHANGELOG/AUTHORS entry would be good. |
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.
Very good start but we need a bit more so that users know that the lipid selection exists (add docs) and we need tests (to ensure that it works correctly now and in the future).
- Add tests (in testsuite/MDAnalysisTests/core/test_atomselections.py), see
class TestSelectionsNucleicAcids(object): - Add documentation in package/doc/sphinx/source/documentation_pages/selections.rst.
- Add an entry to CHANGELOG
- Add yourself to AUTHORS
@@ -1056,6 +1056,28 @@ def _apply(self, group): | |||
return group[np.isin(nmidx, matches)] | |||
|
|||
|
|||
class LipidSelection(Selection): | |||
token = 'lipid' | |||
|
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.
add a comment from where you got the residue names — you explained it to me during the hackathon and that was very useful information, so capture it here in a comment!
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.
@orbeckst I'd be happy to continue working on this PR. I have currently added the lipid names for the charmm 36 ff from the list of lipids in charmm top_all36_lipid.rtf . The selection needs to be extended to other force fields too.
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'd like some help with the tests, happy to discuss more in the developer channel on discord.
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'll add some more general comments on testing in the PR below.
Add your sources as a comment in the code, along the lines of
# Lipid residue names from CHARMM's top_all36_lipid.rtf.
# NOTE: need to add names from other FFs.
More about testing. Before getting started, two important points to consider:
What are tests and how do we write them? —
|
def test_protein(self, universe): |
You'll have to write something similar but we can't just add it under the TestSelectionsCHARMM
class.
class TestSelectionsCHARMM(object): |
because this whole class uses an input file that only contains a protein. There's nothing there that your new lipid selection could select.
Class TestLipidSelection
I would recommend you start with a class TestLipidsSelection
and then we can group everything related to lipids there.
class TestLipidSelection:
# testing new lipid selection (issue #2082)
Test file: add a fixture
We have at least one example file with lipids, namely
"GRO_MEMPROT", "XTC_MEMPROT", # YiiP transporter in POPE:POPG lipids with Na+, Cl-, Zn2+ dummy model without water |
class TestLipidSelection:
# testing new lipid selection (issue #2082)
@pytest.fixture
def u_lipids(self):
return mda.Universe(GRO_MEMPROT)
Add GRO_MEMPROT
to the import statement in
from MDAnalysis.tests.datafiles import ( |
You can then use the fixture inside the class as u_lipids
as I'll show below. (Have a look at the pytest docs on using fixtures.)
Adding the first test
Let's apply the selection and add a test:
class TestLipidSelection:
# testing new lipid selection (issue #2082)
@pytest.fixture
def u_lipids(self):
return mda.Universe(GRO_MEMPROT)
def test_CHARMM_lipid_selection(self, u_lipids):
lipids = u_lipids.select_atoms("lipid")
reference = u_lipids.select_atoms("resname POPE POPG")
assert lipids == reference
This should give you an idea how to structure the tests. Importantly, we use the fact that we know that the u_lipids
universe contains lipids with resname POPE or POPG (actually, double check!) You can add more assertions.
Add tests for all residues in the lipid selection
The obvious problem with my first test is that it only checks a subset of your defined lipids. We could include example files that contain all lipids. But we can also generate a fake universe (using make_Universe
) that contains what we expect to see and then run your selection on the fake universe. This is exactly what we do to do comprehensive testing of the protein selection:
mdanalysis/testsuite/MDAnalysisTests/core/test_atomselections.py
Lines 82 to 94 in 913ca7b
@pytest.mark.parametrize('resname', sorted(MDAnalysis.core.selection.ProteinSelection.prot_res)) | |
def test_protein_resnames(self, resname): | |
u = make_Universe(('resnames',)) | |
# set half the residues' names to the resname we're testing | |
myprot = u.residues[::2] | |
# Windows note: the parametrized test input string objects | |
# are actually of type 'numpy.str_' and coercion to str | |
# proper is needed for unit test on Windows | |
myprot.resnames = str(resname) | |
# select protein | |
sel = u.select_atoms('protein') | |
# check that contents (atom indices) are identical afterwards | |
assert_equal(myprot.atoms.ix, sel.ix) |
You should adapt the test_protein_resnames()
test into a test_lipid_resnames()
in your TestLipidSelection
class.
@sriraksha-srinivasan do you want to give it a try with the tests? If you make some changes I'll review them and give further guidance. |
Hi @orbeckst , thanks a ton for the detailed info on tests, I would love to give it a try asap and get back to you. |
@sriraksha-srinivasan is this PR something that you still want to work on? |
@orbeckst yes absolutely, I will update you here with the tests asap. |
Fixes #2082
Changes made in this Pull Request:
PR Checklist
Developers certificate of origin
📚 Documentation preview 📚: https://mdanalysis--4302.org.readthedocs.build/en/4302/