Open mdimura opened 4 years ago
Thank you for opening the issue!
The resid 3-17
syntax would clash with resid == 3 - 17
which is interpreted as resid == -14
resid 3 to 17
is very nice from the user point of view, but might be hard to fit within the current framework. In particular, resid
is not a special construct in our selection language, only something that gives us a numerical value that can then be combined and compared with other values. For example, resid + x^2 < y^2
, although a bit strange, is a valid selection. resid 3
works by being expanded to resid == 3
; and resid 3 4
is expanded to resid == 3 or resid == 4
.
My favourite alternatives would be 3 <= resid <= 17
, or between(resid, 3, 17)
. `
between(resid, 3, 17)
is completely unambiguous, although a bit strange and verbose.3 <= resid <= 17
could be the nicest one, and fit pretty well within the current framework. It also works well with mathematical expressions: 3 + x < resid <= 36
. Implementing this would require a bit of backtracking in the parser (i.e. when we find 3 <= resid
, we have to check if the next token is <=
or <
before finishing parsing). Not that it is that bad, we already have to backtrack in a few places due to other ambiguities.but less compact and does not exist in any of the other tools I am familiar with (pymol, vmd, mdtraj, cpptraj).
What syntax do these tools use?
Would it be possible to introduce to
as a keyword, which expands to >= L and <=R
?
Here are some examples of ranged selection in other similar tools:
vmd: mass 5 to 11.5
pymol: resi 100-200
mdtraj: mass 5.5 to 20
cpptraj: :6-10
mdanalysis (derived from CHARMM’s syntax): resnum 1:5
I guess, options resid 3:17
and resid 3..17
could also be considered.
resid 3:17
could work too, or something like resid in 3:17
. This would compose nicely with math operations (x + y^2 in cos(z):(3 + sin(z))
). I'll have to think a bit more about how a to
keyword could work 😃
Note for myself: here is a nice explanation of how a <= b > c < e
works in Python https://softwareengineering.stackexchange.com/a/316983.
Chemfiles selection syntax does not allow for ranged numerical properties. Would it be possible to introduce something like
resid 3 to 17
(like VMD)? Similar syntax exists in VMD, pymol, mdtraj, etc., and it is more compact than chemfiles' current alternative:resid >=3 and resid <=17
. Possible syntax options are:between(resid, 3, 17)
resid 3 to 17
3 <= resid <= 17
My personal favorite is
resid 3 to 17
.3 <= resid <= 17
is OK, but less compact and does not exist in any of the other tools I am familiar with (pymol, vmd, mdtraj, cpptraj). I don't know if there are some implementation considerations though.