10
0
mirror of https://github.com/LCPQ/QUESTDB_website.git synced 2024-08-25 05:31:51 +02:00

Add suport of F in table to specify fluorescence data

This commit is contained in:
Mickaël Véril 2019-11-23 18:08:27 +01:00
parent f66d0c8be7
commit 9c18598f82
2 changed files with 56 additions and 35 deletions

View File

@ -7,12 +7,12 @@ from pathlib import Path
from lib import LaTeX from lib import LaTeX
from lib.Orientation import Orientation from lib.Orientation import Orientation
from TexSoup import TexSoup from TexSoup import TexSoup
from lib.data import AbsDataFile,ZPEDataFile,FluoDataFile,dataType from lib.data import dataFileBase,dataType
import argparse import argparse
DEBUG=True DEBUG=False
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('--file', type=argparse.FileType('r')) parser.add_argument('--file', type=argparse.FileType('r'))
parser.add_argument('--type', type=str, choices=[t.name for t in list(dataType)]) parser.add_argument('--defaultType', type=str, choices=[t.name for t in list(dataType)])
parser.add_argument('--MoleculeOrentation',type=str, choices=[t.name for t in list(Orientation)],default=Orientation.LINE.name) parser.add_argument('--MoleculeOrentation',type=str, choices=[t.name for t in list(Orientation)],default=Orientation.LINE.name)
args = parser.parse_args() args = parser.parse_args()
print(args) print(args)
@ -26,12 +26,6 @@ if DEBUG:
datapath=datapath/"test" datapath=datapath/"test"
if not datapath.exists(): if not datapath.exists():
datapath.mkdir() datapath.mkdir()
switcher={ datalst=dataFileBase.readFromTable(dat,orientation=Orientation[args.MoleculeOrentation],default=dataType[args.defaultType])
dataType.ABS: AbsDataFile,
dataType.FLUO: FluoDataFile,
dataType.ZPE: ZPEDataFile
}
filecls=switcher.get(dataType[args.type])
datalst=filecls.readFromTable(dat,Orientation[args.MoleculeOrentation])
for data in datalst: for data in datalst:
data.toFile(datapath) data.toFile(datapath)

View File

@ -30,37 +30,56 @@ class dataFileBase(object):
pass pass
@staticmethod @staticmethod
def convertState(StateTablelist,firstState=state(1,1,"A_1")): def convertState(StateTablelist,default=dataType.ABS,firstState=state(1,1,"A_1")):
tmplst=[] tmplst=[]
for TexState in StateTablelist: for TexState in StateTablelist:
trtype=default
lst=list(TexState.find("$").contents) lst=list(TexState.find("$").contents)
st=str(lst[0]) st=str(lst[0])
m=re.match(r"^\^(?P<multiplicity>\d)(?P<symm>[^\s\[(]*)\s*(?:\[(?:\\mathrm{)?(?P<special>\w)(?:})\])?\s*\((?P<type>[^\)]*)\)",st) m=re.match(r"^\^(?P<multiplicity>\d)(?P<symm>[^\s\[(]*)\s*(?:\[(?:\\mathrm{)?(?P<special>\w)(?:})\])?\s*\((?P<type>[^\)]*)\)",st)
seq=m.group("multiplicity","symm") seq=m.group("multiplicity","symm")
tmplst.append(seq) spgrp=m.group("special")
if spgrp is not None and spgrp=="F":
trtype=dataType.FLUO
tmplst.append((*seq,trtype))
lst=[] lst=[]
for index,item in enumerate(tmplst): for index,item in enumerate(tmplst):
unformfirststate=(str(firstState.multiplicity),firstState.symetry) unformfirststate=(str(firstState.multiplicity),firstState.symetry)
count=([unformfirststate]+tmplst[:index+1]).count(item) count=([unformfirststate]+tmplst[:index+1]).count(item)
lst.append(state(count,int(item[0]),item[1])) lst.append((state(count,int(item[0]),item[1]),item[2]))
return lst return lst
@classmethod @staticmethod
def readFromTable(cls, table,orientation=Orientation.LINE ,firstState=state(1,1,"A_1")): def readFromTable(table,orientation=Orientation.LINE,default=dataType.ABS ,firstState=state(1,1,"A_1")):
datalist=list() datalist=list()
switcher={
dataType.ABS:AbsDataFile,
dataType.FLUO:FluoDataFile,
dataType.ZPE:ZPEDataFile
}
if orientation==Orientation.LINE: if orientation==Orientation.LINE:
for col in range(1,np.size(table,1)): for col in range(1,np.size(table,1)):
data=cls()
col=table[:,col] col=table[:,col]
data.molecule=str(col[0]) mymolecule=str(col[0])
data.method=method(str(col[2]),str(col[1])) mymethod=method(str(col[2]),str(col[1]))
finsts=cls.convertState(table[3:,0],firstState) finsts=dataFileBase.convertState(table[3:,0],firstState)
datacls=dict()
for index,cell in enumerate(col[3:]): for index,cell in enumerate(col[3:]):
if str(cell)!="": if str(cell)!="":
val= list(cell.contents)[0] val= list(cell.contents)[0]
val=float(str(val)) val=float(str(val))
data.excitations.append(excitationValue(firstState,finsts[index],val)) finst=finsts[index]
datalist.append(data) dt=finst[1]
if dt in datacls:
data=datacls[dt]
else:
cl=switcher[dt]
data=cl()
data.molecule=mymolecule
data.method=mymethod
data.excitations.append(excitationValue(firstState,finst[0],val))
for value in datacls.values():
datalist.append(value)
return datalist return datalist
else: else:
subtablesindex=list() subtablesindex=list()
@ -71,17 +90,33 @@ class dataFileBase(object):
firstindex=i firstindex=i
for first, last in subtablesindex: for first, last in subtablesindex:
for col in range(2,np.size(table,1)): for col in range(2,np.size(table,1)):
data=cls()
col=table[:,col] col=table[:,col]
data.molecule=str(table[first,0]) mymolecule=str(table[first,0])
data.method=method(str(col[1]),str(col[0])) mymethod=method(str(col[1]),str(col[0]))
finsts=cls.convertState(table[first:last+1,1],firstState) finsts=dataFileBase.convertState(table[first:last+1,1],default=default,firstState=firstState)
for col in range(2,np.size(table,1)):
datacls=dict()
col=table[:,col]
mymolecule=str(table[first,0])
mymethod=method(str(col[1]),str(col[0]))
finsts=dataFileBase.convertState(table[first:last+1,1],default=default,firstState=firstState)
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= list(cell.contents)[0] val= list(cell.contents)[0]
val=float(str(val)) val=float(str(val))
data.excitations.append(excitationValue(firstState,finsts[index],val)) finst=finsts[index]
datalist.append(data) 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(firstState,finst[0],val))
for value in datacls.values():
datalist.append(value)
return datalist return datalist
def getMetadata(self): def getMetadata(self):
dic=OrderedDict() dic=OrderedDict()
@ -156,10 +191,6 @@ class oneStateDataFileBase(dataFileBase):
dic.move_to_end("DOI") dic.move_to_end("DOI")
return dic return dic
@classmethod
def readFromTable(cls, table,orientation=Orientation.LINE,firstState=state(1,1,"A_1")):
data=super().readFromTable(table,orientation,firstState=firstState)
return data
class AbsDataFile(oneStateDataFileBase): class AbsDataFile(oneStateDataFileBase):
def __init__(self): def __init__(self):
super(AbsDataFile,self).__init__() super(AbsDataFile,self).__init__()
@ -182,10 +213,6 @@ class twoStateDataFileBase(dataFileBase):
self.GS=None self.GS=None
self.ES=None self.ES=None
@classmethod
def readFromTable(cls, table,orientation=Orientation.LINE,firstState=state(1,1,"A_1")):
data=super().readFromTable(table,Orientation,firstState=firstState)
return data
def getMetadata(self): def getMetadata(self):
dic=super(twoStateDataFileBase,self).getMetadata() dic=super(twoStateDataFileBase,self).getMetadata()
dic["GS"]= "" if self.GS is None else self.GS.toDataString() dic["GS"]= "" if self.GS is None else self.GS.toDataString()