Pymol | Pymol绘制GridBox图

简介: Pymol | Pymol绘制GridBox图

将drawgridbox.py脚本放到pymol安装目录下

# -*- coding: utf-8 -*-
from pymol.cgo import *
from pymol import cmd
import itertools
from random import randint
#############################################################################
#
# drawgridbox.py -- Draw a grid box around a selection
#
# AUTHOR: Cunliang Geng
# DATE  : 19/5/2016
#
# Acknowledgement:
# This scirpt was written based on the DrawBoundingBox by Jason Vertrees
#
#############################################################################
def drawgridbox(selection="(all)", nx=10, ny=10, nz=10, padding=0.0, lw=2.0, r=1.0, g=1.0, b=1.0):
    """
    DESCRIPTION
        Given selection, draw a grid box around it.
    USAGE:
        drawgridbox [selection, [nx, [ny, [nz, [padding, [lw, [r, [g, b]]]]]]]]
    PARAMETERS:
        selection,    the selection to enboxen
                      defaults to (all)
        nx,           number of grids on axis X
                      defaults to 10
        ny,           number of grids on axis Y
                      defaults to 10
        nz,           number of grids on axis Z
                      defaults to 10
        padding,      defaults to 0
        lw,           line width
                      defaults to 2.0
        r,            red color component, valid range is [0.0, 1.0]
                      defaults to 1.0
        g,            green color component, valid range is [0.0, 1.0]
                      defaults to 1.0
        b,            blue color component, valid range is [0.0, 1.0]
                      defaults to 1.0
    RETURNS
        string, the name of the CGO box
    NOTES
        * This function creates a randomly named CGO grid box. The user can
        specify the number of grids on X/Y/Z axis, the width of the lines,
        the padding and also the color.
    """
    ([minX, minY, minZ],[maxX, maxY, maxZ]) = cmd.get_extent(selection)
    print("Box dimensions (%.2f, %.2f, %.2f)" % (maxX-minX, maxY-minY, maxZ-minZ))
    minX = minX - float(padding)
    minY = minY - float(padding)
    minZ = minZ - float(padding)
    maxX = maxX + float(padding)
    maxY = maxY + float(padding)
    maxZ = maxZ + float(padding)
    nX=int(nx)
    nY=int(ny)
    nZ=int(nz)
    dX = (maxX-minX)/nX
    dY = (maxY-minY)/nY
    dZ = (maxZ-minZ)/nZ
    if padding != 0:
        print("Box dimensions + padding (%.2f, %.2f, %.2f)" % (maxX-minX, maxY-minY, maxZ-minZ))
    gridbox = [
        LINEWIDTH, float(lw),
        BEGIN, LINES,
        COLOR, float(r), float(g), float(b),
        ]
    for i in range(nX):
        for j in range(nY):
            for k in range(nZ):
                dots= [
                    VERTEX, minX+i*dX, minY+j*dY, minZ+k*dZ,
                    VERTEX, minX+i*dX, minY+j*dY, minZ+(k+1)*dZ,
                    VERTEX, minX+i*dX, minY+(j+1)*dY, minZ+k*dZ,
                    VERTEX, minX+i*dX, minY+(j+1)*dY, minZ+(k+1)*dZ,
                    VERTEX, minX+(i+1)*dX, minY+j*dY, minZ+k*dZ,
                    VERTEX, minX+(i+1)*dX, minY+j*dY, minZ+(k+1)*dZ,
                    VERTEX, minX+(i+1)*dX, minY+(j+1)*dY, minZ+k*dZ,
                    VERTEX, minX+(i+1)*dX, minY+(j+1)*dY, minZ+(k+1)*dZ,
                    VERTEX, minX+i*dX, minY+j*dY, minZ+k*dZ,
                    VERTEX, minX+(i+1)*dX, minY+j*dY, minZ+k*dZ,
                    VERTEX, minX+i*dX, minY+(j+1)*dY, minZ+k*dZ,
                    VERTEX, minX+(i+1)*dX, minY+(j+1)*dY, minZ+k*dZ,
                    VERTEX, minX+i*dX, minY+(j+1)*dY, minZ+(k+1)*dZ,
                    VERTEX, minX+(i+1)*dX, minY+(j+1)*dY, minZ+(k+1)*dZ,
                    VERTEX, minX+i*dX, minY+j*dY, minZ+(k+1)*dZ,
                    VERTEX, minX+(i+1)*dX, minY+j*dY, minZ+(k+1)*dZ,
                    VERTEX, minX+i*dX, minY+j*dY, minZ+k*dZ,
                    VERTEX, minX+i*dX, minY+(j+1)*dY, minZ+k*dZ,
                    VERTEX, minX+(i+1)*dX, minY+j*dY, minZ+k*dZ,
                    VERTEX, minX+(i+1)*dX, minY+(j+1)*dY, minZ+k*dZ,
                    VERTEX, minX+i*dX, minY+j*dY, minZ+(k+1)*dZ,
                    VERTEX, minX+i*dX, minY+(j+1)*dY, minZ+(k+1)*dZ,
                    VERTEX, minX+(i+1)*dX, minY+j*dY, minZ+(k+1)*dZ,
                    VERTEX, minX+(i+1)*dX, minY+(j+1)*dY, minZ+(k+1)*dZ,
                ]
                gridbox += dots
    gridbox.append(END)
    boxName = "gridbox_" + str(randint(0,10000))
    while boxName in cmd.get_names():
        boxName = "gridbox_" + str(randint(0,10000))
    cmd.load_cgo(gridbox,boxName)
    return boxName
cmd.extend ("drawgridbox", drawgridbox)

绘图命令

import drawgridbox
show surface
drawgridbox 1cbh, nx=5, ny=5, nz=5,  lw=1, g=0, b=0

image.png

目录
相关文章
|
8月前
|
存储
QT图形视图框架绘制曲线图和Smith图
QT图形视图框架绘制曲线图和Smith图
161 0
|
8月前
时标网络图绘制步骤
时标网络图绘制步骤
时标网络图绘制步骤
|
8月前
如何绘制PAD图和N-S图(详细步骤)
如何绘制PAD图和N-S图(详细步骤)
761 0
|
7月前
|
机器学习/深度学习 图形学
神笔马良画出三维世界,基于线稿的3D生成编辑方法SketchDream来了
【6月更文挑战第10天】研究人员推出SketchDream系统,将手绘草图与文本描述转化为3D模型,简化了3D内容创作过程。该系统基于深度学习的多模态生成模型,结合草图和文本信息,实现高质量3D生成与编辑。尽管有局限性,如依赖预训练模型和对复杂编辑任务的处理能力,SketchDream在3D生成和编辑方面表现出色,降低了3D建模的门槛。[论文链接](https://arxiv.org/pdf/2405.06461)
104 1
|
8月前
|
存储 数据可视化 关系型数据库
绘制圆环图/雷达图/星形图/极坐标图/径向图POLAR CHART可视化分析汽车性能数据
绘制圆环图/雷达图/星形图/极坐标图/径向图POLAR CHART可视化分析汽车性能数据
|
8月前
|
Python
matplotlib绘制动态瀑布图
matplotlib绘制动态瀑布图
|
8月前
|
存储 数据可视化
使用 plotly 绘制旭日图
使用 plotly 绘制旭日图
350 0
|
8月前
|
存储 数据可视化
创建乐高版马赛克图
创建乐高版马赛克图
113 0
|
数据可视化
R绘图 | 云雨图+双向条形图
R绘图 | 云雨图+双向条形图
174 0
|
数据可视化 数据挖掘
绘图系列|R-corrplot相关图
绘图系列|R-corrplot相关图
156 0