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 on Jul 16, 2006 021 * 022 */ 023package org.biojava.nbio.structure.align.gui; 024 025 026import org.biojava.nbio.structure.Atom; 027import org.biojava.nbio.structure.Structure; 028import org.biojava.nbio.structure.StructureException; 029import org.biojava.nbio.structure.StructureTools; 030import org.biojava.nbio.structure.align.StructureAlignment; 031import org.biojava.nbio.structure.align.ce.ConfigStrucAligParams; 032import org.biojava.nbio.structure.align.gui.jmol.StructureAlignmentJmol; 033import org.biojava.nbio.structure.align.model.AFPChain; 034import org.slf4j.Logger; 035import org.slf4j.LoggerFactory; 036 037 038/** A class that obtains two structures via DAS and aligns them 039 * This is done in a separate thread. 040 * It is possible to register Event listeners to get notification of when the download has finished. 041 * 042 * @author Andreas Prlic 043 * @since 1.7 044 * @version %I% %G% 045 */ 046public class AlignmentCalc implements AlignmentCalculationRunnable { 047 048 private static final Logger logger = LoggerFactory.getLogger(AlignmentCalc.class); 049 050 boolean interrupted = false; 051 052 String pdb1; 053 String pdb2; 054 055 String name1; 056 String name2; 057 058 Structure structure1; 059 Structure structure2; 060 061 AlignmentGui parent; 062 063 /** requests an alignment of pdb1 vs pdb 2. 064 * Chain 1 and chain2 are optional. 065 * If they are empty strings, they are ignored 066 * @param parent the alignment gui frame that interacts with this class 067 * @param s1 structure 1 068 * @param s2 structure 2 069 */ 070 public AlignmentCalc(AlignmentGui parent, Structure s1, Structure s2 , String name1, String name2) { 071 072 this.parent= parent; 073 074 structure1 = s1; 075 structure2 = s2; 076 077 this.name1 = name1; 078 this.name2 = name2; 079 080 } 081 082 @Override 083 public void run() { 084 085 // both structure have been downloaded, now calculate the alignment ... 086 087 StructureAlignment algorithm = parent.getStructureAlignment(); 088 //StructurePairAligner aligner = new StructurePairAligner(); 089 //aligner.setDebug(true); 090 try { 091 092 Atom[] ca1 = StructureTools.getRepresentativeAtomArray(structure1); 093 Atom[] ca2 = StructureTools.getRepresentativeAtomArray(structure2); 094 095 //System.out.println("ca1 size:" + ca1.length + " ca2 size: " + ca2.length); 096 AFPChain afpChain = algorithm.align(ca1, ca2); 097 098 afpChain.setName1(name1); 099 afpChain.setName2(name2); 100 101 StructureAlignmentJmol jmol = StructureAlignmentDisplay.display(afpChain, ca1, ca2); 102 103 String title = jmol.getTitle(); 104 ConfigStrucAligParams params = algorithm.getParameters(); 105 if ( params != null) 106 title += " " + algorithm.getParameters().toString(); 107 jmol.setTitle(title); 108 109 DisplayAFP.showAlignmentPanel(afpChain,ca1,ca2,jmol); 110 111 System.out.println(afpChain.toCE(ca1,ca2)); 112 113 } catch (StructureException e){ 114 e.printStackTrace(); 115 logger.warn(e.getMessage()); 116 } 117 118 119 120 //logger.info("done!"); 121 122 parent.notifyCalcFinished(); 123 124 } 125 126 127 128 129 /** stops what is currently happening and does not continue 130 * 131 * 132 */ 133 @Override 134 public void interrupt() { 135 interrupted = true; 136 } 137 138 @Override 139 public void cleanup() { 140 141 parent.notifyCalcFinished(); 142 143 parent=null; 144 // cleanup... 145 146 structure1 = null; 147 structure2 = null; 148 149 } 150 151 /** does not do anything here... 152 * 153 */ 154 @Override 155 public void setNrCPUs(int useNrCPUs) { 156 // TODO Auto-generated method stub 157 // 158 } 159 160 161 162} 163 164 165 166