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 */
021package org.biojava.nbio.structure.symmetry.gui;
022
023import org.biojava.nbio.structure.Atom;
024import org.biojava.nbio.structure.Structure;
025import org.biojava.nbio.structure.StructureException;
026import org.biojava.nbio.structure.align.gui.AlignmentCalculationRunnable;
027import org.biojava.nbio.structure.symmetry.internal.CESymmParameters;
028import org.biojava.nbio.structure.symmetry.internal.CeSymm;
029import org.biojava.nbio.structure.symmetry.internal.CeSymmResult;
030import org.biojava.nbio.structure.symmetry.utils.SymmetryTools;
031import org.slf4j.Logger;
032import org.slf4j.LoggerFactory;
033
034/**
035 * Calculates a symmetry analysis and displays the results. Linked to the
036 * SymmetryGUI. Does not generalize, uses CeSymm class directly to allow for the
037 * symmetry axis recovery.
038 *
039 * @author Aleix Lafita
040 * @since 4.2.0
041 *
042 */
043public class SymmetryCalc implements AlignmentCalculationRunnable {
044
045        private static final Logger logger = LoggerFactory
046                        .getLogger(SymmetryCalc.class);
047
048        boolean interrupted = false;
049
050        private Structure structure;
051        private SymmetryGui parent;
052
053        /**
054         * Requests for a structure to analyze.
055         */
056        public SymmetryCalc(SymmetryGui p, Structure s) {
057                parent = p;
058                structure = s;
059        }
060
061        @Override
062        public void run() {
063
064                CESymmParameters params = parent.getParameters();
065
066                try {
067
068                        Atom[] atoms = SymmetryTools.getRepresentativeAtoms(structure);
069
070                        CeSymmResult result = CeSymm.analyze(atoms, params);
071                        SymmetryDisplay.display(result);
072
073                } catch (StructureException e) {
074                        logger.warn(e.getMessage());
075                }
076                parent.notifyCalcFinished();
077        }
078
079        @Override
080        public void interrupt() {
081                interrupted = true;
082        }
083
084        @Override
085        public void cleanup() {
086
087                parent.notifyCalcFinished();
088                parent = null;
089                structure = null;
090        }
091
092        @Override
093        public void setNrCPUs(int useNrCPUs) {
094        }
095}