Skill站外收录 @skilllib/skill-2117939930272411739
rdkit
在 Coot 环境中实现分子结构的 RDKit 级操作,支持从 Coot 单体构建化学分子、原子替换等结构编辑、生成标准化 2D 化学图谱,适用于晶体结构解析中对配体或小分子的快速化学信息学分析与可视化。
研究 AI 技能
Skills.MD
# Coot-RDKit Integration
This skill provides guidance for using RDKit within Coot's Python environment for molecular manipulation and visualization.
## Key Integration Points
### Module Import
Use `coot_headless_api` (NOT `chapi`):
```python
import coot_headless_api
from rdkit import Chem
from rdkit.Chem import AllChem
```
### Creating RDKit Molecules from Coot Monomers
```python
import coot_headless_api
import base64
from rdkit import Chem
# Initialize molecules container
molecules = coot_headless_api.molecules_container_t(False) # False = not verbose
# Get monomer from Coot's library
imol = molecules.get_monomer("AMP") # or any other monomer code
# Get RDKit molecule as pickled base64
pickle_base64_str = molecules.get_rdkit_mol_pickle_base64("AMP", imol)
# Decode and create RDKit molecule
pickle_bytes = base64.b64decode(pickle_base64_str)
rdkit_mol = Chem.Mol(pickle_bytes) # Use Chem.Mol(), NOT pickle.loads()
```
## Molecular Manipulation
### Atom Substitution
```python
from rdkit import Chem
# Make editable copy
mol_edit = Chem.RWMol(rdkit_mol)
# Replace atom (e.g., phosphorus to sulfur)
for atom in mol_edit.GetAtoms():
if atom.GetSymbol() == 'P':
atom.SetAtomicNum(16) # 16 = sulfur
break
# Convert back to read-only molecule
modified_mol = mol_edit.GetMol()
Chem.SanitizeMol(modified_mol)
```
## 2D Structure Visualization
### CRITICAL: Always Regenerate 2D Coordinates
When removing hydrogens or modifying structure, ALWAYS regenerate 2D coordinates:
```python
from rdkit.Chem import AllChem
# Remove hydrogens
mol_no_h = Chem.RemoveHs(mol)
# IMPORTANT: Regenerate 2D coords AFTER removing hydrogens
AllChem.Compute2DCoords(mol_no_h)
# Now generate visualization
```
### Generating SVG Diagrams
```python
from rdkit.Chem.Draw import rdMolDraw2D
drawer = rdMolDraw2D.MolDraw2DSVG(400, 400)
drawer.DrawMolecule(mol_no_h)
drawer.FinishDrawing()
svg_string = drawer.GetDrawingText()
# Save without displaying (see Data Handling below)
```
## Data Handling Best Practices
### NEVER Display Large String Data
Do NOT return or print large strings (SVG, base64, etc.) as this causes slow response times:
**BAD:**
```python
svg_data # This displays all the text - SLOW!
```
**GOOD:**
```python
# Just save directly without displaying
# (use len() to verify if needed, though even this may not return properly)
```
### Efficient File Writing
Write files directly without displaying content:
**From Coot Python:**
```python
svg_content = drawer.GetDrawingText()
# Don't display svg_content - just reference it
```
**Then in bash or file creation:**
```bash
# Use the variable directly without echoing/catting the content
```
## Coot Python Limitations
### Single-Line Return Values Only
Coot's Python environment only returns values from single-line expressions:
**Works:**
```python
Chem.MolToSmiles(mol) # Returns SMILES string
```
**Doesn't return properly:**
```python
x = 5
y = 10
x + y # Won't return the value
```
**Workaround** - Define function in one call, execute in next:
```python
# Call 1: Define
def my_function():
x = 5
y = 10
return x + y
# Call 2: Execute
my_function() # Now returns 15
```
## Common Workflows
### Modify and Visualize Ligand
1. Load monomer from Coot library
2. Convert to RDKit molecule
3. Make modifications (atom substitution, etc.)
4. Remove hydrogens if desired for cleaner diagram
5. **Regenerate 2D coordinates** (critical!)
6. Generate SVG diagram
7. Save to file **without displaying**
评论 0
还没有评论,来抢沙发。
相关内容
同类或同场景的收录内容
building-with-kafka-strimzi
在 Kubernetes 上构建基于 Apache Kafka 的事件驱动系统,支持高可靠的消息传递、事务性处理与精确一次语义,结合 Strimzi 运营商实现集群自动化管理,利用 Schema Registry 保障事件模式演进,适用于微服务间解耦通信与实时数据流处理场景。
站外数据与分析
609 0.0
personal-tool-builder
专注于从个人真实痛点出发快速构建实用工具,涵盖命令行程序、本地优先应用和自动化脚本的开发与演进,强调先满足自身需求再逐步扩展,通过持续自用打磨功能,避免过度设计,确保工具简洁有效且长期可维护。
站外商业与营销
196 0.0
threejs-lighting
实现三维场景中的光照与阴影控制,支持多种光源类型及环境光照明,提供从基础布光到高级阴影优化的完整方案,适用于需要真实感渲染或性能平衡的可视化项目。
站外效率工具
442 0.0
aggregation-helper
提供数据聚合场景的自动化辅助能力,涵盖 SQL 查询编写、统计分析建模、可视化方案设计及商业智能配置,支持从需求理解到生产级代码生成的全流程指导。
站外效率工具数据与分析
217 0.0
举报「rdkit」
举报信息仅审核团队可见,同一资产 24 小时内仅可举报一次