File OpenBabelStreamHandler.h

Implements a StreamHandler leveraging OpenBabel for access to more 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 OpenBabelStreamHandler : public Scine::Utils::FormattedStreamHandler
#include <OpenBabelStreamHandler.h>

If obabel is in the PATH, supports IO to range of OpenBabel’s file formats.

Note

Concerning the GPLv2 OpenBabel license, this StreamHandler very much communicates ‘at arms length’ with OpenBabel (https://www.gnu.org/licenses/old-licenses/gpl-2.0-faq.en.html#TOCGPLInProprietarySystem) by merely calling it via system process-level interaction, if present.

Public Functions

OpenBabelStreamHandler()
~OpenBabelStreamHandler()
std::pair<AtomCollection, BondOrderCollection> read(std::istream &is, const std::string &format) const

Reads from an input stream, extracting element types, positions and bond orders (if present)

Return

An Atomcollection and BondOrderCollection

Parameters
  • is: The input stream to read

Exceptions
  • FormatUnsupportedException: If the desired format is unsupported

void write(std::ostream &os, const std::string &format, const AtomCollection &atoms) const

Writes element types and positional information to an arbitrary filetype.

Parameters
  • os: The output stream to write to

  • format: The format to write

  • atoms: The element type and positional information to write to a file

Exceptions
  • FormatUnsupportedException: If the desired format is unsupported

void write(std::ostream &os, const std::string &format, const AtomCollection &atoms, const BondOrderCollection &bondOrders) const

Writes element types and positional information to an arbitrary filetype.

Parameters
  • os: The output stream to write to.

  • format: The format to write

  • atoms: The element type and positional information to write to a file

  • bondOrders: The bond order collection to write to file

Exceptions
  • FormatUnsupportedException: If the desired filetype is unsupported

  • NoBondInformationException: If the specified filetype does not contain bond order information

std::vector<FormatSupportPair> formats() const

Returns a list of supported file formats.

Note

These may, but do not have to be identical to each format’s conventional file suffix

bool formatSupported(const std::string &format, SupportType operation) const

Check whether a particular operation for a format is supported.

Return

true if the operation is supported for that format

Parameters
  • format: The format filetype suffix to check for

  • operation: The operation for which support is queried

std::string name() const

Getter for the name of the FormattedStreamHandler.

Return

Returns the name of the FormattedStreamHandler.

Public Static Functions

static const std::vector<FormatSupportPair> &getSupportedFormats()

List of checked and supported file formats.

Note

This list is po

static bool checkForBinary()

Checks for the presence of ‘obabel’ in the PATH.

Return

Whether ‘obabel’ is found and can be used

static int indirect(std::istream &is, std::ostream &os, const std::string &inFormat, const std::string &outFormat)

Converts between two formats using openbabel with two streams.

Note

For supported formats,

See

openBabelFormats

Warning

This does not check whether obabel is present. Do not use this function without a pre-pended checkForBinary call.

Pre

is populated with data of format inFormat

Post

os is populated with data of format outFormat

Return

The exit code of obabel execution

Parameters
  • is: The input stream for obabel

  • os: The output stream for obabel

  • inFormat: The format string of is

  • outFormat: The format string of os

Public Static Attributes

constexpr const char *model = "OpenBabelStreamHandler"

Private Members

bool _enabled = checkForBinary()