Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion openff/interchange/interop/gromacs/_import/combine.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
import os
from pathlib import Path
from typing import IO


def get_included_path(path: str) -> IO:
if Path(path).exists():
return open(path)

path_from_gmxdata = Path(os.environ["GMXDATA"]) / "top" / path

Check warning on line 10 in openff/interchange/interop/gromacs/_import/combine.py

View check run for this annotation

Codecov / codecov/patch

openff/interchange/interop/gromacs/_import/combine.py#L10

Added line #L10 was not covered by tests

if path_from_gmxdata.exists():
return open(path_from_gmxdata)

Check warning on line 13 in openff/interchange/interop/gromacs/_import/combine.py

View check run for this annotation

Codecov / codecov/patch

openff/interchange/interop/gromacs/_import/combine.py#L12-L13

Added lines #L12 - L13 were not covered by tests

else:
raise ValueError(f"File {path} not found in current directory or GMXDATA top directory.")

Check warning on line 16 in openff/interchange/interop/gromacs/_import/combine.py

View check run for this annotation

Codecov / codecov/patch

openff/interchange/interop/gromacs/_import/combine.py#L16

Added line #L16 was not covered by tests


def make_monolithic(topology_file: str, keep_file: bool = False) -> list[str]:
Expand All @@ -25,7 +40,7 @@
if stripped[0].startswith("#include"):
itp_file = stripped[1].strip('"')

with open(itp_file) as itp_obj:
with get_included_path(itp_file) as itp_obj:
for itp_line in itp_obj:
if len(itp_line) == 0:
continue
Expand Down