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