+ commandArgsProvided = true;
+ for (ArgValue av : avm.getArgValueList(Arg.STRUCTURE))
+ {
+ String val = av.getValue();
+ SubVals subVals = av.getSubVals();
+ SequenceI seq = getSpecifiedSequence(af, avm, av);
+ if (seq == null)
+ {
+ // Could not find sequence from subId, let's assume the first
+ // sequence in the alignframe
+ AlignmentI al = af.getCurrentView().getAlignment();
+ seq = al.getSequenceAt(0);
+ }
+
+ if (seq == null)
+ {
+ addWarn("Could not find sequence for argument "
+ + Arg.STRUCTURE.argString() + "=" + val);
+ continue;
+ }
+ File structureFile = null;
+ if (subVals.getContent() != null
+ && subVals.getContent().length() != 0)
+ {
+ structureFile = new File(subVals.getContent());
+ Console.debug("Using structure file (from argument) '"
+ + structureFile.getAbsolutePath() + "'");
+ }
+ // TRY THIS
+ /*
+ * PDBEntry fileEntry = new AssociatePdbFileWithSeq()
+ * .associatePdbWithSeq(selectedPdbFileName, DataSourceType.FILE,
+ * selectedSequence, true, Desktop.instance);
+ *
+ * sViewer = launchStructureViewer(ssm, new PDBEntry[] { fileEntry }, ap, new
+ * SequenceI[] { selectedSequence });
+ *
+ */
+ /* THIS DOESN'T WORK */
+ else if (seq.getAllPDBEntries() != null
+ && seq.getAllPDBEntries().size() > 0)
+ {
+ structureFile = new File(
+ seq.getAllPDBEntries().elementAt(0).getFile());
+ Console.debug("Using structure file (from sequence) '"
+ + structureFile.getAbsolutePath() + "'");
+ }
+
+ if (structureFile == null)
+ {
+ addWarn("Not provided structure file with '" + val + "'");
+ continue;
+ }
+
+ if (!structureFile.exists())
+ {
+ addWarn("Structure file '" + structureFile.getAbsoluteFile()
+ + "' not found.");
+ continue;
+ }
+
+ Console.debug("Using structure file "
+ + structureFile.getAbsolutePath());
+
+ // open structure view
+ AlignmentPanel ap = af.alignPanel;
+ if (headless)
+ {
+ Cache.setProperty(Preferences.STRUCTURE_DISPLAY,
+ StructureViewer.ViewerType.JMOL.toString());
+ }
+
+ String structureFilepath = structureFile.getAbsolutePath();
+
+ // get PAEMATRIX file and label from subvals or Arg.PAEMATRIX
+ String paeFilepath = ArgParser
+ .getFromSubValArgOrPrefWithSubstitutions(argParser, avm,
+ Arg.PAEMATRIX, Position.AFTER, av, subVals, null,
+ null, null);
+ if (paeFilepath != null)
+ {
+ File paeFile = new File(paeFilepath);
+
+ try
+ {
+ paeFilepath = paeFile.getCanonicalPath();
+ } catch (IOException e)
+ {
+ paeFilepath = paeFile.getAbsolutePath();
+ addWarn("Problem with the PAE file path: '"
+ + paeFile.getPath() + "'");
+ }
+ }
+
+ // showing annotations from structure file or not
+ boolean ssFromStructure = ArgParser.getFromSubValArgOrPref(avm,
+ Arg.SHOWSSANNOTATIONS, subVals, null, "STRUCT_FROM_PDB",
+ true);
+
+ // get TEMPFAC type from subvals or Arg.TEMPFAC in case user Adds
+ // reference annotations
+ String tftString = ArgParser
+ .getFromSubValArgOrPrefWithSubstitutions(argParser, avm,
+ Arg.TEMPFAC, Position.AFTER, av, subVals, null,
+ null, null);
+ boolean notempfac = ArgParser.getFromSubValArgOrPref(avm,
+ Arg.NOTEMPFAC, subVals, null, "ADD_TEMPFACT_ANN", false,
+ true);
+ TFType tft = notempfac ? null : TFType.DEFAULT;
+ if (tftString != null && !notempfac)
+ {
+ // get kind of temperature factor annotation
+ try
+ {
+ tft = TFType.valueOf(tftString.toUpperCase(Locale.ROOT));
+ Console.debug("Obtained Temperature Factor type of '" + tft
+ + "' for structure '" + structureFilepath + "'");
+ } catch (IllegalArgumentException e)
+ {
+ // Just an error message!
+ StringBuilder sb = new StringBuilder().append("Cannot set ")
+ .append(Arg.TEMPFAC.argString()).append(" to '")
+ .append(tft)
+ .append("', ignoring. Valid values are: ");
+ Iterator<TFType> it = Arrays.stream(TFType.values())
+ .iterator();
+ while (it.hasNext())
+ {
+ sb.append(it.next().toString().toLowerCase(Locale.ROOT));
+ if (it.hasNext())
+ sb.append(", ");
+ }
+ addWarn(sb.toString());
+ }
+ }
+
+ String sViewer = ArgParser.getFromSubValArgOrPref(avm,
+ Arg.STRUCTUREVIEWER, Position.AFTER, av, subVals, null,
+ null, "jmol");
+ ViewerType viewerType = ViewerType.getFromString(sViewer);
+
+ // TODO use ssFromStructure
+ StructureViewer sv = StructureChooser
+ .openStructureFileForSequence(null, null, ap, seq, false,
+ structureFilepath, tft, paeFilepath, false,
+ ssFromStructure, false, viewerType);
+
+ if (sv == null)
+ {
+ addError("Failed to import and open structure view for file '"
+ + structureFile + "'.");
+ continue;
+ }
+ try
+ {
+ long tries = 1000;
+ while (sv.isBusy() && tries > 0)
+ {
+ Thread.sleep(25);
+ if (sv.isBusy())
+ {
+ tries--;
+ Console.debug(
+ "Waiting for viewer for " + structureFilepath);
+ }
+ }
+ if (tries == 0 && sv.isBusy())
+ {
+ addWarn("Gave up waiting for structure viewer to load file '"
+ + structureFile
+ + "'. Something may have gone wrong.");
+ }
+ } catch (Exception x)
+ {
+ addError("Exception whilst waiting for structure viewer "
+ + structureFilepath, x);
+ isError = true;
+ }
+
+ // add StructureViewer to svMap list
+ if (svMap == null)
+ {
+ svMap = new HashMap<>();
+ }
+ if (svMap.get(id) == null)
+ {
+ svMap.put(id, new ArrayList<>());
+ }
+ svMap.get(id).add(sv);