marrink-lab / vermouth-martinize

Describe and apply transformation on molecular structures and topologies
Apache License 2.0
84 stars 37 forks source link

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

Open BartBruininks opened 8 months ago

BartBruininks commented 8 months ago

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 commented 8 months ago

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 commented 8 months ago

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 commented 8 months ago

Hoi,

I would say if we don't want to fix it. We could change the error. If there is an #include in the itp, it could be stated that this is not supported and the data should be explicitly present.

Op do 19 okt. 2023 18:13 schreef Fabian Grunewald @.***

:

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)

— Reply to this email directly, view it on GitHub https://github.com/marrink-lab/vermouth-martinize/issues/554#issuecomment-1771195761, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALLQB7YOLNBCVQPMZ4ULGDYAE7TBAVCNFSM6AAAAAA6G47AVWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONZRGE4TKNZWGE . You are receiving this because you authored the thread.Message ID: @.***>