2424 */
2525package org .biojava .nbio .structure ;
2626
27+ import static org .junit .Assert .assertEquals ;
28+ import static org .junit .Assert .assertNotEquals ;
29+ import static org .junit .Assert .assertNotNull ;
2730
2831import java .io .IOException ;
2932import java .util .Iterator ;
33+ import java .util .List ;
3034
3135import org .biojava .nbio .structure .align .util .AtomCache ;
3236import org .biojava .nbio .structure .io .FileParsingParameters ;
3337import org .junit .Test ;
34- import static org .junit .Assert .*;
3538
3639public class TestCloning {
3740
@@ -40,111 +43,134 @@ public void test1a4wCloning() throws StructureException, IOException {
4043
4144 Structure s ;
4245
43- AtomCache cache = new AtomCache ();
44- FileParsingParameters params = new FileParsingParameters ();
46+ final AtomCache cache = new AtomCache ();
47+ final FileParsingParameters params = new FileParsingParameters ();
4548 params .setAlignSeqRes (true );
4649 cache .setFileParsingParams (params );
4750
4851 StructureIO .setAtomCache (cache );
4952
5053 s = StructureIO .getStructure ("1a4w" );
5154
52- Structure c = s .clone ();
55+ final Structure c = s .clone ();
5356
54- compareCloned (s ,c );
57+ compareCloned (s , c );
5558
5659 }
5760
58-
59-
6061 @ Test
6162 public void testAsymUnitCloning () throws StructureException , IOException {
6263
6364 Structure s ;
6465
65-
66- AtomCache cache = new AtomCache ();
67- FileParsingParameters params = new FileParsingParameters ();
66+ final AtomCache cache = new AtomCache ();
67+ final FileParsingParameters params = new FileParsingParameters ();
6868 params .setAlignSeqRes (false );
6969 cache .setFileParsingParams (params );
7070
7171 StructureIO .setAtomCache (cache );
7272
7373 s = StructureIO .getStructure ("1stp" );
7474
75- Structure c = s .clone ();
75+ final Structure c = s .clone ();
7676
77- compareCloned (s ,c );
77+ compareCloned (s , c );
7878 }
7979
8080 @ Test
8181 public void testBioUnitCloning () throws StructureException , IOException {
8282
8383 Structure s ;
84- s = StructureIO .getBiologicalAssembly ("1stp" ,1 );
84+ s = StructureIO .getBiologicalAssembly ("1stp" , 1 );
8585
86- Structure c = s .clone ();
86+ final Structure c = s .clone ();
8787
88- compareCloned (s ,c );
88+ compareCloned (s , c );
8989
9090 }
9191
9292 /**
9393 * A Structure with alt locs, we make sure they are being cloned too
94+ *
9495 * @throws StructureException
9596 * @throws IOException
9697 */
9798 @ Test
9899 public void test3piuCloning () throws StructureException , IOException {
99100
100- AtomCache cache = new AtomCache ();
101- FileParsingParameters params = new FileParsingParameters ();
101+ final AtomCache cache = new AtomCache ();
102+ final FileParsingParameters params = new FileParsingParameters ();
102103 params .setAlignSeqRes (true );
103104 cache .setFileParsingParams (params );
104105
105106 StructureIO .setAtomCache (cache );
106107
107- Structure s = StructureIO .getStructure ("3piu" );
108+ final Structure s = StructureIO .getStructure ("3piu" );
108109
109- Structure c = s .clone ();
110+ final Structure c = s .clone ();
110111
111112 compareCloned (s , c );
112113 }
113114
114- private void compareCloned (Structure s , Structure c ) throws StructureException {
115+ private void compareCloned (final Structure s , final Structure c ) throws StructureException {
115116
116117 assertEquals (s .getChains ().size (), c .getChains ().size ());
117118
118- for ( Chain chain : s .getChains ()) {
119+ for (final Chain chain : s .getChains ()) {
119120
120- Chain test = c .getChain (chain .getId ());
121+ final Chain test = c .getChain (chain .getId ());
121122
122- assertEquals ("Could not correctly clone seqres for chain " + chain .getId () , chain .getSeqResLength (),test .getSeqResLength ());
123+ assertEquals ("Could not correctly clone seqres for chain " + chain .getId (), chain .getSeqResLength (),
124+ test .getSeqResLength ());
123125
124- assertEquals ("Could not correctly clone atom records for chain " + chain .getId () , chain .getAtomLength (),test .getAtomLength ());
126+ assertEquals ("Could not correctly clone atom records for chain " + chain .getId (), chain .getAtomLength (),
127+ test .getAtomLength ());
125128
126129 Iterator <Group > it = test .getAtomGroups ().iterator ();
127- for (Group g : chain .getAtomGroups ()) {
128- Group testGroup = it .next ();
129- //if (g.hasAltLoc()) {
130- // System.out.println(g.toString());
131- //}
130+ for (final Group g : chain .getAtomGroups ()) {
131+ final Group testGroup = it .next ();
132+ // if (g.hasAltLoc()) {
133+ // System.out.println(g.toString());
134+ // }
132135 assertEquals (g .getAltLocs ().size (), testGroup .getAltLocs ().size ());
133136 }
134-
137+
135138 it = test .getSeqResGroups ().iterator ();
136- for (Group g : chain .getSeqResGroups ()) {
137- Group testGroup = it .next ();
139+ for (final Group g : chain .getSeqResGroups ()) {
140+ final Group testGroup = it .next ();
138141 assertEquals (g .getAltLocs ().size (), testGroup .getAltLocs ().size ());
139142 }
140143 }
141144
142- Atom [] allAtoms = StructureTools .getAllAtomArray (s );
145+ final Atom [] allAtoms = StructureTools .getAllAtomArray (s );
146+
147+ final Atom [] allAtomsCloned = StructureTools .getAllAtomArray (c );
148+
149+ assertEquals (allAtoms .length , allAtomsCloned .length );
150+
151+ }
152+
153+ @ Test
154+ public void testBondCloning () throws IOException , StructureException {
155+
156+ final AtomCache cache = new AtomCache ();
157+ cache .setUseMmCif (true );
158+
159+ final FileParsingParameters params = cache .getFileParsingParams ();
160+ params .setCreateAtomBonds (true );
161+ cache .setFileParsingParams (params );
143162
144- Atom [] allAtomsCloned = StructureTools .getAllAtomArray (c );
163+ final Structure s = cache .getStructure ("2I13" );
164+ final List <Bond > bonds = s .getNonPolyChain ("G" ).getAtomGroup (0 ).getAtom (0 ).getBonds ();
165+ assertNotNull (bonds );
145166
146- assertEquals (allAtoms .length ,allAtomsCloned .length );
167+ final Structure s2 = s .clone ();
168+ final List <Bond > bonds2 = s2 .getNonPolyChain ("G" ).getAtomGroup (0 ).getAtom (0 ).getBonds ();
169+ assertNotNull (bonds2 );
147170
171+ assertEquals (bonds .toString (), bonds2 .toString ());
172+ // But the objects should be different as the atoms are clones
173+ assertNotEquals (bonds .toArray (), bonds2 .toArray ());
148174 }
149175
150176}
0 commit comments