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 May 17, 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.MMCIFFileReader; 030import org.biojava.nbio.structure.io.StructureProvider; 031 032import java.util.List; 033 034/** An example of how to read MMcif files 035 * 036 * @author Andreas Prlic 037 * 038 */ 039public class DemoMMCIFReader 040{ 041 042 public static void main(String[] args){ 043 044 DemoMMCIFReader demo = new DemoMMCIFReader(); 045 046 demo.loadSimple(); 047 048 //demo.loadFromDirectAccess(); 049 050 } 051 052 /** A basic example how to load an mmCif file and get a Structure object 053 * 054 */ 055 public void loadSimple(){ 056 String pdbId = "4hhb"; 057 058 AtomCache cache = new AtomCache(); 059 cache.setUseMmCif(true); 060 061 StructureIO.setAtomCache(cache); 062 063 try { 064 Structure s = StructureIO.getStructure(pdbId); 065 066 System.out.println(pdbId + " has nr atoms: " + StructureTools.getNrAtoms(s)); 067 068 } catch (Exception e){ 069 e.printStackTrace(); 070 } 071 } 072 073 074 /** An example demonstrating how to directly use the mmCif file parsing classes. This could potentially be used 075 * to use the parser to populate a data-structure that is different from the biojava-structure data model. 076 * 077 */ 078 public void loadFromDirectAccess(){ 079 String pdbId = "1A4W"; 080 081 StructureProvider pdbreader = new MMCIFFileReader(); 082 083 try { 084 Structure s = pdbreader.getStructureById(pdbId); 085 086 Chain h = s.getChainByPDB("H"); 087 088 List<Group> ligands = h.getAtomLigands(); 089 090 System.out.println("These ligands have been found in chain " + h.getChainID()); 091 092 for (Group l:ligands){ 093 System.out.println(l); 094 } 095 096 System.out.println("Accessing QWE directly: "); 097 Group qwe = h.getGroupByPDB(new ResidueNumber("H",373,null)); 098 099 System.out.println(qwe.getChemComp()); 100 101 System.out.println(h.getSeqResSequence()); 102 System.out.println(h.getAtomSequence()); 103 System.out.println(h.getAtomGroups(GroupType.HETATM)); 104 105 System.out.println("Compounds: " + s.getCompounds()); 106 107 } catch (Exception e) { 108 e.printStackTrace(); 109 } 110 111 112 } 113}