001/* 002 * BioJava development code 003 * 004 * This code may be freely distributed and modified under the 005 * terms of the GNU Lesser General Public Licence. This should 006 * be distributed with the code. If you do not have a copy, 007 * see: 008 * 009 * http://www.gnu.org/copyleft/lesser.html 010 * 011 * Copyright for this code is held jointly by the individual 012 * authors. These should be listed in @author doc comments. 013 * 014 * For more information on the BioJava project and its aims, 015 * or to join the biojava-l mailing list, visit the home page 016 * at: 017 * 018 * http://www.biojava.org/ 019 * 020 * created at May 28, 2008 021 */ 022package org.biojava.nbio.structure.gui.events; 023 024import org.biojava.nbio.structure.Atom; 025import org.biojava.nbio.structure.Chain; 026import org.biojava.nbio.structure.Group; 027import org.biojava.nbio.structure.Structure; 028import org.biojava.nbio.structure.align.StructurePairAligner; 029import org.biojava.nbio.structure.gui.BiojavaJmol; 030import org.biojava.nbio.structure.gui.util.AlignedPosition; 031 032 033 034public class JmolAlignedPositionListener implements AlignmentPositionListener{ 035 036 BiojavaJmol parent; 037 Atom[] ca1; 038 Atom[] ca2; 039 StructurePairAligner structurePairAligner; 040 041 public JmolAlignedPositionListener(BiojavaJmol parent, StructurePairAligner alig){ 042 this.parent = parent; 043 structurePairAligner = alig; 044 } 045 046 047 048 public void setStructure1(Structure structure1) { 049 050 ca1 = structurePairAligner.getAlignmentAtoms(structure1); 051 } 052 053 054 055 public void setStructure2(Structure structure2) { 056 057 ca2 = structurePairAligner.getAlignmentAtoms(structure2); 058 } 059 060 @Override 061 public void mouseOverPosition(AlignedPosition p) { 062 063 //System.out.println("mouseoverposition " + p); 064 065 int p1 = p.getPos1(); 066 int p2 = p.getPos2(); 067 String s = "select "; 068 069 if ((p1 > ca1.length) || (p2 > ca2.length)){ 070 System.err.println("requsting atom out of bounds! " ); 071 return; 072 } 073 074 String pdbpos1 =""; 075 String pdbpos2 = ""; 076 077 if ( p1 >-1) { 078 Atom a = ca1[p1]; 079 Group parent = a.getGroup(); 080 Chain c = parent.getChain(); 081 pdbpos1 = parent.getResidueNumber().toString(); 082 //System.out.printlng"chainid 1 is >"+c.getName()+"<"); 083 if (! c.getChainID().equals( " ")) { 084 pdbpos1 += ":" + c.getChainID(); 085 } 086 087 088 //System.out.println("1:" + parent); 089 s += pdbpos1 +"/1"; 090 } 091 092 if ( p2 >-1) { 093 Atom a = ca2[p2]; 094 Group parent = a.getGroup(); 095 Chain c = parent.getChain(); 096 pdbpos2 = parent.getResidueNumber().toString(); 097 //System.out.println("2:" + parent); 098 //System.out.println("chainid 2 is >"+c.getName()+"<"); 099 if (! c.getChainID().equals( " ")) { 100 pdbpos2 += ":" + c.getChainID(); 101 } 102 if ( p1 > -1) 103 s +=","; 104 s += pdbpos2 +"/2"; 105 } 106 s+="; set display selected;"; 107 //System.out.println(s); 108 parent.evalString(s); 109 110 111 } 112 113 @Override 114 public void positionSelected(AlignedPosition p) { 115 mouseOverPosition(p); 116 117 } 118 119 @Override 120 public void rangeSelected(AlignedPosition start, AlignedPosition end) { 121 122 123 } 124 125 @Override 126 public void selectionLocked() { 127 // TODO Auto-generated method stub 128 129 } 130 131 @Override 132 public void selectionUnlocked() { 133 // TODO Auto-generated method stub 134 135 } 136 137 138 139 @Override 140 public void toggleSelection(AlignedPosition p) { 141 // TODO Auto-generated method stub 142 143 } 144 145 146 147}