public class MFileFormatUtil extends Object
Modifier and Type | Field and Description |
---|---|
static int |
MOLMOVIE
Read multi-molecule files as movies.
|
static int |
MULTISET
The multi-molecule file really contains multiple atom sets of one
molecule.
|
static int |
NOMOLMOVIE
Do not read multi-molecule XYZ files as movies.
|
Constructor and Description |
---|
MFileFormatUtil() |
Modifier and Type | Method and Description |
---|---|
static String[] |
convertToSmilingFormat(Molecule m)
Tries to convert a molecule to a SMILES related format.
|
static String[] |
convertToSmilingFormat(MProp p)
Try to convert a property to text with a SMILES related format argument.
|
static MolExportModule |
createExportModule(String fmt)
Creates an export module for the specified format.
|
static MolExportModule |
createExportModule(String fmt,
String enc)
Creates an export module for the specified format with the specified encoding.
|
static MRecordReader |
createRecordReader(InputStream is,
String opts)
Creates a record reader for an input stream.
|
static MRecordReader |
createRecordReader(InputStream is,
String opts,
String enc,
String path)
Creates a record reader for an input stream.
|
static MFileFormat[] |
findFormats(String fmt,
long flags,
long mask)
Gets a list of formats.
|
static String[] |
getEncodingFromOptions(String fmtopts)
Gets the encoding that was explicitly given as an import option.
|
static String |
getFileExtensionLC(File f)
Gets the file extension in lower case.
|
static String |
getFileExtensionLC(String fname)
Gets the file extension in lower case.
|
static MFileFormat |
getFormat(String fmt)
Gets the file format descriptor for the specified codename.
|
static List<String> |
getFormatNamesWithExtension(String fileName) |
static String |
getKnownExtension(String fname)
Returns the file extension if it is a known extension.
|
static String[] |
getMolfileExtensions()
Gets the array of known molecule file extensions.
|
static String[] |
getMolfileFormats()
Gets the array of known molecule file formats.
|
static String |
getMostLikelyMolFormat(String fname)
Gets the most likey molecule file format from the file name extension.
|
static String |
getUnguessableFormat(String fname)
Gets the file format from the file name extension for formats that
are not guessable from the file content.
|
static boolean |
isOutputCleanable(String fmt)
Tests whether the specified output format is cleanable.
|
static boolean |
isSubFormatOf(String f,
String other)
Tests whether a format is a sub-format of another format.
|
static boolean |
isURLOrFileName(String s)
Tests whether the specified string is an URL (absolute or relative)
or file name.
|
static int |
preprocessFormatAndOptions(String[] fmtopts)
Parses options like "MULTISET", "MOLMOVIE" or "NOMOLMOVIE".
|
static String |
recognizeOneLineFormat(String s)
Recognize a one-line string as CxSMILES, CxSMARTS, AbbrevGroup,
Peptide or IUPAC name.
|
static void |
registerFormat(MFileFormat mff)
Registers a user defined file format.
|
static String[] |
splitFileAndOptions(String arg)
Parses "file{options}" strings used in molecule file import.
|
static String[] |
splitFormatAndOptions(String opts)
Parses "format:options" strings used in molecule file import and export.
|
static void |
testEncoding(String enc)
Tests whether the given charset name is supported by this JVM
|
public static final int MULTISET
public static final int MOLMOVIE
public static final int NOMOLMOVIE
public static boolean isSubFormatOf(String f, String other)
f
- the format codenameother
- the other formatpublic static String[] splitFileAndOptions(String arg)
arg
- string containing the filename and the options
(if there are)public static String[] splitFormatAndOptions(String opts)
splitFormatAndOptions("xyz:f1.4") returns {"xyz", "f1.4"} splitFormatAndOptions("f1.4") returns {null, "f1.4"} splitFormatAndOptions("xyz:") returns {"xyz", ""} splitFormatAndOptions("gzip:xyz:f1.4") returns {"gzip", "xyz:f1.4"}The semicolon can be omitted in case if Marvin's built-in input formats. Example:
splitFormatAndOptions("xyz") returns { "xyz", ""}
opts
- string containing the format and the optionspublic static int preprocessFormatAndOptions(String[] fmtopts)
String[] fmtopts = splitFormatAndOptions("gzip:xyz:MULTISET,f1.4"); // fmtopts == {"gzip", "xyz:MULTISET,f.14"} int result = preprocessFormatAndOptions(fmtopts); // fmtopts == {"gzip", "xyz:f.14"}, results == MULTISET
fmtopts
- two-element array containing the format and the optionssplitFormatAndOptions(java.lang.String)
,
MULTISET
,
MOLMOVIE
,
NOMOLMOVIE
public static String[] getEncodingFromOptions(String fmtopts)
fmtopts
- the input format and optionsIllegalCharsetNameException
- if the encoding is illegalUnsupportedCharsetException
- if the encoding is unsupportedpublic static void testEncoding(String enc) throws IllegalArgumentException
enc
- the name of the charsetIllegalArgumentException
public static String getUnguessableFormat(String fname)
fname
- the filenamepublic static String getFileExtensionLC(File f)
f
- the filepublic static String getFileExtensionLC(String fname)
fname
- the filenamepublic static String getMostLikelyMolFormat(String fname)
fname
- the filenamepublic static String getKnownExtension(String fname)
fname
- the filenamepublic static String[] getMolfileExtensions()
public static String[] getMolfileFormats()
public static boolean isOutputCleanable(String fmt) throws SecurityException
fmt
- the format stringSecurityException
public static void registerFormat(MFileFormat mff)
MFileFormat.F_USER_DEFINED
flag is automatically set.mff
- the file formatpublic static MFileFormat getFormat(String fmt)
fmt
- the format codenamenull
if not foundpublic static MFileFormat[] findFormats(String fmt, long flags, long mask)
fmt
- the format name or null
if not importantflags
- select formats of which the specified flags are setmask
- only bits specified here are taken into accountpublic static MRecordReader createRecordReader(InputStream is, String opts) throws MolFormatException, IOException
is
- the input streamopts
- input options or null
null
if the format was
not recognizedIllegalCharsetNameException
- if illegal encoding is usedUnsupportedCharsetException
- if unsupported encoding is usedSecurityException
- if the module cannot be loaded because of
a firewall problemMolFormatException
IOException
MFileFormat.createRecordReader(MolInputStream, String)
public static MRecordReader createRecordReader(InputStream is, String opts, String enc, String path) throws MolFormatException, IOException
is
- the input streamopts
- input options or null
enc
- the input encoding or nullpath
- the file path (it can also be an URL) or null
null
if the format was
not recognizedIllegalCharsetNameException
- if illegal encoding is usedUnsupportedCharsetException
- if unsupported encoding is usedSecurityException
- if the module cannot be loaded because of
a firewall problemMolFormatException
IOException
MFileFormat.createRecordReader(MolInputStream, String)
public static MolExportModule createExportModule(String fmt) throws MolExportException
fmt
- the format nameSecurityException
- if the module cannot be loaded because of
a firewall problemMolExportException
MFileFormat.createExportModule()
public static MolExportModule createExportModule(String fmt, String enc) throws MolExportException
fmt
- the format nameenc
- the encodingSecurityException
- if the module cannot be loaded because of
a firewall problemMolExportException
MFileFormat.createExportModule()
public static String[] convertToSmilingFormat(Molecule m) throws MolExportException
MolExportException
- if conversion was not successfulpublic static String[] convertToSmilingFormat(MProp p) throws MolExportException
MolExportException
- if conversion was not successfulpublic static String recognizeOneLineFormat(String s)
s
- the input stringpublic static boolean isURLOrFileName(String s)
s
- the string