VMD-L Mailing List
From: Sergei Izrailev (sergei_at_ks.uiuc.edu)
Date: Tue Jul 01 1997 - 20:21:43 CDT
- Next message: s.hogg_at_ic.ac.uk: "Latest Linux News?"
- Previous message: Willy Wriggers: "Re: [VMDTECH] Hingefind"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
In this issue of VMDTech we'll talk about color definitions.
If for some reason you prefer colors different from the default
definitions, you can change and save new definitions so that they are
used in your future VMD sessions.
Another application of this might be (and actually was in some cases)
making black-and-white pictures for publication in scientific
journals.
There are, as usual, two ways of changing color definitions: one uses
the Color form, and the other is text-based. The color setting
process, however, is much easier to use with the forms interface,
whereas the text interface can be used for reproducing a color
scheme you have already chosen.
Sergei Izrailev
sergei_at_ks.uiuc.edu
=====================================================================
Color properties
First, a quick review of how the colors are defined.
Each color has 6 properties:
-- RGB: a triplet of numbers (0.0 to 1.0) describing the color
(red, green, blue);
0 indicates none of that color (also see Diffuse).
-- Alpha: a number (0.0 to 1.0) describing the transparency;
1 is solid, 0 is transparent.
-- Ambient: a triplet of numbers (0.0 to 1.0) describing RGB values
for the ambient light for the given color. Ambient light
provides a uniform illumination of objects with a
background lighting of the specified color. This means
that if you have ambient for the color named 'cyan' set to 1 0
0, the object colored in 'cyan' will appear red in the
absence of any light sources and will have a red component
in the 'shaded' areas in the presence of light sources.
Default is 0 0 0.
-- Diffuse: same as RGB; This property determines the color of the
object. Diffuse reflections are independent of the viewing
direction, but depend on the direction of the light source
with respect to the surface of the displayed object.
-- Specular: a triplet of numbers (0.0 to 1.0) describing the color of
specular reflections. Default is 1 1 1. You can reduce
the reflectivity of the surface by reducing all three
values (say, to 0.5 0.5 0.5). This would give white light
reflections with less intensity. However, you can use any
settings to produce effect of a colored reflection.
-- Shininess: a number (1 to 100) describing how large is the angle of
the specular reflections. The smaller the number the
wider the angle and the more shiny objects appear.
Default is 40.
======================================================================
Setting the color definitions with the Forms interface.
First, open the Color form from the main button bar or by pressing
the 'Color Defs' button on the Graphics form. The Color form is
divided into two parts. The upper part is responsible for assigning
certain colors (such as red, blue, orange) to names that appear under
different categories.
The lower part (Edit Colors), which will most interest us this time,
allows one to change the color definitions. The left browser contains
the names of the available colors (17 total). These names cannot be
changed, but you can change the definition of each color, so that, for
example, you could have the color named 'red' defined as yellow, etc. (Why
would one want to make *such* a redefinition, I don't know, but I have
seen this happen.)
There are 98 colors available in VMD with color ids from 0 to 97. 34
of these are named. Half of the named colors appear in the list on the
Color form (ids 0-16). The other half corresponds to partially
transparent colors, the names of which are the same as of the solid
colors, prefixed with "trans_" (ids 17-33), i.e. trans_white,
trans_yellow, etc. The next group of 32 colors are solid colors used
in color map, followed by the 32 colors that make up the translucent
versions of the solid colors. We'll talk about the first 34 colors.
If you choose 'Color ID' coloring method on the Graphics form, you can
use the color ids 0-15 (and, of course, transparent versions of these
are automatically used when the 'Transparent' button is pressed).
So suppose, we don't really like the appearance of the green color and
we want to make it darker. To see what is happenning we'll change the
color of the background, so choose Display in the category field of
the upper part of the Color form, then choose Background, and,
finally, choose green. The background should become green. The
(default) RGB values are {0.20, 0.70, 0.20}. To make the color darker,
let's bring the RGB values down by moving the red, green and blue
sliders to the left. You can see the color changing as you move the
sliders, so this way you can easily pick the color you prefer to be
named 'green'. The definition can be immediately brought back to the
default values by pressing the 'Default' button on the form.
The text command equivalent for this changing of color is
(note, that moving the sliders changes both 'green' and 'trans_green')
color change rgb green 0 0.5 0
color change rgb trans_green 0 0.5 0
So we changed the RGB definition for color 'green' and 'trans_green' (used
for transparent representations) from {0.2 0.7 0.7} to {0 0.5 0}
The same way you can change all or some of the color definitions and
create a new set of color definitions for yourself.
Notice that there is currently no GUI interface for changing alpha,
specular, ambient and shininess values. These might be added once the
GUI will migrate to Tk.
====================================================================
Using text interface.
The procedure described above is very useful for choosing colors, but
now we want to save the new color definitions for future use. Also
there are some other color paramters that can be changed to improve
the picture.
There are two commands for manipulating colors: 'color' and 'colorinfo'.
The general format for the 'color' command is
color change [alpha|shininess|rgb|ambient|diffuse|specular]
<color name/id> [|newvalue(s)]>
(when no value is specified, the default is used)
color scale [method|midpoint|min|max] <value>
color <category> <name> <new color>
This allows one to change color parameters and scale, or assign
certain color to a certain category.
Examples:
to set the shininess of 'cyan' to 80:
color change shininess cyan 80
to set the color of alanine colored by residue name to yellow:
color Resname ALA yellow
=====================================================================
'colorinfo' command
The general form of 'colorinfo' command is
colorinfo categories
colorinfo category <category>
colorinfo [num|max|colors]
colorinfo [rgb|alpha|shininess|ambient|specular] <name|value>
colorinfo scale [method|methods|midpoint|min|max]
This command provides access to the color definitions.
colorinfo categories
returns a list of available categories
colorinfo category <category>
returns a list of names for the given category
colorinfo num
returns the number of base solid colors (17)
colorinfo max
returns the total number of colors available (98)
colorinfo colors
returns a list of the named solid colors
colorinfo [rgb|alpha|shininess|ambient|specular] <name|colorid>
returns the appropriate values for the given name or color id
colorinfo scale [method|methods|midpoint|min|max]
returns the information about the color scales
The color scales will one day be a topic for another VMD Tech.
Examples:
to find out what color corresponds to which id:
set i 0
foreach color [colorinfo colors] {
puts "$i $color"
incr i
}
to also get a list of RGB values
set i 0
foreach color [colorinfo colors] {
lassign [colorinfo rgb $color] r g b
puts "$i $color \{$r $g $b\}"
incr i
}
=======================================================================
Save/restore color definitions.
The following procedure just opens the specified file and calls the
'save_color' procedure from save_state.tcl script available in the
distribution (many thanks to Ivo Hofacker for writing this script!).
You have to source it, of course:
source $env(VMDDIR)/scripts/vmd/save_state.tcl
The save_state script saves most of the VMD session to a file (including).
It may be useful, however, to save the color definitions in a separate
file, so that they can be used for different molecules.
# save the color definitions in a file
proc savcol {file} {
save_colors [open $file w]
close $filedesc
}
Now to save the colors just type
savcol <filename>
To restore the saved color definitions you now just have to source the
file either in the VMD console window or in your .vmdrc file, so that
the new definitions are read automatically on start-up.
Note, that the save_colors procedure only saves the color definitions
different from the default definitions.
=======================================================================
More examples manipulating color definitions.
1. Once you have set the RGB values for solid colors (with sliders or
otherwise), you may want to set the transparent colors to the same
RGB values. Here is how you could do it:
set numofcolors [colorinfo num]
for {set i 0} {$i < $numofcolors} {incr i} {
lassign [colorinfo rgb $i] r g b
color change rgb [expr $i + $numofcolors] $r $g $b
}
2. If you want to make the transparent colors more (less) transparent:
# Change the alpha value of the transparent colors to a new (given) value
proc change_transparency {new_value} {
display update off
# get the number of colors
set num [colorinfo num]
# the transparent versions are defined as the next set of colors
set max [expr $num + $num]
for {set i $num} {$i < $max} {incr i} {
color change alpha $i $new_value
}
display update on
}
You could even make a new popup window to do this:
user add menu Transp
for {set i 0} {$i < 10} {incr i} {
set f [expr $i / 10.0]
user add subitem Transp $f "change_transparency $f"
}
3. Create a set of black-and-white color definitions.
# map grayscale to color ids 0-16 (0=black; 16=white)
proc make_grayscale {} {
display update off
for {set i 0} {$i < 17} {incr i} {
set val [expr $i / 16.0]
color change rgb $i $val $val $val
}
display update on
}
The only bad thing about this idea is that black becomes white, and
white changes too, so the names of the colors (yellow, orange, etc.)
become useless.
4. Revert all RGB values to defaults:
proc revert_colors {} {
display update off
foreach color [colorinfo colors] {
color change rgb $color
}
display update on
}
5. Making the molecule to show up slowly:
The only application of this that I know of is producing a movie
for demonstration and having parts of the molecule appear and
disappear slowly. These are very crude scripts and they can be
improved.
# change alpha values for all solid colors.
proc change_alpha {newval} {
set num [colorinfo num]
for {set i 0} {$i < $num} {incr i} {
color change alpha $i $newval
}
}
# vary the alpha value from 0 to 1 thus forcing an object to slowly
# appear on the screen.
proc fade_in {} {
for {set i 0} {$i < 1} {set i [expr $i + 0.05]} {
change_alpha $i
}
}
=====================================================================
--
- Next message: s.hogg_at_ic.ac.uk: "Latest Linux News?"
- Previous message: Willy Wriggers: "Re: [VMDTECH] Hingefind"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]