Skip to content

Commit

Permalink
Add support for parsing PubChem MMFF94 partial charges
Browse files Browse the repository at this point in the history
Signed-off-by: Geoff Hutchison <[email protected]>
  • Loading branch information
ghutchis committed Oct 31, 2024
1 parent 78e206c commit 15efe67
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions avogadro/io/fileformatmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ FileFormatManager::FileFormatManager()
addFormat(new OutcarFormat);
addFormat(new PdbFormat);
addFormat(new PoscarFormat);
addFormat(new SdfFormat);
addFormat(new TrrFormat);
addFormat(new TurbomoleFormat);
addFormat(new XyzFormat);
Expand Down
25 changes: 24 additions & 1 deletion avogadro/io/mdlformat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,25 @@ MdlFormat::MdlFormat() {}

MdlFormat::~MdlFormat() {}

void handlePartialCharges(Core::Molecule& mol, std::string data)
{
// the string starts with the number of charges
// then atom index charge
MatrixX charges(mol.atomCount(), 1);
std::istringstream iss(data);
size_t numCharges;
iss >> numCharges;
for (size_t i = 0; i < numCharges; ++i) {
size_t index;
Real charge;
iss >> index >> charge;
// prints with atom index 1, not zero
charges(index - 1, 0) = charge;
}

mol.setPartialCharges("MMFF94", charges);
}

bool MdlFormat::read(std::istream& in, Core::Molecule& mol)
{
string buffer;
Expand Down Expand Up @@ -208,7 +227,11 @@ bool MdlFormat::read(std::istream& in, Core::Molecule& mol)
return true;
if (inValue) {
if (buffer.empty() && dataName.length() > 0) {
mol.setData(dataName, dataValue);
// check for partial charges
if (dataName == "PUBCHEM_MMFF94_PARTIAL_CHARGES")
handlePartialCharges(mol, dataValue);
else
mol.setData(dataName, dataValue);
dataName.clear();
dataValue.clear();
inValue = false;
Expand Down
3 changes: 0 additions & 3 deletions avogadro/io/sdfformat.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ class AVOGADROIO_EXPORT SdfFormat : public MdlFormat

bool read(std::istream& in, Core::Molecule& molecule) override;
bool write(std::ostream& out, const Core::Molecule& molecule) override;

protected:
bool m_writeProperties = true;
};

} // namespace Io
Expand Down

0 comments on commit 15efe67

Please sign in to comment.