@@ -204,13 +204,94 @@ public void testChainTransform() {
204204
205205 }
206206
207- private static Atom getAtom (double x , double y , double z ) {
207+ /**
208+ * Issue https://github.com/biojava/biojava/issues/715
209+ */
210+ @ Test
211+ public void testStructureTransform () throws StructureException {
212+ Group g = new AminoAcidImpl ();
213+ Atom a = getAtom ("CA" , 1 , 1 , 1 );
214+ g .addAtom (a );
215+ Group altLocG = new AminoAcidImpl ();
216+ Atom a2 = getAtom ("CA" , 2 , 2 , 2 );
217+ altLocG .addAtom (a2 );
218+
219+ g .addAltLoc (altLocG );
220+
221+ Chain c1 = new ChainImpl ();
222+ c1 .addGroup (g );
223+ c1 .setChainID ("A" );
224+
225+ Group gc2 = new AminoAcidImpl ();
226+ Atom ac2 = getAtom ("CA" , 3 , 3 , 3 );
227+ gc2 .addAtom (ac2 );
228+ Group altLocGc2 = new AminoAcidImpl ();
229+ Atom ac22 = getAtom ("CA" , 4 , 4 , 4 );
230+ altLocGc2 .addAtom (ac22 );
231+
232+ gc2 .addAltLoc (altLocGc2 );
233+
234+ Chain c2 = new ChainImpl ();
235+ c2 .addGroup (gc2 );
236+ c2 .setChainID ("B" );
237+
238+ Structure s = new StructureImpl ();
239+ s .addChain (c1 );
240+ s .addChain (c2 );
241+
242+
243+ 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
244+ Calc .transform (s , m );
245+
246+ // testing 1st chain
247+ Group thegroup = s .getChainByPDB ("A" ).getAtomGroup (0 );
248+ Group thealtlocgroup = thegroup .getAltLocs ().get (0 );
249+
250+ Atom atom1 = thegroup .getAtom ("CA" );
251+ Atom atom2 = thealtlocgroup .getAtom ("CA" );
252+
253+ // x should be shitfted by 1
254+ assertEquals (2 , atom1 .getX (), 0.00001 );
255+ assertEquals (1 , atom1 .getY (), 0.00001 );
256+ assertEquals (1 , atom1 .getZ (), 0.00001 );
257+
258+ // x should be shitfted by 1
259+ assertEquals (3 , atom2 .getX (), 0.00001 );
260+ assertEquals (2 , atom2 .getY (), 0.00001 );
261+ assertEquals (2 , atom2 .getZ (), 0.00001 );
262+
263+ // testing 2nd chain
264+ thegroup = s .getChainByPDB ("B" ).getAtomGroup (0 );
265+ thealtlocgroup = thegroup .getAltLocs ().get (0 );
266+
267+ atom1 = thegroup .getAtom ("CA" );
268+ atom2 = thealtlocgroup .getAtom ("CA" );
269+
270+ // x should be shitfted by 1
271+ assertEquals (4 , atom1 .getX (), 0.00001 );
272+ assertEquals (3 , atom1 .getY (), 0.00001 );
273+ assertEquals (3 , atom1 .getZ (), 0.00001 );
274+
275+ // x should be shitfted by 1
276+ assertEquals (5 , atom2 .getX (), 0.00001 );
277+ assertEquals (4 , atom2 .getY (), 0.00001 );
278+ assertEquals (4 , atom2 .getZ (), 0.00001 );
279+
280+
281+ }
282+
283+ private static Atom getAtom (String name , double x , double y , double z ) {
208284 Atom a = new AtomImpl ();
209285 a .setX (x );
210286 a .setY (y );
211287 a .setZ (z );
288+ a .setName (name );
212289 return a ;
213290 }
291+
292+ private static Atom getAtom (double x , double y , double z ) {
293+ return getAtom (null , x , y , z );
294+ }
214295
215296 private static Matrix4d getSampleTransform (){
216297
0 commit comments