On Fri, Mar 26, 2010 at 5:14 PM, Werner Schroedinger <
werner.schroedin...@googlemail.com> wrote:

> For making this procedure faster and more automaticm I wonder if somehow
> can I tell pymol to pay atention to some external file, or for the
> ligand being visualized now, to its copy on the hard disk, and
> continuosly monitor it, so when it detects a change (for instance,
> beacuse the quantum program did something) reload the molecule and
> display it.
>

There may already be a built-in function to do this in PyMOL, but I'm not
aware of it.  It's easy to script in Python, however.  The code below
definitely works on Mac.  Depending on how fast your calculation is, you may
want to increase or decrease the interval, but 2s is a reasonable place to
start.

-Nat

####
from pymol import cmd
import threading
import os.path
import time

class monitor_file (object) :
  def __init__ (self, file_name, object_name, interval=2, verbose=True) :
    self.file_name = file_name
    self.object_name = object_name
    self.interval = interval
    self.abort = False
    self.last_mtime = 0
    if os.path.isfile(file_name) :
      self.reload_file()
      self.last_mtime = os.path.getmtime(file_name)

  def reload_file (self) :
    if self.verbose :
      print "Reloading %s as '%s'" % (self.file_name, self.object_name)
    cmd.load(self.file_name, self.object_name, state=1)

  def start (self) :
    if self.verbose :
      print "starting thread"
    t = threading.Thread(target=self.run)
    t.start()

  def run (self) :
    while not self.abort :
      if os.path.isfile(self.file_name) :
        if self.verbose :
          print "checking file mtime. . ."
        current_mtime = os.path.getmtime(self.file_name)
        if current_mtime > self.last_mtime :
          self.reload_file()
          self.last_mtime = current_mtime
      time.sleep(self.interval)
    return True

  def stop (self) :
    self.abort = True

# Usage
m = monitor_file("/var/tmp/caffeine.pdb", "caffeine")
m.start()
------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
PyMOL-users mailing list (PyMOL-users@lists.sourceforge.net)
Info Page: https://lists.sourceforge.net/lists/listinfo/pymol-users
Archives: http://www.mail-archive.com/pymol-users@lists.sourceforge.net

Reply via email to