pwtools.visualize.ViewFactory

class pwtools.visualize.ViewFactory(cmd=None, assert_cmd=None, suffix='.axsf', writer=<function write_axsf>)[source]

Bases: object

Factory for creating interface functions to external molecular viewers.

__init__(cmd=None, assert_cmd=None, suffix='.axsf', writer=<function write_axsf>)[source]
Parameters:
  • cmd (str) – Shell command to call the viewer. Used as <cmd> <structfile>. Example: ‘jmol’, ‘xcrysden –axsf’.

  • assert_cmd (callable) – Function which accepts a single arg. Called as assert_cmd(obj) where obj = Structure or Trajectory instance usually). Will be called early. Use to make additional tests on obj.

  • suffix (str) – File end for written structure file.

  • writer (callable) – Called as writer(obj, structfile). Write struct file to read by viewer.

Examples

>>> viewer = ViewFactory(...)
>>> viewer(struct)
>>> # To start more than one viewer, use bg=True to send the spawned
>>> # process to the background. Will leave temp files on disk.
>>> viewer(struct1, bg=True)
>>> viewer(struct2, bg=True)
__call__(obj, logfile=None, structfile=None, disp=False, keepfiles=False, tmpdir='/tmp', wait=True, bg=False, options='')[source]

Call viewer.

The executed shell command is:

<cmd> <options> <structfile> > <logfile>
Parameters:
  • obj (Structure or Trajectory)

  • logfile (str, optional) – Filename of a logfile for the viewer’s text output.

  • structfile (str, optional) – Filename of a file to write the structure to.

  • disp (bool) – Display text output (i.e. logfile’s content).

  • keepfiles (bool) – Keep structfile and logfile on disk.

  • tmpdir (str, optional) – Directory where temp files are written to.

  • wait (bool, optional) – wait passed to common.system(), wait (or not) for command to exit

  • bg (bool) – Background mode. If True then this is an alias for wait=False + keepfiles=True. The latter is needed b/c with just wait=False, temp files will be deleted right after the shell call and the viewer program may complain.

Methods