2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.9)
3 * Copyright (C) 2015 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.
23 import jalview.api.structures.JalviewStructureDisplayI;
24 import jalview.bin.Cache;
25 import jalview.datamodel.PDBEntry;
26 import jalview.datamodel.SequenceI;
27 import jalview.datamodel.StructureViewerModel;
28 import jalview.structure.StructureSelectionManager;
30 import java.awt.Rectangle;
31 import java.util.ArrayList;
32 import java.util.List;
35 * proxy for handling structure viewers.
37 * this allows new views to be created with the currently configured viewer, the
38 * preferred viewer to be set/read and existing views created previously with a
39 * particular viewer to be recovered
43 public class StructureViewer
45 StructureSelectionManager ssm;
47 public enum ViewerType
52 public ViewerType getViewerType()
54 String viewType = Cache.getDefault(Preferences.STRUCTURE_DISPLAY,
55 ViewerType.JMOL.name());
56 return ViewerType.valueOf(viewType);
59 public void setViewerType(ViewerType type)
61 Cache.setProperty(Preferences.STRUCTURE_DISPLAY, type.name());
64 public StructureViewer(StructureSelectionManager structureSelectionManager)
66 ssm = structureSelectionManager;
70 * View multiple PDB entries, each with associated sequences
77 public JalviewStructureDisplayI viewStructures(PDBEntry[] pdbs,
78 SequenceI[][] seqsForPdbs, AlignmentPanel ap)
80 JalviewStructureDisplayI viewer = onlyOnePdb(pdbs, seqsForPdbs, ap);
85 return viewStructures(getViewerType(), pdbs, seqsForPdbs, ap);
89 * A strictly temporary method pending JAL-1761 refactoring. Determines if all
90 * the passed PDB entries are the same (this is the case if selected sequences
91 * to view structure for are chains of the same structure). If so, calls the
92 * single-pdb version of viewStructures and returns the viewer, else returns
100 private JalviewStructureDisplayI onlyOnePdb(PDBEntry[] pdbs,
101 SequenceI[][] seqsForPdbs, AlignmentPanel ap)
103 List<SequenceI> seqs = new ArrayList<SequenceI>();
104 if (pdbs == null || pdbs.length == 0)
109 String firstFile = pdbs[0].getFile();
110 for (PDBEntry pdb : pdbs)
112 String pdbFile = pdb.getFile();
113 if (pdbFile == null || !pdbFile.equals(firstFile))
117 SequenceI[] pdbseqs = seqsForPdbs[i++];
120 for (SequenceI sq : pdbseqs)
126 return viewStructures(pdbs[0],
127 seqs.toArray(new SequenceI[seqs.size()]), ap);
130 public JalviewStructureDisplayI viewStructures(PDBEntry pdb,
131 SequenceI[] seqsForPdb, AlignmentPanel ap)
133 return viewStructures(getViewerType(), pdb, seqsForPdb, ap);
136 protected JalviewStructureDisplayI viewStructures(ViewerType viewerType,
137 PDBEntry[] pdbs, SequenceI[][] seqsForPdbs, AlignmentPanel ap)
139 JalviewStructureDisplayI sview = null;
140 if (viewerType.equals(ViewerType.JMOL))
142 sview = new AppJmol(ap, pdbs, ap.av.collateForPDB(pdbs));
144 else if (viewerType.equals(ViewerType.CHIMERA))
146 sview = new ChimeraViewFrame(pdbs, ap.av.collateForPDB(pdbs), ap);
150 Cache.log.error("Unknown structure viewer type "
151 + getViewerType().toString());
156 protected JalviewStructureDisplayI viewStructures(ViewerType viewerType,
157 PDBEntry pdb, SequenceI[] seqsForPdb, AlignmentPanel ap)
159 JalviewStructureDisplayI sview = null;
160 if (viewerType.equals(ViewerType.JMOL))
162 sview = new AppJmol(pdb, seqsForPdb, null, ap);
164 else if (viewerType.equals(ViewerType.CHIMERA))
166 sview = new ChimeraViewFrame(pdb, seqsForPdb, null, ap);
170 Cache.log.error("Unknown structure viewer type "
171 + getViewerType().toString());
177 * Create a new panel controlling a structure viewer.
190 public JalviewStructureDisplayI createView(ViewerType type,
191 String[] pdbf, String[] id, SequenceI[][] sq,
192 AlignmentPanel alignPanel, StructureViewerModel viewerData,
193 String fileloc, Rectangle rect, String vid)
195 final boolean useinViewerSuperpos = viewerData.isAlignWithPanel();
196 final boolean usetoColourbyseq = viewerData.isColourWithAlignPanel();
197 final boolean viewerColouring = viewerData.isColourByViewer();
199 JalviewStructureDisplayI sview = null;
203 sview = new AppJmol(pdbf, id, sq, alignPanel, usetoColourbyseq,
204 useinViewerSuperpos, viewerColouring, fileloc, rect, vid);
207 Cache.log.error("Unsupported structure viewer type "
211 Cache.log.error("Unknown structure viewer type " + type.toString());