Class MDReader

java.lang.Object
chemaxon.descriptors.MDReader
Direct Known Subclasses:
MDArrayReader, MDDBReader, MDFileReader

@PublicAPI public abstract class MDReader extends Object
Base class definitions for MDSet input streams. Different descriptors types (as fingerprints, pharmacophore fingerprints) are handled in the same, a transparent manner. Derived classes may differ in the source of initial data they handle: standard molecular structure file, chemical descriptor set file (written by an MDWrite derivative), or database.
Each element read can either get a unique identifier (ID) from the source it comes from, or alternatively an ID can also be generated by the reader.
An MDSet object is returned by the reader in each call. This set can either be re-used or a new instance can be created. This behaviour is determined by setCloneResult( boolean ).
Since:
JChem 2.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected boolean
    indicates if mdSet is cloned or not in next()
    protected int
    starting value of id
    protected boolean
    Generates descriptor from molecule if true, direct read otherwise.
    protected boolean
    generate unique identifiers
    protected int
    unique identifier (ID) of the current element read
    protected String
    name of the tag in the SDfile input which stored the unique structure id
    protected Molecule
    the molecule last read from the structure table
    protected MDSet
    the schema mdSet if descriptors are generated on-the-fly
    protected List<String>
    names of tags that have to be taken from the input Molecule
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Creates an new, empty object.
    protected
    MDReader(MDSet mdSet)
    Creates a molecular structure file or database table reader.
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract void
    Closes down the descriptor stream.
    protected void
    createMDSetComponent(int i, String type, String settings)
    Creates and sets the given component of the internal MDSet object of the given type and specified parameter settings.
    boolean
    Gets the current value of the cloning policy flag.
    Gets the molecular descriptor set.
    Gets the current molecular structure as read from the input file (that is before any transformation were applied).
    abstract MDSet
    Reads the next element from the input and stores it in the MDSet object passed as parameter.
    void
    Initializes the MDSet input stream.
    void
    setCloneResult(boolean cloneResult)
    Sets the cloning policy of the next() method.
    void
    setFirstId(int firstId)
    Sets the ID of the first MDSet.
    void
    setGenerateId(boolean generateId)
    Sets whether ID-s are generated or not.
    void
    Sets the name of the ID tag in the SDfile.
    void
    setTakeTag(int cdSetComponent, String tagName)
    Sets the tag name of a MDSet component.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • id

      protected int id
      unique identifier (ID) of the current element read
    • firstId

      protected int firstId
      starting value of id
    • generateId

      protected boolean generateId
      generate unique identifiers
    • generateDescriptor

      protected boolean generateDescriptor
      Generates descriptor from molecule if true, direct read otherwise.
    • lastReadMolecule

      protected Molecule lastReadMolecule
      the molecule last read from the structure table
    • mdSet

      protected MDSet mdSet
      the schema mdSet if descriptors are generated on-the-fly
    • cloneResult

      protected boolean cloneResult
      indicates if mdSet is cloned or not in next()
    • takeTags

      protected List<String> takeTags
      names of tags that have to be taken from the input Molecule
    • idTagName

      protected String idTagName
      name of the tag in the SDfile input which stored the unique structure id
  • Constructor Details

    • MDReader

      protected MDReader(MDSet mdSet)
      Creates a molecular structure file or database table reader. The reader generates descriptors from the molecule read according to the MDSet parameter passed.
      Parameters:
      mdSet - a sample MDSet object that defines what should be read from the input source
    • MDReader

      protected MDReader()
      Creates an new, empty object.
  • Method Details

    • setGenerateId

      public void setGenerateId(boolean generateId)
      Sets whether ID-s are generated or not. Generated ID-s are positive integers.
      Parameters:
      generateId - ID-s are generated if true, otherwise ID-s are read from the input source
    • setTakeTag

      public void setTakeTag(int cdSetComponent, String tagName)
      Sets the tag name of a MDSet component. If the name is not null, the value of the tag is taken from an SDfile input, otherwise, or in the case when the tag named does not exists in the input file, the desciptor of the specified component is generated.
      Parameters:
      cdSetComponent - index of a component of the MDSet
      tagName - name of the tag to take the value of the descriptor from
    • setIdTagName

      public void setIdTagName(String tagName)
      Sets the name of the ID tag in the SDfile. Unique indentifier is read from that tag if exists, otherwise the value of the identifier is undefined.
      Parameters:
      tagName - name of the ID tag
    • setFirstId

      public void setFirstId(int firstId)
      Sets the ID of the first MDSet. If not set, ID numeration starts from 1.
      Parameters:
      firstId - value of the of the ID of the first MDSet
    • setCloneResult

      public void setCloneResult(boolean cloneResult)
      Sets the cloning policy of the next() method. If set to true returned MDSet objects are new ones, otherswise always the same object is reused and returned (typically, this is passed in the constructor of the class derived from MDReader). By default, cloning policy is set to true. This is the safer option, though it might result in slower operation.
      Parameters:
      cloneResult - indicates cloning behaviour
    • getCloneResult

      public boolean getCloneResult()
      Gets the current value of the cloning policy flag.
      Returns:
      indicator of cloning policy
    • getMDSet

      public MDSet getMDSet()
      Gets the molecular descriptor set. This method is provided in order to allow the used intervene into descriptor generation (for instance by overriding parameter settings).
      Returns:
      the MDSet object
    • reset

      public void reset() throws MDReaderException
      Initializes the MDSet input stream. If the stream is not empty, the subsequent call to next( MDSet cds ) returns the first element.
      Throws:
      MDReaderException - when failed to reset the reader
    • next

      public abstract MDSet next() throws MDReaderException
      Reads the next element from the input and stores it in the MDSet object passed as parameter. This method should be called by the next( ) method of the derived class as the first statement. It clones the internal MDSet instance if needed and increments the id (if id-s are generated).
      Returns:
      the MDSet to be filled in with the next descriptor
      Throws:
      MDReaderException - when failed reading the next descriptor set
    • getMolecule

      public Molecule getMolecule() throws MDReaderException
      Gets the current molecular structure as read from the input file (that is before any transformation were applied). Not all MDReader subclasses can implement this method in a meaningful way, therefore it is not an abstract method (just for the sake of ease).
      Returns:
      always null, see subclasses for meaningful implementation
      Throws:
      MDReaderException - when failed reading the next descriptor set
    • close

      public abstract void close() throws MDReaderException
      Closes down the descriptor stream. After this, no more operation is permitted on the stream.
      Throws:
      MDReaderException - when failed to close the input stream
    • createMDSetComponent

      protected void createMDSetComponent(int i, String type, String settings) throws MDParametersException
      Creates and sets the given component of the internal MDSet object of the given type and specified parameter settings.
      Parameters:
      i - index of the component
      type - class name of the component
      settings - parameter settings
      Throws:
      MDParametersException