新建
abTEM仿真图像批量生成
OrangeFree
推荐镜像 :Basic Image:ubuntu20.04-py3.10-cuda11.6
推荐机型 :c12_m92_1 * NVIDIA V100
赞
1
目录
MoS2
代码
文本
[1]
!nvidia-smi
!pip install abtem==1.0.0b34
!pip install ase
!pip install cupy-cuda116
from ase import Atoms
from ase.build import mx2
from abtem import show_atoms
from abtem.structures import orthogonalize_cell
from ase.io import read, write
import os
import matplotlib.pyplot as plt
import numpy as np
import random
import pickle
import cupy as cp
from abtem import Probe, GridScan, Potential
from abtem import *
def show_atoms_top_and_side_view(atoms):
fig, (ax1, ax2, ax3) = plt.subplots(1, 3, figsize=(12,4))
show_atoms(atoms, ax=ax1, title='Top view')
show_atoms(atoms, ax=ax2, plane='xz', title='Side view')
show_atoms(atoms, ax=ax3, plane='yz', title='Side view')
Wed Oct 11 23:49:50 2023 +-----------------------------------------------------------------------------+ | NVIDIA-SMI 525.85.12 Driver Version: 525.85.12 CUDA Version: 12.0 | |-------------------------------+----------------------+----------------------+ | GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. | | | | MIG M. | |===============================+======================+======================| | 0 Tesla V100-SXM2... Off | 00000000:00:09.0 Off | 0 | | N/A 34C P0 36W / 300W | 0MiB / 32768MiB | 0% Default | | | | N/A | +-------------------------------+----------------------+----------------------+ +-----------------------------------------------------------------------------+ | Processes: | | GPU GI CI PID Type Process name GPU Memory | | ID ID Usage | |=============================================================================| | No running processes found | +-----------------------------------------------------------------------------+ Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Collecting abtem==1.0.0b34 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/23/bb/30276edd8e67b845498b259e7200bd3cf11b372258dbb74a9911501f02de/abtem-1.0.0b34-py3-none-any.whl (540 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 540.7/540.7 kB 2.9 MB/s eta 0:00:00a 0:00:01 Collecting imageio Downloading https://pypi.tuna.tsinghua.edu.cn/packages/f6/37/e21e6f38b93878ba80302e95b8ccd4718d80f0c53055ccae343e606b1e2d/imageio-2.31.5-py3-none-any.whl (313 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 313.2/313.2 kB 18.2 MB/s eta 0:00:00 Collecting pyfftw Downloading https://pypi.tuna.tsinghua.edu.cn/packages/2d/0b/892b876ce00b4aa592d820867970de8e761eb71637ba74b5049f7f9fd46d/pyFFTW-0.13.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.4 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.4/2.4 MB 20.4 MB/s eta 0:00:0000:0100:01 Requirement already satisfied: tqdm in /opt/mamba/lib/python3.10/site-packages (from abtem==1.0.0b34) (4.64.1) Requirement already satisfied: h5py in /opt/mamba/lib/python3.10/site-packages (from abtem==1.0.0b34) (3.8.0) Requirement already satisfied: scipy in /opt/mamba/lib/python3.10/site-packages (from abtem==1.0.0b34) (1.10.1) Requirement already satisfied: psutil in /opt/mamba/lib/python3.10/site-packages (from abtem==1.0.0b34) (5.9.4) Requirement already satisfied: numpy in /opt/mamba/lib/python3.10/site-packages (from abtem==1.0.0b34) (1.24.2) Collecting numba Downloading https://pypi.tuna.tsinghua.edu.cn/packages/e7/69/d228b38ffb70858d74538bdfe5aa18c7640b7f07840239690985b3a94009/numba-0.58.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (3.6 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.6/3.6 MB 33.9 MB/s eta 0:00:0000:0100:01 Collecting ase Downloading https://pypi.tuna.tsinghua.edu.cn/packages/38/b0/3c0a7afaf66274588216c251376ac2bea0269eb7a5e1da77521811060553/ase-3.22.1-py3-none-any.whl (2.2 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 2.2/2.2 MB 38.0 MB/s eta 0:00:00a 0:00:01 Collecting matplotlib Downloading https://pypi.tuna.tsinghua.edu.cn/packages/b5/24/aaccf324ce862bb82277e8814d2aebbb2a2c160d04e95aa2b8c9dc3137a9/matplotlib-3.8.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.6 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 11.6/11.6 MB 29.0 MB/s eta 0:00:0000:0100:01 Collecting pillow>=6.2.0 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/7a/07/e896b096a77375e78e02ce222ae4fd6014928cd76c691d312060a1645dfa/Pillow-10.0.1-cp310-cp310-manylinux_2_28_x86_64.whl (3.6 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.6/3.6 MB 30.9 MB/s eta 0:00:0000:0100:01 Requirement already satisfied: packaging>=20.0 in /opt/mamba/lib/python3.10/site-packages (from matplotlib->abtem==1.0.0b34) (23.0) Requirement already satisfied: python-dateutil>=2.7 in /opt/mamba/lib/python3.10/site-packages (from matplotlib->abtem==1.0.0b34) (2.8.2) Collecting fonttools>=4.22.0 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ac/ed/9a33eca5e2cc35dc1fea0a968509c653db9a99a5979656ae57c6c019d66b/fonttools-4.43.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.5 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.5/4.5 MB 32.5 MB/s eta 0:00:0000:0100:01 Collecting contourpy>=1.0.1 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/f1/6b/e4b0f8708f22dd7c321f87eadbb98708975e115ac6582eb46d1f32197ce6/contourpy-1.1.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (301 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 301.7/301.7 kB 39.6 MB/s eta 0:00:00 Collecting cycler>=0.10 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/e7/05/c19819d5e3d95294a6f5947fb9b9629efb316b96de511b418c53d245aae6/cycler-0.12.1-py3-none-any.whl (8.3 kB) Collecting pyparsing>=2.3.1 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/39/92/8486ede85fcc088f1b3dba4ce92dd29d126fd96b0008ea213167940a2475/pyparsing-3.1.1-py3-none-any.whl (103 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 103.1/103.1 kB 36.5 MB/s eta 0:00:00 Collecting kiwisolver>=1.0.1 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/6f/40/4ab1fdb57fced80ce5903f04ae1aed7c1d5939dda4fd0c0aa526c12fe28a/kiwisolver-1.4.5-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.6 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.6/1.6 MB 32.4 MB/s eta 0:00:00a 0:00:01 Collecting llvmlite<0.42,>=0.41.0dev0 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/50/df/38c9fb5cc64f4fcc0577a14a0665c2a5de74f45a621ac7708320b1ac80c6/llvmlite-0.41.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (43.6 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 43.6/43.6 MB 9.4 MB/s eta 0:00:00:00:0100:01 Requirement already satisfied: six>=1.5 in /opt/mamba/lib/python3.10/site-packages (from python-dateutil>=2.7->matplotlib->abtem==1.0.0b34) (1.16.0) Installing collected packages: pyparsing, pyfftw, pillow, llvmlite, kiwisolver, fonttools, cycler, contourpy, numba, matplotlib, imageio, ase, abtem Successfully installed abtem-1.0.0b34 ase-3.22.1 contourpy-1.1.1 cycler-0.12.1 fonttools-4.43.1 imageio-2.31.5 kiwisolver-1.4.5 llvmlite-0.41.0 matplotlib-3.8.0 numba-0.58.0 pillow-10.0.1 pyfftw-0.13.1 pyparsing-3.1.1 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Requirement already satisfied: ase in /opt/mamba/lib/python3.10/site-packages (3.22.1) Requirement already satisfied: scipy>=1.1.0 in /opt/mamba/lib/python3.10/site-packages (from ase) (1.10.1) Requirement already satisfied: matplotlib>=3.1.0 in /opt/mamba/lib/python3.10/site-packages (from ase) (3.8.0) Requirement already satisfied: numpy>=1.15.0 in /opt/mamba/lib/python3.10/site-packages (from ase) (1.24.2) Requirement already satisfied: pillow>=6.2.0 in /opt/mamba/lib/python3.10/site-packages (from matplotlib>=3.1.0->ase) (10.0.1) Requirement already satisfied: pyparsing>=2.3.1 in /opt/mamba/lib/python3.10/site-packages (from matplotlib>=3.1.0->ase) (3.1.1) Requirement already satisfied: packaging>=20.0 in /opt/mamba/lib/python3.10/site-packages (from matplotlib>=3.1.0->ase) (23.0) Requirement already satisfied: cycler>=0.10 in /opt/mamba/lib/python3.10/site-packages (from matplotlib>=3.1.0->ase) (0.12.1) Requirement already satisfied: kiwisolver>=1.0.1 in /opt/mamba/lib/python3.10/site-packages (from matplotlib>=3.1.0->ase) (1.4.5) Requirement already satisfied: python-dateutil>=2.7 in /opt/mamba/lib/python3.10/site-packages (from matplotlib>=3.1.0->ase) (2.8.2) Requirement already satisfied: fonttools>=4.22.0 in /opt/mamba/lib/python3.10/site-packages (from matplotlib>=3.1.0->ase) (4.43.1) Requirement already satisfied: contourpy>=1.0.1 in /opt/mamba/lib/python3.10/site-packages (from matplotlib>=3.1.0->ase) (1.1.1) Requirement already satisfied: six>=1.5 in /opt/mamba/lib/python3.10/site-packages (from python-dateutil>=2.7->matplotlib>=3.1.0->ase) (1.16.0) WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Collecting cupy-cuda116 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/9a/df/465470beb6c3f62dffba2b696c0967601eb3cc15d83ef9244785a25c1d79/cupy_cuda116-10.6.0-cp310-cp310-manylinux1_x86_64.whl (81.6 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 81.6/81.6 MB 11.0 MB/s eta 0:00:0000:0100:01 Collecting fastrlock>=0.5 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/bc/5d/d1f89b59f5b4b4710fd126e0df31ca4c58f46fc0a831058fc49010972d3d/fastrlock-0.8.2-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_28_x86_64.whl (51 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 51.3/51.3 kB 21.1 MB/s eta 0:00:00 Requirement already satisfied: numpy<1.25,>=1.18 in /opt/mamba/lib/python3.10/site-packages (from cupy-cuda116) (1.24.2) Installing collected packages: fastrlock, cupy-cuda116 Successfully installed cupy-cuda116-10.6.0 fastrlock-0.8.2 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv /opt/mamba/lib/python3.10/site-packages/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html from .autonotebook import tqdm as notebook_tqdm
代码
文本
[2]
# 定义模拟的标签,这些标签用于区分不同的原子模型和模拟设置
sim_tag = 'sim' # 用于表示模拟的原子结构
single_vacancy_tag = '1vacancy' # 用于表示具有单个空位缺陷的原子结构
double_vacancy_tag = '2vacancy' # 用于表示具有双空位缺陷的原子结构
# 指定进行模拟计算的硬件设备,这里设置为使用GPU
device = 'gpu'
# 模拟使用的库,这里是abtem
source = 'abtem'
# 数据集名称,这里是MoS2
dataset_name = 'MoS2'
# 定义项目的根目录
project_dir = '/data/'
# 根据上面的变量定义,构建用于存放模拟生成数据的目录
data_dir = project_dir + '{}/{}_generated_ps064_new2/'.format(dataset_name, source)
# 如果目录不存在,则创建目录
os.makedirs(data_dir, exist_ok=True)
os.makedirs(data_dir+'image/', exist_ok=True)
# 该函数用于生成存储原子信息的 .cif 文件的文件名
def get_atom_name(datadir, data_idfn, tag, pixel_size):
# datadir 是文件的存储目录
# tag 是用于区分不同原子模型的标签
# data_idfn 是用于区分不同数据集或模拟运行的标识
return '{}/atoms_{}_{}_ps{}.cif'.format(datadir, tag, data_idfn, pixel_size)
# 该函数用于生成存储标签信息的 .npy 文件的文件名
def get_label_name(datadir, data_idfn, tag, pixel_size):
return '{}/label_{}_{}_ps{}.npy'.format(datadir, tag, data_idfn, pixel_size)
# 该函数用于生成存储模拟测量结果的 .hdf5 文件的文件名
def get_measurement_name(datadir, data_idfn, tag, pixel_size):
return '{}/measurement_{}_{}_ps{}.hdf5'.format(datadir, tag, data_idfn, pixel_size)
def get_pic_name(datadir, data_idfn, pixel_size):
return '{}/image/pic_{}_ps{}.png'.format(datadir, data_idfn, pixel_size)
def get_ps_name(datadir, data_idfn):
return '{}/image/ps_{}.png'.format(datadir, data_idfn)
vacuum = 1
代码
文本
[3]
def create_atoms(fomula_tag, lattice_constant_a, thick, x=15, y=15, randomize_std=0.01):
# fomula_tag表示分子式,lattice_constant_a表示晶格常数,thick表示厚度,x表示在x和y方向上都有x个单位的重复,randomize_std>0则对原子的位置进行随机扰动
atoms = mx2(formula=fomula_tag, kind='2H', a=lattice_constant_a, thickness=thick, size=(x, y, 1), vacuum=None)
atoms.set_pbc([True, True, False])
atoms = orthogonalize_cell(atoms)
atoms.center(vacuum=1, axis=2)
if randomize_std > 0:
for i in range(atoms.arrays['positions'].shape[0]):
perturbed = lattice_constant_a * np.array([np.random.normal(0, randomize_std), np.random.normal(0, randomize_std), 0])
atoms.arrays['positions'][i, :] += perturbed
return atoms
代码
文本
[4]
def generate_defect(atoms, data_dir, data_idfn, ps, defect_ratio=0.1):
atoms_ele_num = atoms.arrays['numbers']
atoms_positions = atoms.arrays['positions']
S = 16
S_index = np.where(atoms_ele_num == S)[0]
S_positions = atoms_positions[S_index]
# 打印硫原子位置的最大值和最小值
# print('s postions min/max', S_positions[:,0].min(), S_positions[:,0].max(), S_positions[:,1].min(), S_positions[:,1].max())
ok = False
# 当没有生成缺陷时,持续循环
while not ok:
# 计算硫原子的数量
S_cnt = len(S_index)
# 随机决定要删除的硫原子的数量
S_delete_cnt = random.randint(3, int(S_cnt*defect_ratio))
# 随机选择要删除的硫原子的索引
S_delete_index = S_index[random.sample(range(S_cnt), S_delete_cnt)]
# 从原子序数中删除选定的硫原子
atoms_ele_num_modified = np.delete(atoms_ele_num,S_delete_index)
# 从原子坐标中删除选定的硫原子
atoms_positions_modified = np.delete(atoms_positions,S_delete_index,axis=0)
# 打印修改后的原子序数和坐标的形状
print(atoms_ele_num_modified.shape, atoms_positions_modified.shape)
# 复制原子模型并更新其原子序数和坐标
atoms_modified = atoms.copy()
atoms_modified.arrays['numbers'] = atoms_ele_num_modified
atoms_modified.arrays['positions'] = atoms_positions_modified
# 计算被删除的硫原子的z轴坐标和所有硫原子的平均z轴坐标
deleted_z_axis = np.array([atoms_positions[del_idx][2] for del_idx in S_delete_index])
mean_z_axis = np.array([z_axis[2] for z_axis in S_positions]).mean()
# 分别找出位于z轴上方和下方的被删除的硫原子的索引
upper_indexs = S_delete_index[np.where(deleted_z_axis > mean_z_axis)[0]]
lower_indexs = S_delete_index[np.where(deleted_z_axis < mean_z_axis)[0]]
double_index = []
# 查找双硫原子都被删除的位置
for upper_index in upper_indexs:
x0 = atoms_positions[upper_index][0]
y0 = atoms_positions[upper_index][1]
for lower_index in lower_indexs:
x1 = atoms_positions[lower_index][0]
y1 = atoms_positions[lower_index][1]
if (abs(x0-x1)<0.1 and abs(y0-y1)<0.1):
double_index.append(upper_index)
double_index.append(lower_index)
# 找出只有一个硫原子被删除的索引
single_index = [i for i in S_delete_index if i not in double_index]
# 如果双硫原子和单硫原子的缺失都发生了,那么标志变量ok设为True,结束循环?
if len(double_index) > 0 and len(single_index) > 0:
ok = True
# 复制原子模型,然后只留下双硫原子缺失的位置
atoms_double = atoms.copy()
ele_double = atoms_ele_num[double_index]
positions_double = atoms_positions[double_index]
atoms_double.arrays['numbers'] = ele_double
atoms_double.arrays['positions'] = positions_double
# 复制原子模型,然后只留下单硫原子缺失的位置
atoms_single = atoms.copy()
ele_single = atoms_ele_num[single_index]
positions_single = atoms_positions[single_index]
atoms_single.arrays['numbers'] = ele_single
atoms_single.arrays['positions'] = positions_single
# 在当前目录下创建一个名为'data'的子目录(如果该目录不存在)
# os.makedirs('data', exist_ok=True)
ps_name = "{:.3f}".format(ps).split('.')[1]
# 将经过修改的原子模型、单硫原子缺失的原子模型、双硫原子缺失的原子模型分别写入文件
write(get_atom_name(data_dir, data_idfn, sim_tag, ps_name), atoms_modified)
write(get_atom_name(data_dir, data_idfn, single_vacancy_tag, ps_name), atoms_single)
write(get_atom_name(data_dir, data_idfn, double_vacancy_tag, ps_name), atoms_double)
# 将单硫原子缺失和双硫原子缺失的位置坐标(仅x,y轴)分别保存为numpy数组文件
np.save(get_label_name(data_dir, data_idfn, single_vacancy_tag, ps_name), positions_single[:,:2])
np.save(get_label_name(data_dir, data_idfn, double_vacancy_tag, ps_name), positions_double[:,:2])
# 返回经过修改的原子模型、单硫原子缺失的原子模型、双硫原子缺失的原子模型
return atoms_modified, atoms_single, atoms_double
代码
文本
[5]
def simulation(data_dir, data_idfn, tag, name, ps):
# 获取原子样品文件名
ps_name = "{:.3f}".format(ps).split('.')[1]
atoms_file = get_atom_name(data_dir, data_idfn, tag, ps_name)
# 从文件中读取原子样品数据
atoms = read(atoms_file)
# 配置冻结声子模型的参数
sigmas={name:.1,'S':.1}
num_configs=30
# 创建冻结声子模型
frozen_phonon=FrozenPhonons(atoms,num_configs=num_configs,sigmas=sigmas)
# 设置电子显微镜的参数
slice_thickness=2 # 多层切片方法的每一层的间隔(A)
sampling_poten=0.1 # 网格精度
conv_angle=30 # 收敛角(mrad)
energy_EM=80e3 # 电压(V)
df=0 # 散焦(A)
C30=0 # 球差(A)
# 计算电子和原子核的库仑势,用于定量图像模拟
potential = Potential(frozen_phonon,
sampling=sampling_poten,
projection='infinite',
slice_thickness=slice_thickness,
parametrization='kirkland').build()
# 创建探测器探针
probe = Probe(energy=energy_EM, semiangle_cutoff=conv_angle,defocus=df,C30=0, device=device)
# 将探针的网格与库仑势相匹配
probe.grid.match(potential)
# 设置扫描参数
scan_start = (vacuum,vacuum) # 扫描的起始点
scan_end = potential.extent
scan_range_1 = min(400 * ps, scan_end[0])
scan_range_2 = min(600 * ps, scan_end[1])
scan_end_new = (scan_start[0] + scan_range_1, scan_start[1] + scan_range_2)
step_size = ps # 探针扫描步长(A)即为需要的pixel size
gridscan = GridScan(start=scan_start,end=scan_end,sampling=step_size)
# 创建环形探测器
detector = FlexibleAnnularDetector()
# 执行扫描并获取测量结果
measurement = probe.scan(gridscan, detector, potential)
# 获取测量结果文件名
ps_name = "{:.3f}".format(ps).split('.')[1]
file_name = get_measurement_name(data_dir, data_idfn, tag, ps_name)
# 将测量结果写入文件
measurement.write(file_name)
return file_name
代码
文本
[6]
def draw_pic(data_dir, data_idfn, ps):
ps_name = "{:.3f}".format(ps).split('.')[1]
file_name = get_measurement_name(data_dir, data_idfn, sim_tag, ps_name)
measurement = Measurement.read(file_name)
image1 = haadf_measurement = measurement.integrate(50, 250)
plt.imshow(image1.array, cmap='gray', interpolation='none')
plt.title(f'MoS2_{data_idfn}_ps{ps}Å')
plt.axis('off')
# #全像素
# dpi = 300
# fig = plt.figure(figsize=(image1.array.shape[1]/dpi, image1.array.shape[0]/dpi), dpi=dpi)
# plt.imshow(image1.array, cmap='gray', interpolation='none')
# #设置布局
# plt.gca().set_position([0, 0, 1, 1])
# 保存
plt.imsave(get_pic_name(data_dir, data_idfn, ps_name), image1.array, cmap='gray')
# 关闭图像以释放内存
plt.close()
return
代码
文本
MoS2仿真图像需要覆盖的pixel size(Å)如下:
0.064, 0.081, 0.100, 0.120, 0.130, 0.160, 0.200, 0.250, 0.330
代码
文本
[ ]
# 仿真图像的pixel size
ps = 0.064
id_start = 33
id_end = 50
for data_idfn in range(id_start,id_end):
a=data_idfn
data_idfn="{:03d}".format(data_idfn)
atoms = create_atoms(fomula_tag='MoS2', lattice_constant_a=3.19, thick=3.35, x=7, y=7, randomize_std=0.01)
atoms_modified, atoms_single, atoms_double = generate_defect(atoms, data_dir, data_idfn, ps, 0.1)
sim_file_name = simulation(data_dir, data_idfn, sim_tag, 'Mo', ps)
draw_pic(data_dir, data_idfn, ps)
print('已完成:',a+1,'/',id_end)
(280,) (280, 3)
Scan: 0%| | 0/196137 [00:00<?, ?it/s]/opt/mamba/lib/python3.10/site-packages/numba/cuda/dispatcher.py:536: NumbaPerformanceWarning: Grid size 1 will likely result in GPU under-utilization due to low occupancy.
warn(NumbaPerformanceWarning(msg))
Scan: 100%|██████████| 196137/196137 [09:39<00:00, 338.45it/s]
已完成: 33 / 41
(278,) (278, 3)
Scan: 5%|▍ | 9410/196137 [00:30<04:04, 762.27it/s]
代码
文本
[ ]
from numba import cuda
@cuda.jit
def kernel(data):
for data_idfn in range(id_start,id_end):
a=data_idfn
data_idfn="{:03d}".format(data_idfn)
atoms = create_atoms(fomula_tag='MoS2', lattice_constant_a=3.19, thick=3.35, x=20, randomize_std=0.01)
atoms_modified, atoms_single, atoms_double = generate_defect(atoms, data_dir, data_idfn, 0.1)
sim_file_name = simulation(data_dir, data_idfn, sim_tag, 'Mo', 0.064)
draw_pic(data_dir, data_idfn, ps)
print('已完成:',a+1,'/',id_end)
pass
# 初始化数据
data = np.zeros(shape=(10000, 10000), dtype=np.float32)
# 在 GPU 上启动 kernel 函数
kernel[1000, 1000](data)
代码
文本
点个赞吧
推荐阅读
公开
abTEM仿真图像批量生成Orange
发布于 2023-10-11
公开
氧掺杂abTEM仿真Orange
发布于 2023-11-07