Skip to content

Commit

Permalink
Upload a new geometry to use for every calculation
Browse files Browse the repository at this point in the history
This prevents us from re-using the molecule in the database
when we do a calculation.

Instead, the molecule drawn in the Avogadro2 window is always
used for the calculations.

Signed-off-by: Patrick Avery <[email protected]>
  • Loading branch information
psavery committed Nov 7, 2019
1 parent 8dc172e commit 250453e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
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

0 comments on commit 250453e

Please sign in to comment.