引用所需要的python包之后,同计算一一样,按照输入格式输入后,被正常读取。然后转化格式,得到正确的浮点型以及整数型。然后带入计算函数就可以。
import sys, os
import re
from arc import *
from arc.web_functionality import *
def transitTime (beam_waist,mean_speed):
# in s
beam_fwhm = beam_waist / 0.8493218
return sqrt(pi)*beam_fwhm/(2.*mean_speed)
# 输入
input_str = input('请输入')
#Cs 24 S_{1/2} 1/2 0-600 V/cm
#Cs 30 S_{1/2} 1/2 0-200 V/cm
#读取输入的信息
import re
pattern = r"([A-Za-z]+) (\d+) ([A-Za-z]+)_(\{[0-9/]+\}) (\d+)/(\d+) (\d+)-(\d+) V/cm"
# 使用 re.match 匹配模式
match = re.match(pattern, input_str)
if match:
# 提取匹配的信息
element = match.group(1)
n0 = int(match.group(2))
l0 = match.group(3)
j0 = match.group(4)#字符{1/2}
mj0 = float(match.group(5))/float(match.group(6))
Emin = int(match.group(7))
Emax = int(match.group(8))
#说明白你要算谁 Cs还是Rb
if element=='Cs':
calc = StarkMap(Caesium())
else:
calc = StarkMap(Rubidium())
# 判断子能级字母并转换为相应的数值
if l0 == "S":
l0 = 0
elif l0 == "P":
l0 = 1
elif l0 == "D":
l0 = 2
elif l0 == "F":
l0 = 3
#把{1/2}提取出来,成为1/2
import re
# 定义正则表达式模式
pattern = r"\{(\d+)/(\d+)\}"
# 使用正则表达式匹配
match = re.match(pattern, j0)
# if match:
numerator = int(match.group(1)) # 提取分子
denominator = int(match.group(2)) # 提取分母
# 计算分数的值
j0 = numerator / denominator
# Target state
n0 = n0
l0 = l0
j0 = float(j0)
mj0 = float(mj0)
# 打印提取的信息
print("Element:", element)
print("N0:", n0)
print("L0:", l0)
print("J0:", j0)
print("Mj0:", mj0)
print("Emin:", Emin)
print("Emax:", Emax)
#这里根据论文,nmax以及nmin对应着你输入的n加减5,而lmax直接取20
# 定义n的最大值和最小值—
nmax = n0+5
nmin = n0-5
# 轨道量子数最大值,这里是系统的推荐数值
lmax = 20
#所以说这的E一定记得要乘100倍,否则画不出正确的stark映射
Emin = Emin*100 # 电场最小值
Emax = Emax*100 # 电场最大值,这里输入的E单位是V/m,但是输入的是V/cm
N = 1001 # 散点数目
calc.defineBasis(n0, l0, j0, mj0, nmin, nmax, lmax, progressOutput=True)
# 制造斯塔克映射
calc.diagonalise(np.linspace(Emin, Emax, N), progressOutput=True)
# 画斯塔克映射
calc.plotLevelDiagram(progressOutput=True, units=1, highlightState=True)
calc.showPlot(interactive=False)
# 返回目标状态极化率
print(
"%.5f MHz cm^2 / V^2 "
% calc.getPolarizability(showPlot=True, minStateContribution=0.9)
)
else:
print("No match found.")