Flushing output during the script execution

Hello all, I am using Chimera as a visualization tool for small-molecule electron densities obtained by ab initio structure solution. I want to create a small script that will make Chimera read and display the intermediate electron densities as they are produced during the iterative structure solution process. I am not skilled in Python, but I could make a simple Python script by copying and modifying scripts previously posted in this list. Here is the script: from chimera import runCommand as run from os.path import exists from time import sleep map_file= 'test.xplor' while exists(map_file): run('close all') run('open ' + map_file) sleep(1) I am sure this is not the most elegant way to achieve what I need, but it should do the job. What the script should in my opinion do is to read and display the file test.xplor, then wait one second, close the map and reopen it again, until the file test.xplor is deleted. The script does >>almost<< that, it opens the volume viewer, reads the map, but it does not display the map in the main Chimera window. Only after the file test.xplor is deleted, the last map is displayed. Can anybody give me a hint what am I doing wrong? I am using Chimera 1.2540 on Mac OS X 10.4. Thanks in advance for any help. Best regards Lukas Lukas Palatinus Laboratoire de Cristallographie EPFL Lausanne Tel.: +41 (0)21 693 0639 mailto: palat@fzu.cz

Hi Lukas, The runCommand function immediately executes the given command and does not wait for a redraw to occur before going on to the next command in your script. In order to allow Chimera to draw the map you've opened you need to insert a run('wait 1') in front of your sleep() call -- asking Chimera to draw one frame. --Eric Eric Pettersen UCSF Computer Graphics Lab http://www.cgl.ucsf.edu On Oct 27, 2008, at 9:42 AM, Lukas Palatinus wrote:
Hello all, I am using Chimera as a visualization tool for small-molecule electron densities obtained by ab initio structure solution. I want to create a small script that will make Chimera read and display the intermediate electron densities as they are produced during the iterative structure solution process. I am not skilled in Python, but I could make a simple Python script by copying and modifying scripts previously posted in this list. Here is the script:
from chimera import runCommand as run from os.path import exists from time import sleep map_file= 'test.xplor' while exists(map_file): run('close all') run('open ' + map_file) sleep(1)
I am sure this is not the most elegant way to achieve what I need, but it should do the job. What the script should in my opinion do is to read and display the file test.xplor, then wait one second, close the map and reopen it again, until the file test.xplor is deleted. The script does >>almost<< that, it opens the volume viewer, reads the map, but it does not display the map in the main Chimera window. Only after the file test.xplor is deleted, the last map is displayed. Can anybody give me a hint what am I doing wrong? I am using Chimera 1.2540 on Mac OS X 10.4.
Thanks in advance for any help.
Best regards
Lukas
Lukas Palatinus Laboratoire de Cristallographie EPFL Lausanne Tel.: +41 (0)21 693 0639 mailto: palat@fzu.cz
_______________________________________________ Chimera-users mailing list Chimera-users@cgl.ucsf.edu http://www.cgl.ucsf.edu/mailman/listinfo/chimera-users

Hi Lukas, Eric's suggestion to add a "wait 1" explains the immediate problem. But your use of sleep(1) is not so nice since that freezes Chimera. You won't be able to rotate or change the contour level. Better to let Chimera run its event loop and use a timer to check every second for a new file. I've attached the python code that does that. This code isn't perfect. Sometimes the program writing the map may only have it partially written when Chimera reads it and that will produce an error in Chimera. The attached code will continue trying to read but I didn't see an easy way to suppress the error message. Tom Lukas Palatinus wrote:
Hello all, I am using Chimera as a visualization tool for small-molecule electron densities obtained by ab initio structure solution. I want to create a small script that will make Chimera read and display the intermediate electron densities as they are produced during the iterative structure solution process. I am not skilled in Python, but I could make a simple Python script by copying and modifying scripts previously posted in this list. Here is the script:
from chimera import runCommand as run from os.path import exists from time import sleep map_file= 'test.xplor' while exists(map_file): run('close all') run('open ' + map_file) sleep(1)
I am sure this is not the most elegant way to achieve what I need, but it should do the job. What the script should in my opinion do is to read and display the file test.xplor, then wait one second, close the map and reopen it again, until the file test.xplor is deleted. The script does
almost<< that, it opens the volume viewer, reads the map, but it does not display the map in the main Chimera window. Only after the file test.xplor is deleted, the last map is displayed. Can anybody give me a hint what am I doing wrong? I am using Chimera 1.2540 on Mac OS X 10.4.
Thanks in advance for any help.
Best regards
Lukas
Lukas Palatinus Laboratoire de Cristallographie EPFL Lausanne Tel.: +41 (0)21 693 0639 mailto: palat@fzu.cz <mailto:palat@fzu.cz>
------------------------------------------------------------------------
_______________________________________________ Chimera-users mailing list Chimera-users@cgl.ucsf.edu http://www.cgl.ucsf.edu/mailman/listinfo/chimera-users
class monitor_volume: def __init__(self, map_file, delay = 1000): # delay in msec self.map_file = map_file self.delay = delay import chimera self.m = chimera.openModels.open(map_file)[0] self.reopen() def reopen(self): from os.path import exists if exists(self.map_file): try: self.m.data.values_changed() self.m.show() except: pass # Error reading partial data file. from chimera.tkgui import app app.after(self.delay, self.reopen) monitor_volume('test.xplor')
participants (3)
-
Eric Pettersen
-
Lukas Palatinus
-
Thomas Goddard