@@ -548,19 +548,28 @@ public void readSGroup(IAtomContainer readData) throws CDKException {
548548 options = parseOptions (exhaustStringTokenizer (tokenizer ));
549549 }
550550
551+ Sgroup sgroup = new Sgroup ();
551552 // now interpret line
552553 if (type .startsWith ("SUP" )) {
554+ sgroup .setType (SgroupType .CtabAbbreviation );
553555 Iterator <String > keys = options .keySet ().iterator ();
554- int atomID = -1 ;
555556 String label = "" ;
556557 while (keys .hasNext ()) {
557558 String key = keys .next ();
558559 String value = options .get (key );
559560 try {
560561 if (key .equals ("ATOMS" )) {
561562 StringTokenizer atomsTokenizer = new StringTokenizer (value );
562- Integer .parseInt (atomsTokenizer .nextToken ()); // should be 1, int atomCount =
563- atomID = Integer .parseInt (atomsTokenizer .nextToken ());
563+ int nExpected = Integer .parseInt (atomsTokenizer .nextToken ());
564+ while (atomsTokenizer .hasMoreTokens ()) {
565+ sgroup .addAtom (readData .getAtom (Integer .parseInt (atomsTokenizer .nextToken ())-1 ));
566+ }
567+ } else if (key .equals ("XBONDS" )) {
568+ StringTokenizer xbonds = new StringTokenizer (value );
569+ int nExpected = Integer .parseInt (xbonds .nextToken ());
570+ while (xbonds .hasMoreTokens ()) {
571+ sgroup .addBond (readData .getBond (Integer .parseInt (xbonds .nextToken ())-1 ));
572+ }
564573 } else if (key .equals ("LABEL" )) {
565574 label = value ;
566575 } else {
@@ -573,18 +582,16 @@ public void readSGroup(IAtomContainer readData) throws CDKException {
573582 logger .debug (exception );
574583 throw new CDKException (error , exception );
575584 }
576- if (atomID != -1 && label .length () > 0 ) {
577- IAtom original = readData .getAtom (atomID - 1 );
578- IAtom replacement = original ;
579- if (!(original instanceof IPseudoAtom )) {
580- replacement = readData .getBuilder ().newInstance (IPseudoAtom .class ,
581- original );
582- }
583- ((IPseudoAtom ) replacement ).setLabel (label );
584- if (!replacement .equals (original ))
585- AtomContainerManipulator .replaceAtomByAtom (readData , original , replacement );
585+ if (!sgroup .getAtoms ().isEmpty () && label .length () > 0 ) {
586+ sgroup .setSubscript (label );
586587 }
587588 }
589+ List <Sgroup > sgroups = readData .getProperty (CDKConstants .CTAB_SGROUPS );
590+ if (sgroups == null )
591+ sgroups = new ArrayList <>();
592+ sgroups .add (sgroup );
593+ readData .setProperty (CDKConstants .CTAB_SGROUPS ,
594+ sgroups );
588595 } else {
589596 logger .warn ("Skipping unrecognized SGROUP type: " + type );
590597 }
0 commit comments