Commit 3404c828 authored by cmaffeo2's avatar cmaffeo2
Browse files

Accept log_file option for model.simulate() to redirect arbd stdout

parent bd544678
......@@ -705,7 +705,7 @@ class ArbdModel(PdbModel):
if typeA != typeB:
self.nbSchemes.append( (nbScheme, typeB, typeA) )
def simulate(self, output_name, output_directory='output', num_steps=100000000, timestep=None, gpu=0, output_period=1e4, arbd=None, directory='.', replicas=1):
def simulate(self, output_name, output_directory='output', num_steps=100000000, timestep=None, gpu=0, output_period=1e4, arbd=None, directory='.', replicas=1, log_file=None):
assert(type(gpu) is int)
num_steps = int(num_steps)
......@@ -761,10 +761,16 @@ class ArbdModel(PdbModel):
cmd = tuple(str(x) for x in cmd)
print("Running ARBD with: %s" % " ".join(cmd))
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, universal_newlines=True)
for line in process.stdout:
sys.stdout.write(line)
sys.stdout.flush()
if log_file is None or (hasattr(log_file,'write') and callable(log_file.write)):
fd = sys.stdout if log_file is None else log_file
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, universal_newlines=True)
for line in process.stdout:
fd.write(line)
fd.flush()
else:
with open(log_file,'w') as fd:
process = subprocess.Popen(cmd, stdout=log_file, universal_newlines=True)
process.communicate()
except:
raise
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment