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.CifFileReader;
030import org.biojava.nbio.structure.io.StructureProvider;
031import org.biojava.nbio.structure.io.StructureFiletype;
032
033import java.util.List;
034
035/** An example of how to read MMcif files
036 *
037 * @author Andreas Prlic
038 *
039 */
040public class DemoMMCIFReader
041{
042
043        public static void main(String[] args){
044
045                DemoMMCIFReader demo = new DemoMMCIFReader();
046
047                demo.loadSimple();
048
049                demo.loadFromDirectAccess();
050
051        }
052
053        /**
054         * A basic example how to load an mmCif file and get a Structure object
055         *
056         */
057        public void loadSimple(){
058                String pdbId = "4hhb";
059
060                AtomCache cache = new AtomCache();
061                cache.setFiletype(StructureFiletype.CIF);
062
063                StructureIO.setAtomCache(cache);
064                try {
065                        Structure s = StructureIO.getStructure(pdbId);
066                        System.out.println(pdbId + " has nr atoms: " + StructureTools.getNrAtoms(s));
067                } catch (Exception e){
068                        e.printStackTrace();
069                }
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 CifFileReader();
082
083                try {
084                        Structure s = pdbreader.getStructureById(pdbId);
085
086                        System.out.println("Getting chain H of 1A4W");
087
088                        List<Chain> hs = s.getNonPolyChainsByPDB("H");
089
090                        Chain h = hs.get(0);
091                        List<Group> ligands = h.getAtomGroups();
092
093                        System.out.println("These ligands have been found in chain " + h.getName());
094
095                        for (Group l:ligands){
096                                System.out.println(l);
097                        }
098
099                        System.out.println("Accessing QWE directly: ");
100                        Group qwe = s.getNonPolyChainsByPDB("H").get(2).getGroupByPDB(new ResidueNumber("H",373,null));
101
102                        System.out.println(qwe.getChemComp());
103
104                        System.out.println(h.getSeqResSequence());
105                        System.out.println(h.getAtomSequence());
106                        System.out.println(h.getAtomGroups(GroupType.HETATM));
107
108                        System.out.println("Entities: " + s.getEntityInfos());
109
110                } catch (Exception e) {
111                        e.printStackTrace();
112                }
113
114
115        }
116}