Skip to content

Commit

Permalink
#1631 - Revert back previous change, resetting _radicals only if it h…
Browse files Browse the repository at this point in the history
…as no info or it's 0, added integration tests
  • Loading branch information
Simone Zanella committed Feb 18, 2025
1 parent 63791e4 commit ab367e4
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
10 changes: 10 additions & 0 deletions api/tests/integration/ref/basic/fold_unfold.py.out
Original file line number Diff line number Diff line change
Expand Up @@ -1393,3 +1393,13 @@ testing auto mode for [H][H]
testing auto mode for [2H]C
5
2
testing [CH3] |^1:0|
[C]([H])([H])[H] |^1:0|
testing [CH2] |^3:0|
[C]([H])[H] |^3:0|
testing [CH2] |^4:0|
[C]([H])[H] |^4:0|
testing [CH]C1=CC=CO1 |^4:0|
[C]([H])C1OC([H])=C([H])C=1[H] |^4:0|
testing C1C=CC=C([CH])C=1 |^4:5|
C1([H])=C([H])C([C][H])=C([H])C([H])=C1[H] |^4:5|
16 changes: 16 additions & 0 deletions api/tests/integration/tests/basic/fold_unfold.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ def testFoldUnfoldQueryReaction(smiles):
print(mol.countAtoms())


def testFoldUnfoldWithExplicitRadicals(smiles):
print("testing " + smiles)
mol = indigo.loadMolecule(smiles)
mol.unfoldHydrogens()
print(mol.smiles())


testFoldUnfoldSDF(
joinPathPy("../../../../../data/molecules/basic/sugars.sdf", __file__)
)
Expand Down Expand Up @@ -193,3 +200,12 @@ def testFoldUnfoldQueryReaction(smiles):
testAutoFoldUnfoldSingleReaction("[H]CC>>CC")
testAutoFoldUnfoldSingleMol("[H][H]")
testAutoFoldUnfoldSingleMol("[2H]C")

# Monoradical
testFoldUnfoldWithExplicitRadicals("[CH3] |^1:0|")
# Diradical (singlet)
testFoldUnfoldWithExplicitRadicals("[CH2] |^3:0|")
# Diradical (triplet)
testFoldUnfoldWithExplicitRadicals("[CH2] |^4:0|")
testFoldUnfoldWithExplicitRadicals("[CH]C1=CC=CO1 |^4:0|")
testFoldUnfoldWithExplicitRadicals("C1C=CC=C([CH])C=1 |^4:5|")
2 changes: 1 addition & 1 deletion core/indigo-core/molecule/src/base_molecule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4887,7 +4887,7 @@ void BaseMolecule::unfoldHydrogens(Array<int>* markers_out, int max_h_cnt, bool
for (int j = 0; j < h_cnt; j++)
{
int new_h_idx = addAtom(ELEM_H);
int new_bond_idx = addBond_Silent(i, new_h_idx, BOND_SINGLE);
int new_bond_idx = addBond(i, new_h_idx, BOND_SINGLE);

if (only_selected) // if only selected atoms - select new H too
{
Expand Down
2 changes: 1 addition & 1 deletion core/indigo-core/molecule/src/molecule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ void Molecule::_validateVertexConnectivity(int idx, bool validate)
_atoms[idx].explicit_valence = false;
_valence[idx] = -1;
}
if (_radicals.size() > idx)
if (_radicals.size() > idx && _radicals[idx] <= 0)
{
_radicals[idx] = -1;
}
Expand Down

0 comments on commit ab367e4

Please sign in to comment.