修改RuntimeError: found difference in connectivity。import spdkit from spdkit import * m1 = Molecule.from_file("POSCAR1") m2 = Molecule.from_file("POSCAR2") dis = m1.disparity_between(m2) m1.rebond() m1.rebond() rmsd = m1.resemble_rigidly(m2) print(rmsd)
时间: 2024-03-05 22:50:14 浏览: 61
这个错误通常是由于分子之间的连接方式不一致导致的。在计算 RMSD 值之前,需要确保两个分子具有相同的连接方式。您可以尝试以下修改:
```python
import spdkit
from spdkit import *
# 读取分子文件
m1 = Molecule.from_file("POSCAR1")
m2 = Molecule.from_file("POSCAR2")
# 重新确定原子之间的连接方式
m1.rebond()
m2.rebond()
# 检查分子之间的差异性
dis = m1.disparity_between(m2)
if dis:
# 如果分子之间存在差异性,则修正分子的连接方式
m1.fix_bonds(m2.get_bonds())
# 计算 RMSD 值
rmsd = m1.resemble_rigidly(m2)
print(rmsd)
```
这里使用 `fix_bonds` 函数修正分子的连接方式,如果两个分子之间存在差异性,则将第一个分子的连接方式更新为第二个分子的连接方式。然后再计算 RMSD 值。
相关问题
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "D:\Python\Python38\lib\site-packages\fitz\__init__.py", line 1, in <module> from frontend import * File "D:\Python\Python38\lib\site-packages\frontend\__init__.py", line 1, in <module> from .events import * File "D:\Python\Python38\lib\site-packages\frontend\events\__init__.py", line 1, in <module> from .clipboard import * File "D:\Python\Python38\lib\site-packages\frontend\events\clipboard.py", line 2, in <module> from ..dom import Event File "D:\Python\Python38\lib\site-packages\frontend\dom.py", line 439, in <module> from . import dispatcher File "D:\Python\Python38\lib\site-packages\frontend\dispatcher.py", line 15, in <module> from . import config, server File "D:\Python\Python38\lib\site-packages\frontend\server.py", line 24, in <module> app.mount(config.STATIC_ROUTE, StaticFiles(directory=config.STATIC_DIRECTORY), name=config.STATIC_NAME) File "D:\Python\Python38\lib\site-packages\starlette\staticfiles.py", line 57, in __init__ raise RuntimeError(f"Directory '{directory}' does not exist") RuntimeError: Directory 'static/' does not exist
这个错误是运行 Python 代码时,无法找到静态文件目录 'static/' 引起的。可能是你的代码中使用了静态文件,但是没有在正确的位置创建 'static/' 目录,或者你的当前工作目录不正确,导致找不到这个目录。你需要检查代码中的相关路径是否正确,或者创建一个名为 'static/' 的目录。
Error processing line 1 of D:\Anaconda\envs\Train\lib\site-packages\matplotlib-3.7.1-py3.9-nspkg.pth: Fatal Python error: init_import_site: Failed to import the site module Python runtime state: initialized Traceback (most recent call last): File "D:\Anaconda\envs\Train\lib\site.py", line 169, in addpackage exec(line) File "<string>", line 1, in <module> File "D:\Anaconda\envs\Train\lib\importlib\util.py", line 2, in <module> from . import abc File "D:\Anaconda\envs\Train\lib\importlib\abc.py", line 17, in <module> from typing import Protocol, runtime_checkable File "D:\Anaconda\envs\Train\lib\typing.py", line 26, in <module> import re as stdlib_re # Avoid confusion with the re we export. File "E:\fin\re.py", line 2, in <module> from repair import Ui_MainWindow File "E:\fin\repair.py", line 11, in <module> from PyQt5 import QtCore, QtGui, QtWidgets File "D:\Anaconda\envs\Train\lib\site-packages\PyQt5\__init__.py", line 20, in <module> __path__ = __import__('pkgutil').extend_path(__path__, __name__) File "D:\Anaconda\envs\Train\lib\pkgutil.py", line 643, in <module> _NAME_PATTERN = re.compile(f'^(?P<pkg>{_DOTTED_WORDS})(?P<cln>:(?P<obj>{_DOTTED_WORDS})?)?$', re.U) AttributeError: partially initialized module 're' has no attribute 'compile' (most likely due to a circular import) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "D:\Anaconda\envs\Train\lib\site.py", line 589, in <module> main() File "D:\Anaconda\envs\Train\lib\site.py", line 576, in main known_paths = addsitepackages(known_paths) File "D:\Anaconda\envs\Train\lib\site.py", line 359, in addsitepackages addsitedir(sitedir, known_paths) File "D:\Anaconda\envs\Train\lib\site.py", line 208, in addsitedir addpackage(sitedir, name, known_paths) File "D:\Anaconda\envs\Train\lib\site.py", line 179, in addpackage import traceback File "D:\Anaconda\envs\Train\lib\traceback.py", line 5, in <module> import linecache File "D:\Anaconda\envs\Train\lib\linecache.py", line 11, in <module> import tokenize File "D:\Anaconda\envs\Train\lib\tokenize.py", line 32, in <module> import re File "E:\fin\re.py", line 2, in <module> from repair import Ui_MainWindow File "E:\fin\repair.py", line 11, in <module> from PyQt5 import QtCore, QtGui, QtWidgets File "D:\Anaconda\envs\Train\lib\site-packages\PyQt5\__init__.py", line 20, in <module> __path__ = __import__('pkgutil').extend_path(__path__, __name__) File "D:\Anaconda\envs\Train\lib\pkgutil.py", line 6, in <module> import importlib.util File "D:\Anaconda\envs\Train\lib\importlib\util.py", line 2, in <module> from . import abc File "D:\Anaconda\envs\Train\lib\importlib\abc.py", line 17, in <module> from typing import Protocol, runtime_checkable File "D:\Anaconda\envs\Train\lib\typing.py", line 2245, in <module> Pattern = _alias(stdlib_re.Pattern, 1) AttributeError: partially initialized module 're' has no attribute 'Pattern' (most likely due to a circular import)
这个错误看起来是由于 circular import(循环导入)引起的。可能的解决方法是:
1. 检查你的代码中是否存在循环导入的问题。循环导入是指两个或多个模块之间的相互导入,可能会导致类似于你遇到的这种错误。
2. 检查你的环境中是否有重复命名的模块或包。如果有,尝试删除或重命名它们。
3. 尝试更新或重新安装受影响的包,例如 matplotlib 和 PyQt5。
希望这些方法可以帮助你解决问题。
阅读全文