org.molecularplayground.MPJmolAppConfig.spt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jmol Show documentation
Show all versions of jmol Show documentation
Jmol: an open-source Java viewer for chemical structures in 3D
/*
Molecular Playground Configuration File
Bob Hanson, St. Olaf College 12/21/2011
See also MPJmolAppRemoteConfig.spt and MPJmolAppDefaultConfig.spt
Organized around "topics" such as "organic" and "biophysics"
and "subtopics" such as "substitution" or "elimination"
Allows remote control via a PHP call to a server
for setting topic, subtopic, and delay values.
This server is then also called by a web page for web-based interaction
*/
remotedir = "" // leaving this empty disables remote operation
password = "" // set in MPJmolAppRemoteConfig.spt
remotestatus = "" // PHP file to call for topic/subtopic/delay reading
remoteupdate = "" // PHP file to call for updating banner and image
try {
// opportunity to set remote options
script MPJmolAppRemoteConfig.spt
}
defaultTopic = "biophysics"
defaultDelay = 30
delayMax = 120
try {
// opportunity to set default options
script MPJmolAppDefaultConfig.spt
}
function getRemoteStatus() {
// get remote status -- topic, subtopic, and delay
print "remotedir: " + remotedir
if (remotedir == "") { return }
print remoteStatus
var scr = load(remoteStatus)
print scr
try {
script inline @scr // sets topic, and subtopic, and mydelay
}
message remotedir = @{remotedir}
message topic = @{topic}
message subtopic = @{subtopic}
message mydelay = @{mydelay}
}
function remoteSet(s) {
// update remote information for banner and image
if (remotedir == "") { return }
print "remotest " + remoteupdate+s
try {
var x=load(remoteupdate + s)
}
}
function setDirectory() {
// Assumption here is that /.spt exists.
// This is the file with the loadModel() commands and
// generally comes from an Excel spreadsheet, Column A.
if (topic == "") { topic = defaultTopic }
NIOcontentScript=topic + "/" + topic + ".spt"
cd ""
cd @topic
}
function setMPStatus(doCheckTopic) {
// Check for a remote topic change or delay change and
// set directories and delay appropriately.
var oldtopic = topic
getRemoteStatus()
setDirectory()
print topic + ".spt"
print load(topic + ".spt")
if (load(topic + ".spt").find("java.") == 1) {
topic = ""
setDirectory()
}
if (doCheckTopic && oldtopic != topic) {
message @NIOresetMessage
quit
}
if (mydelay < 1) mydelay = defaultDelay
if (mydelay > delayMax) mydelay = delayMax
}
function checkSubTopic(info) {
// simple and/or/not logic checking with parentheses
// just words, not phrases
// for example: substitution or elimination
if (subtopic == "") { return true }
if (subtopic.find(" and ") == 0
&& subtopic.find(" or ") == 0
&& subtopic.find("not ") == 0) { return (info.find(subtopic) > 0) }
var S = subtopic.replace("("," ( ").replace(")"," ) ").split(" ")
for (var i = S.length; i > 0; --i) {
var item = S[i]
if (item == "" || item == "(" || item == ")" || item == "and" || item == "or" || item == "not") { continue }
S[i] = (info.find(item) > 0)
}
x = false
try {
script inline @{"x=" + S.join(" ")}
}
print "x = " + x + " " + S.join(" ")
return x
}
function loadModel(jmolFile,more,banner) {
/*
called from .spt
jmolFile -- should be local to this directory but need not be
more -- additional post-load script for this particular file
banner -- may have "subtopic" field after "##"
that will be checked but removed before display
*/
print "load model " + jmolFile + " " + more + " " + banner
setMPStatus(true)
if (!jmolFile) { return }
if (!checkSubtopic(banner)) { return }
zap
message banner:
var d = 0
try {
remoteSet("log&info=loading " + jmolFile)
load @jmolFile
if (more) { script inline @more }
banner = banner.split("##")[1]
var msg = "banner:" + banner
message @msg
try {
remoteSet("log&info=" + _modelFile)
remoteSet("setbanner&banner=" + banner)
remoteSet("setimage&?POST?_PNG_")
}
catch (err) { print err }
d = [300, (_animating ? [myDelay,_animTimeSec * 2].max : myDelay)].min
}
delay @d
// send terminator message to keep Hub happy
print "terminatormessage=" + NIOterminatormessage
message @NIOterminatorMessage
}
// initialize:
setMPStatus(false)
message MPJmolAppConfig complete