Skip to content

Commit b61555a

Browse files
committed
Commit local changes
1 parent 3fb85a2 commit b61555a

File tree

4 files changed

+90
-25
lines changed

4 files changed

+90
-25
lines changed

biojava-structure/src/main/java/org/biojava/nbio/structure/symmetry/internal/CeSymmIterative.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ private CeSymmResult reconstructSymmResult(Atom[] atoms)
270270

271271
// Set the transformations and scores of the final alignment
272272
SymmetryTools
273-
.updateSymmetryTransformation(result.getAxes(), msa, atoms);
273+
.updateSymmetryTransformation(result.getAxes(), msa);
274274
double tmScore = MultipleAlignmentScorer.getAvgTMScore(msa)
275275
* msa.size();
276276
double rmsd = MultipleAlignmentScorer.getRMSD(msa);

biojava-structure/src/main/java/org/biojava/nbio/structure/symmetry/internal/SymmOptimizer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ private void updateMultipleAlignment() throws StructureException,
351351
throw new RefinerFailedException(
352352
"Optimization converged to length 0");
353353

354-
SymmetryTools.updateSymmetryTransformation(axes, msa, atoms);
354+
SymmetryTools.updateSymmetryTransformation(axes, msa);
355355
}
356356

357357
/**

biojava-structure/src/main/java/org/biojava/nbio/structure/symmetry/internal/SymmetryAxes.java

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,8 @@ public List<List<Integer>> getRepeatRelation(int level, int firstRepeat) {
345345
int m = getNumRepeats(level+1);//size of the children
346346
int d = axis.getOrder(); // degree of this node
347347
int n = m*d; // number of repeats included
348-
if(firstRepeat % n != 0) {
348+
if(firstRepeat % n != 0)
349349
throw new IllegalArgumentException(String.format("Repeat %d cannot start a block at level %s of this tree",firstRepeat,level));
350-
}
351350
if(axis.getSymmType() == SymmetryType.OPEN) {
352351
n -= m; // leave off last child for open symm
353352
}
@@ -418,6 +417,7 @@ public static String getRepeatsCyclicForm(List<List<Integer>> cycleForm, List<?>
418417
}
419418
return str.toString();
420419
}
420+
421421
/**
422422
* Return the transformation that needs to be applied to a
423423
* repeat in order to superimpose onto repeat 0.
@@ -442,6 +442,43 @@ public Matrix4d getRepeatTransform(int repeat){
442442
}
443443
return transform;
444444
}
445+
446+
/**
447+
* Return the transformation that needs to be applied to
448+
* repeat x in order to superimpose onto repeat y.
449+
*
450+
* @param x the first repeat index (transformed)
451+
* @param y the second repeat index (fixed)
452+
* @return transformation matrix for the repeat x
453+
*/
454+
public Matrix4d getRepeatTransform(int x, int y){
455+
456+
Matrix4d transform = new Matrix4d();
457+
transform.setIdentity();
458+
459+
int[] iCounts = getAxisCounts(x);
460+
int[] jCounts = getAxisCounts(y);
461+
462+
int[] counts = new int[iCounts.length];
463+
for (int k = 0; k < iCounts.length; k++)
464+
counts[k] = iCounts[k] - jCounts[k];
465+
466+
for(int t = counts.length-1; t>=0; t--) {
467+
if(counts[t] == 0)
468+
continue;
469+
if (counts[t] > 0) {
470+
Matrix4d axis = new Matrix4d(axes.get(t).getOperator());
471+
for(int i=0;i<counts[t];i++)
472+
transform.mul(axis);
473+
} else if (counts[t] < 0) {
474+
Matrix4d axis = new Matrix4d(axes.get(t).getOperator());
475+
axis.invert();
476+
for(int i=0;i<counts[t];i++)
477+
transform.mul(axis);
478+
}
479+
}
480+
return transform;
481+
}
445482

446483
/**
447484
* Return all symmetry axes of of the structure: the set of axes that
@@ -536,6 +573,24 @@ private int getNumRepeats(int level) {
536573
}
537574
return size;
538575
}
576+
577+
/**
578+
* Get the first repeat index of each axis of a specified level.
579+
* @param level level of the tree to cut at
580+
* @return List of first Repeats of each index, sorted in ascending order
581+
*/
582+
public List<Integer> getFirstRepeats(int level) {
583+
List<Integer> firstRepeats = new ArrayList<Integer>();
584+
if (level == 0)
585+
firstRepeats.add(0); // No top level present
586+
else {
587+
int m = getNumRepeats(level);//size of the level
588+
int d = axes.get(level).getOrder(); // degree of this node
589+
for (int firstRepeat = 0; firstRepeat < m*d; firstRepeat+=d)
590+
firstRepeats.add(firstRepeat);
591+
}
592+
return firstRepeats;
593+
}
539594

540595
public Axis getElementaryAxis(int level) {
541596
return axes.get(level);

biojava-structure/src/main/java/org/biojava/nbio/structure/symmetry/utils/SymmetryTools.java

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import javax.vecmath.Point3d;
3131

3232
import org.biojava.nbio.structure.Atom;
33+
import org.biojava.nbio.structure.Calc;
3334
import org.biojava.nbio.structure.Chain;
3435
import org.biojava.nbio.structure.ChainImpl;
3536
import org.biojava.nbio.structure.Group;
@@ -602,7 +603,7 @@ public static MultipleAlignment toRepeatsAlignment(CeSymmResult result)
602603

603604
for (Structure s : repSt)
604605
atomArrays.add(StructureTools.getRepresentativeAtomArray(s));
605-
606+
606607
newEnsemble.setAtomArrays(atomArrays);
607608

608609
for (int su = 0; su < block.size(); su++) {
@@ -689,6 +690,7 @@ public static MultipleAlignment fromAFP(AFPChain symm, Atom[] atoms)
689690
* error allowed in the axis comparison
690691
* @return true if equivalent, false otherwise
691692
*/
693+
@Deprecated
692694
public static boolean equivalentAxes(Matrix4d axis1, Matrix4d axis2,
693695
double epsilon) {
694696

@@ -795,6 +797,7 @@ else if (!corePos.contains(pos))
795797
* the symmetry alignment
796798
* @return true if the alignment is refined
797799
*/
800+
@Deprecated
798801
public static boolean isRefined(MultipleAlignment symm) {
799802

800803
if (symm.getBlocks().size() > 1) {
@@ -834,6 +837,7 @@ public static boolean isRefined(MultipleAlignment symm) {
834837
* @return
835838
* @throws StructureException
836839
*/
840+
@Deprecated
837841
public static boolean isSignificant(MultipleAlignment msa,
838842
double symmetryThreshold) throws StructureException {
839843

@@ -892,36 +896,42 @@ public static List<Group> getGroups(Atom[] rAtoms) {
892896
* SymmetryAxes object. It will be modified.
893897
* @param msa
894898
* MultipleAlignment. It will be modified.
895-
* @param atoms
896-
* Atom array of the structure
897899
*/
898900
public static void updateSymmetryTransformation(SymmetryAxes axes,
899-
MultipleAlignment msa, Atom[] atoms) throws StructureException {
901+
MultipleAlignment msa) throws StructureException {
900902

901903
List<List<Integer>> block = msa.getBlocks().get(0).getAlignRes();
902904
int length = block.get(0).size();
905+
Atom[] atoms = StructureTools.cloneAtomArray(msa.getEnsemble()
906+
.getAtomArrays().get(0));
903907

904908
if (axes != null) {
905-
for (int t = 0; t < axes.getElementaryAxes().size(); t++) {
909+
for (int level = 0; level < axes.getNumLevels(); level++) {
906910

907-
Matrix4d axis = axes.getElementaryAxes().get(t);
908-
List<Integer> chain1 = axes.getRepeatRelation(t).get(0);
909-
List<Integer> chain2 = axes.getRepeatRelation(t).get(1);
910-
911-
// Calculate the aligned atom arrays
911+
// Calculate the aligned atom arrays to superimpose
912912
List<Atom> list1 = new ArrayList<Atom>();
913913
List<Atom> list2 = new ArrayList<Atom>();
914914

915-
for (int pair = 0; pair < chain1.size(); pair++) {
916-
int p1 = chain1.get(pair);
917-
int p2 = chain2.get(pair);
915+
for (int firstRepeat : axes.getFirstRepeats(level)) {
916+
917+
Matrix4d transform = axes.getRepeatTransform(firstRepeat);
918918

919-
for (int k = 0; k < length; k++) {
920-
Integer pos1 = block.get(p1).get(k);
921-
Integer pos2 = block.get(p2).get(k);
922-
if (pos1 != null && pos2 != null) {
923-
list1.add(atoms[pos1]);
924-
list2.add(atoms[pos2]);
919+
List<List<Integer>> relation = axes.getRepeatRelation(
920+
level, firstRepeat);
921+
922+
for (int index = 0; index < relation.get(0).size(); index++) {
923+
int p1 = relation.get(0).get(index);
924+
int p2 = relation.get(1).get(index);
925+
926+
for (int k = 0; k < length; k++) {
927+
Integer pos1 = block.get(p1).get(k);
928+
Integer pos2 = block.get(p2).get(k);
929+
if (pos1 != null && pos2 != null) {
930+
Calc.transform(atoms[pos1], transform);
931+
Calc.transform(atoms[pos2], transform);
932+
list1.add(atoms[pos1]);
933+
list2.add(atoms[pos2]);
934+
}
925935
}
926936
}
927937
}
@@ -932,8 +942,8 @@ public static void updateSymmetryTransformation(SymmetryAxes axes,
932942
// Calculate the new transformation information
933943
if (arr1.length > 0 && arr2.length > 0) {
934944
SVDSuperimposer svd = new SVDSuperimposer(arr1, arr2);
935-
axis = svd.getTransformation();
936-
axes.updateAxis(t, axis);
945+
Matrix4d axis = svd.getTransformation();
946+
axes.updateAxis(level, axis);
937947
}
938948

939949
// Get the transformations from the SymmetryAxes

0 commit comments

Comments
 (0)