Skip to content

Commit

Permalink
Merge pull request #464 from frantropy/main
Browse files Browse the repository at this point in the history
Fix for make mat allocation
  • Loading branch information
carlocamilloni authored Jul 25, 2024
2 parents 16a0a23 + b895737 commit d8b7f1e
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions tools/make_mat/make_mat.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os
import re
import sys
import tempfile

sys.path.append(os.path.join(os.path.dirname(__file__), "..", "..", "src"))

Expand Down Expand Up @@ -296,7 +298,9 @@ def read_topologies(mego_top, target_top):
"""
Reads the input topologies using parmed. Ignores warnings to prevent printing
of GromacsWarnings regarding 1-4 interactions commonly seen when using
parmed in combination with multi-eGO topologies.
parmed in combination with multi-eGO topologies. In the case of the reference
topology, the last atom number is changed to 1 to prevent parmed from allocating
unnecessary memory.
Parameters
----------
Expand All @@ -313,7 +317,31 @@ def read_topologies(mego_top, target_top):
print(f"ERROR {e} in read_topologies while reading {mego_top}")
exit(1)
try:
topology_ref = pmd.load_file(target_top)
dirname, basename = os.path.split(target_top)
temp_ref = tempfile.NamedTemporaryFile(prefix=basename, dir=dirname)
temp_ref.write(open(target_top, "rb").read())
temp_ref.seek(0)
molecules_tag = False
with open(temp_ref.name, "r") as f:
lines = f.readlines()
lines = [x for x in lines if x.strip()]

for i, line in enumerate(lines):
if line.strip() == "" or line[0] == ";":
continue
if line.strip() == "[ molecules ]":
molecules_tag = True
continue
if line.strip().startswith("["):
molecules_tag = False
if molecules_tag and re.match(r"\s*.+\s+\d+", lines[i]):
print(f"Changing molecule number in line {i} that is {lines[i].strip()} to 1")
lines[i] = re.sub(r"(\s*.+\s+)(\d+)", r"\g<1>1", lines[i])

with open(temp_ref.name, "w") as f:
f.writelines(lines)
topology_ref = pmd.load_file(temp_ref.name)

except Exception as e:
print(f"ERROR {e} in read_topologies while reading {target_top}")
exit(2)
Expand Down

0 comments on commit d8b7f1e

Please sign in to comment.