2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
24 import java.awt.event.ActionEvent;
25 import java.awt.event.ActionListener;
26 import java.awt.event.ItemEvent;
28 import java.io.IOException;
29 import java.util.ArrayList;
30 import java.util.Collection;
31 import java.util.HashSet;
32 import java.util.LinkedHashSet;
33 import java.util.List;
34 import java.util.Locale;
35 import java.util.concurrent.Callable;
36 import java.util.concurrent.Executors;
38 import javax.swing.JCheckBox;
39 import javax.swing.JComboBox;
40 import javax.swing.JLabel;
41 import javax.swing.JMenuItem;
42 import javax.swing.JPopupMenu;
43 import javax.swing.JTable;
44 import javax.swing.SwingUtilities;
45 import javax.swing.table.AbstractTableModel;
47 import org.json.simple.parser.ParseException;
49 import jalview.api.structures.JalviewStructureDisplayI;
50 import jalview.bin.Cache;
51 import jalview.bin.Console;
52 import jalview.bin.Jalview;
53 import jalview.datamodel.AlignmentI;
54 import jalview.datamodel.PDBEntry;
55 import jalview.datamodel.SequenceI;
56 import jalview.fts.api.FTSData;
57 import jalview.fts.api.FTSDataColumnI;
58 import jalview.fts.api.FTSRestClientI;
59 import jalview.fts.core.FTSDataColumnPreferences;
60 import jalview.fts.core.FTSRestRequest;
61 import jalview.fts.core.FTSRestResponse;
62 import jalview.fts.service.pdb.PDBFTSRestClient;
63 import jalview.fts.service.threedbeacons.TDB_FTSData;
64 import jalview.gui.structurechooser.PDBStructureChooserQuerySource;
65 import jalview.gui.structurechooser.StructureChooserQuerySource;
66 import jalview.gui.structurechooser.ThreeDBStructureChooserQuerySource;
67 import jalview.io.DataSourceType;
68 import jalview.io.JalviewFileChooser;
69 import jalview.io.JalviewFileView;
70 import jalview.io.StructureFile;
71 import jalview.jbgui.FilterOption;
72 import jalview.jbgui.GStructureChooser;
73 import jalview.structure.StructureImportSettings.TFType;
74 import jalview.structure.StructureMapping;
75 import jalview.structure.StructureSelectionManager;
76 import jalview.util.MessageManager;
77 import jalview.util.Platform;
78 import jalview.util.StringUtils;
79 import jalview.ws.DBRefFetcher;
80 import jalview.ws.DBRefFetcher.FetchFinishedListenerI;
81 import jalview.ws.dbsources.EBIAlfaFold;
82 import jalview.ws.seqfetcher.DbSourceProxy;
83 import jalview.ws.sifts.SiftsSettings;
86 * Provides the behaviors for the Structure chooser Panel
91 @SuppressWarnings("serial")
92 public class StructureChooser extends GStructureChooser
93 implements IProgressIndicator
95 private static final String AUTOSUPERIMPOSE = "AUTOSUPERIMPOSE";
98 * warn user if need to fetch more than this many uniprot records at once
100 private static final int THRESHOLD_WARN_UNIPROT_FETCH_NEEDED = 20;
102 private SequenceI selectedSequence;
104 private SequenceI[] selectedSequences;
106 private IProgressIndicator progressIndicator;
108 private Collection<FTSData> discoveredStructuresSet;
110 private StructureChooserQuerySource data;
113 protected FTSDataColumnPreferences getFTSDocFieldPrefs()
115 return data.getDocFieldPrefs();
118 private String selectedPdbFileName;
120 private TFType localPdbTempfacType;
122 private String localPdbPaeMatrixFileName;
124 private boolean isValidPBDEntry;
126 private boolean cachedPDBExists;
128 private Collection<FTSData> lastDiscoveredStructuresSet;
130 private boolean canQueryTDB = false;
132 private boolean notQueriedTDBYet = true;
134 List<SequenceI> seqsWithoutSourceDBRef = null;
136 private boolean showChooserGUI = true;
138 private static StructureViewer lastTargetedView = null;
140 public StructureChooser(SequenceI[] selectedSeqs, SequenceI selectedSeq,
143 this(selectedSeqs, selectedSeq, ap, true);
146 public StructureChooser(SequenceI[] selectedSeqs, SequenceI selectedSeq,
147 AlignmentPanel ap, boolean showGUI)
149 // which FTS engine to use
150 data = StructureChooserQuerySource.getQuerySourceFor(selectedSeqs);
154 this.selectedSequence = selectedSeq;
155 this.selectedSequences = selectedSeqs;
156 this.progressIndicator = (ap == null) ? null : ap.alignFrame;
157 this.showChooserGUI = showGUI;
163 * sets canQueryTDB if protein sequences without a canonical uniprot ref or at
164 * least one structure are discovered.
166 private void populateSeqsWithoutSourceDBRef()
168 seqsWithoutSourceDBRef = new ArrayList<SequenceI>();
169 boolean needCanonical = false;
170 for (SequenceI seq : selectedSequences)
174 int dbRef = ThreeDBStructureChooserQuerySource
175 .checkUniprotRefs(seq.getDBRefs());
180 // need to retrieve canonicals
181 needCanonical = true;
182 seqsWithoutSourceDBRef.add(seq);
186 // could be a sequence with pdb ref
187 if (seq.getAllPDBEntries() == null
188 || seq.getAllPDBEntries().size() == 0)
190 seqsWithoutSourceDBRef.add(seq);
196 // retrieve database refs for protein sequences
197 if (!seqsWithoutSourceDBRef.isEmpty())
202 // triggers display of the 'Query TDB' button
203 notQueriedTDBYet = true;
209 * Initializes parameters used by the Structure Chooser Panel
211 protected void init()
213 if (!Jalview.isHeadlessMode())
215 progressBar = new ProgressBar(this.statusPanel, this.statusBar);
218 chk_superpose.setSelected(Cache.getDefault(AUTOSUPERIMPOSE, true));
219 btn_queryTDB.addActionListener(new ActionListener()
223 public void actionPerformed(ActionEvent e)
225 promptForTDBFetch(false);
229 Executors.defaultThreadFactory().newThread(new Runnable()
234 populateSeqsWithoutSourceDBRef();
235 initialStructureDiscovery();
243 private void initialStructureDiscovery()
245 // check which FTS engine to use
246 data = StructureChooserQuerySource.getQuerySourceFor(selectedSequences);
248 // ensure a filter option is in force for search
249 populateFilterComboBox(true, cachedPDBExists);
251 // looks for any existing structures already loaded
252 // for the sequences (the cached ones)
253 // then queries the StructureChooserQuerySource to
254 // discover more structures.
256 // Possible optimisation is to only begin querying
257 // the structure chooser if there are no cached structures.
259 long startTime = System.currentTimeMillis();
260 updateProgressIndicator(
261 MessageManager.getString("status.loading_cached_pdb_entries"),
263 loadLocalCachedPDBEntries();
264 updateProgressIndicator(null, startTime);
265 updateProgressIndicator(
266 MessageManager.getString("status.searching_for_pdb_structures"),
268 fetchStructuresMetaData();
269 // revise filter options if no results were found
270 populateFilterComboBox(isStructuresDiscovered(), cachedPDBExists);
271 discoverStructureViews();
272 updateProgressIndicator(null, startTime);
273 mainFrame.setVisible(showChooserGUI);
278 * raises dialog for Uniprot fetch followed by 3D beacons search
281 * - when true, don't ask, just fetch
283 public void promptForTDBFetch(boolean ignoreGui)
285 final long progressId = System.currentTimeMillis();
287 // final action after prompting and discovering db refs
288 final Runnable strucDiscovery = new Runnable()
293 mainFrame.setEnabled(false);
294 cmb_filterOption.setEnabled(false);
295 progressBar.setProgressBar(
296 MessageManager.getString("status.searching_3d_beacons"),
298 btn_queryTDB.setEnabled(false);
299 // TODO: warn if no accessions discovered
300 populateSeqsWithoutSourceDBRef();
301 // redo initial discovery - this time with 3d beacons
303 previousWantedFields = null;
304 lastSelected = (FilterOption) cmb_filterOption.getSelectedItem();
305 cmb_filterOption.setSelectedItem(null);
306 cachedPDBExists = false; // reset to initial
307 initialStructureDiscovery();
308 if (!isStructuresDiscovered())
310 progressBar.setProgressBar(MessageManager.getString(
311 "status.no_structures_discovered_from_3d_beacons"),
313 btn_queryTDB.setToolTipText(MessageManager.getString(
314 "status.no_structures_discovered_from_3d_beacons"));
315 btn_queryTDB.setEnabled(false);
316 pnl_queryTDB.setVisible(false);
320 cmb_filterOption.setSelectedIndex(0); // select 'best'
321 btn_queryTDB.setVisible(false);
322 pnl_queryTDB.setVisible(false);
323 progressBar.setProgressBar(null, progressId);
325 mainFrame.setEnabled(true);
326 cmb_filterOption.setEnabled(true);
330 final FetchFinishedListenerI afterDbRefFetch = new FetchFinishedListenerI()
334 public void finished()
336 // filter has been selected, so we set flag to remove ourselves
337 notQueriedTDBYet = false;
338 // new thread to discover structures - via 3d beacons
339 Executors.defaultThreadFactory().newThread(strucDiscovery).start();
344 // fetch db refs if OK pressed
345 final Callable discoverCanonicalDBrefs = () -> {
346 btn_queryTDB.setEnabled(false);
347 populateSeqsWithoutSourceDBRef();
349 final int y = seqsWithoutSourceDBRef.size();
352 final SequenceI[] seqWithoutSrcDBRef = seqsWithoutSourceDBRef
353 .toArray(new SequenceI[y]);
354 DBRefFetcher dbRefFetcher = new DBRefFetcher(seqWithoutSrcDBRef,
355 progressBar, new DbSourceProxy[]
356 { new jalview.ws.dbsources.Uniprot() }, null, false);
357 dbRefFetcher.addListener(afterDbRefFetch);
358 // ideally this would also gracefully run with callbacks
360 dbRefFetcher.fetchDBRefs(true);
364 // call finished action directly
365 afterDbRefFetch.finished();
369 final Callable revertview = () -> {
370 if (lastSelected != null)
372 cmb_filterOption.setSelectedItem(lastSelected);
376 int threshold = Cache.getDefault("UNIPROT_AUTOFETCH_THRESHOLD",
377 THRESHOLD_WARN_UNIPROT_FETCH_NEEDED);
378 Console.debug("Using Uniprot fetch threshold of " + threshold);
379 if (ignoreGui || seqsWithoutSourceDBRef.size() < threshold)
381 Executors.newSingleThreadExecutor().submit(discoverCanonicalDBrefs);
384 // need cancel and no to result in the discoverPDB action - mocked is
385 // 'cancel' TODO: mock should be OK
387 StructureChooser thisSC = this;
388 JvOptionPane.newOptionDialog(thisSC.getFrame())
389 .setResponseHandler(JvOptionPane.OK_OPTION,
390 discoverCanonicalDBrefs)
391 .setResponseHandler(JvOptionPane.CANCEL_OPTION, revertview)
392 .setResponseHandler(JvOptionPane.NO_OPTION, revertview)
394 MessageManager.formatMessage(
395 "label.fetch_references_for_3dbeacons",
396 seqsWithoutSourceDBRef.size()),
397 MessageManager.getString("label.3dbeacons"),
398 JvOptionPane.YES_NO_OPTION, JvOptionPane.PLAIN_MESSAGE,
400 { MessageManager.getString("action.ok"),
401 MessageManager.getString("action.cancel") },
402 MessageManager.getString("action.ok"), false);
406 * Builds a drop-down choice list of existing structure viewers to which new
407 * structures may be added. If this list is empty then it, and the 'Add'
408 * button, are hidden.
410 private void discoverStructureViews()
412 if (Desktop.instance != null)
414 targetView.removeAllItems();
415 if (lastTargetedView != null && !lastTargetedView.isVisible())
417 lastTargetedView = null;
419 int linkedViewsAt = 0;
420 for (StructureViewerBase view : Desktop.instance
421 .getStructureViewers(null, null))
423 StructureViewer viewHandler = (lastTargetedView != null
424 && lastTargetedView.sview == view) ? lastTargetedView
425 : StructureViewer.reconfigure(view);
427 if (view.isLinkedWith(ap))
429 targetView.insertItemAt(viewHandler, linkedViewsAt++);
433 targetView.addItem(viewHandler);
438 * show option to Add to viewer if at least 1 viewer found
440 targetView.setVisible(false);
441 if (targetView.getItemCount() > 0)
443 targetView.setVisible(true);
444 if (lastTargetedView != null)
446 targetView.setSelectedItem(lastTargetedView);
450 targetView.setSelectedIndex(0);
453 btn_add.setVisible(targetView.isVisible());
458 * Updates the progress indicator with the specified message
461 * displayed message for the operation
463 * unique handle for this indicator
465 protected void updateProgressIndicator(String message, long id)
467 if (progressIndicator != null)
469 progressIndicator.setProgressBar(message, id);
474 * Retrieve meta-data for all the structure(s) for a given sequence(s) in a
477 void fetchStructuresMetaData()
479 long startTime = System.currentTimeMillis();
480 Collection<FTSDataColumnI> wantedFields = data.getDocFieldPrefs()
481 .getStructureSummaryFields();
483 discoveredStructuresSet = new LinkedHashSet<>();
484 HashSet<String> errors = new HashSet<>();
486 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
489 for (SequenceI seq : selectedSequences)
492 FTSRestResponse resultList;
495 resultList = data.fetchStructuresMetaData(seq, wantedFields,
496 selectedFilterOpt, !chk_invertFilter.isSelected());
497 // null response means the FTSengine didn't yield a query for this
498 // consider designing a special exception if we really wanted to be
500 if (resultList == null)
504 } catch (Exception e)
507 errors.add(e.getMessage());
510 if (resultList.getSearchSummary() != null
511 && !resultList.getSearchSummary().isEmpty())
513 discoveredStructuresSet.addAll(resultList.getSearchSummary());
517 int noOfStructuresFound = 0;
518 String totalTime = (System.currentTimeMillis() - startTime)
520 if (discoveredStructuresSet != null
521 && !discoveredStructuresSet.isEmpty())
524 .setModel(data.getTableModel(discoveredStructuresSet));
526 noOfStructuresFound = discoveredStructuresSet.size();
527 lastDiscoveredStructuresSet = discoveredStructuresSet;
528 mainFrame.setTitle(MessageManager.formatMessage(
529 "label.structure_chooser_no_of_structures",
530 noOfStructuresFound, totalTime));
534 mainFrame.setTitle(MessageManager
535 .getString("label.structure_chooser_manual_association"));
536 if (errors.size() > 0)
538 StringBuilder errorMsg = new StringBuilder();
539 for (String error : errors)
541 errorMsg.append(error).append("\n");
543 JvOptionPane.showMessageDialog(this, errorMsg.toString(),
544 MessageManager.getString("label.pdb_web-service_error"),
545 JvOptionPane.ERROR_MESSAGE);
550 protected void loadLocalCachedPDBEntries()
552 ArrayList<CachedPDB> entries = new ArrayList<>();
553 for (SequenceI seq : selectedSequences)
555 if (seq.getDatasetSequence() != null
556 && seq.getDatasetSequence().getAllPDBEntries() != null)
558 for (PDBEntry pdbEntry : seq.getDatasetSequence()
561 if (pdbEntry.getFile() != null)
563 entries.add(new CachedPDB(seq, pdbEntry));
568 cachedPDBExists = !entries.isEmpty();
569 PDBEntryTableModel tableModelx = new PDBEntryTableModel(entries);
570 tbl_local_pdb.setModel(tableModelx);
574 * Filters a given list of discovered structures based on supplied argument
576 * @param fieldToFilterBy
577 * the field to filter by
579 void filterResultSet(final String fieldToFilterBy)
581 Thread filterThread = new Thread(new Runnable()
587 long startTime = System.currentTimeMillis();
588 lbl_loading.setVisible(true);
589 Collection<FTSDataColumnI> wantedFields = data.getDocFieldPrefs()
590 .getStructureSummaryFields();
591 Collection<FTSData> filteredResponse = new HashSet<>();
592 HashSet<String> errors = new HashSet<>();
594 for (SequenceI seq : selectedSequences)
597 FTSRestResponse resultList;
600 resultList = data.selectFirstRankedQuery(seq,
601 discoveredStructuresSet, wantedFields, fieldToFilterBy,
602 !chk_invertFilter.isSelected());
604 } catch (Exception e)
607 errors.add(e.getMessage());
610 if (resultList.getSearchSummary() != null
611 && !resultList.getSearchSummary().isEmpty())
613 filteredResponse.addAll(resultList.getSearchSummary());
617 String totalTime = (System.currentTimeMillis() - startTime)
619 if (!filteredResponse.isEmpty())
621 final int filterResponseCount = filteredResponse.size();
622 Collection<FTSData> reorderedStructuresSet = new LinkedHashSet<>();
623 reorderedStructuresSet.addAll(filteredResponse);
624 reorderedStructuresSet.addAll(discoveredStructuresSet);
626 .setModel(data.getTableModel(reorderedStructuresSet));
628 FTSRestResponse.configureTableColumn(getResultTable(),
629 wantedFields, tempUserPrefs);
630 getResultTable().getColumn("Ref Sequence").setPreferredWidth(120);
631 getResultTable().getColumn("Ref Sequence").setMinWidth(100);
632 getResultTable().getColumn("Ref Sequence").setMaxWidth(200);
633 // Update table selection model here
634 getResultTable().addRowSelectionInterval(0,
635 filterResponseCount - 1);
636 mainFrame.setTitle(MessageManager.formatMessage(
637 "label.structure_chooser_filter_time", totalTime));
641 mainFrame.setTitle(MessageManager.formatMessage(
642 "label.structure_chooser_filter_time", totalTime));
643 if (errors.size() > 0)
645 StringBuilder errorMsg = new StringBuilder();
646 for (String error : errors)
648 errorMsg.append(error).append("\n");
650 JvOptionPane.showMessageDialog(null, errorMsg.toString(),
651 MessageManager.getString("label.pdb_web-service_error"),
652 JvOptionPane.ERROR_MESSAGE);
656 lbl_loading.setVisible(false);
658 validateSelections();
661 filterThread.start();
665 * Handles action event for btn_pdbFromFile
668 protected void pdbFromFile_actionPerformed()
670 // TODO: JAL-3048 not needed for Jalview-JS until JSmol dep and
673 JalviewFileChooser chooser = new JalviewFileChooser(
674 Cache.getProperty("LAST_DIRECTORY"));
675 chooser.setFileView(new JalviewFileView());
676 chooser.setDialogTitle(
677 MessageManager.formatMessage("label.select_pdb_file_for",
678 selectedSequence.getDisplayId(false)));
679 chooser.setToolTipText(MessageManager.formatMessage(
680 "label.load_pdb_file_associate_with_sequence",
681 selectedSequence.getDisplayId(false)));
683 int value = chooser.showOpenDialog(null);
684 if (value == JalviewFileChooser.APPROVE_OPTION)
686 selectedPdbFileName = chooser.getSelectedFile().getPath();
687 Cache.setProperty("LAST_DIRECTORY", selectedPdbFileName);
688 boolean guessTFType = localPdbPaeMatrixFileName == null;
689 localPdbPaeMatrixFileName = guessPAEFilename();
690 guessTFType |= localPdbPaeMatrixFileName != null;
692 && new File(selectedPdbFileName).getName().startsWith("AF-")
693 && !tempFacAsChanged)
695 // localPdbPaeMatrixFileName was null and now isn't and filename could
696 // well be AlphaFold and user hasn't adjusted the tempFacType
697 combo_tempFacAs.setSelectedItem(TFType.PLDDT);
699 validateSelections();
704 * Handles action event for btn_pdbFromFile
707 protected void paeMatrixFile_actionPerformed()
709 File pdbFile = new File(selectedPdbFileName);
710 String setFile = Cache.getProperty("LAST_DIRECTORY");
711 if (localPdbPaeMatrixFileName != null)
713 File paeFile = new File(localPdbPaeMatrixFileName);
714 if (paeFile.exists())
715 setFile = paeFile.getAbsolutePath();
716 else if (paeFile.getParentFile().exists())
717 setFile = paeFile.getParentFile().getAbsolutePath();
721 String guess = guessPAEFilename();
725 JalviewFileChooser chooser = new JalviewFileChooser(setFile);
726 chooser.setFileView(new JalviewFileView());
727 chooser.setDialogTitle(MessageManager.formatMessage(
728 "label.select_pae_matrix_file_for", pdbFile.getName()));
729 chooser.setToolTipText(MessageManager.formatMessage(
730 "label.load_pae_matrix_file_associate_with_structure",
733 int value = chooser.showOpenDialog(null);
734 if (value == JalviewFileChooser.APPROVE_OPTION)
736 localPdbPaeMatrixFileName = chooser.getSelectedFile().getPath();
737 Cache.setProperty("LAST_DIRECTORY", localPdbPaeMatrixFileName);
739 validateAssociationFromFile();
742 private String guessPAEFilename()
744 if (selectedPdbFileName.toLowerCase(Locale.ROOT).endsWith(".pdb")
745 || selectedPdbFileName.toLowerCase(Locale.ROOT)
748 String jsonExt = selectedPdbFileName.substring(0,
749 selectedPdbFileName.length() - 4) + ".json";
750 // AlphaFold naming scheme
751 String guessFile1 = StringUtils.replaceLast(jsonExt, "model",
752 "predicted_aligned_error");
753 // nf-core mode naming scheme
754 String guessFile2 = StringUtils.replaceLast(jsonExt, ".json",
756 if (new File(guessFile1).exists())
760 else if (new File(jsonExt).exists())
764 else if (new File(guessFile2).exists())
773 * Populates the filter combo-box options dynamically depending on discovered
776 protected void populateFilterComboBox(boolean haveData,
777 boolean cachedPDBExist)
779 populateFilterComboBox(haveData, cachedPDBExist, null);
783 * Populates the filter combo-box options dynamically depending on discovered
786 protected void populateFilterComboBox(boolean haveData,
787 boolean cachedPDBExist, FilterOption lastSel)
791 * temporarily suspend the change listener behaviour
793 cmb_filterOption.removeItemListener(this);
795 cmb_filterOption.removeAllItems();
798 List<FilterOption> filters = data
799 .getAvailableFilterOptions(VIEWS_FILTER);
800 data.updateAvailableFilterOptions(VIEWS_FILTER, filters,
801 lastDiscoveredStructuresSet);
803 for (FilterOption filter : filters)
805 if (lastSel != null && filter.equals(lastSel))
810 cmb_filterOption.addItem(filter);
814 cmb_filterOption.addItem(
815 new FilterOption(MessageManager.getString("label.enter_pdb_id"),
816 "-", VIEWS_ENTER_ID, false, null));
817 cmb_filterOption.addItem(
818 new FilterOption(MessageManager.getString("label.from_file"),
819 "-", VIEWS_FROM_FILE, false, null));
820 if (canQueryTDB && notQueriedTDBYet)
822 btn_queryTDB.setVisible(true);
823 pnl_queryTDB.setVisible(true);
828 FilterOption cachedOption = new FilterOption(
829 MessageManager.getString("label.cached_structures"), "-",
830 VIEWS_LOCAL_PDB, false, null);
831 cmb_filterOption.addItem(cachedOption);
834 cmb_filterOption.setSelectedItem(cachedOption);
839 cmb_filterOption.setSelectedIndex(selSet);
841 cmb_filterOption.addItemListener(this);
845 * Updates the displayed view based on the selected filter option
847 protected void updateCurrentView()
849 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
852 if (lastSelected == selectedFilterOpt)
854 // don't need to do anything, probably
857 // otherwise, record selection
858 // and update the layout and dialog accordingly
859 lastSelected = selectedFilterOpt;
861 layout_switchableViews.show(pnl_switchableViews,
862 selectedFilterOpt.getView());
863 String filterTitle = mainFrame.getTitle();
864 mainFrame.setTitle(frameTitle);
865 chk_invertFilter.setVisible(false);
867 if (selectedFilterOpt.getView() == VIEWS_FILTER)
869 mainFrame.setTitle(filterTitle);
870 // TDB Query has no invert as yet
871 chk_invertFilter.setVisible(selectedFilterOpt
872 .getQuerySource() instanceof PDBStructureChooserQuerySource);
874 if (data != selectedFilterOpt.getQuerySource()
875 || data.needsRefetch(selectedFilterOpt))
877 data = selectedFilterOpt.getQuerySource();
878 // rebuild the views completely, since prefs will also change
884 filterResultSet(selectedFilterOpt.getValue());
887 else if (selectedFilterOpt.getView() == VIEWS_ENTER_ID
888 || selectedFilterOpt.getView() == VIEWS_FROM_FILE)
890 mainFrame.setTitle(MessageManager
891 .getString("label.structure_chooser_manual_association"));
892 idInputAssSeqPanel.loadCmbAssSeq();
893 fileChooserAssSeqPanel.loadCmbAssSeq();
895 validateSelections();
899 * Validates user selection and enables the 'Add' and 'New View' buttons if
900 * all parameters are correct (the Add button will only be visible if there is
901 * at least one existing structure viewer open). This basically means at least
902 * one structure selected and no error messages.
904 * The 'Superpose Structures' option is enabled if either more than one
905 * structure is selected, or the 'Add' to existing view option is enabled, and
906 * disabled if the only option is to open a new view of a single structure.
909 protected void validateSelections()
911 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
913 btn_add.setEnabled(false);
914 String currentView = selectedFilterOpt.getView();
915 int selectedCount = 0;
916 if (currentView == VIEWS_FILTER)
918 selectedCount = getResultTable().getSelectedRows().length;
919 if (selectedCount > 0)
921 btn_add.setEnabled(true);
924 else if (currentView == VIEWS_LOCAL_PDB)
926 selectedCount = tbl_local_pdb.getSelectedRows().length;
927 if (selectedCount > 0)
929 btn_add.setEnabled(true);
932 else if (currentView == VIEWS_ENTER_ID)
934 validateAssociationEnterPdb();
936 else if (currentView == VIEWS_FROM_FILE)
938 validateAssociationFromFile();
941 btn_newView.setEnabled(btn_add.isEnabled());
944 * enable 'Superpose' option if more than one structure is selected,
945 * or there are view(s) available to add structure(s) to
948 .setEnabled(selectedCount > 1 || targetView.getItemCount() > 0);
952 protected boolean showPopupFor(int selectedRow, int x, int y)
954 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
956 String currentView = selectedFilterOpt.getView();
958 if (currentView == VIEWS_FILTER
959 && data instanceof ThreeDBStructureChooserQuerySource)
962 TDB_FTSData row = ((ThreeDBStructureChooserQuerySource) data)
963 .getFTSDataFor(getResultTable(), selectedRow,
964 discoveredStructuresSet);
965 String pageUrl = row.getModelViewUrl();
966 JPopupMenu popup = new JPopupMenu("3D Beacons");
967 JMenuItem viewUrl = new JMenuItem("View model web page");
968 viewUrl.addActionListener(new ActionListener()
971 public void actionPerformed(ActionEvent e)
973 Desktop.showUrl(pageUrl);
977 SwingUtilities.invokeLater(new Runnable()
982 popup.show(getResultTable(), x, y);
987 // event not handled by us
992 * Validates inputs from the Manual PDB entry panel
994 protected void validateAssociationEnterPdb()
996 AssociateSeqOptions assSeqOpt = (AssociateSeqOptions) idInputAssSeqPanel
997 .getCmb_assSeq().getSelectedItem();
998 lbl_pdbManualFetchStatus.setIcon(errorImage);
999 lbl_pdbManualFetchStatus.setToolTipText("");
1000 if (txt_search.getText().length() > 0)
1002 lbl_pdbManualFetchStatus.setToolTipText(JvSwingUtils.wrapTooltip(true,
1003 MessageManager.formatMessage("info.no_pdb_entry_found_for",
1004 txt_search.getText())));
1007 if (errorWarning.length() > 0)
1009 lbl_pdbManualFetchStatus.setIcon(warningImage);
1010 lbl_pdbManualFetchStatus.setToolTipText(
1011 JvSwingUtils.wrapTooltip(true, errorWarning.toString()));
1014 if (selectedSequences.length == 1 || !assSeqOpt.getName()
1015 .equalsIgnoreCase("-Select Associated Seq-"))
1017 txt_search.setEnabled(true);
1018 if (isValidPBDEntry)
1020 btn_add.setEnabled(true);
1021 lbl_pdbManualFetchStatus.setToolTipText("");
1022 lbl_pdbManualFetchStatus.setIcon(goodImage);
1027 txt_search.setEnabled(false);
1028 lbl_pdbManualFetchStatus.setIcon(errorImage);
1033 * Validates inputs for the manual PDB file selection options
1035 protected void validateAssociationFromFile()
1037 AssociateSeqOptions assSeqOpt = (AssociateSeqOptions) fileChooserAssSeqPanel
1038 .getCmb_assSeq().getSelectedItem();
1039 // lbl_fromFileStatus.setIcon(errorImage);
1040 String pdbFileString = "";
1041 String pdbFileTooltip = "";
1042 if (selectedSequences.length == 1 || (assSeqOpt != null && !assSeqOpt
1043 .getName().equalsIgnoreCase("-Select Associated Seq-")))
1045 btn_pdbFromFile.setEnabled(true);
1046 if (selectedPdbFileName != null && selectedPdbFileName.length() > 0)
1048 btn_add.setEnabled(true);
1049 // lbl_fromFileStatus.setIcon(goodImage);
1050 pdbFileString = new File(selectedPdbFileName).getName();
1051 pdbFileTooltip = new File(selectedPdbFileName).getAbsolutePath();
1052 setPdbOptionsEnabled(true);
1056 pdbFileString = MessageManager.getString("label.none");
1057 pdbFileTooltip = MessageManager.getString("label.nothing_selected");
1062 btn_pdbFromFile.setEnabled(false);
1063 // lbl_fromFileStatus.setIcon(errorImage);
1064 pdbFileString = MessageManager.getString("label.none");
1065 pdbFileTooltip = MessageManager.getString("label.nothing_selected");
1067 lbl_pdbFile.setText(pdbFileString);
1068 lbl_pdbFile.setToolTipText(pdbFileTooltip);
1071 String paeFileString = "";
1072 String paeFileTooltip = "";
1073 if (localPdbPaeMatrixFileName != null
1074 && localPdbPaeMatrixFileName.length() > 0)
1076 paeFileString = new File(localPdbPaeMatrixFileName).getName();
1077 paeFileTooltip = new File(localPdbPaeMatrixFileName)
1082 paeFileString = MessageManager.getString("label.none");
1083 paeFileTooltip = MessageManager.getString("label.nothing_selected");
1085 lbl_paeFile.setText(paeFileString);
1086 lbl_paeFile.setToolTipText(paeFileTooltip);
1090 protected void cmbAssSeqStateChanged()
1092 validateSelections();
1095 private FilterOption lastSelected = null;
1098 * Handles the state change event for the 'filter' combo-box and 'invert'
1102 protected void stateChanged(ItemEvent e)
1104 if (e.getSource() instanceof JCheckBox)
1106 updateCurrentView();
1110 if (e.getStateChange() == ItemEvent.SELECTED)
1112 updateCurrentView();
1119 * select structures for viewing by their PDB IDs
1122 * @return true if structures were found and marked as selected
1124 public boolean selectStructure(String... pdbids)
1126 boolean found = false;
1128 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
1129 .getSelectedItem());
1130 String currentView = selectedFilterOpt.getView();
1131 JTable restable = (currentView == VIEWS_FILTER) ? getResultTable()
1132 : (currentView == VIEWS_LOCAL_PDB) ? tbl_local_pdb : null;
1134 if (restable == null)
1136 // can't select (enter PDB ID, or load file - need to also select which
1137 // sequence to associate with)
1141 int pdbIdColIndex = restable.getColumn("PDB Id").getModelIndex();
1142 for (int r = 0; r < restable.getRowCount(); r++)
1144 for (int p = 0; p < pdbids.length; p++)
1146 if (String.valueOf(restable.getValueAt(r, pdbIdColIndex))
1147 .equalsIgnoreCase(pdbids[p]))
1149 restable.setRowSelectionInterval(r, r);
1158 * Handles the 'New View' action
1161 protected void newView_ActionPerformed()
1163 targetView.setSelectedItem(null);
1164 showStructures(false);
1168 * Handles the 'Add to existing viewer' action
1171 protected void add_ActionPerformed()
1173 showStructures(false);
1177 * structure viewer opened by this dialog, or null
1179 private StructureViewer sViewer = null;
1181 public void showStructures(boolean waitUntilFinished)
1184 final StructureSelectionManager ssm = ap.getStructureSelectionManager();
1186 final int preferredHeight = pnl_filter.getHeight();
1188 Runnable viewStruc = new Runnable()
1193 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
1194 .getSelectedItem());
1195 String currentView = selectedFilterOpt.getView();
1196 JTable restable = (currentView == VIEWS_FILTER) ? getResultTable()
1199 if (currentView == VIEWS_FILTER)
1201 int[] selectedRows = restable.getSelectedRows();
1202 PDBEntry[] pdbEntriesToView = new PDBEntry[selectedRows.length];
1203 List<SequenceI> selectedSeqsToView = new ArrayList<>();
1204 pdbEntriesToView = data.collectSelectedRows(restable,
1205 selectedRows, selectedSeqsToView);
1207 SequenceI[] selectedSeqs = selectedSeqsToView
1208 .toArray(new SequenceI[selectedSeqsToView.size()]);
1209 sViewer = launchStructureViewer(ssm, pdbEntriesToView, ap,
1212 else if (currentView == VIEWS_LOCAL_PDB)
1214 int[] selectedRows = tbl_local_pdb.getSelectedRows();
1215 PDBEntry[] pdbEntriesToView = new PDBEntry[selectedRows.length];
1217 int pdbIdColIndex = tbl_local_pdb.getColumn("PDB Id")
1219 int refSeqColIndex = tbl_local_pdb.getColumn("Ref Sequence")
1221 List<SequenceI> selectedSeqsToView = new ArrayList<>();
1222 for (int row : selectedRows)
1224 PDBEntry pdbEntry = ((PDBEntryTableModel) tbl_local_pdb
1225 .getModel()).getPDBEntryAt(row).getPdbEntry();
1227 pdbEntriesToView[count++] = pdbEntry;
1228 SequenceI selectedSeq = (SequenceI) tbl_local_pdb
1229 .getValueAt(row, refSeqColIndex);
1230 selectedSeqsToView.add(selectedSeq);
1232 SequenceI[] selectedSeqs = selectedSeqsToView
1233 .toArray(new SequenceI[selectedSeqsToView.size()]);
1234 sViewer = launchStructureViewer(ssm, pdbEntriesToView, ap,
1237 else if (currentView == VIEWS_ENTER_ID)
1239 SequenceI userSelectedSeq = ((AssociateSeqOptions) idInputAssSeqPanel
1240 .getCmb_assSeq().getSelectedItem()).getSequence();
1241 if (userSelectedSeq != null)
1243 selectedSequence = userSelectedSeq;
1245 String pdbIdStr = txt_search.getText();
1246 PDBEntry pdbEntry = selectedSequence.getPDBEntry(pdbIdStr);
1247 if (pdbEntry == null)
1249 pdbEntry = new PDBEntry();
1250 if (pdbIdStr.split(":").length > 1)
1252 pdbEntry.setId(pdbIdStr.split(":")[0]);
1253 pdbEntry.setChainCode(
1254 pdbIdStr.split(":")[1].toUpperCase(Locale.ROOT));
1258 pdbEntry.setId(pdbIdStr);
1260 pdbEntry.setType(PDBEntry.Type.PDB);
1261 selectedSequence.getDatasetSequence().addPDBId(pdbEntry);
1264 PDBEntry[] pdbEntriesToView = new PDBEntry[] { pdbEntry };
1265 sViewer = launchStructureViewer(ssm, pdbEntriesToView, ap,
1267 { selectedSequence });
1269 else if (currentView == VIEWS_FROM_FILE)
1272 // TEMPFAC NOT WORKING
1273 TFType tft = (TFType) StructureChooser.this.combo_tempFacAs
1275 if (tft != null && tft != TFType.DEFAULT)
1277 ssm.setAddTempFacAnnot(true);
1280 AssociateSeqOptions assSeqOpt = (AssociateSeqOptions) fileChooserAssSeqPanel
1281 .getCmb_assSeq().getSelectedItem();
1283 SequenceI userSelectedSeq = assSeqOpt.getSequence();
1284 if (userSelectedSeq != null)
1286 selectedSequence = userSelectedSeq;
1288 PDBEntry fileEntry = new AssociatePdbFileWithSeq()
1289 .associatePdbWithSeq(selectedPdbFileName,
1290 DataSourceType.FILE, selectedSequence, true,
1293 List<SequenceI> seqList = new ArrayList<>();
1294 seqList.add(selectedSequence);
1295 SequenceI[] seqArray = new SequenceI[] { selectedSequence };
1296 StructureFile sf = ssm.computeMapping(true, seqArray, null,
1297 selectedPdbFileName, DataSourceType.FILE, null);
1298 // EBIAlfaFold.addAlphaFoldPAEToStructure(pdbAlignment, pae, index,
1299 // structIdOrFile, isStructId);
1300 StructureMapping[] sm = ssm.getMapping(fileEntry.getFile());
1301 // DO SOMETHING WITH
1302 String paeFilename = StructureChooser.this.localPdbPaeMatrixFileName;
1303 File paeFile = paeFilename == null ? null : new File(paeFilename);
1304 if (paeFilename != null && paeFile.exists())
1306 AlignmentI al = StructureChooser.this.ap.getAlignment();
1309 EBIAlfaFold.importPaeJSONAsContactMatrixToSequence(al,
1310 paeFile, -1, selectedSequence.getName());
1311 } catch (IOException | ParseException e)
1313 // TODO Auto-generated catch block
1314 e.printStackTrace();
1318 sViewer = launchStructureViewer(ssm, new PDBEntry[] { fileEntry },
1320 { selectedSequence });
1322 SwingUtilities.invokeLater(new Runnable()
1327 closeAction(preferredHeight);
1328 mainFrame.dispose();
1333 Thread runner = new Thread(viewStruc);
1335 if (waitUntilFinished)
1337 while (sViewer == null ? runner.isAlive()
1338 : (sViewer.sview == null ? true
1339 : !sViewer.sview.hasMapping()))
1344 } catch (InterruptedException ie)
1353 * Answers a structure viewer (new or existing) configured to superimpose
1354 * added structures or not according to the user's choice
1359 StructureViewer getTargetedStructureViewer(StructureSelectionManager ssm)
1361 Object sv = targetView.getSelectedItem();
1363 return sv == null ? new StructureViewer(ssm) : (StructureViewer) sv;
1367 * Adds PDB structures to a new or existing structure viewer
1370 * @param pdbEntriesToView
1375 private StructureViewer launchStructureViewer(
1376 StructureSelectionManager ssm, final PDBEntry[] pdbEntriesToView,
1377 final AlignmentPanel alignPanel, SequenceI[] sequences)
1379 long progressId = sequences.hashCode();
1380 setProgressBar(MessageManager
1381 .getString("status.launching_3d_structure_viewer"), progressId);
1382 final StructureViewer theViewer = getTargetedStructureViewer(ssm);
1383 boolean superimpose = chk_superpose.isSelected();
1384 theViewer.setSuperpose(superimpose);
1387 * remember user's choice of superimpose or not
1389 Cache.setProperty(AUTOSUPERIMPOSE,
1390 Boolean.valueOf(superimpose).toString());
1392 setProgressBar(null, progressId);
1393 if (SiftsSettings.isMapWithSifts())
1395 List<SequenceI> seqsWithoutSourceDBRef = new ArrayList<>();
1397 // TODO: skip PDBEntry:Sequence pairs where PDBEntry doesn't look like a
1398 // real PDB ID. For moment, we can also safely do this if there is already
1399 // a known mapping between the PDBEntry and the sequence.
1400 for (SequenceI seq : sequences)
1402 PDBEntry pdbe = pdbEntriesToView[p++];
1403 if (pdbe != null && pdbe.getFile() != null)
1405 StructureMapping[] smm = ssm.getMapping(pdbe.getFile());
1406 if (smm != null && smm.length > 0)
1408 for (StructureMapping sm : smm)
1410 if (sm.getSequence() == seq)
1417 if (seq.getPrimaryDBRefs().isEmpty())
1419 seqsWithoutSourceDBRef.add(seq);
1423 if (!seqsWithoutSourceDBRef.isEmpty())
1425 int y = seqsWithoutSourceDBRef.size();
1426 setProgressBar(MessageManager.formatMessage(
1427 "status.fetching_dbrefs_for_sequences_without_valid_refs",
1429 SequenceI[] seqWithoutSrcDBRef = seqsWithoutSourceDBRef
1430 .toArray(new SequenceI[y]);
1431 DBRefFetcher dbRefFetcher = new DBRefFetcher(seqWithoutSrcDBRef);
1432 dbRefFetcher.fetchDBRefs(true);
1434 setProgressBar("Fetch complete.", progressId); // todo i18n
1437 if (pdbEntriesToView.length > 1)
1440 MessageManager.getString(
1441 "status.fetching_3d_structures_for_selected_entries"),
1443 theViewer.viewStructures(pdbEntriesToView, sequences, alignPanel);
1447 setProgressBar(MessageManager.formatMessage(
1448 "status.fetching_3d_structures_for",
1449 pdbEntriesToView[0].getId()), progressId);
1450 theViewer.viewStructures(pdbEntriesToView[0], sequences, alignPanel);
1452 setProgressBar(null, progressId);
1453 // remember the last viewer we used...
1454 lastTargetedView = theViewer;
1459 * Populates the combo-box used in associating manually fetched structures to
1460 * a unique sequence when more than one sequence selection is made.
1463 protected void populateCmbAssociateSeqOptions(
1464 JComboBox<AssociateSeqOptions> cmb_assSeq,
1465 JLabel lbl_associateSeq)
1467 cmb_assSeq.removeAllItems();
1469 new AssociateSeqOptions("-Select Associated Seq-", null));
1470 lbl_associateSeq.setVisible(false);
1471 if (selectedSequences.length > 1)
1473 for (SequenceI seq : selectedSequences)
1475 cmb_assSeq.addItem(new AssociateSeqOptions(seq));
1480 String seqName = selectedSequence.getDisplayId(false);
1481 seqName = seqName.length() <= 40 ? seqName : seqName.substring(0, 39);
1482 lbl_associateSeq.setText(seqName);
1483 lbl_associateSeq.setVisible(true);
1484 cmb_assSeq.setVisible(false);
1488 protected boolean isStructuresDiscovered()
1490 return discoveredStructuresSet != null
1491 && !discoveredStructuresSet.isEmpty();
1494 protected int PDB_ID_MIN = 3;// or: (Jalview.isJS() ? 3 : 1); // Bob proposes
1496 // Doing a search for "1" or "1c" is valuable?
1497 // Those work but are enormously slow.
1500 protected void txt_search_ActionPerformed()
1502 String text = txt_search.getText().trim();
1503 if (text.length() >= PDB_ID_MIN)
1510 errorWarning.setLength(0);
1511 isValidPBDEntry = false;
1512 if (text.length() > 0)
1514 // TODO move this pdb id search into the PDB specific
1516 // for moment, it will work fine as is because it is self-contained
1517 String searchTerm = text.toLowerCase(Locale.ROOT);
1518 searchTerm = searchTerm.split(":")[0];
1519 // System.out.println(">>>>> search term : " + searchTerm);
1520 List<FTSDataColumnI> wantedFields = new ArrayList<>();
1521 FTSRestRequest pdbRequest = new FTSRestRequest();
1522 pdbRequest.setAllowEmptySeq(false);
1523 pdbRequest.setResponseSize(1);
1524 pdbRequest.setFieldToSearchBy("(pdb_id:");
1525 pdbRequest.setWantedFields(wantedFields);
1526 pdbRequest.setSearchTerm(searchTerm + ")");
1527 pdbRequest.setAssociatedSequence(selectedSequence);
1528 FTSRestClientI pdbRestClient = PDBFTSRestClient.getInstance();
1529 wantedFields.add(pdbRestClient.getPrimaryKeyColumn());
1530 FTSRestResponse resultList;
1533 resultList = pdbRestClient.executeRequest(pdbRequest);
1534 } catch (Exception e)
1536 errorWarning.append(e.getMessage());
1540 validateSelections();
1542 if (resultList.getSearchSummary() != null
1543 && resultList.getSearchSummary().size() > 0)
1545 isValidPBDEntry = true;
1548 validateSelections();
1554 protected void tabRefresh()
1556 if (selectedSequences != null)
1558 lbl_loading.setVisible(true);
1559 Thread refreshThread = new Thread(new Runnable()
1564 fetchStructuresMetaData();
1565 // populateFilterComboBox(true, cachedPDBExists);
1568 ((FilterOption) cmb_filterOption.getSelectedItem())
1570 lbl_loading.setVisible(false);
1573 refreshThread.start();
1577 public class PDBEntryTableModel extends AbstractTableModel
1579 String[] columns = { "Ref Sequence", "PDB Id", "Chain", "Type",
1582 private List<CachedPDB> pdbEntries;
1584 public PDBEntryTableModel(List<CachedPDB> pdbEntries)
1586 this.pdbEntries = new ArrayList<>(pdbEntries);
1590 public String getColumnName(int columnIndex)
1592 return columns[columnIndex];
1596 public int getRowCount()
1598 return pdbEntries.size();
1602 public int getColumnCount()
1604 return columns.length;
1608 public boolean isCellEditable(int row, int column)
1614 public Object getValueAt(int rowIndex, int columnIndex)
1616 Object value = "??";
1617 CachedPDB entry = pdbEntries.get(rowIndex);
1618 switch (columnIndex)
1621 value = entry.getSequence();
1624 value = entry.getQualifiedId();
1627 value = entry.getPdbEntry().getChainCode() == null ? "_"
1628 : entry.getPdbEntry().getChainCode();
1631 value = entry.getPdbEntry().getType();
1634 value = entry.getPdbEntry().getFile();
1641 public Class<?> getColumnClass(int columnIndex)
1643 return columnIndex == 0 ? SequenceI.class : PDBEntry.class;
1646 public CachedPDB getPDBEntryAt(int row)
1648 return pdbEntries.get(row);
1653 private class CachedPDB
1655 private SequenceI sequence;
1657 private PDBEntry pdbEntry;
1659 public CachedPDB(SequenceI sequence, PDBEntry pdbEntry)
1661 this.sequence = sequence;
1662 this.pdbEntry = pdbEntry;
1665 public String getQualifiedId()
1667 if (pdbEntry.hasProvider())
1669 return pdbEntry.getProvider() + ":" + pdbEntry.getId();
1671 return pdbEntry.toString();
1674 public SequenceI getSequence()
1679 public PDBEntry getPdbEntry()
1686 private IProgressIndicator progressBar;
1689 public void setProgressBar(String message, long id)
1691 if (!Platform.isHeadless())
1692 progressBar.setProgressBar(message, id);
1696 public void registerHandler(long id, IProgressIndicatorHandler handler)
1698 progressBar.registerHandler(id, handler);
1702 public boolean operationInProgress()
1704 return progressBar.operationInProgress();
1707 public JalviewStructureDisplayI getOpenedStructureViewer()
1709 return sViewer == null ? null : sViewer.sview;
1713 protected void setFTSDocFieldPrefs(FTSDataColumnPreferences newPrefs)
1715 data.setDocFieldPrefs(newPrefs);
1721 * @return true when all initialisation threads have finished and dialog is
1724 public boolean isDialogVisible()
1726 return mainFrame != null && data != null && cmb_filterOption != null
1727 && mainFrame.isVisible()
1728 && cmb_filterOption.getSelectedItem() != null;
1733 * @return true if the 3D-Beacons query button will/has been displayed
1735 public boolean isCanQueryTDB()
1740 public boolean isNotQueriedTDBYet()
1742 return notQueriedTDBYet;
1746 * Open a single structure file for a given sequence
1748 public static void openStructureFileForSequence(AlignmentPanel ap,
1749 SequenceI seq, File sFile)
1751 // Open the chooser headlessly. Not sure this is actually needed ?
1752 StructureChooser sc = new StructureChooser(new SequenceI[] { seq }, seq,
1754 StructureSelectionManager ssm = ap.getStructureSelectionManager();
1755 PDBEntry fileEntry = null;
1758 fileEntry = new AssociatePdbFileWithSeq().associatePdbWithSeq(
1759 sFile.getAbsolutePath(), DataSourceType.FILE, seq, true,
1761 } catch (Exception e)
1763 Console.error("Could not open structure file '"
1764 + sFile.getAbsolutePath() + "'");
1768 StructureViewer sViewer = sc.launchStructureViewer(ssm,
1770 { fileEntry }, ap, new SequenceI[] { seq });
1772 sc.mainFrame.dispose();