File ChemicalFileHandler.h

File-level I/O on chemical file formats.

Copyright

This code is licensed under the 3-clause BSD license.

Copyright ETH Zurich, Laboratory for Physical Chemistry, Reiher Group.

See LICENSE.txt for details.

namespace Scine

This header file contains functions that allow for common notation for common things that can be done at a different degree of derivatives.

This header contains alias definitions defining which classes to use for the different degrees of derivatives.

namespace Utils
class ChemicalFileHandler
#include <ChemicalFileHandler.h>

Handles the reading and writing of chemical file formats.

Matches suffixes to chemical file formats and then dispatches the calls to appropriate streaming I/O handlers. Catches I/O errors.

Public Static Functions

static std::pair<AtomCollection, BondOrderCollection> read(const std::string &filename)

Reads an atom collection and tries to read a bond order collection from a file.

Supported file formats are currently:

  • mol

  • xyz

Parameters
  • filename: The path to the file to read

If obabel is found in your path, all formats that openbabel supports are also available.

Note

The format of a file is deduced from its suffix.

Return

an AtomCollection and a BondOrderCollection read from the file. The BondOrderCollection may be empty if the file format does not include such information

Exceptions
  • FileInaccessibleException: if the file does not exist or cannot be opened

  • FormatUnsupportedException: if the file suffix cannot be matched to a supported file format

  • FormatMismatchException: if the file’s format does not match the parser’s expectations (e.g. if the suffix does not match the format)

  • NoBondInformationException: if the format does not contain bond order information

static void write(const std::string &filename, const AtomCollection &atoms)

Writes an atom collection to a file.

Supported file formats are currently

  • xyz

  • mol

Note

Overwrites existing files

Parameters
  • filename: The path to the file to write

  • atoms: The atom collection to commit to a file

Exceptions
  • FormatUnsupportedException: if the file suffix cannot be matched to a supported file format

  • FileInaccessibleException: if the file cannot be created

static void write(const std::string &filename, const AtomCollection &atoms, const BondOrderCollection &bondOrders)

Writes an atom collection and a bond order collection to a file.

Supported file formats are currently

  • mol

Note

Overwrites existing files

Parameters
  • filename: The path to the file to write

  • atoms: The atom collection to commit to a file

Exceptions
  • FormatUnsupportedException: if the file suffix cannot be matched to a supported file format

  • FileInaccessibleException: if the file cannot be created

struct FileInaccessibleException : public exception
#include <ChemicalFileHandler.h>

Exception thrown if the file does not exist or cannot be opened.

Public Functions

const char *what() const