import java.net.*;
import java.util.*;
+import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
}
}
- public SequenceStructureBinding addJmolInstance(JmolViewer viewer, String[] sequenceIds)
+ /**
+ * create a new binding between structures in an existing jmol viewer instance
+ * and an alignpanel with sequences that have existing PDBFile entries. Note,
+ * this does not open a new Jmol window, or modify the display of the
+ * structures in the original jmol window.
+ *
+ * @param viewer JmolViewer instance
+ * @param sequenceIds
+ * - sequence Ids to search for associations
+ */
+ public SequenceStructureBinding addStructureViewInstance(Object jmolviewer, String[] sequenceIds)
{
+ org.jmol.api.JmolViewer viewer;
+ if (jmolviewer instanceof JmolViewer)
+ {
+ System.err.println("Unsupported viewer object :"+jmolviewer.getClass());
+ return null;
+ } else {
+ viewer = (JmolViewer) jmolviewer;
+ }
SequenceI[] seqs=null;
if (sequenceIds==null || sequenceIds.length==0)
{
seqs = viewport.getAlignment().getSequencesArray();
} else {
- // resolve seqs for sequenceIds.
+ Vector sqi=new Vector();
+ AlignmentI al = viewport.getAlignment();
+ for (int sid=0;sid<sequenceIds.length;sid++) {
+ SequenceI sq = al.findName(sequenceIds[sid]);
+ if (sq!=null) {
+ sqi.addElement(sq);
+ }
+ }
+ if (sqi.size()>0) {
+ seqs = new SequenceI[sqi.size()];
+ for (int sid=0,sSize=sqi.size();sid<sSize;sid++)
+ {
+ seqs[sid] = (SequenceI) sqi.elementAt(sid);
+ }
+ }
}
- if (// viewer is not mapped)
- true){
- AppletJmol jmv = new AppletJmol(viewer, alignPanel, seqs);
- return jmv;
+ ExtJmol jmv=null;
+ // TODO: search for a jmv that involves viewer
+ if (jmv==null){
+ // create a new viewer/jalview binding.
+ jmv = new ExtJmol(viewer, alignPanel, seqs);
}
- return null;
+ return jmv;
}
+
+ public boolean addPdbFile(String sequenceId, String pdbEntryString,
+ String pdbFile)
+ {
+ SequenceI toaddpdb = viewport.getAlignment().findName(sequenceId);
+ boolean needtoadd=false;
+ if (toaddpdb!=null)
+ {
+ Vector pdbe = toaddpdb.getPDBId();
+ PDBEntry pdbentry = null;
+ if (pdbe!=null && pdbe.size()>0)
+ {
+ for (int pe=0,peSize=pdbe.size(); pe<peSize; pe++)
+ {
+ pdbentry = (PDBEntry) pdbe.elementAt(pe);
+ if (!pdbentry.getId().equals(pdbEntryString) && !pdbentry.getFile().equals(pdbFile))
+ {
+ pdbentry = null;
+ }
+ else
+ {
+ continue;
+ }
+ }
+ }
+ if (pdbentry==null)
+ {
+ pdbentry = new PDBEntry();
+ pdbentry.setId(pdbEntryString);
+ pdbentry.setFile(pdbFile);
+ needtoadd=true; // add this new entry to sequence.
+ }
+ // resolve data source
+ // TODO: this code should be a refactored to an io package
+ String protocol = AppletFormatAdapter.resolveProtocol(pdbFile, "PDB");
+ if (protocol == null)
+ {
+ return false;
+ }
+ if (needtoadd)
+ {
+ // make a note of the access mode and add
+ pdbentry.getProperty().put("protocol", protocol);
+ toaddpdb.addPDBId(pdbentry);
+ }
+ }
+ return true;
+ }
+
+ public void newStructureView(JalviewLite applet, PDBEntry pdb, SequenceI[] seqs,
+ String[] chains, String protocol)
+ {
+ if (protocol==null || protocol.trim().length()==0 || protocol.equals("null"))
+ {
+ protocol = (String) pdb.getProperty().get("protocol");
+ if (protocol==null)
+ {
+ System.err.println("Couldn't work out protocol to open structure: "+pdb.getId());
+ return;
+ }
+ }
+ if (applet.jmolAvailable)
+ {
+ new jalview.appletgui.AppletJmol(pdb, seqs, chains,
+ alignPanel, protocol);
+ applet.lastFrameX += 40;
+ applet.lastFrameY += 40;
+ }
+ else
+ new MCview.AppletPDBViewer(pdb, seqs, chains,
+ alignPanel, protocol);
+ }
}
// //////////////////////////////////////////////
// //////////////////////////////////////////////
- static int lastFrameX = 200;
+ public static int lastFrameX = 200;
- static int lastFrameY = 200;
+ public static int lastFrameY = 200;
boolean fileFound = true;
}
}
- if (jmolAvailable)
- {
- new jalview.appletgui.AppletJmol(pdb, seqs, chains,
- newAlignFrame.alignPanel, protocol);
- lastFrameX += 40;
- lastFrameY += 40;
- }
- else
- new MCview.AppletPDBViewer(pdb, seqs, chains,
- newAlignFrame.alignPanel, protocol);
+ newAlignFrame.newStructureView(applet, pdb, seqs, chains, protocol);
+
}
}
*/
public boolean addPdbFile(AlignFrame alFrame, String sequenceId, String pdbEntryString, String pdbFile)
{
- System.err.println("addPdbFile not yet implemented.");
- return true;
- }
- /**
- * bind the viewer instance to the pdbFile associated with sequences in the given alFrame.
- * @param alFrame
- * @param pdbFile - pdbFile URI as given via applet's parameters or by addPdb
- * @param viewer
- * @return binding for viewer
- * TODO: consider making an exception structure for indicating when binding fails
- */
- public SequenceStructureBinding addJmolInstance(AlignFrame alFrame, String pdbFile, org.jmol.api.JmolViewer viewer)
- {
- System.err.println("addJmolInstance not yet implemented.");
- /**
- */
- return null;
+ return alFrame.addPdbFile(sequenceId, pdbEntryString, pdbFile);
}
/**
- * bind structures in a viewer to any matching sequences in an alignFrame (use seuqenceIds to limit scope of search to specific sequences)
+ * bind structures in a viewer to any matching sequences in an alignFrame (use sequenceIds to limit scope of search to specific sequences)
* @param alFrame
* @param viewer
* @param sequenceIds
* @return
+ * TODO: consider making an exception structure for indicating when binding fails
*/
- public SequenceStructureBinding addJmolInstance(AlignFrame alFrame, org.jmol.api.JmolViewer viewer, String sequenceIds)
+ public SequenceStructureBinding addStructureViewInstance(AlignFrame alFrame, Object viewer, String sequenceIds)
{
if (viewer!=null)
{
if (sequenceIds!=null && sequenceIds.length()>0)
{
- return alFrame.addJmolInstance(viewer, separatorListToArray(sequenceIds));
+ return alFrame.addStructureViewInstance(viewer, separatorListToArray(sequenceIds));
} else {
- return alFrame.addJmolInstance(viewer, null);
+ return alFrame.addStructureViewInstance(viewer, null);
}
}
return null;