Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -538,12 +538,11 @@ 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()) {
transform(altG, m);
}
}

Expand All @@ -556,12 +555,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,9 +573,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);
}
transform(g, m);
}
}

Expand All @@ -604,12 +599,12 @@ public static final void translate(Atom atom, Vector3d v) {
* @param v
*/
public static final void translate(Group group, Vector3d v) {
AtomIterator iter = new AtomIterator(group);

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

}
for (Group altG : group.getAltLocs()) {
translate(altG, v);
}
}

Expand All @@ -623,9 +618,7 @@ public static final void translate(Group group, Vector3d v) {
public static final void translate(Chain chain, Vector3d v) {

for (Group g : chain.getAtomGroups()) {
for (Atom atom : g.getAtoms()) {
translate(atom, v);
}
translate(g, v);
}
}

Expand All @@ -637,12 +630,11 @@ public static final void translate(Chain chain, Vector3d v) {
* @param v
*/
public static final void translate(Structure structure, Vector3d v) {
AtomIterator iter = new AtomIterator(structure);

while (iter.hasNext()) {
Atom atom = iter.next();
translate(atom, v);


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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import javax.vecmath.Matrix4d;
import javax.vecmath.Point3d;
import javax.vecmath.Vector3d;

import org.biojava.nbio.structure.geometry.Matrices;
import org.biojava.nbio.structure.jama.Matrix;
Expand Down Expand Up @@ -157,14 +158,163 @@ public void testVecmathTransformation() {

assertEquals(expected, actual);
}

/**
* Issue https://github.com/biojava/biojava/issues/715
*/
@Test
public void testChainTransform() {

Chain c = createDummyChain();

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(c, m);

Group thegroup = c.getAtomGroup(0);
Group thealtlocgroup = thegroup.getAltLocs().get(0);

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

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

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


}

private static Atom getAtom(double x, double y, double z) {
/**
* Issue https://github.com/biojava/biojava/issues/715
*/
@Test
public void testStructureTransform() {

Structure s = createDummyStructure();

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);


}

@Test
public void testChainTranslate() {
Chain c = createDummyChain();

Vector3d translation = new Vector3d(1, 0, 0);
Calc.translate(c, translation);

Group thegroup = c.getAtomGroup(0);
Group thealtlocgroup = thegroup.getAltLocs().get(0);

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

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

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

@Test
public void testStructureTranslate() {
Structure s = createDummyStructure();

Vector3d translation = new Vector3d(1, 0, 0);
Calc.translate(s, translation);

// 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 All @@ -174,5 +324,53 @@ private static Matrix4d getSampleTransform(){
0.0,0.0,0.0,1.0});
return sample;
}

private static Chain createDummyChain() {
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 c = new ChainImpl();
c.addGroup(g);
return c;
}

private static Structure createDummyStructure() {
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);
return s;
}

}