Commit 967b04d8 authored by cmaffeo2's avatar cmaffeo2
Browse files

Added 'directory' option to arbdmodel.simulate

parent f1c64034
...@@ -676,56 +676,68 @@ class ArbdModel(PdbModel): ...@@ -676,56 +676,68 @@ class ArbdModel(PdbModel):
if typeA != typeB: if typeA != typeB:
self.nbSchemes.append( (nbScheme, typeB, typeA) ) self.nbSchemes.append( (nbScheme, typeB, typeA) )
def simulate(self, outputPrefix, outputDirectory='output', numSteps=100000000, timestep=None, gpu=0, outputPeriod=1e4, arbd=None): def simulate(self, outputPrefix, outputDirectory='output', numSteps=100000000, timestep=None, gpu=0, outputPeriod=1e4, arbd=None, directory='.'):
assert(type(gpu) is int) assert(type(gpu) is int)
numSteps = int(numSteps) numSteps = int(numSteps)
if timestep is not None: d_orig = os.getcwd()
self.timestep = timestep try:
if not os.path.exists(directory):
os.makedirs(directory)
os.chdir(directory)
if self.cacheUpToDate == False: # TODO: remove cache? if timestep is not None:
self._countParticleTypes() self.timestep = timestep
self._updateParticleOrder()
if outputDirectory == '': outputDirectory='.' if self.cacheUpToDate == False: # TODO: remove cache?
self._countParticleTypes()
if arbd is None: self._updateParticleOrder()
for path in os.environ["PATH"].split(os.pathsep):
path = path.strip('"')
fname = os.path.join(path, "arbd")
if os.path.isfile(fname) and os.access(fname, os.X_OK):
arbd = fname
break
if arbd is None: raise Exception("ARBD was not found")
if not os.path.exists(arbd):
raise Exception("ARBD was not found")
if not os.path.isfile(arbd):
raise Exception("ARBD was not found")
if not os.access(arbd, os.X_OK):
raise Exception("ARBD is not executable")
if not os.path.exists(outputDirectory):
os.makedirs(outputDirectory)
elif not os.path.isdir(outputDirectory):
raise Exception("outputDirectory '%s' is not a directory!" % outputDirectory)
self.writePdb( outputPrefix + ".pdb" ) if outputDirectory == '': outputDirectory='.'
self.writePsf( outputPrefix + ".psf" )
self.writeArbdFiles( outputPrefix, numSteps=numSteps, outputPeriod=outputPeriod )
os.sync()
## http://stackoverflow.com/questions/18421757/live-output-from-subprocess-command if arbd is None:
cmd = (arbd, '-g', "%d" % gpu, "%s.bd" % outputPrefix, "%s/%s" % (outputDirectory, outputPrefix)) for path in os.environ["PATH"].split(os.pathsep):
cmd = tuple(str(x) for x in cmd) path = path.strip('"')
fname = os.path.join(path, "arbd")
if os.path.isfile(fname) and os.access(fname, os.X_OK):
arbd = fname
break
if arbd is None: raise Exception("ARBD was not found")
if not os.path.exists(arbd):
raise Exception("ARBD was not found")
if not os.path.isfile(arbd):
raise Exception("ARBD was not found")
if not os.access(arbd, os.X_OK):
raise Exception("ARBD is not executable")
if not os.path.exists(outputDirectory):
os.makedirs(outputDirectory)
elif not os.path.isdir(outputDirectory):
raise Exception("outputDirectory '%s' is not a directory!" % outputDirectory)
self.writePdb( outputPrefix + ".pdb" )
self.writePsf( outputPrefix + ".psf" )
self.writeArbdFiles( outputPrefix, numSteps=numSteps, outputPeriod=outputPeriod )
os.sync()
## http://stackoverflow.com/questions/18421757/live-output-from-subprocess-command
cmd = (arbd, '-g', "%d" % gpu, "%s.bd" % outputPrefix, "%s/%s" % (outputDirectory, outputPrefix))
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()
except:
raise
finally:
os.chdir(d_orig)
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()
# -------------------------- # # -------------------------- #
# Methods for printing model # # Methods for printing model #
......
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