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

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
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: 112 additions & 18 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,67 @@ 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)
{
type = !reaction || dynamic_cast<PathwayReaction*>(reaction.get()) ? IndigoObject::PATHWAY_REACTION : IndigoObject::PATHWAY_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 +133,6 @@ const char* IndigoReaction::debugInfo() const
{
if (type == IndigoObject::REACTION)
return "<reaction>";
if (type == IndigoObject::PATHWAY_REACTION)
return "<pathway reaction>";
return "";
}

Expand Down Expand Up @@ -226,37 +285,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 +343,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 +457,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 +518,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
23 changes: 22 additions & 1 deletion api/c/indigo/src/indigo_reaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,12 @@ public IndigoObject iterateMolecules() {
dispatcher, Indigo.checkResult(this, lib.indigoIterateMolecules(self)), this);
}

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

public String rxnfile() {
dispatcher.setSessionID();
return Indigo.checkResultString(this, lib.indigoRxnfile(self));
Expand Down
2 changes: 2 additions & 0 deletions api/python/indigo/indigo/indigo_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ def __init__(self) -> None:
IndigoLib.lib.indigoIterateCatalysts.argtypes = [c_int]
IndigoLib.lib.indigoIterateMolecules.restype = c_int
IndigoLib.lib.indigoIterateMolecules.argtypes = [c_int]
IndigoLib.lib.indigoIterateReactions.restype = c_int
IndigoLib.lib.indigoIterateReactions.argtypes = [c_int]
IndigoLib.lib.indigoSaveRxnfileToFile.restype = c_int
IndigoLib.lib.indigoSaveRxnfileToFile.argtypes = [c_int, c_char_p]
IndigoLib.lib.indigoRxnfile.restype = c_char_p
Expand Down
Loading
Loading