10
0
mirror of https://github.com/LCPQ/QUESTDB_website.git synced 2024-11-04 05:03:53 +01:00

Fix undefined

This commit is contained in:
Mickaël Véril 2020-07-08 13:24:29 +02:00
parent 76559d21db
commit 2e2080c2a1
2 changed files with 57 additions and 54 deletions

View File

@ -1,63 +1,66 @@
from ..formatHandlerBase import formatHandlerBase from ..formatHandlerBase import formatHandlerBase
from ..formatName import formatName from ..formatName import formatName
from ...data import dataFileBase,DataType,method,excitationValue,datafileSelector,AbsDataFile,getSubtablesRange from ...data import dataFileBase,DataType,method,excitationValue,datafileSelector,AbsDataFile,getSubtablesRange,state
from ...LaTeX import newCommand from ...LaTeX import newCommand
import re import re
from TexSoup import TexSoup
import numpy as np
from ...utils import getValFromCell from ...utils import getValFromCell
@formatName("doubleColumn") @formatName("doubleColumn")
class doubleColumnHandler(formatHandlerBase): class doubleColumnHandler(formatHandlerBase):
def readFromTable(self,table): def readFromTable(self,table):
datacls=dict() datalist=list()
subtablesMol=getSubtablesRange(table) datacls=dict()
for rangeMol in subtablesMol: subtablesMol=getSubtablesRange(table)
mymolecule=str(table[rangeMol[0],0]) for rangeMol in subtablesMol:
moltable=table[rangeMol,:] mymolecule=str(table[rangeMol[0],0])
subtablestrans=getSubtablesRange(moltable,firstindex=0,column=1,count=2) moltable=table[rangeMol,:]
for rangeTrans in subtablestrans: subtablestrans=getSubtablesRange(moltable,firstindex=0,column=1,count=2)
mytrans=moltable[rangeTrans,:] for rangeTrans in subtablestrans:
mytransdesc=mytrans[0:2,1] mytrans=moltable[rangeTrans,:]
for i in range(2): mytransdesc=mytrans[0:2,1]
try: for i in range(2):
mathsoup=TexSoup(mytransdesc[i]) try:
except: mathsoup=TexSoup(mytransdesc[i])
print(f"Error when parsing latex state: {str(mytransdesc[i])}") except:
exit(-1) print(f"Error when parsing latex state: {str(mytransdesc[i])}")
newCommand.runAll(mathsoup,commands) exit(-1)
mytransdesc[i]=str(mathsoup) newCommand.runAll(mathsoup,self.commands)
for colindex in range(3,np.size(table,1)): mytransdesc[i]=str(mathsoup)
col=mytrans[:,colindex] for colindex in range(3,np.size(table,1)):
mybasis=str(table[1,colindex]) col=mytrans[:,colindex]
for index,cell in enumerate(col): mybasis=str(table[1,colindex])
methodnameAT1=str(mytrans[index,2]) for index,cell in enumerate(col):
PTString=r"($\%T_1$)" methodnameAT1=str(mytrans[index,2])
HasT1=methodnameAT1.endswith(PTString) 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: if HasT1:
methodname=methodnameAT1[:-len(PTString)] 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: else:
methodname=str(methodnameAT1) m=re.match(r"^[-+]?\d+\.?\d*",strcell)
mymethod=method(methodname,mybasis) val,unsafe=getValFromCell(TexSoup(m.group(0)))
strcell=str(cell) T1=None
if strcell!="": if (mymolecule,mymethod.name,mymethod.basis) in datacls:
if HasT1: data=datacls[(mymolecule,mymethod.name,mymethod.basis)]
m=re.match(r"^(?P<value>[-+]?\d+\.?\d*)\s*(?:\((?P<T1>\d+\.?\d*)\\\%\))?",strcell) else:
val,unsafe=getValFromCell(TexSoup(m.group("value"))) data=AbsDataFile()
T1=m.group("T1") data.molecule=mymolecule
else: data.method=mymethod
m=re.match(r"^[-+]?\d+\.?\d*",strcell) datacls[(mymolecule,mymethod.name,mymethod.basis)]=data
val,unsafe=getValFromCell(TexSoup(m.group(0))) infin=mytransdesc[0].split(r"\rightarrow")
T1=None for i,item in enumerate(infin):
if (mymolecule,mymethod.name,mymethod.basis) in datacls: m=re.match(r"^(?P<number>\d)\\[,:;\s]\s*\^(?P<multiplicity>\d)(?P<sym>\S*)",item.strip())
data=datacls[(mymolecule,mymethod.name,mymethod.basis)] infin[i]=state(m.group("number"),m.group("multiplicity"),m.group("sym"))
else: data.excitations.append(excitationValue(infin[0],infin[1],val,type=mytransdesc[1],isUnsafe=unsafe,T1=T1))
data=AbsDataFile() for value in datacls.values():
data.molecule=mymolecule datalist.append(value)
data.method=mymethod return datalist
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

View File

@ -20,7 +20,7 @@ class doubleTBEHandler(formatHandlerBase):
except: except:
print(f"Error when parsing latex state: {str(mytransdesc[i])}") print(f"Error when parsing latex state: {str(mytransdesc[i])}")
exit(-1) exit(-1)
newCommand.runAll(mathsoup,commands) newCommand.runAll(mathsoup,self.commands)
mytransdesc=str(mathsoup) mytransdesc=str(mathsoup)
infin=mytransdesc.split(r"\rightarrow") infin=mytransdesc.split(r"\rightarrow")
for i,item in enumerate(infin): for i,item in enumerate(infin):