V1
This commit is contained in:
44
py/call_analyze.py
Normal file
44
py/call_analyze.py
Normal file
@@ -0,0 +1,44 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import argparse
|
||||
import subprocess
|
||||
|
||||
|
||||
def run_analysis_with_subprocess(cif_file, input_file, output_file, filters=None):
|
||||
# 如果没有传递 filters,则使用默认值
|
||||
if filters is None:
|
||||
filters = ["Ordered", "PropOxi", "VoroPerco", "Coulomb", "VoroBV", "VoroInfo", "MergeSite"]
|
||||
|
||||
# 构建命令行参数
|
||||
command = ['python', '../tool/analyze_voronoi_nodes.py', cif_file, '-i', input_file, '-o', output_file, '-f'] + filters
|
||||
|
||||
# 调用 subprocess 执行命令
|
||||
process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
|
||||
# 捕获标准输出和标准错误
|
||||
stdout, stderr = process.communicate()
|
||||
|
||||
# Python 2.7 需要解码 stdout 和 stderr(因为是 str 类型)
|
||||
stdout = stdout.decode('utf-8') if isinstance(stdout, str) else stdout
|
||||
stderr = stderr.decode('utf-8') if isinstance(stderr, str) else stderr
|
||||
|
||||
# 打印输出内容或记录到文件
|
||||
print(stdout)
|
||||
if stderr:
|
||||
print(stderr)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# 设置命令行参数解析器
|
||||
parser = argparse.ArgumentParser(description='Run Voronoi analysis using analyze.py script.')
|
||||
parser.add_argument('cif_file', type=str, help='CIF file to analyze')
|
||||
parser.add_argument('-i', '--input_file', type=str, help='Input YAML file', required=True)
|
||||
parser.add_argument('-o', '--output_file', type=str, help='Output file to save the results', required=True)
|
||||
parser.add_argument('-f', '--filters', nargs='+',
|
||||
default=["Ordered", "PropOxi", "VoroPerco", "Coulomb", "VoroBV", "VoroInfo", "MergeSite"],
|
||||
help='List of filters to apply (default is all filters)')
|
||||
|
||||
# 解析命令行参数
|
||||
args = parser.parse_args()
|
||||
|
||||
# 调用分析函数
|
||||
run_analysis_with_subprocess(args.cif_file, args.input_file, args.output_file, args.filters)
|
||||
Reference in New Issue
Block a user