1 |
filippis |
40 |
package tools; |
2 |
|
|
|
3 |
|
|
import java.sql.*; |
4 |
|
|
import java.io.*; |
5 |
|
|
import java.util.*; |
6 |
|
|
import java.text.*; |
7 |
|
|
|
8 |
|
|
/** |
9 |
|
|
* Package: tools |
10 |
|
|
* Class: PyMol |
11 |
|
|
* Author: Ioannis Filippis, filippis@molgen.mpg.de |
12 |
|
|
* Date: 20/03/2006 |
13 |
|
|
* |
14 |
|
|
* This class serves as a simple PyMol API. Most methods send PyMol commands |
15 |
|
|
* to the PrintWriter taken by the constructor, while others return pymol |
16 |
|
|
* selection strings. There is also the possibility to send the atomic |
17 |
|
|
* coordinates of a specific model of a macromolecule directly from msdsd |
18 |
|
|
* and load them on-the-fly. |
19 |
|
|
* |
20 |
|
|
* Notes: |
21 |
|
|
* - This is not a full PyMol API. Existing methods wrap basic pymol commands |
22 |
|
|
* in a simple, rather stupid way to facilitate contact graph visualization. |
23 |
|
|
* |
24 |
|
|
* Changelog: |
25 |
|
|
* 20/03/06 first created by IF |
26 |
|
|
*/ |
27 |
|
|
public class PyMol { |
28 |
|
|
|
29 |
|
|
// Out: the PrintWriter where PyMol commands are sent to |
30 |
|
|
// attrs: a HashMap with keys the PyMol state variables allowed to be set |
31 |
|
|
// by the set class. Values are integers (could be used in a "switch") |
32 |
|
|
// DF: used to format decimal numbers so commands issued are readable |
33 |
|
|
// objectNameQuotes: used to enable (disable) the use of double quotes for |
34 |
|
|
// strings in PyMol commands (check list related methods) |
35 |
|
|
private PrintWriter Out = null; |
36 |
|
|
private HashMap<String, Integer> attrs = new HashMap<String, Integer>(); |
37 |
|
|
private DecimalFormat DF = new DecimalFormat("#0.000"); |
38 |
|
|
private boolean objectNameQuotes = true; |
39 |
|
|
|
40 |
|
|
// constructor |
41 |
|
|
public PyMol(PrintWriter out) { |
42 |
|
|
|
43 |
|
|
this.Out = out; |
44 |
|
|
|
45 |
|
|
attrs.put("sphere_transparency", new Integer(1)); |
46 |
|
|
attrs.put("sphere_scale", new Integer(2)); |
47 |
|
|
attrs.put("dash_gap", new Integer(3)); |
48 |
|
|
attrs.put("dash_width", new Integer(4)); |
49 |
|
|
attrs.put("transparancy", new Integer(5)); |
50 |
|
|
|
51 |
|
|
} |
52 |
|
|
|
53 |
|
|
/** |
54 |
|
|
* sends the atom lines of a model (modelId) of a biological unit (assemblyId) of a protein |
55 |
|
|
* (accessionCode) directly from msdsd. In this way, the structure is loaded wihout temporary |
56 |
|
|
* pdb files. The structure object is named using the pattern accessionCode_assemblyId_modelId. |
57 |
|
|
* |
58 |
|
|
* Notes: |
59 |
|
|
* - A connection file is needed to connect to msdsd |
60 |
|
|
* - The chain_pdb_code is used in the chainID field in the atom line, while the chain_code is used |
61 |
|
|
* in the segID field (due to its length). Therefore, "segi" and not "chain" must be used in pymol |
62 |
|
|
* selections (all methods take care of that based on the boolean parameter msdsd) |
63 |
|
|
* - There are two versions of sendAtomLines. One that takes the atomic coordinates from the |
64 |
|
|
* partial atom_data tables (needs the table number e.g. 1 for atom_data_1, but is faster), |
65 |
|
|
* while the other uses the merged table (really slow - should be avoided) |
66 |
|
|
* - In general, the method is slow. The use of temporary files should be preferred. Have a look |
67 |
|
|
* at Msdsd2Pdb class. |
68 |
|
|
*/ |
69 |
|
|
public void sendAtomLines(String accessionCode, int assemblyId, int modelId, int atomDataTblNum, String connFile) { |
70 |
|
|
|
71 |
|
|
String query = "SELECT CONCAT("+ |
72 |
|
|
"RPAD(\"ATOM\", 6, \" \"), "+ |
73 |
|
|
"LPAD(serial, 5, \" \"), "+ |
74 |
|
|
"\" \", "+ |
75 |
|
|
"LPAD(chem_atom_name, 4, \" \"), "+ |
76 |
|
|
"IF(alt_code IS NULL, \" \", alt_code), "+ |
77 |
|
|
"code_3_letter, "+ |
78 |
|
|
"\" \", "+ |
79 |
|
|
"IF(chain_pdb_code IS NULL, \" \", chain_pdb_code), "+ |
80 |
|
|
"LPAD(residue_serial, 4, \" \"), "+ |
81 |
|
|
"IF(residue_pdb_insert_code IS NULL, \" \", residue_pdb_insert_code), "+ |
82 |
|
|
"REPEAT(\" \", 3), "+ |
83 |
|
|
"LPAD(x, 8, \" \"), "+ |
84 |
|
|
"LPAD(y, 8, \" \"), "+ |
85 |
|
|
"LPAD(z, 8, \" \"), "+ |
86 |
|
|
"LPAD(occupancy, 6, \" \"), "+ |
87 |
|
|
"REPEAT(\" \", 6), "+ |
88 |
|
|
"REPEAT(\" \", 6), "+ |
89 |
|
|
"RPAD(chain_code, 4, \" \") "+ |
90 |
|
|
") AS atom_lines FROM msdsd.atom_data_"+atomDataTblNum+" WHERE "+ |
91 |
|
|
"(assembly_id = "+assemblyId+") AND "+ |
92 |
|
|
"(model_id = "+modelId+") AND "+ |
93 |
|
|
"((alt_code = \"A\") OR (alt_code IS NULL)) AND "+ |
94 |
|
|
"(pdb_group = \"A\") "+ |
95 |
|
|
"ORDER BY chain_code, residue_serial, serial;"; |
96 |
|
|
|
97 |
|
|
mySQLConnect SQLC = new mySQLConnect(); |
98 |
|
|
SQLC.readConnectionFile(connFile); |
99 |
|
|
Connection conn = SQLC.openConnection(); |
100 |
|
|
|
101 |
|
|
Statement S; |
102 |
|
|
ResultSet R; |
103 |
|
|
|
104 |
|
|
Out.print("cmd.read_pdbstr(\"\"\""); |
105 |
|
|
|
106 |
|
|
try { |
107 |
|
|
S = conn.createStatement(); |
108 |
|
|
R = S.executeQuery(query); |
109 |
|
|
while (R.next()) { |
110 |
|
|
Out.println(R.getString(1)+"\\"); |
111 |
|
|
} |
112 |
|
|
R.close(); |
113 |
|
|
S.close(); |
114 |
|
|
} // end try |
115 |
|
|
catch (SQLException E) { |
116 |
|
|
System.out.println("SQLException: " + E.getMessage()); |
117 |
|
|
System.out.println("SQLState: " + E.getSQLState()); |
118 |
|
|
System.out.println("VendorError: " + E.getErrorCode()); |
119 |
|
|
} // end catch |
120 |
|
|
|
121 |
|
|
SQLC.closeConnection(conn); |
122 |
|
|
|
123 |
|
|
Out.println("END\"\"\", \""+accessionCode+"_"+assemblyId+"_"+modelId+"\")"); |
124 |
|
|
|
125 |
|
|
} |
126 |
|
|
|
127 |
|
|
/** |
128 |
|
|
* sends the atom lines of a model (modelId) of a biological unit (assemblyId) of a protein |
129 |
|
|
* (accessionCode) directly from msdsd. In this way, the structure is loaded wihout temporary |
130 |
|
|
* pdb files. The structure object is named using the pattern accessionCode_assemblyId_modelId. |
131 |
|
|
* |
132 |
|
|
* Notes: |
133 |
|
|
* - A connection file is needed to connect to msdsd |
134 |
|
|
* - The chain_pdb_code is used in the chainID field in the atom line, while the chain_code is used |
135 |
|
|
* in the segID field (due to its length). Therefore, "segi" and not "chain" must be used in pymol |
136 |
|
|
* selections (all methods take care of that based on the boolean parameter msdsd) |
137 |
|
|
* - There are two versions of sendAtomLines. One that takes the atomic coordinates from the |
138 |
|
|
* partial atom_data tables (needs the table number e.g. 1 for atom_data_1, but is faster), |
139 |
|
|
* while the other uses the merged table (really slow - should be avoided) |
140 |
|
|
* - In general, the method is slow. The use of temporary files should be preferred. Have a look |
141 |
|
|
* at Msdsd2Pdb class. |
142 |
|
|
*/ |
143 |
|
|
public void sendAtomLines(String accessionCode, int assemblyId, int modelId, String connFile) { |
144 |
|
|
|
145 |
|
|
String query = "SELECT CONCAT("+ |
146 |
|
|
"RPAD(\"ATOM\", 6, \" \"), "+ |
147 |
|
|
"LPAD(serial, 5, \" \"), "+ |
148 |
|
|
"\" \", "+ |
149 |
|
|
"LPAD(chem_atom_name, 4, \" \"), "+ |
150 |
|
|
"IF(alt_code IS NULL, \" \", alt_code), "+ |
151 |
|
|
"code_3_letter, "+ |
152 |
|
|
"\" \", "+ |
153 |
|
|
"IF(chain_pdb_code IS NULL, \" \", chain_pdb_code), "+ |
154 |
|
|
"LPAD(residue_serial, 4, \" \"), "+ |
155 |
|
|
"IF(residue_pdb_insert_code IS NULL, \" \", residue_pdb_insert_code), "+ |
156 |
|
|
"REPEAT(\" \", 3), "+ |
157 |
|
|
"LPAD(x, 8, \" \"), "+ |
158 |
|
|
"LPAD(y, 8, \" \"), "+ |
159 |
|
|
"LPAD(z, 8, \" \"), "+ |
160 |
|
|
"LPAD(occupancy, 6, \" \"), "+ |
161 |
|
|
"REPEAT(\" \", 6), "+ |
162 |
|
|
"REPEAT(\" \", 6), "+ |
163 |
|
|
"RPAD(chain_code, 4, \" \") "+ |
164 |
|
|
") AS atom_lines FROM msdsd.atom_data WHERE "+ |
165 |
|
|
"(assembly_id = "+assemblyId+") AND "+ |
166 |
|
|
"(model_id = "+modelId+") AND "+ |
167 |
|
|
"((alt_code = \"A\") OR (alt_code IS NULL)) AND "+ |
168 |
|
|
"(pdb_group = \"A\") "+ |
169 |
|
|
"ORDER BY chain_code, residue_serial, serial;"; |
170 |
|
|
|
171 |
|
|
mySQLConnect SQLC = new mySQLConnect(); |
172 |
|
|
SQLC.readConnectionFile(connFile); |
173 |
|
|
Connection conn = SQLC.openConnection(); |
174 |
|
|
|
175 |
|
|
Statement S; |
176 |
|
|
ResultSet R; |
177 |
|
|
|
178 |
|
|
Out.print("cmd.read_pdbstr(\"\"\""); |
179 |
|
|
|
180 |
|
|
try { |
181 |
|
|
S = conn.createStatement(); |
182 |
|
|
R = S.executeQuery(query); |
183 |
|
|
while (R.next()) { |
184 |
|
|
Out.println(R.getString(1)+"\\"); |
185 |
|
|
} |
186 |
|
|
R.close(); |
187 |
|
|
S.close(); |
188 |
|
|
} // end try |
189 |
|
|
catch (SQLException E) { |
190 |
|
|
System.out.println("SQLException: " + E.getMessage()); |
191 |
|
|
System.out.println("SQLState: " + E.getSQLState()); |
192 |
|
|
System.out.println("VendorError: " + E.getErrorCode()); |
193 |
|
|
} // end catch |
194 |
|
|
|
195 |
|
|
SQLC.closeConnection(conn); |
196 |
|
|
|
197 |
|
|
Out.println("END\"\"\", \""+accessionCode+"_"+assemblyId+"_"+modelId+"\")"); |
198 |
|
|
|
199 |
|
|
} |
200 |
|
|
|
201 |
|
|
/** |
202 |
|
|
* loads a pdb file |
203 |
|
|
* |
204 |
|
|
* Notes: |
205 |
|
|
* - There are two versions. One of them loads the pdb file specified by its name and the directory path, while |
206 |
|
|
* the other just uses the filename. |
207 |
|
|
* - Pdb file is expected to have the extension ".pdb". |
208 |
|
|
* - The structure object is named using the accession code (extension ".pdb" is trimmed) |
209 |
|
|
*/ |
210 |
|
|
public String loadPDB(String pdbFileName, String pdbDir) { |
211 |
|
|
|
212 |
|
|
Out.println("cmd.load(\""+pdbDir+"/"+pdbFileName+"\", \""+pdbFileName.substring(0, pdbFileName.length()-4)+"\", 1)"); |
213 |
|
|
|
214 |
|
|
return (pdbFileName.substring(0, pdbFileName.length()-4)); |
215 |
|
|
|
216 |
|
|
} |
217 |
|
|
|
218 |
|
|
/** |
219 |
|
|
* loads a pdb file |
220 |
|
|
* |
221 |
|
|
* Notes: |
222 |
|
|
* - There are two versions. One of them loads the pdb file specified by its name and the directory path, while |
223 |
|
|
* the other just uses the filename. |
224 |
|
|
* - Pdb file is expected to have the extension ".pdb". |
225 |
|
|
* - The structure object is named using the accession code (extension ".pdb" is trimmed) |
226 |
|
|
*/ |
227 |
|
|
public String loadPDB(String pdbFileName) { |
228 |
|
|
|
229 |
|
|
Out.println("cmd.load(\""+pdbFileName+"\", \""+pdbFileName.substring(0, pdbFileName.length()-4)+"\", 1)"); |
230 |
|
|
|
231 |
|
|
return (pdbFileName.substring(0, pdbFileName.length()-4)); |
232 |
|
|
|
233 |
|
|
} |
234 |
|
|
|
235 |
|
|
/** |
236 |
|
|
* adds a node as a sphere centered on the Ca of a residue |
237 |
|
|
* |
238 |
|
|
* Notes: |
239 |
|
|
* - The node object is named n.cid.num (e.g. n.A.15 is the 15th residue-node in chain A) |
240 |
|
|
* - The msdsd boolean is used to denote whether msdsd is the source of the structure. In that case, |
241 |
|
|
* segi is used instead of chain |
242 |
|
|
*/ |
243 |
|
|
public String addNode(String cid, int num, boolean msdsd) { |
244 |
|
|
|
245 |
|
|
String nodeName = "n."+cid+"."+num; |
246 |
|
|
String nodeSel = selectNode(cid, num, msdsd, true); |
247 |
|
|
|
248 |
|
|
Out.println("cmd.create(\""+nodeName+"\", \""+nodeSel+"\""); |
249 |
|
|
Out.println("cmd.show(\"sphere\", \""+nodeName+"\""); |
250 |
|
|
|
251 |
|
|
return nodeName; |
252 |
|
|
|
253 |
|
|
} |
254 |
|
|
|
255 |
|
|
/** |
256 |
|
|
* adds an edge as a distance object between the Ca's of 2 residues |
257 |
|
|
* |
258 |
|
|
* Notes: |
259 |
|
|
* - The edge object is named e.i_cid.i_num.j_cid.j_num (e.g. e.A.1.B.10 is the edge |
260 |
|
|
* between the 1st residue-node in chain A and the 10th residue in chain B) |
261 |
|
|
* - The msdsd boolean is used to denote whether msdsd is the source of the structure. In that case, |
262 |
|
|
* segi is used instead of chain |
263 |
|
|
*/ |
264 |
|
|
public String addEdge(String i_cid, int i_num, String j_cid, int j_num, boolean msdsd) { |
265 |
|
|
|
266 |
|
|
String edgeName = "e."+i_cid+"."+i_num+"."+j_cid+"."+j_num; |
267 |
|
|
String iNodeSel = selectNode(i_cid, i_num, msdsd, true); |
268 |
|
|
String jNodeSel = selectNode(j_cid, j_num, msdsd, true); |
269 |
|
|
|
270 |
|
|
Out.println("cmd.distance(\""+edgeName+"\", \""+iNodeSel+"\", \""+jNodeSel+"\""); |
271 |
|
|
Out.println("cmd.hide(\"labels\")"); |
272 |
|
|
|
273 |
|
|
return edgeName; |
274 |
|
|
|
275 |
|
|
} |
276 |
|
|
|
277 |
|
|
/** |
278 |
|
|
* adds an edge as a sausage Compiled Graphic Object (cgo) between the Ca's of 2 residues |
279 |
|
|
* |
280 |
|
|
* Notes: |
281 |
|
|
* - The edge object is named e.i_cid.i_num.j_cid.j_num (e.g. e.A.1.B.10 is the edge |
282 |
|
|
* between the 1st residue-node in chain A and the 10th residue in chain B) |
283 |
|
|
* - If the graph is directed, then only half of the user-formatted sausage will be |
284 |
|
|
* drawn towards the target node and the rest will be drawn as a thin sausage. |
285 |
|
|
* - rgb(color) and half_rgb(half_color) define the color of the two parts of the edge (if directed). |
286 |
|
|
* There are two versions of addCgoEdge, one with string (color) and one with array of doubles |
287 |
|
|
* (rgb) parameters. |
288 |
|
|
* - The msdsd boolean is used to denote whether msdsd is the source of the structure. In that case, |
289 |
|
|
* segi is used instead of chain. |
290 |
|
|
*/ |
291 |
|
|
public String addCgoEdge(String i_cid, int i_num, String j_cid, int j_num, double[] rgb, double dashGap, double dashLength, double dashRadius, boolean directed, double[] half_rgb, boolean msdsd) { |
292 |
|
|
|
293 |
|
|
String edgeName = "e."+i_cid+"."+i_num+"."+j_cid+"."+j_num; |
294 |
|
|
String iNodeSel = selectNode(i_cid, i_num, msdsd, true); |
295 |
|
|
String jNodeSel = selectNode(j_cid, j_num, msdsd, true); |
296 |
|
|
|
297 |
|
|
Out.println("edge name="+edgeName+", i_node="+iNodeSel+", j_node="+jNodeSel+", r="+rgb[0]+", g="+rgb[1]+", b="+rgb[2]+", dg="+dashGap+", dl="+dashLength+", dr="+dashRadius+", dir="+(directed?1:0)+", dir_r="+half_rgb[0]+", dir_g="+half_rgb[1]+", dir_b="+half_rgb[2]+""); |
298 |
|
|
|
299 |
|
|
return edgeName; |
300 |
|
|
|
301 |
|
|
} |
302 |
|
|
|
303 |
|
|
/** |
304 |
|
|
* adds an edge as a sausage Compiled Graphic Object (cgo) between the Ca's of 2 residues |
305 |
|
|
* |
306 |
|
|
* Notes: |
307 |
|
|
* - The edge object is named e.i_cid.i_num.j_cid.j_num (e.g. e.A.1.B.10 is the edge |
308 |
|
|
* between the 1st residue-node in chain A and the 10th residue in chain B) |
309 |
|
|
* - If the graph is directed, then only half of the user-formatted sausage will be |
310 |
|
|
* drawn towards the target node and the rest will be drawn as a thin sausage. |
311 |
|
|
* - rgb(color) and half_rgb(half_color) define the color of the two parts of the edge (if directed). |
312 |
|
|
* There are two versions of addCgoEdge, one with string (color) and one with array of doubles |
313 |
|
|
* (rgb) parameters. |
314 |
|
|
* - The msdsd boolean is used to denote whether msdsd is the source of the structure. In that case, |
315 |
|
|
* segi is used instead of chain. |
316 |
|
|
* - Have a look at the /project/StruPPi/PyMolAll/pymol/scripts/ioannis/graph.py with the |
317 |
|
|
* implementation of the edge command |
318 |
|
|
*/ |
319 |
|
|
public String addCgoEdge(String i_cid, int i_num, String j_cid, int j_num, String color, double dashGap, double dashLength, double dashRadius, boolean directed, String half_color, boolean msdsd) { |
320 |
|
|
|
321 |
|
|
String edgeName = "e."+i_cid+"."+i_num+"."+j_cid+"."+j_num; |
322 |
|
|
String iNodeSel = selectNode(i_cid, i_num, msdsd, true); |
323 |
|
|
String jNodeSel = selectNode(j_cid, j_num, msdsd, true); |
324 |
|
|
|
325 |
|
|
Out.println("edge name="+edgeName+", i_node="+iNodeSel+", j_node="+jNodeSel+", color="+color+", dg="+dashGap+", dl="+dashLength+", dr="+dashRadius+", dir="+(directed?1:0)+", dir_color="+color+""); |
326 |
|
|
|
327 |
|
|
return edgeName; |
328 |
|
|
|
329 |
|
|
} |
330 |
|
|
|
331 |
|
|
/** |
332 |
|
|
* deletes an object or selection |
333 |
|
|
*/ |
334 |
|
|
public void delete(String objectName) { |
335 |
|
|
|
336 |
|
|
Out.println("cmd.delete("+(objectNameQuotes?"\""+objectName+"\"":objectName)+")"); |
337 |
|
|
if (!objectNameQuotes) { setObjectNameQuotes(true); } |
338 |
|
|
|
339 |
|
|
} |
340 |
|
|
|
341 |
|
|
/** |
342 |
|
|
* deletes a node |
343 |
|
|
*/ |
344 |
|
|
public void delNode(String cid, int num) { |
345 |
|
|
|
346 |
|
|
String nodeName = "\"n."+cid+"."+num+"\""; |
347 |
|
|
Out.println("cmd.delete("+nodeName+")"); |
348 |
|
|
|
349 |
|
|
} |
350 |
|
|
|
351 |
|
|
/** |
352 |
|
|
* deletes an edge |
353 |
|
|
*/ |
354 |
|
|
public void delEdge(String i_cid, int i_num, String j_cid, int j_num) { |
355 |
|
|
|
356 |
|
|
String edgeName = "\"e."+i_cid+"."+i_num+"."+j_cid+"."+j_num+"\""; |
357 |
|
|
Out.println("cmd.delete("+edgeName+")"); |
358 |
|
|
|
359 |
|
|
} |
360 |
|
|
|
361 |
|
|
/** |
362 |
|
|
* turns on atom/bond representation specified by what for an object or selection |
363 |
|
|
*/ |
364 |
|
|
public void showWhat(String what, String objectName) { |
365 |
|
|
|
366 |
|
|
Out.println("cmd.show(\""+what+"\", "+(objectNameQuotes?"\""+objectName+"\"":objectName)+")"); |
367 |
|
|
if (!objectNameQuotes) { setObjectNameQuotes(true); } |
368 |
|
|
|
369 |
|
|
} |
370 |
|
|
|
371 |
|
|
/** |
372 |
|
|
* turns on atom/bond representation for all bonds for an object or selection |
373 |
|
|
*/ |
374 |
|
|
public void show(String objectName) { |
375 |
|
|
|
376 |
|
|
Out.println("cmd.show(\"everything\", "+(objectNameQuotes?"\""+objectName+"\"":objectName)+")"); |
377 |
|
|
if (!objectNameQuotes) { setObjectNameQuotes(true); } |
378 |
|
|
|
379 |
|
|
} |
380 |
|
|
|
381 |
|
|
|
382 |
|
|
/** |
383 |
|
|
* turns on node representation |
384 |
|
|
*/ |
385 |
|
|
public void showNode(String cid, int num) { |
386 |
|
|
|
387 |
|
|
String nodeName = "n."+cid+"."+num; |
388 |
|
|
Out.println("cmd.show(\"sphere\", \""+nodeName+"\")"); |
389 |
|
|
|
390 |
|
|
} |
391 |
|
|
|
392 |
|
|
/** |
393 |
|
|
* turns on edge representation |
394 |
|
|
*/ |
395 |
|
|
public void showEdge(String i_cid, int i_num, String j_cid, int j_num) { |
396 |
|
|
|
397 |
|
|
String edgeName = "e."+i_cid+"."+i_num+"."+j_cid+"."+j_num; |
398 |
|
|
Out.println("cmd.show(\"everything\", \""+edgeName+"\""); |
399 |
|
|
|
400 |
|
|
} |
401 |
|
|
|
402 |
|
|
/** |
403 |
|
|
* turns off atom/bond representation specified by what for an object or selection |
404 |
|
|
*/ |
405 |
|
|
public void hideWhat(String what, String objectName) { |
406 |
|
|
|
407 |
|
|
Out.println("cmd.hide(\""+what+"\", "+(objectNameQuotes?"\""+objectName+"\"":objectName)+")"); |
408 |
|
|
if (!objectNameQuotes) { setObjectNameQuotes(true); } |
409 |
|
|
|
410 |
|
|
} |
411 |
|
|
|
412 |
|
|
/** |
413 |
|
|
* turns off atom/bond representation for all bonds for an object or selection |
414 |
|
|
*/ |
415 |
|
|
public void hide(String objectName) { |
416 |
|
|
|
417 |
|
|
Out.println("cmd.hide(\"everything\", "+(objectNameQuotes?"\""+objectName+"\"":objectName)+")"); |
418 |
|
|
if (!objectNameQuotes) { setObjectNameQuotes(true); } |
419 |
|
|
|
420 |
|
|
} |
421 |
|
|
|
422 |
|
|
/** |
423 |
|
|
* turns off node representation |
424 |
|
|
*/ |
425 |
|
|
public void hideNode(String cid, int num) { |
426 |
|
|
|
427 |
|
|
String nodeName = "n."+cid+"."+num; |
428 |
|
|
Out.println("cmd.hide(\"everything\", \""+nodeName+"\")"); |
429 |
|
|
|
430 |
|
|
} |
431 |
|
|
|
432 |
|
|
/** |
433 |
|
|
* turns off edge representation |
434 |
|
|
*/ |
435 |
|
|
public void hideEdge(String i_cid, int i_num, String j_cid, int j_num) { |
436 |
|
|
|
437 |
|
|
String edgeName = "e."+i_cid+"."+i_num+"."+j_cid+"."+j_num; |
438 |
|
|
Out.println("cmd.hide(\"everything\", \""+edgeName+"\")"); |
439 |
|
|
|
440 |
|
|
} |
441 |
|
|
|
442 |
|
|
/** |
443 |
|
|
* creates a named neighbourhood selection using all atoms within distCutOff Angstrom from |
444 |
|
|
* all atoms of the specified residue |
445 |
|
|
* |
446 |
|
|
* Notes: |
447 |
|
|
* - The neighbourhood selection is named n.cid.num.N (e.g. n.A.1.N is the neighbourhood of |
448 |
|
|
* the 1st residue-node in chain A) |
449 |
|
|
* - The msdsd boolean is used to denote whether msdsd is the source of the structure. In that case, |
450 |
|
|
* segi is used instead of chain. |
451 |
|
|
*/ |
452 |
|
|
public void selNbrPml(String cid, int num, double distCutOff, boolean msdsd) { |
453 |
|
|
|
454 |
|
|
String nodeNbrName = "n."+cid+"."+num+".N"; |
455 |
|
|
String nodeSel = selectNode(cid, num, msdsd, false); |
456 |
|
|
|
457 |
|
|
Out.println("cmd.select(\""+nodeNbrName+"\", \""+nodeSel + " around "+DF.format(distCutOff)+"\")"); |
458 |
|
|
|
459 |
|
|
} |
460 |
|
|
|
461 |
|
|
/** |
462 |
|
|
* creates a selection called name using the atom selection of the papameter selection |
463 |
|
|
* |
464 |
|
|
* Notes: |
465 |
|
|
* - If pink is false, the selection display is disabled (pink stuff go away!!!!) |
466 |
|
|
*/ |
467 |
|
|
public void selPml(String name, String selection, boolean pink) { |
468 |
|
|
|
469 |
|
|
Out.println("cmd.select(\""+name+"\", \""+selection+"\")"); |
470 |
|
|
if (!pink) { Out.println("cmd.disable(\""+name+"\")"); }; |
471 |
|
|
|
472 |
|
|
} |
473 |
|
|
|
474 |
|
|
/** |
475 |
|
|
* returns an atom selection string for a node |
476 |
|
|
* |
477 |
|
|
* Notes: |
478 |
|
|
* - The CA boolean is used to denote whether the Ca atom should be only selected |
479 |
|
|
* - The msdsd boolean is used to denote whether msdsd is the source of the structure. In that case, |
480 |
|
|
* segi is used instead of chain. |
481 |
|
|
*/ |
482 |
|
|
public String selectNode(String cid, int num, boolean msdsd, boolean CA) { |
483 |
|
|
|
484 |
|
|
return "("+(msdsd?"segi ":"chain ")+(cid.equals("")?"\"\"":cid)+" and resi "+num+(CA?" and name CA":"")+")"; |
485 |
|
|
|
486 |
|
|
} |
487 |
|
|
|
488 |
|
|
/** |
489 |
|
|
* returns an atom selection string for a chain |
490 |
|
|
* |
491 |
|
|
* Notes: |
492 |
|
|
* - The msdsd boolean is used to denote whether msdsd is the source of the structure. In that case, |
493 |
|
|
* segi is used instead of chain. |
494 |
|
|
*/ |
495 |
|
|
public String selectChain(String cid, boolean msdsd) { |
496 |
|
|
|
497 |
|
|
return "("+(msdsd?"segi ":"chain ")+(cid.equals("")?"\"\"":cid)+")"; |
498 |
|
|
|
499 |
|
|
} |
500 |
|
|
|
501 |
|
|
/** |
502 |
|
|
* changes one of the PyMol state variable (attribute) for a specific object or selection |
503 |
|
|
* and sets it equal to the provided value. |
504 |
|
|
* |
505 |
|
|
* Notes: |
506 |
|
|
* - If the state variable is not defined in the attrs hashMap, then set returns -1 else 0. |
507 |
|
|
*/ |
508 |
|
|
public int set(String attribute, double value, String objectName) { |
509 |
|
|
|
510 |
|
|
Integer key = null; |
511 |
|
|
key = attrs.get(attribute); |
512 |
|
|
|
513 |
|
|
if (key == null) { return -1; } |
514 |
|
|
|
515 |
|
|
Out.println("cmd.set(\""+attribute+"\", "+DF.format(value)+", "+(objectNameQuotes?"\""+objectName+"\"":objectName)+")"); |
516 |
|
|
if (!objectNameQuotes) { setObjectNameQuotes(true); } |
517 |
|
|
|
518 |
|
|
return 0; |
519 |
|
|
|
520 |
|
|
} |
521 |
|
|
|
522 |
|
|
/** |
523 |
|
|
* sets the color for a node |
524 |
|
|
*/ |
525 |
|
|
public void setNodeColor(String color, String nodeName) { |
526 |
|
|
|
527 |
|
|
Out.println("cmd.set(\"sphere_color\", \""+color+"\", "+(objectNameQuotes?"\""+nodeName+"\"":nodeName)+")"); |
528 |
|
|
if (!objectNameQuotes) { setObjectNameQuotes(true); } |
529 |
|
|
|
530 |
|
|
} |
531 |
|
|
|
532 |
|
|
/** |
533 |
|
|
* sets the color for an object or selection |
534 |
|
|
*/ |
535 |
|
|
public void setColor(String color, String objectName) { |
536 |
|
|
|
537 |
|
|
Out.println("cmd.color(\""+color+"\", "+(objectNameQuotes?"\""+objectName+"\"":objectName)+")"); |
538 |
|
|
if (!objectNameQuotes) { setObjectNameQuotes(true); } |
539 |
|
|
|
540 |
|
|
} |
541 |
|
|
|
542 |
|
|
/** |
543 |
|
|
* define a new color or rather color name based on an existing color |
544 |
|
|
*/ |
545 |
|
|
public void createColor(String colorName, String color) { |
546 |
|
|
|
547 |
|
|
Out.println("cmd.set_color(\""+colorName+"\", cmd.get_color_tuple(cmd.get_color_index(\""+color+"\")))"); |
548 |
|
|
|
549 |
|
|
} |
550 |
|
|
|
551 |
|
|
/** |
552 |
|
|
* define a new color providing the RGB array of doubles |
553 |
|
|
*/ |
554 |
|
|
public void createColor(String colorName, double[] rgb) { |
555 |
|
|
|
556 |
|
|
Out.println("cmd.set_color(\""+colorName+"\", ["+DF.format(rgb[0])+", "+DF.format(rgb[1])+", "+DF.format(rgb[2])+"])"); |
557 |
|
|
|
558 |
|
|
} |
559 |
|
|
|
560 |
|
|
/** |
561 |
|
|
* create/initialize a list |
562 |
|
|
*/ |
563 |
|
|
public void initList(String listName) { |
564 |
|
|
|
565 |
|
|
Out.println(listName+" = []"); |
566 |
|
|
|
567 |
|
|
} |
568 |
|
|
|
569 |
|
|
/** |
570 |
|
|
* append objects to a list |
571 |
|
|
*/ |
572 |
|
|
public void appendList(String listName, String value) { |
573 |
|
|
|
574 |
|
|
Out.println(listName+".append(\""+value+"\")"); |
575 |
|
|
|
576 |
|
|
} |
577 |
|
|
|
578 |
|
|
/** |
579 |
|
|
* iterate through list objects |
580 |
|
|
* |
581 |
|
|
* Notes: |
582 |
|
|
* - item is the name of the variable containing the object |
583 |
|
|
* - This is the only method that "print" instead of "println". |
584 |
|
|
* In this way, a method can be executed at each iteration e.g. |
585 |
|
|
* PyMol pml = new PyMol(out); |
586 |
|
|
* ... |
587 |
|
|
* pml.iterateList("edges", "edge"); |
588 |
|
|
* pml.setColor("red", "edge"); |
589 |
|
|
* - In the previous example, the "edge" parameter in the setColor command |
590 |
|
|
* is the name of tha variable holding the actual object. Therefore, it must |
591 |
|
|
* be evaluated and so not quoted. This is why this method disables the use |
592 |
|
|
* of quotes. setColor, after streaming the command, will reset the objectNameQuotes |
593 |
|
|
* again back to true. |
594 |
|
|
*/ |
595 |
|
|
public void iterateList(String listName, String item) { |
596 |
|
|
|
597 |
|
|
Out.print("for "+item+" in "+listName+":"); |
598 |
|
|
setObjectNameQuotes(false); |
599 |
|
|
|
600 |
|
|
} |
601 |
|
|
|
602 |
|
|
/** |
603 |
|
|
* opens a log file |
604 |
|
|
* |
605 |
|
|
* Notes: |
606 |
|
|
* - There are two versions. One of them opens the log file specified by its name and the directory path, while |
607 |
|
|
* the other just uses the filename. |
608 |
|
|
*/ |
609 |
|
|
public void openLog(String fileName, String dir) { |
610 |
|
|
|
611 |
|
|
Out.println("log_open "+dir+"/"+fileName+".pml"); |
612 |
|
|
|
613 |
|
|
} |
614 |
|
|
|
615 |
|
|
/** |
616 |
|
|
* opens a log file |
617 |
|
|
* |
618 |
|
|
* Notes: |
619 |
|
|
* - There are two versions. One of them opens the log file specified by its name and the directory path, while |
620 |
|
|
* the other just uses the filename. |
621 |
|
|
*/ |
622 |
|
|
public void openLog(String fileName) { |
623 |
|
|
|
624 |
|
|
Out.println("log_open "+fileName+".pml"); |
625 |
|
|
|
626 |
|
|
} |
627 |
|
|
|
628 |
|
|
/** |
629 |
|
|
* closes the last opened log file |
630 |
|
|
*/ |
631 |
|
|
public void closeLog() { |
632 |
|
|
|
633 |
|
|
Out.println("log_close"); |
634 |
|
|
|
635 |
|
|
} |
636 |
|
|
|
637 |
|
|
/** |
638 |
|
|
* writes a png format image file of the current frame |
639 |
|
|
* |
640 |
|
|
* Notes: |
641 |
|
|
* - rayTraced defines whether the image will be ray-traced or not |
642 |
|
|
* - There are two versions. One of them saves the image file as specified by its name and the directory path, |
643 |
|
|
* while the other just uses the filename. |
644 |
|
|
*/ |
645 |
|
|
public void saveImage(String imageName, String dir, boolean rayTraced) { |
646 |
|
|
|
647 |
|
|
if (rayTraced) { Out.println("ray"); } |
648 |
|
|
Out.println("png "+dir+"/"+imageName+".png"); |
649 |
|
|
|
650 |
|
|
} |
651 |
|
|
|
652 |
|
|
/** |
653 |
|
|
* writes a png format image file of the current frame |
654 |
|
|
* |
655 |
|
|
* Notes: |
656 |
|
|
* - rayTraced defines whether the image will be ray-traced or not |
657 |
|
|
* - There are two versions. One of them saves the image file as specified by its name and the directory path, |
658 |
|
|
* while the other just uses the filename. |
659 |
|
|
*/ |
660 |
|
|
public void saveImage(String imageName, boolean rayTraced) { |
661 |
|
|
|
662 |
|
|
if (rayTraced) { Out.println("ray"); } |
663 |
|
|
Out.println("png "+imageName+".png"); |
664 |
|
|
|
665 |
|
|
} |
666 |
|
|
|
667 |
|
|
/** |
668 |
|
|
* sources a pymol command script |
669 |
|
|
* |
670 |
|
|
* Notes: |
671 |
|
|
* - There are two versions. One of them runs the file specified by its name and the directory path, |
672 |
|
|
* while the other just uses the filename. |
673 |
|
|
*/ |
674 |
|
|
public void runScript(String fileName, String dir) { |
675 |
|
|
|
676 |
|
|
Out.println("@"+dir+"/"+fileName+".pml"); |
677 |
|
|
|
678 |
|
|
} |
679 |
|
|
|
680 |
|
|
/** |
681 |
|
|
* sources a pymol command script |
682 |
|
|
* |
683 |
|
|
* Notes: |
684 |
|
|
* - There are two versions. One of them runs the file specified by its name and the directory path, |
685 |
|
|
* while the other just uses the filename. |
686 |
|
|
*/ |
687 |
|
|
public void runScript(String fileName) { |
688 |
|
|
|
689 |
|
|
Out.println("@"+fileName+".pml"); |
690 |
|
|
|
691 |
|
|
} |
692 |
|
|
|
693 |
|
|
/** |
694 |
|
|
* zooms on an object or selection |
695 |
|
|
*/ |
696 |
|
|
public void zoom(String objectName) { |
697 |
|
|
|
698 |
|
|
Out.println("cmd.zoom("+(objectNameQuotes?"\""+objectName+"\"":objectName)+")"); |
699 |
|
|
if (!objectNameQuotes) { setObjectNameQuotes(true); } |
700 |
|
|
|
701 |
|
|
} |
702 |
|
|
|
703 |
|
|
/** |
704 |
|
|
* sets the background color |
705 |
|
|
*/ |
706 |
|
|
public void background(String color) { |
707 |
|
|
|
708 |
|
|
Out.println("cmd.bg_color(\""+color+"\")"); |
709 |
|
|
|
710 |
|
|
} |
711 |
|
|
|
712 |
|
|
/** |
713 |
|
|
* some initialization commands for structure visualization |
714 |
|
|
* |
715 |
|
|
* Notes: |
716 |
|
|
* - These are defined according to Ioannis' preferences |
717 |
|
|
*/ |
718 |
|
|
public void init() { |
719 |
|
|
|
720 |
|
|
Out.println("cmd.set(\"depth_cue\", 0)"); |
721 |
|
|
Out.println("cmd.set(\"ray_trace_fog\", 0)"); |
722 |
|
|
Out.println("cmd.hide()"); |
723 |
|
|
Out.println("cmd.show(\"cartoon\")"); |
724 |
|
|
Out.println("cmd.cartoon(\"automatic\")"); |
725 |
|
|
Out.println("cmd.set(\"cartoon_flat_sheets\", 0)"); |
726 |
|
|
Out.println("cmd.set(\"cartoon_fancy_helices\", 1)"); |
727 |
|
|
Out.println("cmd.hide(\"spheres\", \"hetatm\")"); |
728 |
|
|
|
729 |
|
|
} |
730 |
|
|
|
731 |
|
|
/** |
732 |
|
|
* enables (disables) the use of double quotes for strings in PyMol commands |
733 |
|
|
* |
734 |
|
|
* Notes: |
735 |
|
|
* - check list related methods |
736 |
|
|
*/ |
737 |
|
|
private void setObjectNameQuotes(boolean value) { |
738 |
|
|
|
739 |
|
|
this.objectNameQuotes = value; |
740 |
|
|
|
741 |
|
|
} |
742 |
|
|
|
743 |
|
|
} |