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 demo;
022
023import org.biojava.nbio.structure.Structure;
024import org.biojava.nbio.structure.StructureException;
025import org.biojava.nbio.structure.align.util.AtomCache;
026import org.biojava.nbio.structure.cluster.SubunitClustererMethod;
027import org.biojava.nbio.structure.cluster.SubunitClustererParameters;
028import org.biojava.nbio.structure.gui.BiojavaJmol;
029import org.biojava.nbio.structure.symmetry.axis.AxisAligner;
030import org.biojava.nbio.structure.symmetry.core.QuatSymmetryDetector;
031import org.biojava.nbio.structure.symmetry.core.QuatSymmetryParameters;
032import org.biojava.nbio.structure.symmetry.core.QuatSymmetryResults;
033import org.biojava.nbio.structure.symmetry.jmolScript.JmolSymmetryScriptGenerator;
034import org.biojava.nbio.structure.symmetry.jmolScript.JmolSymmetryScriptGeneratorPointGroup;
035
036import java.io.IOException;
037import java.util.List;
038
039/**
040 * This demo shows how to display the {@link QuatSymmetryResults} of a
041 * structure.
042 * <p>
043 * Examples: 4HHB, 4AQ5, 1LTI, 1STP, 4F88, 2W6E, 2LXC, 3OE7, 4INU, 4D8s, 4EAR,
044 * 4IYQ, 3ZKR
045 * <p>
046 * Local symmetry: 2WPD (2 local symmetries), 4F88 (local C8), 1LTI (local C5),
047 * 2W6E (local C3), 2LXC (local C2), 3OE7 (local C3)
048 * <p>
049 * Local Pseudosymmetry: 3ZDY, 3ZDX
050 * <p>
051 * Helical: 1B47
052 * <p>
053 * With internal symmetry: 4E3E, 1VYM
054 *
055 * @author Peter Rose
056 * @author Aleix Lafita
057 *
058 */
059public class DemoQuatSymmetryJmol {
060
061        public static void main(String[] args) throws IOException,
062                        StructureException {
063
064                String name = "2vml";
065
066                // Download the biological assembly
067                AtomCache cache = new AtomCache();
068                cache.setUseMmCif(true);
069                Structure structure = cache.getStructure("BIO:" + name + ":1");
070
071                QuatSymmetryParameters sp = new QuatSymmetryParameters();
072                SubunitClustererParameters cp = new SubunitClustererParameters();
073                cp.setClustererMethod(SubunitClustererMethod.SEQUENCE); // normal
074                // cp.setClustererMethod(SubunitClustererMethod.STRUCTURE); // pseudo
075                cp.setSequenceCoverageThreshold(0.9);
076
077                // Calculate and display the global symmetry
078                QuatSymmetryResults globalSymmetry = QuatSymmetryDetector
079                                .calcGlobalSymmetry(structure, sp, cp);
080                showResults(structure, name, globalSymmetry);
081
082                // Calculate and displaythe local symmetry
083                List<QuatSymmetryResults> localSymmetry = QuatSymmetryDetector
084                                .calcLocalSymmetries(structure, sp, cp);
085
086                for (QuatSymmetryResults result : localSymmetry)
087                        showResults(structure, name, result);
088
089        }
090
091        private static void showResults(Structure s, String name,
092                        QuatSymmetryResults results) {
093
094                String title = name + ": " + results.getStoichiometry()
095                                + ", " + results.getSymmetry();
096
097                if (results.isPseudoStoichiometric())
098                        title += ", pseudosymmetric";
099
100                if (results.isLocal())
101                        title += ", local";
102
103                String script = "set defaultStructureDSSP true; set measurementUnits ANGSTROMS;  select all;  spacefill off; wireframe off; "
104                                + "backbone off; cartoon on; color cartoon structure; color structure;  select ligand;wireframe 0.16;spacefill 0.5; "
105                                + "color cpk ; select all; model 0;set antialiasDisplay true; autobond=false;save STATE state_1;";
106
107                AxisAligner aligner = AxisAligner.getInstance(results);
108
109                JmolSymmetryScriptGenerator scriptGenerator = JmolSymmetryScriptGeneratorPointGroup
110                                .getInstance(aligner, "g");
111
112                script += scriptGenerator.getOrientationWithZoom(0);
113                script += scriptGenerator.drawPolyhedron();
114                script += scriptGenerator.drawAxes();
115                script += scriptGenerator.colorBySymmetry();
116
117                title += ", method: " + results.getMethod();
118
119                script += "draw axes* on; draw poly* on;";
120
121                BiojavaJmol jmol = new BiojavaJmol();
122                jmol.setStructure(s);
123
124                jmol.setTitle(title);
125                jmol.evalString(script);
126
127        }
128}