Skip to content

Commit

Permalink
fix: deal correctly with non matching reactions (#181)
Browse files Browse the repository at this point in the history
  • Loading branch information
lpatiny authored Nov 14, 2023
1 parent 7221d9a commit 74e337e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
14 changes: 14 additions & 0 deletions __tests__/Reactor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ const { Reactor, Molecule, Reaction, ReactionEncoder } = require('../core');
// Currently we generate RXN files using ChemDraw

describe('Reactor class', () => {
it('impossible water loss', () => {
const reaction = ReactionEncoder.decode(
'eMHAIhH!eF@HhP#QF Qd#!R_vq?DqtJ_@ !R@Fp]Agp',
);

const reactor = new Reactor(reaction);

const match = reactor.setReactant(0, Molecule.fromSmiles('C=C(O)C(C)(C)C'));
expect(match).toStrictEqual(true);

const products = reactor.getProducts();
expect(products).toHaveLength(0);
});

it('deshydratation', () => {
const reaction = ReactionEncoder.decode(
'eMHAIhH!eF@HhP#QF Qd#!R_vq?DqtJ_@ !R@Fp]Agp',
Expand Down
4 changes: 4 additions & 0 deletions src/com/actelion/research/gwt/core/JSReactor.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public boolean setReactant(int no, JSMolecule reactant) {
public JSMolecule[][] getProducts() {
StereoMolecule[][] products = reactor.getProducts();

if (products == null || products.length == 0) {
return new JSMolecule[0][0];
}

JSMolecule[][] jsProducts = new JSMolecule[products.length][products[0].length];

for (int i = 0; i < products.length; i++) {
Expand Down

0 comments on commit 74e337e

Please sign in to comment.