Hex to (PyMOL's) RGB
I needed to convert a bunch of hex-encoded color codes to a set of set_color
commands used by PyMOL. Here’s how I did it:
Now all you need is to load a file with your hex codes, convert it and save to another file:
colors = readLines("hex_colors.txt")
pymol_cmds = hex_to_rgb(colors)
writeLines(pymol_cmds, "set_colors.pml")
This is a small example, yet it shows the power of the pipe operator (NOTE: you need to use the original operator from magrittr
package; my version doesn’t support dots for parameter placement!).