Package org.openscience.cdk.io.iterator
Class IteratingSDFReader
java.lang.Object
org.openscience.cdk.io.ChemObjectIO
org.openscience.cdk.io.iterator.DefaultIteratingChemObjectReader<IAtomContainer>
org.openscience.cdk.io.iterator.IteratingSDFReader
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Iterator<IAtomContainer>
,IChemObjectIO
,IChemObjectReader
,IIteratingChemObjectReader<IAtomContainer>
Iterating MDL SDF reader. It allows to iterate over all molecules
in the SD file, without reading them into memory first. Suitable
for (very) large SDF files. For parsing the molecules in the
SD file, it uses the
MDLV2000Reader
or
MDLV3000Reader
reader; it does not work
for SDF files with MDL formats prior to the V2000 format.
Example use:
File sdfFile = new File("../zinc-structures/ZINC_subset3_3D_charged_wH_maxmin1000.sdf"); IteratingSDFReader reader = new IteratingSDFReader( new FileInputStream(sdfFile), DefaultChemObjectBuilder.getInstance() ); while (reader.hasNext()) { IAtomContainer molecule = (IAtomContainer)reader.next(); }
- Author:
- Egon Willighagen <egonw@sci.kun.nl>
- See Also:
- Source code:
- main
- Belongs to CDK module:
- io
- Keywords:
- file format, MDL molfile, file format, SDF
- Created on:
- 2003-10-19
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.openscience.cdk.io.IChemObjectReader
IChemObjectReader.Mode
-
Field Summary
Fields inherited from class org.openscience.cdk.io.iterator.DefaultIteratingChemObjectReader
errorHandler, mode
-
Constructor Summary
ConstructorsConstructorDescriptionIteratingSDFReader
(InputStream in, IChemObjectBuilder builder) Constructs a new IteratingMDLReader that can read Molecule from a given InputStream.IteratingSDFReader
(InputStream in, IChemObjectBuilder builder, boolean skip) Constructs a new IteratingMDLReader that can read Molecule from a given a InputStream.IteratingSDFReader
(Reader in, IChemObjectBuilder builder) Constructs a new IteratingMDLReader that can read Molecule from a given Reader.IteratingSDFReader
(Reader in, IChemObjectBuilder builder, boolean skip) Constructs a new IteratingMDLReader that can read Molecule from a given a Reader. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes this IChemObjectIO's resources.void
Returns theIResourceFormat
class for this IO class.boolean
hasNext()
Returns true if anotherIAtomContainer
can be read.next()
Returns the nextIAtomContainer
.void
remove()
File IO generally does not support removing of entries.void
setReader
(InputStream reader) Sets the InputStream from which this ChemObjectReader should read the contents.void
Sets the Reader from which this ChemObjectReader should read the contents.void
setSkip
(boolean skip) Indicate whether the reader should skip over SDF records that cause problems.Methods inherited from class org.openscience.cdk.io.iterator.DefaultIteratingChemObjectReader
accepts, handleError, handleError, handleError, handleError, setErrorHandler, setReaderMode
Methods inherited from class org.openscience.cdk.io.ChemObjectIO
addChemObjectIOListener, addSetting, addSettings, fireIOSettingQuestion, getIOSettings, getListeners, getSetting, getSetting, getSettings, hasSetting, removeChemObjectIOListener
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.openscience.cdk.io.IChemObjectIO
addChemObjectIOListener, addSetting, addSettings, getIOSettings, getListeners, getSetting, getSetting, getSettings, hasSetting, removeChemObjectIOListener
Methods inherited from interface java.util.Iterator
forEachRemaining
-
Constructor Details
-
IteratingSDFReader
Constructs a new IteratingMDLReader that can read Molecule from a given Reader.- Parameters:
in
- The Reader to read frombuilder
- The builder
-
IteratingSDFReader
Constructs a new IteratingMDLReader that can read Molecule from a given InputStream.- Parameters:
in
- The InputStream to read frombuilder
- The builder
-
IteratingSDFReader
Constructs a new IteratingMDLReader that can read Molecule from a given a InputStream. This constructor allows specification of whether the reader will skip 'null' molecules. If skip is set to false and a broken/corrupted molecule is read the iterating reader will stop at the broken molecule. However if skip is set to true then the reader will keep trying to read more molecules until the end of the file is reached.- Parameters:
in
- theInputStream
to read frombuilder
- builder to useskip
- whether to skip null molecules
-
IteratingSDFReader
Constructs a new IteratingMDLReader that can read Molecule from a given a Reader. This constructor allows specification of whether the reader will skip 'null' molecules. If skip is set to false and a broken/corrupted molecule is read the iterating reader will stop at the broken molecule. However if skip is set to true then the reader will keep trying to read more molecules until the end of the file is reached.- Parameters:
in
- theReader
to read frombuilder
- builder to useskip
- whether to skip null molecules
-
-
Method Details
-
getFormat
Description copied from interface:IChemObjectIO
Returns theIResourceFormat
class for this IO class. -
hasNext
public boolean hasNext()Returns true if anotherIAtomContainer
can be read. -
setSkip
public void setSkip(boolean skip) Indicate whether the reader should skip over SDF records that cause problems. If true the reader will fetch the next molecule- Parameters:
skip
- ignore error molecules continue reading
-
next
Returns the nextIAtomContainer
. -
close
Description copied from interface:IChemObjectIO
Closes this IChemObjectIO's resources.- Throws:
IOException
- when the wrapper IO class cannot be closed.
-
remove
public void remove()Description copied from class:DefaultIteratingChemObjectReader
File IO generally does not support removing of entries.- Specified by:
remove
in interfaceIterator<IAtomContainer>
- Overrides:
remove
in classDefaultIteratingChemObjectReader<IAtomContainer>
-
setReader
Description copied from interface:IChemObjectReader
Sets the Reader from which this ChemObjectReader should read the contents. -
setReader
Description copied from interface:IChemObjectReader
Sets the InputStream from which this ChemObjectReader should read the contents. -
customizeJob
public void customizeJob()
-