From 8f5ee57efc99f700b7e403bec56ae487db3af8f7 Mon Sep 17 00:00:00 2001 From: zqxian <2821838490@qq.com> Date: Mon, 28 Apr 2025 11:40:04 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=9F=BA=E5=BA=95=E4=B8=AD=E5=BF=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HTMACat/catkit/gen/adsorption.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/HTMACat/catkit/gen/adsorption.py b/HTMACat/catkit/gen/adsorption.py index d87b624..ff80692 100644 --- a/HTMACat/catkit/gen/adsorption.py +++ b/HTMACat/catkit/gen/adsorption.py @@ -650,16 +650,22 @@ def _single_adsorption( max_z = np.max(final_positions[:, 2]) # 获取 slab z 轴最大值 base_position[2] = round(0 - min_z + 2.5 + max_z, 1) - # 计算 slab 中心坐标,确保吸附分子位于 slab 的正中心 - center_x, center_y = utils.center_slab(final_positions) - base_position[0] = round(center_x, 1) - base_position[1] = round(center_y, 1) + # 如果输入的 xy 为 [0, 0],则将分子放在 slab 的 xy 中心 + if site_coord[0] == 0 and site_coord[1] == 0: + center_x, center_y = utils.center_slab(final_positions) # 计算 slab 的 xy 中心 + base_position[0] = round(center_x, 1) # 将分子放置在 xy 中心 + base_position[1] = round(center_y, 1) + else: + # 否则,使用输入的 site_coord 作为 xy 坐标 + base_position[0] = round(site_coord[0], 1) + base_position[1] = round(site_coord[1], 1) atoms.translate(base_position) # 确保所有构型都以正确的 z 轴间距平移 # 将分子平移到指定的 site_coord 位置 - vec_tmp = site_coord - atoms.get_positions()[bond] - atoms.translate([vec_tmp[0], vec_tmp[1], 0]) + vec_tmp = site_coord - atoms.get_positions()[bond] # 计算平移量 + atoms.translate([vec_tmp[0], vec_tmp[1], 0]) # 只平移 x-y,不改变 z + slab_with_adsorbate = slab.copy() slab_with_adsorbate += atoms @@ -729,12 +735,17 @@ def _single_adsorption( # 计算 slab 中心坐标 slab_positions = slab.get_positions() center_x, center_y = utils.center_slab(slab_positions) - base_position[0] = round(center_x, 1) - base_position[1] = round(center_y, 1) + # 如果输入的 xy 为 [0, 0],则将分子放在 slab 的 xy 中心 + if site_coord[0] == 0 and site_coord[1] == 0: + base_position[0] = round(center_x, 1) + base_position[1] = round(center_y, 1) + else: + base_position[0] = round(site_coord[0], 1) + base_position[1] = round(site_coord[1], 1) # 打印检查 print(f"min_z (adsorbate): {min_z}, max_z (slab): {max_z}, new base_position: {base_position}") - + # 平移吸附分子 a.translate(base_position) @@ -742,7 +753,7 @@ def _single_adsorption( xy_translation = site_coord[:2] - a.get_positions()[bond][:2] a.translate([xy_translation[0], xy_translation[1], 0]) # 只移动 x-y,不改变 z print('Final base_position:', base_position) - + # 组合 slab 和吸附物 slabs_list[-1] += a # Add graph connections From a047717cce35fb7d3e462932e247e4d0d2eb29d8 Mon Sep 17 00:00:00 2001 From: zqxian <2821838490@qq.com> Date: Wed, 30 Apr 2025 12:38:36 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=9F=BA=E5=9C=B0=E4=B8=AD=E5=BF=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HTMACat/catkit/gen/adsorption.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/HTMACat/catkit/gen/adsorption.py b/HTMACat/catkit/gen/adsorption.py index ff80692..422478c 100644 --- a/HTMACat/catkit/gen/adsorption.py +++ b/HTMACat/catkit/gen/adsorption.py @@ -650,7 +650,7 @@ def _single_adsorption( max_z = np.max(final_positions[:, 2]) # 获取 slab z 轴最大值 base_position[2] = round(0 - min_z + 2.5 + max_z, 1) - # 如果输入的 xy 为 [0, 0],则将分子放在 slab 的 xy 中心 + # xzq如果输入的 xy 为 [0, 0],则将分子放在 slab 的 xy 中心 if site_coord[0] == 0 and site_coord[1] == 0: center_x, center_y = utils.center_slab(final_positions) # 计算 slab 的 xy 中心 base_position[0] = round(center_x, 1) # 将分子放置在 xy 中心 @@ -735,7 +735,7 @@ def _single_adsorption( # 计算 slab 中心坐标 slab_positions = slab.get_positions() center_x, center_y = utils.center_slab(slab_positions) - # 如果输入的 xy 为 [0, 0],则将分子放在 slab 的 xy 中心 + # xzq如果输入的 xy 为 [0, 0],则将分子放在 slab 的 xy 中心 if site_coord[0] == 0 and site_coord[1] == 0: base_position[0] = round(center_x, 1) base_position[1] = round(center_y, 1)