3 import java.util.ArrayList;
4 import java.util.HashMap;
8 import jalview.api.AlignmentViewPanel;
9 import jalview.datamodel.PDBEntry;
10 import jalview.datamodel.SequenceI;
11 import jalview.ext.pymol.PymolCommands;
12 import jalview.ext.pymol.PymolManager;
13 import jalview.gui.StructureViewer.ViewerType;
14 import jalview.structure.AtomSpec;
15 import jalview.structure.StructureCommandI;
16 import jalview.structure.StructureSelectionManager;
17 import jalview.structures.models.AAStructureBindingModel;
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();
105 if (pymolMonitor != null)
107 pymolMonitor.interrupt();
109 releaseUIResources();
112 public boolean openSession(String pymolSessionFile)
114 StructureCommandI cmd = getCommandGenerator()
115 .loadFile(pymolSessionFile);
116 executeCommand(cmd, false);
120 public boolean launchPymol()
122 if (pymolManager.isPymolLaunched())
127 boolean launched = pymolManager.launchPymol();
130 // start listening for PyMOL selections - how??
134 System.err.println("Failed to launch PyMOL!");
139 public void openFile(PDBEntry pe)
141 // todo : check not already open, remap / rename, etc
142 String file = pe.getFile();
143 StructureCommandI cmd = getCommandGenerator().loadFile(file);
146 * a second parameter sets the pdbid as the loaded PyMOL object name
148 String pdbId = pe.getId();
149 cmd.addParameter(pdbId);
151 executeCommand(cmd, false);
153 pymolObjects.put(file, pdbId);
154 if (!structureFiles.contains(file))
156 structureFiles.add(file);
158 if (getSsm() != null)
160 getSsm().addStructureViewerListener(this);
166 protected String getModelId(int pdbfnum, String file)
172 * Returns the file extension to use for a saved viewer session file (.pse)
175 * @see https://pymolwiki.org/index.php/Save
178 public String getSessionFileExtension()