Skip to content
Open
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
30 changes: 15 additions & 15 deletions python/plumed.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -708,21 +708,21 @@ def _guessplumedroot(kernel=None):
dir from there.
"""
try:
import tempfile
log=tempfile.mkstemp()[1]
with Plumed(kernel) as p:
p.cmd("setLogFile",log)
p.cmd("init")
i=0
root=""
with open(log) as fin:
for line in fin:
i=i+1
if re.match("PLUMED: Root: ",line):
root=re.sub("PLUMED: Root: ","",line).rstrip("\n")
break
if len(root)>0:
return root
from tempfile import NamedTemporaryFile
#mkstemp does not delete the created file, so we improvise:
with NamedTemporaryFile() as tmpfile:
log=tmpfile.name
with Plumed(kernel) as p:
p.cmd("setLogFile",log)
p.cmd("init")
root=None
with open(log) as fin:
for line in fin:
if re.match("PLUMED: Root: ",line):
root=re.sub("PLUMED: Root: ","",line).rstrip("\n")
break
if root and len(root)>0:
return root
except:
pass
# alternative solution, search for a plumed executable in the path
Expand Down
Loading