Avogadro  1.1.0
Signals | Public Member Functions | Protected Slots | Protected Member Functions | Protected Attributes
Avogadro::MoleculeFile Class Reference
Inheritance diagram for Avogadro::MoleculeFile:
Inheritance graph
[legend]

List of all members.

Signals

void ready ()
void firstMolReady ()

Public Member Functions

bool isReady () const
bool isConformerFile () const
unsigned int numMolecules () const
QStringList titles () const
Input (reading molecules)
Moleculemolecule (unsigned int i=0)
OpenBabel::OBMolOBMol (unsigned int i=0)
const std::vector< std::vector
< Eigen::Vector3d > * > & 
conformers () const
Output (writing molecules)
bool replaceMolecule (unsigned int i, Molecule *molecule, QString fileName)
bool insertMolecule (unsigned int i, Molecule *molecule, QString fileName)
bool appendMolecule (Molecule *molecule, QString fileName)
Error handling
const QStringerrors () const
void clearErrors ()
Convenience functions
const QStringfileName () const
const QStringfileType () const
const QStringfileOptions () const

Static Public Member Functions

Static methods
static bool canOpen (const QString &fileName, QIODevice::OpenMode mode)
static MoleculereadMolecule (const QString &fileName, const QString &fileType=QString(), const QString &fileOptions=QString(), QString *error=0)
static bool writeMolecule (const Molecule *molecule, const QString &fileName, const QString &fileType=QString(), QString *error=0)
static bool writeMolecule (const Molecule *molecule, const QString &fileName, const QString &fileType, const QString &fileOptions, QString *error=0)
static bool writeConformers (const Molecule *molecule, const QString &fileName, const QString &fileType=QString(), QString *error=0)
static MoleculeFilereadFile (const QString &fileName, const QString &fileType=QString(), const QString &fileOptions=QString(), bool wait=true)

Protected Slots

void threadFinished ()

Protected Member Functions

 MoleculeFile (const QString &fileName, const QString &fileType, const QString &fileOptions)
QStringListtitlesRef ()
std::vector< std::streampos > & streamposRef ()
std::vector< std::vector
< Eigen::Vector3d > * > & 
conformersRef ()
void setConformerFile (bool value)
void setReady (bool value)
void setFirstReady (bool value)

Protected Attributes

MoleculeFilePrivate *const d
QString m_fileName
QString m_fileType
QString m_fileOptions
QString m_error
std::vector< std::vector
< Eigen::Vector3d > * > 
m_conformers

Member Function Documentation

bool Avogadro::MoleculeFile::appendMolecule ( Molecule molecule,
QString  fileName 
)

Append molecule to the end of the file.

Parameters:
moleculeThe molecule to append.
fileNameThe name of the file for saving.
Todo:
implement this method
bool Avogadro::MoleculeFile::canOpen ( const QString fileName,
QIODevice::OpenMode  mode 
) [static]

Static function to check if a file can be opened in the specified mode.

Parameters:
fileNameThe full path to the file to be opened.
modeQIODevice::OpenMode to check.
Returns:
True if the file can be opened in the specified mode.

References QFile::close(), and QFile::open().

Referenced by readFile(), readMolecule(), and writeConformers().

Clear the errors. Errors are always appended to error(), so unless you clear them explicitly, consecutive calls to errors() returns all errors from before plus the new ones (if any).

References QString::clear().

const std::vector< std::vector< Eigen::Vector3d > * > & Avogadro::MoleculeFile::conformers ( ) const

Get all the conformers from the file. This methods returns an empty vector if the opened file isn't a conformer file (see isConformerFile()).

Referenced by writeConformers().

Returns:
Errors from reading/writing to the file.
const QString& Avogadro::MoleculeFile::fileName ( ) const [inline]
Returns:
the filename for this file

Referenced by writeMolecule().

const QString& Avogadro::MoleculeFile::fileOptions ( ) const [inline]
Returns:
any options set for this file
const QString& Avogadro::MoleculeFile::fileType ( ) const [inline]
Returns:
the file type of this file (e.g., extension or Open Babel code)

This signal is emitted when the first molecule is read

bool Avogadro::MoleculeFile::insertMolecule ( unsigned int  i,
Molecule molecule,
QString  fileName 
)

Insert a molecule at index i.

Parameters:
iThe index for inserting the molecule
moleculeThe molecule to insert
fileNameThe name of the file for saving.
Todo:
implement this method
Returns:
True if the file contains multiple frames/conformers of the same molecule.
Returns:
True if the MoleculeFile is ready (i.e. completed reading the file)
Molecule * Avogadro::MoleculeFile::molecule ( unsigned int  i = 0)

Get the {i}th molecule. This function returns a new pointer, you are responsible for deleting it.

Parameters:
iThe index for the molecule to get from the file (indexed from 0).
Returns:
The ith molecule or 0 when i > numMolecule(). In FileIO::Output mode, this method always returns 0.

References OBMol(), and Avogadro::Molecule::setOBMol().

unsigned int Avogadro::MoleculeFile::numMolecules ( ) const

Get the number of molecules in the file.

Get the original OBMol object for the {i}th molecule. This function returns a new pointer, you are responsible for deleting it.

Parameters:
iThe index for the molecule to get from the file (indexed from 0 to numMolecule()-1).
Returns:
The original OBMol object read by OpenBabel.

References OpenBabel::OBConversion::AddOption(), QString::append(), QByteArray::data(), QString::endsWith(), OpenBabel::OBConversion::FormatFromExt(), OpenBabel::OBConversion::INOPTIONS, QString::isEmpty(), OpenBabel::OBMol::NumAtoms(), OpenBabel::OBConversion::Read(), OpenBabel::OBConversion::SetInFormat(), QString::split(), QString::toAscii(), QString::toLocal8Bit(), and QObject::tr().

Referenced by molecule(), and readFile().

MoleculeFile * Avogadro::MoleculeFile::readFile ( const QString fileName,
const QString fileType = QString(),
const QString fileOptions = QString(),
bool  wait = true 
) [static]

Read an entire file, possibly containing multiple molecules in a separate thread and return a MoleculeFile object with the result.

By default, the wait parameter is set to true and the function waits for the thread to finish before returning. If set to false, listening to the MoleculeFile::ready() signal will be emitted when the results are ready.

Parameters:
fileNameThe full path to the file to be saved.
fileTypeOptional file type parameter - override default file extension parsing.
fileOptionsOptions for reading the molecule file, such as bonding.
waitWait for the thread to finish before returning.
Returns:
MoleculeFile with (future) results.

References QFileInfo::baseName(), canOpen(), QObject::connect(), QByteArray::data(), OBMol(), OpenBabel::OBConversion::ReadFile(), OpenBabel::OBConversion::SetInFormat(), QThread::start(), QObject::thread(), QString::toAscii(), QString::toLocal8Bit(), QObject::tr(), and QThread::wait().

Molecule * Avogadro::MoleculeFile::readMolecule ( const QString fileName,
const QString fileType = QString(),
const QString fileOptions = QString(),
QString error = 0 
) [static]

Static function to load a file and return a Molecule pointer. You are responsible for deleting the molecule object.

Parameters:
fileNameThe full path to the file to be opened.
fileTypeOptional file type parameter - override default file extension parsing.
fileOptionsNewline separated list of options for reading the molecule file, such as bonding.
Returns:
The Molecule object loaded, 0 if the file could not be loaded.

References OpenBabel::OBConversion::AddOption(), QString::append(), canOpen(), QByteArray::data(), OpenBabel::OBConversion::FormatFromExt(), OpenBabel::OBConversion::INOPTIONS, QString::isEmpty(), OpenBabel::OBConversion::Read(), Avogadro::Molecule::setFileName(), OpenBabel::OBConversion::SetInFormat(), Avogadro::Molecule::setOBMol(), QString::split(), QString::toAscii(), QString::toLocal8Bit(), and QObject::tr().

void Avogadro::MoleculeFile::ready ( ) [signal]

This signal is emitted when the results are read (i.e. the file is read).

bool Avogadro::MoleculeFile::replaceMolecule ( unsigned int  i,
Molecule molecule,
QString  fileName 
)

Replace the {i}th molecule with molecule. When a molecule returned by molecule() has changed, this function can be used to write it back to the file at the same position.

Parameters:
iThe index for the molecule to replace.
moleculeThe changed (or a totally different) molecule
fileNameThe name of the file for saving.

References QString::append(), OpenBabel::OBConversion::FormatFromExt(), QString::isEmpty(), Avogadro::Molecule::OBMol(), QFile::remove(), QFile::rename(), OpenBabel::OBConversion::SetOutFormat(), QString::toAscii(), QString::toLocal8Bit(), QObject::tr(), and OpenBabel::OBConversion::Write().

Get the titles for the molecules.

bool Avogadro::MoleculeFile::writeConformers ( const Molecule molecule,
const QString fileName,
const QString fileType = QString(),
QString error = 0 
) [static]

Static function to save a all conformers in a molecule to a file. If writing was unsuccessful, a previously existing file will not be overwritten. All formats with support for multiple molecules can be used.

Parameters:
moleculeThe Molecule object to be saved.
fileNameThe full path to the file to be saved.
fileTypeOptional file type parameter - override default file extension parsing.
Returns:
True on success, false on failure.

References QString::append(), OpenBabel::OBMol::BeginAtom(), canOpen(), conformers(), Avogadro::Molecule::conformers(), QString::endsWith(), OpenBabel::OBConversion::FormatFromExt(), QString::isEmpty(), OpenBabel::OBMol::NextAtom(), Avogadro::Molecule::OBMol(), QFile::remove(), QFile::rename(), OpenBabel::OBConversion::SetOutFormat(), QString::toAscii(), QString::toLocal8Bit(), QObject::tr(), and OpenBabel::OBConversion::Write().

static bool Avogadro::MoleculeFile::writeMolecule ( const Molecule molecule,
const QString fileName,
const QString fileType = QString(),
QString error = 0 
) [inline, static]

Static function to save a single molecule to a file. If writing was unsuccessful, a previously existing file will not be overwritten.

Parameters:
moleculeThe Molecule object to be saved.
fileNameThe full path to the file to be saved.
fileTypeOptional file type parameter - override default file extension parsing.
Deprecated:
Use the overload with the options argument instead.
Returns:
True on success, false on failure.
bool Avogadro::MoleculeFile::writeMolecule ( const Molecule molecule,
const QString fileName,
const QString fileType,
const QString fileOptions,
QString error = 0 
) [static]

Static function to save a single molecule to a file. If writing was unsuccessful, a previously existing file will not be overwritten.

Parameters:
moleculeThe Molecule object to be saved.
fileNameThe full path to the file to be saved.
fileTypeOptional file type parameter - override default file extension parsing.
fileOptionsNewline separated list of options for writing the molecule file.
Returns:
True on success, false on failure.

References OpenBabel::OBConversion::AddOption(), QString::append(), QFile::close(), QByteArray::data(), QFile::exists(), fileName(), OpenBabel::OBConversion::FormatFromExt(), QString::isEmpty(), OB_CHAINS_MOL, Avogadro::Molecule::OBMol(), QFile::open(), OpenBabel::OBConversion::OUTOPTIONS, OpenBabel::OBChainsParser::PerceiveChains(), QFile::remove(), QFile::rename(), QFile::setFileName(), OpenBabel::OBConversion::SetOutFormat(), QString::split(), QString::toAscii(), QString::toLocal8Bit(), QObject::tr(), OpenBabel::OBMol::UnsetFlag(), and OpenBabel::OBConversion::Write().


The documentation for this class was generated from the following files: