001package demo;
002
003import org.biojava.nbio.structure.Structure;
004import org.biojava.nbio.structure.StructureTools;
005import org.biojava.nbio.structure.align.util.AtomCache;
006import org.biojava.nbio.structure.io.FileParsingParameters;
007import org.biojava.nbio.structure.StructureIO;
008
009/*
010 *                    BioJava development code
011 *
012 * This code may be freely distributed and modified under the
013 * terms of the GNU Lesser General Public Licence.  This should
014 * be distributed with the code.  If you do not have a copy,
015 * see:
016 *
017 *      http://www.gnu.org/copyleft/lesser.html
018 *
019 * Copyright for this code is held jointly by the individual
020 * authors.  These should be listed in @author doc comments.
021 *
022 * For more information on the BioJava project and its aims,
023 * or to join the biojava-l mailing list, visit the home page
024 * at:
025 *
026 *      http://www.biojava.org/
027 *
028 * created at Sep 19, 2013
029 * Author: Andreas Prlic
030 */
031
032public class DemoShowLargeAssembly {
033
034        public static void main(String[] args){
035
036                // This loads the PBCV-1 virus capsid, one of, if not the biggest biological assembly in terms on nr. of atoms.
037                // The 1m4x.pdb1.gz file has 313 MB (compressed)
038                // This Structure requires a minimum of 9 GB of memory to be able to be loaded in memory.
039
040                String pdbId = "1M4X";
041
042                Structure bigStructure = readStructure(pdbId,1);
043
044                // let's take a look how much memory this consumes currently
045
046                Runtime r = Runtime.getRuntime();
047
048                // let's try to trigger the Java Garbage collector
049                r.gc();
050
051                System.out.println("Memory consumption after " + pdbId +
052                                " structure has been loaded into memory:");
053
054                String mem = String.format("Total %dMB, Used %dMB, Free %dMB, Max %dMB",
055                                r.totalMemory() / 1048576,
056                                (r.totalMemory() - r.freeMemory()) / 1048576,
057                                r.freeMemory() / 1048576,
058                                r.maxMemory() / 1048576);
059
060                System.out.println(mem);
061
062                // 9693 atoms in the asymmetric unit * 1680 copies per assembly = 16284240 atoms
063                System.out.println("# atoms: " + StructureTools.getNrAtoms(bigStructure));
064
065        }
066        /** Load a specific biological assembly for a PDB entry
067         *
068         * @param pdbId .. the PDB ID
069         * @param bioAssemblyId .. the first assembly has the bioAssemblyId 1
070         * @return a Structure object or null if something went wrong.
071         */
072        public static Structure  readStructure(String pdbId, int bioAssemblyId) {
073
074                // pre-computed files use lower case PDB IDs
075                pdbId = pdbId.toLowerCase();
076
077                // we just need this to track where to store PDB files
078                // this checks the PDB_DIR property (and uses a tmp location if not set)
079                AtomCache cache = new AtomCache();
080                cache.setUseMmCif(true);
081                FileParsingParameters p = cache.getFileParsingParams();
082
083                // some bio assemblies are large, we want an all atom representation and avoid
084                // switching to a Calpha-only representation for large molecules
085                // note, this requires several GB of memory for some of the largest assemblies, such a 1MX4
086                p.setAtomCaThreshold(Integer.MAX_VALUE);
087
088                // parse remark 350
089                p.setParseBioAssembly(true);
090
091                // download missing files
092
093                Structure structure = null;
094                try {
095                        structure = StructureIO.getBiologicalAssembly(pdbId,bioAssemblyId);
096                } catch (Exception e){
097                        e.printStackTrace();
098                        return null;
099                }
100                return structure;
101        }
102}