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