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        /** 
053         * A basic example how to load an mmCif file and get a Structure object
054         *
055         */
056        public void loadSimple(){
057                String pdbId = "4hhb";
058
059                AtomCache cache = new AtomCache();
060                cache.setUseMmCif(true);
061
062                StructureIO.setAtomCache(cache);
063
064                try {
065                        Structure s = StructureIO.getStructure(pdbId);
066
067                        System.out.println(pdbId + " has nr atoms: " + StructureTools.getNrAtoms(s));
068
069                } catch (Exception e){
070                        e.printStackTrace();
071                }
072        }
073
074
075        /**
076         * An example demonstrating how to directly use the mmCif file parsing classes. This could potentially be used
077         * to use the parser to populate a data-structure that is different from the biojava-structure data model.
078         *
079         */
080        public void loadFromDirectAccess(){
081                String pdbId = "1A4W";
082
083                StructureProvider pdbreader = new MMCIFFileReader();
084
085                try {
086                        Structure s = pdbreader.getStructureById(pdbId);
087                        
088                        System.out.println("Getting chain H of 1A4W");
089
090                        List<Chain> hs = s.getNonPolyChainsByPDB("H");
091
092                        Chain h = hs.get(0);
093                        List<Group> ligands = h.getAtomGroups();
094
095                        System.out.println("These ligands have been found in chain " + h.getName());
096
097                        for (Group l:ligands){
098                                System.out.println(l);
099                        }
100
101                        System.out.println("Accessing QWE directly: ");
102                        Group qwe = s.getNonPolyChainsByPDB("H").get(2).getGroupByPDB(new ResidueNumber("H",373,null));
103
104                        System.out.println(qwe.getChemComp());
105
106                        System.out.println(h.getSeqResSequence());
107                        System.out.println(h.getAtomSequence());
108                        System.out.println(h.getAtomGroups(GroupType.HETATM));
109
110                        System.out.println("Entities: " + s.getEntityInfos());
111
112                } catch (Exception e) {
113                        e.printStackTrace();
114                }
115
116
117        }
118}