forked from Pymol-Scripts/Pymol-script-repo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
drawgridbox.py
125 lines (105 loc) · 4.43 KB
/
drawgridbox.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# -*- 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)