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 Nov 5, 2009
021 * Author: Andreas Prlic
022 *
023 */
024
025package org.biojava.nbio.structure.align.gui;
026
027
028import org.biojava.nbio.structure.Structure;
029import org.biojava.nbio.structure.align.MultiThreadedDBSearch;
030import org.biojava.nbio.structure.align.StructureAlignment;
031import org.biojava.nbio.structure.align.util.AtomCache;
032import org.biojava.nbio.structure.align.util.UserConfiguration;
033import org.biojava.nbio.structure.scop.ScopFactory;
034
035import java.io.File;
036import java.util.concurrent.atomic.AtomicBoolean;
037//import org.slf4j.Logger;
038//import org.slf4j.LoggerFactory;
039
040public class AlignmentCalcDB implements AlignmentCalculationRunnable {
041
042
043        public static String SCOP_VERSION =  "1.75";
044
045        //private static final Logger logger = LoggerFactory.getLogger(AlignmentCalcDB.class);
046
047        AtomicBoolean interrupted ;
048
049
050        String name1;
051
052        Structure structure1;
053
054        AlignmentGui parent;
055
056        UserConfiguration config;
057
058
059        String outFile;
060
061        int nrCPUs;
062        Boolean domainSplit ;
063
064        StructureAlignment customAlgorithm;
065
066        MultiThreadedDBSearch job = null;
067
068        public StructureAlignment getAlgorithm() {
069                return customAlgorithm;
070        }
071
072        public void setAlgorithm(StructureAlignment algo) {
073                this.customAlgorithm = algo;
074        }
075
076        public AlignmentCalcDB(AlignmentGui parent, Structure s1,  String name1, UserConfiguration config,String outFile, Boolean domainSplit) {
077
078                this.parent= parent;
079
080                structure1 = s1;
081
082                this.name1 = name1;
083
084                this.config = config;
085                //this.representatives = representatives;
086                interrupted = new AtomicBoolean(false);
087                this.outFile = outFile;
088                this.domainSplit = domainSplit;
089
090                System.out.println("AlignmentCalcDB: Using SCOP version " + SCOP_VERSION);
091                ScopFactory.setScopDatabase(SCOP_VERSION);
092
093        }
094
095
096
097        @Override
098        public void run() {
099
100                StructureAlignment algorithm = null;
101
102                if ( parent != null )
103                        algorithm = parent.getStructureAlignment();
104                else {
105                        algorithm = customAlgorithm;
106                }
107
108
109                if ( name1.startsWith("file:/"))
110                        name1= "CUSTOM";
111
112                job = new MultiThreadedDBSearch(name1,structure1, outFile, algorithm, nrCPUs, domainSplit);
113
114                AtomCache cache = new AtomCache(config);
115                System.out.println("using cache: " + cache.getPath());
116                System.out.println("name1: " + name1);
117                System.out.println("structure:" + structure1.getName());
118                job.setAtomCache(cache);
119
120                if ( name1.equals("CUSTOM")) {
121                        job.setCustomFile1(parent.getDBSearch().getPDBUploadPanel().getFilePath1());
122                        job.setCustomChain1(parent.getDBSearch().getPDBUploadPanel().getChain1());
123                }
124
125                job.run();
126
127                File resultList = job.getResultFile();
128                //              if ((now-startTime)/1000 > 30) {
129
130
131                //              try {
132                //                      out.flush();
133                //                      out.close();
134                //              } catch (Exception e) {
135                //                      e.printStackTrace();
136                //              }
137                if ( parent != null ) {
138                        parent.notifyCalcFinished();
139                        if ( resultList != null) {
140                                DBResultTable table = new DBResultTable();
141                                table.show(resultList,config);
142                        }
143                }
144
145        }
146
147
148
149
150
151        /** stops what is currently happening and does not continue
152         *
153         *
154         */
155        @Override
156        public void interrupt() {
157                interrupted.set(true);
158                if ( job != null)
159                        job.interrupt();
160
161
162
163        }
164
165        @Override
166        public void cleanup()
167        {
168                parent.notifyCalcFinished();
169
170                parent=null;
171                // cleanup...
172
173                structure1 = null;
174                config = null;
175
176                if ( job != null)
177                        job.cleanup();
178
179        }
180
181        @Override
182        public void setNrCPUs(int useNrCPUs) {
183                nrCPUs = useNrCPUs;
184
185        }
186
187        public synchronized boolean isInterrupted() {
188                return interrupted.get();
189        }
190
191
192
193
194
195}