1 package ext.edu.ucsf.rbvi.strucviz2;
4 import java.io.IOException;
5 import java.util.ArrayList;
6 import java.util.Arrays;
7 import java.util.Collection;
8 import java.util.HashMap;
9 import java.util.HashSet;
10 import java.util.List;
12 import java.util.Properties;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
19 * This object maintains the relationship between Chimera objects and Cytoscape
23 public class StructureManager
25 static final String[] defaultStructureKeys =
26 { "Structure", "pdb", "pdbFileName", "PDB ID", "structure",
27 "biopax.xref.PDB", "pdb_ids", "ModelName", "ModelNumber" };
29 static final String[] defaultChemStructKeys =
30 { "Smiles", "smiles", "SMILES" };
32 static final String[] defaultResidueKeys =
33 { "FunctionalResidues", "ResidueList", "Residues" };
35 private final String chimeraPropertyName = "chimera";
37 private final String chimeraPathPropertyKey = "LastChimeraPath";
41 PDB_MODEL, MODBASE_MODEL, SMILES
44 public static Properties pathProps;
46 private String chimeraCommandAttr = "ChimeraCommand";
48 private String chimeraOutputTable = "ChimeraTable";
50 private String chimeraOutputAttr = "ChimeraOutput";
52 private boolean haveGUI = true;
54 private ChimeraManager chimeraManager = null;
56 static private List<ChimeraStructuralObject> chimSelectionList;
58 private boolean ignoreCySelection = false;
60 private File configurationDirectory = null;
62 private static Logger logger = LoggerFactory
63 .getLogger(ext.edu.ucsf.rbvi.strucviz2.StructureManager.class);
65 public StructureManager(boolean haveGUI)
67 this.haveGUI = haveGUI;
68 // Create the Chimera interface
69 chimeraManager = new ChimeraManager(this);
70 chimSelectionList = new ArrayList<ChimeraStructuralObject>();
71 pathProps = new Properties();
74 public ChimeraManager getChimeraManager()
76 return chimeraManager;
79 public boolean openStructures(Collection<List<String>> chimObjNames,
83 Map<String, List<ChimeraModel>> newModels = new HashMap<String, List<ChimeraModel>>();
84 if (chimObjNames.size() > 0)
86 List<String> names = chimObjNames.iterator().next();
91 for (String chimObjName : names)
93 // get or open the corresponding models if they already exist
94 List<ChimeraModel> currentModels = chimeraManager.getChimeraModels(
96 if (currentModels.size() == 0)
98 // open and return models
99 currentModels = chimeraManager.openModel(chimObjName, type);
100 if (currentModels == null)
102 // failed to open model, continue with next
105 // if (type == ModelType.SMILES) {
106 // newModels.put("smiles:" + chimObjName, currentModels);
108 newModels.put(chimObjName, currentModels);
111 for (ChimeraModel currentModel : currentModels)
113 // if not RIN then associate new model with the Cytoscape
115 // if (!currentChimMap.containsKey(currentModel)) {
116 // currentChimMap.put(currentModel, new HashSet<CyIdentifiable>());
127 // if (mnDialog != null) {
128 // mnDialog.modelChanged();
130 // aTask.associate();
135 // TODO: [Release] Handle case where one network is associated with two models
139 * public boolean openStructures(CyNetwork network, Map<CyIdentifiable,
140 * List<String>> chimObjNames, ModelType type) { if
141 * (!chimeraManager.isChimeraLaunched() &&
142 * !chimeraManager.launchChimera(getChimeraPaths(network))) {
143 * logger.error("Chimera could not be launched."); return false; } else if
144 * (chimObjNames.size() == 0) { return false; } else if (network == null) {
145 * return openStructures(chimObjNames.values(), type); }
147 * // potential rins Set<CyNetwork> potentialRINs = new HashSet<CyNetwork>();
148 * // attributes List<String> attrsFound = new ArrayList<String>();
150 * addAll(CytoUtils.getMatchingAttributes(network.getDefaultNodeTable(),
151 * getCurrentStructureKeys(network)));
152 * attrsFound.addAll(CytoUtils.getMatchingAttributes
153 * (network.getDefaultNodeTable(), getCurrentChemStructKeys(network))); // new
154 * models Map<String, List<ChimeraModel>> newModels = new HashMap<String,
155 * List<ChimeraModel>>(); // for each node that has an associated structure
156 * for (CyIdentifiable cyObj : chimObjNames.keySet()) { // get possible res
157 * specs List<String> specsFound = null; if (cyObj instanceof CyNode) {
158 * specsFound = ChimUtils.getResidueKeys(network.getDefaultNodeTable(), cyObj,
159 * attrsFound); } // save node to track its selection and mapping to chimera
160 * objects if (!currentCyMap.containsKey(cyObj)) { currentCyMap.put(cyObj, new
161 * HashSet<ChimeraStructuralObject>()); } // save node to network mapping to
162 * keep track of selection events if (!networkMap.containsKey(cyObj)) {
163 * networkMap.put(cyObj, new HashSet<CyNetwork>()); }
164 * networkMap.get(cyObj).add(network); // for each structure that has to be
165 * opened for (String chimObjName : chimObjNames.get(cyObj)) { // get or open
166 * the corresponding models if they already exist List<ChimeraModel>
167 * currentModels = chimeraManager.getChimeraModels(chimObjName, type); if
168 * (currentModels.size() == 0) { // open and return models currentModels =
169 * chimeraManager.openModel(chimObjName, type); if (currentModels == null) {
170 * // failed to open model, continue with next continue; } // if (type ==
171 * ModelType.SMILES) { // newModels.put("smiles:" + chimObjName,
172 * currentModels); // } else { newModels.put(chimObjName, currentModels); // }
173 * // for each model for (ChimeraModel currentModel : currentModels) { //
174 * check if it is a RIN boolean foundRIN = false; if
175 * (currentModel.getModelType().equals(ModelType.PDB_MODEL)) { // go through
176 * all node annotations and check if any of them is a residue // or a chain if
177 * (cyObj instanceof CyNode && network.containsNode((CyNode) cyObj) &&
178 * specsFound != null && specsFound.size() > 0) { for (String resSpec :
179 * specsFound) { ChimeraStructuralObject res =
180 * ChimUtils.fromAttribute(resSpec, chimeraManager); if (res != null && (res
181 * instanceof ChimeraResidue || res instanceof ChimeraChain)) { // if so,
182 * assume it might be a RIN potentialRINs.add(network); foundRIN = true;
183 * break; } } } else if (cyObj instanceof CyNetwork) { // if cyObj is a
184 * network, check for residue/chain annotations in an // arbitrary node
185 * CyNetwork rinNet = (CyNetwork) cyObj; if (rinNet.getNodeList().size() > 0)
186 * { specsFound = ChimUtils.getResidueKeys( rinNet.getDefaultNodeTable(),
187 * rinNet.getNodeList().get(0), attrsFound); for (String resSpec : specsFound)
188 * { ChimeraStructuralObject res = ChimUtils.fromAttribute( resSpec,
189 * chimeraManager); if (res != null && (res instanceof ChimeraResidue || res
190 * instanceof ChimeraChain)) { potentialRINs.add(network); foundRIN = true;
191 * break; } } } } } if (foundRIN) { continue; } // if not RIN then associate
192 * new model with the Cytoscape // node if
193 * (!currentChimMap.containsKey(currentModel)) {
194 * currentChimMap.put(currentModel, new HashSet<CyIdentifiable>()); } String
195 * cyObjName = network.getRow(cyObj).get(CyNetwork.NAME, String.class); if
196 * (cyObjName != null && cyObjName.endsWith(currentModel.getModelName())) { //
197 * it is a modbase model, associate directly
198 * currentCyMap.get(cyObj).add(currentModel);
199 * currentChimMap.get(currentModel).add(cyObj);
200 * currentModel.addCyObject(cyObj, network); } else if (specsFound != null &&
201 * specsFound.size() > 0) { for (String resSpec : specsFound) {
202 * ChimeraStructuralObject specModel = ChimUtils.fromAttribute( resSpec,
203 * chimeraManager); if (specModel == null &&
204 * resSpec.equals(currentModel.getModelName())) { specModel =
205 * chimeraManager.getChimeraModel( currentModel.getModelNumber(),
206 * currentModel.getSubModelNumber()); } if (specModel != null &&
207 * currentModel.toSpec().equals(specModel.toSpec()) ||
208 * currentModel.getModelName().equals("smiles:" + resSpec)) {
209 * currentCyMap.get(cyObj).add(currentModel);
210 * currentChimMap.get(currentModel).add(cyObj);
211 * currentModel.addCyObject(cyObj, network);
212 * currentModel.setFuncResidues(ChimUtils.parseFuncRes(
213 * getResidueList(network, cyObj), chimObjName)); } } } } } } } // networks
214 * that contain nodes associated to newly opened models // this will usually
215 * be of length 1 for (CyNetwork net : potentialRINs) {
216 * addStructureNetwork(net); } // update dialog if (mnDialog != null) {
217 * mnDialog.modelChanged(); } aTask.associate(); return true; }
219 public void closeStructures(Set<String> chimObjNames)
221 // for each cytoscape object and chimera model pair
222 for (String modelName : chimObjNames)
224 List<ChimeraModel> models = chimeraManager
225 .getChimeraModels(modelName);
226 for (ChimeraModel model : models)
231 // if (mnDialog != null) {
232 // mnDialog.modelChanged();
236 // TODO: [Optional] Can we make a screenshot of a single molecule?
237 public File saveChimeraImage()
242 // Create the temp file name
243 tmpFile = File.createTempFile("structureViz", ".png");
244 chimeraManager.sendChimeraCommand("set bgTransparency", false);
245 chimeraManager.sendChimeraCommand(
246 "copy file " + tmpFile.getAbsolutePath() + " png", true);
247 chimeraManager.sendChimeraCommand("unset bgTransparency", false);
248 } catch (IOException ioe)
251 logger.error("Error writing image", ioe);
256 public void closeModel(ChimeraModel model)
258 // close model in Chimera
259 chimeraManager.closeModel(model);
260 // remove all associations
261 // if (currentChimMap.containsKey(model)) {
262 // for (CyIdentifiable cyObj : model.getCyObjects().keySet()) {
263 // if (cyObj == null) {
265 // } else if (currentCyMap.containsKey(cyObj)) {
266 // currentCyMap.get(cyObj).remove(model);
267 // } else if (cyObj instanceof CyNetwork) {
268 // for (ChimeraResidue residue : model.getResidues()) {
269 // if (currentChimMap.containsKey(residue)) {
270 // for (CyIdentifiable cyObjRes : currentChimMap.get(residue)) {
271 // if (currentCyMap.containsKey(cyObjRes)) {
272 // currentCyMap.get(cyObjRes).remove(residue);
275 // currentChimMap.remove(residue);
280 // currentChimMap.remove(model);
284 // public void addStructureNetwork(CyNetwork rin) {
285 // if (rin == null) {
288 // ChimeraModel model = null;
289 // // the network is not added to the model in the currentChimMap
290 // List<String> attrsFound =
291 // CytoUtils.getMatchingAttributes(rin.getDefaultNodeTable(),
292 // getCurrentStructureKeys(rin));
293 // for (CyNode node : rin.getNodeList()) {
294 // if (!networkMap.containsKey(node)) {
295 // networkMap.put(node, new HashSet<CyNetwork>());
297 // networkMap.get(node).add(rin);
298 // List<String> specsFound =
299 // ChimUtils.getResidueKeys(rin.getDefaultNodeTable(), node,
301 // for (String residueSpec : specsFound) {
302 // // if (!rin.getRow(node).isSet(ChimUtils.RESIDUE_ATTR)) {
305 // // String residueSpec = rin.getRow(node).get(ChimUtils.RESIDUE_ATTR,
307 // ChimeraStructuralObject chimObj = ChimUtils.fromAttribute(residueSpec,
309 // // chimObj.getChimeraModel().addCyObject(node, rin);
310 // if (chimObj == null || chimObj instanceof ChimeraModel) {
313 // model = chimObj.getChimeraModel();
314 // if (!currentCyMap.containsKey(node)) {
315 // currentCyMap.put(node, new HashSet<ChimeraStructuralObject>());
317 // currentCyMap.get(node).add(chimObj);
318 // if (!currentChimMap.containsKey(chimObj)) {
319 // currentChimMap.put(chimObj, new HashSet<CyIdentifiable>());
321 // currentChimMap.get(chimObj).add(node);
324 // if (model != null) {
325 // model.addCyObject(rin, rin);
326 // if (!currentCyMap.containsKey(rin)) {
327 // currentCyMap.put(rin, new HashSet<ChimeraStructuralObject>());
329 // currentCyMap.get(rin).add(model);
333 public void exitChimera()
335 // // exit chimera, invokes clearOnExitChimera
336 // if (mnDialog != null) {
337 // mnDialog.setVisible(false);
340 // if (alDialog != null) {
341 // alDialog.setVisible(false);
343 chimeraManager.exitChimera();
346 // invoked by ChimeraManager whenever Chimera exits
347 public void clearOnChimeraExit()
349 // // clear structures
350 // currentCyMap.clear();
351 // currentChimMap.clear();
352 // networkMap.clear();
353 chimSelectionList.clear();
354 // if (chimTable != null) {
356 // getService(CyTableManager.class)).deleteTable(chimTable.getSUID());
358 // if (mnDialog != null) {
359 // if (mnDialog.isVisible()) {
360 // mnDialog.lostChimera();
361 // mnDialog.setVisible(false);
364 // if (alDialog != null) {
365 // alDialog.setVisible(false);
370 // We need to do this in two passes since some parts of a structure might be
371 // selected and some might not. Our selection model (unfortunately) only
373 // us that something has changed, not what...
374 public void updateCytoscapeSelection()
376 // List<ChimeraStructuralObject> selectedChimObj
377 ignoreCySelection = true;
378 // System.out.println("update Cytoscape selection");
379 // find all possibly selected Cytoscape objects and unselect them
380 // Set<CyNetwork> networks = new HashSet<CyNetwork>();
381 // for (CyIdentifiable currentCyObj : currentCyMap.keySet()) {
382 // if (!networkMap.containsKey(currentCyObj)) {
385 // Set<CyNetwork> currentCyNetworks = networkMap.get(currentCyObj);
386 // if (currentCyNetworks == null || currentCyNetworks.size() == 0) {
390 // for (CyNetwork network : currentCyNetworks) {
391 // if ((currentCyObj instanceof CyNode && network.containsNode((CyNode)
393 // || (currentCyObj instanceof CyEdge && network
394 // .containsEdge((CyEdge) currentCyObj))) {
395 // network.getRow(currentCyObj).set(CyNetwork.SELECTED, false);
396 // networks.add(network);
401 // // select only those associated with selected Chimera objects
402 // Set<CyIdentifiable> currentCyObjs = new HashSet<CyIdentifiable>();
403 // for (ChimeraStructuralObject chimObj : chimSelectionList) {
404 // ChimeraModel currentSelModel = chimObj.getChimeraModel();
405 // if (currentChimMap.containsKey(currentSelModel)) {
406 // currentCyObjs.addAll(currentChimMap.get(currentSelModel));
408 // if (currentChimMap.containsKey(chimObj)) {
409 // currentCyObjs.addAll(currentChimMap.get(chimObj));
411 // // System.out.println(chimObj.toSpec() + ": " +
412 // // currentCyObjs.size());
414 // for (CyIdentifiable cyObj : currentCyObjs) {
415 // // System.out.println(cyObj.toString());
416 // if (cyObj == null || !networkMap.containsKey(cyObj)) {
419 // Set<CyNetwork> currentCyNetworks = networkMap.get(cyObj);
420 // if (currentCyNetworks == null || currentCyNetworks.size() == 0) {
423 // for (CyNetwork network : currentCyNetworks) {
424 // if ((cyObj instanceof CyNode && network.containsNode((CyNode) cyObj))
425 // || (cyObj instanceof CyEdge && network.containsEdge((CyEdge) cyObj))) {
426 // network.getRow(cyObj).set(CyNetwork.SELECTED, true);
427 // networks.add(network);
432 // CyNetworkViewManager cyNetViewManager = (CyNetworkViewManager)
433 // getService(CyNetworkViewManager.class);
434 // // Update network views
435 // for (CyNetwork network : networks) {
436 // Collection<CyNetworkView> views =
437 // cyNetViewManager.getNetworkViews(network);
438 // for (CyNetworkView view : views) {
439 // view.updateView();
442 ignoreCySelection = false;
445 public void cytoscapeSelectionChanged(Map<Long, Boolean> selectedRows)
447 // if (ignoreCySelection || currentCyMap.size() == 0) {
450 // // clearSelectionList();
451 // // System.out.println("cytoscape selection changed");
452 // // iterate over all cy objects with associated models
453 // for (CyIdentifiable cyObj : currentCyMap.keySet()) {
454 // if (cyObj instanceof CyNetwork ||
455 // !selectedRows.containsKey(cyObj.getSUID())) {
458 // for (ChimeraStructuralObject chimObj : currentCyMap.get(cyObj)) {
459 // if (selectedRows.get(cyObj.getSUID())) {
460 // addChimSelection(chimObj);
461 // if (chimObj instanceof ChimeraResidue) {
462 // if (chimObj.getChimeraModel().isSelected()) {
463 // removeChimSelection(chimObj.getChimeraModel());
464 // } else if (chimObj.getChimeraModel()
465 // .getChain(((ChimeraResidue) chimObj).getChainId()).isSelected()) {
466 // removeChimSelection(chimObj.getChimeraModel().getChain(
467 // ((ChimeraResidue) chimObj).getChainId()));
471 // removeChimSelection(chimObj);
472 // if (chimObj.hasSelectedChildren() && chimObj instanceof ChimeraModel) {
473 // for (ChimeraResidue residue : ((ChimeraModel) chimObj)
474 // .getSelectedResidues()) {
475 // removeChimSelection(residue);
481 // System.out.println("selection list: " + getChimSelectionCount());
482 updateChimeraSelection();
486 // Save models in a HashMap/Set for better performance?
487 public void updateChimeraSelection()
489 // System.out.println("update Chimera selection");
491 for (int i = 0; i < chimSelectionList.size(); i++)
493 ChimeraStructuralObject nodeInfo = chimSelectionList.get(i);
494 // we do not care about the model anymore
495 selSpec = selSpec.concat(nodeInfo.toSpec());
496 if (i < chimSelectionList.size() - 1)
499 if (selSpec.length() > 0)
501 chimeraManager.select("sel " + selSpec);
505 chimeraManager.select("~sel");
510 * This is called by the selectionListener to let us know that the user has
511 * changed their selection in Chimera. We need to go back to Chimera to find
512 * out what is currently selected and update our list.
514 public void chimeraSelectionChanged()
516 // System.out.println("Chimera selection changed");
517 clearSelectionList();
518 // Execute the command to get the list of models with selections
519 Map<Integer, ChimeraModel> selectedModelsMap = chimeraManager
520 .getSelectedModels();
521 // Now get the residue-level data
522 chimeraManager.getSelectedResidues(selectedModelsMap);
523 // Get the selected objects
526 for (ChimeraModel selectedModel : selectedModelsMap.values())
528 int modelNumber = selectedModel.getModelNumber();
529 int subModelNumber = selectedModel.getSubModelNumber();
530 // Get the corresponding "real" model
531 if (chimeraManager.hasChimeraModel(modelNumber, subModelNumber))
533 ChimeraModel dataModel = chimeraManager.getChimeraModel(
534 modelNumber, subModelNumber);
535 if (dataModel.getResidueCount() == selectedModel
537 || dataModel.getModelType() == StructureManager.ModelType.SMILES)
539 // Select the entire model
540 addChimSelection(dataModel);
541 // dataModel.setSelected(true);
545 for (ChimeraChain selectedChain : selectedModel.getChains())
547 ChimeraChain dataChain = dataModel.getChain(selectedChain
549 if (selectedChain.getResidueCount() == dataChain
552 addChimSelection(dataChain);
553 // dataChain.setSelected(true);
556 // Need to select individual residues
557 for (ChimeraResidue res : selectedChain.getResidues())
559 String residueIndex = res.getIndex();
560 ChimeraResidue residue = dataChain.getResidue(residueIndex);
565 addChimSelection(residue);
566 // residue.setSelected(true);
569 } // chainIter.hasNext()
572 } // modelIter.hasNext()
573 } catch (Exception ex)
575 logger.warn("Could not update selection", ex);
577 // System.out.println("selection list: " + getChimSelectionCount());
578 // Finally, update the navigator panel
580 updateCytoscapeSelection();
583 public void selectFunctResidues(Collection<ChimeraModel> models)
585 clearSelectionList();
586 for (ChimeraModel model : models)
588 for (ChimeraResidue residue : model.getFuncResidues())
590 addChimSelection(residue);
593 updateChimeraSelection();
594 updateCytoscapeSelection();
598 // public void selectFunctResidues(CyNode node, CyNetwork network) {
599 // clearSelectionList();
600 // if (currentCyMap.containsKey(node)) {
601 // Set<ChimeraStructuralObject> chimObjects = currentCyMap.get(node);
602 // for (ChimeraStructuralObject obj : chimObjects) {
603 // if (obj instanceof ChimeraModel) {
604 // ChimeraModel model = (ChimeraModel) obj;
605 // for (ChimeraResidue residue : model.getFuncResidues()) {
606 // addChimSelection(residue);
611 // updateChimeraSelection();
612 // updateCytoscapeSelection();
613 // selectionChanged();
616 public List<ChimeraStructuralObject> getChimSelectionList()
618 return chimSelectionList;
621 public int getChimSelectionCount()
623 return chimSelectionList.size();
627 * Add a selection to the selection list. This is called primarily by the
628 * Model Navigator Dialog to keep the selections in sync
630 * @param selectionToAdd
631 * the selection to add to our list
633 public void addChimSelection(ChimeraStructuralObject selectionToAdd)
635 if (selectionToAdd != null
636 && !chimSelectionList.contains(selectionToAdd))
638 chimSelectionList.add(selectionToAdd);
639 selectionToAdd.setSelected(true);
644 * Remove a selection from the selection list. This is called primarily by the
645 * Model Navigator Dialog to keep the selections in sync
647 * @param selectionToRemove
648 * the selection to remove from our list
650 public void removeChimSelection(ChimeraStructuralObject selectionToRemove)
652 if (selectionToRemove != null
653 && chimSelectionList.contains(selectionToRemove))
655 chimSelectionList.remove(selectionToRemove);
656 selectionToRemove.setSelected(false);
661 * Clear the list of selected objects
663 public void clearSelectionList()
665 for (ChimeraStructuralObject cso : chimSelectionList)
668 cso.setSelected(false);
670 chimSelectionList.clear();
674 * Associate a new network with the corresponding Chimera objects.
680 * Dump and refresh all of our model/chain/residue info
682 public void updateModels()
684 // Stop all of our listeners while we try to handle this
685 chimeraManager.stopListening();
687 // Get all of the open models
688 List<ChimeraModel> newModelList = chimeraManager.getModelList();
690 // Match them up -- assume that the model #'s haven't changed
691 for (ChimeraModel newModel : newModelList)
693 // Get the color (for our navigator)
694 newModel.setModelColor(chimeraManager.getModelColor(newModel));
696 // Get our model info
697 int modelNumber = newModel.getModelNumber();
698 int subModelNumber = newModel.getSubModelNumber();
700 // If we already know about this model number, get the Structure,
701 // which tells us about the associated CyNode
702 if (chimeraManager.hasChimeraModel(modelNumber, subModelNumber))
704 ChimeraModel oldModel = chimeraManager.getChimeraModel(modelNumber,
706 chimeraManager.removeChimeraModel(modelNumber, subModelNumber);
707 newModel.setModelType(oldModel.getModelType());
708 if (oldModel.getModelType() == ModelType.SMILES)
710 newModel.setModelName(oldModel.getModelName());
712 // re-assign associations to cytoscape objects
713 // Map<CyIdentifiable, CyNetwork> oldModelCyObjs =
714 // oldModel.getCyObjects();
715 // for (CyIdentifiable cyObj : oldModelCyObjs.keySet()) {
716 // // add cy objects to the new model
717 // newModel.addCyObject(cyObj, oldModelCyObjs.get(cyObj));
718 // if (currentCyMap.containsKey(cyObj)) {
719 // currentCyMap.get(cyObj).add(newModel);
720 // if (currentCyMap.get(cyObj).contains(oldModel)) {
721 // currentCyMap.get(cyObj).remove(oldModel);
725 // // add new model to the chimera objects map and remove old model
726 // if (currentChimMap.containsKey(oldModel)) {
727 // currentChimMap.put(newModel, currentChimMap.get(oldModel));
728 // currentChimMap.remove(oldModel);
731 // add new model to ChimeraManager
732 chimeraManager.addChimeraModel(modelNumber, subModelNumber, newModel);
734 // Get the residue information
735 if (newModel.getModelType() != ModelType.SMILES)
737 chimeraManager.addResidues(newModel);
739 // for (CyIdentifiable cyObj : newModel.getCyObjects().keySet()) {
740 // if (cyObj != null && cyObj instanceof CyNetwork) {
741 // addStructureNetwork((CyNetwork) cyObj);
742 // } else if (cyObj != null && cyObj instanceof CyNode) {
743 // newModel.setFuncResidues(ChimUtils.parseFuncRes(
744 // getResidueList(newModel.getCyObjects().get(cyObj), cyObj),
745 // newModel.getModelName()));
750 // associate all models with any node or network
751 // aTask.associate();
753 // Restart all of our listeners
754 chimeraManager.startListening();
758 public void launchModelNavigatorDialog()
760 // TODO: [Optional] Use haveGUI flag
764 // if (mnDialog == null) {
765 // CySwingApplication cyApplication = (CySwingApplication)
766 // getService(CySwingApplication.class);
767 // mnDialog = new ModelNavigatorDialog(cyApplication.getJFrame(), this);
770 // mnDialog.setVisible(true);
773 public boolean isMNDialogOpen()
775 // if (mnDialog != null && mnDialog.isVisible()) {
782 * Invoked by the listener thread.
784 public void modelChanged()
786 // if (mnDialog != null) {
787 // mnDialog.modelChanged();
792 * Inform our interface that the selection has changed
794 public void selectionChanged()
796 // if (mnDialog != null) {
797 // // System.out.println("update dialog selection");
798 // mnDialog.updateSelection(new
799 // ArrayList<ChimeraStructuralObject>(chimSelectionList));
803 public void launchAlignDialog(boolean useChains)
805 // TODO: [Optional] Use haveGUI flag
806 // Sometimes it does not appear in Windows
810 // if (alDialog != null) {
811 // alDialog.setVisible(false);
812 // alDialog.dispose();
814 // System.out.println("launch align dialog");
815 List<ChimeraStructuralObject> chimObjectList = new ArrayList<ChimeraStructuralObject>();
816 for (ChimeraModel model : chimeraManager.getChimeraModels())
820 for (ChimeraChain chain : model.getChains())
822 chimObjectList.add(chain);
827 chimObjectList.add(model);
830 // Bring up the dialog
831 // CySwingApplication cyApplication = (CySwingApplication)
832 // getService(CySwingApplication.class);
833 // alDialog = new AlignStructuresDialog(cyApplication.getJFrame(), this,
836 // alDialog.setVisible(true);
839 public List<String> getAllStructureKeys()
841 return Arrays.asList(defaultStructureKeys);
844 public List<String> getAllChemStructKeys()
846 return Arrays.asList(defaultChemStructKeys);
849 public List<String> getAllResidueKeys()
851 return Arrays.asList(defaultResidueKeys);
854 public List<String> getAllChimeraResidueAttributes()
856 List<String> attributes = new ArrayList<String>();
857 // attributes.addAll(rinManager.getResAttrs());
858 attributes.addAll(chimeraManager.getAttrList());
862 StructureSettings defaultSettings = null;
864 // TODO: [Optional] Change priority of Chimera paths
865 public List<String> getChimeraPaths()
867 List<String> pathList = new ArrayList<String>();
869 // if no network is available and the settings have been modified by the
872 if (defaultSettings != null)
874 String defaultPath = defaultSettings.getChimeraPath();
875 if (defaultPath != null && !defaultPath.equals(""))
877 pathList.add(defaultPath);
882 // if no network settings, check if the last chimera path is saved in the
884 // String lastPath = CytoUtils.getDefaultChimeraPath(registrar,
885 // chimeraPropertyName,
886 // chimeraPathPropertyKey);
887 // if (lastPath != null && !lastPath.equals("")) {
888 // pathList.add(lastPath);
892 // if no user settings and no last path, get default system's settings
893 String os = System.getProperty("os.name");
894 if (os.startsWith("Linux"))
896 pathList.add("/usr/local/chimera/bin/chimera");
897 pathList.add("/usr/local/bin/chimera");
898 pathList.add("/usr/bin/chimera");
900 else if (os.startsWith("Windows"))
902 pathList.add("\\Program Files\\Chimera\\bin\\chimera");
903 pathList.add("C:\\Program Files\\Chimera\\bin\\chimera.exe");
905 else if (os.startsWith("Mac"))
907 pathList.add("/Applications/Chimera.app/Contents/MacOS/chimera");
912 public void setChimeraPathProperty(String path)
914 // CytoUtils.setDefaultChimeraPath(registrar, chimeraPropertyName,
915 // chimeraPathPropertyKey,
919 public void setStructureSettings(StructureSettings structureSettings)
921 this.defaultSettings = structureSettings;
924 public String getCurrentChimeraPath(Object object)
926 if (defaultSettings != null)
928 return defaultSettings.getChimeraPath();
936 // public void initChimTable() {
937 // CyTableManager manager = (CyTableManager) getService(CyTableManager.class);
938 // CyTableFactory factory = (CyTableFactory) getService(CyTableFactory.class);
939 // for (CyTable table : manager.getGlobalTables()) {
940 // if (table.getTitle().equals(chimeraOutputTable)) {
941 // manager.deleteTable(table.getSUID());
944 // chimTable = factory.createTable(chimeraOutputTable, chimeraCommandAttr,
947 // manager.addTable(chimTable);
948 // if (chimTable.getColumn(chimeraOutputAttr) == null) {
949 // chimTable.createListColumn(chimeraOutputAttr, String.class, false);
953 // public void addChimReply(String command, List<String> reply) {
954 // chimTable.getRow(command).set(chimeraOutputAttr, reply);