diff --git a/data/water_aug-cc-pVDZ_CC3.json b/data/water_aug-cc-pVDZ_CC3.json deleted file mode 100644 index 59f1819e..00000000 --- a/data/water_aug-cc-pVDZ_CC3.json +++ /dev/null @@ -1,100 +0,0 @@ -{ - "molecule": "water", - "code": { - "name": "", - "version": "" - }, - "basis": { - "type": "gaussian", - "name": "aug-cc-pVDZ" - }, - "method": "CC3", - "exitations": [ - { - "type": "vert", - "start": { - "number": 1, - "multiplicity": 1, - "symetry": "A_1" - }, - "end": { - "num": 1, - "multiplicity": 1, - "symetry": "B_1" - }, - "energy": 7.51 - }, - { - "type": "vert", - "start": { - "number": 1, - "multiplicity": 1, - "symetry": "A_1" - }, - "end": { - "number": 1, - "multiplicity": 1, - "symetry": "A_2" - }, - "energy": 9.29 - }, - { - "type": "vert", - "start": { - "number": 1, - "multiplicity": 1, - "symetry": "A_1" - }, - "end": { - "number": 2, - "multiplicity": 1, - "symetry": "A_1" - }, - "energy": 9.92 - }, - { - "type": "vert", - "start": { - "number": 1, - "multiplicity": 1, - "symetry": "A_1" - }, - "end": { - "number": 1, - "multiplicity": 3, - "symetry": "B_1" - }, - "energy": 7.13 - }, - { - "type": "vert", - "start": { - "number": 1, - "multiplicity": 1, - "symetry": "A_1" - }, - "end": { - "number": 1, - "multiplicity": 3, - "symetry": "A_2" - }, - "energy": 9.12, - "error": 0.0 - }, - { - "type": "vert", - "start": { - "number": 1, - "multiplicity": 1, - "symmetry": "A_1" - }, - "end": { - "number": 1, - "multiplicity": 3, - "symetry": "A_1" - }, - "energy": 9.47 - } - ], - "doi": "10.1021/acs.jctc.8b00406" -} \ No newline at end of file diff --git a/index.html b/index.html index b0e8ccdf..2f71d32b 100644 --- a/index.html +++ b/index.html @@ -2,20 +2,21 @@ + diff --git a/scripts/data.js b/scripts/data.js index 5157d67e..4d8df9c3 100644 --- a/scripts/data.js +++ b/scripts/data.js @@ -1,21 +1,122 @@ -function getDataFromFile(file,fn) { - var result = null; - var xmlhttp = new XMLHttpRequest(); - xmlhttp - xmlhttp.open("GET",getFullDataPath(file), true); - xmlhttp.onreadystatechange = function() { - if (this.readyState == 4 && this.status == 200) {//when a good response is given do this - - var data = JSON.parse(this.responseText); // convert the response to a json object - fn(data) - } +class code { + constructor(name,version){ + this.name=name + this.version=version + } +} +class basis { + constructor(name,type){ + this.name=name + this.type=type } - xmlhttp.send(); } -function getDoiUrl(doi) { - return 'https://doi.org/'+doi +class state{ + constructor(number,multiplicity,symetry){ + this.number=number; + this.multiplicity=multiplicity; + this.symetry=symetry; + } } -function getFullDataPath(path) { - return 'data/'+path +class doi{ + constructor(doistring){ + this.string=doistring + } + get url() { + return 'https://doi.org/'+doi + } +} +class excitation{ + constructor(start,end,Evert){ + this.start=start; + this.end=end; + this.Evert=Evert; + } +} + +class data { + constructor(){ + this.title=""; + this.code=null; + this.basis=null; + this.doi=null; + this.excitations=[]; + } + static load(file,fn) { + var req = new XMLHttpRequest(); + req.open("GET",getFullDataPath(file), true); + req.onreadystatechange = function() { + if (req.readyState == 4 && req.status == 200) {//when a good response is given do this + var text = req.responseText; + fn(data.loadstring(text)); + } + } + req.send(); + } + static loadstring(text) { + // for each line with metadata + var ismetaArea=true; + //metadata RegExp (start with #; maybe somme spaces; : ; maybe somme space; datas) + var meta=/^#\s*([A-Za-z]+)\s*:\s*(.*)$/; + var dat=new data(); + function readmeta(line){ + // get key value + var match=line.match(meta); + // normalize key to lower + var key=match[1].toLowerCase(); + //if data has value + if(match.length==3 && match[2]) { + var val=match[2]; + switch(key) { + case "title": + dat.title=val; + break; + case "code": + var vals=val.split(",") + if(vals.length>=2){ + dat.code=new code(vals[0],vals[1]); + } else { + dat.code=new code(vals[0],null); + } + break; + case "basis": + var vals=val.split(",") + if(vals.length>=2){ + dat.basis=new basis(vals[0],vals[1]) + } else { + dat.basis=new basis(vals[0],null); + } + break; + case "doi": + dat.doi=new doi(val); + break; + } + } + } + function readrow(line){ + var vals=line.split(/\s+/); + var start=new state(vals[0],vals[1],vals[2]); + var end=new state(vals[3],vals[4],vals[5]); + var ex=new excitation(start,end,vals[6]); + dat.excitations.push(ex); + }; + + text.split("\n").forEach(function(line) { + //if it's not empty line + line=line.trim(); + if (line){ + //if # may be metadata or comment + if (line.charAt(0)=="#") { + //if it's metadata + if(ismetaArea && meta.test(line)) { + readmeta(line); + } + } else { //else its row + ismetaArea=false; + readrow(line); + } + } + }); + return dat + } } diff --git a/scripts/getFullDataPath.js b/scripts/getFullDataPath.js new file mode 100644 index 00000000..5a0e4b33 --- /dev/null +++ b/scripts/getFullDataPath.js @@ -0,0 +1,3 @@ +function getFullDataPath(path) { + return 'data/' + path; +}