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.core;
022
023import java.io.Serializable;
024import java.util.Set;
025
026/**
027 * The QuatSymmetryParameters specify the options used for the detection of
028 * quaternary symmetry in structures using the {@link QuatSymmetryDetector}.
029 *
030 * @author Peter Rose
031 * @author Aleix Lafita
032 *
033 */
034public class QuatSymmetryParameters implements Serializable {
035
036        private static final long serialVersionUID = 1L;
037
038        private double rmsdThreshold = 7.0;
039        private double angleThreshold = 10.0; // max angle deviation for C2 solver
040        // if a structure has both cyclic and helical symmetry (i.e., 3J4F: C2 and
041        // H),
042        // then helical symmetry is assigned if Rmsd(helical) - Rmsd(cyclic) <=
043        // helixRmsdThreshold
044        // A slightly positive value gives preference to helical, if the RMSDs for
045        // the two symmetries
046        // are almost identical
047        private double helixRmsdThreshold = 0.05;
048        private double helixRmsdToRiseRatio = 0.5; // rmsd must be < 0.5 * abs(rise)
049                                                                                                // (previously set to 0.75)
050        private double minimumHelixRise = 1.0;
051        private double minimumHelixAngle = 5.0; // min helix angle to differentiate
052                                                                                        // it from a translational repeat
053        private int maximumLocalCombinations = 10000; // max number of combinations
054                                                                                                        // to try for local symmetry
055                                                                                                        // calculation
056        private double localTimeLimit = 120; // time limit for local calculations in
057                                                                                        // seconds
058        private double localTimeStart = -1; // time when the local calculations started
059                                                                                // if set (>0), local time limit will be used
060
061        private boolean onTheFly = true;
062
063        /**
064         * @return the rmsdThreshold
065         */
066        public double getRmsdThreshold() {
067                return rmsdThreshold;
068        }
069
070        /**
071         * @param rmsdThreshold
072         *            the rmsdThreshold to set
073         */
074        public void setRmsdThreshold(double rmsdThreshold) {
075                this.rmsdThreshold = rmsdThreshold;
076        }
077
078        public double getAngleThreshold() {
079                return angleThreshold;
080        }
081
082        public void setAngleThreshold(double angleThreshold) {
083                this.angleThreshold = angleThreshold;
084        }
085
086        public double getHelixRmsdThreshold() {
087                return helixRmsdThreshold;
088        }
089
090        public void setHelixRmsdThreshold(double helixRmsdThreshold) {
091                this.helixRmsdThreshold = helixRmsdThreshold;
092        }
093
094        /**
095         * @return the helixRmsdToRiseRatio
096         */
097        public double getHelixRmsdToRiseRatio() {
098                return helixRmsdToRiseRatio;
099        }
100
101        /**
102         * @param helixRmsdToRiseRatio
103         *            the helixRmsdToRiseRatio to set
104         */
105        public void setHelixRmsdToRiseRatio(double helixRmsdToRiseRatio) {
106                this.helixRmsdToRiseRatio = helixRmsdToRiseRatio;
107        }
108
109        public double getMinimumHelixRise() {
110                return minimumHelixRise;
111        }
112
113        public void setMinimumHelixRise(double minimumHelixRise) {
114                this.minimumHelixRise = minimumHelixRise;
115        }
116
117        public double getMinimumHelixAngle() {
118                return minimumHelixAngle;
119        }
120
121        public void setMinimumHelixAngle(double minimumHelixAngle) {
122                this.minimumHelixAngle = minimumHelixAngle;
123        }
124
125        public int getMaximumLocalCombinations() {
126                return maximumLocalCombinations;
127        }
128
129        public void setMaximumLocalCombinations(int maximumLocalCombinations) {
130                this.maximumLocalCombinations = maximumLocalCombinations;
131        }
132
133        /**
134         * @return the localTimeLimit
135         */
136        public double getLocalTimeLimit() {
137                return localTimeLimit;
138        }
139
140        /**
141         * @param localTimeLimit
142         *            the localTimeLimit to set
143         */
144        public void setLocalTimeLimit(double localTimeLimit) {
145                this.localTimeLimit = localTimeLimit;
146        }
147
148        /**
149         * @return the localTimeStart
150         */
151        public double getLocalTimeStart() {
152                return localTimeStart;
153        }
154
155        /**
156         * @param localTimeStart
157         *            the time when local calculations started
158         */
159        public void useLocalTimeLimit(double localTimeStart) {
160                this.localTimeStart = localTimeStart;
161        }
162
163        /**
164         * @param combinations
165         *            a set of combinations considered fo far by the local
166         *            symmetry search
167         * @return true, if the number of combinations
168         */
169        public boolean isLocalLimitsExceeded(Set<?> combinations) {
170                if(combinations.size()>maximumLocalCombinations) {
171                        return true;
172                }
173                return isLocalLimitsExceeded();
174        }
175
176        public boolean isLocalLimitsExceeded() {
177                //use the time limit only if the start time was set
178                if (localTimeStart < 0) {
179                        return false;
180                }
181                double elapsedTime = (System.nanoTime() - localTimeStart) / 1000000000;
182                return elapsedTime > localTimeLimit;
183        }
184
185        /**
186         * On-the-fly Jmol bioassembly generation.
187         *
188         * @return true if Jmol on the fly bioassembly generation is used
189         */
190        public boolean isOnTheFly() {
191                return onTheFly;
192        }
193
194        /**
195         * On-the-fly Jmol bioassembly generation.
196         *
197         * @param useJmolBioAssemblies
198         *            true if Jmol on the fly bioassembly generation is used, false
199         *            otherwise
200         */
201        public void setOnTheFly(boolean useJmolBioAssemblies) {
202                this.onTheFly = useJmolBioAssemblies;
203        }
204
205        @Override
206        public String toString() {
207                return "QuatSymmetryParameters [rmsdThreshold=" + rmsdThreshold
208                                + ", angleThreshold=" + angleThreshold
209                                + ", helixRmsdThreshold=" + helixRmsdThreshold
210                                + ", helixRmsdToRiseRatio=" + helixRmsdToRiseRatio
211                                + ", minimumHelixRise=" + minimumHelixRise
212                                + ", minimumHelixAngle=" + minimumHelixAngle
213                                + ", maximumLocalCombinations=" + maximumLocalCombinations
214                                + ", localTimeStart=" + localTimeStart
215                                + ", localTimeLimit=" + localTimeLimit + ", onTheFly="
216                                + onTheFly + "]";
217        }
218
219}