3 import jalview.api.AlignmentViewPanel;
4 import jalview.datamodel.PDBEntry;
5 import jalview.datamodel.SequenceI;
6 import jalview.ext.pymol.PymolCommands;
7 import jalview.ext.pymol.PymolManager;
8 import jalview.gui.StructureViewer.ViewerType;
9 import jalview.structure.AtomSpec;
10 import jalview.structure.StructureCommandI;
11 import jalview.structure.StructureSelectionManager;
12 import jalview.structures.models.AAStructureBindingModel;
14 import java.util.ArrayList;
15 import java.util.HashMap;
16 import java.util.List;
19 public class PymolBindingModel extends AAStructureBindingModel
21 private PymolManager pymolManager;
23 private Thread pymolMonitor;
26 * full paths to structure files opened in PyMOL
28 List<String> structureFiles = new ArrayList<>();
31 * lookup from file path to PyMOL object name
33 Map<String, String> pymolObjects = new HashMap<>();
43 public PymolBindingModel(StructureViewerBase viewer,
44 StructureSelectionManager ssm, PDBEntry[] pdbentry,
45 SequenceI[][] sequenceIs)
47 super(ssm, pdbentry, sequenceIs, null);
48 pymolManager = new PymolManager();
49 setStructureCommands(new PymolCommands());
54 public String[] getStructureFiles()
56 return structureFiles.toArray(new String[structureFiles.size()]);
60 public void highlightAtoms(List<AtomSpec> atoms)
65 public SequenceRenderer getSequenceRenderer(AlignmentViewPanel alignment)
68 return new SequenceRenderer(alignment.getAlignViewport());
72 protected List<String> executeCommand(StructureCommandI command,
75 System.out.println(command.toString()); // debug
76 return pymolManager.sendCommand(command, getReply);
80 protected String getModelIdForFile(String file)
82 return pymolObjects.containsKey(file) ? pymolObjects.get(file) : "";
86 protected ViewerType getViewerType()
88 return ViewerType.PYMOL;
91 public boolean isPymolRunning()
93 return pymolManager.isPymolLaunched();
96 public void closeViewer(boolean closePymol)
98 getSsm().removeStructureViewerListener(this, this.getStructureFiles());
101 pymolManager.exitPymol();
103 // if (this.pymolListener != null)
105 // pymolListener.shutdown();
106 // pymolListener = null;
110 if (pymolMonitor != null)
112 pymolMonitor.interrupt();
114 releaseUIResources();
117 public boolean openSession(String pymolSessionFile)
119 StructureCommandI cmd = getCommandGenerator()
120 .loadFile(pymolSessionFile);
121 executeCommand(cmd, false);
125 public boolean launchPymol()
127 if (pymolManager.isPymolLaunched())
132 boolean launched = pymolManager.launchPymol();
135 // start listening for PyMOL selections - how??
139 System.err.println("Failed to launch PyMOL!");
144 public void openFile(PDBEntry pe)
146 // todo : check not already open, remap / rename, etc
147 String file = pe.getFile();
148 StructureCommandI cmd = getCommandGenerator().loadFile(file);
151 * a second parameter sets the pdbid as the loaded PyMOL object name
153 String pdbId = pe.getId();
154 cmd.addParameter(pdbId);
156 executeCommand(cmd, false);
158 pymolObjects.put(file, pdbId);
159 if (!structureFiles.contains(file))
161 structureFiles.add(file);
163 if (getSsm() != null)
165 getSsm().addStructureViewerListener(this);
171 protected String getModelId(int pdbfnum, String file)