// compstru_bh.js
// A script for creating the compstru report page Jmol capability
// Bob Hanson and Ben Hinke, St. Olaf College
// BH 5/30/2018 11:12:27 PM
// put your j2s path here
var j2sPath = "https://chemapps.stolaf.edu/jmol/jsmol/j2s";
getStructure = function(n) {
var data = document.getElementsByName("stru")[(n-1)*2].value;
return data
}
showDistance = function() {
var num1 = parseFloat(document.getElementById("distnum").value);
if (isNaN(num1))
num1 = 0.5;
var script = 'set labelfor {*} ""; '
+ 'cscheme = "bwr";'
+ 'c = {fx<1 & fy <1 & fz < 1 && fx>=0 & fy >=0 & fz >=0};'
+ 'rmax = 2.0;'
+ 's1= {1.1 & c}; s2 = {2.1 & c};'
+ 'x=s2.distance.min({1.1}); s2.property_d = x; select s2; label %3.3[property_d];color {1.1} grey;'
+ 'select {2.1}; color property_d @cscheme range 0 @rmax; z=x.max.format("%3.2f"); y=x.min.format("%3.2f");'
+ 'info = getProperty("auxiliaryinfo.models");'
+ 'abc1 = info[1].unitCellParams; abc2 = info[2].unitCellParams;'
+ 'a1 = abc1[1]; b1 = abc1[2]; c1 = abc1[3];'
+ 'a2 = abc2[1]; b2 = abc2[2]; c2 = abc2[3];'
+ 'dd = b2/b1*c2/c1*a1/a2*a1/a2;'
+ 'dc = s2.fxyz.all.distance.min({1.1}.fxyz.all).average;'
+ 'delta = (sqrt(2) * dc + 1) * (dd < 1 ? 1 / dd : dd) - 1;'
+ 'delta=delta.format("%3.3f") ;set echo bottom left;'
if (structureType == '3 and 1') {
script +='caption="\u2206=@{delta}";';
} else {
script += 'cmin=("" + color(cscheme,0,rmax,y)).replace("{","[").replace("}","]").replace(" ",",");'
+ 'cmax=("" + color(cscheme,0,rmax,z)).replace("{","[").replace("}","]").replace(" ",",");'
+ 'caption="min=@{y}max=@{z}";';
}
script += 'echo @caption;select *;labels off; font labels 20;background labels yellow;set labelfor {property_d >' + num1 + '} "%3.3[property_d]"'
Jmol.scriptWait(jmol, script)
}
var structureType = null
loadStructure = function(n1,n2,to1) {
var script = "na = {*}; if (na){save orientation a};load data 'mydata'\n" + getStructure(n1) + "\nend 'mydata' {444 666 1};\ndisplay cell=555;"
+"if (na){restore orientation a}else{zoom *2.5;save orientation a}"
if(to1) { //This is for the #3->#1 structure
structureType = "3 to 1"
var struc1 = getStructure(n1).split("\n")
var struc2 = getStructure(n2).split("\n")
struc2[1] = struc1[1]
script += ";load data 'append'\n" + struc2.join("\n") + "\nend 'append' packed 0.2; frame all;restore orientation a;display cell=555;"
} else if(n2) {
structureType = "3 and 1"
script += ";load data 'append'\n" + getStructure(n2) + "\nend 'append' packed 0.2; frame all;restore orientation a;display cell=555;"
+ "unitcell {2.1}; draw width 0.1 unitcell mesh nofill; unitcell {1.1}"
}
Jmol.scriptWait(jmol, script)
var atomNames = Jmol.evaluateVar(jmol, "{1.1}.atomname.pivot.keys")
//alert(JSON.stringify(atomNames))
//var s = ""
//};
//jQuery $("#atomNames").html(s);
}
var script = "set antialiasdisplay; set zoomlarge false";
jmolReady = function() {
loadStructure(1);
}
var Info = {
width: 450,
height: 450,
script: script,
use: "HTML5",
j2sPath: j2sPath,
isSigned: false,
addSelectionOptions: false,
serverURL: "https://chemapps.stolaf.edu/jmol/jsmol/php/jsmol.php",
readyFunction: jmolReady,
// console: "jmol_infodiv",
// disableInitialConsole: true,
defaultModel: null,
debug: false
}
$(document).ready(function(){
// This demonstration shows that
// what is put on the page can depend upon the platform.
// Note that the use of $(document.ready()) is optional but preferred.
// You can do the traditional in-body coding if you want. See also simple2-nojq.htm.
// But as Gusts Kaksis pointed out, if we are using jQuery for database lookups, we might
// as well use it for more than that.
// note that we create the applet first, before the controls, because
// we need window.jmol to be defined for those, and Jmol.getAppletHtml does that.
$("#middlepanel").html(Jmol.getAppletHtml("jmol", Info));
// alternatively, you can use
//
// jmol = "jmol"
//
// and then create the buttons before the applet itself.
// Just make sure if you do that to use the name of the applet you are
// actually going to be using. So, perhaps:
//
// jmolApplet0 = "jmolApplet0"
//
var use = (Info.use != "JAVA" ? Info.use : Info.isSigned ? "SIGNED" : "JAVA");
var radios = [
["set background white", "white", true],
["set background black", "black"]
];
// right panel
Jmol.setButtonCss(null, "style='width:160px'");
$("#rightpanel").html(
Jmol.jmolButton(jmol,[function(){loadStructure(1)}],"Load Structure #1")
+ " "
+ Jmol.jmolButton(jmol,[function(){loadStructure(2)}],"Load Structure #2")
+ " "
+ Jmol.jmolButton(jmol,[function(){loadStructure(3)}],"Load Structure #3")
+ "