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 */
021/**
022 *
023 */
024package org.biojava.nbio.structure.symmetry.jmolScript;
025
026import org.biojava.nbio.structure.symmetry.axis.RotationAxisAligner;
027import org.biojava.nbio.structure.symmetry.geometry.Prism;
028
029
030/**
031 * @author Peter
032 *
033 */
034public class JmolSymmetryScriptGeneratorDn extends JmolSymmetryScriptGeneratorPointGroup {
035
036        public JmolSymmetryScriptGeneratorDn(RotationAxisAligner axisTransformation, String name) {
037                super(axisTransformation, name);
038                int fold = axisTransformation.getRotationGroup().getRotation(0).getFold();
039
040                // special case for D2. Since there is no 2-fold prism, draw a 4-fold
041                // prism that encases the D2 structure
042                if (axisTransformation.getRotationGroup().getPointGroup().equals("D2")) {
043                        fold = 4;
044                }
045
046                Prism p = new Prism(fold);
047                p.setHeight(axisTransformation.getDimension().z*2);
048                p.setInscribedRadius(axisTransformation.getRadius());
049                setPolyhedron(p);
050        }
051
052        @Override
053        public int getZoom() {
054                // find maximum extension of structure
055                double maxExtension = getMaxExtension();
056                // find maximum extension of polyhedron
057                double polyhedronExtension = Math.max(getPolyhedron().getCirumscribedRadius(), getAxisTransformation().getDimension().z);
058
059                int zoom = Math.round((float)(maxExtension/polyhedronExtension * 110));
060                if (zoom > 100) {
061                        zoom = 100;
062                }
063                return zoom;
064        }
065
066        @Override
067        public int getOrientationCount() {
068                // for Dn point groups the last view is redundant due to symmetry.
069                return getPolyhedron().getViewCount()-1;
070        }
071
072        /**
073         * Returns the name of a specific orientation
074         * @param index orientation index
075         * @return name of orientation
076         */
077        @Override
078        public String getOrientationName(int index) {
079                if (index == 0 && getAxisTransformation().getRotationGroup().getPointGroup().equals("D2")) {
080                        return "Front C2 axis";
081                } else {
082                        return getPolyhedron().getViewName(index);
083                }
084        }
085}