📄 jmol.js
字号:
}else{
sout+=key+i+"="+(typeof(A[i]) == "string" && A[i]!="null"?"\""+A[i].replace(/\"/g,"\\\"")+"\"":A[i])
}
}
}
return sout
}
function _jmolSortKey0(a,b){
return (a[0]<b[0]?1:a[0]>b[0]?-1:0)
}
function _jmolSortMessages(A){
if(!A || typeof(A)!="object")return []
var B = []
for(var i=A.length-1;i>=0;i--)for(var j=0;j<A[i].length;j++)B[B.length]=A[i][j]
if(B.length == 0) return
B=B.sort(_jmolSortKey0)
return B
}
/////////additional extensions //////////
function _jmolDomScriptLoad(URL){
//open(URL) //to debug
_jmol.servercall=URL
var node = document.getElementById("_jmolScriptNode")
if (node && _jmol.browser!="msie"){
document.getElementsByTagName("HEAD")[0].removeChild(node)
node=null
}
if (node) {
node.setAttribute("src",URL)
} else {
node=document.createElement("script")
node.setAttribute("id","_jmolScriptNode")
node.setAttribute("type","text/javascript")
node.setAttribute("src",URL)
document.getElementsByTagName("HEAD")[0].appendChild(node)
}
}
function _jmolExtractPostData(url){
S=url.split("&POST:")
var s=""
for(var i=1;i<S.length;i++){
KV=S[i].split("=")
s+="&POSTKEY"+i+"="+KV[0]
s+="&POSTVALUE"+i+"="+KV[1]
}
return "&url="+escape(S[0])+s
}
function _jmolLoadModel(targetSuffix,remoteURL,array,isError,errorMessage){
//called by server, but in client
//overload this function to customize return
_jmol.remoteURL=remoteURL
if(isError)alert(errorMessage)
jmolLoadInlineScript(array.join("\n"),_jmol.optionalscript,targetSuffix)
}
//////////user property/status functions/////////
function jmolGetStatus(strStatus,targetSuffix){
return _jmolSortMessages(jmolGetPropertyAsArray("jmolStatus",strStatus,targetSuffix))
}
function jmolGetPropertyAsArray(sKey,sValue,targetSuffix) {
return _jmolEvalJSON(jmolGetPropertyAsJSON(sKey,sValue,targetSuffix),sKey)
}
function jmolGetPropertyAsString(sKey,sValue,targetSuffix) {
var applet = _jmolGetApplet(targetSuffix);
if(!sValue)sValue=""
return (applet ? applet.getPropertyAsString(sKey,sValue) + "" : "")
}
function jmolGetPropertyAsJSON(sKey,sValue,targetSuffix) {
if(!sValue)sValue = ""
var applet = _jmolGetApplet(targetSuffix);
try {
return (applet ? applet.getPropertyAsJSON(sKey,sValue) + "" : "")
} catch(e) {
return ""
}
}
function jmolGetPropertyAsJavaObject(sKey,sValue,targetSuffix) {
if(!sValue)sValue = ""
var applet = _jmolGetApplet(targetSuffix);
return (applet ? applet.getProperty(sKey,sValue) : null)
}
function jmolDecodeJSON(s) {
return _jmolEnumerateObject(_jmolEvalJSON(s),"")
}
///////// synchronous scripting ////////
function jmolScriptWait(script, targetSuffix) {
if(!targetSuffix)targetSuffix="0"
var Ret=jmolScriptWaitAsArray(script, targetSuffix)
var s = ""
for(var i=Ret.length;--i>=0;)
for(var j=0;j< Ret[i].length;j++)
s+=Ret[i][j]+"\n"
return s
}
function jmolScriptWaitOutput(script, targetSuffix) {
if(!targetSuffix)targetSuffix="0"
var ret = ""
try{
if (script) {
_jmolCheckBrowser();
var applet=_jmolGetApplet(targetSuffix);
if (applet) ret += applet.scriptWaitOutput(script);
}
}catch(e){
}
return ret;
}
function jmolEvaluate(molecularMath, targetSuffix) {
//carries out molecular math on a model
if(!targetSuffix)targetSuffix="0"
var result = "" + jmolGetPropertyAsJavaObject("evaluate", molecularMath, targetSuffix);
var s = result.replace(/\-*\d+/,"")
if (s == "" && !isNaN(parseInt(result)))return parseInt(result);
var s = result.replace(/\-*\d*\.\d*/,"")
if (s == "" && !isNaN(parseFloat(result)))return parseFloat(result);
return result;
}
function jmolScriptEcho(script, targetSuffix) {
// returns a newline-separated list of all echos from a script
if(!targetSuffix)targetSuffix="0"
var Ret=jmolScriptWaitAsArray(script, targetSuffix)
var s = ""
for(var i=Ret.length;--i>=0;)
for(var j=Ret[i].length;--j>=0;)
if (Ret[i][j][1] == "scriptEcho")s+=Ret[i][j][3]+"\n"
return s.replace(/ \| /g, "\n")
}
function jmolScriptMessage(script, targetSuffix) {
// returns a newline-separated list of all messages from a script, ending with "script completed\n"
if(!targetSuffix)targetSuffix="0"
var Ret=jmolScriptWaitAsArray(script, targetSuffix)
var s = ""
for(var i=Ret.length;--i>=0;)
for(var j=Ret[i].length;--j>=0;)
if (Ret[i][j][1] == "scriptStatus")s+=Ret[i][j][3]+"\n"
return s.replace(/ \| /g, "\n")
}
function jmolScriptWaitAsArray(script, targetSuffix) {
var ret = ""
try{
jmolGetStatus("scriptEcho,scriptMessage,scriptStatus,scriptError",targetSuffix)
if (script) {
_jmolCheckBrowser();
var applet=_jmolGetApplet(targetSuffix);
if (applet) ret += applet.scriptWait(script);
ret = _jmolEvalJSON(ret,"jmolStatus")
if(typeof ret == "object")
return ret
}
}catch(e){
}
return [[ret]]
}
//////////// save/restore orientation /////////////
function jmolSaveOrientation(id, targetSuffix) {
if(!targetSuffix)targetSuffix="0"
return _jmol["savedOrientation"+id] = jmolGetPropertyAsArray("orientationInfo","info",targetSuffix).moveTo
}
function jmolRestoreOrientation(id, targetSuffix) {
if(!targetSuffix)targetSuffix="0"
var s=_jmol["savedOrientation"+id]
if (!s || s == "")return
s=s.replace(/1\.0/,"0")
return jmolScriptWait(s,targetSuffix)
}
function jmolRestoreOrientationDelayed(id, delay, targetSuffix) {
if(arguments.length < 2)delay=1;
if(!targetSuffix)targetSuffix="0"
var s=_jmol["savedOrientation"+id]
if (!s || s == "")return
s=s.replace(/1\.0/,delay)
return jmolScriptWait(s,targetSuffix)
}
//////////// add parameter /////////////
/*
* for adding callbacks or other parameters. Use:
jmolSetDocument(0)
var s= jmolApplet(....)
s = jmolAppletAddParam(s,"messageCallback", "myFunctionName")
document.write(s)
jmolSetDocument(document) // if you want to then write buttons and such normally
*/
function jmolAppletAddParam(appletCode,name,value){
if(value == "")return appletCode
return appletCode.replace(/\<param/,"\n<param name='"+name+"' value='"+value+"' />\n<param")
}
///////////////auto load Research Consortium for Structural Biology (RCSB) data ///////////
function jmolLoadAjax_STOLAF_RCSB(fileformat,pdbid,optionalscript,targetSuffix){
if(!_jmol.thismodel)_jmol.thismodel = "1crn"
if(!_jmol.serverURL)_jmol.serverURL="http://fusion.stolaf.edu/chemistry/jmol/getajaxjs.cfm"
if(!_jmol.RCSBserver)_jmol.RCSBserver="http://www.rcsb.org"
if(!_jmol.defaultURL_RCSB)_jmol.defaultURL_RCSB=_jmol.RCSBserver+"/pdb/files/1CRN.CIF"
if(!fileformat)fileformat="PDB"
if(!pdbid)pdbid=prompt("Enter a 4-digit PDB ID:",_jmol.thismodel)
if(!pdbid || pdbid.length != 4)return ""
if(!targetSuffix)targetSuffix="0"
if(!optionalscript)optionalscript=""
var url=_jmol.defaultURL_RCSB.replace(/1CRN/g,pdbid.toUpperCase())
if(fileformat!="CIF")url=url.replace(/CIF/,fileformat)
_jmol.optionalscript=optionalscript
_jmol.thismodel=pdbid
_jmol.thistargetsuffix=targetSuffix
_jmol.thisurl=url
_jmol.modelArray = []
url=_jmol.serverURL+"?returnfunction=_jmolLoadModel&returnArray=_jmol.modelArray&id="+targetSuffix+_jmolExtractPostData(url)
_jmolDomScriptLoad(url)
return url
}
/////////////// St. Olaf College AJAX server -- ANY URL ///////////
function jmolLoadAjax_STOLAF_ANY(url, userid, optionalscript,targetSuffix){
_jmol.serverURL="http://fusion.stolaf.edu/chemistry/jmol/getajaxjs.cfm"
if(!_jmol.thisurlANY)_jmol.thisurlANY = "http://www.stolaf.edu/depts/chemistry/mo/struc/data/ycp3-1.mol"
if(!url)url=prompt("Enter any (uncompressed file) URL:", _jmol.thisurlANY)
if(!userid)userid="0"
if(!targetSuffix)targetSuffix="0"
if(!optionalscript)optionalscript=""
_jmol.optionalscript=optionalscript
_jmol.thistargetsuffix=targetSuffix
_jmol.modelArray = []
_jmol.thisurl = url
url=_jmol.serverURL+"?returnfunction=_jmolLoadModel&returnArray=_jmol.modelArray&id="+targetSuffix+_jmolExtractPostData(url)
_jmolDomScriptLoad(url)
}
/////////////// Mineralogical Society of America (MSA) data /////////
function jmolLoadAjax_MSA(key,value,optionalscript,targetSuffix){
if(!_jmol.thiskeyMSA)_jmol.thiskeyMSA = "mineral"
if(!_jmol.thismodelMSA)_jmol.thismodelMSA = "quartz"
if(!_jmol.ajaxURL_MSA)_jmol.ajaxURL_MSA="http://rruff.geo.arizona.edu/AMS/result.php?mineral=quartz&viewing=ajaxjs"
if(!key)key=prompt("Enter a field:", _jmol.thiskeyMSA)
if(!key)return ""
if(!value)value=prompt("Enter a "+key+":", _jmol.thismodelMSA)
if(!value)return ""
if(!targetSuffix)targetSuffix="0"
if(!optionalscript)optionalscript=""
if(optionalscript == 1)optionalscript='load "" {1 1 1}'
var url=_jmol.ajaxURL_MSA.replace(/mineral/g,key).replace(/quartz/g,value)
_jmol.optionalscript=optionalscript
_jmol.thiskeyMSA=key
_jmol.thismodelMSA=value
_jmol.thistargetsuffix=targetSuffix
_jmol.thisurl=url
_jmol.modelArray = []
loadModel=_jmolLoadModel
_jmolDomScriptLoad(url)
return url
}
function jmolLoadAjaxJS(url, userid, optionalscript,targetSuffix){
if(!userid)userid="0"
if(!targetSuffix)targetSuffix="0"
if(!optionalscript)optionalscript=""
_jmol.optionalscript=optionalscript
_jmol.thismodel=userid
_jmol.thistargetsuffix=targetSuffix
_jmol.modelArray = []
_jmol.thisurl = url
url+="&returnFunction=_jmolLoadModel&returnArray=_jmol.modelArray&id="+targetSuffix
_jmolDomScriptLoad(url)
}
//// in case Jmol library has already been loaded:
}catch(e){}
///////////////moving atoms //////////////
// HIGHLY experimental!!
function jmolSetAtomCoord(i,x,y,z,targetSuffix){
_jmolCheckBrowser();
var applet=_jmolGetApplet(targetSuffix);
if (applet) applet.getProperty('jmolViewer').setAtomCoord(i,x,y,z)
}
function jmolSetAtomCoordRelative(i,x,y,z,targetSuffix){
_jmolCheckBrowser();
var applet=_jmolGetApplet(targetSuffix);
if (applet) applet.getProperty('jmolViewer').setAtomCoordRelative(i,x,y,z)
}
///////////////applet fake for testing buttons/////////////
if(document.location.search.indexOf("NOAPPLET")>=0){
jmolApplet = function(w){
var s="<table style='background-color:black' width="+w+"><tr height="+w+">"
+"<td align=center valign=center style='background-color:white'>"
+"Applet would be here"
+"<p><textarea id=fakeApplet rows=5 cols=50></textarea>"
+"</td></tr></table>"
return _jmolDocumentWrite(s)
}
_jmolFindApplet = function(){return jmolApplet0}
jmolApplet0 = {
script: function(script){document.getElementById("fakeApplet").value="\njmolScript:\n"+script}
,scriptWait: function(script){document.getElementById("fakeApplet").value="\njmolScriptWait:\n"+script}
,loadInline: function(data,script){document.getElementById("fakeApplet").value="\njmolLoadInline data:\n"+data+"\n\nscript:\n"+script}
}
}
///////////////////////////////////////////
//new 9:49 AM 3/6/2007:
//both w and h are optional.
//if either is between 0 and 1, then it is taken as percent/100.
//if either is greater than 1, then it is taken as a size.
function jmolResize(w,h) {
_jmol.alerted = true;
var percentW = (!w ? 100 : w <= 1 && w > 0 ? w * 100 : 0)
var percentH = (!h ? percentW : h <= 1 && h > 0 ? h * 100 : 0)
if (_jmol.browser=="msie") {
var width=document.body.clientWidth;
var height=document.body.clientHeight;
} else {
var netscapeScrollWidth=15;
var width=window.innerWidth - netscapeScrollWidth;
var height=window.innerHeight-netscapeScrollWidth;
}
var applet = _jmolGetApplet(0);
if(!applet)return;
applet.style.width = (percentW ? width * percentW/100 : w)+"px"
applet.style.height = (percentH ? height * percentH/100 : h)+"px"
title=width + " " + height + " " + (new Date())
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -