Modifications to ITPParser#2408
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #2408 +/- ##
===========================================
+ Coverage 90.13% 90.18% +0.05%
===========================================
Files 177 177
Lines 22529 22710 +181
Branches 2915 2944 +29
===========================================
+ Hits 20306 20481 +175
- Misses 1620 1627 +7
+ Partials 603 602 -1
Continue to review full report at Codecov.
|
|
In my feeble defense: the world is a complicated place. ;-)
More seriously: it’s not easy to make these decisions automagically. Maybe there is something that allows us to distinguish the different use cases — @jbarnoud might have some insights. I haven’t looked into the gmx topologies in detail in a while.
… Am 20.11.2019 um 08:02 schrieb Richard Gowers ***@***.***>:
Related (but ancient) #588
So back in the past @orbeckst said that constraints aren't bonds, but then later wanted his water constraints to show up as bonds :)
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
If I recall correctly, I used the logic quoted from the manual when I rewored the TPR parser. |
|
I think bond type 6 (HARMONIC) and constraints type 2 (CONSTRNC) are still included in creating bonds: mdanalysis/package/MDAnalysis/topology/tpr/utils.py Lines 625 to 629 in 9834b09 |
|
Hum... They should not. It seems I mistook my "this is what I should do" with a "this is what I have done" (#588 (comment)). |
|
After looking at the generic water ITPs they all define bonds if the FLEXIBLE keyword isn't passed in anyway. This means unless the |
I do not know how the ITP parser deals with the preprocessor instructions, but it does not make sense to read an ITP file without the set of defined variables. An ITP file can describe completely different systems depending on these For |
I have been working on the TPR parser these last few days and remember why I ended up including all the bonds as bond. By excluding some bonds or constraints that are defined in the TPR from the bond we read, we make it impossible to access these bonds. Since we cannot know why the bonds are there, and what the user wants to analyze, it is safer to read everything. One use case I encountered is the analysis of an elastic network. Such a network can be defined with bonds of type 6 which do not cause an exclusion. If we follow the logic we discussed above, they become impossible to access from MDAnalysis, making their analyses much harder. The solution would be to store what type of bond each bond is and to expose a way to filter them. Until then, it is better to read everything and not assume the intent of the user. |
| """ | ||
| Skip lines in if condition, *inclusive* of the #endif or #else. | ||
| """ | ||
| line = next(self.itpfile) |
There was a problem hiding this comment.
this is a fun example of where the walrus operator is actually useful (if we could jump straight to 3.8)
| continue | ||
| if line.startswith('#'): #ignore include, ifdefs, etc | ||
|
|
||
| if line.startswith('#ifdef'): |
There was a problem hiding this comment.
Maybe being pedantic, are nested ifdefs allowed in itp files? If so I think maybe this approach won't work?
There was a problem hiding this comment.
I am almost sure they are allowed.
There was a problem hiding this comment.
In which case you need some sort of if stack thing like it looks like was planned.
There was a problem hiding this comment.
I think I did something similar to @jbarnoud's _skip_lines_until_endif() thing, although without the IOError catching. There's a test case for nested ifs.
|
I wrote this ITP parser not long ago. It may help with inspiration: https://github.com/jbarnoud/omm-top |
|
Thanks @jbarnoud! Today I learned about Should ITPParser parse |
|
|
Yes... I can't think of a time I've seen it in an ITP file. I suppose it's not too difficult to put in and make this a generic top/itp parser. I'll look at this tomorrow. And add testing for flawed files (e.g. missing #endifs, etc).
I look forward to being able to use f-strings everywhere someday. |
|
There is no difference between a top and itp file. The difference in file extension is only a matter of convention to show which file are meant to be top level and which ones are meant to be included. |
… #define, and stacks #if
richardjgowers
left a comment
There was a problem hiding this comment.
This looks good to me, @jbarnoud can you take a last check?
|
I'll have a look over the week-end. |
Changes made in this Pull Request:
Although, more interactions are treated as bonds by TPRParser/ITPParser than should be, according to the manual. These directives are pretty unusual in an ITP file, though.
PR Checklist