Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Automate JMol to created multiple 2d images through looping
# script to systematically create many images of molecular structures
# R Lutz 19 Jan 2019
set antialiasImages FALSE # the following is recommended to avoid ragged
# edges around the image, per JMol docs
# ====================================================================
# CONFIGURABLE PARAMS
var rot_max = 2.0 # in degrees
var output_width = 600 # shouldn't be > 600, according to automl guidance
var output_height = 480 #
var png_compression = 2 # 0..10 possible
var png_type = "PNGT" # PNGT uses transparent background, PNG doesn't.
# Will need to experiment to see which is better
var img_path = "./images/" # location for generated images
var number_impressions = 10 # number images for each compound
var cids = ["1983", "5793", "2244", "8078", "57480752", "12644680"]
# 1983 Tylenol
# 5793 Glucose
# 2244 Aspirin
# 8078 Cyclohexane
# 57480752 (2S,3S)-2-Bromo-3-Chlorobutane
# 12644680 (2R,3R)-2-Bromo-3-Chlorobutane
# ====================================================================
for (var i = 0; i < cids.count; i++) {
load @{":" + cids[i]} # prefix of : points to pubchem in JMol
for (var j = 0; j < number_impressions; j++) {
var path_name = img_path + cids[i] + "-" + j + ".png"
rotate X @{random(rot_max)}; rotate Y @{random(rot_max)}; rotate Z @{random(rot_max)}
write IMAGE @output_width @output_height @png_type @png_compression @path_name
}
}
# script to systematically create many images of molecular structures
# the following is recommended to avoid ragged edges around the image
set antialiasImages FALSE
# ====================================================================
# CONFIGURABLE PARAMS
var angle_increment = 10
var output_width = 600
var output_height = 480
var png_compression = 2
var png_type = "PNGT" # PNGT uses transparent background, PNG doesn't.
# Will need to experiment to see which is better
var cids = ["1983", "5793", "2244", "8078", "57480752", "12644680" ]
# 1983 Tylenol
# 5793 Glucose
# 2244 Aspirin
# 8078 Cyclohexane
# 57480752 (2S,3S)-2-Bromo-3-Chlorobutane
# 12644680 (2R,3R)-2-Bromo-3-Chlorobutane
# ====================================================================
#
var step_size = 360 / angle_increment
for (var j = 0; j < 6; j++) {
var cid = cids[j]
var load_path = ":" + cid
load @load_path
for (var i = 0; i <= step_size; i++) {
var path_name = "./images/" + cid + "-x-" + i + ".png"
rotate X @angle_increment
write IMAGE @output_width @output_height @png_type @png_compression @path_name
}
for (var i = 0; i <= step_size; i++) {
var path_name = "./images/" + cid + "-y-" + i + ".png"
rotate Y @angle_increment
write IMAGE @output_width @output_height @png_type @png_compression @path_name
}
for (var i = 0; i <= step_size; i++) {
var path_name = "./images/" + cid + "-z-" + i + ".png"
rotate Z @angle_increment
write IMAGE @output_width @output_height @png_type @png_compression @path_name
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.