Compare commits
10 Commits
f973372fcc
...
be2b157f55
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
be2b157f55 | ||
|
|
11c451ad67 | ||
|
|
c0618c822d | ||
|
|
237d2b4c93 | ||
|
|
6e2c3c4f53 | ||
|
|
6fc8139ba7 | ||
|
|
e46b925df9 | ||
|
|
1bc7d248c9 | ||
|
|
9e2ccaef07 | ||
|
|
ebd67d40a5 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -6,4 +6,5 @@ __pycache__
|
||||
*.sdf
|
||||
*.gif
|
||||
*.pyc
|
||||
*.cif
|
||||
*.cif
|
||||
data/
|
||||
62
README.md
62
README.md
@@ -15,7 +15,7 @@ scripts为一些脚本文件,主要是测试代码
|
||||
## 环境安装
|
||||
|
||||
```shell
|
||||
conda install -c conda-forge ffmpeg pymol-open-source biopython loguru
|
||||
conda install -c conda-forge ffmpeg pymol-open-source biopython loguru ipython rdkit click -y
|
||||
```
|
||||
|
||||
## 最高质量渲染
|
||||
@@ -124,7 +124,6 @@ class PyMOLAnimator:
|
||||
# 使用
|
||||
animator = PyMOLAnimator((1920, 1080), 300, 120, Path('/path/to/save'))
|
||||
animator.save_frames('frame1', 'frame2')
|
||||
|
||||
```
|
||||
|
||||
## 场景设置
|
||||
@@ -161,3 +160,62 @@ animator.save_frames('frame1', 'frame2')
|
||||
|
||||
这会存储一个名为"MyScene"的场景,并附带一条消息。
|
||||
|
||||
### `select` and `create`
|
||||
|
||||
```shell
|
||||
选择所有蛋白质: select 8g2c_pro, polymer.protein
|
||||
|
||||
创建一个新的对象: create 8g2c_pro, polymer.protein
|
||||
|
||||
选择所有核酸: select 8g2c_nucleic, polymer.nucleic
|
||||
|
||||
创建一个新的对象: create 8g2c_nucleic, polymer.nucleic
|
||||
|
||||
选择小分子: select 8g2c_tyk, resn TYK
|
||||
```
|
||||
|
||||
### 背景美化
|
||||
|
||||
```shell
|
||||
# 1. 设置背景为白色,并将表面透明度设置为 50%
|
||||
bg_color white # 设置背景颜色为白色
|
||||
set transparency, 0.5 # 设置所有表面透明度为 50%
|
||||
|
||||
# 2. 使表面显示使用原子自身的颜色
|
||||
set surface_color_by_atom, 1 # 启用表面按原子颜色显示
|
||||
|
||||
# 3. 蛋白质:着色为橙色,并显示表面
|
||||
color orange, polymer.protein # 将所有蛋白质(polymer.protein)着色为橙色
|
||||
show surface, polymer.protein # 显示蛋白质的表面
|
||||
|
||||
# 4. 核酸:着色为白色,并显示表面
|
||||
color white, polymer.nucleic # 将所有核酸(polymer.nucleic)着色为白色
|
||||
show surface, polymer.nucleic # 显示核酸的表面
|
||||
|
||||
# 5. 小分子:根据分子的 ligand id(这里假设用 organic 选择小分子)着色为红色,并显示表面
|
||||
color red, organic # 将所有小分子(organic)着色为红色
|
||||
show surface, organic # 显示小分子的表面
|
||||
```
|
||||
|
||||
## 删除辅因子
|
||||
|
||||
```shell
|
||||
# 删除8G2C中的辅因子(保留TYK)
|
||||
cmd.remove("resn K or resn MG or resn SF4 or resn ZN")
|
||||
|
||||
# 删除8G2D中的辅因子(保留TYK)
|
||||
cmd.remove("resn K or resn MG or resn SF4 or resn ZN")
|
||||
```
|
||||
|
||||
## Schrodinger_Suites linux install
|
||||
|
||||
```shell
|
||||
cd Schrodinger_Suites_2021-2_Linux-x86_64
|
||||
bash INSTALL (或者chmod u+x INSTALL ,之后 ./INSTALL )
|
||||
(接下来选安装路径,比如/home/laiguanxue/softwares/Schrodinger_Suites_2023)
|
||||
(后面一路yes)
|
||||
(将Crack/patcher拷贝到安装路径中)
|
||||
chmod u+x schrodinger-2023-3-patcher-linux
|
||||
./schrodinger-2023-3-patcher-linux
|
||||
(之后选择破解的版本)
|
||||
```
|
||||
70
gradient_transparency.py
Normal file
70
gradient_transparency.py
Normal file
@@ -0,0 +1,70 @@
|
||||
from pymol import cmd
|
||||
import math
|
||||
|
||||
def calculate_gradient_transparency(obj, mole, num_segments=10, transparency_min=0.5, transparency_max=1.0):
|
||||
"""
|
||||
设置基于距离的透明度梯度,并允许自定义透明度变化范围。
|
||||
|
||||
参数:
|
||||
- obj: 对象名 (str)
|
||||
- mole: 小分子名 (str)
|
||||
- num_segments: 梯度分段数 (int)
|
||||
- transparency_min: 最小透明度 (float)
|
||||
- transparency_max: 最大透明度 (float)
|
||||
"""
|
||||
# 检查 obj 是否存在
|
||||
if not cmd.count_atoms(obj):
|
||||
print(f"Error: The object '{obj}' does not exist or is empty. Please check your inputs.")
|
||||
return
|
||||
|
||||
# 检查 mole 是否存在
|
||||
if not cmd.count_atoms(mole):
|
||||
print(f"Error: The object '{mole}' does not exist or is empty. Please check your inputs.")
|
||||
return
|
||||
|
||||
# 获取复合物的边界框
|
||||
min_coords, max_coords = cmd.get_extent(obj)
|
||||
diagonal_length = math.sqrt(sum((max_coords[i] - min_coords[i])**2 for i in range(3)))
|
||||
|
||||
# 手动计算 mole 的几何中心
|
||||
model = cmd.get_model(mole)
|
||||
x, y, z = 0, 0, 0
|
||||
for atom in model.atom:
|
||||
x += atom.coord[0]
|
||||
y += atom.coord[1]
|
||||
z += atom.coord[2]
|
||||
num_atoms = len(model.atom)
|
||||
center_coords = (x / num_atoms, y / num_atoms, z / num_atoms)
|
||||
|
||||
# 打印计算信息
|
||||
print("\n[Gradient Transparency Calculation]")
|
||||
print(f"Bounding Box Min: {min_coords}")
|
||||
print(f"Bounding Box Max: {max_coords}")
|
||||
print(f"Diagonal Length: {diagonal_length:.3f} Å")
|
||||
print(f"Center of {mole}: ({center_coords[0]:.3f}, {center_coords[1]:.3f}, {center_coords[2]:.3f})\n")
|
||||
|
||||
# 4. 计算梯度区间
|
||||
segment_length = diagonal_length / num_segments # 每个梯度的长度
|
||||
print(f"Gradient Segments: {num_segments} (Length per Segment: {segment_length:.3f} Å)\n")
|
||||
|
||||
# 打印透明度范围
|
||||
print(f"Transparency Range: {transparency_min} to {transparency_max}")
|
||||
|
||||
# 创建透明度梯度
|
||||
for i in range(num_segments):
|
||||
start = i * segment_length
|
||||
end = (i + 1) * segment_length
|
||||
|
||||
# 计算透明度值(线性插值)
|
||||
transparency = transparency_min + (transparency_max - transparency_min) * (i / (num_segments - 1))
|
||||
|
||||
# 创建选择并设置透明度(略去重复代码)
|
||||
print(f"Segment {i+1}: {start:.3f}-{end:.3f} Å, Transparency: {transparency:.2f}")
|
||||
|
||||
# 显示表面和卡通
|
||||
cmd.show("surface", obj)
|
||||
cmd.show("cartoon", obj)
|
||||
print("\n[Gradient Transparency Applied Successfully]\n")
|
||||
|
||||
# 调用函数(默认使用20个梯度)
|
||||
calculate_gradient_transparency("all", "mole", num_segments=20)
|
||||
@@ -220,6 +220,16 @@ def protgrey(selection='all'):
|
||||
#cmd.create(obj_name, f'byres (resn {resn} and chain {chain}) around {distance} or (resn {resn} and chain {chain})') # 选择resn的对象和resn对象周围3A的原子扩展至残基的原子
|
||||
#cmd.hide('everything', 'all')
|
||||
#cmd.show('lines', obj_name)
|
||||
# 选择所有核酸(DNA 或 RNA)
|
||||
# select nucleic_acids, polymer.nucleic
|
||||
# # 选择所有蛋白质
|
||||
# select proteins, polymer.protein
|
||||
# # 锁定到链
|
||||
# select chainA_protein, polymer.protein and chain A
|
||||
## pymol 编辑模式
|
||||
#选择mouse,3 botton edit 模式,需要在3 botton view 模式下先选择对象。
|
||||
#按住shift + 左键进行旋转
|
||||
#按住shift + 中键进行平移
|
||||
cmd.extend('colorp',colorp)
|
||||
cmd.extend('method',method)
|
||||
|
||||
|
||||
57
script/optimize_sdf.py
Normal file
57
script/optimize_sdf.py
Normal file
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- encoding: utf-8 -*-
|
||||
'''
|
||||
@file :optimize_sdf.py
|
||||
@Description: : 使用rdkit 将2d转3d,增加基本的坐标优化功能
|
||||
@Date :2024/09/07 09:34:41
|
||||
@Author :lyzeng
|
||||
@Email :pylyzeng@gmail.com
|
||||
@version :1.0
|
||||
'''
|
||||
|
||||
|
||||
|
||||
import os
|
||||
import click
|
||||
from rdkit import Chem
|
||||
from rdkit.Chem import AllChem
|
||||
|
||||
def generate_3d_coordinates(input_sdf: str, output_sdf: str):
|
||||
# 读取SDF文件
|
||||
suppl = Chem.SDMolSupplier(input_sdf)
|
||||
writer = Chem.SDWriter(output_sdf)
|
||||
|
||||
for mol in suppl:
|
||||
if mol is None:
|
||||
continue
|
||||
|
||||
# 生成3D坐标
|
||||
mol = Chem.AddHs(mol) # 添加氢原子
|
||||
if AllChem.EmbedMolecule(mol) == 0: # 生成3D坐标
|
||||
AllChem.UFFOptimizeMolecule(mol) # 优化分子结构
|
||||
writer.write(mol) # 将分子写入输出文件
|
||||
|
||||
writer.close()
|
||||
|
||||
@click.command()
|
||||
@click.argument('input_sdf', type=click.File('r'))
|
||||
@click.option('--output_dir', type=click.Path(), default='.', help='输出目录,默认为当前目录')
|
||||
def optimize_sdf(input_sdf, output_dir):
|
||||
"""优化输入SDF文件中的3D坐标并输出到指定目录"""
|
||||
# 获取输入文件名并构造输出文件路径
|
||||
input_filename = os.path.basename(input_sdf.name)
|
||||
output_sdf = os.path.join(output_dir, f"optimized_{input_filename}")
|
||||
|
||||
# 创建输出目录(如果不存在)
|
||||
os.makedirs(output_dir, exist_ok=True)
|
||||
|
||||
# 生成3D结构并保存
|
||||
generate_3d_coordinates(input_sdf.name, output_sdf)
|
||||
|
||||
click.echo(f"优化的SDF文件已保存到: {output_sdf}")
|
||||
|
||||
if __name__ == '__main__':
|
||||
optimize_sdf()
|
||||
|
||||
# python optimize_sdf.py /mnt/c/project/pymol/data/Structure2D_COMPOUND_CID_5280440.sdf --output_dir /mnt/c/project/pymol/data/output
|
||||
# python optimize_sdf.py --help
|
||||
Reference in New Issue
Block a user