This commit is contained in:
2025-12-07 13:56:33 +08:00
parent 49f54b04cd
commit c83985cd02
22 changed files with 2732 additions and 0 deletions

72
py/step4.py Normal file
View File

@@ -0,0 +1,72 @@
import os
import re
import shutil
def process_files(cif_folder,input_folder,output_folder, anion):
# 确保输出文件夹存在
os.makedirs(output_folder, exist_ok=True)
# 获取 txt 文件夹中的所有 txt 文件
txt_files = [f for f in os.listdir(cif_folder) if f.endswith('.txt')]
# 遍历 txt 文件
for txt_file in txt_files:
txt_path = os.path.join(cif_folder, txt_file)
# 打开并读取 txt 文件内容
with open(txt_path, 'r', encoding='utf-8') as file:
content = file.read()
matches = re.findall(r"Maximum node length detected: (\d+\.\d+) A", content)
# 使用正则表达式查找符合条件的内容
if matches:
# 提取文件名(去掉.txt后缀
base_name = os.path.splitext(txt_file)[0]
check = False
if anion == "O":
print(f"{base_name}的扩大锂离子直径为{matches[0]}A")
if float(matches[0]) > 2.2:
check = True
print(f"符合要求")
else:
print("不符合要求")
elif anion == "S":
print(f"{base_name}的扩大锂离子直径为{matches[0]}A")
if float(matches[0]) > 2.2:
check = True
print(f"符合要求")
else:
print("不符合要求")
elif anion == "Cl":
print(f"{base_name}的扩大锂离子直径为{matches[0]}A")
if float(matches[0]) > 2:
check = True
print(f"符合要求")
else:
print("不符合要求")
elif anion == "Br":
print(f"{base_name}的扩大锂离子直径为{matches[0]}A")
if float(matches[0]) > 2:
check = True
print(f"符合要求")
else:
print("不符合要求")
if check:
# 查找与 txt 文件同名的 cif 文件
cif_path = os.path.join(input_folder, base_name)
# 如果对应的 cif 文件存在,复制到 output_folder
if os.path.exists(cif_path):
shutil.copy(cif_path, os.path.join(output_folder, base_name))
print(f"Copied {base_name} to {output_folder}")
if __name__ == "__main__":
# process_files("../data/after_step1/O","../data/after_step3/O", "../data/after_step4/O", "O")
# process_files("../data/after_step1/S", "../data/after_step3/S","../data/after_step4/S", "S")
process_files("../data/after_step1/Cl", "../data/after_step3/Cl","../data/after_step4/Cl", "Cl")
process_files("../data/after_step1/Br", "../data/after_step3/Br","../data/after_step4/Br", "Br")