| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
package jalview.gui; |
| 22 |
|
|
| 23 |
|
import java.util.ArrayList; |
| 24 |
|
import java.util.HashMap; |
| 25 |
|
import java.util.List; |
| 26 |
|
import java.util.Map; |
| 27 |
|
|
| 28 |
|
import jalview.api.AlignmentViewPanel; |
| 29 |
|
import jalview.bin.Console; |
| 30 |
|
import jalview.datamodel.PDBEntry; |
| 31 |
|
import jalview.datamodel.SequenceI; |
| 32 |
|
import jalview.ext.pymol.PymolCommands; |
| 33 |
|
import jalview.ext.pymol.PymolManager; |
| 34 |
|
import jalview.gui.StructureViewer.ViewerType; |
| 35 |
|
import jalview.structure.AtomSpec; |
| 36 |
|
import jalview.structure.AtomSpecModel; |
| 37 |
|
import jalview.structure.StructureCommand; |
| 38 |
|
import jalview.structure.StructureCommandI; |
| 39 |
|
import jalview.structure.StructureSelectionManager; |
| 40 |
|
import jalview.structures.models.AAStructureBindingModel; |
| 41 |
|
|
| |
|
| 0% |
Uncovered Elements: 83 (83) |
Complexity: 24 |
Complexity Density: 0.44 |
|
| 42 |
|
public class PymolBindingModel extends AAStructureBindingModel |
| 43 |
|
{ |
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
private static String LABEL_FORMAT = "\"%s %s\" % (resn,resi)"; |
| 50 |
|
|
| 51 |
|
private PymolManager pymolManager; |
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
| 56 |
|
List<String> structureFiles = new ArrayList<>(); |
| 57 |
|
|
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 61 |
|
Map<String, String> pymolObjects = new HashMap<>(); |
| 62 |
|
|
| 63 |
|
private String lastLabelSpec; |
| 64 |
|
|
| 65 |
|
|
| 66 |
|
|
| 67 |
|
|
| 68 |
|
@param |
| 69 |
|
@param |
| 70 |
|
@param |
| 71 |
|
@param |
| 72 |
|
|
| |
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 73 |
0 |
public PymolBindingModel(StructureViewerBase viewer,... |
| 74 |
|
StructureSelectionManager ssm, PDBEntry[] pdbentry, |
| 75 |
|
SequenceI[][] sequenceIs) |
| 76 |
|
{ |
| 77 |
0 |
super(ssm, pdbentry, sequenceIs, null); |
| 78 |
0 |
pymolManager = new PymolManager(); |
| 79 |
0 |
setStructureCommands(new PymolCommands()); |
| 80 |
0 |
setViewer(viewer); |
| 81 |
|
} |
| 82 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 83 |
0 |
@Override... |
| 84 |
|
public String[] getStructureFiles() |
| 85 |
|
{ |
| 86 |
0 |
return structureFiles.toArray(new String[structureFiles.size()]); |
| 87 |
|
} |
| 88 |
|
|
| |
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 2 |
Complexity Density: 0.2 |
|
| 89 |
0 |
@Override... |
| 90 |
|
public void highlightAtoms(List<AtomSpec> atoms) |
| 91 |
|
{ |
| 92 |
|
|
| 93 |
|
|
| 94 |
|
|
| 95 |
0 |
StringBuilder sb = new StringBuilder(); |
| 96 |
0 |
for (AtomSpec atom : atoms) |
| 97 |
|
{ |
| 98 |
|
|
| 99 |
0 |
String modelId = getModelIdForFile(atom.getPdbFile()); |
| 100 |
0 |
sb.append(String.format(" %s//%s/%d/*", modelId, atom.getChain(), |
| 101 |
|
atom.getPdbResNum())); |
| 102 |
|
} |
| 103 |
0 |
String labelSpec = sb.toString(); |
| 104 |
0 |
if (labelSpec.equals(lastLabelSpec)) |
| 105 |
|
{ |
| 106 |
0 |
return; |
| 107 |
|
} |
| 108 |
0 |
StructureCommandI command = new StructureCommand("indicate", labelSpec); |
| 109 |
0 |
executeCommand(command, false); |
| 110 |
|
|
| 111 |
0 |
lastLabelSpec = labelSpec; |
| 112 |
|
} |
| 113 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 114 |
0 |
@Override... |
| 115 |
|
public SequenceRenderer getSequenceRenderer(AlignmentViewPanel avp) |
| 116 |
|
{ |
| 117 |
0 |
return new SequenceRenderer(avp.getAlignViewport()); |
| 118 |
|
} |
| 119 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 120 |
0 |
@Override... |
| 121 |
|
protected List<String> executeCommand(StructureCommandI command, |
| 122 |
|
boolean getReply) |
| 123 |
|
{ |
| 124 |
|
|
| 125 |
0 |
return pymolManager.sendCommand(command, getReply); |
| 126 |
|
} |
| 127 |
|
|
| |
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 2 |
|
| 128 |
0 |
@Override... |
| 129 |
|
protected String getModelIdForFile(String file) |
| 130 |
|
{ |
| 131 |
0 |
return pymolObjects.containsKey(file) ? pymolObjects.get(file) : ""; |
| 132 |
|
} |
| 133 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 134 |
0 |
@Override... |
| 135 |
|
protected ViewerType getViewerType() |
| 136 |
|
{ |
| 137 |
0 |
return ViewerType.PYMOL; |
| 138 |
|
} |
| 139 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 140 |
0 |
@Override... |
| 141 |
|
public boolean isViewerRunning() |
| 142 |
|
{ |
| 143 |
0 |
return pymolManager != null && pymolManager.isPymolLaunched(); |
| 144 |
|
} |
| 145 |
|
|
| |
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 146 |
0 |
@Override... |
| 147 |
|
public void closeViewer(boolean closePymol) |
| 148 |
|
{ |
| 149 |
0 |
super.closeViewer(closePymol); |
| 150 |
0 |
pymolManager = null; |
| 151 |
|
} |
| 152 |
|
|
| |
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
| 153 |
0 |
public boolean launchPymol()... |
| 154 |
|
{ |
| 155 |
0 |
if (pymolManager.isPymolLaunched()) |
| 156 |
|
{ |
| 157 |
0 |
return true; |
| 158 |
|
} |
| 159 |
|
|
| 160 |
0 |
Process pymol = pymolManager.launchPymol(); |
| 161 |
0 |
if (pymol != null) |
| 162 |
|
{ |
| 163 |
|
|
| 164 |
0 |
startExternalViewerMonitor(pymol); |
| 165 |
|
} |
| 166 |
|
else |
| 167 |
|
{ |
| 168 |
0 |
Console.error("Failed to launch PyMOL!"); |
| 169 |
|
} |
| 170 |
0 |
return pymol != null; |
| 171 |
|
} |
| 172 |
|
|
| |
|
| 0% |
Uncovered Elements: 24 (24) |
Complexity: 6 |
Complexity Density: 0.33 |
|
| 173 |
0 |
public void openFile(PDBEntry pe)... |
| 174 |
|
{ |
| 175 |
|
|
| 176 |
0 |
String file = pe.getFile(); |
| 177 |
0 |
StructureCommandI cmd = getCommandGenerator().loadFile(file); |
| 178 |
|
|
| 179 |
|
|
| 180 |
|
|
| 181 |
|
|
| 182 |
0 |
String pdbId = pe.getId(); |
| 183 |
0 |
try |
| 184 |
|
{ |
| 185 |
0 |
String safePDBId = java.net.URLEncoder.encode(pdbId, "UTF-8"); |
| 186 |
0 |
pdbId = safePDBId.replace('%', '_'); |
| 187 |
0 |
pdbId = pdbId.replace("-", "__"); |
| 188 |
0 |
char fc = pdbId.charAt(0); |
| 189 |
|
|
| 190 |
0 |
if (fc >= '0' && fc <= '9') |
| 191 |
|
{ |
| 192 |
0 |
pdbId = 's' + pdbId; |
| 193 |
|
} |
| 194 |
|
|
| 195 |
|
} catch (Exception x) |
| 196 |
|
{ |
| 197 |
0 |
Console.error("Unxpected encoding exception for '" + pdbId + "'", x); |
| 198 |
|
} |
| 199 |
0 |
cmd.addParameter(pdbId); |
| 200 |
|
|
| 201 |
0 |
executeCommand(cmd, false); |
| 202 |
|
|
| 203 |
0 |
pymolObjects.put(file, pdbId); |
| 204 |
0 |
if (!structureFiles.contains(file)) |
| 205 |
|
{ |
| 206 |
0 |
structureFiles.add(file); |
| 207 |
|
} |
| 208 |
0 |
if (getSsm() != null) |
| 209 |
|
{ |
| 210 |
0 |
getSsm().addStructureViewerListener(this); |
| 211 |
|
} |
| 212 |
|
|
| 213 |
|
} |
| 214 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 215 |
0 |
@Override... |
| 216 |
|
protected String getModelId(int pdbfnum, String file) |
| 217 |
|
{ |
| 218 |
0 |
return file; |
| 219 |
|
} |
| 220 |
|
|
| 221 |
|
|
| 222 |
|
|
| 223 |
|
|
| 224 |
|
@return |
| 225 |
|
@see |
| 226 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 227 |
0 |
@Override... |
| 228 |
|
public String getSessionFileExtension() |
| 229 |
|
{ |
| 230 |
0 |
return ".pse"; |
| 231 |
|
} |
| 232 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 233 |
0 |
@Override... |
| 234 |
|
public String getHelpURL() |
| 235 |
|
{ |
| 236 |
0 |
return "https://pymolwiki.org/"; |
| 237 |
|
} |
| 238 |
|
|
| 239 |
|
|
| 240 |
|
|
| 241 |
|
|
| 242 |
|
|
| 243 |
|
@param |
| 244 |
|
@return |
| 245 |
|
|
| |
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
| 246 |
0 |
public int sendFeaturesToViewer(AlignmentViewPanel avp)... |
| 247 |
|
{ |
| 248 |
|
|
| 249 |
0 |
Map<String, Map<Object, AtomSpecModel>> featureValues = buildFeaturesMap( |
| 250 |
|
avp); |
| 251 |
0 |
List<StructureCommandI> commands = getCommandGenerator() |
| 252 |
|
.setAttributes(featureValues); |
| 253 |
0 |
executeCommands(commands, false, null); |
| 254 |
0 |
return commands.size(); |
| 255 |
|
} |
| 256 |
|
|
| 257 |
|
} |