From: amwaterhouse Date: Thu, 10 Nov 2005 11:00:08 +0000 (+0000) Subject: PDM mapping X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=76389b07e78f92b6db0aeaf2f964d9dcb6671543;p=jalview.git PDM mapping --- diff --git a/src/MCview/PDBCanvas.java b/src/MCview/PDBCanvas.java new file mode 100755 index 0000000..e9f8dce --- /dev/null +++ b/src/MCview/PDBCanvas.java @@ -0,0 +1,686 @@ +/* +* Jalview - A Sequence Alignment Editor and Viewer +* Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA +*/ +package MCview; + +import jalview.analysis.AlignSeq; + +import jalview.datamodel.*; + +// JBPNote TODO: This class is quite noisy - needs proper log.info/log.debug +import java.awt.*; +import java.awt.event.*; + +import java.io.*; + +import java.util.*; + +import javax.swing.*; + + +public class PDBCanvas extends JPanel implements MouseListener, MouseMotionListener +{ + 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; + int bsize; + Image img; + Graphics ig; + Dimension prefsize; + float[] centre = new float[3]; + float[] width = new float[3]; + float maxwidth; + float scale; + String inStr; + String inType; + boolean bysequence = true; + boolean depthcue = true; + boolean wire = false; + boolean bymolecule = false; + boolean zbuffer = true; + boolean dragging; + int xstart; + int xend; + int ystart; + int yend; + int xmid; + int ymid; + Font font = new Font("Helvetica", Font.PLAIN, 10); + jalview.gui.SequenceRenderer sr; + jalview.gui.FeatureRenderer fr; + + public PDBCanvas() + { + + } + + public void setPDBFile(PDBfile pdb, Sequence sequence, + jalview.gui.SequenceRenderer sr, + jalview.gui.FeatureRenderer fr) + { + + + this.sr = sr; + this.fr = fr; + int max = -10; + int maxchain = -1; + int pdbstart = 0; + int pdbend = 0; + int seqstart = 0; + int seqend = 0; + + for (int i = 0; i < pdb.chains.size(); i++) { + // Now lets compare the sequences to get + // the start and end points. + // Align the sequence to the pdb + AlignSeq as = new AlignSeq(sequence, + ((PDBChain) pdb.chains.elementAt(i)).sequence, "pep"); + as.calcScoreMatrix(); + as.traceAlignment(); + as.printAlignment(); + + + if (as.maxscore > max) { + max = as.maxscore; + maxchain = i; + + pdbstart = as.seq2start; + pdbend = as.seq2end; + seqstart = as.seq1start + sequence.getStart()-1; + seqend = as.seq1end + sequence.getEnd()-1; + } + + System.out.println("PDB start/end " + pdbstart + " " + pdbend); + System.out.println("SEQ start/end "+ seqstart + " " + seqend); + } + + ((PDBChain) pdb.chains.elementAt(maxchain)).pdbstart = pdbstart; + ((PDBChain) pdb.chains.elementAt(maxchain)).pdbend = pdbend; + ((PDBChain) pdb.chains.elementAt(maxchain)).seqstart = seqstart; + ((PDBChain) pdb.chains.elementAt(maxchain)).seqend = seqend; + ((PDBChain) pdb.chains.elementAt(maxchain)).isVisible = true; + ((PDBChain) pdb.chains.elementAt(maxchain)).sequence = sequence; + + this.pdb = pdb; + this.prefsize = new Dimension(getWidth(), getHeight()); + + //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); + + findCentre(); + findWidth(); + + scale = findScale(); + + System.out.println("Scale factor = " + scale); + + updateSeqColours(); + ToolTipManager.sharedInstance().registerComponent(this); + ToolTipManager.sharedInstance().setInitialDelay(0); + ToolTipManager.sharedInstance().setDismissDelay(10000); + + } + + public void deleteBonds() { + scale = 0; + maxwidth = 0; + + width[0] = 0; + width[1] = 0; + width[2] = 0; + + centre[0] = 0; + centre[1] = 0; + centre[2] = 0; + + for (int i = 0; i < pdb.chains.size(); i++) { + ((PDBChain) pdb.chains.elementAt(i)).bonds = null; + } + } + + public void findWidth() { + float[] max = new float[3]; + float[] min = new float[3]; + + max[0] = (float) -1e30; + max[1] = (float) -1e30; + max[2] = (float) -1e30; + + min[0] = (float) 1e30; + min[1] = (float) 1e30; + min[2] = (float) 1e30; + + for (int ii = 0; ii < pdb.chains.size(); ii++) { + if (((PDBChain) pdb.chains.elementAt(ii)).isVisible) { + Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds; + + for (int i = 0; i < bonds.size(); i++) { + Bond tmp = (Bond) bonds.elementAt(i); + + if (tmp.start[0] >= max[0]) { + max[0] = tmp.start[0]; + } + + if (tmp.start[1] >= max[1]) { + max[1] = tmp.start[1]; + } + + if (tmp.start[2] >= max[2]) { + max[2] = tmp.start[2]; + } + + if (tmp.start[0] <= min[0]) { + min[0] = tmp.start[0]; + } + + if (tmp.start[1] <= min[1]) { + min[1] = tmp.start[1]; + } + + if (tmp.start[2] <= min[2]) { + min[2] = tmp.start[2]; + } + + if (tmp.end[0] >= max[0]) { + max[0] = tmp.end[0]; + } + + if (tmp.end[1] >= max[1]) { + max[1] = tmp.end[1]; + } + + if (tmp.end[2] >= max[2]) { + max[2] = tmp.end[2]; + } + + if (tmp.end[0] <= min[0]) { + min[0] = tmp.end[0]; + } + + if (tmp.end[1] <= min[1]) { + min[1] = tmp.end[1]; + } + + if (tmp.end[2] <= min[2]) { + min[2] = tmp.end[2]; + } + } + } + } + + System.out.println("xmax " + max[0] + " min " + min[0]); + System.out.println("ymax " + max[1] + " min " + min[1]); + System.out.println("zmax " + max[2] + " min " + min[2]); + + width[0] = (float) Math.abs(max[0] - min[0]); + width[1] = (float) Math.abs(max[1] - min[1]); + width[2] = (float) Math.abs(max[2] - min[2]); + + maxwidth = width[0]; + + if (width[1] > width[0]) { + maxwidth = width[1]; + } + + if (width[2] > width[1]) { + maxwidth = width[2]; + } + + System.out.println("Maxwidth = " + maxwidth); + } + + public float findScale() { + int dim; + int width; + int height; + + if (getWidth() != 0) { + width = getWidth(); + height = getHeight(); + } else { + width = prefsize.width; + height = prefsize.height; + } + + if (width < height) { + dim = width; + } else { + dim = height; + } + + return (float) (dim / (1.5d * maxwidth)); + } + + public void findCentre() { + float xtot = 0; + float ytot = 0; + float ztot = 0; + + int bsize = 0; + + //Find centre coordinate + for (int ii = 0; ii < pdb.chains.size(); ii++) { + if (((PDBChain) pdb.chains.elementAt(ii)).isVisible) { + Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds; + + bsize += bonds.size(); + + for (int i = 0; i < bonds.size(); i++) { + xtot = xtot + ((Bond) bonds.elementAt(i)).start[0] + + ((Bond) bonds.elementAt(i)).end[0]; + + ytot = ytot + ((Bond) bonds.elementAt(i)).start[1] + + ((Bond) bonds.elementAt(i)).end[1]; + + ztot = ztot + ((Bond) bonds.elementAt(i)).start[2] + + ((Bond) bonds.elementAt(i)).end[2]; + } + } + } + + centre[0] = xtot / (2 * (float) bsize); + centre[1] = ytot / (2 * (float) bsize); + centre[2] = ztot / (2 * (float) bsize); + } + + public void paintComponent(Graphics g) { + + if(pdb==null) + { + g.setColor(Color.black); + g.setFont(new Font("Verdana", Font.BOLD, 14)); + g.drawString("Retrieving PDB data....", 20, getHeight()/2); + + return; + } + + + //Only create the image at the beginning - + //this saves much memory usage + if ((img == null) || (prefsize.width != getWidth()) || + (prefsize.height != getHeight())) { + prefsize.width = getWidth(); + prefsize.height = getHeight(); + + scale = findScale(); + img = createImage(prefsize.width, prefsize.height); + ig = img.getGraphics(); + Graphics2D ig2 = (Graphics2D) ig; + + ig2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + + + redrawneeded = true; + } + + + if (redrawneeded) + { + drawAll(ig, prefsize.width, prefsize.height); + redrawneeded = false; + } + + g.drawImage(img, 0, 0, this); + } + + public void drawAll(Graphics g, int width, int height) + { + g.setColor(Color.black); + g.fillRect(0, 0, width, height); + drawScene(g); + drawLabels(g); + } + + + public void updateSeqColours() + { + if(bysequence) + { + for (int ii = 0; ii < pdb.chains.size(); ii++) + { + ( (PDBChain) pdb.chains.elementAt(ii)).colourBySequence(sr, fr); + } + } + + redrawneeded=true; + repaint(); + + } + + public void drawScene(Graphics g) { + // Sort the bonds by z coord + Vector bonds = new Vector(); + + for (int ii = 0; ii < pdb.chains.size(); ii++) + { + if ( ( (PDBChain) pdb.chains.elementAt(ii)).isVisible) + { + Vector tmp = ( (PDBChain) pdb.chains.elementAt(ii)).bonds; + + for (int i = 0; i < tmp.size(); i++) + { + bonds.addElement(tmp.elementAt(i)); + } + } + } + + if (zbuffer) { + Zsort.Zsort(bonds); + } + + for (int i = 0; i < bonds.size(); i++) { + Bond tmpBond = (Bond) bonds.elementAt(i); + + xstart = (int) (((tmpBond.start[0] - centre[0]) * scale) + + (getWidth() / 2)); + ystart = (int) (((tmpBond.start[1] - centre[1]) * scale) + + (getHeight() / 2)); + + xend = (int) (((tmpBond.end[0] - centre[0]) * scale) + + (getWidth() / 2)); + yend = (int) (((tmpBond.end[1] - centre[1]) * scale) + + (getHeight() / 2)); + + xmid = (xend + xstart) / 2; + ymid = (yend + ystart) / 2; + + if (depthcue && !bymolecule) { + if (tmpBond.start[2] < (centre[2] - (maxwidth / 6))) { + g.setColor(tmpBond.startCol.darker().darker()); + drawLine(g, xstart, ystart, xmid, ymid); + + g.setColor(tmpBond.endCol.darker().darker()); + drawLine(g, xmid, ymid, xend, yend); + } else if (tmpBond.start[2] < (centre[2] + (maxwidth / 6))) { + g.setColor(tmpBond.startCol.darker()); + drawLine(g, xstart, ystart, xmid, ymid); + + g.setColor(tmpBond.endCol.darker()); + drawLine(g, xmid, ymid, xend, yend); + } else { + g.setColor(tmpBond.startCol); + drawLine(g, xstart, ystart, xmid, ymid); + + g.setColor(tmpBond.endCol); + drawLine(g, xmid, ymid, xend, yend); + } + } else if (depthcue && bymolecule) { + if (tmpBond.start[2] < (centre[2] - (maxwidth / 6))) { + g.setColor(Color.green.darker().darker()); + drawLine(g, xstart, ystart, xend, yend); + } else if (tmpBond.start[2] < (centre[2] + (maxwidth / 6))) { + g.setColor(Color.green.darker()); + drawLine(g, xstart, ystart, xend, yend); + } else { + g.setColor(Color.green); + drawLine(g, xstart, ystart, xend, yend); + } + } else if (!depthcue && !bymolecule) { + g.setColor(tmpBond.startCol); + drawLine(g, xstart, ystart, xmid, ymid); + g.setColor(tmpBond.endCol); + drawLine(g, xmid, ymid, xend, yend); + } else { + drawLine(g, xstart, ystart, xend, yend); + } + } + } + + public void drawLine(Graphics g, int x1, int y1, int x2, int y2) { + if (!wire) { + if (((float) Math.abs(y2 - y1) / (float) Math.abs(x2 - x1)) < 0.5) { + g.drawLine(x1, y1, x2, y2); + g.drawLine(x1 + 1, y1 + 1, x2 + 1, y2 + 1); + g.drawLine(x1, y1 - 1, x2, y2 - 1); + } else { + g.setColor(g.getColor().brighter()); + g.drawLine(x1, y1, x2, y2); + g.drawLine(x1 + 1, y1, x2 + 1, y2); + g.drawLine(x1 - 1, y1, x2 - 1, y2); + } + } else { + g.drawLine(x1, y1, x2, y2); + } + } + + public Dimension minimumsize() { + return prefsize; + } + + public Dimension preferredsize() { + return prefsize; + } + + public void keyPressed(KeyEvent evt) { + int key = evt.getKeyChar(); + System.out.println(key); + if (evt.getKeyCode() == KeyEvent.VK_UP) + { + scale = (float) (scale * 1.1); + redrawneeded = true; + repaint(); + } + else if (evt.getKeyCode() == KeyEvent.VK_DOWN) + { + scale = (float) (scale * 0.9); + redrawneeded = true; + repaint(); + } + } + + public void mousePressed(MouseEvent e) { + myAtom fatom = findAtom(e.getX(), e.getY()); + if(fatom!=null) + { + fatom.isSelected = !fatom.isSelected; + redrawneeded = true; + repaint(); + } + mx = e.getX(); + my = e.getY(); + omx = mx; + omy = my; + dragging = false; + } + + public void mouseMoved(MouseEvent e) { + + myAtom fatom = findAtom(e.getX(), e.getY()); + + if (fatom != null) { + this.setToolTipText(fatom.resNumber+" "+ fatom.resName); + } else { + this.setToolTipText(""); + } + } + + public void mouseClicked(MouseEvent e) { + } + + public void mouseEntered(MouseEvent e) { + } + + public void mouseExited(MouseEvent e) { + } + + public void mouseDragged(MouseEvent evt) { + int x = evt.getX(); + int y = evt.getY(); + mx = x; + my = y; + + MCMatrix objmat = new MCMatrix(3, 3); + objmat.setIdentity(); + + if ((evt.getModifiers() & Event.META_MASK) != 0) { + objmat.rotatez((float) ((mx - omx))); + } else { + objmat.rotatex((float) ((my - omy))); + objmat.rotatey((float) ((omx - mx))); + } + + //Alter the bonds + for (int ii = 0; ii < pdb.chains.size(); ii++) { + Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds; + + for (int i = 0; i < bonds.size(); i++) { + Bond tmpBond = (Bond) bonds.elementAt(i); + + //Translate the bond so the centre is 0,0,0 + tmpBond.translate(-centre[0], -centre[1], -centre[2]); + + //Now apply the rotation matrix + tmpBond.start = objmat.vectorMultiply(tmpBond.start); + tmpBond.end = objmat.vectorMultiply(tmpBond.end); + + //Now translate back again + tmpBond.translate(centre[0], centre[1], centre[2]); + } + } + + objmat = null; + + omx = mx; + omy = my; + + dragging = true; + + redrawneeded = true; + + repaint(); + } + + public void mouseReleased(MouseEvent evt) { + dragging = false; + return; + } + + void drawLabels(Graphics g) { + + for (int ii = 0; ii < pdb.chains.size(); ii++) { + PDBChain chain = (PDBChain) pdb.chains.elementAt(ii); + + if (chain.isVisible) { + Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds; + + for (int i = 0; i < bonds.size(); i++) { + Bond tmpBond = (Bond) bonds.elementAt(i); + + if (tmpBond.at1.isSelected) { + labelAtom(g, tmpBond, 1); + } + + if (tmpBond.at2.isSelected) { + labelAtom(g, tmpBond, 2); + } + } + } + } + } + + public void labelAtom(Graphics g, Bond b, int n) { + g.setFont(font); + + if (n == 1) { + int xstart = (int) (((b.start[0] - centre[0]) * scale) + + (getWidth() / 2)); + int ystart = (int) (((b.start[1] - centre[1]) * scale) + + (getHeight() / 2)); + + g.setColor(Color.red); + g.drawString(b.at1.resName + "-" + b.at1.resNumber, xstart, ystart); + } + + if (n == 2) { + int xstart = (int) (((b.end[0] - centre[0]) * scale) + + (getWidth() / 2)); + int ystart = (int) (((b.end[1] - centre[1]) * scale) + + (getHeight() / 2)); + + g.setColor(Color.red); + g.drawString(b.at2.resName + "-" + b.at2.resNumber, xstart, ystart); + } + } + + public myAtom findAtom(int x, int y) { + myAtom fatom = null; + + int foundchain = -1; + + for (int ii = 0; ii < pdb.chains.size(); ii++) { + PDBChain chain = (PDBChain) pdb.chains.elementAt(ii); + + if (chain.isVisible) { + Vector bonds = ((PDBChain) pdb.chains.elementAt(ii)).bonds; + + for (int i = 0; i < bonds.size(); i++) { + Bond tmpBond = (Bond) bonds.elementAt(i); + + int truex = (int) (((tmpBond.start[0] - centre[0]) * scale) + + (getWidth() / 2)); + + if (Math.abs(truex - x) <= 2) { + int truey = (int) (((tmpBond.start[1] - centre[1]) * scale) + + (getHeight() / 2)); + + if (Math.abs(truey - y) <= 2) + { + fatom = tmpBond.at1; + foundchain = ii; + } + } + } + } + + if (fatom != null) //)&& chain.ds != null) + { + chain = (PDBChain) pdb.chains.elementAt(foundchain); + + // SMJS TODO + // int tmp = chain.ds.seqstart + fatom.resNumber - chain.offset; + // int pos = chain.ds.findIndex(tmp); + // System.out.println("Found seq " + chain.ds.name + " " + tmp + " " + pos); + } + } + + return fatom; + } + + public void update(Graphics g) { + paint(g); + } +} diff --git a/src/MCview/PDBViewer.java b/src/MCview/PDBViewer.java new file mode 100755 index 0000000..2610b40 --- /dev/null +++ b/src/MCview/PDBViewer.java @@ -0,0 +1,400 @@ +package MCview; + +import javax.swing.*; +import java.awt.event.*; +import jalview.datamodel.*; +import jalview.gui.*; +import jalview.io.EBIFetchClient; +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; +import java.io.FileOutputStream; +import org.jibble.epsgraphics.EpsGraphics2D; +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.awt.Graphics; +import java.awt.Graphics2D; +import java.awt.RenderingHints; + +public class PDBViewer extends JInternalFrame implements Runnable +{ + PDBEntry pdb; + Sequence sequence; + SeqCanvas seqcanvas; + PDBCanvas pdbcanvas; + + + public PDBViewer(PDBEntry entry, + Sequence seq, + SeqCanvas seqcanvas) + { + pdb = entry; + sequence = seq; + this.seqcanvas = seqcanvas; + + + try + { + jbInit(); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + + pdbcanvas = new PDBCanvas(); + setContentPane(pdbcanvas); + Desktop.addInternalFrame(this, + sequence.getName() + ":" + pdb.getId() + + " Method: " + pdb.getProperty().get("method") + + " Chain:" + pdb.getProperty().get("chains"), + 400, 400); + + Thread worker = new Thread(this); + worker.start(); + } + + public void run() + { + try + { + EBIFetchClient ebi = new EBIFetchClient(); + String[] result = ebi.fetchData("pdb:" + pdb.getId(), null, + null); + + PDBfile pdbfile = new PDBfile(result); + + pdbcanvas.setPDBFile(pdbfile, + sequence, + seqcanvas.getSequenceRenderer(), + seqcanvas.getFeatureRenderer()); + + seqcanvas.setPDBViewer(pdbcanvas); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + + private void jbInit() + throws Exception + { + this.addKeyListener(new KeyAdapter() + { + public void keyPressed(KeyEvent evt) + { + System.out.println("key press"); + pdbcanvas.keyPressed(evt); + } + }); + + this.setJMenuBar(jMenuBar1); + fileMenu.setText("File"); + coloursMenu.setText("Colours"); + saveMenu.setActionCommand("Save Image"); + saveMenu.setText("Save As"); + png.setText("PNG"); + png.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + png_actionPerformed(e); + } + }); + eps.setText("EPS"); + eps.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + eps_actionPerformed(e); + } + }); + mapping.setText("View Mapping"); + wire.setText("Wireframe"); + wire.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + wire_actionPerformed(e); + } + }); + depth.setSelected(true); + depth.setText("Depthcue"); + depth.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + depth_actionPerformed(e); + } + }); + zbuffer.setSelected(true); + zbuffer.setText("Z Buffering"); + zbuffer.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + zbuffer_actionPerformed(e); + } + }); + charge.setText("Charge & Cysteine"); + charge.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + charge_actionPerformed(e); + } + }); + hydro.setText("Hydrophobicity"); + hydro.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + hydro_actionPerformed(e); + } + }); + chain.setText("By Chain"); + chain.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + chain_actionPerformed(e); + } + }); + seqButton.setSelected(true); + seqButton.setText("By Sequence"); + seqButton.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + seqButton_actionPerformed(e); + } + }); + molecule.setText("By Molecule"); + molecule.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent e) + { + molecule_actionPerformed(e); + } + }); + jMenuBar1.add(fileMenu); + jMenuBar1.add(coloursMenu); + fileMenu.add(saveMenu); + fileMenu.add(mapping); + saveMenu.add(png); + saveMenu.add(eps); + coloursMenu.add(seqButton); + coloursMenu.add(chain); + coloursMenu.add(hydro); + coloursMenu.add(charge); + coloursMenu.addSeparator(); + coloursMenu.add(wire); + coloursMenu.add(depth); + coloursMenu.add(zbuffer); + coloursMenu.add(molecule); + ButtonGroup bg = new ButtonGroup(); + bg.add(seqButton); + bg.add(chain); + bg.add(hydro); + bg.add(charge); + } + + JMenuBar jMenuBar1 = new JMenuBar(); + JMenu fileMenu = new JMenu(); + JMenu coloursMenu = new JMenu(); + JMenu saveMenu = new JMenu(); + JMenuItem png = new JMenuItem(); + JMenuItem eps = new JMenuItem(); + JMenuItem mapping = new JMenuItem(); + JCheckBoxMenuItem wire = new JCheckBoxMenuItem(); + JCheckBoxMenuItem depth = new JCheckBoxMenuItem(); + JCheckBoxMenuItem zbuffer = new JCheckBoxMenuItem(); + JRadioButtonMenuItem charge = new JRadioButtonMenuItem(); + JRadioButtonMenuItem hydro = new JRadioButtonMenuItem(); + JRadioButtonMenuItem chain = new JRadioButtonMenuItem(); + JRadioButtonMenuItem seqButton = new JRadioButtonMenuItem(); + JCheckBoxMenuItem molecule = new JCheckBoxMenuItem(); + + public void png_actionPerformed(ActionEvent e) + { + int width = pdbcanvas.getWidth(); + int height = pdbcanvas.getHeight(); + + try + { + jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(jalview.bin.Cache.getProperty( + "LAST_DIRECTORY"), new String[] { "png" }, + new String[] { "Portable network graphics" }, + "Portable network graphics"); + + chooser.setFileView(new jalview.io.JalviewFileView()); + chooser.setDialogTitle("Create PNG Image of Molecule"); + chooser.setToolTipText("Save"); + + int value = chooser.showSaveDialog(this); + + if (value != jalview.io.JalviewFileChooser.APPROVE_OPTION) + { + return; + } + + jalview.bin.Cache.setProperty("LAST_DIRECTORY", + chooser.getSelectedFile().getParent()); + + FileOutputStream out = new FileOutputStream(chooser.getSelectedFile()); + + BufferedImage bi = new BufferedImage(width, height, + BufferedImage.TYPE_INT_RGB); + Graphics png = bi.getGraphics(); + Graphics2D ig2 = (Graphics2D) png; + ig2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + + + pdbcanvas.drawAll(png, width, height); + + ImageIO.write(bi, "png", out); + out.close(); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + } + + public void eps_actionPerformed(ActionEvent e) + { + boolean accurateText = true; + + String renderStyle = jalview.bin.Cache.getDefault("EPS_RENDERING", + "Prompt each time"); + + // If we need to prompt, and if the GUI is visible then + // Prompt for EPS rendering style + if (renderStyle.equalsIgnoreCase("Prompt each time") + && ! + (System.getProperty("java.awt.headless") != null + && System.getProperty("java.awt.headless").equals("true"))) + { + EPSOptions eps = new EPSOptions(); + renderStyle = eps.getValue(); + + if (renderStyle==null || eps.cancelled) + return; + + + } + + if (renderStyle.equalsIgnoreCase("text")) + { + accurateText = false; + } + + int width = getWidth(); + int height = getHeight(); + + try + { + jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(jalview.bin.Cache.getProperty( + "LAST_DIRECTORY"), new String[] { "eps" }, + new String[] { "Encapsulated Postscript" }, + "Encapsulated Postscript"); + chooser.setFileView(new jalview.io.JalviewFileView()); + chooser.setDialogTitle("Create EPS file from tree"); + chooser.setToolTipText("Save"); + + int value = chooser.showSaveDialog(this); + + if (value != jalview.io.JalviewFileChooser.APPROVE_OPTION) + { + return; + } + + jalview.bin.Cache.setProperty("LAST_DIRECTORY", + chooser.getSelectedFile().getParent()); + + FileOutputStream out = new FileOutputStream(chooser.getSelectedFile()); + EpsGraphics2D pg = new EpsGraphics2D("Tree", out, 0, 0, width, + height); + Graphics2D ig2 = (Graphics2D) pg; + ig2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, + RenderingHints.VALUE_ANTIALIAS_ON); + + + pg.setAccurateTextMode(accurateText); + + pdbcanvas.drawAll(pg, width, height); + + pg.flush(); + pg.close(); + } + catch (Exception ex) + { + ex.printStackTrace(); + } + + } + + public void charge_actionPerformed(ActionEvent e) + { + pdbcanvas.pdb.setChargeColours(); + pdbcanvas.redrawneeded=true; + pdbcanvas.repaint(); + } + + public void hydro_actionPerformed(ActionEvent e) + { + pdbcanvas.pdb.setHydrophobicityColours(); + pdbcanvas.redrawneeded=true; + pdbcanvas.repaint(); + } + + public void chain_actionPerformed(ActionEvent e) + { + pdbcanvas.pdb.setChainColours(); + pdbcanvas.redrawneeded=true; + pdbcanvas.repaint(); + } + + public void zbuffer_actionPerformed(ActionEvent e) + { + pdbcanvas.zbuffer = ! pdbcanvas.zbuffer; + pdbcanvas.redrawneeded=true; + pdbcanvas.repaint(); + } + + public void molecule_actionPerformed(ActionEvent e) + { + pdbcanvas.bymolecule = ! pdbcanvas.bymolecule; + pdbcanvas.redrawneeded=true; + pdbcanvas.repaint(); + } + + public void depth_actionPerformed(ActionEvent e) + { + pdbcanvas.depthcue = ! pdbcanvas.depthcue; + pdbcanvas.redrawneeded=true; + pdbcanvas.repaint(); + } + + public void wire_actionPerformed(ActionEvent e) + { + pdbcanvas.wire = ! pdbcanvas.wire; + pdbcanvas.redrawneeded=true; + pdbcanvas.repaint(); + } + + public void seqButton_actionPerformed(ActionEvent e) + { + pdbcanvas.bysequence = seqButton.isSelected(); + pdbcanvas.updateSeqColours(); + } + + void clearButtonGroup() + { + charge.setSelected(false); + hydro.setSelected(false); + chain.setSelected(false); + seqButton.setSelected(false); + } +} diff --git a/src/jalview/datamodel/PDBEntry.java b/src/jalview/datamodel/PDBEntry.java new file mode 100755 index 0000000..508e530 --- /dev/null +++ b/src/jalview/datamodel/PDBEntry.java @@ -0,0 +1,38 @@ +package jalview.datamodel; + +import java.util.*; +public class PDBEntry +{ + String type; + String id; + // //String method; + //String chains; + Hashtable properties; + + public PDBEntry() + { } + + public void setType(String type) + { this.type = type; } + + public String getType() + { return type; } + + public void setId(String id) + { this.id = id; } + + public String getId() + { return id; } + + public void setProperty(Hashtable property) + { + this.properties = property; + } + + public Hashtable getProperty() + { + return properties; + } + + +}