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 org.biojava.nbio.structure.align.gui; 022 023import org.biojava.nbio.structure.Structure; 024import org.biojava.nbio.structure.StructureIO; 025import org.biojava.nbio.structure.StructureImpl; 026import org.biojava.nbio.structure.StructureTools; 027import org.biojava.nbio.structure.align.gui.jmol.StructureAlignmentJmol; 028import org.biojava.nbio.structure.align.util.AtomCache; 029import org.biojava.nbio.structure.align.util.UserConfiguration; 030import org.biojava.nbio.structure.quaternary.BioAssemblyTools; 031 032import javax.swing.*; 033import java.awt.*; 034 035public class StructureLoaderThread extends SwingWorker<String, Object> { 036 037 String name; 038 boolean showBiolAssembly; 039 040 UserConfiguration config; 041 042 StructureLoaderThread(UserConfiguration config, String name, boolean showBiolAssembly){ 043 this.name = name; 044 this.showBiolAssembly = showBiolAssembly; 045 046 this.config = config; 047 } 048 049 @Override 050 protected String doInBackground() { 051 052 System.out.println("loading " + name ); 053 054 AtomCache cache = new AtomCache(config.getPdbFilePath(),config.getCacheFilePath()); 055 Structure s = null; 056 try { 057 if ( showBiolAssembly) { 058 s= StructureIO.getBiologicalAssembly(name); 059 060 int atomCount = StructureTools.getNrAtoms(s); 061 062 if ( atomCount > 200000){ 063 // uh oh, we are probably going to exceed 512 MB usage... 064 // scale down to something smaller 065 System.err.println("Structure very large. Reducing display to C alpha atoms only"); 066 s = BioAssemblyTools.getReducedStructure(s); 067 } 068 069 } else { 070 s = cache.getStructure(name); 071 } 072 073 System.out.println("done loading structure..."); 074 075 076 StructureAlignmentJmol jmol = new StructureAlignmentJmol(); 077 jmol.setStructure(s); 078 079 jmol.evalString("set antialiasDisplay on; select all;spacefill off; wireframe off; backbone off; cartoon;color cartoon chain; select ligand;wireframe 0.16;spacefill 0.5; select all; color cartoon structure;"); 080 jmol.evalString("save STATE state_1"); 081 082 083 084 } catch (Exception e){ 085 e.printStackTrace(); 086 087 JOptionPane.showMessageDialog(null, "Error while loading " + name + ":" + e.getMessage()); 088 089 s = new StructureImpl(); 090 } 091 hideProgressBar(); 092 return "Done."; 093 094 } 095 096 public static void showProgressBar() { 097 098 if ( progressFrame == null){ 099 100 SwingUtilities.invokeLater(new Runnable() { 101 102 @Override 103 public void run() { 104 // TODO Auto-generated method stub 105 106 107 final JFrame frame = new JFrame("Loading ..."); 108 final JProgressBar progressBar = new JProgressBar(); 109 110 progressBar.setIndeterminate(true); 111 112 final JPanel contentPane = new JPanel(); 113 contentPane.setBorder(BorderFactory.createEmptyBorder(10,10,10,10)); 114 contentPane.setLayout(new BorderLayout()); 115 contentPane.add(new JLabel("Loading ..."), BorderLayout.NORTH); 116 contentPane.add(progressBar, BorderLayout.CENTER); 117 frame.setContentPane(contentPane); 118 frame.pack(); 119 frame.setLocationRelativeTo(null); 120 progressFrame = frame; 121 frame.setVisible(true); 122 } 123 }); 124 125 } 126 127 128 } 129 130 static JFrame progressFrame = null; 131 private void hideProgressBar() { 132 133 SwingUtilities.invokeLater(new Runnable() { 134 135 @Override 136 public void run() { 137 if ( progressFrame != null){ 138 progressFrame.dispose(); 139 progressFrame = null; 140 } 141 } 142 }); 143 144 } 145}