org.openscience.cdk.io.iterator
Class IteratingSDFReader

java.lang.Object
  extended by org.openscience.cdk.io.ChemObjectIO
      extended by org.openscience.cdk.io.iterator.DefaultIteratingChemObjectReader<IAtomContainer>
          extended by org.openscience.cdk.io.iterator.IteratingSDFReader
All Implemented Interfaces:
Closeable, Iterator<IAtomContainer>, IChemObjectIO, IChemObjectReader, IIteratingChemObjectReader<IAtomContainer>

@TestClass(value="org.openscience.cdk.io.iterator.IteratingSDFReaderTest")
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 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");
 IteratingMDLReader reader = new IteratingMDLReader(
   new FileInputStream(sdfFile), DefaultChemObjectBuilder.getInstance()
 );
 while (reader.hasNext()) {
   IMolecule molecule = (IMolecule)reader.next();
 }
 

Author:
Egon Willighagen
See Also:
MDLV2000Reader, MDLV3000Reader
Keywords:
file format, MDL molfile, file format, SDF
Created on:
2003-10-19
Belongs to CDK module:
io
Source code:
cdk-1.4.x

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.openscience.cdk.io.IChemObjectReader
IChemObjectReader.Mode
 
Constructor Summary
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
 void close()
          Closes this IChemObjectIO's resources.
 void customizeJob()
           
 IResourceFormat getFormat()
          Returns the IResourceFormat class for this IO class.
 boolean hasNext()
          Returns true if another IMolecule can be read.
 IAtomContainer next()
          Returns the next IMolecule.
 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, getIOSettings, getListeners, getSetting, getSetting, getSettings, hasSetting, removeChemObjectIOListener
 
Methods inherited from class java.lang.Object
equals, 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
 

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 from
builder - The builder

IteratingSDFReader

@TestMethod(value="testReadDataItems")
public IteratingSDFReader(InputStream in,
                                          IChemObjectBuilder builder)
Constructs a new IteratingMDLReader that can read Molecule from a given InputStream.

Parameters:
in - The InputStream to read from
builder - 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 - the InputStream to read from
builder - builder to use
skip - 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 - the Reader to read from
builder - builder to use
skip - whether to skip null molecules
Method Detail

getFormat

@TestMethod(value="testGetFormat")
public IResourceFormat getFormat()
Description copied from interface: IChemObjectIO
Returns the IResourceFormat class for this IO class.


hasNext

public boolean hasNext()
Returns true if another IMolecule 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 next IMolecule.


close

@TestMethod(value="testClose")
public void close()
           throws IOException
Description copied from interface: IChemObjectIO
Closes this IChemObjectIO's resources.

Throws:
IOException

remove

public void remove()
Description copied from class: DefaultIteratingChemObjectReader
File IO generally does not support removing of entries.

Specified by:
remove in interface Iterator<IAtomContainer>
Overrides:
remove in class DefaultIteratingChemObjectReader<IAtomContainer>

setReader

@TestMethod(value="testSetReader_Reader")
public void setReader(Reader reader)
Description copied from interface: IChemObjectReader
Sets the Reader from which this ChemObjectReader should read the contents.


setReader

@TestMethod(value="testSetReader_InputStream")
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()