Logo Search packages:      
Sourcecode: cdk version File versions  Download package

IChemObject org::openscience::cdk::io::MACiEReader::readReactions ( boolean  selectEntry  )  throws CDKException, IOException [inline, private]

Read a Reaction from a file in MACiE RDF format.

Returns:
The Reaction that was read from the MDL file.

Definition at line 227 of file MACiEReader.java.

References org::openscience::cdk::ChemSequence::addChemModel(), CreationDate, org::openscience::cdk::tools::LoggingTool::debug(), org::openscience::cdk::tools::LoggingTool::error(), org::openscience::cdk::io::DefaultChemObjectReader::fireFrameRead(), org::openscience::cdk::io::setting::IntegerIOSetting::getSettingValue(), org::openscience::cdk::tools::LoggingTool::info(), org::openscience::cdk::ChemObject::setProperty(), org::openscience::cdk::ChemModel::setReactionSet(), and org::openscience::cdk::tools::LoggingTool::warn().

Referenced by read().

                                                                                            {
        ChemSequence entries = new ChemSequence();
        currentEntry = null;
        int entryCounter = 0;
        currentReactionStepSet = null;
        
        while (input.ready()) {
            String line = input.readLine();
            if (line.startsWith("$RDFILE")) {
                entries = new ChemSequence();
            } else if (line.startsWith("$DATM")) {
                entries.setProperty(CreationDate, line.substring(7));
            } else if (line.startsWith("$RIREG")) {
                // new entry, store previous entry if any
                if (currentEntry != null) {
                    // store previous entry
                    currentEntry.setReactionSet(currentReactionStepSet);
                    createNiceMACiETitle(currentEntry);
                    entries.addChemModel(currentEntry);
                    fireFrameRead();
                    if (selectEntry && (entryCounter == selectedEntry.getSettingValue())) {
                        logger.info("Starting reading wanted frame: ", selectedEntry);
                        return currentEntry;
                    } else {
                        logger.debug("Not reading unwanted frame: " + entryCounter);
                    }
                }
                currentEntry = new ChemModel();
                entryCounter++;
                if (!selectEntry || entryCounter == selectedEntry.getSettingValue()) {
                    readThisEntry = true;
                } else {
                    readThisEntry = false;
                }
                currentReactionStepSet = new ReactionSet();
            } else if (line.startsWith("$DTYPE")) {
                String[] tuple = readDtypeDatumTuple(line);
                String dataType = tuple[0];
                String datum   = tuple[1];
                
                // now some regular expression wizardry
                Matcher subLevelMatcher = subLevelDatum.matcher(dataType);
                if (subLevelMatcher.matches()) {
                    // sub level field found
                    String field = subLevelMatcher.group(2);
                    String fieldNumber = subLevelMatcher.group(3);
                    String subfield = subLevelMatcher.group(4);
                    processSubLevelField(field, fieldNumber, subfield, datum);
                } else {
                    Matcher topLevelMatcher = topLevelDatum.matcher(dataType);
                    if (topLevelMatcher.matches()) {
                        // top level field found
                        String field = topLevelMatcher.group(2);
                        processTopLevelField(field, datum);
                    } else {
                        logger.error("Could not parse datum tuple of type ", dataType,
                                     " around line " + input.getLineNumber());
                    }
                }
            } else {
                logger.warn("Unrecognized command on line " + input.getLineNumber(), ": ", line);
            }
        }
        
        if (currentEntry != null) {
            createNiceMACiETitle(currentEntry);
            // store last entry
            currentEntry.setReactionSet(currentReactionStepSet);
            entries.addChemModel(currentEntry);
            fireFrameRead();
        }
        
        if (selectEntry) {
            // apparently selected last one, other already returned
            return currentEntry;
        }
        return entries;
    }


Generated by  Doxygen 1.6.0   Back to index