Class 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 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
  • Constructor Details

    • 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

      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 Details

    • getFormat

      public IResourceFormat getFormat()
      Description copied from interface: IChemObjectIO
      Returns the IResourceFormat class for this IO class.
    • hasNext

      public boolean hasNext()
      Returns true if another IAtomContainer 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 IAtomContainer.
    • 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 interface Iterator<IAtomContainer>
      Overrides:
      remove in class DefaultIteratingChemObjectReader<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()