Avogadro
1.1.0
|
Signals | |
void | ready () |
void | firstMolReady () |
Public Member Functions | |
bool | isReady () const |
bool | isConformerFile () const |
unsigned int | numMolecules () const |
QStringList | titles () const |
Input (reading molecules) | |
Molecule * | molecule (unsigned int i=0) |
OpenBabel::OBMol * | OBMol (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 QString & | errors () const |
void | clearErrors () |
Convenience functions | |
const QString & | fileName () const |
const QString & | fileType () const |
const QString & | fileOptions () const |
Static Public Member Functions | |
Static methods | |
static bool | canOpen (const QString &fileName, QIODevice::OpenMode mode) |
static Molecule * | readMolecule (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 MoleculeFile * | readFile (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) | |
QStringList & | titlesRef () |
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 |
bool Avogadro::MoleculeFile::appendMolecule | ( | Molecule * | molecule, |
QString | fileName | ||
) |
Append molecule
to the end of the file.
molecule | The molecule to append. |
fileName | The name of the file for saving. |
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
.
fileName | The full path to the file to be opened. |
mode | QIODevice::OpenMode to check. |
mode
. References QFile::close(), and QFile::open().
Referenced by readFile(), readMolecule(), and writeConformers().
void Avogadro::MoleculeFile::clearErrors | ( | ) |
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().
const QString & Avogadro::MoleculeFile::errors | ( | ) | const |
const QString& Avogadro::MoleculeFile::fileName | ( | ) | const [inline] |
Referenced by writeMolecule().
const QString& Avogadro::MoleculeFile::fileOptions | ( | ) | const [inline] |
const QString& Avogadro::MoleculeFile::fileType | ( | ) | const [inline] |
void Avogadro::MoleculeFile::firstMolReady | ( | ) | [signal] |
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
.
i | The index for inserting the molecule |
molecule | The molecule to insert |
fileName | The name of the file for saving. |
bool Avogadro::MoleculeFile::isConformerFile | ( | ) | const |
bool Avogadro::MoleculeFile::isReady | ( | ) | const |
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.
i | The index for the molecule to get from the file (indexed from 0). |
References OBMol(), and Avogadro::Molecule::setOBMol().
unsigned int Avogadro::MoleculeFile::numMolecules | ( | ) | const |
Get the number of molecules in the file.
OpenBabel::OBMol * Avogadro::MoleculeFile::OBMol | ( | unsigned int | i = 0 | ) |
Get the original OBMol object for the {i}th
molecule. This function returns a new pointer, you are responsible for deleting it.
i | The index for the molecule to get from the file (indexed from 0 to numMolecule()-1). |
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.
fileName | The full path to the file to be saved. |
fileType | Optional file type parameter - override default file extension parsing. |
fileOptions | Options for reading the molecule file, such as bonding. |
wait | Wait for the thread to finish before returning. |
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.
fileName | The full path to the file to be opened. |
fileType | Optional file type parameter - override default file extension parsing. |
fileOptions | Newline separated list of options for reading the molecule file, such as bonding. |
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.
i | The index for the molecule to replace. |
molecule | The changed (or a totally different) molecule |
fileName | The 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().
QStringList Avogadro::MoleculeFile::titles | ( | ) | const |
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.
molecule | The Molecule object to be saved. |
fileName | The full path to the file to be saved. |
fileType | Optional file type parameter - override default file extension parsing. |
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.
molecule | The Molecule object to be saved. |
fileName | The full path to the file to be saved. |
fileType | Optional file type parameter - override default file extension parsing. |
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.
molecule | The Molecule object to be saved. |
fileName | The full path to the file to be saved. |
fileType | Optional file type parameter - override default file extension parsing. |
fileOptions | Newline separated list of options for writing the molecule file. |
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().