mirror of
https://github.com/LCPQ/QUESTDB_website.git
synced 2025-01-12 22:18:29 +01:00
Merge branch 'master' into ADC
This commit is contained in:
commit
fa31721e7b
@ -99,12 +99,12 @@ draft: false
|
||||
var data= await loadAllData()
|
||||
window.defaultDats = []
|
||||
for (const sub of Object.values(data)) {
|
||||
for (const doi of uniq(sub.map(d => d.DOI.string))) {
|
||||
const subdoi = sub.filter(d => d.DOI.string === doi)
|
||||
for (const doi of uniq(sub.map(d => (d.DOI == null ? "" : d.DOI.string)))) {
|
||||
const subdoi = sub.filter(d => (d.DOI == null ? "" : d.DOI.string) === doi)
|
||||
for (mol of uniq(subdoi.map(d => d.molecule))) {
|
||||
const submol = subdoi.filter(d => d.molecule === mol)
|
||||
const source = submol.find((d) => {
|
||||
if (d.DOI.string === "10.1021/acs.jctc.8b01205") {
|
||||
if ((d.DOI == null ? "" : d.DOI.string) === "10.1021/acs.jctc.8b01205") {
|
||||
return d.method.name === "CASPT2" && d.method.basis === "aug-cc-pVDZ"
|
||||
} else {
|
||||
return d.method.isTBE
|
||||
@ -120,11 +120,24 @@ draft: false
|
||||
|
||||
window.defaultDats = window.defaultDats.concat(sub)
|
||||
}
|
||||
await doiCache.addRange(Array.from(new Set(window.defaultDats.map(d=>d.DOI.string))))
|
||||
await doiCache.addRange(Array.from(new Set(window.defaultDats.filter(d=>d.DOI!==null).map(d=>d.DOI.string))))
|
||||
window.defaultDats = window.defaultDats.sort((datfa,datfb)=>{
|
||||
const puba = doiCache.get(datfa.DOI.string).format('data', { format: 'object' })[0]
|
||||
const pubb = doiCache.get(datfb.DOI.string).format('data', { format: 'object' })[0]
|
||||
return pubUtils.getIssuedDate(puba) - pubUtils.getIssuedDate(pubb)
|
||||
const DOIa=datfa.DOI
|
||||
const DOIb=datfb.DOI
|
||||
if (DOIa == null && DOIb == null) {
|
||||
return 0
|
||||
}
|
||||
else if (DOIa == null){
|
||||
return 1
|
||||
}
|
||||
else if (DOIb == null){
|
||||
return -1
|
||||
}
|
||||
else {
|
||||
const puba = doiCache.get(DOIa.string).format('data', { format: 'object' })[0]
|
||||
const pubb = doiCache.get(DOIb.string).format('data', { format: 'object' })[0]
|
||||
return pubUtils.getIssuedDate(puba) - pubUtils.getIssuedDate(pubb)
|
||||
}
|
||||
})
|
||||
processingIndicator.isActive = false
|
||||
reloadCustomFiles()
|
||||
@ -194,7 +207,8 @@ draft: false
|
||||
const sets = await (async () => {
|
||||
if (name === "DOI") {
|
||||
const publis = await getPublis()
|
||||
const sets = publis.sets
|
||||
var sets = publis.sets
|
||||
sets.set("","Unknow set")
|
||||
return sets
|
||||
}
|
||||
else {
|
||||
@ -238,7 +252,7 @@ draft: false
|
||||
case "basis":
|
||||
return data.method.basis
|
||||
case "DOI":
|
||||
return data.DOI.string
|
||||
return data.DOI === null ? "" : data.DOI.string
|
||||
default:
|
||||
return data[name]
|
||||
break;
|
||||
@ -256,7 +270,7 @@ draft: false
|
||||
if (!(sdatdic.has(key))) {
|
||||
sdatdic.set(key, new Map())
|
||||
}
|
||||
const myT1s = T1ref.get(d.DOI.string).get(d.molecule)
|
||||
const myT1s = T1ref.get(d.DOI == null ? "" : d.DOI.string).get(d.molecule)
|
||||
for (const exc of d.excitations) {
|
||||
var allowT1 = false
|
||||
const T1Key = JSON.stringify((exc.initial, exc.final))
|
||||
@ -367,14 +381,14 @@ draft: false
|
||||
})
|
||||
})
|
||||
window.T1ref = new Map()
|
||||
var dois = new Set(window.filtData.map((d) => d.DOI.string))
|
||||
var dois = new Set(window.filtData.map((d) =>d.DOI===null ? "" : d.DOI.string))
|
||||
var mols = new Set(window.filtData.map((d) => d.molecule))
|
||||
await window.doiCache.addRange(dois)
|
||||
for (const doi of dois) {
|
||||
window.T1ref.set(doi, new Map())
|
||||
for (const mol of mols) {
|
||||
window.T1ref.get(doi).set(mol, new Map())
|
||||
var TBESortdat = window.dats.filter(d => d.DOI.string === doi && d.molecule === mol).sort((d1, d2) => {
|
||||
var TBESortdat = window.dats.filter(d => (d.DOI === null ? "" : d.DOI.string) === doi && d.molecule === mol).sort((d1, d2) => {
|
||||
if (d1.method.isTBE && !d2.method.isTBE) {
|
||||
return -1
|
||||
} else if (!d1.method.isTBE && d2.method.isTBE) {
|
||||
@ -398,7 +412,7 @@ draft: false
|
||||
}
|
||||
}
|
||||
$(sel_ref).empty()
|
||||
for (const el of uniq(window.filtData.map(d => [d.method, d.DOI.string]))) {
|
||||
for (const el of uniq(window.filtData.map(d => [d.method, (d.DOI === null ? null : d.DOI.string)]))) {
|
||||
op = $("<option/>", {
|
||||
value: JSON.stringify(el)
|
||||
}).text(el[0])
|
||||
@ -413,10 +427,11 @@ draft: false
|
||||
var data = $("#data")
|
||||
$(data).empty();
|
||||
if (window.filtData.length > 0) {
|
||||
const sets = (await getPublis()).sets
|
||||
var sets = (await getPublis()).sets
|
||||
sets.set("","Unknow set")
|
||||
for (const doi of doiCache.keys()) {
|
||||
paperdata = window.filtData.filter((d) => {
|
||||
return d.DOI.string == doi
|
||||
return (d.DOI === null ? "" : d.DOI.string) == doi
|
||||
})
|
||||
var methods = uniq(paperdata.map(d => d.method))
|
||||
const sortedMethods = methods.sort((a, b) => {
|
||||
@ -451,7 +466,7 @@ draft: false
|
||||
datadic = new Map()
|
||||
for (const dat of paperdata) {
|
||||
const key1 = dat.molecule;
|
||||
const myT1s = T1ref.get(dat.DOI.string).get(dat.molecule)
|
||||
const myT1s = T1ref.get(dat.DOI == null ? "" : dat.DOI.string).get(dat.molecule)
|
||||
if (!datadic.has(key1)) {
|
||||
datadic.set(key1, new Map())
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ draft: false
|
||||
window.onload = async function () {
|
||||
var div = document.getElementById("publis_div")
|
||||
const Cite = require("citation-js")
|
||||
const sdois = uniq(Object.values(await loadAllData()).flat().map(d => d.DOI.string))
|
||||
const sdois = uniq(Object.values(await loadAllData()).flat().filter(d => d.DOI !== null).map(d => d.DOI.string))
|
||||
const spubliscite = await Cite.async(sdois)
|
||||
const pubs = await getPublis()
|
||||
const uospublis = spubliscite.format('data', { format: 'object' })
|
||||
|
@ -169,6 +169,8 @@ class excitationBase {
|
||||
this.type.Value = this.type | excitationTypes.Rydberg
|
||||
} else if (ty.includes(String.raw`\mathrm{V}`)) {
|
||||
this.type.Value = this.type | excitationTypes.Valence
|
||||
} else if (ty.toLowerCase()===excitationTypes.Double.description.string.toLowerCase()){
|
||||
this.type.Value = this.type | excitationTypes.Double
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,32 +4,39 @@ import re
|
||||
from enum import IntEnum,auto,unique
|
||||
import numpy as np
|
||||
from pathlib import Path
|
||||
from lib import LaTeX
|
||||
from lib.dfbOptions import dfbOptions
|
||||
from lib.Format import Format
|
||||
from lib import LaTeX,formats,dfbOptions
|
||||
from lib.formats import getFormatHandlers
|
||||
from TexSoup import TexSoup,TexNode,TexCmd,TexEnv
|
||||
from lib.data import dataFileBase,DataType,state
|
||||
from collections import defaultdict
|
||||
import argparse
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('--file', type=argparse.FileType('r'))
|
||||
parser.add_argument("--list","-l",action="store_true", help='List all available format')
|
||||
parser.add_argument('--debug', action='store_true', help='Debug mode')
|
||||
args = parser.parse_args()
|
||||
lines=args.file.readlines()
|
||||
soup=TexSoup(lines)
|
||||
opt=soup.dfbOptions
|
||||
if type(opt) is TexNode and type(opt.expr) is TexEnv:
|
||||
texOps=dfbOptions.readFromEnv(opt)
|
||||
if args.list:
|
||||
print("The list of avalable formats are:")
|
||||
for formatName,_ in getFormatHandlers():
|
||||
print(formatName)
|
||||
elif args.file!=None:
|
||||
lines=args.file.readlines()
|
||||
soup=TexSoup(lines)
|
||||
opt=soup.dfbOptions
|
||||
if type(opt) is TexNode and type(opt.expr) is TexEnv:
|
||||
texOps=dfbOptions.readFromEnv(opt)
|
||||
else:
|
||||
texOps=dfbOptions()
|
||||
commands=[LaTeX.newCommand(cmd) for cmd in soup.find_all("newcommand")]
|
||||
dat=LaTeX.tabularToData(soup.tabular,commands)
|
||||
scriptpath=Path(sys.argv[0]).resolve()
|
||||
datapath=scriptpath.parents[1]/"static"/"data"
|
||||
if args.debug:
|
||||
datapath=datapath/"test"
|
||||
if not datapath.exists():
|
||||
datapath.mkdir()
|
||||
datalst=dataFileBase.readFromTable(dat,texOps,commands=commands)
|
||||
for data in datalst:
|
||||
data.toFile(datapath,texOps.suffix)
|
||||
else:
|
||||
texOps=dfbOptions()
|
||||
commands=[LaTeX.newCommand(cmd) for cmd in soup.find_all("newcommand")]
|
||||
dat=LaTeX.tabularToData(soup.tabular,commands)
|
||||
scriptpath=Path(sys.argv[0]).resolve()
|
||||
datapath=scriptpath.parents[1]/"static"/"data"
|
||||
if args.debug:
|
||||
datapath=datapath/"test"
|
||||
if not datapath.exists():
|
||||
datapath.mkdir()
|
||||
datalst=dataFileBase.readFromTable(dat,texOps,commands=commands)
|
||||
for data in datalst:
|
||||
data.toFile(datapath,texOps.suffix)
|
||||
parser.print_help()
|
@ -1,9 +0,0 @@
|
||||
from enum import IntEnum,auto,unique
|
||||
@unique
|
||||
class Format(IntEnum):
|
||||
LINE=auto()
|
||||
COLUMN=auto()
|
||||
DOUBLECOLUMN=auto()
|
||||
EXOTICCOLUMN=auto()
|
||||
TBE=auto()
|
||||
DOUBLETBE=auto()
|
@ -138,4 +138,20 @@ def tabularToData(table,commands=None):
|
||||
table=np.array(lnewtable,TexNode)
|
||||
return table
|
||||
else:
|
||||
raise ValueError("Only tabular LaTeX environment is supported")
|
||||
raise ValueError("Only tabular LaTeX environment is supported")
|
||||
|
||||
def extractMath(TexMath,Soup=False,commands=[]):
|
||||
if not Soup and len(commands)>0:
|
||||
raise ValueError("Commandw are only usable when Soup is True")
|
||||
math=TexMath.find("$")
|
||||
lst=list(math.contents)
|
||||
mystr=str(lst[0])
|
||||
if not Soup:
|
||||
return mystr
|
||||
mathsoup=None
|
||||
try:
|
||||
mathsoup=TexSoup(mystr)
|
||||
except:
|
||||
raise ValueError(f"Error when parsing latex math: {mystr}")
|
||||
newCommand.runAll(mathsoup,commands)
|
||||
return mathsoup
|
@ -0,0 +1 @@
|
||||
from .dfbOptions import dfbOptions
|
@ -1,10 +1,10 @@
|
||||
from collections import OrderedDict
|
||||
from TexSoup import TexSoup
|
||||
from .LaTeX import newCommand
|
||||
from .LaTeX import newCommand,extractMath
|
||||
from .utils import getValFromCell,checkFloat
|
||||
from TexSoup import TexNode,TexEnv
|
||||
from enum import IntEnum,auto,unique,IntFlag
|
||||
from .Format import Format
|
||||
from .formats import getFormatHandlers
|
||||
import re
|
||||
import numpy as np
|
||||
import json
|
||||
@ -25,6 +25,27 @@ class state:
|
||||
class DataType(IntEnum):
|
||||
ABS=auto()
|
||||
FLUO=auto()
|
||||
|
||||
def datafileSelector(dataType):
|
||||
switcher={
|
||||
DataType.ABS:AbsDataFile,
|
||||
DataType.FLUO:FluoDataFile,
|
||||
}
|
||||
return switcher[dataType]
|
||||
|
||||
def getSubtablesRange(table,firstindex=2,column=0,count=1):
|
||||
subtablesRange=list()
|
||||
i=firstindex+count
|
||||
while i<np.size(table,0):
|
||||
if str(table[i,column])!="":
|
||||
subtablesRange.append(range(firstindex,i))
|
||||
firstindex=i
|
||||
i+=count
|
||||
else:
|
||||
i+=1
|
||||
subtablesRange.append(range(firstindex,np.size(table,0)))
|
||||
return subtablesRange
|
||||
|
||||
class dataFileBase(object):
|
||||
def __init__(self):
|
||||
self.molecule = ''
|
||||
@ -46,17 +67,7 @@ class dataFileBase(object):
|
||||
def convertState(StateTablelist,initialState,default=DataType.ABS,commands=[]):
|
||||
tmplst=[]
|
||||
for TexState in StateTablelist:
|
||||
math=TexState.find("$")
|
||||
lst=list(math.contents)
|
||||
mystr=str(lst[0])
|
||||
mathsoup=None
|
||||
try:
|
||||
mathsoup=TexSoup(mystr)
|
||||
except:
|
||||
print(f"Error when parsing latex state: {mystr}")
|
||||
exit(-1)
|
||||
newCommand.runAll(mathsoup,commands)
|
||||
st=str(mathsoup)
|
||||
st=str(extractMath(TexState,Soup=True,commands=commands))
|
||||
m=re.match(r"^\^(?P<multiplicity>\d)(?P<symm>[^\s\[(]*)\s*(?:\[(?:\\mathrm{)?(?P<special>\w)(?:})\])?\s*(:?\((?P<type>[^\)]*)\))?",st)
|
||||
seq=m.group("multiplicity","symm")
|
||||
mul=int(m.group("multiplicity"))
|
||||
@ -78,253 +89,13 @@ class dataFileBase(object):
|
||||
return lst
|
||||
@staticmethod
|
||||
def readFromTable(table,TexOps, commands=[]):
|
||||
def getSubtableIndex(table,firstindex=2,column=0,count=1):
|
||||
subtablesindex=list()
|
||||
i=firstindex+count
|
||||
while i<np.size(table,0):
|
||||
if str(table[i,column])!="":
|
||||
subtablesindex.append((firstindex,i-1))
|
||||
firstindex=i
|
||||
i+=count
|
||||
else:
|
||||
i+=1
|
||||
subtablesindex.append((firstindex,np.size(table,0)))
|
||||
return subtablesindex
|
||||
|
||||
datalist=list()
|
||||
switcher={
|
||||
DataType.ABS:AbsDataFile,
|
||||
DataType.FLUO:FluoDataFile,
|
||||
}
|
||||
if TexOps.format==Format.LINE:
|
||||
for col in range(1,np.size(table,1)):
|
||||
col=table[:,col]
|
||||
mymolecule=str(col[0])
|
||||
mymethod=method(str(col[2]),str(col[1]))
|
||||
initialState=TexOps.initialStates[mymolecule]
|
||||
finsts=dataFileBase.convertState(table[3:,0],initialState,default=TexOps.defaultType,commands=commands)
|
||||
datacls=dict()
|
||||
for index,cell in enumerate(col[3:]):
|
||||
if str(cell)!="":
|
||||
val,unsafe=getValFromCell(cell)
|
||||
finst=finsts[index]
|
||||
dt=finst[1]
|
||||
if dt in datacls:
|
||||
data=datacls[dt]
|
||||
else:
|
||||
cl=switcher[dt]
|
||||
data=cl()
|
||||
datacls[dt]=data
|
||||
data.molecule=mymolecule
|
||||
data.method=mymethod
|
||||
data.excitations.append(excitationValue(initialState,finst[0],val,type=finst[2],isUnsafe=unsafe))
|
||||
for value in datacls.values():
|
||||
datalist.append(value)
|
||||
return datalist
|
||||
elif TexOps.format==Format.COLUMN:
|
||||
subtablesindex=getSubtableIndex(table)
|
||||
for first, last in subtablesindex:
|
||||
for col in range(2,np.size(table,1)):
|
||||
datacls=dict()
|
||||
col=table[:,col]
|
||||
mymolecule=str(table[first,0])
|
||||
initialState=TexOps.initialStates[mymolecule]
|
||||
mymethod=method(str(col[1]),str(col[0]))
|
||||
finsts=dataFileBase.convertState(table[first:last+1,1],initialState,default=TexOps.defaultType,commands=commands)
|
||||
for index,cell in enumerate(col[first:last+1]):
|
||||
if str(cell)!="":
|
||||
val,unsafe=getValFromCell(cell)
|
||||
finst=finsts[index]
|
||||
dt=finst[1]
|
||||
if dt in datacls:
|
||||
data=datacls[dt]
|
||||
else:
|
||||
cl=switcher[dt]
|
||||
data=cl()
|
||||
data.molecule=mymolecule
|
||||
data.method=mymethod
|
||||
datacls[dt]=data
|
||||
data.excitations.append(excitationValue(initialState,finst[0],val,type=finst[2]))
|
||||
for value in datacls.values():
|
||||
datalist.append(value)
|
||||
return datalist
|
||||
elif TexOps.format==Format.DOUBLECOLUMN:
|
||||
datacls=dict()
|
||||
subtablesMol=getSubtableIndex(table)
|
||||
for firstMol, lastMol in subtablesMol:
|
||||
mymolecule=str(table[firstMol,0])
|
||||
moltable=table[firstMol:lastMol+1,:]
|
||||
subtablestrans=getSubtableIndex(moltable,firstindex=0,column=1,count=2)
|
||||
for firstTrans,lastTrans in subtablestrans:
|
||||
mytrans=moltable[firstTrans:lastTrans+1,:]
|
||||
mytransdesc=mytrans[0:2,1]
|
||||
for i in range(2):
|
||||
try:
|
||||
mathsoup=TexSoup(mytransdesc[i])
|
||||
except:
|
||||
print(f"Error when parsing latex state: {str(mytransdesc[i])}")
|
||||
exit(-1)
|
||||
newCommand.runAll(mathsoup,commands)
|
||||
mytransdesc[i]=str(mathsoup)
|
||||
for colindex in range(3,np.size(table,1)):
|
||||
col=mytrans[:,colindex]
|
||||
mybasis=str(table[1,colindex])
|
||||
for index,cell in enumerate(col):
|
||||
methodnameAT1=str(mytrans[index,2])
|
||||
PTString=r"($\%T_1$)"
|
||||
HasT1=methodnameAT1.endswith(PTString)
|
||||
if HasT1:
|
||||
methodname=methodnameAT1[:-len(PTString)]
|
||||
else:
|
||||
methodname=str(methodnameAT1)
|
||||
mymethod=method(methodname,mybasis)
|
||||
strcell=str(cell)
|
||||
if strcell!="":
|
||||
if HasT1:
|
||||
m=re.match(r"^(?P<value>[-+]?\d+\.?\d*)\s*(?:\((?P<T1>\d+\.?\d*)\\\%\))?",strcell)
|
||||
val,unsafe=getValFromCell(TexSoup(m.group("value")))
|
||||
T1=m.group("T1")
|
||||
else:
|
||||
m=re.match(r"^[-+]?\d+\.?\d*",strcell)
|
||||
val,unsafe=getValFromCell(TexSoup(m.group(0)))
|
||||
T1=None
|
||||
if (mymolecule,mymethod.name,mymethod.basis) in datacls:
|
||||
data=datacls[(mymolecule,mymethod.name,mymethod.basis)]
|
||||
else:
|
||||
data=AbsDataFile()
|
||||
data.molecule=mymolecule
|
||||
data.method=mymethod
|
||||
datacls[(mymolecule,mymethod.name,mymethod.basis)]=data
|
||||
infin=mytransdesc[0].split(r"\rightarrow")
|
||||
for i,item in enumerate(infin):
|
||||
m=re.match(r"^(?P<number>\d)\\[,:;\s]\s*\^(?P<multiplicity>\d)(?P<sym>\S*)",item.strip())
|
||||
infin[i]=state(m.group("number"),m.group("multiplicity"),m.group("sym"))
|
||||
data.excitations.append(excitationValue(infin[0],infin[1],val,type=mytransdesc[1],isUnsafe=unsafe,T1=T1))
|
||||
for value in datacls.values():
|
||||
datalist.append(value)
|
||||
return datalist
|
||||
elif TexOps.format==Format.EXOTICCOLUMN:
|
||||
import json
|
||||
subtablesindex=getSubtableIndex(table)
|
||||
for first, last in subtablesindex:
|
||||
valDic=dict()
|
||||
mymolecule=str(table[first,0])
|
||||
initialState=TexOps.initialStates[mymolecule]
|
||||
for col in range(2,np.size(table,1)):
|
||||
col=table[:,col]
|
||||
basis=str(col[0])
|
||||
mymethcell=list(col[1])
|
||||
if isinstance(mymethcell[0],TexNode) and mymethcell[0].name=="$":
|
||||
kindSoup=TexSoup("".join(list(mymethcell[0].expr.all)))
|
||||
newCommand.runAll(kindSoup,commands)
|
||||
kind=str(kindSoup)
|
||||
methodnameSoup=TexSoup(mymethcell[1].value)
|
||||
newCommand.runAll(methodnameSoup,commands)
|
||||
methodname=str(methodnameSoup)
|
||||
else:
|
||||
kind=""
|
||||
methtex=col[1]
|
||||
newCommand.runAll(methtex,commands)
|
||||
methodname=str(methtex)
|
||||
mymethod=method(methodname,basis)
|
||||
methkey=json.dumps(mymethod.__dict__)
|
||||
finsts=dataFileBase.convertState(table[first:last+1,1],initialState,default=TexOps.default,commands=commands)
|
||||
for index,cell in enumerate(col[first:last+1]):
|
||||
if str(cell)!="":
|
||||
val,unsafe=getValFromCell(cell)
|
||||
finst=finsts[index]
|
||||
dt=finst[1]
|
||||
if dt in valDic:
|
||||
dtDic=valDic[dt]
|
||||
else:
|
||||
dtDic=dict()
|
||||
valDic[dt]=dtDic
|
||||
if not methkey in dtDic:
|
||||
dtDic[methkey]=dict()
|
||||
dataDic=dtDic[methkey]
|
||||
exkey=(json.dumps(finst[0].__dict__,),finst[2])
|
||||
if not exkey in dataDic:
|
||||
dataDic[exkey]=dict()
|
||||
if kind=='':
|
||||
dataDic[exkey][kind]=(val,unsafe)
|
||||
else:
|
||||
dataDic[exkey][kind]=val
|
||||
#data.excitations.append(excitationValue(initialState,finst[0],val,type=finst[2]))
|
||||
for dt,methdic in valDic.items():
|
||||
for methstring,exdic in methdic.items():
|
||||
data=switcher[dt]()
|
||||
data.molecule=mymolecule
|
||||
methdic=json.loads(methstring)
|
||||
data.method=method(methdic["name"],methdic["basis"])
|
||||
for exstr,values in exdic.items():
|
||||
stDict=json.loads(exstr[0])
|
||||
ty=exstr[1]
|
||||
st=state(stDict["number"],stDict["multiplicity"],stDict["symetry"])
|
||||
T1=values["\\%T_1"] if "\\%T_1" in values else None
|
||||
oF= values["f"] if "f" in values else None
|
||||
val,unsafe=values[""]
|
||||
data.excitations.append(excitationValue(initialState,st,val,type=ty,T1=T1,isUnsafe=unsafe,oscilatorForces=oF))
|
||||
datalist.append(data)
|
||||
return datalist
|
||||
elif TexOps.format==Format.TBE:
|
||||
subtablesindex=getSubtableIndex(table)
|
||||
for first, last in subtablesindex:
|
||||
datacls=dict()
|
||||
mymolecule=str(table[first,0])
|
||||
initialState=TexOps.initialStates[mymolecule]
|
||||
mymethod=(method("TBE(FC)"),method("TBE"))
|
||||
finsts=dataFileBase.convertState(table[first:last+1,1],initialState,default=TexOps.defaultType,commands=commands)
|
||||
for index,row in enumerate(table[first:last+1,]):
|
||||
oscilatorForces=checkFloat(str(row[2]))
|
||||
T1 = checkFloat(str(row[3]))
|
||||
val,unsafe = getValFromCell(row[4])
|
||||
corr,unsafecorr = getValFromCell(row[7])
|
||||
finst=finsts[index]
|
||||
dt=finst[1]
|
||||
if dt in datacls:
|
||||
datamtbe = datacls[dt]
|
||||
else:
|
||||
cl=switcher[dt]
|
||||
datamtbe=[]
|
||||
for met in mymethod:
|
||||
data=cl()
|
||||
data.molecule=mymolecule
|
||||
data.method=met
|
||||
datamtbe.append(data)
|
||||
datacls[dt]=datamtbe
|
||||
vs=[val,corr]
|
||||
uns=[unsafe,unsafecorr]
|
||||
for i in range(2):
|
||||
datamtbe[i].excitations.append(excitationValue(initialState,finst[0],vs[i],type=finst[2],T1=T1,oscilatorForces=oscilatorForces,isUnsafe=uns[i]))
|
||||
for value in datacls.values():
|
||||
for dat in value:
|
||||
datalist.append(dat)
|
||||
return datalist
|
||||
elif TexOps.format==Format.DOUBLETBE:
|
||||
datacls=dict()
|
||||
subtablesMol=getSubtableIndex(table)
|
||||
for firstMol, lastMol in subtablesMol:
|
||||
data=AbsDataFile()
|
||||
data.molecule=str(table[firstMol,0])
|
||||
data.method=method("TBE","CBS")
|
||||
for mytrans in table[firstMol:lastMol+1]:
|
||||
try:
|
||||
mathsoup=TexSoup(mytrans[1])
|
||||
except:
|
||||
print(f"Error when parsing latex state: {str(mytransdesc[i])}")
|
||||
exit(-1)
|
||||
newCommand.runAll(mathsoup,commands)
|
||||
mytransdesc=str(mathsoup)
|
||||
infin=mytransdesc.split(r"\rightarrow")
|
||||
for i,item in enumerate(infin):
|
||||
m=re.match(r"^(?P<number>\d)\\[,:;\s]\s*\^(?P<multiplicity>\d)(?P<sym>\S*)",item.strip())
|
||||
infin[i]=state(m.group("number"),m.group("multiplicity"),m.group("sym"))
|
||||
cell=mytrans[6]
|
||||
val,unsafe=getValFromCell(cell)
|
||||
data.excitations.append(excitationValue(infin[0],infin[1],val,isUnsafe=unsafe))
|
||||
datalist.append(data)
|
||||
return datalist
|
||||
|
||||
for formatName,Cls in getFormatHandlers():
|
||||
if formatName.lower()==TexOps.format.lower():
|
||||
handler=Cls(TexOps,commands)
|
||||
break
|
||||
else:
|
||||
raise ValueError()
|
||||
return handler.readFromTable(table)
|
||||
def getMetadata(self):
|
||||
dic=OrderedDict()
|
||||
dic["Molecule"]=self.molecule
|
||||
|
@ -1,12 +1,12 @@
|
||||
from TexSoup import TexSoup,TexCmd
|
||||
from .Format import Format
|
||||
from . import formats
|
||||
from .data import dataFileBase,DataType,state
|
||||
from collections import defaultdict
|
||||
|
||||
class dfbOptions(object):
|
||||
def __init__(self):
|
||||
self.defaultType=DataType.ABS
|
||||
self.format=Format.LINE
|
||||
self.format="line"
|
||||
self.suffix=None
|
||||
self.initialStates=defaultdict(lambda : state(1,1,"A_1"))
|
||||
|
||||
@ -23,7 +23,7 @@ class dfbOptions(object):
|
||||
if dfbFormatNode!=None:
|
||||
dfbFormat=dfbFormatNode.expr
|
||||
if type(dfbFormat) is TexCmd:
|
||||
dfb_Opt.format=Format[dfbFormat.args[0].value.upper()]
|
||||
dfb_Opt.format=dfbFormat.args[0].value
|
||||
|
||||
dfbSuffixNode=lateEnv.suffix
|
||||
if dfbSuffixNode!=None:
|
||||
|
3
tools/lib/formats/__init__.py
Normal file
3
tools/lib/formats/__init__.py
Normal file
@ -0,0 +1,3 @@
|
||||
from .formatHandlerBase import formatHandlerBase
|
||||
from .formatName import formatName
|
||||
from .getFormatHandlers import getFormatHandlers
|
41
tools/lib/formats/default/TBEHandler.py
Normal file
41
tools/lib/formats/default/TBEHandler.py
Normal file
@ -0,0 +1,41 @@
|
||||
from ..formatHandlerBase import formatHandlerBase
|
||||
from ..formatName import formatName
|
||||
from ...data import dataFileBase,DataType,method,excitationValue,datafileSelector,getSubtablesRange
|
||||
from ...utils import getValFromCell, checkFloat
|
||||
@formatName("TBE")
|
||||
class TBEHandler(formatHandlerBase):
|
||||
def readFromTable(self,table):
|
||||
datalist=list()
|
||||
subtablesRange=getSubtablesRange(table)
|
||||
for myrange in subtablesRange:
|
||||
datacls=dict()
|
||||
mymolecule=str(table[myrange[0],0])
|
||||
initialState=self.TexOps.initialStates[mymolecule]
|
||||
mymethod=(method("TBE(FC)"),method("TBE"))
|
||||
finsts=dataFileBase.convertState(table[myrange,1],initialState,default=self.TexOps.defaultType,commands=self.commands)
|
||||
for index,row in enumerate(table[myrange,]):
|
||||
oscilatorForces=checkFloat(str(row[2]))
|
||||
T1 = checkFloat(str(row[3]))
|
||||
val,unsafe = getValFromCell(row[4])
|
||||
corr,unsafecorr = getValFromCell(row[7])
|
||||
finst=finsts[index]
|
||||
dt=finst[1]
|
||||
if dt in datacls:
|
||||
datamtbe = datacls[dt]
|
||||
else:
|
||||
cl=datafileSelector(dt)
|
||||
datamtbe=[]
|
||||
for met in mymethod:
|
||||
data=cl()
|
||||
data.molecule=mymolecule
|
||||
data.method=met
|
||||
datamtbe.append(data)
|
||||
datacls[dt]=datamtbe
|
||||
vs=[val,corr]
|
||||
uns=[unsafe,unsafecorr]
|
||||
for i in range(2):
|
||||
datamtbe[i].excitations.append(excitationValue(initialState,finst[0],vs[i],type=finst[2],T1=T1,oscilatorForces=oscilatorForces,isUnsafe=uns[i]))
|
||||
for value in datacls.values():
|
||||
for dat in value:
|
||||
datalist.append(dat)
|
||||
return datalist
|
6
tools/lib/formats/default/__init__.py
Normal file
6
tools/lib/formats/default/__init__.py
Normal file
@ -0,0 +1,6 @@
|
||||
from .lineHandler import lineHandler
|
||||
from .columnHandler import columnHandler
|
||||
from .doubleColumnHandler import doubleColumnHandler
|
||||
from .TBEHandler import TBEHandler
|
||||
from .doubleTBEHandler import doubleTBEHandler
|
||||
from .exoticColumnHandler import exoticColumnHandler
|
35
tools/lib/formats/default/columnHandler.py
Normal file
35
tools/lib/formats/default/columnHandler.py
Normal file
@ -0,0 +1,35 @@
|
||||
from ..formatHandlerBase import formatHandlerBase
|
||||
from ..formatName import formatName
|
||||
from ...data import dataFileBase,DataType,method,excitationValue,datafileSelector,getSubtablesRange
|
||||
from ...utils import getValFromCell
|
||||
import numpy as np
|
||||
@formatName("column")
|
||||
class columnHandler(formatHandlerBase):
|
||||
def readFromTable(self,table):
|
||||
datalist=list()
|
||||
subtablesRange=getSubtablesRange(table)
|
||||
for myrange in subtablesRange:
|
||||
for col in range(2,np.size(table,1)):
|
||||
datacls=dict()
|
||||
col=table[:,col]
|
||||
mymolecule=str(table[myrange[0],0])
|
||||
initialState=self.TexOps.initialStates[mymolecule]
|
||||
mymethod=method(str(col[1]),str(col[0]))
|
||||
finsts=dataFileBase.convertState(table[myrange,1],initialState,default=self.TexOps.defaultType,commands=self.commands)
|
||||
for index,cell in enumerate(col[myrange]):
|
||||
if str(cell)!="":
|
||||
val,unsafe=getValFromCell(cell)
|
||||
finst=finsts[index]
|
||||
dt=finst[1]
|
||||
if dt in datacls:
|
||||
data=datacls[dt]
|
||||
else:
|
||||
cl=datafileSelector(dt)
|
||||
data=cl()
|
||||
data.molecule=mymolecule
|
||||
data.method=mymethod
|
||||
datacls[dt]=data
|
||||
data.excitations.append(excitationValue(initialState,finst[0],val,type=finst[2]))
|
||||
for value in datacls.values():
|
||||
datalist.append(value)
|
||||
return datalist
|
62
tools/lib/formats/default/doubleColumnHandler.py
Normal file
62
tools/lib/formats/default/doubleColumnHandler.py
Normal file
@ -0,0 +1,62 @@
|
||||
from ..formatHandlerBase import formatHandlerBase
|
||||
from ..formatName import formatName
|
||||
from ...data import dataFileBase,DataType,method,excitationValue,datafileSelector,AbsDataFile,getSubtablesRange,state
|
||||
from ...LaTeX import newCommand,extractMath
|
||||
import re
|
||||
from TexSoup import TexSoup
|
||||
import numpy as np
|
||||
from ...utils import getValFromCell
|
||||
@formatName("doubleColumn")
|
||||
class doubleColumnHandler(formatHandlerBase):
|
||||
def readFromTable(self,table):
|
||||
datalist=list()
|
||||
datacls=dict()
|
||||
subtablesMol=getSubtablesRange(table)
|
||||
for rangeMol in subtablesMol:
|
||||
mymolecule=str(table[rangeMol[0],0])
|
||||
moltable=table[rangeMol,:]
|
||||
subtablestrans=getSubtablesRange(moltable,firstindex=0,column=1,count=2)
|
||||
for rangeTrans in subtablestrans:
|
||||
mytrans=moltable[rangeTrans,:]
|
||||
mytransdesc=mytrans[0:2,1]
|
||||
|
||||
for i in range(2):
|
||||
mathsoup=extractMath(mytransdesc[i],Soup=True,commands=self.commands)
|
||||
mytransdesc[i]=str(mathsoup)
|
||||
for colindex in range(3,np.size(table,1)):
|
||||
col=mytrans[:,colindex]
|
||||
mybasis=str(table[1,colindex])
|
||||
for index,cell in enumerate(col):
|
||||
methodnameAT1=str(mytrans[index,2])
|
||||
PTString=r"($\%T_1$)"
|
||||
HasT1=methodnameAT1.endswith(PTString)
|
||||
if HasT1:
|
||||
methodname=methodnameAT1[:-len(PTString)]
|
||||
else:
|
||||
methodname=str(methodnameAT1)
|
||||
mymethod=method(methodname,mybasis)
|
||||
strcell=str(cell)
|
||||
if strcell!="":
|
||||
if HasT1:
|
||||
m=re.match(r"^(?P<value>[-+]?\d+\.?\d*)\s*(?:\((?P<T1>\d+\.?\d*)\\\%\))?",strcell)
|
||||
val,unsafe=getValFromCell(TexSoup(m.group("value")))
|
||||
T1=m.group("T1")
|
||||
else:
|
||||
m=re.match(r"^[-+]?\d+\.?\d*",strcell)
|
||||
val,unsafe=getValFromCell(TexSoup(m.group(0)))
|
||||
T1=None
|
||||
if (mymolecule,mymethod.name,mymethod.basis) in datacls:
|
||||
data=datacls[(mymolecule,mymethod.name,mymethod.basis)]
|
||||
else:
|
||||
data=AbsDataFile()
|
||||
data.molecule=mymolecule
|
||||
data.method=mymethod
|
||||
datacls[(mymolecule,mymethod.name,mymethod.basis)]=data
|
||||
infin=mytransdesc[0].split(r"\rightarrow")
|
||||
for i,item in enumerate(infin):
|
||||
m=re.match(r"^(?P<number>\d)\\[,:;\s]\s*\^(?P<multiplicity>\d)(?P<sym>\S*)",item.strip())
|
||||
infin[i]=state(m.group("number"),m.group("multiplicity"),m.group("sym"))
|
||||
data.excitations.append(excitationValue(infin[0],infin[1],val,type=mytransdesc[1],isUnsafe=unsafe,T1=T1))
|
||||
for value in datacls.values():
|
||||
datalist.append(value)
|
||||
return datalist
|
28
tools/lib/formats/default/doubleTBEHandler.py
Normal file
28
tools/lib/formats/default/doubleTBEHandler.py
Normal file
@ -0,0 +1,28 @@
|
||||
from ..formatHandlerBase import formatHandlerBase
|
||||
from ..formatName import formatName
|
||||
from ...data import dataFileBase,DataType,method,excitationValue,datafileSelector,getSubtablesRange,AbsDataFile,state
|
||||
from ...utils import getValFromCell, checkFloat
|
||||
from ...LaTeX import newCommand,extractMath
|
||||
from TexSoup import TexSoup
|
||||
import re
|
||||
@formatName("doubleTBE")
|
||||
class doubleTBEHandler(formatHandlerBase):
|
||||
def readFromTable(self,table):
|
||||
datalist=list()
|
||||
subtablesMol=getSubtablesRange(table)
|
||||
for rangeMol in subtablesMol:
|
||||
data=AbsDataFile()
|
||||
data.molecule=str(table[rangeMol[0],0])
|
||||
data.method=method("TBE","CBS")
|
||||
for mytrans in table[rangeMol]:
|
||||
mathsoup=extractMath(mytrans[1],Soup=True,commands=self.commands)
|
||||
mytransdesc=str(mathsoup)
|
||||
infin=mytransdesc.split(r"\rightarrow")
|
||||
for i,item in enumerate(infin):
|
||||
m=re.match(r"^(?P<number>\d)\\[,:;\s]\s*\^(?P<multiplicity>\d)(?P<sym>\S*)",item.strip())
|
||||
infin[i]=state(m.group("number"),m.group("multiplicity"),m.group("sym"))
|
||||
cell=mytrans[6]
|
||||
val,unsafe=getValFromCell(cell)
|
||||
data.excitations.append(excitationValue(infin[0],infin[1],val,isUnsafe=unsafe))
|
||||
datalist.append(data)
|
||||
return datalist
|
73
tools/lib/formats/default/exoticColumnHandler.py
Normal file
73
tools/lib/formats/default/exoticColumnHandler.py
Normal file
@ -0,0 +1,73 @@
|
||||
from ..formatHandlerBase import formatHandlerBase
|
||||
from ..formatName import formatName
|
||||
from ...data import dataFileBase,DataType,method,excitationValue,datafileSelector,getSubtablesRange,state
|
||||
from ...utils import getValFromCell
|
||||
from TexSoup import TexSoup,TexNode
|
||||
from ...LaTeX import newCommand
|
||||
import numpy as np
|
||||
import json
|
||||
@formatName("exoticColumn")
|
||||
class exoticColumnHandler(formatHandlerBase):
|
||||
def readFromTable(self,table):
|
||||
datalist=list()
|
||||
subtablesRange=getSubtablesRange(table)
|
||||
for myrange in subtablesRange:
|
||||
valDic=dict()
|
||||
mymolecule=str(table[myrange[0],0])
|
||||
initialState=self.TexOps.initialStates[mymolecule]
|
||||
for col in range(2,np.size(table,1)):
|
||||
col=table[:,col]
|
||||
basis=str(col[0])
|
||||
mymethcell=list(col[1])
|
||||
if isinstance(mymethcell[0],TexNode) and mymethcell[0].name=="$":
|
||||
kindSoup=TexSoup("".join(list(mymethcell[0].expr.all)))
|
||||
newCommand.runAll(kindSoup,self.commands)
|
||||
kind=str(kindSoup)
|
||||
methodnameSoup=TexSoup(mymethcell[1].value)
|
||||
newCommand.runAll(methodnameSoup,self.commands)
|
||||
methodname=str(methodnameSoup)
|
||||
else:
|
||||
kind=""
|
||||
methtex=col[1]
|
||||
newCommand.runAll(methtex,self.commands)
|
||||
methodname=str(methtex)
|
||||
mymethod=method(methodname,basis)
|
||||
methkey=json.dumps(mymethod.__dict__)
|
||||
finsts=dataFileBase.convertState(table[myrange,1],initialState,default=self.TexOps.defaultType,commands=self.commands)
|
||||
for index,cell in enumerate(col[myrange]):
|
||||
if str(cell)!="":
|
||||
val,unsafe=getValFromCell(cell)
|
||||
finst=finsts[index]
|
||||
dt=finst[1]
|
||||
if dt in valDic:
|
||||
dtDic=valDic[dt]
|
||||
else:
|
||||
dtDic=dict()
|
||||
valDic[dt]=dtDic
|
||||
if not methkey in dtDic:
|
||||
dtDic[methkey]=dict()
|
||||
dataDic=dtDic[methkey]
|
||||
exkey=(json.dumps(finst[0].__dict__,),finst[2])
|
||||
if not exkey in dataDic:
|
||||
dataDic[exkey]=dict()
|
||||
if kind=='':
|
||||
dataDic[exkey][kind]=(val,unsafe)
|
||||
else:
|
||||
dataDic[exkey][kind]=val
|
||||
#data.excitations.append(excitationValue(initialState,finst[0],val,type=finst[2]))
|
||||
for dt,methdic in valDic.items():
|
||||
for methstring,exdic in methdic.items():
|
||||
data=datafileSelector(dt)()
|
||||
data.molecule=mymolecule
|
||||
methdic=json.loads(methstring)
|
||||
data.method=method(methdic["name"],methdic["basis"])
|
||||
for exstr,values in exdic.items():
|
||||
stDict=json.loads(exstr[0])
|
||||
ty=exstr[1]
|
||||
st=state(stDict["number"],stDict["multiplicity"],stDict["symetry"])
|
||||
T1=values["\\%T_1"] if "\\%T_1" in values else None
|
||||
oF= values["f"] if "f" in values else None
|
||||
val,unsafe=values[""]
|
||||
data.excitations.append(excitationValue(initialState,st,val,type=ty,T1=T1,isUnsafe=unsafe,oscilatorForces=oF))
|
||||
datalist.append(data)
|
||||
return datalist
|
33
tools/lib/formats/default/lineHandler.py
Normal file
33
tools/lib/formats/default/lineHandler.py
Normal file
@ -0,0 +1,33 @@
|
||||
from ..formatHandlerBase import formatHandlerBase
|
||||
from ..formatName import formatName
|
||||
from ...data import dataFileBase,DataType,method,excitationValue,datafileSelector
|
||||
from ...utils import getValFromCell
|
||||
import numpy as np
|
||||
@formatName("line")
|
||||
class lineHandler(formatHandlerBase):
|
||||
def readFromTable(self,table):
|
||||
datalist=list()
|
||||
for col in range(1,np.size(table,1)):
|
||||
col=table[:,col]
|
||||
mymolecule=str(col[0])
|
||||
mymethod=method(str(col[2]),str(col[1]))
|
||||
initialState=self.TexOps.initialStates[mymolecule]
|
||||
finsts=dataFileBase.convertState(table[3:,0],initialState,default=self.TexOps.defaultType,commands=self.commands)
|
||||
datacls=dict()
|
||||
for index,cell in enumerate(col[3:]):
|
||||
if str(cell)!="":
|
||||
val,unsafe=getValFromCell(cell)
|
||||
finst=finsts[index]
|
||||
dt=finst[1]
|
||||
if dt in datacls:
|
||||
data=datacls[dt]
|
||||
else:
|
||||
cl=datafileSelector(dt)
|
||||
data=cl()
|
||||
datacls[dt]=data
|
||||
data.molecule=mymolecule
|
||||
data.method=mymethod
|
||||
data.excitations.append(excitationValue(initialState,finst[0],val,type=finst[2],isUnsafe=unsafe))
|
||||
for value in datacls.values():
|
||||
datalist.append(value)
|
||||
return datalist
|
10
tools/lib/formats/formatHandlerBase.py
Normal file
10
tools/lib/formats/formatHandlerBase.py
Normal file
@ -0,0 +1,10 @@
|
||||
from abc import ABCMeta
|
||||
from abc import abstractmethod
|
||||
class formatHandlerBase(object):
|
||||
__metaclass__ = ABCMeta
|
||||
def __init__(self,TexOps, commands=[]):
|
||||
self.TexOps=TexOps
|
||||
self.commands=commands
|
||||
@abstractmethod
|
||||
def readFromTable(self,table):
|
||||
raise NotImplementedError()
|
5
tools/lib/formats/formatName.py
Normal file
5
tools/lib/formats/formatName.py
Normal file
@ -0,0 +1,5 @@
|
||||
def formatName(name):
|
||||
def formatWrapped(Cls):
|
||||
Cls.__formatName__=name
|
||||
return Cls
|
||||
return formatWrapped
|
11
tools/lib/formats/getFormatHandlers.py
Normal file
11
tools/lib/formats/getFormatHandlers.py
Normal file
@ -0,0 +1,11 @@
|
||||
import inspect
|
||||
from . import formatHandlerBase
|
||||
|
||||
def getFormatHandlers(includeUnnamed=False):
|
||||
from . import default
|
||||
for clsName,Cls in inspect.getmembers(default,inspect.isclass):
|
||||
if issubclass(Cls,formatHandlerBase):
|
||||
if hasattr(Cls,"__formatName__"):
|
||||
yield (Cls.__formatName__,Cls)
|
||||
elif(includeUnnamed):
|
||||
yield (None,Cls)
|
Loading…
Reference in New Issue
Block a user