mirror of
https://github.com/LCPQ/QUESTDB_website.git
synced 2025-01-12 05:58:23 +01:00
Add firstStates parameter
This commit is contained in:
parent
9e387e0415
commit
e5a789ba93
@ -7,7 +7,8 @@ from pathlib import Path
|
|||||||
from lib import LaTeX
|
from lib import LaTeX
|
||||||
from lib.Format import Format
|
from lib.Format import Format
|
||||||
from TexSoup import TexSoup,TexCmd
|
from TexSoup import TexSoup,TexCmd
|
||||||
from lib.data import dataFileBase,DataType
|
from lib.data import dataFileBase,DataType,state
|
||||||
|
from collections import defaultdict
|
||||||
import argparse
|
import argparse
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('--file', type=argparse.FileType('r'))
|
parser.add_argument('--file', type=argparse.FileType('r'))
|
||||||
@ -16,7 +17,7 @@ args = parser.parse_args()
|
|||||||
lines=args.file.readlines()
|
lines=args.file.readlines()
|
||||||
soup=TexSoup(lines)
|
soup=TexSoup(lines)
|
||||||
opt=soup.dfbOptions
|
opt=soup.dfbOptions
|
||||||
dfb_Opt= {"defaultType":DataType.ABS,"format":Format.LINE,"suffix":None}
|
dfb_Opt= {"defaultType":DataType.ABS,"format":Format.LINE,"suffix":None,"firstStates":defaultdict(lambda : state(1,1,"A_1"))}
|
||||||
dfbDefaultTypeNode=opt.defaultType
|
dfbDefaultTypeNode=opt.defaultType
|
||||||
if dfbDefaultTypeNode!=None:
|
if dfbDefaultTypeNode!=None:
|
||||||
dfbDefaultType=dfbDefaultTypeNode.expr
|
dfbDefaultType=dfbDefaultTypeNode.expr
|
||||||
@ -34,6 +35,18 @@ if dfbSuffixNode!=None:
|
|||||||
dfbSuffix=dfbSuffixNode.expr
|
dfbSuffix=dfbSuffixNode.expr
|
||||||
if type(dfbSuffix) is TexCmd:
|
if type(dfbSuffix) is TexCmd:
|
||||||
dfb_Opt["suffix"]=dfbSuffix.args[0].value
|
dfb_Opt["suffix"]=dfbSuffix.args[0].value
|
||||||
|
dfbFirstStateNodes=list(opt.find_all("firstState"))
|
||||||
|
for node in dfbFirstStateNodes:
|
||||||
|
firstState=node.expr
|
||||||
|
if type(firstState) is TexCmd:
|
||||||
|
vRArgs=[arg.value for arg in firstState.args if arg.type=="required"]
|
||||||
|
vOArgs=[arg.value for arg in firstState.args if arg.type=="optional"]
|
||||||
|
if len(vOArgs)==0:
|
||||||
|
defaultstate=state.fromString(vRArgs[0])
|
||||||
|
dfb_Opt["firstStates"].default_factory=lambda : defaultstate
|
||||||
|
else:
|
||||||
|
mystate=state.fromString(vRArgs[0])
|
||||||
|
dfb_Opt["firstStates"][vOArgs[0]]=mystate
|
||||||
commands=[LaTeX.newCommand(cmd) for cmd in soup.find_all("newcommand")]
|
commands=[LaTeX.newCommand(cmd) for cmd in soup.find_all("newcommand")]
|
||||||
dat=LaTeX.tabularToData(soup.tabular,commands)
|
dat=LaTeX.tabularToData(soup.tabular,commands)
|
||||||
scriptpath=Path(sys.argv[0]).resolve()
|
scriptpath=Path(sys.argv[0]).resolve()
|
||||||
@ -42,6 +55,6 @@ if args.debug:
|
|||||||
datapath=datapath/"test"
|
datapath=datapath/"test"
|
||||||
if not datapath.exists():
|
if not datapath.exists():
|
||||||
datapath.mkdir()
|
datapath.mkdir()
|
||||||
datalst=dataFileBase.readFromTable(dat,format=dfb_Opt["format"],default=dfb_Opt["defaultType"],commands=commands)
|
datalst=dataFileBase.readFromTable(dat,dfb_Opt["firstStates"],format=dfb_Opt["format"],default=dfb_Opt["defaultType"],commands=commands)
|
||||||
for data in datalst:
|
for data in datalst:
|
||||||
data.toFile(datapath,dfb_Opt["suffix"])
|
data.toFile(datapath,dfb_Opt["suffix"])
|
@ -14,8 +14,13 @@ class state:
|
|||||||
self.number = number
|
self.number = number
|
||||||
self.multiplicity = multiplicity
|
self.multiplicity = multiplicity
|
||||||
self.symetry = symetry
|
self.symetry = symetry
|
||||||
|
@staticmethod
|
||||||
|
def fromString(string):
|
||||||
|
m=re.match(r"^(?P<number>\d)\s*\^(?P<multiplicity>\d)(?P<sym>\S*)",string)
|
||||||
|
num=m.group('number')
|
||||||
|
mul=m.group('multiplicity')
|
||||||
|
sym=m.group('sym')
|
||||||
|
return state(num,mul,sym)
|
||||||
@unique
|
@unique
|
||||||
class DataType(IntEnum):
|
class DataType(IntEnum):
|
||||||
ABS=auto()
|
ABS=auto()
|
||||||
@ -38,7 +43,7 @@ class dataFileBase(object):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def convertState(StateTablelist,default=DataType.ABS,firstState=state(1,1,"A_1"),commands=[]):
|
def convertState(StateTablelist,firstState,default=DataType.ABS,commands=[]):
|
||||||
tmplst=[]
|
tmplst=[]
|
||||||
for TexState in StateTablelist:
|
for TexState in StateTablelist:
|
||||||
math=TexState.find("$")
|
math=TexState.find("$")
|
||||||
@ -71,9 +76,8 @@ class dataFileBase(object):
|
|||||||
count=countlst.count(countitem)
|
count=countlst.count(countitem)
|
||||||
lst.append((state(count,item[0],item[1]),item[2],item[3]))
|
lst.append((state(count,item[0],item[1]),item[2],item[3]))
|
||||||
return lst
|
return lst
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def readFromTable(table,format=Format.LINE,default=DataType.ABS ,firstState=state(1,1,"A_1"),commands=[]):
|
def readFromTable(table,firstStates,format=Format.LINE,default=DataType.ABS, commands=[]):
|
||||||
def getSubtableIndex(table,firstindex=2,column=0,count=1):
|
def getSubtableIndex(table,firstindex=2,column=0,count=1):
|
||||||
subtablesindex=list()
|
subtablesindex=list()
|
||||||
i=firstindex+count
|
i=firstindex+count
|
||||||
@ -97,7 +101,8 @@ class dataFileBase(object):
|
|||||||
col=table[:,col]
|
col=table[:,col]
|
||||||
mymolecule=str(col[0])
|
mymolecule=str(col[0])
|
||||||
mymethod=method(str(col[2]),str(col[1]))
|
mymethod=method(str(col[2]),str(col[1]))
|
||||||
finsts=dataFileBase.convertState(table[3:,0],default=default,firstState=firstState,commands=commands)
|
firstState=firstStates[mymolecule]
|
||||||
|
finsts=dataFileBase.convertState(table[3:,0],firstState,default=default,commands=commands)
|
||||||
datacls=dict()
|
datacls=dict()
|
||||||
for index,cell in enumerate(col[3:]):
|
for index,cell in enumerate(col[3:]):
|
||||||
if str(cell)!="":
|
if str(cell)!="":
|
||||||
@ -123,8 +128,9 @@ class dataFileBase(object):
|
|||||||
datacls=dict()
|
datacls=dict()
|
||||||
col=table[:,col]
|
col=table[:,col]
|
||||||
mymolecule=str(table[first,0])
|
mymolecule=str(table[first,0])
|
||||||
|
firstState=firstStates[mymolecule]
|
||||||
mymethod=method(str(col[1]),str(col[0]))
|
mymethod=method(str(col[1]),str(col[0]))
|
||||||
finsts=dataFileBase.convertState(table[first:last+1,1],default=default,firstState=firstState,commands=commands)
|
finsts=dataFileBase.convertState(table[first:last+1,1],firstState,default=default,commands=commands)
|
||||||
for index,cell in enumerate(col[first:last+1]):
|
for index,cell in enumerate(col[first:last+1]):
|
||||||
if str(cell)!="":
|
if str(cell)!="":
|
||||||
val,unsafe=getValFromCell(cell)
|
val,unsafe=getValFromCell(cell)
|
||||||
@ -203,6 +209,7 @@ class dataFileBase(object):
|
|||||||
for first, last in subtablesindex:
|
for first, last in subtablesindex:
|
||||||
valDic=dict()
|
valDic=dict()
|
||||||
mymolecule=str(table[first,0])
|
mymolecule=str(table[first,0])
|
||||||
|
firstState=firstStates[mymolecule]
|
||||||
for col in range(2,np.size(table,1)):
|
for col in range(2,np.size(table,1)):
|
||||||
col=table[:,col]
|
col=table[:,col]
|
||||||
basis=str(col[0])
|
basis=str(col[0])
|
||||||
@ -221,7 +228,7 @@ class dataFileBase(object):
|
|||||||
methodname=str(methtex)
|
methodname=str(methtex)
|
||||||
mymethod=method(methodname,basis)
|
mymethod=method(methodname,basis)
|
||||||
methkey=json.dumps(mymethod.__dict__)
|
methkey=json.dumps(mymethod.__dict__)
|
||||||
finsts=dataFileBase.convertState(table[first:last+1,1],default=default,firstState=firstState,commands=commands)
|
finsts=dataFileBase.convertState(table[first:last+1,1],firstState,default=default,commands=commands)
|
||||||
for index,cell in enumerate(col[first:last+1]):
|
for index,cell in enumerate(col[first:last+1]):
|
||||||
if str(cell)!="":
|
if str(cell)!="":
|
||||||
val,unsafe=getValFromCell(cell)
|
val,unsafe=getValFromCell(cell)
|
||||||
@ -264,8 +271,9 @@ class dataFileBase(object):
|
|||||||
for first, last in subtablesindex:
|
for first, last in subtablesindex:
|
||||||
datacls=dict()
|
datacls=dict()
|
||||||
mymolecule=str(table[first,0])
|
mymolecule=str(table[first,0])
|
||||||
|
firstState=firstStates[mymolecule]
|
||||||
mymethod=(method("TBE(FC)"),method("TBE"))
|
mymethod=(method("TBE(FC)"),method("TBE"))
|
||||||
finsts=dataFileBase.convertState(table[first:last+1,1],default=default,firstState=firstState,commands=commands)
|
finsts=dataFileBase.convertState(table[first:last+1,1],firstState,default=default,commands=commands)
|
||||||
for index,row in enumerate(table[first:last+1,]):
|
for index,row in enumerate(table[first:last+1,]):
|
||||||
oscilatorForces=checkFloat(str(row[2]))
|
oscilatorForces=checkFloat(str(row[2]))
|
||||||
T1 = checkFloat(str(row[3]))
|
T1 = checkFloat(str(row[3]))
|
||||||
|
Loading…
Reference in New Issue
Block a user