Skip to content

Commit

Permalink
Merge pull request #432 from psavery/mongochem-use-geometries
Browse files Browse the repository at this point in the history
Utilize new geometry endpoints for MongoChem
  • Loading branch information
cryos authored Jan 14, 2020
2 parents 22f1091 + b55a677 commit 41fe64e
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 1 deletion.
36 changes: 36 additions & 0 deletions avogadro/qtplugins/mongochem/calculationsubmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,40 @@ void CalculationSubmitter::finishUploadMolecule(const QVariant& results)
return;
}

// Now, upload the particular geometry that we will use
uploadGeometry();
}

void CalculationSubmitter::uploadGeometry()
{
QByteArray postData = m_moleculeCjson.toLatin1();

QString url =(m_girderUrl + "/molecules/%1/geometries").arg(m_moleculeId);

QList<QPair<QString, QString>> urlQueries = {
{ "provenanceType", "Uploaded from Avogadro2" }
};

auto* request =
new GirderRequest(m_networkManager.data(), url, m_girderToken);
request->setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
request->setUrlQueries(urlQueries);
request->post(postData);

connect(request, &GirderRequest::result, this,
&CalculationSubmitter::finishUploadGeometry);
connect(request, &GirderRequest::error, this, &CalculationSubmitter::error);
deleteRequestWhenFinished(request);
}

void CalculationSubmitter::finishUploadGeometry(const QVariant& results)
{
m_geometryId = results.toMap()["_id"].toString();
if (m_geometryId.isEmpty()) {
emit error("Failed to upload geometry!");
return;
}

// Now, make sure the calculation has not already been done before.
fetchCalculation();
}
Expand All @@ -105,6 +139,7 @@ void CalculationSubmitter::fetchCalculation()

QList<QPair<QString, QString>> urlQueries = {
{ "moleculeId", m_moleculeId },
{ "geometryId", m_geometryId },
{ "inputParameters", inputParams },
{ "imageName", QString("%1:%2").arg(repository).arg(tag) }
};
Expand Down Expand Up @@ -272,6 +307,7 @@ void CalculationSubmitter::createPendingCalculation()

QJsonObject json;
json["moleculeId"] = m_moleculeId;
json["geometryId"] = m_geometryId;
json["public"] = true;
json["cjson"] = QJsonValue();

Expand Down
4 changes: 4 additions & 0 deletions avogadro/qtplugins/mongochem/calculationsubmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ private slots:
void uploadMolecule();
void finishUploadMolecule(const QVariant& results);

void uploadGeometry();
void finishUploadGeometry(const QVariant& results);

void fetchCalculation();
void finishFetchCalculation(const QVariant& results);

Expand Down Expand Up @@ -94,6 +97,7 @@ private slots:

// These will be set during the process
QString m_moleculeId;
QString m_geometryId;
QString m_pendingCalculationId;
QString m_clusterId;
QString m_queueId;
Expand Down
46 changes: 45 additions & 1 deletion avogadro/qtplugins/mongochem/mongochemwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,51 @@ void MongoChemWidget::uploadMolecule()

void MongoChemWidget::finishUploadMolecule(const QVariant& results)
{
Q_UNUSED(results)
auto moleculeId = results.toMap()["_id"].toString();
if (moleculeId.isEmpty()) {
QString message = "Failed to upload molecule";
qDebug() << message;
QMessageBox::critical(this, "MongoChem", message);
return;
}

// Now, upload the particular geometry
uploadGeometry(moleculeId);
}

void MongoChemWidget::uploadGeometry(const QString& moleculeId)
{
QByteArray postData = m_plugin->currentMoleculeCjson().toLatin1();

QString url =(m_girderUrl + "/molecules/%1/geometries").arg(moleculeId);

QList<QPair<QString, QString>> urlQueries = {
{ "provenanceType", "Uploaded by Avogadro2 User" }
};

auto* request =
new GirderRequest(m_networkManager.data(), url, m_girderToken);
request->setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
request->setUrlQueries(urlQueries);
request->post(postData);

connect(request, &GirderRequest::result, this,
&MongoChemWidget::finishUploadGeometry);
connect(request, &GirderRequest::error, this, &MongoChemWidget::error);
connect(request, &GirderRequest::result, request,
&GirderRequest::deleteLater);
connect(request, &GirderRequest::error, request, &GirderRequest::deleteLater);
}

void MongoChemWidget::finishUploadGeometry(const QVariant& results)
{
auto geometryId = results.toMap()["_id"].toString();
if (geometryId.isEmpty()) {
QString message = "Failed to upload geometry";
qDebug() << message;
QMessageBox::critical(this, "MongoChem", message);
return;
}

QString message = "Upload successful!";
qDebug() << message;
Expand Down
2 changes: 2 additions & 0 deletions avogadro/qtplugins/mongochem/mongochemwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ private slots:
void finishDownloadMolecule(const QVariant& results);
void uploadMolecule();
void finishUploadMolecule(const QVariant& results);
void uploadGeometry(const QString& moleculeId);
void finishUploadGeometry(const QVariant& results);
void submitCalculation();
void finishSubmitCalculation(const QVariantMap& results);
void finishWatchCalculation(const QByteArray& cjson);
Expand Down

0 comments on commit 41fe64e

Please sign in to comment.