001/*
002 *                    PDB web 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 *
015 * Created on May 23, 2009
016 * Created by Andreas Prlic
017 *
018 */
019
020package org.biojava.nbio.structure.align.pairwise;
021
022import org.biojava.nbio.structure.Atom;
023import org.biojava.nbio.structure.Calc;
024import org.biojava.nbio.structure.align.helper.JointFragments;
025import org.biojava.nbio.structure.jama.Matrix;
026
027import javax.swing.*;
028import java.awt.event.WindowAdapter;
029import java.awt.event.WindowEvent;
030import java.util.List;
031
032
033/** A class to listen to progress of the structure alignment calculations
034 *
035 * @author andreas
036 *
037 */
038public class AlignmentProgressListener
039{
040
041        String n1;
042        String n2;
043        int l1;
044        int l2;
045
046        Atom[] ca1 ;
047        Atom[] ca2;
048
049        public AlignmentProgressListener(){
050
051        }
052
053        public void startingAlignment(String name1, Atom[] ca1, String name2, Atom[] ca2){
054                n1 = name1;
055                n2 = name2;
056                l1 = ca1.length;
057                l2 = ca2.length;
058                this.ca1 = ca1;
059                this.ca2 = ca2;
060        }
061
062        public void calculatedFragmentPairs(List<FragmentPair> fragments){
063                System.out.println("got: " + fragments.size() + " fragments");
064
065                String title = "Initial FragmentPairs for:" +  n1 + "("+l1+")"+ " vs. " + n2 + " ("+l2+")";
066                // ScaleableMatrixPanel panel = new ScaleableMatrixPanel();
067
068
069                Matrix m = new Matrix(l1,l2,99);
070
071                for (FragmentPair p : fragments){
072                        for (FragmentPair pair2: fragments){
073
074
075                                //Atom v2 = tmpfidx[j].getCenter2();
076                                Atom v1 = p.getUnitv();
077                                Atom v2 = pair2.getUnitv();
078                                //System.out.println("v1: "+v1);
079                                //System.out.println("v2: "+v2);
080
081                                double dist = Calc.getDistance(v1,v2);
082                                for (int i =0 ; i < p.getLength(); i++){
083                                        int p1 = p.getPos1();
084                                        int p2 = p.getPos2();
085                                        m.set(p1+i,p2+i,dist);
086                                }
087                                for (int i =0 ; i < pair2.getLength(); i++){
088                                        int p1 = pair2.getPos1();
089                                        int p2 = pair2.getPos2();
090                                        m.set(p1+i,p2+i,dist);
091                                }
092
093
094                        }
095
096                }
097                //  panel.setMatrix(m);
098                JFrame frame = new JFrame();
099
100                frame.setTitle(title);
101
102                frame.addWindowListener(new WindowAdapter(){
103                        @Override
104                        public void windowClosing(WindowEvent e){
105                                JFrame f = (JFrame) e.getSource();
106                                f.setVisible(false);
107                                f.dispose();
108                        }
109
110
111
112                });
113                //frame.getContentPane().add(panel);
114                frame.pack();
115                frame.setVisible(true);
116
117
118
119        }
120
121
122        public void jointFragments(JointFragments[] fragments){
123                System.out.println("numberof Joint fragments: " + fragments.length);
124
125                String title = "JointFragment for:" +  n1 + "("+l1+")"+ " vs. " + n2 + " ("+l2+")";
126                // ScaleableMatrixPanel panel = new ScaleableMatrixPanel();
127
128                Matrix m = new Matrix(l1,l2,99);
129
130                for (JointFragments p : fragments){
131                        for (int[] idx : p.getIdxlist() ){
132                                m.set(idx[0],idx[1],p.getRms());
133                        }
134                }
135                // panel.setMatrix(m);
136                JFrame frame = new JFrame();
137
138                frame.setTitle(title);
139
140                frame.addWindowListener(new WindowAdapter(){
141                        @Override
142                        public void windowClosing(WindowEvent e){
143                                JFrame f = (JFrame) e.getSource();
144                                f.setVisible(false);
145                                f.dispose();
146                        }
147
148
149
150                });
151                // frame.getContentPane().add(panel);
152                frame.pack();
153                frame.setVisible(true);
154
155
156
157
158                for (JointFragments f : fragments){
159                        System.out.println(f);
160                }
161        }
162}
163
164
165