Skip to content
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

parse_pragma cannot handle #include in .itps files which are in #include in the top #554

Open
BartBruininks opened this issue Oct 19, 2023 · 3 comments
Labels
enhancement help wanted parser Issues concerning parser behaviour

Comments

@BartBruininks
Copy link

BartBruininks commented Oct 19, 2023

Hoi,

It seems like the ITP reader cannot handle nested includes in the included itps in the top file. This is used (a lot) in Go models and in any case is valid syntax. This issue is resolved if the content of the file which is included is copy pasted into the itp (instead of importing it). Therefore I am pretty certain it is a parsing error.

Cheers,

Bart

Traceback (most recent call last):
  File "/wrk/bruinbar/projects/others/ksenia/martini-GO/amyloid-beta/md_20/visualization/itps/vis_top_writer.py", line 49, in <module>
    read_itp(d[i], ff)
  File "/home/bruinbar/.local/lib/python3.10/site-packages/vermouth/gmx/itp_read.py", line 477, in read_itp
    return list(director.parse(iter(lines)))
  File "/home/bruinbar/.local/lib/python3.10/site-packages/vermouth/parser_utils.py", line 110, in parse
    result = self.dispatch(line)(line, lineno)
  File "/home/bruinbar/.local/lib/python3.10/site-packages/vermouth/gmx/itp_read.py", line 154, in parse_pragma
    raise IOError("Don't know how to parse pargma {} at"
OSError: Don't know how to parse pargma #include "2beg_atoms_go_mono.itp" atline 68.
@pckroon pckroon added parser Issues concerning parser behaviour help wanted labels Oct 19, 2023
@pckroon
Copy link
Member

pckroon commented Oct 19, 2023

I think this got discussed some time ago (as in, a few years ago), but I can't find the associated issue.
IIRC the main problem is that finding the included file is annoyingly complicated which is why we put it off originally.
The included files can either be absolute path, local (but it's ambiguous whether it's local to the ITP file being read or the current working directory), or a file somewhere in GMX_DIR (env var, forgot the name).

If this is an important feature for you fixing it yourself and opening a PR will be by far the fastest :)

@fgrunewald
Copy link
Member

The itp reader does not resolve #includes at all and the reason is that they are in fact rarely used in itp files. The Go model is really the only exception. At the time we did not bother because it raised some other questions like do we parse #defines and how to deal with these paragmas. The new Go model implementation also completely gets rid of the include files.

If you are interested to read an itp file with #includes try the polyply topology parser as shown below. FYI you need a topology file, which means you at least need to define the [molecules] directive at the end of the file.

from polyply.src.topology import Topology 
topology = Topology.from_gmx_topfile(name=name, path=toppath)

@BartBruininks
Copy link
Author

BartBruininks commented Oct 19, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement help wanted parser Issues concerning parser behaviour
Projects
None yet
Development

No branches or pull requests

3 participants