Skip to content

Commit 349d4e1

Browse files
authored
Merge pull request #507 from sbliven/pointgroups2
Symmetry Axes Refactoring
2 parents 3fea9a9 + 0756453 commit 349d4e1

File tree

13 files changed

+1119
-443
lines changed

13 files changed

+1119
-443
lines changed

biojava-structure-gui/src/main/java/org/biojava/nbio/structure/align/gui/jmol/MultipleAlignmentJmol.java

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@
4848
import org.biojava.nbio.structure.StructureException;
4949
import org.biojava.nbio.structure.StructureIdentifier;
5050
import org.biojava.nbio.structure.align.gui.MenuCreator;
51-
import org.biojava.nbio.structure.align.gui.MultipleAlignmentJmolDisplay;
5251
import org.biojava.nbio.structure.align.gui.MultipleAlignmentGUI;
52+
import org.biojava.nbio.structure.align.gui.MultipleAlignmentJmolDisplay;
5353
import org.biojava.nbio.structure.align.multiple.Block;
5454
import org.biojava.nbio.structure.align.multiple.BlockSet;
5555
import org.biojava.nbio.structure.align.multiple.MultipleAlignment;
@@ -78,8 +78,7 @@ public class MultipleAlignmentJmol extends AbstractAlignmentJmol {
7878
private JCheckBox colorByBlocks;
7979
private List<JCheckBox> selectedStructures;
8080

81-
private static final String LIGAND_DISPLAY_SCRIPT =
82-
"select ligand; wireframe 40; spacefill 120; color CPK;";
81+
private static final String LIGAND_DISPLAY_SCRIPT = "select ligand; wireframe 40; spacefill 120; color CPK;";
8382

8483
private static final Logger logger = LoggerFactory
8584
.getLogger(MultipleAlignmentJmol.class);
@@ -162,17 +161,19 @@ public void windowClosing(WindowEvent e) {
162161

163162
// / STRUCTURE SELECTION
164163
if (multAln != null) {
165-
Box hBox0 = Box.createHorizontalBox();
166-
hBox0.setMaximumSize(new Dimension(Short.MAX_VALUE, 30));
167164

165+
Box hBox00 = Box.createHorizontalBox();
166+
hBox00.setMaximumSize(new Dimension(Short.MAX_VALUE, 30));
167+
168168
JButton show = new JButton("Show Only: ");
169169
show.addActionListener(new ActionListener() {
170170

171171
@Override
172172
public void actionPerformed(ActionEvent e) {
173173
jmolPanel.evalString("save selection;");
174-
String cmd = getJmolString(multAln, transformedAtoms,
175-
colorPalette, colorByBlocks.isSelected());
174+
String cmd = getJmolString(multAln,
175+
transformedAtoms, colorPalette,
176+
colorByBlocks.isSelected());
176177
cmd += "; restrict ";
177178
for (int st = 0; st < multAln.size(); st++) {
178179
if (selectedStructures.get(st).isSelected()) {
@@ -183,21 +184,28 @@ public void actionPerformed(ActionEvent e) {
183184
jmolPanel.executeCmd(cmd + " restore selection;");
184185
}
185186
});
187+
hBox00.add(show);
188+
hBox00.add(Box.createGlue());
189+
vBox.add(hBox00);
190+
191+
// A line of structures of maximum 5
192+
for (int line = 0; line < 1 + (multAln.size() / 5); line++) {
193+
Box hBox0 = Box.createHorizontalBox();
194+
hBox0.setMaximumSize(new Dimension(Short.MAX_VALUE, 30));
195+
196+
for (int str = line * 5; str < Math.min((line + 1) * 5,
197+
multAln.size()); str++) {
198+
JCheckBox structureSelection = new JCheckBox(multAln
199+
.getEnsemble().getStructureIdentifiers().get(str)
200+
.getIdentifier());
201+
hBox0.add(structureSelection);
202+
hBox0.add(Box.createGlue());
203+
structureSelection.setSelected(true);
204+
selectedStructures.add(structureSelection);
205+
}
186206

187-
hBox0.add(show);
188-
hBox0.add(Box.createGlue());
189-
190-
for (int str = 0; str < multAln.size(); str++) {
191-
JCheckBox structureSelection = new JCheckBox(multAln
192-
.getEnsemble().getStructureIdentifiers().get(str)
193-
.getIdentifier());
194-
hBox0.add(structureSelection);
195-
hBox0.add(Box.createGlue());
196-
structureSelection.setSelected(true);
197-
selectedStructures.add(structureSelection);
207+
vBox.add(hBox0);
198208
}
199-
200-
vBox.add(hBox0);
201209
}
202210

203211
// / COMBO BOXES
@@ -260,7 +268,6 @@ public void actionPerformed(ActionEvent e) {
260268

261269
// / CHECK BOXES
262270
Box hBox2 = Box.createHorizontalBox();
263-
hBox2.setMaximumSize(new Dimension(Short.MAX_VALUE, 30));
264271

265272
JButton resetDisplay = new JButton("Reset Display");
266273
resetDisplay.addActionListener(new ActionListener() {
@@ -414,12 +421,12 @@ public void actionPerformed(ActionEvent ae) {
414421
// Kimura, Structural and Fractional Dissimilarity Score
415422
Phylogeny kimura = MultipleAlignmentTools
416423
.getKimuraTree(multAln);
417-
Phylogeny sdm = MultipleAlignmentTools
418-
.getHSDMTree(multAln);
424+
Phylogeny sdm = MultipleAlignmentTools.getHSDMTree(multAln);
419425
// Phylogeny structural = MultipleAlignmentTools
420-
// .getStructuralTree(multAln);
426+
// .getStructuralTree(multAln);
421427

422-
Archaeopteryx.createApplication(new Phylogeny[] { kimura, sdm });
428+
Archaeopteryx
429+
.createApplication(new Phylogeny[] { kimura, sdm });
423430
}
424431
} catch (Exception e) {
425432
logger.error("Could not complete display option.", e);

biojava-structure-gui/src/main/java/org/biojava/nbio/structure/symmetry/gui/SymmetryDisplay.java

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,25 @@
2424
import java.util.ArrayList;
2525
import java.util.Arrays;
2626
import java.util.List;
27-
import java.util.Set;
28-
import java.util.TreeSet;
29-
3027
import javax.swing.JMenu;
3128
import javax.swing.JMenuBar;
3229
import javax.swing.JMenuItem;
33-
import javax.vecmath.Matrix4d;
3430

3531
import org.biojava.nbio.structure.Atom;
3632
import org.biojava.nbio.structure.Group;
3733
import org.biojava.nbio.structure.StructureException;
3834
import org.biojava.nbio.structure.StructureTools;
35+
import org.biojava.nbio.structure.align.gui.MultipleAlignmentJmolDisplay;
3936
import org.biojava.nbio.structure.align.gui.StructureAlignmentDisplay;
4037
import org.biojava.nbio.structure.align.gui.jmol.AbstractAlignmentJmol;
41-
import org.biojava.nbio.structure.align.gui.MultipleAlignmentJmolDisplay;
4238
import org.biojava.nbio.structure.align.gui.jmol.MultipleAlignmentJmol;
4339
import org.biojava.nbio.structure.align.multiple.MultipleAlignment;
4440
import org.biojava.nbio.structure.align.util.RotationAxis;
4541
import org.biojava.nbio.structure.symmetry.core.AxisAligner;
4642
import org.biojava.nbio.structure.symmetry.core.QuatSymmetryResults;
4743
import org.biojava.nbio.structure.symmetry.internal.CeSymmResult;
4844
import org.biojava.nbio.structure.symmetry.internal.SymmetryAxes;
45+
import org.biojava.nbio.structure.symmetry.internal.SymmetryAxes.Axis;
4946
import org.biojava.nbio.structure.symmetry.jmolScript.JmolSymmetryScriptGenerator;
5047
import org.biojava.nbio.structure.symmetry.jmolScript.JmolSymmetryScriptGeneratorPointGroup;
5148
import org.biojava.nbio.structure.symmetry.utils.SymmetryTools;
@@ -208,22 +205,43 @@ private static void addSymmetryMenu(MultipleAlignmentJmol jmol,
208205
*/
209206
public static String printSymmetryAxes(CeSymmResult symm)
210207
throws StructureException {
208+
return printSymmetryAxes(symm,true);
209+
}
210+
211+
/**
212+
* Generates a String that displays the symmetry axes of a structure.
213+
*
214+
* @param symm
215+
* CeSymmResult
216+
* @param allAxes Indicates whether all axes should be displayed or just
217+
* the elemenatary ones
218+
* @return
219+
* @throws StructureException
220+
*/
221+
public static String printSymmetryAxes(CeSymmResult symm,boolean allAxes)
222+
throws StructureException {
211223

212224
int id = 0;
213225
String script = "";
214226
SymmetryAxes axes = symm.getAxes();
215227
List<Atom[]> repeats = SymmetryTools.toRepeatsAlignment(symm)
216228
.getAtomArrays();
217229

218-
List<Matrix4d> symmAxes = axes.getElementaryAxes();
219-
for (int a = 0; a < symmAxes.size(); a++) {
220-
RotationAxis rot = new RotationAxis(symmAxes.get(a));
221-
Set<Integer> repIndex = new TreeSet<Integer>(axes
222-
.getRepeatRelation(a).get(0));
223-
repIndex.addAll(axes.getRepeatRelation(a).get(1));
230+
List<Axis> symmAxes;
231+
if(allAxes) {
232+
symmAxes = axes.getSymmetryAxes();
233+
} else {
234+
symmAxes= axes.getElementaryAxesObjects();
235+
}
236+
for (Axis a : symmAxes) {
237+
RotationAxis rot = a.getRotationAxis();
238+
List<List<Integer>> cyclicForm = axes.getRepeatsCyclicForm(a);
224239
List<Atom> repAtoms = new ArrayList<Atom>();
225-
for (Integer r : repIndex)
226-
repAtoms.addAll(Arrays.asList(repeats.get(r)));
240+
for(List<Integer> cycle : cyclicForm) {
241+
for(Integer repeat : cycle) {
242+
repAtoms.addAll(Arrays.asList(repeats.get(repeat)));
243+
}
244+
}
227245

228246
script += rot.getJmolScript(
229247
repAtoms.toArray(new Atom[repAtoms.size()]), id);

biojava-structure-gui/src/main/java/org/biojava/nbio/structure/symmetry/gui/SymmetryListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public void actionPerformed(ActionEvent ae) {
6666
try {
6767
if (cmd.equals("Repeats Superposition")) {
6868
MultipleAlignmentJmol j = SymmetryDisplay.displayRepeats(symm);
69-
String s = SymmetryDisplay.printSymmetryAxes(symm);
69+
String s = SymmetryDisplay.printSymmetryAxes(symm, false);
7070
j.evalString(s);
7171

7272
} else if (cmd.equals("Multiple Structure Alignment")) {

biojava-structure/src/main/java/org/biojava/nbio/structure/BioAssemblyIdentifier.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ public Structure loadStructure(AtomCache cache) throws StructureException,
7272

7373
@Override
7474
public SubstructureIdentifier toCanonical() throws StructureException {
75-
// null pdbCode indicates that the structure can't be loaded by AtomCache
76-
return new SubstructureIdentifier(null, new ArrayList<ResidueRange>());
75+
return new SubstructureIdentifier(pdbCode, new ArrayList<ResidueRange>());
7776
}
7877

7978
@Override

biojava-structure/src/main/java/org/biojava/nbio/structure/align/util/RotationAxis.java

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.biojava.nbio.structure.Calc;
2626
import org.biojava.nbio.structure.StructureException;
2727
import org.biojava.nbio.structure.align.model.AFPChain;
28+
import org.biojava.nbio.structure.contact.Pair;
2829
import org.biojava.nbio.structure.jama.Matrix;
2930

3031
import javax.vecmath.AxisAngle4d;
@@ -112,6 +113,10 @@ public Atom getScrewTranslation() {
112113
public Vector3d getVector3dScrewTranslation() {
113114
return new Vector3d(screwTranslation.getX(),screwTranslation.getY(),screwTranslation.getZ());
114115
}
116+
117+
public double getTranslation() {
118+
return Calc.amount(screwTranslation);
119+
}
115120

116121
/**
117122
* Get the component of translation perpendicular to the axis of rotation.
@@ -385,27 +390,17 @@ public String getJmolScript(Atom[] atoms){
385390
}
386391

387392
/**
388-
* Returns a Jmol script which will display the axis of rotation. This
389-
* consists of a cyan arrow along the axis, plus an arc showing the angle
390-
* of rotation.
393+
* Find a segment of the axis that covers the specified set of atoms.
391394
* <p>
392-
* As the rotation angle gets smaller, the axis of rotation becomes poorly
393-
* defined and would need to get farther and farther away from the protein.
394-
* This is not particularly useful, so we arbitrarily draw it parallel to
395-
* the translation and omit the arc.
396-
* @param atoms Some atoms from the protein, used for determining the bounds
397-
* of the axis.
398-
* @param axisID in case of representing more than one axis in the same jmol
399-
* panel, indicate the ID number.
400-
*
401-
* @return The Jmol script, suitable for calls to
402-
* {@link org.biojava.nbio.structure.align.gui.jmol.StructureAlignmentJmol#evalString() jmol.evalString()}
395+
* Projects the input atoms onto the rotation axis and returns the bounding
396+
* points.
397+
* <p>
398+
* In the case of a pure translational axis, the axis location is undefined
399+
* so the center of mass will be used instead.
400+
* @param atoms
401+
* @return two points defining the axis segment
403402
*/
404-
public String getJmolScript(Atom[] atoms, int axisID){
405-
final double width=.5;// width of JMol object
406-
final String axisColor = "yellow"; //axis color
407-
final String screwColor = "orange"; //screw translation color
408-
403+
public Pair<Atom> getAxisEnds(Atom[] atoms) {
409404
// Project each Atom onto the rotation axis to determine limits
410405
double min, max;
411406
min = max = Calc.scalarProduct(rotationAxis,atoms[0]);
@@ -417,7 +412,7 @@ public String getJmolScript(Atom[] atoms, int axisID){
417412
double uLen = Calc.scalarProduct(rotationAxis,rotationAxis);// Should be 1, but double check
418413
min/=uLen;
419414
max/=uLen;
420-
415+
421416
// Project the origin onto the axis. If the axis is undefined, use the center of mass
422417
Atom axialPt;
423418
if(rotationPos == null) {
@@ -439,6 +434,34 @@ public String getJmolScript(Atom[] atoms, int axisID){
439434
Atom axisMax = (Atom) axialPt.clone();
440435
Calc.scaleAdd(max, rotationAxis, axisMax);
441436

437+
return new Pair<>(axisMin, axisMax);
438+
}
439+
/**
440+
* Returns a Jmol script which will display the axis of rotation. This
441+
* consists of a cyan arrow along the axis, plus an arc showing the angle
442+
* of rotation.
443+
* <p>
444+
* As the rotation angle gets smaller, the axis of rotation becomes poorly
445+
* defined and would need to get farther and farther away from the protein.
446+
* This is not particularly useful, so we arbitrarily draw it parallel to
447+
* the translation and omit the arc.
448+
* @param atoms Some atoms from the protein, used for determining the bounds
449+
* of the axis.
450+
* @param axisID in case of representing more than one axis in the same jmol
451+
* panel, indicate the ID number.
452+
*
453+
* @return The Jmol script, suitable for calls to
454+
* {@link org.biojava.nbio.structure.align.gui.jmol.StructureAlignmentJmol#evalString() jmol.evalString()}
455+
*/
456+
public String getJmolScript(Atom[] atoms, int axisID){
457+
final double width=.5;// width of JMol object
458+
final String axisColor = "yellow"; //axis color
459+
final String screwColor = "orange"; //screw translation color
460+
461+
Pair<Atom> endPoints = getAxisEnds(atoms);
462+
Atom axisMin = endPoints.getFirst();
463+
Atom axisMax = endPoints.getSecond();
464+
442465
StringWriter result = new StringWriter();
443466

444467
// set arrow heads to a reasonable length

0 commit comments

Comments
 (0)