增加扩胞逻辑
This commit is contained in:
@@ -131,6 +131,7 @@ class StructureInspector:
|
||||
Returns:
|
||||
StructureInfo: 分析结果
|
||||
"""
|
||||
import os
|
||||
info = StructureInfo(
|
||||
file_path=file_path,
|
||||
file_name=os.path.basename(file_path)
|
||||
@@ -139,47 +140,64 @@ class StructureInspector:
|
||||
# 尝试读取结构
|
||||
try:
|
||||
structure = Structure.from_file(file_path)
|
||||
info.is_valid = True
|
||||
except Exception as e:
|
||||
info.error_message = str(e)
|
||||
info.is_valid = False
|
||||
info.error_message = f"读取CIF失败: {str(e)}"
|
||||
return info
|
||||
|
||||
# 基础信息
|
||||
info.elements = {str(el) for el in structure.composition.elements}
|
||||
info.num_sites = structure.num_sites
|
||||
info.formula = structure.composition.reduced_formula
|
||||
# 结构读取成功,标记为有效
|
||||
info.is_valid = True
|
||||
|
||||
# 检查是否为二元化合物
|
||||
info.is_binary_compound = len(structure.composition.elements) == 2
|
||||
# 后续分析用 try-except 包裹,确保即使分析出错也能返回基本信息
|
||||
try:
|
||||
# 基础信息
|
||||
info.elements = {str(el) for el in structure.composition.elements}
|
||||
info.num_sites = structure.num_sites
|
||||
info.formula = structure.composition.reduced_formula
|
||||
|
||||
# 检查是否含有目标阳离子
|
||||
info.contains_target_cation = self.target_cation in info.elements
|
||||
# 检查是否为二元化合物
|
||||
info.is_binary_compound = len(structure.composition.elements) == 2
|
||||
|
||||
# 检查阴离子类型
|
||||
info.anion_types = info.elements.intersection(self.target_anions)
|
||||
if len(info.anion_types) == 0:
|
||||
info.anion_mode = "none"
|
||||
elif len(info.anion_types) == 1:
|
||||
info.anion_mode = "single"
|
||||
else:
|
||||
info.anion_mode = "mixed"
|
||||
# 检查是否含有目标阳离子
|
||||
info.contains_target_cation = self.target_cation in info.elements
|
||||
|
||||
# 检查氧化态
|
||||
info.has_oxidation_states = self._check_oxidation_states(structure)
|
||||
# 检查阴离子类型
|
||||
info.anion_types = info.elements.intersection(self.target_anions)
|
||||
if len(info.anion_types) == 0:
|
||||
info.anion_mode = "none"
|
||||
elif len(info.anion_types) == 1:
|
||||
info.anion_mode = "single"
|
||||
else:
|
||||
info.anion_mode = "mixed"
|
||||
|
||||
# 检查共占位(核心分析)
|
||||
self._analyze_partial_occupancy(structure, info)
|
||||
# 检查氧化态
|
||||
info.has_oxidation_states = self._check_oxidation_states(structure)
|
||||
|
||||
# 检查水分子
|
||||
info.has_water_molecule = self._check_water_molecule(structure)
|
||||
# 检查共占位(核心分析)
|
||||
try:
|
||||
self._analyze_partial_occupancy(structure, info)
|
||||
except Exception as e:
|
||||
# 共占位分析失败,记录但继续
|
||||
pass
|
||||
|
||||
# 检查放射性元素
|
||||
info.has_radioactive_elements = bool(
|
||||
info.elements.intersection(self.RADIOACTIVE_ELEMENTS)
|
||||
)
|
||||
# 检查水分子
|
||||
try:
|
||||
info.has_water_molecule = self._check_water_molecule(structure)
|
||||
except:
|
||||
info.has_water_molecule = False
|
||||
|
||||
# 判断可处理性
|
||||
self._evaluate_processability(info)
|
||||
# 检查放射性元素
|
||||
info.has_radioactive_elements = bool(
|
||||
info.elements.intersection(self.RADIOACTIVE_ELEMENTS)
|
||||
)
|
||||
|
||||
# 判断可处理性
|
||||
self._evaluate_processability(info)
|
||||
|
||||
except Exception as e:
|
||||
# 分析过程出错,但文件本身是有效的
|
||||
# 保留 is_valid = True,但记录错误
|
||||
info.error_message = f"分析过程出错: {str(e)}"
|
||||
|
||||
return info
|
||||
|
||||
|
||||
Reference in New Issue
Block a user