public class MolImporter extends MDocSource implements chemaxon.marvin.io.formats.MoleculeImporterIface
The input file format is guessed automatically or specified as an import option to the constructor. Many different formats are supported like "mol", "rgf", "sdf", "rdf", "csmol", "csrgf", "cssdf", "csrdf", "mol2", "cml", "mrv", "smiles", "cxsmiles", "pdb", "xyz", "cube", "name". For more information on formats, please visit File Formats in Marvin. MolImporter can also import gzip compressed and base64 encoded structures.
By default, in case of machines with multiple processors processing is concurrent,
otherwise single-threaded. By default, the number of worker threads is the number
of processors - the number of concurrent threads can be set in
setThreadCount(int).
Serialized Molecule objects can also be imported using the
"chemaxon.struc.Molecule" format. In this case processing is single-threaded.
| Constructor and Description |
|---|
MolImporter(File f)
Create a molecule importer for a file.
|
MolImporter(File f,
String opts)
Create a molecule importer for a file.
|
MolImporter(InputStream is)
Create a molecule importer for an input stream.
|
MolImporter(InputStream is,
String opts)
Create a molecule importer for an input stream.
|
MolImporter(InputStream is,
String opts,
String enc)
Create a molecule importer for an input stream.
|
MolImporter(InputStream is,
String opts,
String enc,
String fileName)
Create a molecule importer for an input stream.
|
MolImporter(String fname)
Create a molecule importer for a file.
|
MolImporter(String fname,
Object component,
String msg)
Create a molecule importer with a progress monitor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Close the underlying input stream.
|
Molecule |
createMol()
Creates a target molecule object for import.
|
int |
estimateNumRecords()
Estimates the total number of records.
|
File |
getFile()
Gets the file object for the input.
|
String |
getFileName()
Gets the name of the input file
|
String |
getFormat()
Get the file format.
|
MPropertyContainer |
getGlobalProperties()
Gets the global properties in a container that was retrieved from
the input stream, earlier.
|
String |
getGrabbedMoleculeString()
Gets the last grabbed molecule string with LF style line endings by default.
|
int |
getLineCount()
Gets the current line number.
|
MolImportModule |
getMolImportModule() |
String |
getOptions()
Gets the import options.
|
boolean |
getQueryMode()
Gets query mode.
|
int |
getRecordCount()
Gets the current record number.
|
int |
getRecordCountMax()
Gets the total number of records read.
|
static MDocument |
importDoc(byte[] b)
Reads a document from a byte array.
|
static MDocument |
importDoc(byte[] b,
String opts,
String enc)
Reads a document from a byte array.
|
static Molecule |
importMol(byte[] b)
Read a molecule from a byte array.
|
static boolean |
importMol(byte[] b,
Molecule mol)
Read a molecule from a byte array.
|
static Molecule |
importMol(byte[] b,
String opts,
String enc)
Read a molecule from a byte array.
|
static boolean |
importMol(byte[] b,
String opts,
String enc,
Molecule mol)
Read a molecule from a byte array.
|
static Molecule |
importMol(String s)
Read a molecule from a string.
|
static Molecule |
importMol(String s,
chemaxon.formats.ImportOptions options)
Read a molecule from a string with the given options.
|
static boolean |
importMol(String s,
Molecule mol)
Read a molecule from a string.
|
static Molecule |
importMol(String s,
String opts)
Read a molecule from a string.
|
static Molecule |
importMol(String s,
String opts,
String enc)
Deprecated.
(Since Marvin 5.5) There is no need to specify an encoding for a String input. Instead,
if you have a String to import, call
importMol(String,String);
if you have a byte array, call importMol(byte[], String, String). |
static boolean |
importMol(String s,
String opts,
String enc,
Molecule mol)
Deprecated.
(Since Marvin 5.5) There is no need to specify an encoding for a String input. Instead,
if you have a String to import, call
importMol(String, String);
if you have a byte array, call importMol(byte[], String, String, Molecule). |
boolean |
isEndReached()
Tests whether the end of input is already reached.
|
boolean |
isGrabbingEnabled()
Deprecated.
as of Marvin 6.2. It has no effect on the code.
|
boolean |
isMolMovie()
Are the imported molecules merged into one multi-set molecule?
|
boolean |
isMultiSet()
Are the imported molecules merged into one multi-set molecule?
|
boolean |
isRewindable()
Tests whether rewinding (seeking backwards) is possible in the
underlying input stream.
|
MDocument |
nextDoc()
Reads the next document.
|
static MDocument |
parseMRV(String sval)
Parses a document from a string in Marvin Document (MRV) format.
|
Molecule |
read()
Read the next molecule.
|
boolean |
read(Molecule mol)
Deprecated.
as of Marvin 14.7.7. use
read() instead |
MDocument |
readDoc(MDocument doc,
Molecule buf)
Deprecated.
as of Marvin 14.7.7. use
nextDoc() instead |
Molecule |
readMol(Molecule mol)
Deprecated.
as of Marvin 14.7.7. use
read() instead |
String |
readRecordAsText()
Reads the next molecule in text format without creating a
Molecule object. |
void |
seekRecord(int k,
MProgressMonitor pmon)
Seek the specified record.
|
protected void |
seekVisitedRecord(int k)
Seeks an already visited position in case of rewindable input.
|
void |
setGrabbingEnabled(boolean v)
Deprecated.
as of Marvin 6.2. It has no effect on the code.
|
void |
setQueryMode(boolean q)
Sets query mode.
|
void |
setThreadCount(int threadCount)
Sets the number of threads for concurrent processing.
|
boolean |
skipRecord()
Skips the next molecule or document instead of reading it into memory.
|
long |
tell()
Returns the current file offset.
|
getDocLabel, getMoleculeIterator, iterator, seekForward, seekRecordAtFraction, skipRecordspublic MolImporter(InputStream is) throws IOException, MolFormatException
is - the input stream to readIOException - If I/O error occured when determining
the file format.MolFormatException - If the molecule file is in a
format that cannot be readIllegalCharsetNameException - if illegal encoding is usedUnsupportedCharsetException - if unsupported encoding is usedpublic MolImporter(InputStream is, String opts) throws IOException, MolFormatException
is - the input stream to readopts - the file format and/or options separated by a colon;
use null for automatic format recognition
and default optionsIOException - If I/O error occured when determining
the file format.MolFormatException - If the molecule file is in a
format that cannot be readIllegalCharsetNameException - if illegal encoding is usedUnsupportedCharsetException - if unsupported encoding is usedpublic MolImporter(InputStream is, String opts, String enc) throws IOException, MolFormatException
is - the input stream to readopts - the file format and/or options separated by a colon;
use null for automatic format recognition
and default optionsenc - charset name or nullIOException - If I/O error occured when determining
the file format.MolFormatException - If the molecule file is in a
format that cannot be readIllegalCharsetNameException - if illegal encoding is usedUnsupportedCharsetException - if unsupported encoding is usedpublic MolImporter(InputStream is, String opts, String enc, String fileName) throws IOException, MolFormatException
is - the input stream to readopts - the file format and/or options separated by a colon;
use null for automatic format recognition
and default optionsenc - charset name or nullfileName - the original filename the stream is reading fromIOException - If I/O error occured when determining
the file format.MolFormatException - If the molecule file is in a
format that cannot be readIllegalCharsetNameException - if illegal encoding is usedUnsupportedCharsetException - if unsupported encoding is usedpublic MolImporter(File f, String opts) throws IOException
f - the file to readopts - the file format and/or options separated by a colon;
use null for automatic format recognition
and default optionsIOException - If I/O error occured when determining
the file format.MolFormatException - If the molecule file is in a
format that cannot be readIllegalCharsetNameException - if illegal encoding is usedUnsupportedCharsetException - if unsupported encoding is usedtell(),
close()public MolImporter(File f) throws IOException
f - the file to readIOException - If I/O error occured when determining
the file format.MolFormatException - If the molecule file is in a
format that cannot be readIllegalCharsetNameException - if illegal encoding is usedUnsupportedCharsetException - if unsupported encoding is usedtell(),
close()public MolImporter(String fname) throws IOException, MolFormatException
fname - name of the file to readIOException - If I/O error occured when determining
the file format.MolFormatException - If the molecule file is in a
format that cannot be readIllegalCharsetNameException - if illegal encoding is usedUnsupportedCharsetException - if unsupported encoding is usedtell(),
close()public MolImporter(String fname, Object component, String msg) throws IOException, MolFormatException
fname - name of the file to readcomponent - the parent componentmsg - displayed message, where %p is replaced by the
file pathIOException - If I/O error occured when determining
the file format.MolFormatException - If the molecule file is in a
format that cannot be readIllegalCharsetNameException - if illegal encoding is usedUnsupportedCharsetException - if unsupported encoding is usedtell(),
close()public String getFileName()
public File getFile()
public String getOptions()
public MolImportModule getMolImportModule()
@Deprecated public boolean isGrabbingEnabled()
true if enabled, false if disabled@Deprecated public void setGrabbingEnabled(boolean v)
v - true enables, false disables itpublic String getGrabbedMoleculeString()
public boolean isMultiSet()
true if the input is a multi-set moleculepublic boolean isMolMovie()
true if the input is a multi-set moleculepublic void setThreadCount(int threadCount)
throws IllegalStateException
1 CPU.threadCount - the number of threads, set 0 for the number of CPUs,
1 for single-threaded modeIllegalStateException - if concurrent processing is already started or
if object input stream is used instead of record importerpublic boolean getQueryMode()
public void setQueryMode(boolean q)
q - query modepublic Molecule read() throws IOException
read in interface chemaxon.marvin.io.formats.MoleculeImporterIfacenull at end of fileIOException - If I/O error occuredpublic Molecule createMol()
public MDocument nextDoc() throws IOException
nextDoc in class MDocSourcenull at end of fileIOException - If I/O error occured@Deprecated public MDocument readDoc(MDocument doc, Molecule buf) throws MolFormatException, IOException
nextDoc() insteaddoc - target document object or nullbuf - target molecule object or nullnull at end of fileIOException - If I/O error occuredMolFormatException@Deprecated public Molecule readMol(Molecule mol) throws MolFormatException, IOException
read() insteadnull then processing is
single-threaded.mol - target molecule objectnull at end of fileIOException - If I/O error occuredMolFormatException@Deprecated public boolean read(Molecule mol) throws IOException
read() insteadnull then the processing is
single-threaded.
This method requires the parameter 'mol' molecule to be created with MolImporter.createMol() method.mol - target molecule objecttrue after success,
false at end of fileIOException - If I/O error occuredpublic boolean skipRecord()
throws MolFormatException,
IOException
skipRecord in class MDocSourcetrue if the end of molecule is found,
false if there is no chance to continueIOException - if read error occuredMolFormatExceptionpublic String readRecordAsText() throws MRecordParseException, MolExportException, IOException
Molecule object.
Processing is single-threaded.null at end of fileMRecordParseException - If the record could not be parsedMolExportException - if binary data cannot be exported
to MRV format textIOException - if read error occuredpublic boolean isRewindable()
false.
Therefore this method should not be called before calling setThreadCount(int).isRewindable in class MDocSourcetrue if rewinding is possible,
false otherwiseseekRecord(int, MProgressMonitor),
setThreadCount(int)public void seekRecord(int k,
MProgressMonitor pmon)
throws EOFException,
IOException
setThreadCount(int).
Backward seeking (rewinding) in the stream is only possible if the
underlying input stream is seekable. Note, that in concurrent mode
this is not true, the import is not rewindable.
Forward seeking is always possible.
Seeking terminates before reaching the specified position if the
user cancels the progress dialog.seekRecord in class MDocSourcek - positionpmon - progress monitor or nullEOFException - if end of file reached while trying to seekIOException - if read error occuredisRewindable(),
setThreadCount(int)protected void seekVisitedRecord(int k)
throws IOException
setThreadCount(int).seekVisitedRecord in class MDocSourcek - the record indexIOException - if read error occuredsetThreadCount(int)public boolean isEndReached()
isEndReached in class MDocSourcetrue if the end was reached,
false otherwisepublic int estimateNumRecords()
estimateNumRecords in class MDocSourcepublic long tell()
throws IOException
IOException - if the position cannot be determinedpublic int getLineCount()
setThreadCount(int).setThreadCount(int)public int getRecordCount()
getRecordCount in class MDocSourcepublic int getRecordCountMax()
getRecordCountMax in class MDocSourcepublic void close()
throws IOException
close in interface chemaxon.marvin.io.formats.MoleculeImporterIfaceclose in interface Closeableclose in interface AutoCloseableclose in class MDocSourceIOException - If an I/O error has occurred.public String getFormat()
public static Molecule importMol(byte[] b) throws MolFormatException
b - the molecule file contentsMolFormatException - If the molecule file is in a
format that cannot be readpublic static Molecule importMol(byte[] b, String opts, String enc) throws MolFormatException
b - the molecule file contentsopts - the file format and/or options separated by a colon;
use null for automatic format recognition
and default optionsenc - encoding or nullMolFormatException - If the molecule file is in a
format that cannot be readpublic static boolean importMol(byte[] b,
Molecule mol)
throws MolFormatException
b - the molecule file contentsmol - target molecule objectMolFormatException - If the molecule file is in a
format that cannot be readpublic static boolean importMol(byte[] b,
String opts,
String enc,
Molecule mol)
throws MolFormatException
b - the molecule file contentsopts - the file format and/or options separated by a colon;
use null for automatic format recognition
and default optionsenc - encoding or nullmol - target molecule objectMolFormatException - If the molecule file is in a
format that cannot be readpublic static MDocument importDoc(byte[] b) throws MolFormatException
b - the file contentsnull if no document found in inputMolFormatException - If the molecule file is in a
format that cannot be readpublic static MDocument importDoc(byte[] b, String opts, String enc) throws MolFormatException
b - the file contentsopts - the file format and/or options separated by a colon;
use null for automatic format recognition
and default optionsenc - encoding or nullnull if no document found in inputMolFormatException - If the molecule file is in a
format that cannot be readpublic static Molecule importMol(String s) throws MolFormatException
importMol(String,String) to avoid
wasting time with format recognition.
Processing is single-threaded.s - the molecule file contentsMolFormatException - If the molecule file is in a
format that cannot be readpublic static Molecule importMol(String s, String opts) throws MolFormatException
s - the molecule file contentsopts - the file format and/or options separated by a colon;
use null for automatic format recognition
and default optionsMolFormatException - If the molecule file is in a
format that cannot be readpublic static Molecule importMol(String s, chemaxon.formats.ImportOptions options) throws MolFormatException
s - the molecule file contentsoptions - options defined by an options objectMolFormatException - If the molecule file is in a
format that cannot be read@Deprecated public static Molecule importMol(String s, String opts, String enc) throws MolFormatException
importMol(String,String);
if you have a byte array, call importMol(byte[], String, String).s - the molecule file contentsopts - the file format and/or options separated by a colon;
use null for automatic format recognition
and default optionsenc - encoding or nullMolFormatException - If the molecule file is in a
format that cannot be readpublic static boolean importMol(String s, Molecule mol) throws MolFormatException
s - the file contentsmol - target molecule objectMolFormatException - If the molecule file is in a
format that cannot be read@Deprecated public static boolean importMol(String s, String opts, String enc, Molecule mol) throws MolFormatException
importMol(String, String);
if you have a byte array, call importMol(byte[], String, String, Molecule).s - the file contentsopts - the file format and/or options separated by a colon;
use null for automatic format recognition
and default optionsenc - encoding or nullmol - target molecule objectMolFormatException - If the molecule file is in a
format that cannot be readpublic MPropertyContainer getGlobalProperties()
public static MDocument parseMRV(String sval) throws IOException
sval - the stringIOException