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