Function chemfiles::guess_format
source · pub fn guess_format<P>(path: P) -> Result<String, Error>
Expand description
Get the format that chemfiles would use to read a file at the given
path
.
The format is mostly guessed from the path extension, chemfiles only tries
to read the file to distinguish between CIF and mmCIF files. Opening the
file using the returned format string might still fail. For example, it will
fail if the file is not actually formatted according to the guessed format;
or the format/compression combination is not supported (e.g. XTC / GZ
will
not work since the XTC reader does not support compressed files).
The returned format is represented in a way compatible with the various
Trajectory
constructors, i.e. "<format name> [/ <compression>]"
, where
compression is optional.
Errors
This function returns an error if the file format couldn’t be guessed.
Panics
This function panics if the path can’t be converted to a Unicode string.
Examples
let format = chemfiles::guess_format("trajectory.xyz.xz").unwrap();
assert_eq!(format, "XYZ / XZ");
let format = chemfiles::guess_format("trajectory.nc").unwrap();
assert_eq!(format, "Amber NetCDF");
let format = chemfiles::guess_format("trajectory.unknown.format");
assert!(format.is_err());