3 * Copyright (c) 2006 The Regents of the University of California.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions, and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions, and the following
13 * disclaimer in the documentation and/or other materials provided
14 * with the distribution.
15 * 3. Redistributions must acknowledge that this software was
16 * originally developed by the UCSF Computer Graphics Laboratory
17 * under support by the NIH National Center for Research Resources,
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY
21 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
27 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
29 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 package ext.edu.ucsf.rbvi.strucviz2;
35 import jalview.bin.Cache;
36 import jalview.gui.Preferences;
37 import jalview.util.FileUtils;
40 import java.io.IOException;
41 import java.nio.file.Paths;
42 import java.util.ArrayList;
43 import java.util.Arrays;
44 import java.util.Collection;
45 import java.util.HashMap;
46 import java.util.List;
48 import java.util.Properties;
51 import org.slf4j.Logger;
52 import org.slf4j.LoggerFactory;
55 * This object maintains the relationship between Chimera objects and Cytoscape
59 public class StructureManager
61 static final String[] defaultStructureKeys = { "Structure", "pdb",
62 "pdbFileName", "PDB ID", "structure", "biopax.xref.PDB", "pdb_ids",
63 "ModelName", "ModelNumber" };
65 static final String[] defaultChemStructKeys = { "Smiles", "smiles",
68 static final String[] defaultResidueKeys = { "FunctionalResidues",
69 "ResidueList", "Residues" };
73 PDB_MODEL, MODBASE_MODEL, SMILES
76 public static Properties pathProps;
78 private String chimeraCommandAttr = "ChimeraCommand";
80 private String chimeraOutputTable = "ChimeraTable";
82 private String chimeraOutputAttr = "ChimeraOutput";
84 private boolean haveGUI = true;
86 private ChimeraManager chimeraManager = null;
88 static private List<ChimeraStructuralObject> chimSelectionList;
90 private boolean ignoreCySelection = false;
92 private File configurationDirectory = null;
94 private static Logger logger = LoggerFactory
95 .getLogger(ext.edu.ucsf.rbvi.strucviz2.StructureManager.class);
97 public StructureManager(boolean haveGUI)
99 this.haveGUI = haveGUI;
100 // Create the Chimera interface
101 chimeraManager = new ChimeraManager(this);
102 chimSelectionList = new ArrayList<>();
103 pathProps = new Properties();
106 public ChimeraManager getChimeraManager()
108 return chimeraManager;
111 public boolean openStructures(Collection<List<String>> chimObjNames,
115 Map<String, List<ChimeraModel>> newModels = new HashMap<>();
116 if (chimObjNames.size() > 0)
118 List<String> names = chimObjNames.iterator().next();
123 for (String chimObjName : names)
125 // get or open the corresponding models if they already exist
126 List<ChimeraModel> currentModels = chimeraManager.getChimeraModels(
128 if (currentModels.size() == 0)
130 // open and return models
131 currentModels = chimeraManager.openModel(chimObjName, type);
132 if (currentModels == null)
134 // failed to open model, continue with next
137 // if (type == ModelType.SMILES) {
138 // newModels.put("smiles:" + chimObjName, currentModels);
140 newModels.put(chimObjName, currentModels);
143 for (ChimeraModel currentModel : currentModels)
145 // if not RIN then associate new model with the Cytoscape
147 // if (!currentChimMap.containsKey(currentModel)) {
148 // currentChimMap.put(currentModel, new HashSet<CyIdentifiable>());
159 // if (mnDialog != null) {
160 // mnDialog.modelChanged();
162 // aTask.associate();
167 // TODO: [Release] Handle case where one network is associated with two models
171 * public boolean openStructures(CyNetwork network, Map<CyIdentifiable,
172 * List<String>> chimObjNames, ModelType type) { if
173 * (!chimeraManager.isChimeraLaunched() &&
174 * !chimeraManager.launchChimera(getChimeraPaths(network))) {
175 * logger.error("Chimera could not be launched."); return false; } else if
176 * (chimObjNames.size() == 0) { return false; } else if (network == null) {
177 * return openStructures(chimObjNames.values(), type); }
179 * // potential rins Set<CyNetwork> potentialRINs = new HashSet<CyNetwork>();
180 * // attributes List<String> attrsFound = new ArrayList<String>();
182 * addAll(CytoUtils.getMatchingAttributes(network.getDefaultNodeTable(),
183 * getCurrentStructureKeys(network)));
184 * attrsFound.addAll(CytoUtils.getMatchingAttributes
185 * (network.getDefaultNodeTable(), getCurrentChemStructKeys(network))); // new
186 * models Map<String, List<ChimeraModel>> newModels = new HashMap<String,
187 * List<ChimeraModel>>(); // for each node that has an associated structure
188 * for (CyIdentifiable cyObj : chimObjNames.keySet()) { // get possible res
189 * specs List<String> specsFound = null; if (cyObj instanceof CyNode) {
190 * specsFound = ChimUtils.getResidueKeys(network.getDefaultNodeTable(), cyObj,
191 * attrsFound); } // save node to track its selection and mapping to chimera
192 * objects if (!currentCyMap.containsKey(cyObj)) { currentCyMap.put(cyObj, new
193 * HashSet<ChimeraStructuralObject>()); } // save node to network mapping to
194 * keep track of selection events if (!networkMap.containsKey(cyObj)) {
195 * networkMap.put(cyObj, new HashSet<CyNetwork>()); }
196 * networkMap.get(cyObj).add(network); // for each structure that has to be
197 * opened for (String chimObjName : chimObjNames.get(cyObj)) { // get or open
198 * the corresponding models if they already exist List<ChimeraModel>
199 * currentModels = chimeraManager.getChimeraModels(chimObjName, type); if
200 * (currentModels.size() == 0) { // open and return models currentModels =
201 * chimeraManager.openModel(chimObjName, type); if (currentModels == null) {
202 * // failed to open model, continue with next continue; } // if (type ==
203 * ModelType.SMILES) { // newModels.put("smiles:" + chimObjName,
204 * currentModels); // } else { newModels.put(chimObjName, currentModels); // }
205 * // for each model for (ChimeraModel currentModel : currentModels) { //
206 * check if it is a RIN boolean foundRIN = false; if
207 * (currentModel.getModelType().equals(ModelType.PDB_MODEL)) { // go through
208 * all node annotations and check if any of them is a residue // or a chain if
209 * (cyObj instanceof CyNode && network.containsNode((CyNode) cyObj) &&
210 * specsFound != null && specsFound.size() > 0) { for (String resSpec :
211 * specsFound) { ChimeraStructuralObject res =
212 * ChimUtils.fromAttribute(resSpec, chimeraManager); if (res != null && (res
213 * instanceof ChimeraResidue || res instanceof ChimeraChain)) { // if so,
214 * assume it might be a RIN potentialRINs.add(network); foundRIN = true;
215 * break; } } } else if (cyObj instanceof CyNetwork) { // if cyObj is a
216 * network, check for residue/chain annotations in an // arbitrary node
217 * CyNetwork rinNet = (CyNetwork) cyObj; if (rinNet.getNodeList().size() > 0)
218 * { specsFound = ChimUtils.getResidueKeys( rinNet.getDefaultNodeTable(),
219 * rinNet.getNodeList().get(0), attrsFound); for (String resSpec : specsFound)
220 * { ChimeraStructuralObject res = ChimUtils.fromAttribute( resSpec,
221 * chimeraManager); if (res != null && (res instanceof ChimeraResidue || res
222 * instanceof ChimeraChain)) { potentialRINs.add(network); foundRIN = true;
223 * break; } } } } } if (foundRIN) { continue; } // if not RIN then associate
224 * new model with the Cytoscape // node if
225 * (!currentChimMap.containsKey(currentModel)) {
226 * currentChimMap.put(currentModel, new HashSet<CyIdentifiable>()); } String
227 * cyObjName = network.getRow(cyObj).get(CyNetwork.NAME, String.class); if
228 * (cyObjName != null && cyObjName.endsWith(currentModel.getModelName())) { //
229 * it is a modbase model, associate directly
230 * currentCyMap.get(cyObj).add(currentModel);
231 * currentChimMap.get(currentModel).add(cyObj);
232 * currentModel.addCyObject(cyObj, network); } else if (specsFound != null &&
233 * specsFound.size() > 0) { for (String resSpec : specsFound) {
234 * ChimeraStructuralObject specModel = ChimUtils.fromAttribute( resSpec,
235 * chimeraManager); if (specModel == null &&
236 * resSpec.equals(currentModel.getModelName())) { specModel =
237 * chimeraManager.getChimeraModel( currentModel.getModelNumber(),
238 * currentModel.getSubModelNumber()); } if (specModel != null &&
239 * currentModel.toSpec().equals(specModel.toSpec()) ||
240 * currentModel.getModelName().equals("smiles:" + resSpec)) {
241 * currentCyMap.get(cyObj).add(currentModel);
242 * currentChimMap.get(currentModel).add(cyObj);
243 * currentModel.addCyObject(cyObj, network);
244 * currentModel.setFuncResidues(ChimUtils.parseFuncRes(
245 * getResidueList(network, cyObj), chimObjName)); } } } } } } } // networks
246 * that contain nodes associated to newly opened models // this will usually
247 * be of length 1 for (CyNetwork net : potentialRINs) {
248 * addStructureNetwork(net); } // update dialog if (mnDialog != null) {
249 * mnDialog.modelChanged(); } aTask.associate(); return true; }
251 public void closeStructures(Set<String> chimObjNames)
253 // for each cytoscape object and chimera model pair
254 for (String modelName : chimObjNames)
256 List<ChimeraModel> models = chimeraManager
257 .getChimeraModels(modelName);
258 for (ChimeraModel model : models)
263 // if (mnDialog != null) {
264 // mnDialog.modelChanged();
268 // TODO: [Optional] Can we make a screenshot of a single molecule?
269 public File saveChimeraImage()
274 // Create the temp file name
275 tmpFile = File.createTempFile("structureViz", ".png");
276 chimeraManager.sendChimeraCommand("set bgTransparency", false);
277 chimeraManager.sendChimeraCommand(
278 "copy file " + tmpFile.getAbsolutePath() + " png", true);
279 chimeraManager.sendChimeraCommand("unset bgTransparency", false);
280 } catch (IOException ioe)
283 logger.error("Error writing image", ioe);
288 public void closeModel(ChimeraModel model)
290 // close model in Chimera
291 chimeraManager.closeModel(model);
292 // remove all associations
293 // if (currentChimMap.containsKey(model)) {
294 // for (CyIdentifiable cyObj : model.getCyObjects().keySet()) {
295 // if (cyObj == null) {
297 // } else if (currentCyMap.containsKey(cyObj)) {
298 // currentCyMap.get(cyObj).remove(model);
299 // } else if (cyObj instanceof CyNetwork) {
300 // for (ChimeraResidue residue : model.getResidues()) {
301 // if (currentChimMap.containsKey(residue)) {
302 // for (CyIdentifiable cyObjRes : currentChimMap.get(residue)) {
303 // if (currentCyMap.containsKey(cyObjRes)) {
304 // currentCyMap.get(cyObjRes).remove(residue);
307 // currentChimMap.remove(residue);
312 // currentChimMap.remove(model);
316 // public void addStructureNetwork(CyNetwork rin) {
317 // if (rin == null) {
320 // ChimeraModel model = null;
321 // // the network is not added to the model in the currentChimMap
322 // List<String> attrsFound =
323 // CytoUtils.getMatchingAttributes(rin.getDefaultNodeTable(),
324 // getCurrentStructureKeys(rin));
325 // for (CyNode node : rin.getNodeList()) {
326 // if (!networkMap.containsKey(node)) {
327 // networkMap.put(node, new HashSet<CyNetwork>());
329 // networkMap.get(node).add(rin);
330 // List<String> specsFound =
331 // ChimUtils.getResidueKeys(rin.getDefaultNodeTable(), node,
333 // for (String residueSpec : specsFound) {
334 // // if (!rin.getRow(node).isSet(ChimUtils.RESIDUE_ATTR)) {
337 // // String residueSpec = rin.getRow(node).get(ChimUtils.RESIDUE_ATTR,
339 // ChimeraStructuralObject chimObj = ChimUtils.fromAttribute(residueSpec,
341 // // chimObj.getChimeraModel().addCyObject(node, rin);
342 // if (chimObj == null || chimObj instanceof ChimeraModel) {
345 // model = chimObj.getChimeraModel();
346 // if (!currentCyMap.containsKey(node)) {
347 // currentCyMap.put(node, new HashSet<ChimeraStructuralObject>());
349 // currentCyMap.get(node).add(chimObj);
350 // if (!currentChimMap.containsKey(chimObj)) {
351 // currentChimMap.put(chimObj, new HashSet<CyIdentifiable>());
353 // currentChimMap.get(chimObj).add(node);
356 // if (model != null) {
357 // model.addCyObject(rin, rin);
358 // if (!currentCyMap.containsKey(rin)) {
359 // currentCyMap.put(rin, new HashSet<ChimeraStructuralObject>());
361 // currentCyMap.get(rin).add(model);
365 public void exitChimera()
367 // // exit chimera, invokes clearOnExitChimera
368 // if (mnDialog != null) {
369 // mnDialog.setVisible(false);
372 // if (alDialog != null) {
373 // alDialog.setVisible(false);
375 chimeraManager.exitChimera();
378 // invoked by ChimeraManager whenever Chimera exits
379 public void clearOnChimeraExit()
381 // // clear structures
382 // currentCyMap.clear();
383 // currentChimMap.clear();
384 // networkMap.clear();
385 chimSelectionList.clear();
386 // if (chimTable != null) {
388 // getService(CyTableManager.class)).deleteTable(chimTable.getSUID());
390 // if (mnDialog != null) {
391 // if (mnDialog.isVisible()) {
392 // mnDialog.lostChimera();
393 // mnDialog.setVisible(false);
396 // if (alDialog != null) {
397 // alDialog.setVisible(false);
402 // We need to do this in two passes since some parts of a structure might be
403 // selected and some might not. Our selection model (unfortunately) only
405 // us that something has changed, not what...
406 public void updateCytoscapeSelection()
408 // List<ChimeraStructuralObject> selectedChimObj
409 ignoreCySelection = true;
410 // System.out.println("update Cytoscape selection");
411 // find all possibly selected Cytoscape objects and unselect them
412 // Set<CyNetwork> networks = new HashSet<CyNetwork>();
413 // for (CyIdentifiable currentCyObj : currentCyMap.keySet()) {
414 // if (!networkMap.containsKey(currentCyObj)) {
417 // Set<CyNetwork> currentCyNetworks = networkMap.get(currentCyObj);
418 // if (currentCyNetworks == null || currentCyNetworks.size() == 0) {
422 // for (CyNetwork network : currentCyNetworks) {
423 // if ((currentCyObj instanceof CyNode && network.containsNode((CyNode)
425 // || (currentCyObj instanceof CyEdge && network
426 // .containsEdge((CyEdge) currentCyObj))) {
427 // network.getRow(currentCyObj).set(CyNetwork.SELECTED, false);
428 // networks.add(network);
433 // // select only those associated with selected Chimera objects
434 // Set<CyIdentifiable> currentCyObjs = new HashSet<CyIdentifiable>();
435 // for (ChimeraStructuralObject chimObj : chimSelectionList) {
436 // ChimeraModel currentSelModel = chimObj.getChimeraModel();
437 // if (currentChimMap.containsKey(currentSelModel)) {
438 // currentCyObjs.addAll(currentChimMap.get(currentSelModel));
440 // if (currentChimMap.containsKey(chimObj)) {
441 // currentCyObjs.addAll(currentChimMap.get(chimObj));
443 // // System.out.println(chimObj.toSpec() + ": " +
444 // // currentCyObjs.size());
446 // for (CyIdentifiable cyObj : currentCyObjs) {
447 // // System.out.println(cyObj.toString());
448 // if (cyObj == null || !networkMap.containsKey(cyObj)) {
451 // Set<CyNetwork> currentCyNetworks = networkMap.get(cyObj);
452 // if (currentCyNetworks == null || currentCyNetworks.size() == 0) {
455 // for (CyNetwork network : currentCyNetworks) {
456 // if ((cyObj instanceof CyNode && network.containsNode((CyNode) cyObj))
457 // || (cyObj instanceof CyEdge && network.containsEdge((CyEdge) cyObj))) {
458 // network.getRow(cyObj).set(CyNetwork.SELECTED, true);
459 // networks.add(network);
464 // CyNetworkViewManager cyNetViewManager = (CyNetworkViewManager)
465 // getService(CyNetworkViewManager.class);
466 // // Update network views
467 // for (CyNetwork network : networks) {
468 // Collection<CyNetworkView> views =
469 // cyNetViewManager.getNetworkViews(network);
470 // for (CyNetworkView view : views) {
471 // view.updateView();
474 ignoreCySelection = false;
477 public void cytoscapeSelectionChanged(Map<Long, Boolean> selectedRows)
479 // if (ignoreCySelection || currentCyMap.size() == 0) {
482 // // clearSelectionList();
483 // // System.out.println("cytoscape selection changed");
484 // // iterate over all cy objects with associated models
485 // for (CyIdentifiable cyObj : currentCyMap.keySet()) {
486 // if (cyObj instanceof CyNetwork ||
487 // !selectedRows.containsKey(cyObj.getSUID())) {
490 // for (ChimeraStructuralObject chimObj : currentCyMap.get(cyObj)) {
491 // if (selectedRows.get(cyObj.getSUID())) {
492 // addChimSelection(chimObj);
493 // if (chimObj instanceof ChimeraResidue) {
494 // if (chimObj.getChimeraModel().isSelected()) {
495 // removeChimSelection(chimObj.getChimeraModel());
496 // } else if (chimObj.getChimeraModel()
497 // .getChain(((ChimeraResidue) chimObj).getChainId()).isSelected()) {
498 // removeChimSelection(chimObj.getChimeraModel().getChain(
499 // ((ChimeraResidue) chimObj).getChainId()));
503 // removeChimSelection(chimObj);
504 // if (chimObj.hasSelectedChildren() && chimObj instanceof ChimeraModel) {
505 // for (ChimeraResidue residue : ((ChimeraModel) chimObj)
506 // .getSelectedResidues()) {
507 // removeChimSelection(residue);
513 // System.out.println("selection list: " + getChimSelectionCount());
514 updateChimeraSelection();
518 // Save models in a HashMap/Set for better performance?
519 public void updateChimeraSelection()
521 // System.out.println("update Chimera selection");
523 for (int i = 0; i < chimSelectionList.size(); i++)
525 ChimeraStructuralObject nodeInfo = chimSelectionList.get(i);
526 // we do not care about the model anymore
527 selSpec = selSpec.concat(nodeInfo.toSpec());
528 if (i < chimSelectionList.size() - 1)
533 if (selSpec.length() > 0)
535 chimeraManager.select("sel " + selSpec);
539 chimeraManager.select("~sel");
544 * This is called by the selectionListener to let us know that the user has
545 * changed their selection in Chimera. We need to go back to Chimera to find
546 * out what is currently selected and update our list.
548 public void chimeraSelectionChanged()
550 // System.out.println("Chimera selection changed");
551 clearSelectionList();
552 // Execute the command to get the list of models with selections
553 Map<Integer, ChimeraModel> selectedModelsMap = chimeraManager
554 .getSelectedModels();
555 // Now get the residue-level data
556 chimeraManager.getSelectedResidues(selectedModelsMap);
557 // Get the selected objects
560 for (ChimeraModel selectedModel : selectedModelsMap.values())
562 int modelNumber = selectedModel.getModelNumber();
563 int subModelNumber = selectedModel.getSubModelNumber();
564 // Get the corresponding "real" model
565 if (chimeraManager.hasChimeraModel(modelNumber, subModelNumber))
567 ChimeraModel dataModel = chimeraManager.getChimeraModel(
568 modelNumber, subModelNumber);
569 if (dataModel.getResidueCount() == selectedModel
571 || dataModel.getModelType() == StructureManager.ModelType.SMILES)
573 // Select the entire model
574 addChimSelection(dataModel);
575 // dataModel.setSelected(true);
579 for (ChimeraChain selectedChain : selectedModel.getChains())
581 ChimeraChain dataChain = dataModel.getChain(selectedChain
583 if (selectedChain.getResidueCount() == dataChain
586 addChimSelection(dataChain);
587 // dataChain.setSelected(true);
590 // Need to select individual residues
591 for (ChimeraResidue res : selectedChain.getResidues())
593 String residueIndex = res.getIndex();
594 ChimeraResidue residue = dataChain.getResidue(residueIndex);
599 addChimSelection(residue);
600 // residue.setSelected(true);
603 } // chainIter.hasNext()
606 } // modelIter.hasNext()
607 } catch (Exception ex)
609 logger.warn("Could not update selection", ex);
611 // System.out.println("selection list: " + getChimSelectionCount());
612 // Finally, update the navigator panel
614 updateCytoscapeSelection();
617 public void selectFunctResidues(Collection<ChimeraModel> models)
619 clearSelectionList();
620 for (ChimeraModel model : models)
622 for (ChimeraResidue residue : model.getFuncResidues())
624 addChimSelection(residue);
627 updateChimeraSelection();
628 updateCytoscapeSelection();
632 // public void selectFunctResidues(CyNode node, CyNetwork network) {
633 // clearSelectionList();
634 // if (currentCyMap.containsKey(node)) {
635 // Set<ChimeraStructuralObject> chimObjects = currentCyMap.get(node);
636 // for (ChimeraStructuralObject obj : chimObjects) {
637 // if (obj instanceof ChimeraModel) {
638 // ChimeraModel model = (ChimeraModel) obj;
639 // for (ChimeraResidue residue : model.getFuncResidues()) {
640 // addChimSelection(residue);
645 // updateChimeraSelection();
646 // updateCytoscapeSelection();
647 // selectionChanged();
650 public List<ChimeraStructuralObject> getChimSelectionList()
652 return chimSelectionList;
655 public int getChimSelectionCount()
657 return chimSelectionList.size();
661 * Add a selection to the selection list. This is called primarily by the
662 * Model Navigator Dialog to keep the selections in sync
664 * @param selectionToAdd
665 * the selection to add to our list
667 public void addChimSelection(ChimeraStructuralObject selectionToAdd)
669 if (selectionToAdd != null
670 && !chimSelectionList.contains(selectionToAdd))
672 chimSelectionList.add(selectionToAdd);
673 selectionToAdd.setSelected(true);
678 * Remove a selection from the selection list. This is called primarily by the
679 * Model Navigator Dialog to keep the selections in sync
681 * @param selectionToRemove
682 * the selection to remove from our list
684 public void removeChimSelection(ChimeraStructuralObject selectionToRemove)
686 if (selectionToRemove != null
687 && chimSelectionList.contains(selectionToRemove))
689 chimSelectionList.remove(selectionToRemove);
690 selectionToRemove.setSelected(false);
695 * Clear the list of selected objects
697 public void clearSelectionList()
699 for (ChimeraStructuralObject cso : chimSelectionList)
703 cso.setSelected(false);
706 chimSelectionList.clear();
710 * Associate a new network with the corresponding Chimera objects.
716 * Dump and refresh all of our model/chain/residue info
718 public void updateModels()
720 // Stop all of our listeners while we try to handle this
721 chimeraManager.stopListening();
723 // Get all of the open models
724 List<ChimeraModel> newModelList = chimeraManager.getModelList();
726 // Match them up -- assume that the model #'s haven't changed
727 for (ChimeraModel newModel : newModelList)
729 // Get the color (for our navigator)
730 newModel.setModelColor(chimeraManager.getModelColor(newModel));
732 // Get our model info
733 int modelNumber = newModel.getModelNumber();
734 int subModelNumber = newModel.getSubModelNumber();
736 // If we already know about this model number, get the Structure,
737 // which tells us about the associated CyNode
738 if (chimeraManager.hasChimeraModel(modelNumber, subModelNumber))
740 ChimeraModel oldModel = chimeraManager.getChimeraModel(modelNumber,
742 chimeraManager.removeChimeraModel(modelNumber, subModelNumber);
743 newModel.setModelType(oldModel.getModelType());
744 if (oldModel.getModelType() == ModelType.SMILES)
746 newModel.setModelName(oldModel.getModelName());
748 // re-assign associations to cytoscape objects
749 // Map<CyIdentifiable, CyNetwork> oldModelCyObjs =
750 // oldModel.getCyObjects();
751 // for (CyIdentifiable cyObj : oldModelCyObjs.keySet()) {
752 // // add cy objects to the new model
753 // newModel.addCyObject(cyObj, oldModelCyObjs.get(cyObj));
754 // if (currentCyMap.containsKey(cyObj)) {
755 // currentCyMap.get(cyObj).add(newModel);
756 // if (currentCyMap.get(cyObj).contains(oldModel)) {
757 // currentCyMap.get(cyObj).remove(oldModel);
761 // // add new model to the chimera objects map and remove old model
762 // if (currentChimMap.containsKey(oldModel)) {
763 // currentChimMap.put(newModel, currentChimMap.get(oldModel));
764 // currentChimMap.remove(oldModel);
767 // add new model to ChimeraManager
768 chimeraManager.addChimeraModel(modelNumber, subModelNumber, newModel);
770 // Get the residue information
771 if (newModel.getModelType() != ModelType.SMILES)
773 chimeraManager.addResidues(newModel);
775 // for (CyIdentifiable cyObj : newModel.getCyObjects().keySet()) {
776 // if (cyObj != null && cyObj instanceof CyNetwork) {
777 // addStructureNetwork((CyNetwork) cyObj);
778 // } else if (cyObj != null && cyObj instanceof CyNode) {
779 // newModel.setFuncResidues(ChimUtils.parseFuncRes(
780 // getResidueList(newModel.getCyObjects().get(cyObj), cyObj),
781 // newModel.getModelName()));
786 // associate all models with any node or network
787 // aTask.associate();
789 // Restart all of our listeners
790 chimeraManager.startListening();
794 public void launchModelNavigatorDialog()
796 // TODO: [Optional] Use haveGUI flag
800 // if (mnDialog == null) {
801 // CySwingApplication cyApplication = (CySwingApplication)
802 // getService(CySwingApplication.class);
803 // mnDialog = new ModelNavigatorDialog(cyApplication.getJFrame(), this);
806 // mnDialog.setVisible(true);
809 public boolean isMNDialogOpen()
811 // if (mnDialog != null && mnDialog.isVisible()) {
818 * Invoked by the listener thread.
820 public void modelChanged()
822 // if (mnDialog != null) {
823 // mnDialog.modelChanged();
828 * Inform our interface that the selection has changed
830 public void selectionChanged()
832 // if (mnDialog != null) {
833 // // System.out.println("update dialog selection");
834 // mnDialog.updateSelection(new
835 // ArrayList<ChimeraStructuralObject>(chimSelectionList));
839 public void launchAlignDialog(boolean useChains)
841 // TODO: [Optional] Use haveGUI flag
842 // Sometimes it does not appear in Windows
846 // if (alDialog != null) {
847 // alDialog.setVisible(false);
848 // alDialog.dispose();
850 // System.out.println("launch align dialog");
851 List<ChimeraStructuralObject> chimObjectList = new ArrayList<>();
852 for (ChimeraModel model : chimeraManager.getChimeraModels())
856 for (ChimeraChain chain : model.getChains())
858 chimObjectList.add(chain);
863 chimObjectList.add(model);
866 // Bring up the dialog
867 // CySwingApplication cyApplication = (CySwingApplication)
868 // getService(CySwingApplication.class);
869 // alDialog = new AlignStructuresDialog(cyApplication.getJFrame(), this,
872 // alDialog.setVisible(true);
875 public List<String> getAllStructureKeys()
877 return Arrays.asList(defaultStructureKeys);
880 public List<String> getAllChemStructKeys()
882 return Arrays.asList(defaultChemStructKeys);
885 public List<String> getAllResidueKeys()
887 return Arrays.asList(defaultResidueKeys);
890 public List<String> getAllChimeraResidueAttributes()
892 List<String> attributes = new ArrayList<>();
893 // attributes.addAll(rinManager.getResAttrs());
894 attributes.addAll(chimeraManager.getAttrList());
898 StructureSettings defaultSettings = null;
900 // TODO: [Optional] Change priority of Chimera paths
901 public static List<String> getChimeraPaths()
903 List<String> pathList = new ArrayList<>();
905 // if no network is available and the settings have been modified by the
909 // For Jalview, Preferences/Cache plays this role instead
910 // if (defaultSettings != null)
912 // String defaultPath = defaultSettings.getChimeraPath();
913 // if (defaultPath != null && !defaultPath.equals(""))
915 // pathList.add(defaultPath);
921 * Jalview addition: check if path set in user preferences.
923 String userPath = Cache.getDefault(Preferences.CHIMERA_PATH, null);
924 if (userPath != null)
926 pathList.add(0, userPath);
929 // Add default installation paths
930 String os = System.getProperty("os.name");
931 if (os.startsWith("Linux"))
933 pathList.add("/usr/local/chimera/bin/chimera");
934 pathList.add("/usr/local/bin/chimera");
935 pathList.add("/usr/bin/chimera");
937 else if (os.startsWith("Windows"))
940 * typical Windows installation path is
941 * C:\Program Files\Chimera 1.12\bin\chimera.exe
943 for (String root : new String[] { "\\Program Files",
944 "C:\\Program Files", "\\Program Files (x86)",
945 "C:\\Program Files (x86)" })
948 * match a path ending in \bin\chimera or \bin\chimera.exe
949 * back-slash is double escaped - for Java String, and regex pattern
951 pathList.addAll(FileUtils.findMatchingPaths(
952 ".*\\\\bin\\\\chimera(\\\\.exe)?$", Paths.get(root)));
955 else if (os.startsWith("Mac"))
957 pathList.add("/Applications/Chimera.app/Contents/MacOS/chimera");
962 public void setChimeraPathProperty(String path)
964 // CytoUtils.setDefaultChimeraPath(registrar, chimeraPropertyName,
965 // chimeraPathPropertyKey,
969 public void setStructureSettings(StructureSettings structureSettings)
971 this.defaultSettings = structureSettings;
974 public String getCurrentChimeraPath(Object object)
976 if (defaultSettings != null)
978 return defaultSettings.getChimeraPath();
986 // public void initChimTable() {
987 // CyTableManager manager = (CyTableManager) getService(CyTableManager.class);
988 // CyTableFactory factory = (CyTableFactory) getService(CyTableFactory.class);
989 // for (CyTable table : manager.getGlobalTables()) {
990 // if (table.getTitle().equals(chimeraOutputTable)) {
991 // manager.deleteTable(table.getSUID());
994 // chimTable = factory.createTable(chimeraOutputTable, chimeraCommandAttr,
997 // manager.addTable(chimTable);
998 // if (chimTable.getColumn(chimeraOutputAttr) == null) {
999 // chimTable.createListColumn(chimeraOutputAttr, String.class, false);
1003 // public void addChimReply(String command, List<String> reply) {
1004 // chimTable.getRow(command).set(chimeraOutputAttr, reply);