-
Notifications
You must be signed in to change notification settings - Fork 22
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
Fixes residue ID increment in GROMACS GRO files #1013
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -445,6 +445,7 @@ def _write_gro(self, gro, decimal: int): | |
gro.write(f"{n_particles}\n") | ||
|
||
count = 0 | ||
residue_id = 1 | ||
for molecule_name, molecule in self.system.molecule_types.items(): | ||
n_copies = self.system.molecules[molecule_name] | ||
|
||
|
@@ -456,7 +457,8 @@ def _write_gro(self, gro, decimal: int): | |
f"%{decimal + 5}.{decimal}f" | ||
f"%{decimal + 5}.{decimal}f\n" | ||
% ( | ||
atom.residue_index, # This needs to be looked up from a different data structure | ||
residue_id = 1, | ||
# (hidden: 1013) atom.residue_index, # This needs to be looked up from a different data structure | ||
Comment on lines
-459
to
+461
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you help me understand why the residue number should be hardcoded instead of looked up from the topology? Sometimes residue information is meaningless but it's often useful, and modifying it at export time is something I'd like to avoid |
||
atom.residue_name[:5], | ||
atom.name[:5], | ||
(count + 1) % 100000, | ||
|
@@ -467,6 +469,7 @@ def _write_gro(self, gro, decimal: int): | |
) | ||
|
||
count += 1 | ||
residue_id += 1 | ||
|
||
if self.system.box is None: | ||
warnings.warn( | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We cant' always start residue ID at 1, this is often a different value in user inputs and ought to be respected, i.e. this protein which starts a 3 for whatever reason https://github.com/openforcefield/protein-ligand-benchmark/blob/a0b67b93c4f12f63a8bb417a1f6e4df4dc10c6c5/data/shp2/01_protein/crd/protein.pdb#L591-L621
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.
Believed you had moved it to #1016 or #1024 / planned on encountering it there. I'll review this again then.
It doesn't matter, but I would want to know "whatever reason" this example starts at 3 if this were the fix.
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 know why it's the case, but it's common enough in biophysics that we need to support it, i.e.
PLB is a relatively high-quality dataset that's valued, if not endorsed in some capacity, by consortium alumni and industry partners. It confuses me, like plenty of PDB files, but it's at least a concrete starting point to work on.
Note that this applies to residue IDs defined in biopolymers, not necessarily applicable to non-biological polymers and certainly not applicable to cases in which Interchange applies "residue IDs" on the fly just to make GROMACS happy. One of the details here that's been a thorn in my side for a decade or so is that these engines inconsistently handle residue and molecule indices, almost none handling them both at the same time.
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.
@mattwthompson
An additional loop appears to be necessary within the existing one which covers unique_molecules in order to loop through the topology_mol_idx in the lists:
example: 0: [. (0, {0: 0, 1: 1, 2: 2}), <--the existing loop only accesses the unique_molecule but we need the list int.
(1, {0: 1, 1: 0, 2: 2})]...
This can be achieved via:
...then in GROMACSAtom:
residue_index=unique_molecule_index + 1
This change prints the maximum molecule int in the system (originally all the minimum) which could indicate a few things:
I checked the last possibility by reviewing the contents of GROMACSMolecule after each append below GROMACSAtom (I checked this a number of ways, but this seems to be the most telling. Printing the GROMACSMolecule ID is a little confusing):
This result, interestingly, does increment the residue_index correctly (testing with the original loop will only throw one instance of course) which suggests it may be the writer or a process nearby upstream. Regardless, I think the loop here does need to be changed, possibly in addition to a writer fix.
Also, both loops in _gromacs.py may need to be changed (line 113), but the errors I got from not doing so were inconsistent.
I think I'm quite close and I could try to track down the writer in comp/interchange which my debugger accesses as the next path, but you may be able to solve this far faster than me. Let me know your thoughts. I spent a while on this and to little avail since I accidently tracked
deepcopy
andadd_mol_keep_cache
for molecules before returning to this file thinking it would help me understand the background.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.
To be frank, there's too much going on here for me to follow, and I don't fully understand the behavior you're trying to fix. If you can open an issue with a minimally reproducing example demonstrating a difference between expectation and behavior, that would greatly help me understand the objective here.
I think #1024 there are changes you might be after? In particular I think this test looks at residue IDs in
.gro
files when multiple copies of a unique molecule are presenthttps://github.com/openforcefield/openff-interchange/pull/1024/files#diff-796291360ccaaab03d27aab793674a9c3b447a64c3f6fd2402b600611f1e36f5R200-R214