Skip to content

Commit bc9011a

Browse files
committed
Fix and unit test for biojava#715
1 parent 2898281 commit bc9011a

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
@@ -579,6 +579,11 @@ public static final void transform(Chain chain, Matrix4d m) {
579579
for (Atom atom : g.getAtoms()) {
580580
transform(atom, m);
581581
}
582+
for (Group altG : g.getAltLocs()) {
583+
for (Atom atom : altG.getAtoms()) {
584+
transform(atom, m);
585+
}
586+
}
582587
}
583588
}
584589

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
@@ -157,6 +157,53 @@ public void testVecmathTransformation() {
157157

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

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

0 commit comments

Comments
 (0)