@@ -303,6 +303,7 @@ private IReaction readReaction(IChemObjectBuilder builder) throws CDKException {
303303
304304 int reactantCount = 0 ;
305305 int productCount = 0 ;
306+ int agentCount = 0 ; // optional
306307 try {
307308 String countsLine = input .readLine ();
308309 linecount ++;
@@ -318,10 +319,13 @@ private IReaction readReaction(IChemObjectBuilder builder) throws CDKException {
318319 * this line contains the number of reactants and products
319320 */
320321 StringTokenizer tokenizer = new StringTokenizer (countsLine );
321- reactantCount = Integer .valueOf (tokenizer .nextToken ()). intValue ( );
322+ reactantCount = Integer .parseInt (tokenizer .nextToken ());
322323 logger .info ("Expecting " + reactantCount + " reactants in file" );
323- productCount = Integer .valueOf (tokenizer .nextToken ()). intValue ( );
324+ productCount = Integer .parseInt (tokenizer .nextToken ());
324325 logger .info ("Expecting " + productCount + " products in file" );
326+ if (tokenizer .hasMoreTokens ())
327+ agentCount = Integer .parseInt (tokenizer .nextToken ());
328+ logger .info ("Expecting " + agentCount + " agents in file" );
325329 } catch (IOException | NumberFormatException exception ) {
326330 logger .debug (exception );
327331 throw new CDKException ("Error while counts line of RXN file" , exception );
@@ -330,7 +334,7 @@ private IReaction readReaction(IChemObjectBuilder builder) throws CDKException {
330334 // now read the reactants
331335 try {
332336 for (int i = 1 ; i <= reactantCount ; i ++) {
333- StringBuffer molFile = new StringBuffer ();
337+ StringBuilder molFile = new StringBuilder ();
334338 input .readLine (); // announceMDLFileLine
335339 String molFileLine = "" ;
336340 do {
@@ -358,7 +362,7 @@ private IReaction readReaction(IChemObjectBuilder builder) throws CDKException {
358362 // now read the products
359363 try {
360364 for (int i = 1 ; i <= productCount ; i ++) {
361- StringBuffer molFile = new StringBuffer ();
365+ StringBuilder molFile = new StringBuilder ();
362366 input .readLine (); // String announceMDLFileLine =
363367 String molFileLine = "" ;
364368 do {
@@ -383,6 +387,34 @@ private IReaction readReaction(IChemObjectBuilder builder) throws CDKException {
383387 throw new CDKException ("Error while reading products" , exception );
384388 }
385389
390+ // now read the products
391+ try {
392+ for (int i = 1 ; i <= agentCount ; i ++) {
393+ StringBuilder molFile = new StringBuilder ();
394+ input .readLine (); // String announceMDLFileLine =
395+ String molFileLine = "" ;
396+ do {
397+ molFileLine = input .readLine ();
398+ molFile .append (molFileLine );
399+ molFile .append ('\n' );
400+ } while (!molFileLine .equals ("M END" ));
401+
402+ // read MDL molfile content
403+ MDLReader reader = new MDLReader (new StringReader (molFile .toString ()), super .mode );
404+ IAtomContainer agent = (IAtomContainer ) reader .read (builder .newInstance (IAtomContainer .class ));
405+ reader .close ();
406+
407+ // add reactant
408+ reaction .addAgent (agent );
409+ }
410+ } catch (CDKException exception ) {
411+ // rethrow exception from MDLReader
412+ throw exception ;
413+ } catch (IOException | IllegalArgumentException exception ) {
414+ logger .debug (exception );
415+ throw new CDKException ("Error while reading products" , exception );
416+ }
417+
386418 // now try to map things, if wanted
387419 logger .info ("Reading atom-atom mapping from file" );
388420 // distribute all atoms over two AtomContainer's
0 commit comments