6 import java.util.BitSet;
7 import java.util.Vector;
9 import jalview.bin.Cache;
10 import jalview.datamodel.PDBEntry;
11 import jalview.datamodel.SequenceI;
13 import org.jmol.popup.JmolPopup;
15 class AppJmolBinding extends jalview.ext.jmol.JalviewJmolBinding
21 private AppJmol appJmolWindow;
23 public AppJmolBinding(AppJmol appJmol, PDBEntry[] pdbentry,
24 SequenceI[][] sequenceIs, String[][] chains, String protocol)
26 super(pdbentry, sequenceIs, chains, protocol);
27 appJmolWindow = appJmol;
30 FeatureRenderer fr = null;
33 public jalview.api.FeatureRenderer getFeatureRenderer()
35 if (appJmolWindow.ap.av.showSequenceFeatures)
39 fr = new FeatureRenderer(appJmolWindow.ap);
42 fr.transferSettings(appJmolWindow.ap.seqPanel.seqCanvas
43 .getFeatureRenderer());
50 public jalview.api.SequenceRenderer getSequenceRenderer()
52 return new SequenceRenderer(appJmolWindow.ap.av);
55 public void sendConsoleEcho(String strEcho)
57 if (appJmolWindow.scriptWindow != null)
59 appJmolWindow.scriptWindow.sendConsoleEcho(strEcho);
63 public void sendConsoleMessage(String strStatus)
65 if (appJmolWindow.scriptWindow != null && strStatus != null)
66 // && !strStatus.equals("Script completed"))
67 // should we squash the script completed string ?
69 appJmolWindow.scriptWindow.sendConsoleMessage(strStatus);
74 public void showUrl(String url, String target)
78 jalview.util.BrowserLauncher.openURL(url);
81 Cache.log.error("Failed to launch Jmol-associated url " + url, e);
82 // TODO: 2.6 : warn user if browser was not configured.
87 public void refreshGUI()
89 // appJmolWindow.repaint();
90 appJmolWindow.updateTitleAndMenus();
93 public void updateColours(Object source)
95 AlignmentPanel ap = (AlignmentPanel) source;
96 if (appJmolWindow.ap.alignFrame.getCurrentView() != ap.av)
99 colourBySequence(ap.av.getShowSequenceFeatures(), ap.av.alignment);
102 public void notifyScriptTermination(String strStatus, int msWalltime)
104 if (appJmolWindow.scriptWindow != null)
105 appJmolWindow.scriptWindow.notifyScriptTermination(strStatus,
109 public void showUrl(String url)
111 showUrl(url, "jmol");
114 public void newJmolPopup(boolean translateLocale, String menuName,
118 jmolpopup = JmolPopup.newJmolPopup(viewer, translateLocale, menuName,
123 * add structures and any known sequence associations
125 * @returns the pdb entries added to the current set.
127 private PDBEntry[] addSequenceAndChain(PDBEntry[] pdbe,
128 SequenceI[][] seq, String[][] chns)
131 Vector v = new Vector();
132 Vector rtn = new Vector();
133 for (int i = 0; i < pdbentry.length; i++)
135 v.addElement(pdbentry[i]);
137 for (int i = 0; i < pdbe.length; i++)
139 int r = v.indexOf(pdbe[i]);
140 if (r == -1 || r >= pdbentry.length)
142 rtn.addElement(new int[]
144 v.addElement(pdbe[i]);
148 // just make sure the sequence/chain entries are all up to date
149 addSequenceAndChain(r, seq[i], chns[i]);
152 pdbe = new PDBEntry[v.size()];
157 // expand the tied seuqence[] and string[] arrays
158 SequenceI[][] sqs = new SequenceI[pdbentry.length][];
159 String[][] sch = new String[pdbentry.length][];
160 System.arraycopy(sequence, 0, sqs, 0, sequence.length);
161 System.arraycopy(chains, 0, sch, 0, this.chains.length);
164 pdbe = new PDBEntry[rtn.size()];
165 for (int r = 0; r < pdbe.length; r++)
167 int[] stri = ((int[]) rtn.elementAt(r));
168 // record the pdb file as a new addition
169 pdbe[r] = pdbentry[stri[0]];
170 // and add the new sequence/chain entries
171 addSequenceAndChain(stri[0], seq[stri[1]], chns[stri[1]]);
181 void addSequence(int pe, SequenceI[] seq)
183 // add sequences to the pe'th pdbentry's seuqence set.
184 addSequenceAndChain(pe, seq, null);
187 private void addSequenceAndChain(int pe, SequenceI[] seq, String[] tchain)
189 if (pe < 0 || pe >= pdbentry.length)
192 "Implementation error - no corresponding pdbentry (for index "
193 + pe + ") to add sequences mappings to");
195 final String nullChain = "TheNullChain";
196 Vector s = new Vector();
197 Vector c = new Vector();
200 chains = new String[pdbentry.length][];
202 if (sequence[pe] != null)
204 for (int i = 0; i < sequence[pe].length; i++)
206 s.addElement(sequence[pe][i]);
207 if (chains[pe] != null)
209 if (i < chains[pe].length)
211 c.addElement(chains[pe][i]);
215 c.addElement(nullChain);
220 if (tchain != null && tchain.length > 0)
222 c.addElement(nullChain);
227 for (int i = 0; i < seq.length; i++)
229 if (!s.contains(seq[i]))
231 s.addElement(seq[i]);
232 if (tchain != null && i < tchain.length)
234 c.addElement(tchain[i] == null ? nullChain : tchain[i]);
238 SequenceI[] tmp = new SequenceI[s.size()];
243 String[] tch = new String[c.size()];
245 for (int i = 0; i < tch.length; i++)
247 if (tch[i] == nullChain)
260 public void selectionChanged(BitSet arg0)
262 // TODO Auto-generated method stub
266 public void refreshPdbEntries()
268 // TODO Auto-generated method stub
273 * add another pdb entry into the view, with associated sequences and chains
279 * if true, new structure(s) will be align using associated alignment
281 public synchronized void addStructure(PDBEntry pdbentry, SequenceI[] seq,
282 String[] chains, final boolean align)
284 PDBEntry[] pe = addSequenceAndChain(new PDBEntry[]
285 { pdbentry }, new SequenceI[][]
286 { seq }, new String[][]
290 StringBuffer cmd = new StringBuffer();
291 cmd.append("load APPEND");
292 for (int p = 0; p < pe.length; p++)
295 cmd.append(pe[p].getFile());
299 final String command = cmd.toString();
301 new Thread(new Runnable()
305 evalStateCommand(command);
308 // may need to wait around until script has finished
309 while (viewer.isScriptExecuting())
314 } catch (Exception e)
319 superposeStructures(appJmolWindow.ap.av.getAlignment(), -1, null);
327 * add the given sequences to the mapping scope for the given pdb file handle
330 * - pdbFile identifier
332 * - set of sequences it can be mapped to
334 public void addSequenceForStructFile(String pdbFile, SequenceI[] seq)
336 for (int pe = 0; pe < pdbentry.length; pe++)
338 if (pdbentry[pe].getFile().equals(pdbFile))
340 addSequence(pe, seq);