Class MDFileReader


  • @PublicAPI
    public class MDFileReader
    extends MDReader
    Reads MDSet objects from a text file. The input text file can either be a molecular structure file (for example SDfile, MOL file etc.) or it can be a molecular descriptor file written by MDFileWriter. In both cases an MDSet object created by the client of this class is build and returned by the reader methods. The two kinds of operation requires two different ways to create the MDFileReader object, see appropriate constructors.
    Since:
    JChem 2.0
    • Constructor Detail

      • MDFileReader

        public MDFileReader​(String inputFileName)
                     throws MDReaderException
        Creates and initialises a MDSet file reader for reading one single MolecularDescriptor. This works for descriptor files written by MDFileWriter.
        Parameters:
        inputFileName - name of the descriptor input file
        Throws:
        MDReaderException - if the record couldn't be read.
      • MDFileReader

        public MDFileReader​(String[] inputFileNames)
                     throws MDReaderException
        Creates and initialises an MDSet file reader for reading multiple MolecularDescriptor components.
        Parameters:
        inputFileNames - input file names
        Throws:
        MDReaderException - if the record couldn't be read.
      • MDFileReader

        public MDFileReader​(String inputFileName,
                            MDSet mdSet)
                     throws MDReaderException
        Creates and intializes a file reader that reads a molecular structure file. Since the molecular structure file does not carry any information about the descriptors to be generated for molecules retrieved, an MDSet template has to be provided in this constructor. This has to be properly initialized (apparently, by default constructors) as this specifies what kind of descriptors are read from the molecule file.
        Parameters:
        inputFileName - name of the input molecular structure file
        mdSet - sample Molecular Descriptor Set
        Throws:
        MDReaderException - if the record couldn't be read.
      • MDFileReader

        public MDFileReader​(InputStream inputFile,
                            MDSet mdSet)
                     throws MDReaderException
        Creates and intializes a file reader that reads a molecular structure file. Since the molecular structure file does not carry any information about the descriptors to be generated for molecules retrieved, an MDSet template has to be provided in this constructor. This has to be properly initialized (apparently, by default constructors) as this specifies what kind of descriptors are read from the molecule file.
        Parameters:
        inputFile - input molecular structure file
        mdSet - sample Molecular Descriptor Set
        Throws:
        MDReaderException - if the record couldn't be read.
    • Method Detail

      • setKeepOriginalMolecule

        public void setKeepOriginalMolecule​(boolean keep)
        Sets if original molecule, as read from the input file, has to be saved or not. Saving the original is useful in the case when the original molecule has to be used in other parts of the application (for instance a typical need is to write back the molecule into an SDfile). The generation of MolecularDescriptor transforms the original structure. The opriginal molecule can be retrieved by getMolecule(). This method is applicable only if the input file is a molecular structure file.
        Parameters:
        keep - indicates if the original structure has to be preserved or not
      • 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).
        Overrides:
        getMolecule in class MDReader
        Returns:
        always null, see subclasses for meaningful implementation
        Throws:
        MDReaderException - when failed reading the next descriptor set
      • reset

        public void reset()
                   throws MDReaderException
        Resets the stream. The first call of next( MDSet cds ) after reset() reads the first line of the input stream.
        Overrides:
        reset in class MDReader
        Throws:
        MDReaderException - when failed to reset the reader
      • next

        public MDSet next()
                   throws MDReaderException
        Reads the next MDSet object from the input source. The returned object is either reused or always a new instance is created depending on setCloneResult() settings.
        Specified by:
        next in class MDReader
        Returns:
        the descriptors read from the input source
        Throws:
        MDReaderException - when file is corrupt
      • close

        public void close()
                   throws MDReaderException
        Closes the reader. No more operation is allowed on the reader after it has been closed.
        Specified by:
        close in class MDReader
        Throws:
        MDReaderException - i/o errors are reinterpreted