
Hi, I'm trying to write a script to change the surface colors of volumes in Chimera: This is what I have so far. for m in chimera.openModels.list(): print m.surface_colors m.surface_colors = [(1.0, 0.0, 0.0, 1.0)] print m.surface_colors This seems to alter the surface colors, but has no effect on what the maps look like in the UI. Do I need to call something else for the UI to be updated, or am I using the wrong approach entirely? Also, I would like to only select the volumes in the first line but I don't know what modelTypes this is: for m in chimera.openModels.list(modelTypes=[chimera.Molecule]): Many thanks, Will. William Moore Wellcome Trust Centre for Gene Regulation & Expression College of Life Sciences MSI/WTB/JBC Complex University of Dundee Dow Street Dundee DD1 5EH United Kingdom Phone 01382 386364 http://openmicroscopy.org.uk

Hi Will, Here's a Python script that will change a volume color: from chimera import openModels from VolumeViewer import Volume for v in openModels.list(modelTypes=[Volume]): v.set_parameters(surface_colors = [(1.0, 0.0, 0.0, 1.0)]) v.show() You can do the same thing more easily with a Chimera command and you can put such commands in a file (suffix .cmd) for Chimera to execute (by opening the file). volume # color plum This colors all volume models as plum color. If you wanted a specific model you would use for example #2 instead of #. The notation # means all models. You could also run this Chimera command from Python. from chimera import runCommand runCommand("volume # color plum") Tom
Hi,
I'm trying to write a script to change the surface colors of volumes in Chimera:
This is what I have so far.
for m in chimera.openModels.list(): print m.surface_colors m.surface_colors = [(1.0, 0.0, 0.0, 1.0)] print m.surface_colors
This seems to alter the surface colors, but has no effect on what the maps look like in the UI. Do I need to call something else for the UI to be updated, or am I using the wrong approach entirely?
Also, I would like to only select the volumes in the first line but I don't know what modelTypes this is: for m in chimera.openModels.list(modelTypes=[chimera.Molecule]):
Many thanks,
Will.
William Moore Wellcome Trust Centre for Gene Regulation & Expression College of Life Sciences MSI/WTB/JBC Complex University of Dundee Dow Street Dundee DD1 5EH United Kingdom
Phone 01382 386364 http://openmicroscopy.org.uk

Hi Tom, Thanks for that. Works great! Now I have another question: I'm trying to pass colors to the script in the arguments, but not having much luck. In the script itself, do you recover the arguments in the normal way: Like this? import getopt, sys, os try: opts, args = getopt.getopt(sys.argv[1:] ,"a:", []) except getopt.GetoptError, err: pass returnMap = {} print opts for opt, arg in opts: if opt == "-a": returnMap["a"] = arg print returnMap If I run this script directly from the command line like this: python colourMaps.py -a red I get the expected print out [('-a', 'red')] {'a': 'red'} but if I try to call this script at the same time as opening maps from the command line, I don't get anything: chimera volume.mrc --script colourMaps.py -- -a red Reply log: [] {} I'm also getting a UI dialog "Please designate file type for --script" which I have to 'cancel' every time I open chimera with this command. Is there any way I can avoid this? Many thanks, Will. On 15 Mar 2010, at 17:25, Thomas Goddard wrote:
Hi Will,
Here's a Python script that will change a volume color:
from chimera import openModels from VolumeViewer import Volume for v in openModels.list(modelTypes=[Volume]): v.set_parameters(surface_colors = [(1.0, 0.0, 0.0, 1.0)]) v.show()
You can do the same thing more easily with a Chimera command and you can put such commands in a file (suffix .cmd) for Chimera to execute (by opening the file).
volume # color plum
This colors all volume models as plum color. If you wanted a specific model you would use for example #2 instead of #. The notation # means all models.
You could also run this Chimera command from Python.
from chimera import runCommand runCommand("volume # color plum")
Tom
Hi,
I'm trying to write a script to change the surface colors of volumes in Chimera:
This is what I have so far.
for m in chimera.openModels.list(): print m.surface_colors m.surface_colors = [(1.0, 0.0, 0.0, 1.0)] print m.surface_colors
This seems to alter the surface colors, but has no effect on what the maps look like in the UI. Do I need to call something else for the UI to be updated, or am I using the wrong approach entirely?
Also, I would like to only select the volumes in the first line but I don't know what modelTypes this is: for m in chimera.openModels.list(modelTypes=[chimera.Molecule]):
Many thanks,
Will.
William Moore Wellcome Trust Centre for Gene Regulation & Expression College of Life Sciences MSI/WTB/JBC Complex University of Dundee Dow Street Dundee DD1 5EH United Kingdom
Phone 01382 386364 http://openmicroscopy.org.uk
William Moore Wellcome Trust Centre for Gene Regulation & Expression College of Life Sciences MSI/WTB/JBC Complex University of Dundee Dow Street Dundee DD1 5EH United Kingdom Phone 01382 386364 http://openmicroscopy.org.uk

Hi Will, Your method of starting Chimera chimera volume.mrc --script colourMaps.py -- -a red looks reasonable but doesn't work. Chimera insists that the data files come after the options (like --script). But the --script <file> option treats all subsequent arguments as script arguments (not data files) unless they start with "--". The bottom line is Chimera wants the data file at the end but that doesn't open the data file if you use the --script option. This is pretty messed up and we will do something to fix it. In the meantime you can use chimera --script colourMaps.py volume.mrc -a red This won't open volume.mrc, instead volume.mrc will be the first argument to your script and your script will have to open it with from chimera import openModels openModels.open(sys.argv[1]) Thanks for pointing out this problem. We will discuss it at our weekly Chimera meeting and come up with a solution that lets you open data files and a script on the command-line. Tom
Hi Tom,
Thanks for that. Works great!
Now I have another question:
I'm trying to pass colors to the script in the arguments, but not having much luck. In the script itself, do you recover the arguments in the normal way: Like this?
import getopt, sys, os try: opts, args = getopt.getopt(sys.argv[1:] ,"a:", []) except getopt.GetoptError, err: pass returnMap = {} print opts for opt, arg in opts: if opt == "-a": returnMap["a"] = arg print returnMap
If I run this script directly from the command line like this: python colourMaps.py -a red
I get the expected print out [('-a', 'red')] {'a': 'red'}
but if I try to call this script at the same time as opening maps from the command line, I don't get anything: chimera volume.mrc --script colourMaps.py -- -a red
Reply log: [] {}
I'm also getting a UI dialog "Please designate file type for --script" which I have to 'cancel' every time I open chimera with this command. Is there any way I can avoid this?
Many thanks,
Will.
participants (2)
-
Thomas Goddard
-
Will Moore