This commit is contained in:
Greg Landrum
2021-04-23 22:43:18 +02:00
committed by GitHub
parent 158fe71ff2
commit a1d94d5f22
2 changed files with 37 additions and 3 deletions

View File

@@ -224,19 +224,28 @@ unsigned int set2DCoords(ROMol &mol, bool clearConfs) {
auto smiles = MolToSmiles(mol);
struct reaccs_molecule_t *mp = stringToReaccs(smiles, true);
struct reaccs_molecule_t *mp2 = reaccsGetCoords(mp);
TEST_ASSERT(mp2->n_atoms == mol.getNumAtoms());
TEST_ASSERT(mp2->n_atoms >= mol.getNumAtoms());
auto *conf = new RDKit::Conformer(mol.getNumAtoms());
conf->set3D(false);
// the toolkit may add chiral Hs... we need to be able to ignore them:
std::vector<int> nonHydrogenIndices;
for (unsigned int i = 0; i < mp2->n_atoms; i++) {
if (strcmp(mp2->atom_array[i].atom_symbol, "H")) {
nonHydrogenIndices.push_back(i);
}
}
TEST_ASSERT(nonHydrogenIndices.size() == mol.getNumAtoms());
// Atoms in the intermediate smiles representation may be ordered
// differently compared to the original input molecule.
// Make sure that output coordinates are assigned in the correct order.
std::vector<unsigned int> atomOrdering;
mol.getProp(common_properties::_smilesAtomOutputOrder, atomOrdering);
for (unsigned int i = 0; i < mol.getNumAtoms(); ++i) {
auto x = mp2->atom_array[atomOrdering[i]].x;
auto y = mp2->atom_array[atomOrdering[i]].y;
auto x = mp2->atom_array[nonHydrogenIndices[atomOrdering[i]]].x;
auto y = mp2->atom_array[nonHydrogenIndices[atomOrdering[i]]].y;
RDGeom::Point3D loc(x, y, 0.);
conf->setAtomPos(i, loc);
}

View File

@@ -452,6 +452,30 @@ void testInitStruChk() {
BOOST_LOG(rdInfoLog) << "done" << std::endl;
}
void testGithub4075() {
BOOST_LOG(rdInfoLog) << "testing Github #4075: AvalonTools.Generate2DCoords "
"results in an assert violation"
<< std::endl;
{
auto mol = "Cl[C@H](C)CCC(F)Cl"_smiles;
TEST_ASSERT(mol);
AvalonTools::set2DCoords(*mol);
TEST_ASSERT(mol->getNumConformers() == 1);
std::unique_ptr<ROMol> newMol(MolBlockToMol(MolToMolBlock(*mol)));
TEST_ASSERT(newMol);
TEST_ASSERT(MolToSmiles(*newMol) == MolToSmiles(*mol));
}
{
auto mol = "Cl[C@H](C)C([C@H](O)I)C[C@H](F)Cl"_smiles;
TEST_ASSERT(mol);
AvalonTools::set2DCoords(*mol);
TEST_ASSERT(mol->getNumConformers() == 1);
std::unique_ptr<ROMol> newMol(MolBlockToMol(MolToMolBlock(*mol)));
TEST_ASSERT(newMol);
TEST_ASSERT(MolToSmiles(*newMol) == MolToSmiles(*mol));
}
BOOST_LOG(rdInfoLog) << "done" << std::endl;
}
int main() {
RDLog::InitLogs();
#if 1
@@ -469,6 +493,7 @@ int main() {
testCountFps();
#endif
testInitStruChk();
testGithub4075();
return 0;
}