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 */
021package demo;
022
023
024
025import org.biojava.nbio.structure.Structure;
026import org.biojava.nbio.structure.StructureException;
027import org.biojava.nbio.structure.io.StructureFiletype;
028import org.biojava.nbio.structure.StructureIO;
029import org.biojava.nbio.structure.align.util.AtomCache;
030import org.biojava.nbio.structure.asa.AsaCalculator;
031import org.biojava.nbio.structure.asa.GroupAsa;
032
033import java.io.IOException;
034
035public class DemoAsa {
036
037        private static final boolean hetAtoms = false;
038
039        public static void main(String[] args) throws IOException, StructureException {
040
041                String pdbCode = args[0];
042                int numThreads = Integer.parseInt(args[1]);
043
044                demoAsa(pdbCode, numThreads);
045        }
046
047        private static void demoAsa(String pdbCode, int numThreads) throws IOException, StructureException {
048
049                AtomCache cache = new AtomCache();
050                cache.setFiletype(StructureFiletype.CIF);
051
052                StructureIO.setAtomCache(cache);
053
054                Structure structure = StructureIO.getStructure(pdbCode);
055
056                long start = System.currentTimeMillis();
057
058                AsaCalculator asaCalc = new AsaCalculator(structure,
059                                AsaCalculator.DEFAULT_PROBE_SIZE,
060                                1000, numThreads, hetAtoms);
061
062                GroupAsa[] groupAsas = asaCalc.getGroupAsas();
063
064                long end = System.currentTimeMillis();
065
066
067                double tot = 0;
068
069
070
071                for (GroupAsa groupAsa: groupAsas) {
072                        System.out.printf("%1s\t%5s\t%3s\t%6.2f\n",
073                                        groupAsa.getGroup().getChainId(),
074                                        groupAsa.getGroup().getResidueNumber(),
075                                        groupAsa.getGroup().getPDBName(),
076                                        groupAsa.getAsaU());
077                        tot+=groupAsa.getAsaU();
078                }
079
080
081                System.out.printf("Total area: %9.2f\n",tot);
082                System.out.printf("Time: %4.1fs\n",((end-start)/1000.0));
083
084
085                System.out.println("Testing scaling: ");
086                double[] runTimes = new double[numThreads];
087                for (int nThreads=1;nThreads<=numThreads;nThreads++) {
088                        start = System.currentTimeMillis();
089
090                        asaCalc = new AsaCalculator(structure,
091                                        AsaCalculator.DEFAULT_PROBE_SIZE,
092                                        1000, numThreads, hetAtoms);
093
094                        // only calculating all atom ASAs without keeping the returned value
095                        asaCalc.calculateAsas();
096
097                        end = System.currentTimeMillis();
098                        runTimes[nThreads-1] = (end-start)/1000.0;
099
100                }
101                for (int nThreads=1;nThreads<=numThreads;nThreads++) {
102                        System.out.printf(nThreads+" threads, time: %4.1fs -- x%2.1f\n",runTimes[nThreads-1],runTimes[0]/runTimes[nThreads-1]);
103                }
104
105
106        }
107
108
109}