PySRIM的抽象执行器
项目描述
pysrim-docker
PySRIM的Docker执行器
入门指南
要使用此包,只需删除对SR
和TRIM
的run()
方法的调用,并用执行器的run
调度方法调用替换,例如:
from srim.executor import DockerExecutor
from srim import TRIM
executor = DockerExecutor()
trim = TRIM(...)
result = executor.run(trim)
默认情况下,DockerExecutor
使用costrouc/srim
Docker镜像,并将输入和输出文件写入临时目录。
示例
from srim.executor import DockerExecutor
from srim import Ion, Layer, Target, TRIM
from matplotlib import pyplot as plt
# Construct a 3MeV Nickel ion
ion = Ion('Ni', energy=3.0e6)
# Construct a layer of nick 20um thick with a displacement energy of 30 eV
layer = Layer({
'Ni': {
'stoich': 1.0,
'E_d': 30.0,
'lattice': 0.0,
'surface': 3.0
}}, density=8.9, width=20000.0)
# Construct a target of a single layer of Nickel
target = Target([layer])
# Initialize a TRIM calculation with given target and ion for 25 ions, quick calculation
trim = TRIM(target, ion, number_ions=25, calculation=1)
# Create executor and run TRIM
executor = DockerExecutor()
result = executor.run(trim)
# Pull out ionization
ioniz = result.ioniz
# Plot results
_, ax = plt.subplots()
ax.plot(ioniz.depth, ioniz.ions, label='Ionization from Ions')
ax.plot(ioniz.depth, ioniz.recoils, label='Ionization from Recoils')
plt.show()
为什么?
SRIM可以通过多种方式调用以运行模拟。类Unix操作系统用户可以选择使用带有或不带有xvfb
的wine
。Windows用户可以直接调用二进制文件。Docker用户可以选择使用预先构建的SRIM容器。
通过将执行器从SRIM输入文件生成中抽象出来,可以轻松地交换或扩展执行器。