Skip to content

Commit

Permalink
Merge pull request #1942 from ghutchis/qupkake-sdf-labels
Browse files Browse the repository at this point in the history
Handle SDF data blocks better, including from QupKake
  • Loading branch information
ghutchis authored Jan 15, 2025
2 parents 99029fa + 17a6a14 commit 7f9183e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
33 changes: 29 additions & 4 deletions avogadro/io/mdlformat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ bool MdlFormat::read(std::istream& in, Core::Molecule& mol)
string dataValue;
while (getline(in, buffer)) {
if (trimmed(buffer) == "$$$$")
return true;
break;
if (inValue) {
if (buffer.empty() && dataName.length() > 0) {
// check for partial charges
Expand All @@ -293,14 +293,39 @@ bool MdlFormat::read(std::istream& in, Core::Molecule& mol)
dataValue += "\n";
dataValue += buffer;
}
} else if (startsWith(buffer, "> <")) {
} else if (startsWith(buffer, "> ")) {
// This is a data header, read the name of the entry, and the value on
// the following lines.
dataName = trimmed(buffer).substr(3, buffer.length() - 4);
inValue = true;
// e.g., > <propName>
// dataName will be anything from < to >
size_t start = buffer.find('<');
size_t end = buffer.find('>', start);
if (start != string::npos && end != string::npos) {
dataName = buffer.substr(start + 1, end - start - 1);
inValue = true;
}
}
}

// handle pKa from QupKake model
if (mol.hasData("pka") && mol.hasData("idx")) {
// pka can sometimes say "tensor(3.1452)" or "3.1452"
// just convert to a string with 2 decimal places
std::string pka = mol.data("pka").toString();
if (startsWith(pka, "tensor("))
pka = pka.substr(7, pka.size() - 8);
// find the decimal to only keep 2 decimal places
size_t decimal = pka.find(".");
if (decimal != std::string::npos)
pka = pka.substr(0, decimal + 3);
mol.setData("pka", pka);
// convert the idx to an atom index
// and set the label
std::string idx = mol.data("idx").toString();
size_t atomIdx = lexicalCast<size_t>(idx);
mol.setAtomLabel(atomIdx, pka);
}

return true;
}

Expand Down
4 changes: 2 additions & 2 deletions avogadro/qtplugins/label/label.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,14 +379,14 @@ void Label::processAtom(const Core::Molecule& molecule,
}

auto* interface = m_layerManager.getSetting<LayerLabel>(layer);
std::string text = "";
std::string text = atom.label();

if (interface->atomOptions & LayerLabel::LabelOptions::PartialCharge) {
QString charge = partialCharge(const_cast<Molecule*>(&molecule), i);
text += charge.toStdString();
}
if (interface->atomOptions & LayerLabel::LabelOptions::Custom) {
text += (text == "" ? "" : " / ") + atom.label();
// already set
}
if (interface->atomOptions & LayerLabel::LabelOptions::Index) {
text += (text == "" ? "" : " / ") + std::to_string(atom.index() + 1);
Expand Down

0 comments on commit 7f9183e

Please sign in to comment.