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 * Created on Mar 11, 2010
021 * Author: Andreas Prlic
022 *
023 */
024
025package demo;
026
027
028import org.biojava.nbio.structure.Atom;
029import org.biojava.nbio.structure.Structure;
030import org.biojava.nbio.structure.StructureTools;
031import org.biojava.nbio.structure.align.StructureAlignment;
032import org.biojava.nbio.structure.align.StructureAlignmentFactory;
033import org.biojava.nbio.structure.align.fatcat.FatCatFlexible;
034import org.biojava.nbio.structure.align.gui.DisplayAFP;
035import org.biojava.nbio.structure.align.gui.StructureAlignmentDisplay;
036import org.biojava.nbio.structure.align.gui.jmol.StructureAlignmentJmol;
037import org.biojava.nbio.structure.align.model.AFPChain;
038import org.biojava.nbio.structure.align.model.AfpChainWriter;
039import org.biojava.nbio.structure.align.util.AtomCache;
040
041
042public class CookBook
043{
044
045
046        public static void main(String[] args){
047
048                String name1="1HNG.B";
049                String name2="1A64.A";
050
051
052                try {
053
054                        // for this example we are going to use the jFatCat-rigid algorithm
055                        StructureAlignment algorithm = StructureAlignmentFactory.getAlgorithm(FatCatFlexible.algorithmName);
056
057                        // the cache takes care of loading the structures
058                        // Downloads files to a temp dir by default
059                        AtomCache cache = new AtomCache();
060
061
062                        //////////////////////////////
063                        // no need to change anything below this line
064                        // ////////////////////////////
065
066                        // load the structures
067                        Structure structure1 = cache.getStructure(name1);
068                        Structure structure2 = cache.getStructure(name2);
069
070                        // we are only using the CA atoms in the structure for the alignment
071                        Atom[] ca1 = StructureTools.getAtomCAArray(structure1);
072                        Atom[] ca2 = StructureTools.getAtomCAArray(structure2);
073
074                        // do the actual alignment
075                        AFPChain afpChain = algorithm.align(ca1,ca2);
076
077                        // just name the two molecules
078                        afpChain.setName1(name1);
079                        afpChain.setName2(name2);
080
081                        // print and display results:
082
083
084                        // flexible original results:
085                        System.out.println(afpChain.toFatcat(ca1,ca2));
086
087                        // show the alignment in 3D in jmol
088                        StructureAlignmentJmol jmol= StructureAlignmentDisplay.display(afpChain, ca1, ca2);
089
090                        // set the display title for the frame
091                        jmol.setTitle(algorithm.getAlgorithmName() + " : " + name1 + " vs. " + name2);
092
093                        // here we open up the alignment - text panel that can interact with the 3D jmol display.
094                        DisplayAFP.showAlignmentPanel(afpChain, ca1,ca2,jmol);
095
096                        // we can print an XML version
097                        //System.out.println(AFPChainXMLConverter.toXML(afpChain, ca1, ca2));
098
099                        // or print the same output as original FATCAT
100                        System.out.println(AfpChainWriter.toFatCat(afpChain, ca1, ca2));
101
102
103
104
105
106                } catch (Exception e){
107                        e.printStackTrace();
108                }
109        }
110}