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
023
024import org.biojava.nbio.structure.Structure;
025import org.biojava.nbio.structure.align.util.AtomCache;
026import org.biojava.nbio.structure.io.FileParsingParameters;
027import org.biojava.nbio.structure.StructureIO;
028
029
030/** Example of how to load PDB files using the AtomCache class.
031 *
032 * @author Andreas Prlic
033 *
034 */
035public class DemoAtomCache {
036        public static void main(String[] args){
037                demoAtomCache();
038                demoStructureIO();
039
040        }
041
042        @SuppressWarnings("unused")
043        private static void demoStructureIO()  {
044
045
046                try {
047                        Structure s1 = StructureIO.getStructure("4hhb");
048
049                        Structure bioAssembly = StructureIO.getBiologicalAssembly("1stp",1);
050
051                        // do something with them...
052                } catch (Exception e){
053                        e.printStackTrace();
054                }
055
056        }
057
058        private static void demoAtomCache() {
059                AtomCache cache = new AtomCache();
060
061                FileParsingParameters params = cache.getFileParsingParams();
062
063                params.setAlignSeqRes(true);
064                params.setHeaderOnly(false);
065                params.setParseCAOnly(false);
066                params.setParseSecStruc(false);
067
068                String[] pdbIDs = new String[]{"4hhb", "1cdg","5pti","1gav", "WRONGID" };
069
070                for (String pdbID : pdbIDs){
071
072                        try {
073                                Structure s = cache.getStructure(pdbID);
074                                if ( s == null) {
075                                        System.out.println("could not find structure " + pdbID);
076                                        continue;
077                                }
078                                // do something with the structure
079                                System.out.println(s);
080
081                        } catch (Exception e){
082                                // something crazy happened...
083                                System.err.println("Can't load structure " + pdbID + " reason: " + e.getMessage());
084                                //e.printStackTrace();
085                        }
086                }
087
088        }
089}