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
025import java.util.ArrayList;
026import java.util.List;
027
028import org.biojava.nbio.structure.Atom;
029import org.biojava.nbio.structure.Structure;
030import org.biojava.nbio.structure.StructureException;
031import org.biojava.nbio.structure.StructureIdentifier;
032import org.biojava.nbio.structure.StructureTools;
033import org.biojava.nbio.structure.align.MultipleStructureAligner;
034import org.biojava.nbio.structure.align.multiple.MultipleAlignment;
035import org.slf4j.Logger;
036import org.slf4j.LoggerFactory;
037
038/**
039 *  A class that obtains structures via DAS and aligns them.
040 *  This is done in a separate thread.
041 *  It is possible to register Event listeners to get notification of when
042 *  the download has finished.
043 *
044 * @author Aleix Lafita
045 * @since 4.2.0
046 *
047 */
048public class MultipleAlignmentCalc implements AlignmentCalculationRunnable {
049
050        private static final Logger logger =
051                        LoggerFactory.getLogger(MultipleAlignmentCalc.class);
052
053        private List<StructureIdentifier> names;
054        private List<Structure> structures;
055
056        private MultipleAlignmentGUI parent;
057
058        /**
059         * Requests an alignment of the pdbs.
060         * If they are empty strings, they are ignored.
061         *
062         * @param parent the gui frame that interacts with this class
063         * @param structures
064         * @param names
065         */
066        public MultipleAlignmentCalc(MultipleAlignmentGUI parent,
067                        List<Structure> structures, List<StructureIdentifier> names) {
068
069                this.parent= parent;
070                this.structures = structures;
071                this.names = names;
072        }
073
074        @Override
075        public void run() {
076
077                MultipleStructureAligner algorithm =
078                                parent.getMultipleStructureAligner();
079                try {
080
081                        List<Atom[]> atomArrays = new ArrayList<Atom[]>();
082                        for (Structure s:structures){
083                                Atom[] ca = StructureTools.getRepresentativeAtomArray(s);
084                                atomArrays.add(ca);
085                        }
086
087                        MultipleAlignment msa = algorithm.align(atomArrays);
088                        msa.getEnsemble().setStructureIdentifiers(names);
089
090                        MultipleAlignmentJmolDisplay.display(msa);
091
092                } catch (StructureException e) {
093                        e.printStackTrace();
094                        logger.warn(e.getMessage());
095                }
096
097                parent.notifyCalcFinished();
098        }
099
100        @Override
101        public void interrupt() {}
102
103        @Override
104        public void cleanup() {
105
106                parent.notifyCalcFinished();
107                parent=null;
108                structures = null;
109                names = null;
110        }
111
112        @Override
113        public void setNrCPUs(int useNrCPUs) {
114                // TODO Auto-generated method stub
115        }
116}