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

#2195 - Indigo functions doesn't work if query atom and monomer on the canvas at the same time #2710

Merged
merged 1 commit into from
Dec 24, 2024
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
5 changes: 5 additions & 0 deletions api/c/indigo/src/indigo_savers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ void IndigoSmilesSaver::generateSmarts(IndigoObject& obj, Array<char>& out_buffe
{
BaseMolecule& mol = obj.getBaseMolecule();

if (mol.tgroups.getTGroupCount())
{
mol.transformTemplatesToSuperatoms();
}

SmilesSaver saver(output);
saver.smarts_mode = true;
if (mol.isQueryMolecule())
Expand Down
10 changes: 6 additions & 4 deletions api/tests/integration/ref/formats/ket_to_ket.py.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
*** KET to KET ***
images.ket:SUCCEED
ambiguous_monomer.ket doc: SUCCEED
ambiguous_monomer.ket mol: SUCCEED
monomer_shape.ket doc: SUCCEED
monomer_shape.ket mol: SUCCEED
ambiguous_monomer.ket doc loadKetDocument: SUCCEED
ambiguous_monomer.ket mol loadMolecule: SUCCEED
ambiguous_monomer.ket mol loadQueryMolecule: SUCCEED
monomer_shape.ket doc loadKetDocument: SUCCEED
monomer_shape.ket mol loadMolecule: SUCCEED
monomer_shape.ket mol loadQueryMolecule: SUCCEED
7 changes: 6 additions & 1 deletion api/tests/integration/tests/formats/custom_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ def test_smarts_to_ket(smarts_in, expected_str):


def test_ket_to_smarts(filename, expected_str):
mol = indigo.loadQueryMoleculeFromFile(os.path.join(ref_path, filename))
try:
mol = indigo.loadMoleculeFromFile(os.path.join(ref_path, filename))
except IndigoException as e:
mol = indigo.loadQueryMoleculeFromFile(
os.path.join(ref_path, filename)
)
smarts = mol.smarts()
if smarts == expected_str:
print(
Expand Down
15 changes: 8 additions & 7 deletions api/tests/integration/tests/formats/ket_to_ket.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,17 @@ def check_res(filename, format, ket_ref, ket):
"ambiguous_monomer",
]
formats = {
"doc": indigo.loadKetDocument,
"mol": indigo.loadMolecule,
"doc": [indigo.loadKetDocument],
"mol": [indigo.loadMolecule, indigo.loadQueryMolecule],
}
for filename in sorted(files):
for format in sorted(formats.keys()):
file_path = os.path.join(ref_path, filename)
with open("{}_{}.ket".format(file_path, format), "r") as file:
ket_ref = file.read()
mol = formats[format](ket_ref)
# with open("{}_{}.ket".format(file_path, format), "w") as file:
# file.write(mol.json())
ket = mol.json()
check_res(filename, format, ket_ref, ket)
for loader in formats[format]:
mol = loader(ket_ref)
# with open("{}_{}.ket".format(file_path, format), "w") as file:
# file.write(mol.json())
ket = mol.json()
check_res(filename, format + " " + loader.__name__, ket_ref, ket)
55 changes: 49 additions & 6 deletions core/indigo-core/molecule/base_molecule.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,55 @@ namespace indigo
virtual bool isPseudoAtom(int idx) = 0;
virtual const char* getPseudoAtom(int idx) = 0;

struct _AttachOrder
{
int ap_idx;
Array<char> ap_id;
};

struct _TemplateOccurrence
{
int name_idx; // index in _template_names
int class_idx; // index in _template_classes
int seq_id; // sequence id
int template_idx; // template idx
Array<char> seq_name; // sequence name
DisplayOption contracted; // display option (-1 if undefined, 0 - expanded, 1 - contracted)
Array<_AttachOrder> order; // attach order info
_TemplateOccurrence() : name_idx(-1), class_idx(-1), seq_id(-1), template_idx(-1), contracted(DisplayOption::Undefined)
{
}
_TemplateOccurrence(const _TemplateOccurrence& other)
: name_idx(other.name_idx), class_idx(other.class_idx), seq_id(other.seq_id), template_idx(other.template_idx), contracted(other.contracted)
{
seq_name.copy(other.seq_name);
order.copy(other.order);
}
};
ObjPool<_TemplateOccurrence> _template_occurrences;

StringPool _template_classes;
StringPool _template_names;

virtual int addTemplateAtom(const char* text) = 0;
virtual bool isTemplateAtom(int idx) = 0;
virtual const char* getTemplateAtom(int idx) = 0;
virtual const int getTemplateAtomSeqid(int idx) = 0;
virtual const char* getTemplateAtomSeqName(int idx) = 0;
virtual const char* getTemplateAtomClass(int idx) = 0;
virtual const int getTemplateAtomDisplayOption(int idx) = 0;
virtual const int getTemplateAtomTemplateIndex(int idx) = 0;
virtual int getTemplateAtomOccurrence(int idx) = 0;

const char* getTemplateAtom(int idx);
const int getTemplateAtomSeqid(int idx);
const char* getTemplateAtomSeqName(int idx);
const char* getTemplateAtomClass(int idx);
const int getTemplateAtomDisplayOption(int idx);
const int getTemplateAtomTemplateIndex(int idx);

void renameTemplateAtom(int idx, const char* text);
void setTemplateAtomName(int idx, const char* text);
void setTemplateAtomClass(int idx, const char* text);
void setTemplateAtomSeqid(int idx, int seq_id);
void setTemplateAtomSeqName(int idx, const char* seq_name);

void setTemplateAtomDisplayOption(int idx, int contracted);
void setTemplateAtomTemplateIndex(int idx, int temp_idx);

bool getUnresolvedTemplatesList(BaseMolecule& bmol, std::string& unresolved);

Expand Down Expand Up @@ -313,6 +355,7 @@ namespace indigo
virtual int addAtom(int label) = 0;

virtual int addBond(int beg, int end, int order) = 0;
virtual int addBond_Silent(int beg, int end, int order) = 0;

void unfoldHydrogens(Array<int>* markers_out, int max_h_cnt = -1, bool impl_h_no_throw = false, bool only_selected = false);

Expand Down
42 changes: 4 additions & 38 deletions core/indigo-core/molecule/molecule.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,13 @@ namespace indigo

void setPseudoAtom(int idx, const char* text);

void renameTemplateAtom(int idx, const char* text);
bool isTemplateAtom(int idx) override;
int getTemplateAtomOccurrence(int idx) override;
virtual int addTemplateAtom(const char* text) override;
void setTemplateAtom(int idx, const char* text);
void setTemplateAtomName(int idx, const char* text);
void setTemplateAtomClass(int idx, const char* text);
void setTemplateAtomSeqid(int idx, int seq_id);
void setTemplateAtomSeqName(int idx, const char* seq_name);

void setTemplateAtomDisplayOption(int idx, int contracted);
void setTemplateAtomTemplateIndex(int idx, int temp_idx);

int addBond(int beg, int end, int order) override;
int addBond_Silent(int beg, int end, int order);
int addBond_Silent(int beg, int end, int order) override;

void setAtomCharge(int idx, int charge);
void setAtomCharge_Silent(int idx, int charge);
Expand Down Expand Up @@ -98,14 +93,6 @@ namespace indigo
bool isPseudoAtom(int idx) override;
const char* getPseudoAtom(int idx) override;

bool isTemplateAtom(int idx) override;
const char* getTemplateAtom(int idx) override;
const int getTemplateAtomSeqid(int idx) override;
const char* getTemplateAtomSeqName(int idx) override;
const char* getTemplateAtomClass(int idx) override;
const int getTemplateAtomTemplateIndex(int idx) override;
const int getTemplateAtomDisplayOption(int idx) override;

bool isRSite(int atom_idx) override;
dword getRSiteBits(int atom_idx) override;
void allowRGroupOnRSite(int atom_idx, int rg_idx) override;
Expand Down Expand Up @@ -202,27 +189,6 @@ namespace indigo

StringPool _pseudo_atom_values;

struct _AttachOrder
{
int ap_idx;
Array<char> ap_id;
};

struct _TemplateOccurrence
{
int name_idx; // index in _template_names
int class_idx; // index in _template_classes
int seq_id; // sequence id
int template_idx; // template idx
Array<char> seq_name; // sequence name
DisplayOption contracted; // display option (-1 if undefined, 0 - expanded, 1 - contracted)
Array<_AttachOrder> order; // attach order info
};
ObjPool<_TemplateOccurrence> _template_occurrences;

StringPool _template_classes;
StringPool _template_names;

bool _aromatized;

bool _ignore_bad_valence;
Expand Down
10 changes: 3 additions & 7 deletions core/indigo-core/molecule/molecule_layered_molecules.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,9 @@ namespace indigo
bool isPseudoAtom(int idx) override;
const char* getPseudoAtom(int idx) override;

int addTemplateAtom(const char* text) override;
bool isTemplateAtom(int idx) override;
const char* getTemplateAtom(int idx) override;
const int getTemplateAtomSeqid(int idx) override;
const char* getTemplateAtomSeqName(int idx) override;
const int getTemplateAtomTemplateIndex(int idx) override;

const char* getTemplateAtomClass(int idx) override;
const int getTemplateAtomDisplayOption(int idx) override;
int getTemplateAtomOccurrence(int idx) override;

bool isRSite(int atom_idx) override;
dword getRSiteBits(int atom_idx) override;
Expand Down Expand Up @@ -132,6 +127,7 @@ namespace indigo

int addAtom(int label) override;
int addBond(int beg, int end, int order) override;
int addBond_Silent(int beg, int end, int order) override;

int getImplicitH(int idx, bool impl_h_no_throw) override;
void setImplicitH(int idx, int impl_h) override;
Expand Down
10 changes: 4 additions & 6 deletions core/indigo-core/molecule/query_molecule.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ namespace indigo

int value_min;
int value_max;
int occurrence_idx;

// available only when type is ATOM_PSEUDO or ATOM_TEMPLATE or ATOM_TEMPLATE_CLASS
Array<char> alias;
Expand Down Expand Up @@ -319,13 +320,9 @@ namespace indigo
bool isPseudoAtom(int idx) override;
const char* getPseudoAtom(int idx) override;

int addTemplateAtom(const char* text) override;
bool isTemplateAtom(int idx) override;
const char* getTemplateAtom(int idx) override;
const int getTemplateAtomSeqid(int idx) override;
const char* getTemplateAtomSeqName(int idx) override;
const char* getTemplateAtomClass(int idx) override;
const int getTemplateAtomDisplayOption(int idx) override;
const int getTemplateAtomTemplateIndex(int idx) override;
int getTemplateAtomOccurrence(int idx) override;

bool isRSite(int atom_idx) override;
dword getRSiteBits(int atom_idx) override;
Expand Down Expand Up @@ -411,6 +408,7 @@ namespace indigo

int addAtom(int label) override;
int addBond(int beg, int end, int order) override;
int addBond_Silent(int beg, int end, int order) override;

int getImplicitH(int idx, bool impl_h_no_throw) override;
void setImplicitH(int idx, int impl_h) override;
Expand Down
Loading
Loading