private IReactionSet readReactionSet ( IReactionSet setOfReactions ) throws CDKException { IReaction r = readReaction ( setOfReactions . getBuilder ( ) ) ; if ( r != null ) { setOfReactions . addReaction ( r ) ; } try { String line ; while ( ( line = input . readLine ( ) ) != null ) { logger . debug ( "line: " , line ) ; // apparently, this is a SDF file, continue with // reading mol files if ( line . equals ( "$$$$" ) ) { r = readReaction ( setOfReactions . getBuilder ( ) ) ; if ( r != null ) { setOfReactions . addReaction ( r ) ; } } else { // here the stuff between 'M END' and '$$$$' if ( r != null ) { // ok, the first lines should start with '>' String fieldName = null ; if ( line . startsWith ( "> " ) ) { // ok, should extract the field name int index = line . indexOf ( ' ' ) ; if ( index != - 1 ) { int index2 = line . substring ( index ) . indexOf ( ' ' ) ; if ( index2 != - 1 ) { fieldName = line . substring ( index + 1 , index + index2 ) ; } } // end skip all other lines while ( ( line = input . readLine ( ) ) != null && line . startsWith ( ">" ) ) { logger . debug ( "data header line: " , line ) ; } } if ( line == null ) { throw new CDKException ( "Expecting data line here, but found null!" ) ; } String data = line ; while ( ( line = input . readLine ( ) ) != null && line . trim ( ) . length ( ) > 0 ) { if ( line . equals ( "$$$$" ) ) { logger . error ( "Expecting data line here, but found end of molecule: " , line ) ; break ; } logger . debug ( "data line: " , line ) ; data += line ; // preserve newlines, unless the line is exactly 80 chars; in that case it // is assumed to continue on the next line. See MDL documentation. if ( line . length ( ) < 80 ) data += "\n" ; } if ( fieldName != null ) { logger . info ( "fieldName, data: " , fieldName , ", " , data ) ; r . setProperty ( fieldName , data ) ; } } } } } catch ( CDKException cdkexc ) { throw cdkexc ; } catch ( IOException exception ) { String error = "Error while parsing SDF" ; logger . error ( error ) ; logger . debug ( exception ) ; throw new CDKException ( error , exception ) ; } return setOfReactions ; }
Read a IReactionSet from a file in MDL RDF format .