The ProteinDataBank_CIF.hip file I posted has an example of one way to do it. I made groups for each element, then assigned them colours with the Color SOP:
@group_oxygen = (s@element=="O");
@group_nitrogen = (s@element=="N");
@group_carbon = (s@element=="C");
@group_sulfur = (s@element=="S");
That file had no hydrogen (H), phosphorus (P), fluorine (F), chlorine (Cl), or iron (Fe) in it, so I didn't bother creating groups for them. That's probably most of the elements you'll encounter in pdb files for organic molecules. The “s” prefix on “s@element” indicates to VEX that the attribute is a string, (it assumes float if it can't guess from the attribute name). The “group_” indicates that it's a group, instead of a regular attribute.
Alternatively, I could have done:
if (s@element=="O") {
@pscale = ...; // Replace the dots with some value representing the radius
@Cd = {0.9, 0, 0}; // Cd is the colour attribute, this one is red.
}
else if (s@element=="N") {
@pscale = ...;
@Cd = {0, 0.345, 0.9};
}
else if (s@element=="C") {
@pscale = ...;
@Cd = {0.00625, 0.00625, 0.00625};
}
else if (s@element=="S") {
@pscale = ...;
@Cd = {0.9, 0.9, 0};
}
else {
@pscale = ...;
@Cd = {1, 1, 1};
}
Writing code for fun and profit since... 2005? Wow, I'm getting old.
https://www.youtube.com/channel/UC_HFmdvpe9U2G3OMNViKMEQ [
www.youtube.com]