2323import org .biojava .nbio .structure .align .util .AtomCache ;
2424import org .biojava .nbio .structure .io .FileParsingParameters ;
2525import org .biojava .nbio .structure .io .mmcif .ChemCompGroupFactory ;
26+ import org .biojava .nbio .structure .io .mmcif .MMCIFFileTools ;
27+ import org .biojava .nbio .structure .io .mmcif .SimpleMMcifConsumer ;
28+ import org .biojava .nbio .structure .io .mmcif .SimpleMMcifParser ;
2629import org .biojava .nbio .structure .io .mmcif .chem .PolymerType ;
2730import org .biojava .nbio .structure .io .mmcif .chem .ResidueType ;
31+ import org .biojava .nbio .structure .io .mmcif .model .AtomSite ;
2832import org .biojava .nbio .structure .io .mmcif .model .ChemComp ;
2933import org .biojava .nbio .structure .io .mmcif .model .ChemCompBond ;
3034import org .junit .Test ;
3135
36+ import java .io .BufferedReader ;
3237import java .io .IOException ;
38+ import java .io .StringReader ;
3339import java .util .ArrayList ;
3440import java .util .List ;
3541
@@ -85,28 +91,26 @@ public void testAltLocParsing() throws StructureException, IOException{
8591
8692 assertTrue ("The group does not have an altLoc " , g .hasAltLoc ());
8793
88- assertTrue ( "The nr of altLocs is not 1, but " + g .getAltLocs ().size (), g . getAltLocs (). size () == 1 );
94+ assertEquals ( 1 , g .getAltLocs ().size ());
8995
9096 assertEquals ( g .getPDBName (), "KOR" );
9197
9298 Group altLocG = g .getAltLocs ().get (0 );
9399
94100 assertEquals (altLocG .getPDBName (),"K1R" );
95101
96- assertEquals (275 ,groupCount );
102+ assertEquals (275 , groupCount );
97103
98104 // citric acid is now in its own chain
99105
100106 Chain b = s .getChain ("B" );
101- assertTrue (b .getAtomGroups ().size () == 1 );
102-
107+ assertEquals (1 , b .getAtomGroups ().size ());
103108
104109 ResidueNumber resNum2 = ResidueNumber .fromString ("265" );
105110
106111 Group g2 = a .getGroupByPDB (resNum2 );
107112 assertTrue (g2 .hasAltLoc ());
108113
109-
110114 }
111115
112116 @ Test
@@ -127,8 +131,7 @@ public void test2W72() throws IOException, StructureException{
127131
128132 Atom [] caA = StructureTools .getRepresentativeAtomArray (a );
129133
130- assertEquals (caA .length ,141 );
131-
134+ assertEquals (141 , caA .length );
132135
133136 }
134137
@@ -148,7 +151,6 @@ public void test1U7F() throws IOException, StructureException{
148151 ensureAllAtomsSameAltCode (altGroup , g );
149152 }
150153
151-
152154 }
153155
154156 @ Test
@@ -166,7 +168,6 @@ public void test1JXX() throws IOException, StructureException{
166168 ensureAllAtomsSameAltCode (altGroup , g );
167169 }
168170
169-
170171 }
171172
172173
@@ -208,15 +209,20 @@ private void ensureAllAtomsSameAltCode(Group groupInputAltLocGroup, Group inputM
208209 @ Test
209210 public void test1AAC () throws IOException , StructureException {
210211
212+ AtomCache cache = new AtomCache ();
213+ cache .setUseMmCif (false );
214+ StructureIO .setAtomCache (cache );
215+
211216 Structure s = StructureIO .getStructure ("1AAC" );
212217
213218 Chain a = s .getPolyChainByPDB ("A" );
214219
215220 Group g = a .getGroupByPDB ( ResidueNumber .fromString ("27" ));
216221 testCBAtomInMainGroup (g );
217222
218- AtomCache cache = new AtomCache ();
223+ cache = new AtomCache ();
219224 cache .setUseMmCif (true );
225+ StructureIO .setAtomCache (cache );
220226
221227 Structure s1 = cache .getStructure ("1AAC" );
222228 Chain a1 = s1 .getPolyChainByPDB ("A" );
@@ -225,20 +231,6 @@ public void test1AAC() throws IOException, StructureException{
225231
226232 testCBAtomInMainGroup (g1 );
227233
228-
229-
230- // int pos = 0;
231- // for (Group alt: g.getAltLocs()) {
232- // pos++;
233- // System.out.println("altLoc: " + pos + " " + alt);
234- // for (Atom atom : alt.getAtoms()) {
235- // System.out.print(atom.toPDB());
236- // }
237- // }
238-
239-
240-
241-
242234 }
243235
244236 private void testCBAtomInMainGroup (Group g ) {
@@ -248,7 +240,7 @@ private void testCBAtomInMainGroup(Group g) {
248240
249241 for (Atom atom : g .getAtoms ()) {
250242 //System.out.print(atom.toPDB());
251- if ( atom .getName ().equals (StructureTools .CA_ATOM_NAME )){
243+ if ( atom .getName ().equals (StructureTools .CB_ATOM_NAME )){
252244
253245 cbInMain = true ;
254246 break ;
@@ -316,7 +308,7 @@ public void test3PIUpdb() throws IOException, StructureException{
316308 }
317309 }
318310
319- assertTrue (ca .length == caList .size ());
311+ assertEquals (ca .length , caList .size ());
320312
321313 }
322314
@@ -354,7 +346,7 @@ private void doTestAllAltLocsSamAtomsMainGroup(String pdbId) throws IOException,
354346 for (Group g : c .getAtomGroups ()){
355347
356348 for (Group altLocGroup :g .getAltLocs ()) {
357- assertEquals (altLocGroup .size (), g .size ());
349+ assertEquals (g .size (), altLocGroup .size ());
358350 }
359351 }
360352 }
@@ -482,7 +474,7 @@ public void test4CUPBonds() throws IOException, StructureException{
482474 }
483475 }
484476
485- assertTrue (ca .length == caList .size ());
477+ assertEquals (ca .length , caList .size ());
486478
487479
488480 }
@@ -534,7 +526,6 @@ public void test3PIUmmcif() throws IOException, StructureException{
534526
535527 }
536528
537-
538529 }
539530 if (! caInMain && g .hasAtom (StructureTools .CA_ATOM_NAME )){
540531 // g.hasAtom checks altLocs
@@ -546,7 +537,6 @@ public void test3PIUmmcif() throws IOException, StructureException{
546537
547538 assertEquals (ca .length , caList .size ());
548539
549-
550540 }
551541
552542 @ Test
@@ -592,7 +582,6 @@ public void test3U7Tmmcif() throws IOException, StructureException{
592582
593583 }
594584
595-
596585 }
597586 if (! caInMain && g .hasAtom (StructureTools .CA_ATOM_NAME )){
598587 // g.hasAtom checks altLocs
@@ -604,6 +593,154 @@ public void test3U7Tmmcif() throws IOException, StructureException{
604593
605594 assertEquals (ca .length , caList .size ());
606595
596+ }
597+
598+ @ Test
599+ public void testMmcifWritingPartialAltlocs () throws IOException {
600+ String mmcifData =
601+ "data_test\n " +
602+ "loop_\n " +
603+ "_atom_site.group_PDB \n " +
604+ "_atom_site.id \n " +
605+ "_atom_site.type_symbol \n " +
606+ "_atom_site.label_atom_id \n " +
607+ "_atom_site.label_alt_id \n " +
608+ "_atom_site.label_comp_id \n " +
609+ "_atom_site.label_asym_id \n " +
610+ "_atom_site.label_entity_id \n " +
611+ "_atom_site.label_seq_id \n " +
612+ "_atom_site.pdbx_PDB_ins_code \n " +
613+ "_atom_site.Cartn_x \n " +
614+ "_atom_site.Cartn_y \n " +
615+ "_atom_site.Cartn_z \n " +
616+ "_atom_site.occupancy \n " +
617+ "_atom_site.B_iso_or_equiv \n " +
618+ "_atom_site.pdbx_formal_charge \n " +
619+ "_atom_site.auth_seq_id \n " +
620+ "_atom_site.auth_comp_id \n " +
621+ "_atom_site.auth_asym_id \n " +
622+ "_atom_site.auth_atom_id \n " +
623+ "_atom_site.pdbx_PDB_model_num \n " +
624+ "ATOM 102 N N . ARG A 1 13 ? 9.889 23.379 13.115 1.00 6.57 ? 102 ARG A N 1\n " +
625+ "ATOM 103 C CA . ARG A 1 13 ? 9.540 23.003 14.482 1.00 7.05 ? 102 ARG A CA 1\n " +
626+ "ATOM 104 C C . ARG A 1 13 ? 10.407 23.758 15.489 1.00 6.88 ? 102 ARG A C 1\n " +
627+ "ATOM 105 O O . ARG A 1 13 ? 9.915 24.196 16.532 1.00 7.69 ? 102 ARG A O 1\n " +
628+ "ATOM 106 C CB . ARG A 1 13 ? 9.706 21.494 14.688 1.00 9.07 ? 102 ARG A CB 1\n " +
629+ "ATOM 107 C CG A ARG A 1 13 ? 8.757 20.644 13.854 0.50 14.39 ? 102 ARG A CG 1\n " +
630+ "ATOM 108 C CG B ARG A 1 13 ? 8.693 20.645 13.938 0.50 13.58 ? 102 ARG A CG 1\n " +
631+ "ATOM 109 C CD A ARG A 1 13 ? 9.109 19.164 13.950 0.50 18.14 ? 102 ARG A CD 1\n " +
632+ "ATOM 110 C CD B ARG A 1 13 ? 8.710 19.216 14.456 0.50 16.34 ? 102 ARG A CD 1\n " +
633+ "ATOM 111 N NE A ARG A 1 13 ? 8.983 18.644 15.310 0.50 20.72 ? 102 ARG A NE 1\n " +
634+ "ATOM 112 N NE B ARG A 1 13 ? 8.315 19.158 15.861 0.50 23.99 ? 102 ARG A NE 1\n " +
635+ "ATOM 113 C CZ A ARG A 1 13 ? 7.826 18.445 15.933 0.50 23.45 ? 102 ARG A CZ 1\n " +
636+ "ATOM 114 C CZ B ARG A 1 13 ? 8.404 18.072 16.622 0.50 24.56 ? 102 ARG A CZ 1\n " +
637+ "ATOM 115 N NH1 A ARG A 1 13 ? 6.683 18.718 15.321 0.50 23.60 ? 102 ARG A NH1 1\n " +
638+ "ATOM 116 N NH1 B ARG A 1 13 ? 8.881 16.942 16.118 0.50 28.42 ? 102 ARG A NH1 1\n " +
639+ "ATOM 117 N NH2 A ARG A 1 13 ? 7.812 17.972 17.172 0.50 24.80 ? 102 ARG A NH2 1\n " +
640+ "ATOM 118 N NH2 B ARG A 1 13 ? 8.013 18.115 17.888 0.50 26.52 ? 102 ARG A NH2 1\n " ;
641+
642+ SimpleMMcifParser parser = new SimpleMMcifParser ();
643+ SimpleMMcifConsumer consumer = new SimpleMMcifConsumer ();
644+ parser .addMMcifConsumer (consumer );
645+
646+ BufferedReader buf = new BufferedReader (new StringReader (mmcifData ));
647+ parser .parse (buf );
648+ buf .close ();
649+
650+ Structure s = consumer .getStructure ();
651+ Chain c = s .getPolyChains ().get (0 );
652+ assertEquals (1 , c .getAtomGroups ().size ());
653+ Group g = c .getAtomGroup (0 );
654+ assertEquals (11 , g .size ());
655+ assertEquals (1 , g .getAltLocs ().size ());
656+
657+ for (Atom a : g .getAtoms ()) {
658+ if (a .getName ().equals ("C" ) || a .getName ().equals ("N" ) || a .getName ().equals ("O" ) || a .getName ().equals ("CA" ) || a .getName ().equals ("CB" ))
659+ assertEquals (' ' , a .getAltLoc ().charValue ());
660+ else
661+ assertEquals ('A' , a .getAltLoc ().charValue ());
662+ }
663+
664+ assertEquals (11 , g .getAltLocs ().get (0 ).size ());
665+ for (Atom a : g .getAltLocs ().get (0 ).getAtoms ()) {
666+ if (a .getName ().equals ("C" ) || a .getName ().equals ("N" ) || a .getName ().equals ("O" ) || a .getName ().equals ("CA" ) || a .getName ().equals ("CB" ))
667+ assertEquals (' ' , a .getAltLoc ().charValue ());
668+ else
669+ assertEquals ('B' , a .getAltLoc ().charValue ());
670+ }
671+
672+ List <AtomSite > atomSites = MMCIFFileTools .convertChainToAtomSites (c , 1 , "A" , "A" );
673+ assertEquals (17 , atomSites .size ());
674+
675+ }
676+
677+ @ Test
678+ public void testMmcifWritingAllAltlocs () throws IOException {
679+ String mmcifData =
680+ "data_test\n " +
681+ "loop_\n " +
682+ "_atom_site.group_PDB \n " +
683+ "_atom_site.id \n " +
684+ "_atom_site.type_symbol \n " +
685+ "_atom_site.label_atom_id \n " +
686+ "_atom_site.label_alt_id \n " +
687+ "_atom_site.label_comp_id \n " +
688+ "_atom_site.label_asym_id \n " +
689+ "_atom_site.label_entity_id \n " +
690+ "_atom_site.label_seq_id \n " +
691+ "_atom_site.pdbx_PDB_ins_code \n " +
692+ "_atom_site.Cartn_x \n " +
693+ "_atom_site.Cartn_y \n " +
694+ "_atom_site.Cartn_z \n " +
695+ "_atom_site.occupancy \n " +
696+ "_atom_site.B_iso_or_equiv \n " +
697+ "_atom_site.pdbx_formal_charge \n " +
698+ "_atom_site.auth_seq_id \n " +
699+ "_atom_site.auth_comp_id \n " +
700+ "_atom_site.auth_asym_id \n " +
701+ "_atom_site.auth_atom_id \n " +
702+ "_atom_site.pdbx_PDB_model_num \n " +
703+ "ATOM 204 N N A PRO A 1 23 ? 15.057 31.425 23.772 0.50 3.09 ? 112 PRO A N 1 \n " +
704+ "ATOM 205 N N B PRO A 1 23 ? 14.762 31.778 23.217 0.50 15.25 ? 112 PRO A N 1 \n " +
705+ "ATOM 206 C CA A PRO A 1 23 ? 16.391 30.930 23.416 0.50 5.82 ? 112 PRO A CA 1 \n " +
706+ "ATOM 207 C CA B PRO A 1 23 ? 16.049 31.406 22.622 0.50 15.44 ? 112 PRO A CA 1 \n " +
707+ "ATOM 208 C C A PRO A 1 23 ? 17.360 30.580 24.546 0.50 6.73 ? 112 PRO A C 1 \n " +
708+ "ATOM 209 C C B PRO A 1 23 ? 16.971 30.922 23.734 0.50 15.04 ? 112 PRO A C 1 \n " +
709+ "ATOM 210 O O A PRO A 1 23 ? 18.566 30.784 24.409 0.50 10.00 ? 112 PRO A O 1 \n " +
710+ "ATOM 211 O O B PRO A 1 23 ? 18.076 31.430 23.925 0.50 14.61 ? 112 PRO A O 1 \n " +
711+ "ATOM 212 C CB A PRO A 1 23 ? 16.931 32.050 22.542 0.50 8.38 ? 112 PRO A CB 1 \n " +
712+ "ATOM 213 C CB B PRO A 1 23 ? 16.519 32.710 21.986 0.50 14.09 ? 112 PRO A CB 1 \n " +
713+ "ATOM 214 C CG A PRO A 1 23 ? 16.424 33.256 23.263 0.50 7.59 ? 112 PRO A CG 1 \n " +
714+ "ATOM 215 C CG B PRO A 1 23 ? 15.960 33.743 22.908 0.50 15.66 ? 112 PRO A CG 1 \n " +
715+ "ATOM 216 C CD A PRO A 1 23 ? 14.980 32.886 23.580 0.50 6.98 ? 112 PRO A CD 1 \n " +
716+ "ATOM 217 C CD B PRO A 1 23 ? 14.558 33.235 23.153 0.50 14.91 ? 112 PRO A CD 1 \n " ;
717+
718+ SimpleMMcifParser parser = new SimpleMMcifParser ();
719+ SimpleMMcifConsumer consumer = new SimpleMMcifConsumer ();
720+ parser .addMMcifConsumer (consumer );
721+
722+ BufferedReader buf = new BufferedReader (new StringReader (mmcifData ));
723+ parser .parse (buf );
724+ buf .close ();
725+
726+ Structure s = consumer .getStructure ();
727+ Chain c = s .getPolyChains ().get (0 );
728+ assertEquals (1 , c .getAtomGroups ().size ());
729+
730+ Group g = c .getAtomGroup (0 );
731+ assertEquals (7 , g .size ());
732+
733+ assertEquals (1 , g .getAltLocs ().size ());
734+
735+ for (Atom a : g .getAtoms ()) {
736+ assertEquals ('A' , a .getAltLoc ().charValue ());
737+ }
738+ for (Atom a : g .getAltLocs ().get (0 ).getAtoms ()) {
739+ assertEquals ('B' , a .getAltLoc ().charValue ());
740+ }
741+
742+ List <AtomSite > atomSites = MMCIFFileTools .convertChainToAtomSites (c , 1 , "A" , "A" );
743+ assertEquals (14 , atomSites .size ());
607744
608745 }
609746
0 commit comments