Skip to content

Commit

Permalink
core: reaction layout fix (#734)
Browse files Browse the repository at this point in the history
* current work

* renderer fix

* clang fix

* simple objects test added

* docker hub and npm

* multi.ket

* reaction layout fix

* r-groups numbering fix

* pr fixes

* pr fixes

Co-authored-by: Roman Porozhnetov <Roman_Porozhnetov@epam.com>
  • Loading branch information
even1024 and even1024 authored May 19, 2022
1 parent a8a5c6d commit 260b321
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/indigo-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1216,4 +1216,4 @@ jobs:
docker push epmlsop/indigo-service:enhanced-latest
- name: Publish master
if: github.ref == 'refs/heads/master'
run: docker push epmlsop/indigo-service:enhanced-latest
run: docker push epmlsop/indigo-service:enhanced-latest
29 changes: 17 additions & 12 deletions api/c/indigo/src/indigo_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,24 @@ CEXPORT int indigoLayout(int object)
else if (IndigoBaseReaction::is(obj))
{
BaseReaction& rxn = obj.getBaseReaction();
ReactionLayout rl(rxn, self.smart_layout);
rl.max_iterations = self.layout_max_iterations;
rl.layout_orientation = (layout_orientation_value)self.layout_orientation;
rl.bond_length = 1.6f;
rl.horizontal_interval_factor = self.layout_horintervalfactor;

rl.make();
try
{
rxn.markStereocenterBonds();
}
catch (Exception e)
if (rxn.isMultistep())
throw IndigoError("Multistep layout is not implemented yet.");
else
{
ReactionLayout rl(rxn, self.smart_layout);
rl.max_iterations = self.layout_max_iterations;
rl.layout_orientation = (layout_orientation_value)self.layout_orientation;
rl.bond_length = 1.6f;
rl.horizontal_interval_factor = self.layout_horintervalfactor;

rl.make();
try
{
rxn.markStereocenterBonds();
}
catch (Exception e)
{
}
}
}
else
Expand Down
4 changes: 4 additions & 0 deletions core/indigo-core/molecule/src/molecule_json_saver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,10 @@ void MoleculeJsonSaver::saveMolecule(BaseMolecule& bmol, Writer<StringBuffer>& w
int n_rgroups = mol->rgroups.getRGroupCount();
for (int i = 1; i <= n_rgroups; ++i)
{
RGroup& rgroup = mol->rgroups.getRGroup(i);
if (rgroup.fragments.size() == 0)
continue;

buf.clear();
out.printf("rg%d", i);
buf.push(0);
Expand Down
2 changes: 1 addition & 1 deletion core/indigo-core/reaction/reaction_json_saver.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace indigo

void saveReaction(BaseReaction& rxn);
void saveSingleReaction(BaseReaction& rxn, BaseMolecule& merged, MoleculeJsonSaver& json_saver);
void saveReactionWithMetadata(BaseReaction& rxn, BaseMolecule& merged, MoleculeJsonSaver& json_saver);
void saveMultistepReaction(BaseReaction& rxn, BaseMolecule& merged, MoleculeJsonSaver& json_saver);

bool _add_stereo_desc;
DECL_ERROR;
Expand Down
13 changes: 6 additions & 7 deletions core/indigo-core/reaction/src/reaction_json_saver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ ReactionJsonSaver::~ReactionJsonSaver()
{
}

void ReactionJsonSaver::saveReactionWithMetadata(BaseReaction& rxn, BaseMolecule& merged, MoleculeJsonSaver& json_saver)
void ReactionJsonSaver::saveMultistepReaction(BaseReaction& rxn, BaseMolecule& merged, MoleculeJsonSaver& json_saver)
{

for (int i = rxn.begin(); i != rxn.end(); i = rxn.next(i))
merged.mergeWithMolecule(rxn.getBaseMolecule(i), 0, 0);

Expand Down Expand Up @@ -93,8 +92,8 @@ void ReactionJsonSaver::saveReactionWithMetadata(BaseReaction& rxn, BaseMolecule
Value pos_array(kArrayType);
Value pos1(kObjectType);
Value pos2(kObjectType);
pos1.AddMember("x", Value().SetDouble(ar._begin.x), ket.GetAllocator());
pos1.AddMember("y", Value().SetDouble(ar._begin.y), ket.GetAllocator());
pos1.AddMember("x", Value().SetDouble(ar._end.x), ket.GetAllocator());
pos1.AddMember("y", Value().SetDouble(ar._end.y), ket.GetAllocator());
pos1.AddMember("z", Value().SetDouble(0.0), ket.GetAllocator());
pos2.AddMember("x", Value().SetDouble(ar._begin.x), ket.GetAllocator());
pos2.AddMember("y", Value().SetDouble(ar._begin.y), ket.GetAllocator());
Expand Down Expand Up @@ -219,7 +218,7 @@ void ReactionJsonSaver::saveSingleReaction(BaseReaction& rxn, BaseMolecule& merg
plus.AddMember("type", "plus", ket.GetAllocator());
Value location(kArrayType);
location.PushBack(Value().SetDouble(plus_offset.x), ket.GetAllocator());
location.PushBack(Value().SetDouble(-plus_offset.y), ket.GetAllocator()); // TODO: remove -
location.PushBack(Value().SetDouble(plus_offset.y), ket.GetAllocator());
location.PushBack(Value().SetDouble(0.0), ket.GetAllocator());
plus.AddMember("location", location, ket.GetAllocator());
nodes.PushBack(plus, ket.GetAllocator());
Expand Down Expand Up @@ -311,9 +310,9 @@ void ReactionJsonSaver::saveReaction(BaseReaction& rxn)
merged = std::make_unique<Molecule>();
}

if (rxn.metaData().size())
if (rxn.isMultistep())
{
saveReactionWithMetadata(rxn, *merged, json_saver);
saveMultistepReaction(rxn, *merged, json_saver);
}
else
{
Expand Down

0 comments on commit 260b321

Please sign in to comment.