Skip to content

Commit

Permalink
Set SDF tags as properties of the RDKit molecule. [closes #296]
Browse files Browse the repository at this point in the history
  • Loading branch information
lohedges committed Feb 14, 2025
1 parent 0a8830b commit 704c08f
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions wrapper/Convert/SireRDKit/sire_rdkit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ namespace SireRDKit
RDKit::RWMol molecule;
molecule.beginBatchEdit();

// set the name of the molecule
std::string name;
if (mol.hasProperty("name"))
{
Expand All @@ -608,6 +609,33 @@ namespace SireRDKit
}
molecule.setProp<std::string>("_Name", name);

// set any SDF tags as properties
std::string sdf_tag;
if (mol.hasProperty("sdf_data"))
{
const auto sdf_data = mol.property("sdf_data").asA<SireBase::Properties>();

for (const auto &tag : sdf_data.propertyKeys())
{
try
{
molecule.setProp<std::string>(tag.toStdString(), sdf_data.property(tag).asAString().toStdString());
}
catch (...)
{
const auto string_array = sdf_data.property(tag).asA<SireBase::StringArrayProperty>();

QString string;
for (int i=0; i<string_array.size(); i++)
{
string.append(string_array[i] + "\n");
}

molecule.setProp<std::string>(tag.toStdString(), string.toStdString());
}
}
}

const auto atoms = mol.atoms();

QList<SireMol::Element> elements;
Expand Down

0 comments on commit 704c08f

Please sign in to comment.