2424
2525import javax .vecmath .Matrix4d ;
2626import javax .vecmath .Point3d ;
27+ import javax .vecmath .Vector3d ;
2728
2829import org .biojava .nbio .structure .geometry .Matrices ;
2930import org .biojava .nbio .structure .jama .Matrix ;
@@ -157,14 +158,163 @@ public void testVecmathTransformation() {
157158
158159 assertEquals (expected , actual );
159160 }
161+
162+ /**
163+ * Issue https://github.com/biojava/biojava/issues/715
164+ */
165+ @ Test
166+ public void testChainTransform () {
167+
168+ Chain c = createDummyChain ();
169+
170+ 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
171+ Calc .transform (c , m );
172+
173+ Group thegroup = c .getAtomGroup (0 );
174+ Group thealtlocgroup = thegroup .getAltLocs ().get (0 );
175+
176+ Atom atom1 = thegroup .getAtom ("CA" );
177+ Atom atom2 = thealtlocgroup .getAtom ("CA" );
178+
179+ // x should be shifted by 1
180+ assertEquals (2 , atom1 .getX (), 0.00001 );
181+ assertEquals (1 , atom1 .getY (), 0.00001 );
182+ assertEquals (1 , atom1 .getZ (), 0.00001 );
183+
184+ // x should be shifted by 1
185+ assertEquals (3 , atom2 .getX (), 0.00001 );
186+ assertEquals (2 , atom2 .getY (), 0.00001 );
187+ assertEquals (2 , atom2 .getZ (), 0.00001 );
188+
189+
190+ }
160191
161- private static Atom getAtom (double x , double y , double z ) {
192+ /**
193+ * Issue https://github.com/biojava/biojava/issues/715
194+ */
195+ @ Test
196+ public void testStructureTransform () {
197+
198+ Structure s = createDummyStructure ();
199+
200+ 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
201+ Calc .transform (s , m );
202+
203+ // testing 1st chain
204+ Group thegroup = s .getChain ("A" ).getAtomGroup (0 );
205+ Group thealtlocgroup = thegroup .getAltLocs ().get (0 );
206+
207+ Atom atom1 = thegroup .getAtom ("CA" );
208+ Atom atom2 = thealtlocgroup .getAtom ("CA" );
209+
210+ // x should be shitfted by 1
211+ assertEquals (2 , atom1 .getX (), 0.00001 );
212+ assertEquals (1 , atom1 .getY (), 0.00001 );
213+ assertEquals (1 , atom1 .getZ (), 0.00001 );
214+
215+ // x should be shitfted by 1
216+ assertEquals (3 , atom2 .getX (), 0.00001 );
217+ assertEquals (2 , atom2 .getY (), 0.00001 );
218+ assertEquals (2 , atom2 .getZ (), 0.00001 );
219+
220+ // testing 2nd chain
221+ thegroup = s .getChain ("B" ).getAtomGroup (0 );
222+ thealtlocgroup = thegroup .getAltLocs ().get (0 );
223+
224+ atom1 = thegroup .getAtom ("CA" );
225+ atom2 = thealtlocgroup .getAtom ("CA" );
226+
227+ // x should be shitfted by 1
228+ assertEquals (4 , atom1 .getX (), 0.00001 );
229+ assertEquals (3 , atom1 .getY (), 0.00001 );
230+ assertEquals (3 , atom1 .getZ (), 0.00001 );
231+
232+ // x should be shitfted by 1
233+ assertEquals (5 , atom2 .getX (), 0.00001 );
234+ assertEquals (4 , atom2 .getY (), 0.00001 );
235+ assertEquals (4 , atom2 .getZ (), 0.00001 );
236+
237+
238+ }
239+
240+ @ Test
241+ public void testChainTranslate () {
242+ Chain c = createDummyChain ();
243+
244+ Vector3d translation = new Vector3d (1 , 0 , 0 );
245+ Calc .translate (c , translation );
246+
247+ Group thegroup = c .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 shifted 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 shifted 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+
264+ @ Test
265+ public void testStructureTranslate () {
266+ Structure s = createDummyStructure ();
267+
268+ Vector3d translation = new Vector3d (1 , 0 , 0 );
269+ Calc .translate (s , translation );
270+
271+ // testing 1st chain
272+ Group thegroup = s .getChain ("A" ).getAtomGroup (0 );
273+ Group thealtlocgroup = thegroup .getAltLocs ().get (0 );
274+
275+ Atom atom1 = thegroup .getAtom ("CA" );
276+ Atom atom2 = thealtlocgroup .getAtom ("CA" );
277+
278+ // x should be shitfted by 1
279+ assertEquals (2 , atom1 .getX (), 0.00001 );
280+ assertEquals (1 , atom1 .getY (), 0.00001 );
281+ assertEquals (1 , atom1 .getZ (), 0.00001 );
282+
283+ // x should be shitfted by 1
284+ assertEquals (3 , atom2 .getX (), 0.00001 );
285+ assertEquals (2 , atom2 .getY (), 0.00001 );
286+ assertEquals (2 , atom2 .getZ (), 0.00001 );
287+
288+ // testing 2nd chain
289+ thegroup = s .getChain ("B" ).getAtomGroup (0 );
290+ thealtlocgroup = thegroup .getAltLocs ().get (0 );
291+
292+ atom1 = thegroup .getAtom ("CA" );
293+ atom2 = thealtlocgroup .getAtom ("CA" );
294+
295+ // x should be shitfted by 1
296+ assertEquals (4 , atom1 .getX (), 0.00001 );
297+ assertEquals (3 , atom1 .getY (), 0.00001 );
298+ assertEquals (3 , atom1 .getZ (), 0.00001 );
299+
300+ // x should be shitfted by 1
301+ assertEquals (5 , atom2 .getX (), 0.00001 );
302+ assertEquals (4 , atom2 .getY (), 0.00001 );
303+ assertEquals (4 , atom2 .getZ (), 0.00001 );
304+ }
305+
306+ private static Atom getAtom (String name , double x , double y , double z ) {
162307 Atom a = new AtomImpl ();
163308 a .setX (x );
164309 a .setY (y );
165310 a .setZ (z );
311+ a .setName (name );
166312 return a ;
167313 }
314+
315+ private static Atom getAtom (double x , double y , double z ) {
316+ return getAtom (null , x , y , z );
317+ }
168318
169319 private static Matrix4d getSampleTransform (){
170320
@@ -174,5 +324,53 @@ private static Matrix4d getSampleTransform(){
174324 0.0 ,0.0 ,0.0 ,1.0 });
175325 return sample ;
176326 }
327+
328+ private static Chain createDummyChain () {
329+ Group g = new AminoAcidImpl ();
330+ Atom a = getAtom ("CA" , 1 , 1 , 1 );
331+ g .addAtom (a );
332+ Group altLocG = new AminoAcidImpl ();
333+ Atom a2 = getAtom ("CA" , 2 , 2 , 2 );
334+ altLocG .addAtom (a2 );
335+
336+ g .addAltLoc (altLocG );
337+
338+ Chain c = new ChainImpl ();
339+ c .addGroup (g );
340+ return c ;
341+ }
342+
343+ private static Structure createDummyStructure () {
344+ Group g = new AminoAcidImpl ();
345+ Atom a = getAtom ("CA" , 1 , 1 , 1 );
346+ g .addAtom (a );
347+ Group altLocG = new AminoAcidImpl ();
348+ Atom a2 = getAtom ("CA" , 2 , 2 , 2 );
349+ altLocG .addAtom (a2 );
350+
351+ g .addAltLoc (altLocG );
352+
353+ Chain c1 = new ChainImpl ();
354+ c1 .addGroup (g );
355+ c1 .setId ("A" );
356+
357+ Group gc2 = new AminoAcidImpl ();
358+ Atom ac2 = getAtom ("CA" , 3 , 3 , 3 );
359+ gc2 .addAtom (ac2 );
360+ Group altLocGc2 = new AminoAcidImpl ();
361+ Atom ac22 = getAtom ("CA" , 4 , 4 , 4 );
362+ altLocGc2 .addAtom (ac22 );
363+
364+ gc2 .addAltLoc (altLocGc2 );
365+
366+ Chain c2 = new ChainImpl ();
367+ c2 .addGroup (gc2 );
368+ c2 .setId ("B" );
369+
370+ Structure s = new StructureImpl ();
371+ s .addChain (c1 );
372+ s .addChain (c2 );
373+ return s ;
374+ }
177375
178376}
0 commit comments