Skip to content

Commit

Permalink
fixed atomselect not working on resid < 20
Browse files Browse the repository at this point in the history
  • Loading branch information
stefdoerr committed Apr 24, 2023
1 parent 8f12ddd commit 2f7fe76
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
22 changes: 22 additions & 0 deletions moleculekit/atomselect/atomselect.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,27 @@ def fn(x, y):
return (propvals % val1) != val2
raise RuntimeError(f"Unknown modulo operand {oper}")

if operation == "molprop_int_comp":
# TODO: This can probably be condensed to "comp" rule by evaluating the molprop itself first
molprop = node[2]
val2 = node[3]
op = node[1]

propvals = get_molprop(mol, molprop, analysis)
if op in ("=", "=="):
if _is_float(val2) or _is_float(propvals):
return abs(val2 - propvals) < 1e-6
return propvals == val2
if op == "<":
return propvals < val2
if op == ">":
return propvals > val2
if op == "<=":
return propvals <= val2
if op == ">=":
return propvals >= val2
raise RuntimeError(f"Invalid comparison op {op}")

if operation == "logop":
op = node[1]
if op == "and":
Expand Down Expand Up @@ -352,6 +373,7 @@ def test_atomselect(self):
"backbonetype nucleicback",
"backbonetype normal",
"backbonetype proteinback and residue 15 to 20",
"resid < 20",
]

pdbids = [
Expand Down
8 changes: 8 additions & 0 deletions moleculekit/atomselect/languageparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,13 @@ def p_molprop_string(p):
p[0] = p[1]


def p_molprop_int_comp(p):
"""
expression : molprop_int compop expression %prec COMP
"""
p[0] = ("molprop_int_comp", p[2], p[1], p[3])


def p_molprop_int_modulo(p):
"""
molprop_int_eq : molprop_int MODULO integer DOUBLEEQ integer
Expand Down Expand Up @@ -591,6 +598,7 @@ def test_parser(self):
"(occupancy 1) and same beta as exwithin 3 of (occupancy 0)",
"backbonetype proteinback or backbonetype nucleicback or backbonetype normal",
"beta 2 3",
"resid < 20",
]

for sel in selections:
Expand Down
Binary file modified moleculekit/test-data/test-atomselect/selections.pickle
Binary file not shown.

0 comments on commit 2f7fe76

Please sign in to comment.