Skip to content

Commit 548dd59

Browse files
committed
added rounview.py
1 parent 663672a commit 548dd59

File tree

1 file changed

+179
-0
lines changed

1 file changed

+179
-0
lines changed

roundview.py

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
from __future__ import division
2+
"""
3+
4+
5+
version 1.0 26 October 2015
6+
Posted in github for first time.
7+
8+
version 1.1 23 November 2015
9+
Corrected description of the rounding off the matrix elements.
10+
Corrected hard wrapped text the broke the script.
11+
Added example of running program as a horizontal script.
12+
Made code pep8 compliant (changed use of blank lines,
13+
removed whitespaces in defualt arguments assignments,
14+
inserted whitespaces after commas in lists,
15+
removed whitespaces at the ends of lines).
16+
Added version number.
17+
18+
version 1.2 23 May 2016
19+
Edited copyright notice.
20+
Corrected typos
21+
22+
23+
Copyright Notice
24+
================
25+
26+
Copyright (C) 2016 Blaine Mooers
27+
28+
This program is free software: you can redistribute it and/or modify
29+
it under the terms of the GNU General Public License as published by
30+
the Free Software Foundation, either version 3 of the License.
31+
32+
This program is distributed in the hope that it will be useful,
33+
but WITHOUT ANY WARRANTY; without even the implied warranty of
34+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
35+
See the GNU General Public License for more details:
36+
http://www.gnu.org/licenses/.
37+
38+
The source code in this file is copyrighted, but you can
39+
freely use and copy it as long as you don't change or remove any of
40+
the copyright notices.
41+
42+
Blaine Mooers, PhD
43+
44+
975 NE 10th St, BRC 466
45+
University of Oklahoma Health Sciences Center,
46+
Oklahoma City, OK, USA 73104
47+
48+
"""
49+
from pymol import stored, cmd
50+
__author__ = "Blaine Mooers"
51+
__copyright__ = "Blaine Mooers, University of Oklahoma Health Sciences Center, Oklahoma City, OK, USA 73104"
52+
__license__ = "GPL-3"
53+
__version__ = "1.0.2"
54+
__credits__ = ["William Beasley","Chiedza Kanyumbu"]
55+
# people who reported bug fixes, made suggestions, etc.
56+
__date__ = "30 May 2016"
57+
__maintainer__ = "Blaine Mooers"
58+
__email__ = "[email protected]"
59+
__status__ = "Production"
60+
61+
62+
def roundview(StoredView=0, decimal_places=2, outname="roundedview.txt"):
63+
64+
"""
65+
DESCRIPTION
66+
67+
Adds the command "roundview" that gets a view (default is 0,
68+
the current view; you can get a stored view assigned to some
69+
other digit with the view command) and rounds to two decimal
70+
places (two digits to the right of the decimal point) the
71+
viewpoint matrix elements and rewrites the matrix elements
72+
on a single line with no whitespaces and a semicolon at the
73+
end. The saved space eases the making of a single line of
74+
PyMOL commands separated by semicolons. This enables rapid
75+
and interactive editing of chunks of PyMOL commands. The
76+
viewpoints are appended to the bottom of a text file in the
77+
present working directory called "roundedview.txt". The line
78+
could be easier to copy from this file than from the command
79+
history window in the external gui. A semicolon with nothing
80+
to the right of it at the end of a line of grouped commands
81+
is harmless.
82+
83+
84+
USAGE
85+
86+
roundview [view, decimal_places, outname]
87+
88+
Note that the values in the [] are optional.
89+
90+
The default values for the arguments of the function
91+
are "0,2, roundedview.txt".
92+
93+
Simple one-line example with roundview.py script in current working
94+
directory--check by typing 'pwd' and 'ls *.py' on the command line. PyMOL
95+
should return 'roundview.py' in the lisf of files in the external (top) gui.
96+
Next, paste the following command on the external (top) commandline, hit
97+
return, and wait 5-10 seconds:
98+
99+
fetch 1lw9, async=0; run roundview.py; roundview 0,1
100+
101+
102+
The following view setting will be returned without the blackslash.
103+
104+
set_view (1.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,1.0,0.0,0.0,-155.2,35.1,11.5,9.7,122.3,188.0,-20.0);
105+
106+
Advanced option:
107+
108+
Copy roundview.py to the folder ~/.pymol/startup and then
109+
the command will always be accessible. You may have to
110+
create these directories.
111+
112+
113+
18 elements of the view matrix (0-17)
114+
115+
0 - 8 = column-major 3x3 matrix that rotates the model axes
116+
to camera axes
117+
118+
9 - 11 = origin of rotation relative to the camera
119+
in camera space
120+
121+
12 - 14 = origin of rotation in model space
122+
123+
15 = front plane distance from the camera
124+
125+
16 = rear plane distance from the camera
126+
127+
17 = orthoscopic flag
128+
(not implemented in older versions)
129+
130+
"""
131+
132+
#convert the commandline arguments from strings to integers
133+
134+
StoredView = int(StoredView)
135+
decimal_places = int(decimal_places)
136+
137+
138+
#call the get_view function
139+
140+
m = cmd.get_view(StoredView)
141+
142+
143+
#Make a list of the elements in the orientation matrix.
144+
145+
myList = [m[0], m[1], m[2], m[3], m[4], m[5], m[6],
146+
m[7], m[8], m[9], m[10], m[11], m[12], m[13], m[14],
147+
m[15], m[16], m[17]]
148+
149+
150+
#Round off the matrix elements to two decimal places (two fractional places)
151+
#This rounding approach solved the problem of unwanted
152+
#whitespaces when I tried using a string format statement
153+
154+
myRoundedList = [ round(elem, decimal_places) for elem in myList]
155+
156+
157+
#x is the format of the output. The whitespace is required
158+
#between the "set_view" and "(".
159+
160+
x = 'set_view ({0},{1},{2},{3},{4},{5},{6},{7},\
161+
{8},{9},{10},{11},{12},{13},{14},{15},{16},{17});'
162+
163+
164+
#print to the external gui.
165+
166+
print x.format(*myRoundedList)
167+
168+
169+
#Write to a text file.
170+
171+
myFile = open("roundedview.txt", "a")
172+
myFile.write(x.format(*myRoundedList) + "\n")
173+
myFile.close()
174+
return
175+
176+
177+
#The extend command makes roundview into a PyMOL command.
178+
179+
cmd.extend("roundview", roundview)

0 commit comments

Comments
 (0)