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/doubleTBEHandler.py

33 lines
1.3 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,AbsDataFile,state
2020-07-03 14:51:12 +02:00
from ...utils import getValFromCell, checkFloat
from ...LaTeX import newCommand
from TexSoup import TexSoup
import re
@formatName("doubleTBE")
class doubleTBEHandler(formatHandlerBase):
def readFromTable(self,table):
datalist=list()
subtablesMol=getSubtablesRange(table)
for rangeMol in subtablesMol:
2020-07-03 14:51:12 +02:00
data=AbsDataFile()
data.molecule=str(table[rangeMol,0])
2020-07-03 14:51:12 +02:00
data.method=method("TBE","CBS")
for mytrans in table[rangeMol]:
2020-07-03 14:51:12 +02:00
try:
mathsoup=TexSoup(mytrans[1])
except:
print(f"Error when parsing latex state: {str(mytransdesc[i])}")
exit(-1)
2020-07-08 13:24:29 +02:00
newCommand.runAll(mathsoup,self.commands)
2020-07-03 14:51:12 +02:00
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