10
0
mirror of https://github.com/LCPQ/QUESTDB_website.git synced 2024-12-25 22:03:49 +01:00

replace forEach with for of when it's relevant

This commit is contained in:
Mickaël Véril 2019-09-26 20:25:51 +02:00
parent 73abfb7371
commit f27fcf013e
2 changed files with 174 additions and 176 deletions

View File

@ -19,12 +19,12 @@ draft: false
window.dats=await loadAllData() window.dats=await loadAllData()
window.data=new CombinedData() window.data=new CombinedData()
molecules=new Set(Object.values(window.dats).flat().map((d)=>d.molecule)) molecules=new Set(Object.values(window.dats).flat().map((d)=>d.molecule))
molecules.forEach(el=>{ for (const el of molecules) {
op=document.createElement("option") op=document.createElement("option")
op.value=el op.value=el
op.innerText=el op.innerText=el
document.getElementById("select_mol").appendChild(op) document.getElementById("select_mol").appendChild(op)
}) }
} }
function select_mol_onchange(event){ function select_mol_onchange(event){
update_mol(event.target.value) update_mol(event.target.value)
@ -39,20 +39,20 @@ draft: false
update_ZPE(window.dats["ZPE"][event.target.value]) update_ZPE(window.dats["ZPE"][event.target.value])
} }
async function update_mol(molecule){ async function update_mol(molecule){
Object.keys(window.dats).forEach((key)=>{ for (const [key,dat] of Object.entries(window.dats)) {
var s=document.getElementById(String.raw`select_${key}`) var s=document.getElementById(String.raw`select_${key}`)
while (s.options[s.options.length-1].value!= "") { while (s.options[s.options.length-1].value!= "") {
s.options.remove(s.options[s.options.length-1]) s.options.remove(s.options[s.options.length-1])
} }
window.dats[key].forEach(val=>{ dat.forEach((val,index)=>{
if(val.molecule==molecule){ if(val.molecule==molecule){
var op=document.createElement("option") var op=document.createElement("option")
op.value=window.dats[key].indexOf(val) op.value=index
op.innerText=val.method.toString() op.innerText=val.method.toString()
s.appendChild(op) s.appendChild(op)
} }
}) })
}) }
} }
async function update_abs(abs){ async function update_abs(abs){
window.data.Abs=abs window.data.Abs=abs
@ -91,7 +91,7 @@ draft: false
} }
div=document.getElementById("meta_div") div=document.getElementById("meta_div")
div.innerHTML="" div.innerHTML=""
for (element of md) { for (const element of md) {
var node =null; var node =null;
switch (trueTypeOf(element)) { switch (trueTypeOf(element)) {
case "string": case "string":
@ -123,19 +123,19 @@ draft: false
} }
var tb=document.getElementById("ex_table_b"); var tb=document.getElementById("ex_table_b");
tb.innerHTML='' tb.innerHTML=''
window.data.excitations.forEach(el=> { for (const el of window.data.excitations) {
var row=document.createElement("tr") var row=document.createElement("tr")
var rowd=[] var rowd=[]
rowd.push(String.raw`${LatexInline[0]} ${el.initial.toLaTeX()} \rightarrow ${el.final.toLaTeX()}${LatexInline[1]}`) rowd.push(String.raw`${LatexInline[0]} ${el.initial.toLaTeX()} \rightarrow ${el.final.toLaTeX()}${LatexInline[1]}`)
var e=[el.Eabs,el.Efluo,el.EZPE,el.Eadia,el.Ezz] var e=[el.Eabs,el.Efluo,el.EZPE,el.Eadia,el.Ezz]
e.forEach((val)=>rowd.push(noNanPrecision(val,3))) e.forEach((val)=>rowd.push(noNanPrecision(val,3)))
rowd.forEach((d)=>{ for(d of rowd) {
td=document.createElement("td") td=document.createElement("td")
td.innerText=d td.innerText=d
row.appendChild(td) row.appendChild(td)
}) }
tb.appendChild(row) tb.appendChild(row)
}); }
await MathJax.typesetPromise(); await MathJax.typesetPromise();
document.getElementById("ex_div").hidden=false document.getElementById("ex_div").hidden=false
var plotdat = [{ var plotdat = [{

View File

@ -1,200 +1,198 @@
class code { class code {
constructor(name,version){ constructor(name, version) {
this.name=name; this.name = name;
this.version=version; this.version = version;
}; };
toString() { toString() {
var str=this.name; var str = this.name;
if (this.version) { if (this.version) {
str=str+' ('+this.version+')'; str = str + ' (' + this.version + ')';
} }
return str; return str;
} }
static fromString(str) { static fromString(str) {
var vals=str.split(",") var vals = str.split(",")
if(vals.length>=2){ if (vals.length >= 2) {
return new code(vals[0],vals[1]); return new code(vals[0], vals[1]);
} else { } else {
return new code(vals[0],null); return new code(vals[0], null);
} }
} }
} }
class method { class method {
constructor(name,basis){ constructor(name, basis) {
this.name=name; this.name = name;
this.basis=basis; this.basis = basis;
} }
static fromString(str) { static fromString(str) {
var vals=str.split(",") var vals = str.split(",")
if(vals.length==2){ if (vals.length == 2) {
return new method(vals[0],vals[1]); return new method(vals[0], vals[1]);
} }
else{ else {
return new method(vals[0],null) return new method(vals[0], null)
} }
} }
toString() { toString() {
var str=this.name; var str = this.name;
if (this.name) { if (this.name) {
str=str+'/'+this.basis; str = str + '/' + this.basis;
} }
return str; return str;
} }
} }
class state{ class state {
constructor(number,multiplicity,symetry){ constructor(number, multiplicity, symetry) {
this.number=number; this.number = number;
this.multiplicity=multiplicity; this.multiplicity = multiplicity;
this.symetry=symetry; this.symetry = symetry;
}; };
toString() { toString() {
var str=this.number+ ' ^'+this.multiplicity+this.symetry; var str = this.number + ' ^' + this.multiplicity + this.symetry;
return str; return str;
}; };
toLaTeX() { toLaTeX() {
var tex= String.raw`${this.number}\:\vphantom{\mathrm{${this.symetry.charAt(0)}}}^{${this.multiplicity}}\mathrm{${this.symetry}}`; var tex = String.raw`${this.number}\:\vphantom{\mathrm{${this.symetry.charAt(0)}}}^{${this.multiplicity}}\mathrm{${this.symetry}}`;
return tex; return tex;
}; };
} }
class doi{ class doi {
constructor(doistring){ constructor(doistring) {
this.string=doistring this.string = doistring
}; };
toString() { toString() {
return this.string; return this.string;
}; };
get url() { get url() {
return 'https://doi.org/'+this.string; return 'https://doi.org/' + this.string;
}; };
} }
class excitationBase{ class excitationBase {
constructor(initial,final){ constructor(initial, final) {
this.initial=initial; this.initial = initial;
this.final=final this.final = final
} }
} }
class excitationValue extends excitationBase{ class excitationValue extends excitationBase {
constructor(initial,final,value){ constructor(initial, final, value) {
super(initial,final) super(initial, final)
this.value=value this.value = value
} }
} }
class excitation extends excitationBase{ class excitation extends excitationBase {
constructor(initial,final,Eabs,Efluo,EZPE){ constructor(initial, final, Eabs, Efluo, EZPE) {
super(initial,final) super(initial, final)
this.Eabs=Eabs this.Eabs = Eabs
this.Efluo=Efluo this.Efluo = Efluo
this.EZPE=EZPE this.EZPE = EZPE
} }
get Eadia() { get Eadia() {
return (this.Eabs+this.Efluo)/2 return (this.Eabs + this.Efluo) / 2
} }
get Ezz() { get Ezz() {
return this.Eadia-this.EZPE return this.Eadia - this.EZPE
} }
toString() { toString() {
return this.start+ ', ' + this.end +', '+ noNanPrecision(this.Eabs,3); return this.start + ', ' + this.end + ', ' + noNanPrecision(this.Eabs, 3);
} }
} }
class dataFileBase { class dataFileBase {
constructor(){ constructor() {
this.molecule='' this.molecule = ''
this.comment=null this.comment = null
this.code=null this.code = null
this.method=null this.method = null
this.excitations=[] this.excitations = []
this.DOI=null this.DOI = null
} }
static async loadAsync(file) { static async loadAsync(file) {
return this.loadString(await getTextFromFileAsync(getFullDataPath(file))); return this.loadString(await getTextFromFileAsync(getFullDataPath(file)));
} }
static readmetaPair(key, value,dat){ static readmetaPair(key, value, dat) {
switch(key) { switch (key) {
case "molecule": case "molecule":
dat.molecule=value dat.molecule = value
break; break;
case "comment": case "comment":
dat.comment=value dat.comment = value
break; break;
case "code": case "code":
dat.code=code.fromString(value) dat.code = code.fromString(value)
break; break;
case "method": case "method":
dat.method=method.fromString(value) dat.method = method.fromString(value)
break; break;
case "doi": case "doi":
dat.DOI=new doi(value); dat.DOI = new doi(value);
break; break;
default: default:
} }
} }
static loadString(text) { static loadString(text) {
// for each line with metadata // for each line with metadata
var ismetaArea=true; var ismetaArea = true;
//metadata RegExp (start with #; maybe somme spaces; : ; maybe somme space; datas) //metadata RegExp (start with #; maybe somme spaces; : ; maybe somme space; datas)
var meta=/^#\s*([A-Za-z_]+)\s*:\s*(.*)$/; var meta = /^#\s*([A-Za-z_]+)\s*:\s*(.*)$/;
var classname=this.name var classname = this.name
var dat=eval(String.raw`new ${this.name}()`) var dat = eval(String.raw`new ${this.name}()`)
function readmeta(line){ function readmeta(line) {
// get key value // get key value
var match=line.match(meta) var match = line.match(meta)
// normalize key to lower // normalize key to lower
var key=match[1].toLowerCase() var key = match[1].toLowerCase()
//if data has value //if data has value
if(match.length==3 && match[2]) { if (match.length == 3 && match[2]) {
var val=match[2] var val = match[2]
eval(String.raw`${classname}.readmetaPair(key,val,dat)`) eval(String.raw`${classname}.readmetaPair(key,val,dat)`)
} }
} }
function readrow(line){ function readrow(line) {
var vals=line.split(/\s+/); var vals = line.split(/\s+/);
while (vals.length<8){ while (vals.length < 8) {
vals.push(null); vals.push(null);
} }
var start=new state(parseInt(vals[0],10),parseInt(vals[1],10),vals[2]); var start = new state(parseInt(vals[0], 10), parseInt(vals[1], 10), vals[2]);
var end=new state(parseInt(vals[3],10),vals[4],vals[5]); var end = new state(parseInt(vals[3], 10), vals[4], vals[5]);
var ex= new excitationValue(start,end,parseFloat(vals[6],10)); var ex = new excitationValue(start, end, parseFloat(vals[6], 10));
dat.excitations.push(ex); dat.excitations.push(ex);
}; };
text.split("\n").forEach(function(line) { for (var line of text.split("\n")) {
//if it's not empty line //if it's not empty line
line=line.trim(); line = line.trim();
if (line){ if (line) {
//if # may be metadata or comment //if # may be metadata or comment
if (line.charAt(0)=="#") { if (line.charAt(0) == "#") {
//if it's metadata //if it's metadata
if(ismetaArea && meta.test(line)) { if (ismetaArea && meta.test(line)) {
readmeta(line); readmeta(line);
} }
} else { //else its row } else { //else its row
ismetaArea=false; ismetaArea = false;
readrow(line); readrow(line);
} }
} }
}); }
return dat return dat
} }
} }
class oneStateDataFile extends dataFileBase { class oneStateDataFile extends dataFileBase {
constructor(){ constructor() {
super() super()
this.geometry=null this.geometry = null
} }
static readmetaPair(key,value,dat) static readmetaPair(key, value, dat) {
{ if (key == "geom") {
if(key=="geom") dat.geometry = method.fromString(value)
{
dat.geometry=method.fromString(value)
} }
else{ else {
dataFileBase.readmetaPair(key,value,dat) dataFileBase.readmetaPair(key, value, dat)
} }
} }
} }
@ -204,83 +202,83 @@ class AbsDataFile extends oneStateDataFile {
class FluoDataFile extends oneStateDataFile { class FluoDataFile extends oneStateDataFile {
} }
class twoStateDataFileBase extends dataFileBase{ class twoStateDataFileBase extends dataFileBase {
constructor(){ constructor() {
super() super()
this.GS=null this.GS = null
this.ES=null this.ES = null
} }
static readmetaPair(key,value,dat){ static readmetaPair(key, value, dat) {
switch(key) { switch (key) {
case "gs": case "gs":
dat.GS=method.fromString(value) dat.GS = method.fromString(value)
break; break;
case "es": case "es":
dat.ES=method.fromString(value) dat.ES = method.fromString(value)
break; break;
default: default:
dataFileBase.readmetaPair(key,value,dat) dataFileBase.readmetaPair(key, value, dat)
} }
} }
} }
class ZPEDataFile extends twoStateDataFileBase { class ZPEDataFile extends twoStateDataFileBase {
} }
class CombinedData{ class CombinedData {
constructor(){ constructor() {
this.Abs=null this.Abs = null
this.Fluo=null this.Fluo = null
this.ZPE=null this.ZPE = null
} }
get excitations() { get excitations() {
var exs=[] var exs = []
var dic=new Map() var dic = new Map()
if(this.Abs!=null){ if (this.Abs != null) {
this.Abs.excitations.forEach((el)=>{ for (const el of this.Abs.excitations) {
var key=JSON.stringify([el.initial,el.final]) var key = JSON.stringify([el.initial, el.final])
if(!dic.has(key)){ if (!dic.has(key)) {
dic.set(key,{}) dic.set(key, {})
} }
dic.get(key)["abs"]=el.value dic.get(key)["abs"] = el.value
})
} }
if(this.Fluo!=null){ if (this.Fluo != null) {
this.Fluo.excitations.forEach((el)=>{ for (const el of this.Fluo.excitations) {
var key=JSON.stringify([el.initial,el.final]) var key = JSON.stringify([el.initial, el.final])
if(!dic.has(key)){ if (!dic.has(key)) {
dic.set(key,{}) dic.set(key, {})
} }
dic.get(key)["fluo"]=el.value dic.get(key)["fluo"] = el.value
})
} }
if(this.ZPE!=null){
this.ZPE.excitations.forEach((el)=>{
var key=JSON.stringify([el.initial,el.final])
if(!dic.has(key)){
dic.set(key,{})
} }
dic.get(key)["ZPE"]=el.value if (this.ZPE != null) {
}) for (const el of this.ZPE.excitations) {
var key = JSON.stringify([el.initial, el.final])
if (!dic.has(key)) {
dic.set(key, {})
} }
dic.forEach((value,key)=>{ dic.get(key)["ZPE"] = el.value
var eabs=NaN
var efluo=NaN
var eZPE=NaN
var mykey=JSON.parse(key)
mykey.forEach(el=>{
Reflect.setPrototypeOf(el,state.prototype)
})
if("abs" in value){
eabs=value["abs"]
} }
if("fluo" in value){
efluo=value["fluo"]
} }
if("ZPE" in value){ dic.forEach((value, key) => {
eZPE=value["ZPE"] var eabs = NaN
var efluo = NaN
var eZPE = NaN
var mykey = JSON.parse(key)
for (var el of mykey) {
Reflect.setPrototypeOf(el, state.prototype)
} }
exs.push(new excitation(mykey[0],mykey[1],eabs,efluo,eZPE)) if ("abs" in value) {
eabs = value["abs"]
}
if ("fluo" in value) {
efluo = value["fluo"]
}
if ("ZPE" in value) {
eZPE = value["ZPE"]
}
exs.push(new excitation(mykey[0], mykey[1], eabs, efluo, eZPE))
}) })
return exs return exs
}; }
}
} }