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 Jan 27, 2010
021 * Author: Andreas Prlic
022 *
023 */
024
025package demo;
026
027import org.biojava.nbio.structure.*;
028import org.biojava.nbio.structure.align.util.AtomCache;
029import org.biojava.nbio.structure.io.FileParsingParameters;
030import org.biojava.nbio.structure.io.PDBFileReader;
031import org.biojava.nbio.core.util.InputStreamProvider;
032
033
034
035/** Example for how to load protein structures (from PDB files).
036 *
037 * @author Andreas Prlic
038 *
039 */
040public class DemoLoadStructure
041{
042
043        public static void main(String[] args){
044
045                DemoLoadStructure demo  = new DemoLoadStructure();
046
047                demo.loadStructureIO();
048
049                //demo.basicLoad();
050
051                //demo.loadStructureFromCache();
052        }
053
054        public void loadStructureIO(){
055                try {
056                        Structure s1 = StructureIO.getStructure("1gav");
057                        System.out.println(s1.getPDBCode() + " asym unit has nr atoms:");
058                        System.out.println(StructureTools.getNrAtoms(s1));
059
060
061                        Chain chain1 = s1.getChainByIndex(0);
062
063                        System.out.println("First chain: " + chain1);
064
065                        System.out.println("Chain " + chain1.getName() + " has the following sequence mismatches:");
066                        for (SeqMisMatch mm : chain1.getSeqMisMatches()){
067                                System.out.println(mm);
068                        }
069
070                        Structure s2 = StructureIO.getBiologicalAssembly("1gav");
071                        System.out.println(s2.getPDBCode() + " biological assembly has nr atoms:");
072                        System.out.println(StructureTools.getNrAtoms(s2));
073
074                } catch (Exception e){
075                        e.printStackTrace();
076                }
077
078        }
079
080
081        public void basicLoad(){
082                try {
083
084                        PDBFileReader reader = new PDBFileReader();
085
086                        // the path to the local PDB installation
087                        reader.setPath("/tmp");
088
089                        // configure the parameters of file parsing
090
091                        FileParsingParameters params = new FileParsingParameters();
092
093                        // should the ATOM and SEQRES residues be aligned when creating the internal data model?
094                        params.setAlignSeqRes(true);
095
096                        // should secondary structure get parsed from the file
097                        params.setParseSecStruc(false);
098
099                        reader.setFileParsingParameters(params);
100
101                        Structure structure = reader.getStructureById("4hhb");
102
103                        System.out.println(structure);
104
105                        Chain c = structure.getPolyChainByPDB("C");
106
107
108                        System.out.print(c);
109
110                        System.out.println(c.getEntityInfo());
111
112
113                } catch (Exception e){
114                        e.printStackTrace();
115                }
116
117        }
118
119        public void loadStructureFromCache(){
120                String pdbId = "4hhb";
121                String chainName = "4hhb.A";
122                String entityName = "4hhb:0";
123
124                // we can set a flag if the file should be cached in memory
125                // this will enhance IO massively if the same files have to be accessed over and over again.
126                // since this is a soft cache, no danger of memory leak
127                // this is actually not necessary to provide, since the default is "true" if the AtomCache is being used.
128                System.setProperty(InputStreamProvider.CACHE_PROPERTY, "true");
129
130                AtomCache cache = new AtomCache();
131
132                try {
133                        System.out.println("======================");
134                        Structure s = cache.getStructure(pdbId);
135
136                        System.out.println("Full Structure:" + s);
137
138                        Atom[] ca = cache.getAtoms(chainName);
139                        System.out.println("got " + ca.length + " CA atoms");
140
141                        Structure firstEntity = cache.getStructure(entityName);
142                        System.out.println("First entity: " + firstEntity);
143
144                } catch (Exception e){
145                        e.printStackTrace();
146                }
147
148        }
149
150
151}