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