10
0
mirror of https://github.com/LCPQ/QUESTDB_website.git synced 2024-11-04 21:24:00 +01:00
QUESTDB_website/tools/lib/formats/default/exoticColumnHandler.py

73 lines
3.0 KiB
Python
Raw Normal View History

2020-07-03 14:51:12 +02:00
from ..formatHandlerBase import formatHandlerBase
from ..formatName import formatName
from ...data import dataFileBase,DataType,method,excitationValue,datafileSelector,getSubtablesRange,state
2020-07-03 14:51:12 +02:00
from ...utils import getValFromCell
2020-07-04 15:41:24 +02:00
from TexSoup import TexSoup,TexNode
2020-07-03 14:51:12 +02:00
from ...LaTeX import newCommand
2020-07-04 15:41:24 +02:00
import numpy as np
2020-07-03 14:51:12 +02:00
import json
@formatName("exoticColumn")
class exoticColumnHandler(formatHandlerBase):
def readFromTable(self,table):
datalist=list()
subtablesRange=getSubtablesRange(table)
for myrange in subtablesRange:
2020-07-03 14:51:12 +02:00
valDic=dict()
mymolecule=str(table[myrange[0],0])
2020-07-04 15:41:24 +02:00
initialState=self.TexOps.initialStates[mymolecule]
2020-07-03 14:51:12 +02:00
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)))
2020-10-08 18:41:13 +02:00
newCommand.runAll(kindSoup,self.Commands)
2020-07-03 14:51:12 +02:00
kind=str(kindSoup)
methodnameSoup=TexSoup(mymethcell[1].value)
2020-10-08 18:41:13 +02:00
newCommand.runAll(methodnameSoup,self.Commands)
2020-07-03 14:51:12 +02:00
methodname=str(methodnameSoup)
else:
kind=""
methtex=col[1]
2020-10-08 18:41:13 +02:00
newCommand.runAll(methtex,self.Commands)
2020-07-03 14:51:12 +02:00
methodname=str(methtex)
mymethod=method(methodname,basis)
methkey=json.dumps(mymethod.__dict__)
2020-10-08 18:41:13 +02:00
finsts=dataFileBase.convertState(table[myrange,1],initialState,default=self.TexOps.defaultType,commands=self.Commands)
for index,cell in enumerate(col[myrange]):
2020-07-03 14:51:12 +02:00
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():
2020-08-03 16:25:10 +02:00
data=datafileSelector(dt)()
2020-07-03 14:51:12 +02:00
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]
2020-09-30 14:18:34 +02:00
st=state(stDict["number"],stDict["multiplicity"],stDict["symmetry"])
2020-07-03 14:51:12 +02:00
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