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

Bugfix/#2045 Export of unresolved monomer to everything except KET and IDT should cause specific error message (but it doesn't) #2806

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

David-Kuts
Copy link
Collaborator

@David-Kuts David-Kuts commented Mar 11, 2025

Fix code. Add UT.

Generic request

  • PR name follows the pattern #1234 – issue name
  • branch name does not contain '#'
  • base branch (master or release/xx) is correct
  • PR is linked with the issue
  • task status changed to "Code review"
  • code follows product standards
  • regression tests updated

Optional

  • unit-tests written

try
{
int molecule = -1;
molecule = indigoLoadKetDocumentFromFile(dataPath("molecules/basic/unknown_monomers.ket").c_str());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use indigoLoadMoleculeFromFile - indigoCanonicalSmarts doesn't support KetDocument yet.

try
{
int molecule = -1;
molecule = indigoLoadKetDocumentFromFile(dataPath("molecules/basic/unknown_monomers.ket").c_str());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use indigoLoadMoleculeFromFile - indigoSmarts doesn't support KetDocument yet.

}
catch (const std::exception& e)
{
ASSERT_STREQ("core: <KetDocument> can not be converted to SMARTS", e.what());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This message looks wrong.
Looks like no exception thrown.
Could you please rewrite these tests like

catch (const std::exception& e)
{
    ASSERT_STREQ(msg, e.what());
    return;
}
ASSERT(false);

just to be sure that exception thrown

Copy link
Collaborator Author

@David-Kuts David-Kuts Mar 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The exception is thrown in void IndigoSmilesSaver::generateSmarts(IndigoObject& obj, Array<char>& out_buffer) in indigo_severs.cpp.

            ...
            loader_tmp.loadQueryReaction(qreaction);
            saver.saveQueryReaction(qreaction);
        }
    }
    else
        throw IndigoError("%s can not be converted to SMARTS", obj.debugInfo());
    out_buffer.push(0);

In this case, do I still need to write code in the way you suggest?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Beacuse after indigoLoadMoleculeFromFile molecule not a KetDocument - but error message contains this type wich is strange.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've checked. Yes, it is not throwing an exception.

In void IndigoSmilesSaver::generateSmarts(IndigoObject& obj, Array<char>& out_buffer) in

...
{
      Array<char> mol_out_buffer;
      ArrayOutput mol_output(mol_out_buffer);
      MolfileSaver saver_tmp(mol_output);
      saver_tmp.saveMolecule(mol.asMolecule());
      mol_out_buffer.push(0);
      BufferScanner sc(mol_out_buffer);
      MolfileLoader loader_tmp(sc);
      QueryMolecule qmol;
      loader_tmp.loadQueryMolecule(qmol);
      saver.saveQueryMolecule(qmol);
}
...
  1. The first one called is void MolfileSaver::saveMolecule(Molecule& mol) ==> void MolfileSaver::saveMolecule(Molecule& mol) ==> void MolfileSaver::_validate(BaseMolecule& bmol)

  2. The second one called is void SmilesSaver::saveQueryMolecule(QueryMolecule& mol) ==> void SmilesSaver::_saveMolecule() ==> void SmilesSaver::_validate(BaseMolecule& bmol)

At the end of those calls bool BaseMolecule::getUnresolvedTemplatesList(BaseMolecule& bmol, std::string& unresolved) is called

The first and the second ones have different behavior:

  1. unresolved.size() returns 0
  2. does not even enter the if-body:
if (!bmol.isQueryMolecule())
    {
        if (bmol.tgroups.getTGroupCount())
        {
            for (auto tgidx = bmol.tgroups.begin(); tgidx != bmol.tgroups.end(); tgidx = bmol.tgroups.next(tgidx))
            {
                auto& tg = bmol.tgroups.getTGroup(tgidx);
                if (tg.unresolved && tg.tgroup_alias.size())
                {
                    if (unresolved.size())
                        unresolved += ',';
                    unresolved += tg.tgroup_alias.ptr();
                }
            }
        }
    }

Could you tell, please, which behavior is expected and which one is not?

Maybe you have any other suggestions to fix the bug due to my lack of understanding of how the things are working.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove if (!bmol.isQueryMolecule()) - looks like this is something from first versions without query molecules support.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getUnresolvedTemplatesList should return correct list of unresolved templates.
If it return wrong list - thois is a bug.

Copy link
Collaborator

@AliaksandrDziarkach AliaksandrDziarkach Mar 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to getUnresolvedTemplatesList code it could return empty list if uresolved has no alias.
Pleas add hasUnresolvedTemplates wich will return true if at least one unresolved template exists.
And use it instead of getUnresolvedTemplatesList

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants