2424
2525/**
2626 * Tests to see if roundtripping of MMTF can be done.
27+ *
2728 * @author Anthony Bradley
2829 *
2930 */
3031public class TestMmtfRoundTrip {
3132
3233 /**
3334 * Test that we can round trip a simple structure.
35+ *
3436 * @throws IOException an error reading the file
3537 * @throws StructureException an error parsing the structure
3638 */
3739 @ Test
3840 public void testRoundTrip () throws IOException , StructureException {
41+
42+ // Load a structure in MMCIF format
3943 AtomCache cache = new AtomCache ();
4044 cache .setUseMmCif (true );
4145 ChemCompGroupFactory .setChemCompProvider (new DownloadChemCompProvider ());
4246
43-
4447 StructureIO .setAtomCache (cache );
4548 Structure structure = StructureIO .getStructure ("4CUP" );
49+
50+ // Write the structure to a MMTF encoding
4651 AdapterToStructureData writerToEncoder = new AdapterToStructureData ();
4752 new MmtfStructureWriter (structure , writerToEncoder );
53+
54+ // Load back the structure from the MMTF encoding
4855 MmtfStructureReader mmtfStructureReader = new MmtfStructureReader ();
4956 new StructureDataToAdapter (writerToEncoder , mmtfStructureReader );
57+
5058 assertTrue (checkIfAtomsSame (structure ,mmtfStructureReader .getStructure ()));
5159 }
5260
@@ -58,18 +66,23 @@ public void testRoundTrip() throws IOException, StructureException {
5866 * @return
5967 */
6068 private boolean checkIfAtomsSame (Structure structOne , Structure structTwo ) {
69+
70+ // Check the same number of models
6171 int numModels = structOne .nrModels ();
6272 if (numModels !=structTwo .nrModels ()){
6373 System .out .println ("Error - diff number models: " +structOne .getPDBCode ());
6474 return false ;
6575 }
76+
6677 for (int i =0 ;i <numModels ;i ++){
78+
6779 List <Chain > chainsOne = structOne .getChains (i );
6880 List <Chain > chainsTwo = structTwo .getChains (i );
6981 if (chainsOne .size ()!=chainsTwo .size ()){
7082 System .out .println ("Error - diff number chains: " +structOne .getPDBCode ());
7183 return false ;
7284 }
85+
7386 // Now make sure they're sorted in the right order
7487 sortChains (chainsOne , chainsTwo );
7588 // Check that each one has the same number of poly, non-poly and water chains
@@ -182,8 +195,9 @@ else if(atomOne.getBonds().size()!=atomTwo.getBonds().size()){
182195 }
183196 return true ;
184197 }
198+
185199 /**
186- * Check both structures have the same number of poly,non-poly and water chains
200+ * Check both structures have the same number of poly, non-poly and water chains
187201 * @param structOne the first structure
188202 * @param structTwo the second structure
189203 * @param i the model index
@@ -193,8 +207,10 @@ private void checkDiffChains(Structure structOne, Structure structTwo, int i) {
193207 assertEquals (structOne .getNonPolyChains (i ).size (), structTwo .getNonPolyChains (i ).size ());
194208 assertEquals (structOne .getWaterChains (i ).size (), structTwo .getWaterChains (i ).size ());
195209 }
210+
196211 /**
197212 * Sort the atom based on PDB serial id
213+ *
198214 * @param atomsOne the first list
199215 * @param atomsTwo the second list
200216 */
@@ -227,6 +243,7 @@ public int compare(Atom o1, Atom o2) {
227243
228244 /**
229245 * Sort the chains based on chain id.
246+ *
230247 * @param chainsOne the first list of chains
231248 * @param chainsTwo the second list of chains
232249 */
0 commit comments