10
0
mirror of https://github.com/LCPQ/QUESTDB_website.git synced 2024-12-25 05:43:46 +01:00

Use same class for Absorption and fluorescence files and improve select

This commit is contained in:
Mickaël Véril 2020-01-27 11:09:35 +01:00
parent 7d5d38a1e9
commit 976a56adac
4 changed files with 149 additions and 156 deletions

View File

@ -21,6 +21,7 @@ draft: false
type="text/javascript"></script>
<script src="/js/DOICache.js"></script>
<script src="/js/nestedCheckbox.js"></script>
<script src="/js/selectSelectAll.js"></script>
<script src="https://unpkg.com/simple-statistics@7.0.2/dist/simple-statistics.min.js"></script>
<script>
window.onload = async () => {
@ -63,25 +64,15 @@ draft: false
delete (cbextl)
delete (allc)
window.doiCache = new DOICache()
await loadFiles()
}
async function loadFiles() {
processingIndicator.isActive = true
var chks = []
var chks = $("#form_datFiles > ul > ul > li >input[type=checkbox]:checked")
var proms = Array.from(chks).map((c) => {
switch (c.value) {
case "abs":
return getAbsFilesName().map((f) => AbsDataFile.loadAsync(f));
break;
case "fluo":
return getFluoFilesName().map((f) => FluoDataFile.loadAsync(f));
break;
default:
return []
break;
}
})
window.dats = []
proms = []
proms.push(getAbsFilesName().map((f) => VertDataFile.loadAsync(f, VertExcitationKinds.Absorbtion)));
proms.push(getFluoFilesName().map((f) => VertDataFile.loadAsync(f, VertExcitationKinds.Fluorescence)))
window.defaultDats = []
for (const subproms of proms) {
var sub = await Promise.all(subproms)
for (mol of uniq(sub.map(d => d.molecule))) {
@ -91,34 +82,21 @@ draft: false
dat.CopyExcitationsTypeFrom(TBE)
}
}
window.dats = window.dats.concat(sub)
window.defaultDats = window.defaultDats.concat(sub)
}
processingIndicator.isActive = false
reloadFileSelector()
await reloadSelect()
}
function reloadFileSelector() {
$("#customFiles_input").attr("value", "").attr("disabled", false)
}
async function reloadSelect() {
processingIndicator.isActive = true
radioval = $('#form_dat > fieldset > input[name=datatype]:checked').val();
const files = $("#customFiles_input")[0].files
for (file of [...files]) {
switch (radioval) {
case "abs":
var dat = await AbsDataFile.loadAsync(file)
window.dats = window.defaultDats;
const kinds=new Map([["file_abs", VertExcitationKinds.Absorbtion], ["file_fluo", VertExcitationKinds.Fluorescence]])
for (const el of $('#form_dat > fieldset > div > input[type="file"')) {
if (kinds.has(el.name)) {
for (const f of el.files) {
const dat=await VertDataFile.loadAsync(f, kinds.get(this.name))
window.dats.push(dat)
break;
case "fluo":
dat = await FluoDataFile.loadAsync(file)
window.dats.push(dat)
break;
case "ZPE":
dat = await ZPEDataFile.loadAsync(file)
window.dats.push(dat)
break;
}
}
}
$('#form_dat > fieldset > div > select,#sel_ref').each(function () {
@ -150,7 +128,6 @@ draft: false
})
$('#form_dat > input[type="submit"').prop('disabled', false);
processingIndicator.isActive = false
await reloadContent()
}
async function reloadStat() {
processingIndicator.isActive = true
@ -165,9 +142,9 @@ draft: false
sdatdic.set(key, new Map())
}
for (const exc of d.excitations) {
const key2 = JSON.stringify([d.molecule, exc.initial, exc.final])
const key2 = JSON.stringify([d.molecule, exc.initial, exc.final, exc.cVertExcitationKind])
const keydic = sdatdic.get(key)
if ((!exc.isUnsafe || window.filterParams[0]) && ((exc.type & window.filterParams[1]) !== 0)) {
if ((!exc.isUnsafe || window.filterParams[0]) && ((exc.type & window.filterParams[1]) !== 0) && ((exc.VertExcitationKind & window.filterParams[2]) !== 0)) {
if (!(keydic.has(key2))) {
keydic.set(key2, [])
}
@ -259,7 +236,7 @@ draft: false
processingIndicator.isActive = false
}
async function reloadContent() {
window.filterParams = [$("#cb_unsafe").prop("checked"), Array.from(Array.from($("#cb_exTypeList>li>input[type=checkbox]:checked")).map(el => parseInt(el.value))).reduce((pv, cv) => pv + cv, 0)]
window.filterParams = [$("#cb_unsafe").prop("checked"), Array.from(Array.from($("#cb_exTypeList>li>input[type=checkbox]:checked")).map(el => parseInt(el.value))).reduce((pv, cv) => pv + cv, 0), Array.from(Array.from($("#cb_exVertKindList>li>input[type=checkbox]:checked")).map(el => parseInt(el.value))).reduce((pv, cv) => pv + cv, 0)]
doiCache.clear()
processingIndicator.isActive = true
const LatexInline = ['\\(', '\\)']
@ -349,8 +326,8 @@ draft: false
const key3 = JSON.stringify(dat.method)
for (const ex of dat.excitations) {
Reflect.setPrototypeOf(ex.type, excitationType.prototype)
if ((window.filterParams[1] & ex.type) !== 0) {
const key2 = JSON.stringify([ex.initial, ex.final, ex.type])
if (((window.filterParams[1] & ex.type) !== 0) && ((window.filterParams[2] & ex.VertExcitationKind) !== 0)) {
const key2 = JSON.stringify([ex.initial, ex.final, ex.type, ex.VertExcitationKind])
if (!datadic.get(key1).has(key2)) {
datadic.get(key1).set(key2, new Map())
}
@ -365,6 +342,7 @@ draft: false
Reflect.setPrototypeOf(ex[0], state.prototype)
Reflect.setPrototypeOf(ex[1], state.prototype)
Reflect.setPrototypeOf(ex[2], excitationType.prototype)
Reflect.setPrototypeOf(ex[3], VertExcitationKind.prototype)
var tr = $("<tr/>")
var tdmol = $("<td/>")
if (printmol) {
@ -372,7 +350,11 @@ draft: false
printmol = false
}
tr.append(tdmol)
$("<td/>").text(String.raw`${LatexInline[0]}${ex[0].toLaTeX()} \rightarrow ${ex[1].toLaTeX()} (${ex[2].LaTeX}) ${LatexInline[1]}`).appendTo(tr)
var Vertkindtext = ""
if (ex[3].Value == VertExcitationKinds.Fluorescence.Value) {
Vertkindtext = String.raw`[${VertExcitationKinds.Fluorescence.LaTeX}]`
}
$("<td/>").text(String.raw`${LatexInline[0]}${ex[0].toLaTeX()} \rightarrow ${ex[1].toLaTeX()} ${Vertkindtext}(${ex[2].LaTeX}) ${LatexInline[1]}`).appendTo(tr)
var entries = Array.from(exdat.entries())
for (const method of sortedMethods) {
td = $("<td/>").addClass("NumberCell")
@ -436,51 +418,59 @@ draft: false
<li>Now you can see the list of selected data and some statistics about these data</li>
</ol>
</p>
<form id="form_datFiles" action="javascript:loadFiles()" method="post">
<legend>Data type</legend>
<ul class="nestedCbList" style="padding-left: 0em;">
<li>
<input type="checkbox" onchange="nestedCheckbox_change(event)" id="cb_fileType_All"></input>
<label for="cb_fileType_All"> All</label>
</li>
<ul class="nestedCbList">
<li>
<input type="checkbox" onchange="nestedCheckbox_change(event)" id="cb_abs" value="abs" name="datatype">
<label for="cb_abs">Absorption</label>
</li>
<li>
<input type="checkbox" onchange="nestedCheckbox_change(event)" id="cb_fluo" value="fluo" name="datatype">
<label for="fluo">Fluorescence</label>
</ul>
</li>
<input type="submit" value="Load files" />
</form>
<form id="form_dat" action="javascript:submitdat()" method="post">
<fieldset>
<legend>Import custom files</legend>
<div>
<label for="customFiles_input">Add custom data file</label>
<input type="file" multiple onchange="reloadSelect()" id="customFiles_input" disabled=true></input>
<label for="absFiles_input">Add custom absorption data files</label>
<input type="file" multiple onchange="reloadSelect()" id="absFiles_input" name="file_abs"></input>
</div>
<div>
<label for="fluoFiles_input">Add custom fluorescence data files</label>
<input type="file" multiple onchange="reloadSelect()" id="fluoFiles_input" name="file_fluo"></input>
</div>
</fieldset>
<fieldset class="table">
<div style="display: inline-block;">
<label for="DOI_select">Set</label>
<label for="DOI_select">Sets</label>
<button class="SelectAll" onclick="selectSelectAll_click(event)">Select all</button>
<select multiple id="DOI_select" name="DOI"></select>
</div>
<div style="display:inline-block">
<label for="mol_select">Molecule</label>
<label for="mol_select">Molecules</label>
<button class="SelectAll" onclick="selectSelectAll_click(event)">Select all</button>
<select multiple id="mol_select" name="molecule"></select>
</div>
<br />
<div style="display: inline-block;">
<label for="method_select">Method</label>
<label for="method_select">Methods</label>
<button class="SelectAll" onclick="selectSelectAll_click(event)">Select all</button>
<select multiple id="method_select" name="method"></select>
</div>
<div style="display: inline-block;">
<label for="basis_select">Basis</label>
<label for="basis_select">Basis sets</label>
<button class="SelectAll" onclick="selectSelectAll_click(event)">Select all</button>
<select multiple id="basis_select" name="basis"></select>
</div>
</fieldset>
<fieldset>
<legend>Vertical excitation kind</legend>
<ul class="nestedCbList" style="padding-left: 0em;">
<li>
<input type="checkbox" onchange="nestedCheckbox_change(event)" id="cb_fileType_All"></input>
<label for="cb_fileType_All"> All</label>
</li>
<ul class="nestedCbList" id="cb_exVertKindList">
<li>
<input type="checkbox" onchange="nestedCheckbox_change(event)" id="cb_abs" value="1" name="datatype">
<label for="cb_abs">Absorption</label>
</li>
<li>
<input type="checkbox" onchange="nestedCheckbox_change(event)" id="cb_fluo" value="2" name="datatype">
<label for="fluo">Fluorescence</label>
</ul>
</li>
</fieldset>
<fieldset id="excitationFilter">
<legend>Filters</legend>
<ul class="nestedCbList" style="padding-left: 0em;">

View File

@ -5,6 +5,9 @@ ul.nestedCbList {
list-style-type: none;
padding-left: 1em;
}
form button.SelectAll {
display: block;
}
form label{
padding-left: 5px;
padding-right: 5px;

View File

@ -1,12 +1,12 @@
class excitationTypes {
static get VALENCE() { return new excitationType(1, String.raw`\mathrm{V}`) }
static get RYDBERG() { return new excitationType(1 << 1, String.raw`\mathrm{R}`) }
static get PiPis() { return new excitationType(1 << 2, String.raw`\pi \rightarrow \pi^\star`) }
static get nPis() { return new excitationType(1 << 3, String.raw`n \rightarrow \pi^\star`) }
static get Single() { return new excitationType(1 << 4, "S") }
static get Double() { return new excitationType(1 << 5, "D") }
static get Singlet() { return new excitationType(1 << 6, "1") }
static get Triplet() { return new excitationType(1 << 7, "3") }
static get VALENCE() { return new excitationType(1<< 1, String.raw`\mathrm{V}`) }
static get RYDBERG() { return new excitationType(1 << 2, String.raw`\mathrm{R}`) }
static get PiPis() { return new excitationType(1 << 3, String.raw`\pi \rightarrow \pi^\star`) }
static get nPis() { return new excitationType(1 << 4, String.raw`n \rightarrow \pi^\star`) }
static get Single() { return new excitationType(1 << 5, "S") }
static get Double() { return new excitationType(1 << 6, "D") }
static get Singlet() { return new excitationType(1 << 7, "1") }
static get Triplet() { return new excitationType(1 << 8, "3") }
// Max bit shifts is 31 because int are int32 So 1 << 31 are -2147483648
static get Others() { return new excitationType(1 << 31, String.raw`\mathrm{Others}`) }
static get All() {
@ -25,7 +25,8 @@ class excitationTypes {
return this.All().filter((x) => { value & x[1] })
}
}
class excitationType {
class LaTeXDescribedValueBase {
constructor(value, laTeX) {
this.Value = value;
this.LaTeX = laTeX
@ -34,6 +35,12 @@ class excitationType {
return this.Value;
}
}
class excitationType extends LaTeXDescribedValueBase{
}
class VertExcitationKind extends LaTeXDescribedValueBase{
}
class code {
constructor(name, version) {
this.name = name;
@ -207,6 +214,10 @@ class dataFileBase {
this.DOI = null
this.sourceFile = null
}
static _GetMetaRexEx() {
//metadata RegExp (start with #; maybe somme spaces; : ; maybe somme space; datas)
return /^#\s*([A-Za-z_]+)\s*:\s*(.*)$/;
}
CopyExcitationsTypeFrom(data) {
for (const ex of this.excitations) {
const ex2=data.excitations.find((e)=>{
@ -217,7 +228,7 @@ class dataFileBase {
}
}
}
static async loadAsync(file) {
static async loadAsync(file,kind=undefined) {
switch (trueTypeOf(file)) {
case String.name:
file = getFullDataPath(file)
@ -227,68 +238,67 @@ class dataFileBase {
var str = await getTextFromUploadedFileAsync(file)
break
}
var dat = this.loadString(str);
var dat = this.loadString(str,kind);
dat.sourceFile = new websiteFile(file)
return dat
}
static readmetaPair(key, value, dat) {
_OnReadMetaPair(key, value) {
switch (key) {
case "molecule":
dat.molecule = value
this.molecule = value
break;
case "comment":
dat.comment = value
this.comment = value
break;
case "code":
dat.code = code.fromString(value)
this.code = code.fromString(value)
break;
case "method":
dat.method = method.fromString(value)
this.method = method.fromString(value)
break;
case "doi":
dat.DOI = DOI.fromString(value);
this.DOI = DOI.fromString(value);
break;
default:
}
}
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 classname = this.name
var dat = eval(String.raw`new ${this.name}()`)
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]
eval(String.raw`${classname}.readmetaPair(key,val,dat)`)
_OnReadRow(line) {
var vals = line.match(/\([^\)]+\)|\S+/g)
var start = new state(parseInt(vals[0], 10), parseInt(vals[1], 10), vals[2]);
var end = new state(parseInt(vals[3], 10), parseInt(vals[4],10), vals[5]);
var hasType = vals.length >= 7 && isNaN(vals[6])
var type = ((vals.length >= 7 && hasType) ? vals[6] : null)
if (type) {
const m = type.match(/^\(([^\)]*)\)$/)
if (m) {
type = m[1]
}
}
function readrow(line) {
var vals = line.match(/\([^\)]+\)|\S+/g)
var start = new state(parseInt(vals[0], 10), parseInt(vals[1], 10), vals[2]);
var end = new state(parseInt(vals[3], 10), parseInt(vals[4],10), vals[5]);
var hasType = vals.length >= 7 && isNaN(vals[6])
var type = ((vals.length >= 7 && hasType) ? vals[6] : null)
if (type) {
const m = type.match(/^\(([^\)]*)\)$/)
if (m) {
type = m[1]
}
}
var val = ((vals.length >= 7 + hasType) ? parseFloat(vals[6 + hasType], 10) : NaN)
var oscilatorForces = ((vals.length >= 8 + hasType) ? parseFloat(vals[7 + hasType], 10) : NaN)
var T1 = ((vals.length >= 9 + hasType) ? parseFloat(vals[8 + hasType], 10) : NaN)
var isUnsafe = ((vals.length >= 10 + hasType) ? vals[9 + hasType] === true.toString() : false)
var ex = new excitationValue(start, end, type, val, oscilatorForces, T1, isUnsafe);
dat.excitations.push(ex);
};
var val = ((vals.length >= 7 + hasType) ? parseFloat(vals[6 + hasType], 10) : NaN)
var oscilatorForces = ((vals.length >= 8 + hasType) ? parseFloat(vals[7 + hasType], 10) : NaN)
var T1 = ((vals.length >= 9 + hasType) ? parseFloat(vals[8 + hasType], 10) : NaN)
var isUnsafe = ((vals.length >= 10 + hasType) ? vals[9 + hasType] === true.toString() : false)
var ex = new excitationValue(start, end, type, val, oscilatorForces, T1, isUnsafe);
if (this.VertExcitationKind) {
ex.VertExcitationKind=this.VertExcitationKind
}
return ex;
};
_OnReadMeta(line) {
// get key value
var match = line.match(dataFileBase._GetMetaRexEx())
// normalize key to lower
var key = match[1].toLowerCase()
//if data has value
if (match.length == 3 && match[2]) {
var val = match[2]
this._OnReadMetaPair(key,val)
}
}
static loadString(text,kind=null) {
// for each line with metadata
var ismetaArea = true;
var dat = new VertDataFile()
for (var line of text.split("\n")) {
//if it's not empty line
line = line.trim();
@ -296,61 +306,43 @@ class dataFileBase {
//if # may be metadata or comment
if (line.charAt(0) == "#") {
//if it's metadata
if (ismetaArea && meta.test(line)) {
readmeta(line);
if (ismetaArea && dataFileBase._GetMetaRexEx().test(line)) {
dat._OnReadMeta(line);
}
} else { //else its row
ismetaArea = false;
readrow(line);
dat.excitations.push(dat._OnReadRow(line,kind));
}
}
}
return dat
}
}
class oneStateDataFileBase extends dataFileBase {
constructor() {
class VertExcitationKinds{
static get Absorbtion() {return new VertExcitationKind(1, String.raw`\mathrm{A}`)}
static get Fluorescence() {return new VertExcitationKind(1<<1, String.raw`\mathrm{F}`)}
}
class VertDataFile extends dataFileBase {
constructor(VertExcitationKind) {
super()
this.VertExcitationKind=VertExcitationKind
this.geometry = null
}
static readmetaPair(key, value, dat) {
_OnReadMetaPair(key, value) {
if (key == "geom") {
dat.geometry = method.fromString(value)
this.geometry = method.fromString(value)
}
else {
dataFileBase.readmetaPair(key, value, dat)
super._OnReadMetaPair(key, value)
}
}
}
class AbsDataFile extends oneStateDataFileBase {
}
class FluoDataFile extends oneStateDataFileBase {
}
class twoStateDataFileBase extends dataFileBase {
constructor() {
super()
this.GS = null
this.ES = null
}
static readmetaPair(key, value, dat) {
switch (key) {
case "gs":
dat.GS = method.fromString(value)
break;
case "es":
dat.ES = method.fromString(value)
break;
default:
dataFileBase.readmetaPair(key, value, dat)
}
_OnReadRow(line,kind) {
var ex=super._OnReadRow(line)
ex.VertExcitationKind=kind
return ex
}
}
class ZPEDataFile extends twoStateDataFileBase {
}
class CombinedData {
constructor() {
this.Abs = null

View File

@ -0,0 +1,8 @@
function selectSelectAll_click(e) {
ctrl=$(e.target).next()
if (ctrl.prop('type') == 'select-multiple' ) {
ctrl.find("option").each(function() {
$(this).attr('selected', 'selected');
});
}
}