Class RdfileReader
- All Implemented Interfaces:
Closeable,AutoCloseable,Iterator<RdfileRecord>
This class facilitates reading RDFiles the specification of which was initially published in [Dalby, A. et. al.. Journal of Chemical Information and Computer Sciences. 1992. 32] and is now maintained by Daussault Systems [Dassault Systèmes, CTFile Formats Biovia Databases 2020, 2020, Dassault Systèmes, https://discover.3ds.com/sites/default/files/2020-08/biovia_ctfileformats_2020.pdf].
An RDFile is composed of- an RDFile header
- one or more records where each record comprises
- an optional internal or external registry number
- a molecule represented as a MolFile in V2000 or V3000 format or a reaction represented as an RxnFile in V2000 or V3000 format
- an optional data block that consists of one or more (data field identifier, data) pairs
// read an RDF that is expected to only contain molecules
List<IAtomContainer> molecules = new ArrayList<>();
try (RdfileReader rdfileReader = new RdfileReader(new FileReader("molecules.rdf"), SilentChemObjectBuilder.getInstance())) {
while(rdfileReader.hasNext()) {
final RdfileRecord rdfileRecord = rdfileReader.next();
if (rdfileRecord.isMolfile()) {
molecules.add(rdfileRecord.getAtomContainer());
} else {
// create log entry or throw exception as only molecules are expected in this RDF
}
}
}
By default, any remaining records are skipped if an error is encountered in a record. This can be changed
by using one of the constructors that allows to provide a boolean value for the argument
continueOnError (one takes an #RdfileReader(InputStream,IChemObject,boolean) InputStream,
the other one a #RdfileReader(Reader,IChemObject,boolean) Reader).
- Author:
- Uli Fechner
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionRdfileReader(InputStream in, IChemObjectBuilder chemObjectBuilder) Creates a new RdfileReader instance with the given InputStream and IChemObjectBuilder.RdfileReader(InputStream in, IChemObjectBuilder chemObjectBuilder, boolean continueOnError) Creates a new RdfileReader instance with the given InputStream and IChemObjectBuilder.RdfileReader(Reader reader, IChemObjectBuilder chemObjectBuilder, boolean continueOnError) Creates a new RdfileReader instance with the given InputStream and IChemObjectBuilder. -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Iterator
forEachRemaining, remove
-
Constructor Details
-
RdfileReader
Creates a new RdfileReader instance with the given InputStream and IChemObjectBuilder.- Parameters:
in- the InputStream serving the RDfile datachemObjectBuilder- the IChemObjectBuilder for creating CDK objects
-
RdfileReader
Creates a new RdfileReader instance with the given InputStream and IChemObjectBuilder.If
continueOnErroristrueremaining records are processed when an error is encountered; iffalseall remaining records in the file are skipped.- Parameters:
in- the InputStream serving the RDfile datachemObjectBuilder- the IChemObjectBuilder for creating CDK objectscontinueOnError- determines whether to continue processing records in case an error is encountered
-
RdfileReader
Creates a new RdfileReader instance with the given InputStream and IChemObjectBuilder.If
continueOnErroristrueremaining records are processed when an error is encountered; iffalseall remaining records in the file are skipped.- Parameters:
reader- the Reader providing the RDfile datachemObjectBuilder- the IChemObjectBuilder for creating CDK objectscontinueOnError- determines whether to continue processing records in case an error is encountered
-
-
Method Details
-
hasNext
public boolean hasNext()- Specified by:
hasNextin interfaceIterator<RdfileRecord>
-
next
- Specified by:
nextin interfaceIterator<RdfileRecord>
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-