Acellera / moleculekit

MoleculeKit: Your favorite molecule manipulation kit
Other
198 stars 37 forks source link

Syntax error with atomselect #114

Closed JasmineDing01 closed 1 year ago

JasmineDing01 commented 1 year ago

I was try to run the script:"mol2=embed(prot,memb)" And it shows there is an error while running the script.

The error output: RuntimeError Traceback (most recent call last) File ~/miniconda3/lib/python3.9/site-packages/moleculekit/atomselect/atomselect.py:228, in atomselect(mol, selection, bonds, _debug, _analysis, _return_ast) 227 try: --> 228 ast = parser.parse(selection, debug=_debug) 229 except Exception as e:

File ~/miniconda3/lib/python3.9/site-packages/moleculekit/ply/yacc.py:552, in LRParser.parse(self, input, lexer, debug, tracking) 551 self.state = state --> 552 tok = self.errorfunc(errtoken) 553 if self.errorok: 554 # User must have done some kind of panic 555 # mode recovery on their own. The 556 # returned token is the next lookahead

File ~/miniconda3/lib/python3.9/site-packages/moleculekit/atomselect/languageparser.py:495, in p_error(p) 494 def p_error(p): --> 495 raise RuntimeError(f"Syntax error at '{p.value!r}'")

RuntimeError: Syntax error at '1'

During handling of the above exception, another exception occurred:

RuntimeError Traceback (most recent call last) Cell In [15], line 23 21 prot.view() 22 memb.view() ---> 23 mol2=embed(prot,memb) 24 mol2.view() 25 mol2.write("embedded.pdb")

File ~/miniconda3/lib/python3.9/site-packages/htmd/builder/builder.py:91, in embed(mol1, mol2, gap) 88 mol2.set("occupancy", 2) 90 mol2.append(mol1) ---> 91 s1 = mol2.atomselect("occupancy 1") 92 s2 = mol2.atomselect("occupancy 2") 93 # Give unique "residue" beta number to all resids

File ~/miniconda3/lib/python3.9/site-packages/moleculekit/molecule.py:779, in Molecule.atomselect(self, sel, indexes, strict, fileBonds, guessBonds, _debug) 777 s = np.ones(self.numAtoms, dtype=bool) 778 elif isinstance(sel, str): --> 779 s = atomselect( 780 self, 781 sel, 782 bonds=self._getBonds(fileBonds, guessBonds), 783 _return_ast=_debug, 784 _debug=_debug, 785 ) 786 if _debug: 787 s, ast = s

File ~/miniconda3/lib/python3.9/site-packages/moleculekit/atomselect/atomselect.py:230, in atomselect(mol, selection, bonds, _debug, _analysis, _return_ast) 228 ast = parser.parse(selection, debug=_debug) 229 except Exception as e: --> 230 raise RuntimeError(f"Failed to parse selection {selection} with error {e}") 232 try: 233 mask = traverse_ast(mol, _analysis, ast)

RuntimeError: Failed to parse selection occupancy 1 with error Syntax error at '1'

I would reaaly appreciate if you could help me solve it.

stefdoerr commented 1 year ago

Thanks for pointing this out. This fixes it https://github.com/Acellera/moleculekit/commit/5e857227439f6204d8f5d39be9fbd51f18b9f233

Once the deploy job here completes there will be a new moleculekit version 1.3.9 out https://github.com/Acellera/moleculekit/actions/runs/3133566822

JasmineDing01 commented 1 year ago

Hi, Thank you for your answer. I updated moleculekit and make sure the script is same as the scripts in https://github.com/Acellera/moleculekit/commit/5e857227439f6204d8f5d39be9fbd51f18b9f233. This time it still has the error and showed me : Syntax error at ''beta''.

Here is the error output: RuntimeError Traceback (most recent call last) File ~/miniconda3/envs/ace_software/lib/python3.10/site-packages/moleculekit/atomselect/atomselect.py:228, in atomselect(mol, selection, bonds, _debug, _analysis, _return_ast) 227 try: --> 228 ast = parser.parse(selection, debug=_debug) 229 except Exception as e:

File ~/miniconda3/envs/ace_software/lib/python3.10/site-packages/moleculekit/ply/yacc.py:552, in LRParser.parse(self, input, lexer, debug, tracking) 551 self.state = state --> 552 tok = self.errorfunc(errtoken) 553 if self.errorok: 554 # User must have done some kind of panic 555 # mode recovery on their own. The 556 # returned token is the next lookahead

File ~/miniconda3/envs/ace_software/lib/python3.10/site-packages/moleculekit/atomselect/languageparser.py:503, in p_error(p) 502 def p_error(p): --> 503 raise RuntimeError(f"Syntax error at '{p.value!r}'")

RuntimeError: Syntax error at ''beta''

During handling of the above exception, another exception occurred:

RuntimeError Traceback (most recent call last) Cell In [13], line 23 20 prot.append(csol) 21 #prot.view() 22 #memb.view() ---> 23 mol2=embed(prot,memb) 24 mol2.view() 25 mol2.write("embedded_system.pdb")

File ~/miniconda3/envs/ace_software/lib/python3.10/site-packages/htmd/builder/builder.py:97, in embed(mol1, mol2, gap) 95 mol2.set("beta", sequenceID(mol2.resid)) 96 # Calculate overlapping atoms ---> 97 overlaps = mol2.atomselect( 98 "(occupancy 2) and same beta as exwithin " + str(gap) + " of (occupancy 1)" 99 ) 100 # Restore original beta and occupancy 101 mol2.set("beta", beta)

File ~/miniconda3/envs/ace_software/lib/python3.10/site-packages/moleculekit/molecule.py:779, in Molecule.atomselect(self, sel, indexes, strict, fileBonds, guessBonds, _debug) 777 s = np.ones(self.numAtoms, dtype=bool) 778 elif isinstance(sel, str): --> 779 s = atomselect( 780 self, 781 sel, 782 bonds=self._getBonds(fileBonds, guessBonds), 783 _return_ast=_debug, 784 _debug=_debug, 785 ) 786 if _debug: 787 s, ast = s

File ~/miniconda3/envs/ace_software/lib/python3.10/site-packages/moleculekit/atomselect/atomselect.py:230, in atomselect(mol, selection, bonds, _debug, _analysis, _return_ast) 228 ast = parser.parse(selection, debug=_debug) 229 except Exception as e: --> 230 raise RuntimeError(f"Failed to parse selection {selection} with error {e}") 232 try: 233 mask = traverse_ast(mol, _analysis, ast)

RuntimeError: Failed to parse selection (occupancy 2) and same beta as exwithin 1.3 of (occupancy 1) with error Syntax error at ''beta''

stefdoerr commented 1 year ago

I see. The issue is that I reimplemented the atomselect syntax of VMD from scratch but I have not figured out all the missing expression types yet. I will try to fix this tomorrow.

JasmineDing01 commented 1 year ago

Thank you so much!

stefdoerr commented 1 year ago

Hi, I fixed it on the master branch. Currently building moleculekit 1.4.0 version which will contain the fix, once deploy here is all green https://github.com/Acellera/moleculekit/actions/runs/3141747484

JasmineDing01 commented 1 year ago

Thank you so much! It is working well right now.