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>
public class IteratingSDFReader extends DefaultIteratingChemObjectReader<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 theMDLV2000Reader
orMDLV3000Reader
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:
MDLV2000Reader
,MDLV3000Reader
- 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
Constructors Constructor Description IteratingSDFReader(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes this IChemObjectIO's resources.void
customizeJob()
IResourceFormat
getFormat()
Returns theIResourceFormat
class for this IO class.boolean
hasNext()
Returns true if anotherIAtomContainer
can be read.IAtomContainer
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
setReader(Reader reader)
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 Detail
-
IteratingSDFReader
public IteratingSDFReader(Reader in, IChemObjectBuilder builder)
Constructs a new IteratingMDLReader that can read Molecule from a given Reader.- Parameters:
in
- The Reader to read frombuilder
- The builder
-
IteratingSDFReader
public IteratingSDFReader(InputStream in, IChemObjectBuilder builder)
Constructs a new IteratingMDLReader that can read Molecule from a given InputStream.- Parameters:
in
- The InputStream to read frombuilder
- The builder
-
IteratingSDFReader
public IteratingSDFReader(InputStream in, IChemObjectBuilder builder, boolean skip)
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
public IteratingSDFReader(Reader in, IChemObjectBuilder builder, boolean skip)
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 Detail
-
getFormat
public IResourceFormat 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
public IAtomContainer next()
Returns the nextIAtomContainer
.
-
close
public void close() throws IOException
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
public void setReader(Reader reader)
Description copied from interface:IChemObjectReader
Sets the Reader from which this ChemObjectReader should read the contents.
-
setReader
public void setReader(InputStream reader)
Description copied from interface:IChemObjectReader
Sets the InputStream from which this ChemObjectReader should read the contents.
-
customizeJob
public void customizeJob()
-
-