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.internal;
022
023import java.util.Map;
024
025import org.biojava.nbio.structure.Atom;
026import org.biojava.nbio.structure.StructureException;
027import org.biojava.nbio.structure.align.model.AFPChain;
028import org.biojava.nbio.structure.align.util.AlignmentTools;
029
030/**
031 * Calls Spencer's method for determining order.
032 * This method uses the sequence alignment information
033 * to guess the order of symmetry.
034 *
035 * @author dmyersturnbull
036 * @since 4.2.0
037 *
038 */
039public class SequenceFunctionOrderDetector implements OrderDetector {
040
041        private int maxSymmetry = 8;
042        private float minimumMetricChange = 0.4f;
043
044        public SequenceFunctionOrderDetector() {}
045
046        public SequenceFunctionOrderDetector(int maxSymmetry, float minimumMetricChange) {
047                this.maxSymmetry = maxSymmetry;
048                this.minimumMetricChange = minimumMetricChange;
049        }
050
051        @Override
052        public int calculateOrder(AFPChain afpChain, Atom[] ca)
053                        throws RefinerFailedException {
054                try {
055                        Map<Integer,Integer> alignment =
056                                        AlignmentTools.alignmentAsMap(afpChain);
057
058                        return AlignmentTools.getSymmetryOrder(alignment,
059                                        new AlignmentTools.IdentityMap<Integer>(),
060                                        maxSymmetry, minimumMetricChange);
061
062                } catch (StructureException e) {
063                        throw new RefinerFailedException(e);
064                }
065        }
066
067        @Override
068        public String toString() {
069                return "SequenceFunctionOrderDetector [maxSymmetry=" + maxSymmetry
070                                + ", minimumMetricChange=" + minimumMetricChange + "]";
071        }
072}