Traceback (most recent call last): File "ADF.py", line 18, in <module> atoms.set_calculator(SinglePointCalculator(atoms, energy=0, forces=np.zeros((len(atoms), 3)), stress=np.zeros(6), neighborlist=nl)) File "/export/home/anliying/.local/lib/python3.8/site-packages/ase-3.22.1-py3.8.egg/ase/calculators/singlepoint.py", line 22, in init assert property in all_properties AssertionError。import numpy as np from ase.io import read from ase.build import make_supercell from ase.visualize import view from ase.neighborlist import NeighborList from ase.calculators.singlepoint import SinglePointCalculator # 读入三个POSCAR文件,计算原子分布函数 structures = [] for file in ['structure1.cif', 'structure2.cif', 'structure3.cif']: atoms = read(file) # 构造超胞,避免周期性边界对ADF计算的影响 atoms = make_supercell(atoms, [[2, 0, 0], [0, 2, 0], [0, 0, 2]]) # 计算邻居列表 nl = NeighborList([1.2] * len(atoms), self_interaction=False) nl.update(atoms) # 将邻居列表传递给SinglePointCalculator atoms.set_calculator(SinglePointCalculator(atoms, energy=0, forces=np.zeros((len(atoms), 3)), stress=np.zeros(6), neighborlist=nl)) # 计算原子分布函数 adf = atoms.get_atomic_distribution_function() structures.append(adf) # 将ADF转化为特征矩阵 bins = np.linspace(0, 10, num=100) # 分100个bin adf_hists = [np.histogram(adf, bins=bins)[0] for adf in structures] feature_matrix = np.array(adf_hists) / [len(atoms) for atoms in structures] # 归一化特征矩阵 feature_matrix = feature_matrix / np.linalg.norm(feature_matrix, axis=1, keepdims=True),基于错误改代码
时间: 2024-03-12 12:42:54 浏览: 21
It seems that the error occurs because the `property` argument is not recognized by the `SinglePointCalculator` constructor.
To fix this error, you can replace the `property` argument with `properties` in the `SinglePointCalculator` constructor. The corrected code should look like this:
```
atoms.set_calculator(SinglePointCalculator(atoms, energy=0, forces=np.zeros((len(atoms), 3)), stress=np.zeros(6), properties=['energy', 'forces'], neighborlist=nl))
```
Note that I have also added the `properties` argument with the values `['energy', 'forces']` to specify the properties that the calculator should compute.
相关问题
Traceback (most recent call last): File "test.py", line 2, in <module> import pandas ImportErr
Traceback (most recent call last): File "test.py", line 2, in <module> import pandas ImportError: No module named pandas这段错误信息表明在Python脚本中尝试导入pandas模块时出现了错误,提示找不到pandas模块。
可能的原因是您的环境中没有安装pandas模块。您可以通过使用pip命令在终端中安装pandas模块。如果您使用的是Python 2,可以使用pip命令,如果使用的是Python 3,可以使用pip3命令。但是引用中的错误信息显示pip3命令也无法正常工作,可能是由于pip3的安装有问题或者环境变量配置不正确。
此外,引用中提到在终端首选项中启用设置地区环境变量,这也是一种可能的解决方法。您可以尝试设置正确的地区环境变量,然后重新运行脚本,看是否能够解决导入错误的问题。
Traceback (most recent call last): File "script.py", line 3, in <module> import numpy as np
Traceback (most recent call last): File "script.py", line 3, in <module> import numpy as np
这个错误是因为你的代码中导入了numpy库,但是你的环境中没有安装numpy库导致的。你可以使用以下命令来安装numpy库:
pip install numpy
如果你使用的是Python 3,可以使用以下命令来安装:
pip3 install numpy
安装完成后,再次运行代码应该就不会出现这个错误了。