import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-
import jalview.api.structures.JalviewStructureDisplayI;
import jalview.bin.Cache;
import jalview.bin.Console;
import jalview.datamodel.PDBEntry;
import jalview.datamodel.SequenceI;
import jalview.datamodel.StructureViewerModel;
+import jalview.structure.StructureMapping;
import jalview.structure.StructureSelectionManager;
+import jalview.util.MessageManager;
+import jalview.util.Platform;
+import jalview.ws.DBRefFetcher;
+import jalview.ws.seqfetcher.DbSourceProxy;
+import jalview.ws.sifts.SiftsSettings;
+
+
/**
* A proxy for handling structure viewers, that orchestrates adding selected
*/
public class StructureViewer
{
+
+ static
+ {
+ Platform.loadStaticResource("core/core_jvjmol.z.js",
+ "org.jmol.viewer.Viewer");
+ }
+
+
+
+
private static final String UNKNOWN_VIEWER_TYPE = "Unknown structure viewer type ";
StructureSelectionManager ssm;
* Creates a new panel controlling a structure viewer
*
* @param type
+ * @param pdbf
+ * @param id
+ * @param sq
* @param alignPanel
* @param viewerData
* @param sessionFile
String sessionFile, String vid)
{
JalviewStructureDisplayI viewer = null;
+
switch (type)
{
case JMOL:
superposeAdded = alignAddedStructures;
}
+ /**
+ * Launch a minimal implementation of a StructureViewer.
+ *
+ * @param alignPanel
+ * @param pdb
+ * @param seqs
+ * @return
+ */
+ public static StructureViewer launchStructureViewer(
+ AlignmentPanel alignPanel, PDBEntry pdb, SequenceI[] seqs)
+ {
+ return launchStructureViewer(alignPanel, new PDBEntry[] { pdb }, seqs,
+ false, null, null);
+ }
+
+ /**
+ * Adds PDB structures to a new or existing structure viewer
+ *
+ * @param ssm
+ * @param pdbEntriesToView
+ * @param alignPanel
+ * @param sequences
+ * @return
+ */
+ protected static StructureViewer launchStructureViewer(
+ final AlignmentPanel ap, final PDBEntry[] pdbEntriesToView,
+ SequenceI[] sequences, boolean superimpose,
+ StructureViewer theViewer, IProgressIndicator pb)
+ {
+ final StructureSelectionManager ssm = ap.getStructureSelectionManager();
+ if (theViewer == null)
+ theViewer = new StructureViewer(ssm);
+ long progressId = sequences.hashCode();
+ if (pb != null)
+ pb.setProgressBar(MessageManager.getString(
+ "status.launching_3d_structure_viewer"), progressId);
+ theViewer.setSuperpose(superimpose);
+
+ /*
+ * remember user's choice of superimpose or not
+ */
+ Cache.setProperty(StructureChooser.AUTOSUPERIMPOSE,
+ Boolean.valueOf(superimpose).toString());
+
+ if (pb != null)
+ pb.setProgressBar(null, progressId);
+ if (SiftsSettings.isMapWithSifts())
+ {
+ List<SequenceI> seqsWithoutSourceDBRef = new ArrayList<>();
+ int p = 0;
+ // TODO: skip PDBEntry:Sequence pairs where PDBEntry doesn't look like a
+ // real PDB ID. For moment, we can also safely do this if there is already
+ // a known mapping between the PDBEntry and the sequence.
+ for (SequenceI seq : sequences)
+ {
+ PDBEntry pdbe = pdbEntriesToView[p++];
+ if (pdbe != null && pdbe.getFile() != null)
+ {
+ StructureMapping[] smm = ssm.getMapping(pdbe.getFile());
+ if (smm != null && smm.length > 0)
+ {
+ for (StructureMapping sm : smm)
+ {
+ if (sm.getSequence() == seq)
+ {
+ continue;
+ }
+ }
+ }
+ }
+ if (seq.getPrimaryDBRefs().isEmpty())
+ {
+ seqsWithoutSourceDBRef.add(seq);
+ continue;
+ }
+ }
+ if (!seqsWithoutSourceDBRef.isEmpty())
+ {
+ int y = seqsWithoutSourceDBRef.size();
+ if (pb != null)
+ pb.setProgressBar(MessageManager.formatMessage(
+ "status.fetching_dbrefs_for_sequences_without_valid_refs",
+ y), progressId);
+ SequenceI[] seqWithoutSrcDBRef = seqsWithoutSourceDBRef
+ .toArray(new SequenceI[y]);
+ DBRefFetcher dbRefFetcher = new DBRefFetcher(seqWithoutSrcDBRef);
+ dbRefFetcher.fetchDBRefs(true);
+
+ if (pb != null)
+ pb.setProgressBar("Fetch complete.", progressId); // todo i18n
+ }
+ }
+ if (pdbEntriesToView.length > 1)
+ {
+ if (pb != null)
+ pb.setProgressBar(MessageManager.getString(
+ "status.fetching_3d_structures_for_selected_entries"),
+ progressId);
+ theViewer.viewStructures(pdbEntriesToView, sequences, ap);
+ }
+ else
+ {
+ if (pb != null)
+ pb.setProgressBar(MessageManager.formatMessage(
+ "status.fetching_3d_structures_for",
+ pdbEntriesToView[0].getId()), progressId);
+ theViewer.viewStructures(pdbEntriesToView[0], sequences, ap);
+ }
+ if (pb != null)
+ pb.setProgressBar(null, progressId);
+ // remember the last viewer we used...
+ StructureChooser.lastTargetedView = theViewer;
+ return theViewer;
+ }
+
}