import jalview.analysis.*;
import jalview.datamodel.*;
+import jalview.gui.*;
+import jalview.structure.*;
public class PDBCanvas
- extends JPanel implements MouseListener, MouseMotionListener
+ extends JPanel implements MouseListener, MouseMotionListener, StructureListener
{
- MCMatrix idmat = new MCMatrix(3, 3);
- MCMatrix objmat = new MCMatrix(3, 3);
boolean redrawneeded = true;
int omx = 0;
int mx = 0;
int omy = 0;
int my = 0;
public PDBfile pdb;
+ PDBEntry pdbentry;
int bsize;
Image img;
Graphics ig;
int ymid;
Font font = new Font("Helvetica", Font.PLAIN, 10);
jalview.gui.SeqCanvas seqcanvas;
- public Sequence sequence;
+ public SequenceI [] sequence;
final StringBuffer mappingDetails = new StringBuffer();
PDBChain mainchain;
Vector highlightRes;
boolean seqColoursReady = false;
jalview.gui.FeatureRenderer fr;
Color backgroundColour = Color.black;
+ AlignmentPanel ap;
+ StructureSelectionManager ssm;
+ String errorMessage;
- public PDBCanvas(jalview.gui.SeqCanvas seqcanvas, Sequence seq)
+
+ void init(PDBEntry pdbentry,
+ SequenceI[] seq,
+ String [] chains,
+ AlignmentPanel ap,
+ String protocol)
{
- this.seqcanvas = seqcanvas;
+ this.ap = ap;
+ this.pdbentry = pdbentry;
this.sequence = seq;
- }
- public void setPDBFile(PDBfile pdb)
- {
+ ssm = StructureSelectionManager.getStructureSelectionManager();
+
+ try{
+ pdb = ssm.setMapping(seq, chains, pdbentry.getFile(), protocol);
+
+ if(protocol.equals(jalview.io.AppletFormatAdapter.PASTE))
+ pdbentry.setFile("INLINE"+pdb.id);
+
+ }catch(Exception ex)
+ {
+ ex.printStackTrace();
+ return;
+ }
+
+ if(pdb==null)
+ {
+ errorMessage = "Error loading file: "+pdbentry.getId();
+ return;
+ }
+ pdbentry.setId(pdb.id);
+
+ ssm.addStructureViewerListener(this);
+
+ colourBySequence();
+
int max = -10;
int maxchain = -1;
int pdbstart = 0;
int pdbend = 0;
int seqstart = 0;
int seqend = 0;
- AlignSeq maxAlignseq = null;
+
+ //JUST DEAL WITH ONE SEQUENCE FOR NOW
+ SequenceI sequence = seq[0];
for (int i = 0; i < pdb.chains.size(); i++)
{
// Align the sequence to the pdb
AlignSeq as = new AlignSeq(sequence,
( (PDBChain) pdb.chains.elementAt(i)).sequence,
- AlignSeq.PEP);
+ "pep");
as.calcScoreMatrix();
as.traceAlignment();
PrintStream ps = new PrintStream(System.out)
{
max = as.maxscore;
maxchain = i;
+
pdbstart = as.seq2start;
pdbend = as.seq2end;
seqstart = as.seq1start + sequence.getStart() - 1;
seqend = as.seq1end + sequence.getEnd() - 1;
- maxAlignseq = as;
}
mappingDetails.append("\nPDB start/end " + pdbstart + " " + pdbend);
mainchain.seqstart = seqstart;
mainchain.seqend = seqend;
mainchain.isVisible = true;
- mainchain.makeExactMapping(maxAlignseq, sequence);
- mainchain.transferRESNUMFeatures(sequence, null);
- seqcanvas.getFeatureRenderer().featuresAdded();
+
this.pdb = pdb;
- this.prefsize = new Dimension(getWidth(), getHeight());
+ this.prefsize = new Dimension(getSize().width, getSize().height);
- //Initialize the matrices to identity
- for (int i = 0; i < 3; i++)
- {
- for (int j = 0; j < 3; j++)
- {
- if (i != j)
- {
- idmat.addElement(i, j, 0);
- objmat.addElement(i, j, 0);
- }
- else
- {
- idmat.addElement(i, j, 1);
- objmat.addElement(i, j, 1);
- }
- }
- }
addMouseMotionListener(this);
addMouseListener(this);
- addMouseWheelListener(new MouseWheelListener()
+ addKeyListener(new KeyAdapter()
{
- public void mouseWheelMoved(MouseWheelEvent e)
+ public void keyPressed(KeyEvent evt)
{
- if (e.getWheelRotation() > 0)
- {
- scale = (float) (scale * 1.1);
- redrawneeded = true;
- repaint();
- }
-
- else
- {
- scale = (float) (scale * 0.9);
- redrawneeded = true;
- repaint();
- }
+ keyPressed(evt);
}
});
{
super.paintComponent(g);
- if (!seqColoursReady)
+ if (!seqColoursReady || errorMessage!=null)
{
g.setColor(Color.black);
g.setFont(new Font("Verdana", Font.BOLD, 14));
- g.drawString("Retrieving PDB data....", 20, getHeight() / 2);
+ g.drawString(errorMessage==null?
+ "Retrieving PDB data....":errorMessage,
+ 20, getHeight() / 2);
return;
}
return;
}
- // System.out.println("update seq colours");
- if (bysequence && pdb != null)
- {
- for (int ii = 0; ii < pdb.chains.size(); ii++)
- {
- colourBySequence( (PDBChain) pdb.chains.elementAt(ii));
- }
- }
+ colourBySequence();
redrawneeded = true;
repaint();
}
- int findTrueIndex(int pos)
- {
- // returns the alignment position for a residue
- int j = sequence.getStart(); // first position in PDB atom coordinate sequence
- int i = 0;
-
- while ( (i < sequence.getLength()) && (j <= pos + 1))
- {
- if (!jalview.util.Comparison.isGap(sequence.getCharAt(i)))
- {
- j++;
- }
-
- i++;
- }
-
- if (i > 1)
- {
- i--;
- }
-
- if (j < pos)
- {
- return sequence.getEnd() + 1;
- }
- else
- {
- return i;
- }
- }
// This method has been taken out of PDBChain to allow
// Applet and Application specific sequence renderers to be used
- void colourBySequence(PDBChain chain)
+ void colourBySequence()
{
- // System.out.println("colour by seq");
- boolean showFeatures = false;
+ SequenceRenderer sr = new SequenceRenderer(ap.av);
+
+ StructureMapping[] mapping = ssm.getMapping(pdbentry.getFile());
- //NO LONGER USED SINCE APPJMOL
-// if (seqcanvas.getViewport().getShowSequenceFeatures())
+ boolean showFeatures = false;
+ if (ap.av.getShowSequenceFeatures())
{
- showFeatures = true;
if (fr == null)
{
- //NO LONGER USED SINCE APPJMOL
-// fr = new jalview.gui.FeatureRenderer(seqcanvas.getViewport());
+ fr = new FeatureRenderer(ap);
}
- fr.transferSettings(seqcanvas.getFeatureRenderer());
+ fr.transferSettings(ap.alignFrame.getFeatureRenderer());
+
+ showFeatures = true;
}
- Bond tmp;
- for (int i = 0; i < chain.bonds.size(); i++)
+ PDBChain chain;
+ if (bysequence && pdb != null)
{
- tmp = (Bond) chain.bonds.elementAt(i);
-
- if (chain != mainchain)
- {
- continue;
- }
-
- //if ( (tmp.at1.resNumber >= ( (chain.offset + chain.pdbstart) - 1)) &&
- // (tmp.at1.resNumber <= ( (chain.offset + chain.pdbend) - 1)))
- {
- int index = findTrueIndex(tmp.at1.alignmentMapping);
- //sequence.findIndex(tmp.at1.alignmentMapping);
- if (index != -1)
- {
- tmp.startCol = seqcanvas.getSequenceRenderer().
- getResidueBoxColour(sequence, index);
-
- if (showFeatures)
- {
- tmp.startCol = fr.findFeatureColour(tmp.startCol, sequence, index);
- }
-
- if (tmp.startCol == null)
- {
- tmp.startCol = Color.white;
- }
- }
- }
-
- //if ( (tmp.at2.resNumber >= ( (chain.offset + chain.pdbstart) - 1)) &&
- // (tmp.at2.resNumber <= ( (chain.pdbend + chain.offset) - 1)))
+ for (int ii = 0; ii < pdb.chains.size(); ii++)
{
+ chain = (PDBChain) pdb.chains.elementAt(ii);
- int index = findTrueIndex(tmp.at2.alignmentMapping);
- //sequence.findIndex( tmp.at2.alignmentMapping );
- if (index != -1)
+ for (int i = 0; i < chain.bonds.size(); i++)
{
- tmp.endCol = seqcanvas.getSequenceRenderer().
- getResidueBoxColour(sequence, index);
-
- if (showFeatures)
+ Bond tmp = (Bond) chain.bonds.elementAt(i);
+ tmp.startCol = Color.lightGray;
+ tmp.endCol = Color.lightGray;
+ if (chain != mainchain)
{
- tmp.endCol = fr.findFeatureColour(tmp.endCol, sequence, index);
+ continue;
}
- if (tmp.endCol == null)
+ for (int s = 0; s < sequence.length; s++)
{
- tmp.endCol = Color.white;
+ for (int m = 0; m < mapping.length; m++)
+ {
+ if (mapping[m].getSequence() == sequence[s])
+ {
+ int pos = mapping[m].getSeqPos(tmp.at1.resNumber)-1;
+ if (pos > 0)
+ {
+ pos = sequence[s].findIndex(pos);
+ tmp.startCol = sr.getResidueBoxColour(sequence[s], pos);
+ if (showFeatures)
+ {
+ tmp.startCol = fr.findFeatureColour(tmp.startCol,
+ sequence[s],
+ pos);
+ }
+ }
+ pos = mapping[m].getSeqPos(tmp.at2.resNumber)-1;
+ if (pos > 0)
+ {
+ pos = sequence[s].findIndex(pos);
+ tmp.endCol = sr.getResidueBoxColour(sequence[s], pos);
+ if (showFeatures)
+ {
+ tmp.endCol = fr.findFeatureColour(tmp.endCol,
+ sequence[s],
+ pos);
+ }
+ }
+
+ }
+ }
}
}
}
chain = (PDBChain) pdb.chains.elementAt(foundchain);
if (chain == mainchain)
{
- highlightSeqcanvas(fatom.alignmentMapping);
+ mouseOverStructure(fatom.resNumber, chain.id);
}
}
}
else
{
- highlightSeqcanvas( -1);
+ mouseOverStructure(-1, chain!=null?chain.id:null);
this.setToolTipText(null);
}
}
- void highlightSeqcanvas(int pos)
- {
- SearchResults searchResults = new SearchResults();
- if (highlightRes != null)
- {
- for (int i = 0; i < highlightRes.size(); i++)
- {
- int a = Integer.parseInt(highlightRes.elementAt(
- i).toString()) + 1;
-
- searchResults.addResult(sequence, a, a);
- }
- }
-
- if (pos != -1)
- {
- searchResults.addResult(sequence, pos + 1, pos + 1);
- }
-
- seqcanvas.highlightSearchResults(searchResults);
- }
-
public void mouseClicked(MouseEvent e)
{}
findCentre();
setupBonds();
}
+
+ //////////////////////////////////
+ ///StructureListener
+ public String getPdbFile()
+ {
+ return pdbentry.getFile();
+ }
+
+
+ String lastMessage;
+ public void mouseOverStructure(int pdbResNum, String chain)
+ {
+ if (lastMessage == null || !lastMessage.equals(pdbResNum+chain))
+ ssm.mouseOverStructure(pdbResNum, chain, pdbentry.getFile());
+
+ lastMessage = pdbResNum+chain;
+ }
+
+ StringBuffer resetLastRes = new StringBuffer();
+ StringBuffer eval = new StringBuffer();
+
+ public void highlightAtom(int atomIndex, int pdbResNum, String chain, String pdbfile)
+ {
+ if (!seqColoursReady)
+ {
+ return;
+ }
+
+ if (highlightRes != null
+ && highlightRes.contains( (atomIndex - 1) + ""))
+ {
+ return;
+ }
+
+ int index = -1;
+ Bond tmpBond;
+ for (index = 0; index < mainchain.bonds.size(); index++)
+ {
+ tmpBond = (Bond) mainchain.bonds.elementAt(index);
+ if (tmpBond.at1.atomIndex == atomIndex)
+ {
+ if (highlightBond1 != null)
+ {
+ highlightBond1.at2.isSelected = false;
+ }
+
+ if (highlightBond2 != null)
+ {
+ highlightBond2.at1.isSelected = false;
+ }
+
+ highlightBond1 = null;
+ highlightBond2 = null;
+
+ if (index > 0)
+ {
+ highlightBond1 = (Bond) mainchain.bonds.elementAt(index - 1);
+ highlightBond1.at2.isSelected = true;
+ }
+
+ if (index != mainchain.bonds.size())
+ {
+ highlightBond2 = (Bond) mainchain.bonds.elementAt(index);
+ highlightBond2.at1.isSelected = true;
+ }
+
+ break;
+ }
+ }
+
+ redrawneeded = true;
+ repaint();
+ }
+
+
+ public Color getColour(int atomIndex, int pdbResNum, String chain, String pdbfile)
+ {
+ return Color.white;
+ // if (!pdbfile.equals(pdbentry.getFile()))
+ // return null;
+
+ //return new Color(viewer.getAtomArgb(atomIndex));
+ }
+
+ public void updateColours(Object source)
+ {
+ colourBySequence();
+ redrawneeded = true;
+ repaint();
+ }
+
}
import java.io.*;
-import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
-import java.util.BitSet;
import jalview.datamodel.*;
import jalview.gui.*;
import jalview.io.*;
import jalview.schemes.*;
-
-import org.jmol.api.*;
-import org.jmol.adapter.smarter.SmarterJmolAdapter;
-import org.jmol.util.Logger;
-import org.jmol.popup.*;
+import java.awt.BorderLayout;
public class PDBViewer
extends JInternalFrame implements Runnable
{
- PDBEntry pdb;
+
/**
* The associated sequence in an alignment
*/
- Sequence sequence;
PDBCanvas pdbcanvas;
+
+ PDBEntry pdbentry;
+ SequenceI[]seq;
+ String[]chains;
+ AlignmentPanel ap;
+ String protocol;
String tmpPDBFile;
- public PDBViewer(PDBEntry entry,
- Sequence seq,
- SeqCanvas seqcanvas)
+ public PDBViewer(PDBEntry pdbentry,
+ SequenceI[] seq,
+ String[] chains,
+ AlignmentPanel ap,
+ String protocol)
+
{
- /* try
+ this.pdbentry = pdbentry;
+ this.seq = seq;
+ this.chains = chains;
+ this.ap = ap;
+ this.protocol = protocol;
+
+ try
{
jbInit();
}
ex.printStackTrace();
}
- if (entry == null)
- {
- return;
- }
- pdb = entry;
- sequence = seq;
- pdbcanvas = new PDBCanvas(seqcanvas, sequence);
- if (pdb.getFile() != null)
+ StringBuffer title = new StringBuffer(seq[0].getName()
+ + ":"
+ + pdbentry.getFile());
+
+ pdbcanvas = new PDBCanvas();
+
+ setContentPane(pdbcanvas);
+
+ if (pdbentry.getFile() != null)
{
try
{
- tmpPDBFile = pdb.getFile();
+ tmpPDBFile = pdbentry.getFile();
PDBfile pdbfile = new PDBfile(tmpPDBFile,
jalview.io.AppletFormatAdapter.FILE);
- pdbcanvas.setPDBFile(pdbfile);
+
+ pdbcanvas.init(pdbentry, seq, chains, ap, protocol);
}
catch (java.io.IOException ex)
worker.start();
}
- public void run()
- {
- try
- {
- EBIFetchClient ebi = new EBIFetchClient();
- String query = "pdb:" + pdb.getId();
- tmpPDBFile = ebi.fetchDataAsFile(query, "default", "raw").getAbsolutePath();
- if (tmpPDBFile != null)
- {
- PDBfile pdbfile = new PDBfile(tmpPDBFile,
- jalview.io.AppletFormatAdapter.FILE);
- pdbcanvas.setPDBFile(pdbfile);
- }
- else
- {
- throw new Exception("Empty result for WSDbFetch Query: " + query);
- }
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- showErrorMessage("Failed to retrieve PDB structure.");
-// this.dispose();
- }
- }
- setContentPane(pdbcanvas);
- StringBuffer title = new StringBuffer(sequence.getName() + ":" + pdb.getId());
- if (pdb.getProperty() != null)
+ if (pdbentry.getProperty() != null)
{
- if (pdb.getProperty().get("method") != null)
+ if (pdbentry.getProperty().get("method") != null)
{
title.append(" Method: ");
- title.append(pdb.getProperty().get("method"));
+ title.append(pdbentry.getProperty().get("method"));
}
- if (pdb.getProperty().get("chains") != null)
+ if (pdbentry.getProperty().get("chains") != null)
{
title.append(" Chain:");
- title.append(pdb.getProperty().get("chains"));
+ title.append(pdbentry.getProperty().get("chains"));
}
}
- */
-
- Container contentPane = getContentPane();
- JmolPanel jmolPanel = new JmolPanel();
- contentPane.add(jmolPanel);
-
- JmolViewer viewer = jmolPanel.viewer;
-
-
- System.out.println(entry.getFile()+" "+entry.getId());
- viewer.openFile(entry.getFile());
-
-
- StringBuffer string = new StringBuffer();
-
- for(int i=0; i<seq.getLength(); i++)
- {
- Color col = seqcanvas.getSequenceRenderer().getResidueBoxColour(seq, i);
-
- string.append("select " + i + "B; color [" +
- col.getRed()+","
- +col.getGreen()+","
- +col.getBlue()+"]; ");
- }
- System.out.println(string);
-
- viewer.evalString(string.toString());
-
-
- String strError = viewer.getOpenFileError();
- if (strError != null)
- Logger.error(strError);
-
-
- // Desktop.addInternalFrame(this,
- // seq.getName() + ":1GAQ"
- // , 400, 400);
-
+ Desktop.addInternalFrame(this, title.toString(), 400, 400);
}
-
-
-
- static class JmolPanel
- extends JPanel implements JmolSelectionListener
- {
- JmolViewer viewer;
- JmolAdapter adapter;
- JmolPanel()
- {
- adapter = new SmarterJmolAdapter(null);
- viewer = org.jmol.viewer.Viewer.allocateViewer(this, adapter);
- viewer.addSelectionListener(this);
-
- MyStatusListener myStatusListener;
- myStatusListener = new MyStatusListener();
- viewer.setJmolStatusListener(myStatusListener);
-
- JFrame frame = new JFrame("script window");
- // scriptWindow = new ScriptWindow(viewer, frame);
-
- myStatusListener.jmolpopup = JmolPopup.newJmolPopup(viewer);
- }
- public ScriptWindow scriptWindow;
- class MyStatusListener implements JmolStatusListener
- {
-
- JmolPopup jmolpopup ;
-
-
- public String eval(String strEval) {
- return "# 'eval' is implemented only for the applet.";
- }
-
- public void createImage(String file, String type, int quality) {
- System.out.println("CREATE IMAGE");
- // ImageCreator c = new ImageCreator(viewer, status);
- // c.createImage(file, type, quality);
- }
-
- public void setCallbackFunction(String callbackType, String callbackFunction) {
- // applet only?
- }
-
- public void notifyFileLoaded(String fullPathName, String fileName,
- String modelName, Object clientFile,
- String errorMsg) {
-
- }
-
- public void notifyFrameChanged(int frameNo) {
- // Note: twos-complement. To get actual frame number, use
- // Math.max(frameNo, -2 - frameNo)
- // -1 means all frames are now displayed
-
- boolean isAnimationRunning = (frameNo <= -2);
-
- }
-
- public void notifyScriptStart(String statusMessage, String additionalInfo) {
- //System.out.println("notifyScriptStart:" + statusMessage + (additionalInfo == "" ? "" : additionalInfo));
- }
-
- public void sendConsoleEcho(String strEcho) {
- if (scriptWindow != null)
- scriptWindow.sendConsoleEcho(strEcho);
- }
-
- public void sendConsoleMessage(String strStatus) {
- if (scriptWindow != null)
- scriptWindow.sendConsoleMessage(strStatus);
- }
-
- public void notifyScriptTermination(String strStatus, int msWalltime) {
- if (scriptWindow != null)
- scriptWindow.notifyScriptTermination(strStatus, msWalltime);
- }
-
- public void handlePopupMenu(int x, int y) {
- jmolpopup.show(x, y);
- }
-
- public void notifyNewPickingModeMeasurement(int iatom, String strMeasure) {
- notifyAtomPicked(iatom, strMeasure);
- }
-
- public void notifyNewDefaultModeMeasurement(int count, String strInfo) {
- // measurementTable.updateTables();
- }
-
- public void notifyAtomPicked(int atomIndex, String strInfo) {
-
- System.out.println("ATOM PICKED "+atomIndex+" "+strInfo);
- if (scriptWindow != null) {
- scriptWindow.sendConsoleMessage(strInfo);
- scriptWindow.sendConsoleMessage("\n");
- }
- }
-
- public void notifyAtomHovered(int atomIndex, String strInfo) {
-System.out.println("HOVER "+atomIndex+" "+strInfo);
- }
-
- public void sendSyncScript(String script, String appletName) {
- }
-
- public void showUrl(String url) {
- }
-
- public void showConsole(boolean showConsole) {
- System.out.println("SHOW CONSOLE" +(scriptWindow==null));
- if (scriptWindow == null)
- return;
-
- scriptWindow.setVisible(showConsole);
- }
-
- public float functionXY(String functionName, int x, int y) {
- return 0; // for user-defined isosurface functions (testing only -- bob hanson)
- }
-
- }
-
-
- class ScriptWindowAction extends AbstractAction {
-
- public ScriptWindowAction() {
- super("BLAH");
- }
-
- public void actionPerformed(ActionEvent e) {
- if (scriptWindow != null)
- scriptWindow.show();
- }
- }
-
- /**
- * Called when the selected atoms change
- * @param selection bit set giving selection of atom indexes
- */
- public void selectionChanged(BitSet selection)
- {
- System.out.println("SELECTION: "+selection);
- }
-
-
- public JmolSimpleViewer getViewer()
- {
- return viewer;
- }
-
- final Dimension currentSize = new Dimension();
- final Rectangle rectClip = new Rectangle();
-
- public void paint(Graphics g)
- {
-
- getSize(currentSize);
- g.getClipBounds(rectClip);
- viewer.renderScreenImage(g, currentSize, rectClip);
- }
- }
-
-
public void run()
{
try
{
EBIFetchClient ebi = new EBIFetchClient();
- String query = "pdb:" + pdb.getId();
- tmpPDBFile = ebi.fetchDataAsFile(query, "default", "raw").getAbsolutePath();
- if (tmpPDBFile != null)
- {
- PDBfile pdbfile = new PDBfile(tmpPDBFile,
- jalview.io.AppletFormatAdapter.FILE);
- pdbcanvas.setPDBFile(pdbfile);
- }
- else
- {
- throw new Exception("Empty result for WSDbFetch Query: " + query);
- }
+ String query = "pdb:" + pdbentry.getId();
+ pdbentry.setFile(ebi.fetchDataAsFile(query, "default", "raw")
+ .getAbsolutePath());
+
+ if(pdbentry.getFile()!=null)
+ pdbcanvas.init(pdbentry, seq, chains, ap, protocol);
}
catch (Exception ex)
{
+ pdbcanvas.errorMessage = "Error retrieving file: "+pdbentry.getId();
ex.printStackTrace();
- showErrorMessage("Failed to retrieve PDB structure.");
-// this.dispose();
}
}
public void mapping_actionPerformed(ActionEvent e)
{
jalview.gui.CutAndPasteTransfer cap = new jalview.gui.CutAndPasteTransfer();
- // Desktop.addInternalFrame(cap, "PDB - Sequence Mapping", 550, 600);
+ Desktop.addInternalFrame(cap, "PDB - Sequence Mapping", 550, 600);
cap.setText(pdbcanvas.mappingDetails.toString());
}
pdbcanvas.setAllchainsVisible(allchains.getState());
}
- void showErrorMessage(String error)
- {
- // JOptionPane.showInternalMessageDialog(Desktop.desktop,
- // error, "PDB Viewer Error",
- // JOptionPane.WARNING_MESSAGE);
- }
public void zappo_actionPerformed(ActionEvent e)
{