ARC代码计算一

文章介绍了如何使用Python编程,通过正则表达式解析输入的原子能级信息,进行波长、频率、矩阵元素和速率的计算,涉及Cs和Rb两种元素的电子跃迁.
摘要由CSDN通过智能技术生成

两个状态之间的基本计算

import sys, os
from arc import *
from arc.web_functionality import *
import re

# 输入字符串-按照三个计算固定的格式进行输入
input_str = input('请输入')

# 定义正则表达式模式-按照正确的格式进行读取,将所输入的内容进行提取
pattern = r"([A-Za-z]+) (\d+) ([A-Za-z]+)_(\{[0-9/]+\})->(\d+) ([A-Za-z]+)_(\{[0-9/]+\})"

# 使用正则表达式匹配-在这里要把提取出的东西,需要把其中的内容,转化为字符型、浮点型以及整数型
match = re.match(pattern, input_str)

if match:
    # 提取匹配的部分
    element = match.group(1)  # Cs
    n1 = int(match.group(2))  # 60
    l1 = match.group(3)  # S
    j1 = match.group(4)  # {1/2}
    n2 = int(match.group(5))  # 60
    l2 = match.group(6)  # P
    j2 = match.group(7)  # {3/2}

    
else:
    print("No match found.")
    
print(input_str)

#判断是Cs还是Rb
if element=='Cs':    
    atom = Caesium()
else:
    atom = Rubidium()
    
    
# 判断子能级字母并转换为相应的数值
if l1 == "S":
    l1 = 0
elif l1 == "P":
    l1 = 1
elif l1 == "D":
    l1 = 2
elif l1 == "F":
    l1 = 3

if l2 == "S":
    l2 = 0
elif l2 == "P":
    l2 = 1
elif l2 == "D":
    l2 = 2
elif l2 == "F":
    l2 = 3
    
    
#把{1/2}提取出来,成为1/2
import re

    # 定义正则表达式模式
pattern = r"\{(\d+)/(\d+)\}"

    # 使用正则表达式匹配
match = re.match(pattern, j1)
match1 = re.match(pattern, j2)

# if match:
numerator = int(match.group(1))  # 提取分子
denominator = int(match.group(2))  # 提取分母
numerator1 = int(match1.group(1))  # 提取分子
denominator1 = int(match1.group(2))  # 提取分母

    # 计算分数的值
j1 = numerator / denominator
j2 = numerator1 / denominator1


# Initial State
n1 = int(n1)
l1 = int(l1)
j1 = float(j1)
# Final State
n2 = int(n2)
l2 = int(l2)
j2 = float(j2)

# 打印提取的信息——这里是用于检查错误,查看你的代码是否出现问题
#print("Element:", element)
#print("N1:", n1)
#print("L1:", l1)
#print("J1:", j1)
#print("N2:", n2)
#print("L2:", l2)
#print("J2:", j2)

if __name__ == '__main__':

    atom = atom
    
    #主要计算代码
    print('计算波长频率以及偶极矩参数2 倒转参数')
    print('Wavelength')
             print((printValueString(atom.getTransitionWavelength(n1,l1,j1,n2,l2,j2),'m',decimalPlaces=5)))
    print('Frequency')
    print((printValueString(atom.getTransitionFrequency(n1,l1,j1,n2,l2,j2),'Hz',decimalPlaces=5)))
    print('Radia part')
    print((atom.getRadialMatrixElement(n1,l1,j1,n2,l2,j2)))
    print('Reduced dipole matrix element 1')
    print((atom.getReducedMatrixElementJ(n1,l1,j1,n2,l2,j2)) )
    print('Reduced dipole matrix element 2')
    valued = atom.getReducedMatrixElementJ_asymmetric(n1,l1,j1,n2,l2,j2)
    print((valued) )
    
    
    
    print('计算速率2')
    a,b,c = atom.getLiteratureDME(n1,l1,j1,n2,l2,j2)
    if (a): htmlLiteratureOutput(b,c)
    rate400 = atom.getTransitionRate(n1,l1,j1,n2,l2,j2, temperature=400.)
    if (rate400>1.e-2):
        print('0K')
        print(atom.getTransitionRate(n1,l1,j1,n2,l2,j2, temperature=0.))
        print('200K')
        print(atom.getTransitionRate(n1,l1,j1,n2,l2,j2, temperature=200.))
        print('300K')
        print(atom.getTransitionRate(n1,l1,j1,n2,l2,j2, temperature=300.))
        print('400K')
        print(atom.getTransitionRate(n1,l1,j1,n2,l2,j2, temperature=400.))
        

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值