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.Atom;
024import org.biojava.nbio.structure.StructureException;
025import org.biojava.nbio.structure.align.StructureAlignment;
026import org.biojava.nbio.structure.align.StructureAlignmentFactory;
027import org.biojava.nbio.structure.align.ce.CeMain;
028import org.biojava.nbio.structure.align.gui.jmol.StructureAlignmentJmol;
029import org.biojava.nbio.structure.align.model.AFPChain;
030import org.biojava.nbio.structure.align.util.AtomCache;
031import org.biojava.nbio.structure.align.util.RotationAxis;
032import org.biojava.nbio.structure.jama.Matrix;
033
034import java.io.IOException;
035
036/**
037 * A demo for how to use {@link RotationAxis} to display the rotation for an
038 * alignment. This is particularly useful for symmetric alignments, eg between
039 * several chains of a symmetric or pseudo-symmetric complex.
040 *
041 * @author Spencer Bliven
042 *
043 */
044public final class DemoRotationAxis {
045
046        public static void main(String[] args) {
047
048                // Compare two chains of a dimer to force CE to give a symmetric alignment.
049                String name1 = "1AVD.A";
050                String name2 = "1AVD.B";
051                String display = "1AVD";
052
053                //              name1 = "4HHB.A:,B:";
054                //              name2 = "4HHB.C:,D:";
055                //              display = "4HHB";
056
057                AtomCache cache = new AtomCache();
058                try {
059                        // Get the structures
060                        Atom[] ca1 = cache.getAtoms(name1);
061                        Atom[] ca2 = cache.getAtoms(name2);
062                        Atom[] caD = cache.getAtoms(display);
063
064                        // Perform the alignment
065                        StructureAlignment ce = StructureAlignmentFactory.getAlgorithm(CeMain.algorithmName);
066                        AFPChain afpChain = ce.align(ca1, ca2);
067
068                        // Calculate the axis of rotation
069                        Matrix mat = afpChain.getBlockRotationMatrix()[0];
070                        Atom shift = afpChain.getBlockShiftVector()[0];
071                        RotationAxis axis = new RotationAxis(mat,shift);
072
073                        // Print the angle of rotation
074                        double theta = Math.toDegrees(axis.getAngle());
075                        System.out.format("Angle: %f degrees%n",theta);
076
077                        // Display the alignment with Jmol
078                        StructureAlignmentJmol jmolPanel = new StructureAlignmentJmol();
079                        jmolPanel.setAtoms(caD);
080
081                        // Set some standard protein display properties
082                        jmolPanel.evalString("select * ; color chain;");
083                        jmolPanel.evalString("select nucleic; cartoon on;");
084                        jmolPanel.evalString("select *; spacefill off; wireframe off; cartoon on;  ");
085
086                        // draw axis
087                        String jmolString = axis.getJmolScript(caD);
088                        jmolPanel.evalString(jmolString);
089
090
091
092                        /*
093                        // draw intermediate vectors for debugging
094                        double width = .5;
095                        Atom s = axis.getRotationPos();
096                        Atom u = axis.getRotationAxis();
097                        jmolPanel.evalString(String.format("draw ID s VECTOR {0,0,0} {%f,%f,%f} WIDTH %f COLOR orange \">s\";",
098                                        s.getX(),s.getY(),s.getZ(), width ));
099
100                        Atom perp = axis.getOtherTranslation();
101                        Atom screw = axis.getScrewTranslation();
102
103                        double uScale = 10;
104                        jmolPanel.evalString(String.format("draw ID u VECTOR {0,0,0} {%f,%f,%f} WIDTH %f COLOR orange \">u\";",
105                                        uScale*u.getX(),uScale*u.getY(),uScale*u.getZ(), width ));
106
107                        jmolPanel.evalString(String.format("draw ID perp VECTOR {0,0,0} {%f,%f,%f} WIDTH %f COLOR yellow \">tPerp\";",
108                                        perp.getX(),perp.getY(),perp.getZ(), width));
109                        jmolPanel.evalString(String.format("draw ID screw VECTOR {0,0,0} {%f,%f,%f} WIDTH %f COLOR yellow \">screw\";",
110                                        screw.getX(),screw.getY(),screw.getZ(), width));
111
112                        jmolPanel.evalString(String.format("draw ID t VECTOR {0,0,0} {%f,%f,%f} WIDTH %f COLOR yellow \">t\";",
113                                        shift.getX(),shift.getY(),shift.getZ(), width));
114
115                        // draw coordinate axes
116                        jmolPanel.evalString("draw ID x VECTOR {0,0,0} {5,0,0} WIDTH 0.5 COLOR red \">x\";");
117                        jmolPanel.evalString("draw ID y VECTOR {0,0,0} {0,5,0} WIDTH 0.5 COLOR green \">y\";");
118                        jmolPanel.evalString("draw ID z VECTOR {0,0,0} {0,0,5} WIDTH 0.5 COLOR blue \">z\";");
119                        */
120
121                } catch (IOException e) {
122                        e.printStackTrace();
123                } catch (StructureException e) {
124                        e.printStackTrace();
125                }
126        }
127}