Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1446 Dearomatization does not work with query features #1455

Merged
merged 13 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions api/tests/integration/ref/arom/query_dearom.py.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
**** Dearomatize query molecules
Aromatic: c1ccccc1
Dearomatized: [#6]1-[#6]=[#6]-[#6]=[#6]-[#6]=1

Aromatic: c1cccc[c;h0]1
Dearomatized: [#6]1-[#6]=[#6]-[#6]=[#6]-[#6;h0]=1

Aromatic: c1cccc[c;X4]1
Dearomatized: [#6]1-[#6]=[#6]-[#6]=[#6]-[#6;X4]=1

Aromatic: [#6]12:[#6]:[#6]:[#6]:[#6]:[#6]:1:[#6]:[#7]:[#7;h1]:2
Dearomatized: [#6]12-[#6]=[#6]-[#6]=[#6]-[#6]-1=[#6]-[#7]-[#7;h1]=2

Aromatic: [#6]12:[#6]:[#6]:[#6]:[#6]:[#6]:1:[#6]:[#7]:[#7;h0]:2
Dearomatized: [#6]12-[#6]=[#6]-[#6]=[#6]-[#6]-1=[#6]-[#7]-[#7;h0]=2

Aromatic: [#6]12:[#6]:[#6]:[#6]:[#6]:[#6]:1:[#6]:[#7;h0]:[#7]:2
Dearomatized: [#6]12-[#6]=[#6]-[#6]=[#6]-[#6]=1-[#6]=[#7;h0]-[#7]-2

Aromatic: [#6]12:[#6]:[#6]:[#6]:[#6]:[#6]:1:[#6]:[#7;h0]:[#7;h0]:2
Cannot be dearomatized: [#6]12:[#6]:[#6]:[#6]:[#6]:[#6]:1:[#6]:[#7;h0]:[#7;h0]:2

50 changes: 50 additions & 0 deletions api/tests/integration/tests/arom/query_dearom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import os
import sys

sys.path.append(
os.path.normpath(
os.path.join(os.path.abspath(__file__), "..", "..", "..", "common")
)
)
from env_indigo import *

print("**** Dearomatize query molecules")

indigo = Indigo()

m = indigo.loadSmarts("c1ccccc1")
print("Aromatic: %s" % m.smarts())
m.dearomatize()
print("Dearomatized: %s\n" % m.smarts())

m = indigo.loadSmarts("c1[ch0]cccc1")
print("Aromatic: %s" % m.smarts())
m.dearomatize()
print("Dearomatized: %s\n" % m.smarts())

m = indigo.loadSmarts("c1[cX4]cccc1")
print("Aromatic: %s" % m.smarts())
m.dearomatize()
print("Dearomatized: %s\n" % m.smarts())

This comment was marked as resolved.


m = indigo.loadSmarts("[#6]12:[#7;h1]:[#7]:[#6]:[#6]:1:[#6]:[#6]:[#6]:[#6]:2")
print("Aromatic: %s" % m.smarts())
m.dearomatize()
print("Dearomatized: %s\n" % m.smarts())

m = indigo.loadSmarts("[#6]12:[#7;h0]:[#7]:[#6]:[#6]:1:[#6]:[#6]:[#6]:[#6]:2")
print("Aromatic: %s" % m.smarts())
m.dearomatize()
print("Dearomatized: %s\n" % m.smarts())

m = indigo.loadSmarts("[#6]12:[#7]:[#7;h0]:[#6]:[#6]:1:[#6]:[#6]:[#6]:[#6]:2")
print("Aromatic: %s" % m.smarts())
m.dearomatize()
print("Dearomatized: %s\n" % m.smarts())

m = indigo.loadSmarts(
"[#6]12:[#7;h0]:[#7;h0]:[#6]:[#6]:1:[#6]:[#6]:[#6]:[#6]:2"
)
print("Aromatic: %s" % m.smarts())
m.dearomatize()
print("Cannot be dearomatized: %s\n" % m.smarts())
5 changes: 2 additions & 3 deletions api/wasm/indigo-ketcher/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,9 +571,8 @@ M END

test("dearomatize", "query_mol", () => {
let options = new indigo.MapStringString();
assert.throws(() => {
indigo.dearomatize(qmol_smarts, "molfile", options);
});
const dearomatized_smiles = indigo.convert(indigo.dearomatize(mol_smiles_aromatized, "molfile", options), "smiles", options);
assert.equal(dearomatized_smiles, "C1C=CC=CC=1");
options.delete();
});
}
Expand Down
17 changes: 10 additions & 7 deletions core/indigo-core/molecule/molecule_dearom.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ namespace indigo
protected:
BaseMolecule& _molecule;
int _aromaticGroups;
bool _isQueryMolecule;

// Additional data stored here to prevent reallocatoins
CP_DECL;
Expand Down Expand Up @@ -208,6 +209,7 @@ namespace indigo
const AromaticityOptions& _options;
int _connectivityGroups;
int _activeGroup;
bool _isQueryMolecule;

DearomatizationsGroups _aromaticGroups;
DearomatizationsStorage* _dearomatizations;
Expand All @@ -222,10 +224,10 @@ namespace indigo
void _initEdges(void);
void _initVertices(void);

void _prepareGroup(int group, Molecule& submolecule);
void _prepareGroup(int group, BaseMolecule& submolecule);

void _fixHeteratom(int atom_idx, bool toFix);
void _processMatching(Molecule& submolecule, int group, const byte* hetroAtomsState);
void _processMatching(BaseMolecule& submolecule, int group, const byte* hetroAtomsState);
void _enumerateMatching(void);
void _handleMatching(void);
};
Expand Down Expand Up @@ -317,21 +319,22 @@ namespace indigo
class MoleculeDearomatizer
{
public:
MoleculeDearomatizer(Molecule& mol, DearomatizationsStorage& dearomatizations);
MoleculeDearomatizer(BaseMolecule& mol, DearomatizationsStorage& dearomatizations);

// Function dearomatizes as much as possible.
// Returns true if all bonds were dearomatized, false overwise
static bool dearomatizeMolecule(Molecule& mol, const AromaticityOptions& options);
static bool dearomatizeMolecule(BaseMolecule& mol, const AromaticityOptions& options);

static bool restoreHydrogens(Molecule& mol, const AromaticityOptions& options);
static bool restoreHydrogens(Molecule& mol, bool unambiguous_only);
static bool restoreHydrogens(BaseMolecule& mol, const AromaticityOptions& options);
static bool restoreHydrogens(BaseMolecule& mol, bool unambiguous_only);

void dearomatizeGroup(int group, int dearomatization_index);
void restoreHydrogens(int group, int dearomatization_index);

private:
DearomatizationsStorage& _dearomatizations;
Molecule& _mol;
BaseMolecule& _mol;
bool _isQueryMolecule;

int _countDoubleBonds(int group, int dearomatization_index);
int _getBestDearomatization(int group);
Expand Down
2 changes: 2 additions & 0 deletions core/indigo-core/molecule/query_molecule.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ namespace indigo
void getBondDescription(int idx, Array<char>& description) override;
bool possibleBondOrder(int idx, int order) override;

bool possibleAromaticBond(int idx);
bool possibleNitrogenV5(int idx);

static std::string getSmartsBondStr(QueryMolecule::Bond* bond);
Expand Down Expand Up @@ -378,6 +379,7 @@ namespace indigo
static Bond* getBondOrderTerm(Bond& qb, bool& complex);
static bool isOrBond(Bond& qb, int type1, int type2);
static bool isSingleOrDouble(Bond& qb);
static bool isSmartsEmptyBond(Bond& qb);
static int getQueryBondType(Bond& qb);
static int getQueryBondType(Bond& qb, int& direction, bool& negative);
static int getAtomType(const char* label);
Expand Down
Loading
Loading