本文整理汇总了C++中MongoDatabase::fetchMolecule方法的典型用法代码示例。如果您正苦于以下问题:C++ MongoDatabase::fetchMolecule方法的具体用法?C++ MongoDatabase::fetchMolecule怎么用?C++ MongoDatabase::fetchMolecule使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MongoDatabase
的用法示例。
在下文中一共展示了MongoDatabase::fetchMolecule方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: exportMolecule
void ExportMoleculeHandler::exportMolecule()
{
if (m_molecule.isValid()) {
// Retrieve the molecule from the database.
MongoDatabase *db = MongoDatabase::instance();
mongo::BSONObj moleculeObj = db->fetchMolecule(m_molecule);
Avogadro::Core::Molecule mol;
// Check for atoms in the molecule.
if (moleculeObj.hasField("atoms")) {
// Generate chemical json string.
std::string cjson = CjsonExporter::toCjson(moleculeObj);
// Create a molecule object for export.
FileFormatManager::instance().readString(mol, cjson, "cjson");
}
else if (moleculeObj.hasField("inchi")) {
// Attempt to load from InChI otherwise.
FileFormatManager::instance().readString(mol,
moleculeObj.getStringField("inchi"),
"inchi");
}
// get molecule name to set default file name
QString moleculeName = moleculeObj.getStringField("name");
if (moleculeName.isEmpty())
moleculeName = "molecule";
// Pop-up dialog and get file name
QString fileName = QFileDialog::getSaveFileName(0,
tr("Save File"),
QDir::currentPath() +
QDir::separator() +
moleculeName + ".cml");
if (fileName.isEmpty())
return;
bool ok = FileFormatManager::instance().writeFile(mol,
fileName.toStdString());
if(!ok) {
// writing failed, display an error dialog
QString errorMessage =
QString("Failed to write molecule to file (%1).").arg(fileName);
QMessageBox::critical(0, "Molecule Export Failed", errorMessage);
}
}
}