Skip to content

Commit 523920e

Browse files
committed
Modifications from the SuperPosition changes w compile errors
1 parent ed41a52 commit 523920e

31 files changed

Lines changed: 224 additions & 82 deletions

biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/StructureTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
package org.biojava.nbio.structure.test;
2222

2323
import org.biojava.nbio.structure.*;
24+
import org.biojava.nbio.structure.geometry.SuperPositionSVD;
2425
import org.biojava.nbio.structure.io.FileParsingParameters;
2526
import org.biojava.nbio.structure.io.PDBFileParser;
2627
import org.biojava.nbio.structure.io.SSBondImpl;
@@ -267,7 +268,7 @@ public void testMutation() throws Exception {
267268
atoms2[2] = g2.getAtom("CB");
268269

269270

270-
SVDSuperimposer svds = new SVDSuperimposer(atoms1,atoms2);
271+
SuperPositionSVD svds = new SuperPositionSVD(atoms1,atoms2);
271272

272273

273274
Matrix rotMatrix = svds.getRotation();

biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/align/FlipAFPChainTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
package org.biojava.nbio.structure.test.align;
2626

2727
import junit.framework.TestCase;
28+
2829
import org.biojava.nbio.structure.*;
2930
import org.biojava.nbio.structure.align.StructureAlignment;
3031
import org.biojava.nbio.structure.align.StructureAlignmentFactory;
@@ -36,6 +37,7 @@
3637
import org.biojava.nbio.structure.align.xml.AFPChainFlipper;
3738
import org.biojava.nbio.structure.align.xml.AFPChainXMLConverter;
3839
import org.biojava.nbio.structure.align.xml.AFPChainXMLParser;
40+
import org.biojava.nbio.structure.geometry.SuperPositionSVD;
3941
import org.biojava.nbio.structure.jama.Matrix;
4042

4143
import java.io.IOException;
@@ -150,7 +152,7 @@ private double getRMSD(AFPChain afpChain, Atom[] ca1, Atom[] ca2)
150152

151153
assertTrue(catmp1.length == afpChain.getNrEQR());
152154

153-
return SVDSuperimposer.getRMS(catmp1,catmp2);
155+
return SuperPositionSVD.getRMS(catmp1,catmp2);
154156
}
155157

156158
public static void rotateAtoms2(AFPChain afpChain,Atom[] ca2){

biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/align/fatcat/FlipAFPChainTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
package org.biojava.nbio.structure.test.align.fatcat;
2626

2727
import junit.framework.TestCase;
28+
2829
import org.biojava.nbio.structure.*;
2930
import org.biojava.nbio.structure.align.StructureAlignment;
3031
import org.biojava.nbio.structure.align.StructureAlignmentFactory;
@@ -40,6 +41,7 @@
4041
import org.biojava.nbio.structure.align.xml.AFPChainFlipper;
4142
import org.biojava.nbio.structure.align.xml.AFPChainXMLConverter;
4243
import org.biojava.nbio.structure.align.xml.AFPChainXMLParser;
44+
import org.biojava.nbio.structure.geometry.SuperPositionSVD;
4345
import org.biojava.nbio.structure.jama.Matrix;
4446

4547
import java.io.IOException;
@@ -171,7 +173,7 @@ private double getRMSD(AFPChain afpChain, Atom[] ca1, Atom[] ca2)
171173

172174
assertTrue(catmp1.length == afpChain.getNrEQR());
173175

174-
return SVDSuperimposer.getRMS(catmp1,catmp2);
176+
return SuperPositionSVD.getRMS(catmp1,catmp2);
175177
}
176178

177179
public static void rotateAtoms2(AFPChain afpChain,Atom[] ca2){

biojava-integrationtest/src/test/java/org/biojava/nbio/structure/test/align/fatcat/TestFlexibleRotationMatrices.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
package org.biojava.nbio.structure.test.align.fatcat;
2626

2727
import junit.framework.TestCase;
28+
2829
import org.biojava.nbio.structure.*;
2930
import org.biojava.nbio.structure.align.StructureAlignment;
3031
import org.biojava.nbio.structure.align.fatcat.FatCatFlexible;
@@ -34,6 +35,7 @@
3435
import org.biojava.nbio.structure.align.util.AtomCache;
3536
import org.biojava.nbio.structure.align.xml.AFPChainXMLConverter;
3637
import org.biojava.nbio.structure.align.xml.AFPChainXMLParser;
38+
import org.biojava.nbio.structure.geometry.SuperPositionSVD;
3739
import org.biojava.nbio.structure.jama.Matrix;
3840

3941
import java.io.IOException;
@@ -200,7 +202,7 @@ private void compareBlock(int blockNr, AFPChain afpChain, AFPChain newChain,
200202
// calc RMSD
201203

202204

203-
double rmsdFile = SVDSuperimposer.getRMS(blockSet1, blockSet2);
205+
double rmsdFile = SuperPositionSVD.getRMS(blockSet1, blockSet2);
204206

205207
// this is the value from the file. it never seems to match precisely, probably is calculated from initial block.
206208
// we can't reproduce the initial block, since we don;t serialize it.
@@ -209,7 +211,7 @@ private void compareBlock(int blockNr, AFPChain afpChain, AFPChain newChain,
209211

210212
// THIS IS CALCULATING THE "correct" rotation matrix, that should be in the file
211213

212-
SVDSuperimposer svd = new SVDSuperimposer(blockSet1, blockSet2copy);
214+
SuperPositionSVD svd = new SuperPositionSVD(blockSet1, blockSet2copy);
213215
//double rmsdForce = SVDSuperimposer.getRMS(atomSet1, atomSet2);
214216
Matrix m = svd.getRotation();
215217
Atom s = svd.getTranslation();
@@ -231,7 +233,7 @@ private void compareBlock(int blockNr, AFPChain afpChain, AFPChain newChain,
231233
Calc.rotate(a, m);
232234
Calc.shift( a, s);
233235
}
234-
double rmsd3 = SVDSuperimposer.getRMS(blockSet1,blockSet2copy);
236+
double rmsd3 = SuperPositionSVD.getRMS(blockSet1,blockSet2copy);
235237

236238
assertTrue("The RMSD values don;t match after rotation / shift for block " + blockNr + "! should be: " + rmsd3 + " but found: " +rmsdFile, compareRmsd(rmsd3, rmsdFile));
237239

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

Lines changed: 130 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
package org.biojava.nbio.structure;
2424

2525
import org.biojava.nbio.structure.geometry.CalcPoint;
26+
import org.biojava.nbio.structure.geometry.SuperPositionSVD;
2627
import org.biojava.nbio.structure.jama.Matrix;
2728
import org.slf4j.Logger;
2829
import org.slf4j.LoggerFactory;
@@ -992,13 +993,14 @@ public static final Atom createVirtualCBAtom(AminoAcid amino)
992993
arr2[1] = amino.getCA();
993994
arr2[2] = amino.getC();
994995

995-
// ok now we got the two arrays, do a SVD:
996+
// ok now we got the two arrays, do a Superposition:
996997

997-
SVDSuperimposer svd = new SVDSuperimposer(arr2, arr1);
998-
999-
Matrix rotMatrix = svd.getRotation();
1000-
Atom tranMatrix = svd.getTranslation();
998+
SuperPositionSVD svd = new SuperPositionSVD(false);
1001999

1000+
Matrix4d transform = svd.superpose(arr1, arr2);
1001+
Matrix rotMatrix = getRotationMatrix(transform);
1002+
Atom tranMatrix = getTranslationVector(transform);
1003+
10021004
Calc.rotate(aCB, rotMatrix);
10031005

10041006
Atom virtualCB = Calc.add(aCB, tranMatrix);
@@ -1264,4 +1266,127 @@ public static Point3d[] atomsToPoints(Atom[] atoms) {
12641266
}
12651267
return points;
12661268
}
1269+
1270+
/**
1271+
* Calculate the RMSD of two Atom arrays, already superposed.
1272+
*
1273+
* @param x
1274+
* array of Atoms superposed to y
1275+
* @param y
1276+
* array of Atoms superposed to x
1277+
* @return RMSD
1278+
*/
1279+
public static double rmsd(Atom[] x, Atom[] y) {
1280+
return CalcPoint.rmsd(atomsToPoints(x), atomsToPoints(y));
1281+
}
1282+
1283+
/**
1284+
* Calculate the TM-Score for the superposition.
1285+
*
1286+
* <em>Normalizes by the <strong>maximum</strong>-length structure (that is, {@code max\{len1,len2\}}) rather than the minimum.</em>
1287+
*
1288+
* Atom sets must be superposed.
1289+
*
1290+
* <p>
1291+
* Citation:<br/>
1292+
* <i>Zhang Y and Skolnick J (2004). "Scoring function for automated
1293+
* assessment of protein structure template quality". Proteins 57: 702 -
1294+
* 710.</i>
1295+
*
1296+
* @param atomSet1
1297+
* atom array 1
1298+
* @param atomSet2
1299+
* atom array 2
1300+
* @param len1
1301+
* The full length of the protein supplying atomSet1
1302+
* @param len2
1303+
* The full length of the protein supplying atomSet2
1304+
* @return The TM-Score
1305+
* @throws StructureException
1306+
* @see {@link #getTMScore(Atom[], Atom[], int, int)}, which normalizes by
1307+
* the minimum length
1308+
*/
1309+
public static double getTMScoreAlternate(Atom[] atomSet1, Atom[] atomSet2,
1310+
int len1, int len2) throws StructureException {
1311+
if (atomSet1.length != atomSet2.length) {
1312+
throw new StructureException(
1313+
"The two atom sets are not of same length!");
1314+
}
1315+
if (atomSet1.length > len1) {
1316+
throw new StructureException(
1317+
"len1 must be greater or equal to the alignment length!");
1318+
}
1319+
if (atomSet2.length > len2) {
1320+
throw new StructureException(
1321+
"len2 must be greater or equal to the alignment length!");
1322+
}
1323+
1324+
int Lmax = Math.max(len1, len2);
1325+
int Laln = atomSet1.length;
1326+
1327+
double d0 = 1.24 * Math.cbrt(Lmax - 15.) - 1.8;
1328+
double d0sq = d0 * d0;
1329+
1330+
double sum = 0;
1331+
for (int i = 0; i < Laln; i++) {
1332+
double d = Calc.getDistance(atomSet1[i], atomSet2[i]);
1333+
sum += 1. / (1 + d * d / d0sq);
1334+
}
1335+
1336+
return sum / Lmax;
1337+
}
1338+
1339+
/**
1340+
* Calculate the TM-Score for the superposition.
1341+
*
1342+
* <em>Normalizes by the <strong>minimum</strong>-length structure (that is, {@code min\{len1,len2\}}).</em>
1343+
*
1344+
* Atom sets must be pre-rotated.
1345+
*
1346+
* <p>
1347+
* Citation:<br/>
1348+
* <i>Zhang Y and Skolnick J (2004). "Scoring function for automated
1349+
* assessment of protein structure template quality". Proteins 57: 702 -
1350+
* 710.</i>
1351+
*
1352+
* @param atomSet1
1353+
* atom array 1
1354+
* @param atomSet2
1355+
* atom array 2
1356+
* @param len1
1357+
* The full length of the protein supplying atomSet1
1358+
* @param len2
1359+
* The full length of the protein supplying atomSet2
1360+
* @return The TM-Score
1361+
* @throws StructureException
1362+
*/
1363+
public static double getTMScore(Atom[] atomSet1, Atom[] atomSet2, int len1,
1364+
int len2) throws StructureException {
1365+
if (atomSet1.length != atomSet2.length) {
1366+
throw new StructureException(
1367+
"The two atom sets are not of same length!");
1368+
}
1369+
if (atomSet1.length > len1) {
1370+
throw new StructureException(
1371+
"len1 must be greater or equal to the alignment length!");
1372+
}
1373+
if (atomSet2.length > len2) {
1374+
throw new StructureException(
1375+
"len2 must be greater or equal to the alignment length!");
1376+
}
1377+
1378+
int Lmin = Math.min(len1, len2);
1379+
int Laln = atomSet1.length;
1380+
1381+
double d0 = 1.24 * Math.cbrt(Lmin - 15.) - 1.8;
1382+
double d0sq = d0 * d0;
1383+
1384+
double sum = 0;
1385+
for (int i = 0; i < Laln; i++) {
1386+
double d = Calc.getDistance(atomSet1[i], atomSet2[i]);
1387+
sum += 1. / (1 + d * d / d0sq);
1388+
}
1389+
1390+
return sum / Lmin;
1391+
}
12671392
}

biojava-structure/src/main/java/org/biojava/nbio/structure/align/AFPTwister.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.biojava.nbio.structure.*;
3030
import org.biojava.nbio.structure.align.model.AFP;
3131
import org.biojava.nbio.structure.align.model.AFPChain;
32+
import org.biojava.nbio.structure.geometry.SuperPositionSVD;
3233
import org.biojava.nbio.structure.jama.Matrix;
3334
import org.slf4j.Logger;
3435
import org.slf4j.LoggerFactory;
@@ -249,7 +250,7 @@ private static void transformOrigPDB(int n, int[] res1, int[] res2, Atom[] ca1,
249250
Matrix r;
250251
Atom t;
251252

252-
SVDSuperimposer svd = new SVDSuperimposer(cod1, cod2);
253+
SuperPositionSVD svd = new SuperPositionSVD(cod1, cod2);
253254

254255
r = svd.getRotation();
255256
t = svd.getTranslation();
@@ -374,7 +375,7 @@ private static double calCaRmsd(Atom[] ca1, Atom[] pro, int resn, int[] res1, in
374375
logger.info("length of atoms == 0!");
375376
return 99;
376377
}
377-
SVDSuperimposer svd = new SVDSuperimposer(cod1, cod2);
378+
SuperPositionSVD svd = new SuperPositionSVD(cod1, cod2);
378379

379380
r = svd.getRotation();
380381
t = svd.getTranslation();
@@ -385,7 +386,7 @@ private static double calCaRmsd(Atom[] ca1, Atom[] pro, int resn, int[] res1, in
385386
Calc.shift(a.getGroup(), t);
386387
}
387388

388-
return SVDSuperimposer.getRMS(cod1, cod2);
389+
return SuperPositionSVD.getRMS(cod1, cod2);
389390
}
390391

391392
/**

biojava-structure/src/main/java/org/biojava/nbio/structure/align/StructurePairAligner.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.biojava.nbio.structure.align.helper.AlignTools;
2828
import org.biojava.nbio.structure.align.helper.JointFragments;
2929
import org.biojava.nbio.structure.align.pairwise.*;
30+
import org.biojava.nbio.structure.geometry.SuperPositionSVD;
3031
import org.biojava.nbio.structure.io.PDBFileParser;
3132
import org.biojava.nbio.structure.io.PDBFileReader;
3233
import org.biojava.nbio.structure.jama.Matrix;
@@ -474,7 +475,7 @@ public void align(Atom[] ca1, Atom[] ca2, StrucAligParameters params)
474475
f.setCenter1(center1);
475476
f.setCenter2(center2);
476477

477-
SVDSuperimposer svd = new SVDSuperimposer(catmp1,catmp2);
478+
SuperPositionSVD svd = new SuperPositionSVD(catmp1,catmp2);
478479
Matrix rotmat = svd.getRotation();
479480
f.setRot(rotmat);
480481

biojava-structure/src/main/java/org/biojava/nbio/structure/align/ce/CECalculator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929
import org.biojava.nbio.structure.Atom;
3030
import org.biojava.nbio.structure.Calc;
3131
import org.biojava.nbio.structure.Group;
32-
import org.biojava.nbio.structure.SVDSuperimposer;
3332
import org.biojava.nbio.structure.StructureException;
3433
import org.biojava.nbio.structure.StructureTools;
3534
import org.biojava.nbio.structure.align.model.AFP;
3635
import org.biojava.nbio.structure.align.model.AFPChain;
3736
import org.biojava.nbio.structure.align.util.AFPAlignmentDisplay;
37+
import org.biojava.nbio.structure.geometry.SuperPositionSVD;
3838
import org.biojava.nbio.structure.jama.Matrix;
3939
import org.biojava.nbio.core.sequence.compound.AminoAcidCompound;
4040
import org.biojava.nbio.core.sequence.compound.AminoAcidCompoundSet;
@@ -1912,7 +1912,7 @@ public double calc_rmsd(Atom[] pro1, Atom[] pro2, int strLen, boolean storeTrans
19121912
Atom[] cod2 = getAtoms(pro2, strLen,true);
19131913

19141914
assert(cod1.length == cod2.length);
1915-
SVDSuperimposer svd = new SVDSuperimposer(cod1, cod2);
1915+
SuperPositionSVD svd = new SuperPositionSVD(cod1, cod2);
19161916

19171917
Matrix matrix = svd.getRotation();
19181918
Atom shift = svd.getTranslation();
@@ -1925,7 +1925,7 @@ public double calc_rmsd(Atom[] pro1, Atom[] pro2, int strLen, boolean storeTrans
19251925
Calc.rotate(a.getGroup(), matrix);
19261926
Calc.shift(a.getGroup(), shift);
19271927
}
1928-
return SVDSuperimposer.getRMS(cod1, cod2);
1928+
return SuperPositionSVD.getRMS(cod1, cod2);
19291929

19301930
}
19311931

biojava-structure/src/main/java/org/biojava/nbio/structure/align/ce/CeCPMain.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.biojava.nbio.structure.align.model.AFPChain;
3030
import org.biojava.nbio.structure.align.util.AFPAlignmentDisplay;
3131
import org.biojava.nbio.structure.align.util.ConfigurationException;
32+
import org.biojava.nbio.structure.geometry.SuperPositionSVD;
3233
import org.biojava.nbio.structure.jama.Matrix;
3334

3435
import java.lang.reflect.InvocationTargetException;
@@ -492,7 +493,7 @@ public static AFPChain filterDuplicateAFPs(AFPChain afpChain, CECalculator ceCal
492493

493494
if(alignLen>0) {
494495
// superimpose
495-
SVDSuperimposer svd = new SVDSuperimposer(atoms1, atoms2);
496+
SuperPositionSVD svd = new SuperPositionSVD(atoms1, atoms2);
496497

497498
Matrix matrix = svd.getRotation();
498499
Atom shift = svd.getTranslation();
@@ -503,8 +504,8 @@ public static AFPChain filterDuplicateAFPs(AFPChain afpChain, CECalculator ceCal
503504
}
504505

505506
//and get overall rmsd
506-
rmsd = SVDSuperimposer.getRMS(atoms1, atoms2);
507-
tmScore = SVDSuperimposer.getTMScore(atoms1, atoms2, ca1.length, ca2len);
507+
rmsd = SuperPositionSVD.getRMS(atoms1, atoms2);
508+
tmScore = SuperPositionSVD.getTMScore(atoms1, atoms2, ca1.length, ca2len);
508509

509510
// set all block rotations to the overall rotation
510511
// It's not well documented if this is the expected behavior, but

0 commit comments

Comments
 (0)