mirror of
https://github.com/rdkit/rdkit.git
synced 2026-06-03 21:44:30 +08:00
15
External/AvalonTools/AvalonTools.cpp
vendored
15
External/AvalonTools/AvalonTools.cpp
vendored
@@ -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);
|
||||
}
|
||||
|
||||
25
External/AvalonTools/test1.cpp
vendored
25
External/AvalonTools/test1.cpp
vendored
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user