mirror of https://github.com/lammps/lammps.git
Allow writing input script from Python session
This implements the requested feature in issue #145. The `write_script` method now gives you a way of dumping out all used commands into a LAMMPS input script file. Note: this also dumps all commands which are indirectly issued by PyLammps
This commit is contained in:
parent
717e719b83
commit
6e3705f380
|
@ -454,6 +454,7 @@ class PyLammps(object):
|
|||
else:
|
||||
self.lmp = lammps(name=name,cmdargs=cmdargs,ptr=None,comm=comm)
|
||||
print("LAMMPS output is captured by PyLammps wrapper")
|
||||
self._cmd_history = []
|
||||
|
||||
def __del__(self):
|
||||
if self.lmp: self.lmp.close()
|
||||
|
@ -469,8 +470,15 @@ class PyLammps(object):
|
|||
def file(self,file):
|
||||
self.lmp.file(file)
|
||||
|
||||
def write_script(self,filename):
|
||||
""" Write LAMMPS script file containing all commands executed up until now """
|
||||
with open(filename, "w") as f:
|
||||
for cmd in self._cmd_history:
|
||||
f.write("%s\n" % cmd)
|
||||
|
||||
def command(self,cmd):
|
||||
self.lmp.command(cmd)
|
||||
self._cmd_history.append(cmd)
|
||||
|
||||
@property
|
||||
def atoms(self):
|
||||
|
@ -643,7 +651,7 @@ class PyLammps(object):
|
|||
cmd_args = [name] + [str(x) for x in args]
|
||||
|
||||
with OutputCapture() as capture:
|
||||
self.lmp.command(' '.join(cmd_args))
|
||||
self.command(' '.join(cmd_args))
|
||||
output = capture.output
|
||||
|
||||
if 'verbose' in kwargs and kwargs['verbose']:
|
||||
|
|
Loading…
Reference in New Issue