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

#2237 - Save multi reactions (pathway, single, edge cases) to RDF #2379

Merged
merged 36 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
3394b44
pre fixes
even1024 Sep 9, 2024
454f464
conversions
even1024 Sep 11, 2024
fe3a10e
all fixed
even1024 Sep 15, 2024
91915e4
all fixed
even1024 Sep 15, 2024
85a06f2
all fixed
even1024 Sep 15, 2024
165b6c6
all fixed
even1024 Sep 15, 2024
bac5824
all fixed
even1024 Sep 15, 2024
e94a2d8
clang format
even1024 Sep 16, 2024
ddc6c31
clang format
even1024 Sep 16, 2024
7410b5d
clang format
even1024 Sep 16, 2024
d0f4173
wasm fix
even1024 Sep 16, 2024
d26ed91
386 fix
even1024 Sep 16, 2024
3ee19e7
all fixed
even1024 Sep 16, 2024
6912cc1
Merge branch 'master' of github.com:epam/Indigo into 2237-detect-pathway
even1024 Sep 16, 2024
0119e8f
all fixed
even1024 Sep 16, 2024
2754e54
all fixed
even1024 Sep 18, 2024
6c9a9dc
conflicts resolve
even1024 Sep 18, 2024
e403c3e
conflicts resolve
even1024 Sep 18, 2024
dbf49de
clang format
even1024 Sep 18, 2024
067ec18
all fixed
even1024 Sep 19, 2024
f107079
all fixed
even1024 Sep 19, 2024
f80c864
Merge branch 'master' into 2237-detect-pathway
even1024 Sep 19, 2024
39200a8
all fixed
even1024 Sep 19, 2024
1b87d85
all fixed
even1024 Sep 19, 2024
5d08d3c
all fixed
even1024 Sep 19, 2024
ce7371b
all fixed
even1024 Sep 19, 2024
b56fbad
all fixed
even1024 Sep 19, 2024
e98b36a
all fixed
even1024 Sep 19, 2024
f9e7b94
all fixed
even1024 Sep 19, 2024
879e382
all fixed
even1024 Sep 19, 2024
1099a1e
all fixed
even1024 Sep 19, 2024
bec7863
all fixed
even1024 Sep 20, 2024
b891730
all fixed
even1024 Sep 20, 2024
df86cde
all fixed
even1024 Sep 20, 2024
a966745
pathway fix
even1024 Sep 24, 2024
8402777
pathway fix
even1024 Sep 24, 2024
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
3 changes: 3 additions & 0 deletions api/c/indigo-renderer/src/indigo_render2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "base_cpp/scanner.h"
#include "molecule/molecule.h"
#include "molecule/query_molecule.h"
#include "reaction/pathway_reaction.h"
#include "reaction/query_reaction.h"
#include "reaction/reaction.h"
#include "render_cdxml.h"
Expand Down Expand Up @@ -461,6 +462,8 @@ CEXPORT int indigoRender(int object, int output)
{
if (obj.getBaseReaction().isQueryReaction())
rp.rxn.reset(new QueryReaction());
else if (obj.getBaseReaction().isPathwayReaction())
rp.rxn.reset(new PathwayReaction());
else
rp.rxn.reset(new Reaction());
rp.rxn->clone(self.getObject(object).getBaseReaction(), 0, 0, 0);
Expand Down
1 change: 1 addition & 0 deletions api/c/indigo/indigo.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ CEXPORT int indigoIterateProducts(int reaction);
CEXPORT int indigoIterateCatalysts(int reaction);
// Returns an iterator for reactants, products, and catalysts.
CEXPORT int indigoIterateMolecules(int reaction);
CEXPORT int indigoIterateReactions(int reaction);

CEXPORT int indigoSaveRxnfile(int reaction, int output);
CEXPORT int indigoSaveRxnfileToFile(int reaction, const char* filename);
Expand Down
2 changes: 2 additions & 0 deletions api/c/indigo/src/indigo_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ namespace indigo
class BaseReaction;
class QueryReaction;
class Reaction;
class PathwayReaction;
class Output;
class Scanner;
class SdfLoader;
Expand Down Expand Up @@ -190,6 +191,7 @@ class DLLEXPORT IndigoObject
virtual BaseReaction& getBaseReaction();
virtual QueryReaction& getQueryReaction();
virtual Reaction& getReaction();
virtual PathwayReaction& getPathwayReaction();

virtual IndigoObject* clone();

Expand Down
14 changes: 9 additions & 5 deletions api/c/indigo/src/indigo_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
***************************************************************************/
#include <algorithm>
#include <vector>

#include "base_cpp/cancellation_handler.h"
#include "indigo_internal.h"
#include "indigo_molecule.h"
#include "indigo_reaction.h"
#include "layout/molecule_cleaner_2d.h"
#include "layout/molecule_layout.h"
#include "layout/pathway_layout.h"
#include "layout/reaction_layout.h"
#include "reaction/base_reaction.h"
#include <algorithm>
#include <vector>

CEXPORT int indigoLayout(int object)
{
Expand Down Expand Up @@ -101,9 +102,12 @@ CEXPORT int indigoLayout(int object)
else if (IndigoBaseReaction::is(obj))
{
BaseReaction& rxn = obj.getBaseReaction();
bool no_layout = rxn.intermediateCount() || rxn.specialConditionsCount() || rxn.meta().getNonChemicalMetaCount() ||
obj.type == IndigoObject::PATHWAY_REACTION || rxn.multitaleCount();
if (!no_layout)
if (rxn.isPathwayReaction())
{
PathwayLayout pl(static_cast<PathwayReaction&>(rxn));
pl.make();
}
else
{
ReactionLayout rl(rxn, self.smart_layout, self.layout_options);
rl.setMaxIterations(self.layout_max_iterations);
Expand Down
6 changes: 6 additions & 0 deletions api/c/indigo/src/indigo_object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "base_cpp/output.h"
#include "base_cpp/properties_map.h"
#include "reaction/pathway_reaction.h"
#include "reaction/reaction.h"

#include "indigo_internal.h"
Expand Down Expand Up @@ -225,6 +226,11 @@ Reaction& IndigoObject::getReaction()
throw IndigoError("%s is not a reaction", debugInfo());
}

PathwayReaction& IndigoObject::getPathwayReaction()
{
throw IndigoError("%s is not a pathway reaction", debugInfo());
}

BaseReaction& IndigoObject::getBaseReaction()
{
throw IndigoError("%s is not a base reaction", debugInfo());
Expand Down
130 changes: 111 additions & 19 deletions api/c/indigo/src/indigo_reaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "indigo_mapping.h"
#include "indigo_molecule.h"
#include "reaction/canonical_rsmiles_saver.h"
#include "reaction/pathway_reaction.h"
#include "reaction/reaction_auto_loader.h"
#include "reaction/reaction_automapper.h"
#include "reaction/rsmiles_loader.h"
Expand Down Expand Up @@ -60,7 +61,66 @@ const char* IndigoBaseReaction::debugInfo() const
}

//
// IndigoBaseReaction
// IndigoPathwayReaction
//

IndigoPathwayReaction::IndigoPathwayReaction() : IndigoBaseReaction(PATHWAY_REACTION)
{
init();
}

const char* IndigoPathwayReaction::debugInfo() const
{
if (type == IndigoObject::PATHWAY_REACTION)
return "<pathway reaction>";
return "";
}

IndigoPathwayReaction::~IndigoPathwayReaction()
{
}

void IndigoPathwayReaction::init(std::unique_ptr<BaseReaction>&& reaction)
{
rxn = reaction ? std::move(reaction) : std::make_unique<PathwayReaction>();
}

BaseReaction& IndigoPathwayReaction::getBaseReaction()
{
assert(rxn);
return *rxn;
}

PathwayReaction& IndigoPathwayReaction::getPathwayReaction()
{
assert(rxn);
return dynamic_cast<PathwayReaction&>(*rxn);
}

const char* IndigoPathwayReaction::getName()
{
if (!rxn || rxn->name.ptr() == 0)
return "";
return rxn->name.ptr();
}

IndigoObject* IndigoPathwayReaction::clone()
{
return cloneFrom(*this);
}

IndigoPathwayReaction* IndigoPathwayReaction::cloneFrom(IndigoObject& obj)
{
Reaction& rxn = obj.getReaction();
std::unique_ptr<IndigoPathwayReaction> rxnptr = std::make_unique<IndigoPathwayReaction>();
rxnptr->rxn->clone(rxn, 0, 0, 0);
auto& props = obj.getProperties();
rxnptr->copyProperties(props);
return rxnptr.release();
}

//
// IndigoReaction
//

IndigoReaction::IndigoReaction() : IndigoBaseReaction(REACTION)
Expand All @@ -72,8 +132,6 @@ const char* IndigoReaction::debugInfo() const
{
if (type == IndigoObject::REACTION)
return "<reaction>";
if (type == IndigoObject::PATHWAY_REACTION)
return "<pathway reaction>";
return "";
}

Expand All @@ -83,7 +141,6 @@ IndigoReaction::~IndigoReaction()

void IndigoReaction::init(std::unique_ptr<BaseReaction>&& reaction)
{
type = !reaction || dynamic_cast<Reaction*>(reaction.get()) ? IndigoObject::REACTION : IndigoObject::PATHWAY_REACTION;
rxn = reaction ? std::move(reaction) : std::make_unique<Reaction>();
}

Expand Down Expand Up @@ -226,37 +283,49 @@ IndigoReactionIter::~IndigoReactionIter()

int IndigoReactionIter::_begin()
{
if (_subtype == REACTANTS)
switch (_subtype)
{
case REACTANTS:
return _rxn.reactantBegin();
if (_subtype == PRODUCTS)
case PRODUCTS:
return _rxn.productBegin();
if (_subtype == CATALYSTS)
case CATALYSTS:
return _rxn.catalystBegin();

case REACTIONS:
return _rxn.reactionBegin();
}
return _rxn.begin();
}

int IndigoReactionIter::_end()
{
if (_subtype == REACTANTS)
switch (_subtype)
{
case REACTANTS:
return _rxn.reactantEnd();
if (_subtype == PRODUCTS)
case PRODUCTS:
return _rxn.productEnd();
if (_subtype == CATALYSTS)
case CATALYSTS:
return _rxn.catalystEnd();

case REACTIONS:
return _rxn.reactionEnd();
}
return _rxn.end();
}

int IndigoReactionIter::_next(int i)
{
if (_subtype == REACTANTS)
switch (_subtype)
{
case REACTANTS:
return _rxn.reactantNext(i);
if (_subtype == PRODUCTS)
case PRODUCTS:
return _rxn.productNext(i);
if (_subtype == CATALYSTS)
case CATALYSTS:
return _rxn.catalystNext(i);

case REACTIONS:
return _rxn.reactionNext(i);
}
return _rxn.next(i);
}

Expand All @@ -272,7 +341,13 @@ IndigoObject* IndigoReactionIter::next()
if (_idx == _end())
return 0;

if (_map)
if (_subtype == REACTION)
{
auto reaction = new IndigoReaction();
reaction->init(_rxn.getBaseReaction(_idx));
return reaction;
}
else if (_map)
{
return new IndigoReactionMolecule(_rxn, *_map, _idx);
}
Expand Down Expand Up @@ -380,9 +455,21 @@ CEXPORT int indigoLoadReaction(int source)
loader.ignore_noncritical_query_features = self.ignore_noncritical_query_features;
loader.dearomatize_on_load = self.dearomatize_on_load;
loader.arom_options = self.arom_options;
auto rxn = loader.loadReaction(false);
std::unique_ptr<IndigoBaseReaction> rxnptr;
if (rxn->isPathwayReaction())
{
auto pwr = std::make_unique<IndigoPathwayReaction>();
pwr->init(std::move(rxn));
rxnptr = std::move(pwr);
}
else
{
auto reaction = std::make_unique<IndigoReaction>();
reaction->init(std::move(rxn));
rxnptr = std::move(reaction);
}

std::unique_ptr<IndigoReaction> rxnptr = std::make_unique<IndigoReaction>();
rxnptr->init(loader.loadReaction(false));
return self.addObject(rxnptr.release());
}
INDIGO_END(-1);
Expand Down Expand Up @@ -429,6 +516,11 @@ CEXPORT int indigoIterateMolecules(int reaction)
return _indigoIterateReaction(reaction, IndigoReactionIter::MOLECULES);
}

CEXPORT int indigoIterateReactions(int reaction)
{
return _indigoIterateReaction(reaction, IndigoReactionIter::REACTIONS);
}

CEXPORT int indigoCreateReaction(void)
{
INDIGO_BEGIN
Expand Down
25 changes: 23 additions & 2 deletions api/c/indigo/src/indigo_reaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class DLLEXPORT IndigoReaction : public IndigoBaseReaction
IndigoReaction();
~IndigoReaction() override;

void init(std::unique_ptr<BaseReaction>&& = {});
void init(std::unique_ptr<BaseReaction>&& reaction = {});
BaseReaction& getBaseReaction() override;
Reaction& getReaction() override;
const char* getName() override;
Expand All @@ -79,6 +79,26 @@ class DLLEXPORT IndigoReaction : public IndigoBaseReaction
std::unique_ptr<BaseReaction> rxn;
};

class DLLEXPORT IndigoPathwayReaction : public IndigoBaseReaction
{
public:
IndigoPathwayReaction();
~IndigoPathwayReaction() override;

void init(std::unique_ptr<BaseReaction>&& = {});
BaseReaction& getBaseReaction() override;
PathwayReaction& getPathwayReaction() override;
const char* getName() override;

IndigoObject* clone() override;

static IndigoPathwayReaction* cloneFrom(IndigoObject& obj);

const char* debugInfo() const override;

std::unique_ptr<BaseReaction> rxn;
};

class DLLEXPORT IndigoQueryReaction : public IndigoBaseReaction
{
public:
Expand Down Expand Up @@ -131,7 +151,8 @@ class IndigoReactionIter : public IndigoObject
REACTANTS,
PRODUCTS,
CATALYSTS,
MOLECULES
MOLECULES,
REACTIONS
};

IndigoReactionIter(BaseReaction& rxn, MonomersProperties& map, int subtype);
Expand Down
3 changes: 1 addition & 2 deletions api/c/indigo/src/indigo_savers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -770,9 +770,8 @@ CEXPORT int indigoSaveCml(int item, int output)
}
if (IndigoBaseReaction::is(obj))
{
Reaction& rxn = obj.getReaction();
auto& rxn = obj.getBaseReaction();
ReactionCmlSaver saver(out);

saver.saveReaction(rxn);
out.flush();
return 1;
Expand Down
3 changes: 3 additions & 0 deletions api/dotnet/src/IndigoLib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ public unsafe class IndigoLib
[DllImport("indigo"), SuppressUnmanagedCodeSecurity]
public static extern int indigoIterateMolecules(int reader);

[DllImport("indigo"), SuppressUnmanagedCodeSecurity]
public static extern int indigoIterateReactions(int reader);

[DllImport("indigo"), SuppressUnmanagedCodeSecurity]
public static extern int indigoSaveRxnfile(int reaction, int output);

Expand Down
6 changes: 6 additions & 0 deletions api/dotnet/src/IndigoObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,12 @@ public IEnumerable iterateMolecules()
return new IndigoObject(dispatcher, dispatcher.checkResult(IndigoLib.indigoIterateMolecules(self)), this);
}

public IEnumerable iterateReactions()
{
dispatcher.setSessionID();
return new IndigoObject(dispatcher, dispatcher.checkResult(IndigoLib.indigoIterateReactions(self)), this);
}

public string rxnfile()
{
dispatcher.setSessionID();
Expand Down
2 changes: 2 additions & 0 deletions api/java/indigo/src/main/java/com/epam/indigo/IndigoLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ public interface IndigoLib extends Library {

int indigoIterateMolecules(int reaction);

int indigoIterateReactions(int reaction);

int indigoSaveRxnfile(int reaction, int output);

int indigoSaveRxnfileToFile(int reaction, String filename);
Expand Down
Loading
Loading