Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixing also Calc.transform(Structure,Matrix4d)
  • Loading branch information
josemduarte committed Dec 8, 2017
commit 3a1ad26c6d0df71508e58a52a114978b940b9022
Original file line number Diff line number Diff line change
Expand Up @@ -538,12 +538,13 @@ public static final void transform(Atom atom, Matrix4d m) {
* @param m
*/
public static final void transform(Group group, Matrix4d m) {
AtomIterator iter = new AtomIterator(group);

while (iter.hasNext()) {
Atom atom = iter.next();
for (Atom atom : group.getAtoms()) {
transform(atom, m);

}
for (Group altG : group.getAltLocs()) {
for (Atom atom : altG.getAtoms()) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recursive call to transform(g, m) could also be possible here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, now changed

transform(atom, m);
}
}
}

Expand All @@ -556,12 +557,10 @@ public static final void transform(Group group, Matrix4d m) {
* @param m
*/
public static final void transform(Structure structure, Matrix4d m) {
AtomIterator iter = new AtomIterator(structure);

while (iter.hasNext()) {
Atom atom = iter.next();
transform(atom, m);

for (int n=0; n<structure.nrModels();n++) {
for (Chain c : structure.getChains(n)) {
transform(c, m);
}
}
}

Expand All @@ -576,14 +575,7 @@ public static final void transform(Structure structure, Matrix4d m) {
public static final void transform(Chain chain, Matrix4d m) {

for (Group g : chain.getAtomGroups()) {
for (Atom atom : g.getAtoms()) {
transform(atom, m);
}
for (Group altG : g.getAltLocs()) {
for (Atom atom : altG.getAtoms()) {
transform(atom, m);
}
}
transform(g, m);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,18 +164,10 @@ public void testVecmathTransformation() {
@Test
public void testChainTransform() {
Group g = new AminoAcidImpl();
Atom a = new AtomImpl();
a.setName("CA");
a.setX(1);
a.setY(1);
a.setZ(1);
Atom a = getAtom("CA", 1, 1, 1);
g.addAtom(a);
Group altLocG = new AminoAcidImpl();
Atom a2 = new AtomImpl();
a2.setName("CA");
a2.setX(2);
a2.setY(2);
a2.setZ(2);
Atom a2 = getAtom("CA", 2, 2, 2);
altLocG.addAtom(a2);

g.addAltLoc(altLocG);
Expand Down Expand Up @@ -205,13 +197,94 @@ public void testChainTransform() {

}

private static Atom getAtom(double x, double y, double z) {
/**
* Issue https://github.com/biojava/biojava/issues/715
*/
@Test
public void testStructureTransform() {
Group g = new AminoAcidImpl();
Atom a = getAtom("CA", 1, 1, 1);
g.addAtom(a);
Group altLocG = new AminoAcidImpl();
Atom a2 = getAtom("CA", 2, 2, 2);
altLocG.addAtom(a2);

g.addAltLoc(altLocG);

Chain c1 = new ChainImpl();
c1.addGroup(g);
c1.setId("A");

Group gc2 = new AminoAcidImpl();
Atom ac2 = getAtom("CA", 3, 3, 3);
gc2.addAtom(ac2);
Group altLocGc2 = new AminoAcidImpl();
Atom ac22 = getAtom("CA", 4, 4, 4);
altLocGc2.addAtom(ac22);

gc2.addAltLoc(altLocGc2);

Chain c2 = new ChainImpl();
c2.addGroup(gc2);
c2.setId("B");

Structure s = new StructureImpl();
s.addChain(c1);
s.addChain(c2);


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
Calc.transform(s, m);

// testing 1st chain
Group thegroup = s.getChain("A").getAtomGroup(0);
Group thealtlocgroup = thegroup.getAltLocs().get(0);

Atom atom1 = thegroup.getAtom("CA");
Atom atom2 = thealtlocgroup.getAtom("CA");

// x should be shitfted by 1
assertEquals(2, atom1.getX(), 0.00001);
assertEquals(1, atom1.getY(), 0.00001);
assertEquals(1, atom1.getZ(), 0.00001);

// x should be shitfted by 1
assertEquals(3, atom2.getX(), 0.00001);
assertEquals(2, atom2.getY(), 0.00001);
assertEquals(2, atom2.getZ(), 0.00001);

// testing 2nd chain
thegroup = s.getChain("B").getAtomGroup(0);
thealtlocgroup = thegroup.getAltLocs().get(0);

atom1 = thegroup.getAtom("CA");
atom2 = thealtlocgroup.getAtom("CA");

// x should be shitfted by 1
assertEquals(4, atom1.getX(), 0.00001);
assertEquals(3, atom1.getY(), 0.00001);
assertEquals(3, atom1.getZ(), 0.00001);

// x should be shitfted by 1
assertEquals(5, atom2.getX(), 0.00001);
assertEquals(4, atom2.getY(), 0.00001);
assertEquals(4, atom2.getZ(), 0.00001);


}

private static Atom getAtom(String name, double x, double y, double z) {
Atom a = new AtomImpl();
a.setX(x);
a.setY(y);
a.setZ(z);
a.setName(name);
return a;
}

private static Atom getAtom(double x, double y, double z) {
return getAtom(null, x, y, z);
}

private static Matrix4d getSampleTransform(){

Expand Down