Skip to content

Commit fe8c716

Browse files
committed
Fix and unit test for biojava#715
1 parent 56b9d07 commit fe8c716

File tree

2 files changed

+52
-0
lines changed
  • biojava-structure/src

2 files changed

+52
-0
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,11 @@ public static final void transform (Chain chain, Matrix4d m) {
521521
for (Atom atom: g.getAtoms()) {
522522
transform(atom,m);
523523
}
524+
for (Group altG : g.getAltLocs()) {
525+
for (Atom atom : altG.getAtoms()) {
526+
transform(atom, m);
527+
}
528+
}
524529
}
525530
}
526531

biojava-structure/src/test/java/org/biojava/nbio/structure/TestCalc.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,53 @@ public void testVecmathTransformation() {
156156

157157
assertEquals(expected, actual);
158158
}
159+
160+
/**
161+
* Issue https://github.com/biojava/biojava/issues/715
162+
*/
163+
@Test
164+
public void testChainTransform() {
165+
Group g = new AminoAcidImpl();
166+
Atom a = new AtomImpl();
167+
a.setName("CA");
168+
a.setX(1);
169+
a.setY(1);
170+
a.setZ(1);
171+
g.addAtom(a);
172+
Group altLocG = new AminoAcidImpl();
173+
Atom a2 = new AtomImpl();
174+
a2.setName("CA");
175+
a2.setX(2);
176+
a2.setY(2);
177+
a2.setZ(2);
178+
altLocG.addAtom(a2);
179+
180+
g.addAltLoc(altLocG);
181+
182+
Chain c = new ChainImpl();
183+
c.addGroup(g);
184+
185+
Matrix4d m = new Matrix4d(1,0,0,1, 0,1,0,0, 0,0,1,0, 0,0,0,1); // shift of 1 in x axis
186+
Calc.transform(c, m);
187+
188+
Group thegroup = c.getAtomGroup(0);
189+
Group thealtlocgroup = thegroup.getAltLocs().get(0);
190+
191+
Atom atom1 = thegroup.getAtom("CA");
192+
Atom atom2 = thealtlocgroup.getAtom("CA");
193+
194+
// x should be shitfted by 1
195+
assertEquals(2, atom1.getX(), 0.00001);
196+
assertEquals(1, atom1.getY(), 0.00001);
197+
assertEquals(1, atom1.getZ(), 0.00001);
198+
199+
// x should be shitfted by 1
200+
assertEquals(3, atom2.getX(), 0.00001);
201+
assertEquals(2, atom2.getY(), 0.00001);
202+
assertEquals(2, atom2.getZ(), 0.00001);
203+
204+
205+
}
159206

160207
private static Atom getAtom(double x, double y, double z) {
161208
Atom a = new AtomImpl();

0 commit comments

Comments
 (0)