+ // assemble String[] { pdb files }, String[] { id for each
+ // file }, orig_fileloc, SequenceI[][] {{ seqs_file 1 }, {
+ // seqs_file 2}, boolean[] {
+ // linkAlignPanel,superposeWithAlignpanel}} from hash
+ StructureViewerModel jmoldat = structureViewers.get(sviewid);
+ jmoldat.setAlignWithPanel(jmoldat.isAlignWithPanel()
+ | (structureState.hasAlignwithAlignPanel() ? structureState
+ .getAlignwithAlignPanel() : false));
+
+ /*
+ * Default colour by linked panel to false if not specified (e.g.
+ * for pre-2.7 projects)
+ */
+ boolean colourWithAlignPanel = jmoldat.isColourWithAlignPanel();
+ colourWithAlignPanel |= (structureState
+ .hasColourwithAlignPanel() ? structureState
+ .getColourwithAlignPanel() : false);
+ jmoldat.setColourWithAlignPanel(colourWithAlignPanel);
+
+ /*
+ * Default colour by viewer to true if not specified (e.g. for
+ * pre-2.7 projects)
+ */
+ boolean colourByViewer = jmoldat.isColourByViewer();
+ colourByViewer &= structureState.hasColourByJmol() ? structureState
+ .getColourByJmol() : true;
+ jmoldat.setColourByViewer(colourByViewer);
+
+ if (jmoldat.getStateData().length() < structureState
+ .getContent().length())
+ {
+ {
+ jmoldat.setStateData(structureState.getContent());
+ }
+ }
+ if (ids[p].getFile() != null)
+ {
+ File mapkey = new File(ids[p].getFile());
+ StructureData seqstrmaps = jmoldat.getFileData().get(mapkey);
+ if (seqstrmaps == null)
+ {
+ jmoldat.getFileData().put(
+ mapkey,
+ seqstrmaps = jmoldat.new StructureData(pdbFile,
+ ids[p].getId()));
+ }
+ if (!seqstrmaps.getSeqList().contains(seq))
+ {
+ seqstrmaps.getSeqList().add(seq);
+ // TODO and chains?
+ }
+ }
+ else
+ {
+ errorMessage = ("The Jmol views in this project were imported\nfrom an older version of Jalview.\nPlease review the sequence colour associations\nin the Colour by section of the Jmol View menu.\n\nIn the case of problems, see note at\nhttp://issues.jalview.org/browse/JAL-747");
+ warn(errorMessage);
+ }
+ }
+ }
+ }
+ }
+ // Instantiate the associated structure views
+ for (Entry<String, StructureViewerModel> entry : structureViewers
+ .entrySet())
+ {
+ try
+ {
+ createOrLinkStructureViewer(entry, af, ap, jprovider);
+ } catch (Exception e)
+ {
+ System.err.println("Error loading structure viewer: "
+ + e.getMessage());
+ // failed - try the next one
+ }
+ }
+ }
+
+ /**
+ *
+ * @param viewerData
+ * @param af
+ * @param ap
+ * @param jprovider
+ */
+ protected void createOrLinkStructureViewer(
+ Entry<String, StructureViewerModel> viewerData, AlignFrame af,
+ AlignmentPanel ap, jarInputStreamProvider jprovider)
+ {
+ final StructureViewerModel stateData = viewerData.getValue();
+
+ /*
+ * Search for any viewer windows already open from other alignment views
+ * that exactly match the stored structure state
+ */
+ StructureViewerBase comp = findMatchingViewer(viewerData);
+
+ if (comp != null)
+ {
+ linkStructureViewer(ap, comp, stateData);
+ return;
+ }
+
+ /*
+ * From 2.9: stateData.type contains JMOL or CHIMERA, data is in jar entry
+ * "viewer_"+stateData.viewId
+ */
+ if (ViewerType.CHIMERA.toString().equals(stateData.getType()))
+ {
+ createChimeraViewer(viewerData, af, jprovider);
+ }
+ else
+ {
+ /*
+ * else Jmol (if pre-2.9, stateData contains JMOL state string)
+ */
+ createJmolViewer(viewerData, af, jprovider);
+ }
+ }
+
+ /**
+ * Create a new Chimera viewer.
+ *
+ * @param data
+ * @param af
+ * @param jprovider
+ */
+ protected void createChimeraViewer(
+ Entry<String, StructureViewerModel> viewerData, AlignFrame af,
+ jarInputStreamProvider jprovider)
+ {
+ StructureViewerModel data = viewerData.getValue();
+ String chimeraSessionFile = data.getStateData();
+
+ /*
+ * Copy Chimera session from jar entry "viewer_"+viewId to a temporary file
+ *
+ * NB this is the 'saved' viewId as in the project file XML, _not_ the
+ * 'uniquified' sviewid used to reconstruct the viewer here
+ */
+ String viewerJarEntryName = getViewerJarEntryName(data.getViewId());
+ chimeraSessionFile = copyJarEntry(jprovider, viewerJarEntryName,
+ "chimera", null);
+
+ Set<Entry<File, StructureData>> fileData = data.getFileData()
+ .entrySet();
+ List<PDBEntry> pdbs = new ArrayList<PDBEntry>();
+ List<SequenceI[]> allseqs = new ArrayList<SequenceI[]>();
+ for (Entry<File, StructureData> pdb : fileData)
+ {
+ String filePath = pdb.getValue().getFilePath();
+ String pdbId = pdb.getValue().getPdbId();
+ // pdbs.add(new PDBEntry(filePath, pdbId));
+ pdbs.add(new PDBEntry(pdbId, null, PDBEntry.Type.PDB, filePath));
+ final List<SequenceI> seqList = pdb.getValue().getSeqList();
+ SequenceI[] seqs = seqList.toArray(new SequenceI[seqList.size()]);
+ allseqs.add(seqs);
+ }
+
+ boolean colourByChimera = data.isColourByViewer();
+ boolean colourBySequence = data.isColourWithAlignPanel();
+
+ // TODO use StructureViewer as a factory here, see JAL-1761
+ final PDBEntry[] pdbArray = pdbs.toArray(new PDBEntry[pdbs.size()]);
+ final SequenceI[][] seqsArray = allseqs.toArray(new SequenceI[allseqs
+ .size()][]);
+ String newViewId = viewerData.getKey();
+
+ ChimeraViewFrame cvf = new ChimeraViewFrame(chimeraSessionFile,
+ af.alignPanel, pdbArray, seqsArray, colourByChimera,
+ colourBySequence, newViewId);
+ cvf.setSize(data.getWidth(), data.getHeight());
+ cvf.setLocation(data.getX(), data.getY());
+ }