Search in sources :

Example 1 with Reaction

use of com.actelion.research.chem.reaction.Reaction in project openchemlib by Actelion.

the class SmilesParser method parseReaction.

public Reaction parseReaction(byte[] smiles) throws Exception {
    int index1 = ArrayUtils.indexOf(smiles, (byte) '>');
    int index2 = (index1 == -1) ? -1 : ArrayUtils.indexOf(smiles, (byte) '>', index1 + 1);
    if (index2 == -1)
        throw new Exception("Missing one or both separators ('>').");
    if (ArrayUtils.indexOf(smiles, (byte) '>', index2 + 1) != -1)
        throw new Exception("Found more than 2 separators ('>').");
    StereoMolecule reactants = new StereoMolecule();
    parse(reactants, smiles, 0, index1);
    StereoMolecule products = new StereoMolecule();
    parse(products, smiles, index2 + 1, smiles.length);
    StereoMolecule catalysts = null;
    if (index2 - index1 > 1) {
        catalysts = new StereoMolecule();
        parse(catalysts, smiles, index1 + 1, index2);
    }
    Reaction rxn = new Reaction();
    rxn.addReactant(reactants);
    rxn.addProduct(products);
    if (catalysts != null)
        rxn.addCatalyst(catalysts);
    return rxn;
}
Also used : Reaction(com.actelion.research.chem.reaction.Reaction)

Example 2 with Reaction

use of com.actelion.research.chem.reaction.Reaction in project openchemlib by Actelion.

the class JDrawArea method paintComponent.

public void paintComponent(Graphics g) {
    super.paintComponent(g);
    ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
    Dimension theSize = getSize();
    if (mSize == null || mSize.width != theSize.width || mSize.height != theSize.height) {
        mSize = theSize;
        if (mUpdateMode < UPDATE_CHECK_COORDS) {
            mUpdateMode = UPDATE_CHECK_COORDS;
        }
    }
    Color background = UIManager.getColor("TextArea.background");
    Color foreground = UIManager.getColor("TextArea.foreground");
    g.setColor(background);
    g.fillRect(0, 0, theSize.width, theSize.height);
    if ((mMode & MODE_REACTION) != 0 && mDrawingObjectList.size() == 0) {
        float mx = 0.5f * (float) theSize.width;
        float my = 0.5f * (float) theSize.height;
        float dx = 0.5f * DEFAULT_ARROW_LENGTH * (float) theSize.width;
        ReactionArrow arrow = new ReactionArrow();
        arrow.setCoordinates(mx - dx, my, mx + dx, my);
        arrow.setDeletable(false);
        mDrawingObjectList.add(arrow);
    }
    boolean isScaledView = false;
    if (mUpdateMode != UPDATE_NONE) {
        if ((mMode & MODE_MULTIPLE_FRAGMENTS) != 0 && mUpdateMode != UPDATE_SCALE_COORDS_USE_FRAGMENTS) {
            analyzeFragmentMembership();
        }
        mDepictor = ((mMode & MODE_REACTION) != 0) ? new ExtendedDepictor(new Reaction(mFragment, mReactantCount), mDrawingObjectList, false, USE_GRAPHICS_2D) : ((mMode & MODE_MARKUSH_STRUCTURE) != 0) ? new ExtendedDepictor(mFragment, mReactantCount, mDrawingObjectList, USE_GRAPHICS_2D) : ((mMode & MODE_MULTIPLE_FRAGMENTS) != 0) ? new ExtendedDepictor(mFragment, mDrawingObjectList, USE_GRAPHICS_2D) : new ExtendedDepictor(mMol, mDrawingObjectList, USE_GRAPHICS_2D);
        mDepictor.setForegroundColor(foreground, background);
        mDepictor.setFragmentNoColor(((mMode & MODE_MULTIPLE_FRAGMENTS) == 0) ? null : LookAndFeelHelper.isDarkLookAndFeel() ? ColorHelper.brighter(background, 0.85f) : ColorHelper.darker(background, 0.85f));
        mDepictor.setDisplayMode(mDisplayMode | AbstractDepictor.cDModeHiliteAllQueryFeatures | ((mCurrentTool == JDrawToolbar.cToolMapper) ? AbstractDepictor.cDModeShowMapping | AbstractDepictor.cDModeSuppressCIPParity : 0));
        if ((mMode & (MODE_REACTION | MODE_MARKUSH_STRUCTURE | MODE_MULTIPLE_FRAGMENTS)) == 0) {
            mDepictor.getMoleculeDepictor(0).setAtomText(mAtomText);
        }
        switch(mUpdateMode) {
            case UPDATE_INVENT_COORDS:
            case UPDATE_SCALE_COORDS:
            case UPDATE_SCALE_COORDS_USE_FRAGMENTS:
                cleanupCoordinates(g, mDepictor);
                break;
            case UPDATE_CHECK_COORDS:
                DepictorTransformation t1 = mDepictor.updateCoords(g, new Rectangle2D.Double(0, 0, theSize.width, theSize.height), 0);
                if (t1 != null && (mMode & MODE_MULTIPLE_FRAGMENTS) != 0) {
                    // in fragment mode depictor transforms mFragment[] rather than mMol
                    t1.applyTo(mMol);
                }
                break;
            case UPDATE_CHECK_VIEW:
                DepictorTransformation t2 = mDepictor.validateView(g, new Rectangle2D.Double(0, 0, theSize.width, theSize.height), 0);
                isScaledView = (t2 != null && !t2.isVoidTransformation());
                break;
        }
        mUpdateMode = UPDATE_NONE;
    }
    if (mDepictor != null) {
        mDepictor.paintFragmentNumbers(g);
    }
    // don't hilite anything when the view is scaled and object coords don't reflect screen coords
    if (!isScaledView) {
        drawHiliting(g);
    }
    if (mDepictor != null) {
        mDepictor.paintStructures(g);
        mDepictor.paintDrawingObjects(g);
    }
    if (mCurrentHiliteAtom != -1 && mAtomKeyStrokeBuffer.length() != 0) {
        int x = (int) mMol.getAtomX(mCurrentHiliteAtom);
        int y = (int) mMol.getAtomY(mCurrentHiliteAtom);
        String s = mAtomKeyStrokeBuffer.toString();
        int validity = getAtomKeyStrokeValidity(s);
        g.setColor((validity == KEY_IS_ATOM_LABEL) ? foreground : (validity == KEY_IS_SUBSTITUENT) ? Color.BLUE : (validity == KEY_IS_VALID_START) ? Color.GRAY : Color.RED);
        if (validity == KEY_IS_INVALID)
            s = s + "<unknown>";
        g.setFont(g.getFont().deriveFont(0, 24));
        g.drawString(s, x, y);
    }
    g.setColor(foreground);
    switch(mPendingRequest) {
        case cRequestNewBond:
            int x1, y1, x2, y2, xdiff, ydiff;
            x1 = (int) mX1;
            y1 = (int) mY1;
            if (mCurrentHiliteAtom == -1 || mCurrentHiliteAtom == mAtom1) {
                x2 = (int) mX2;
                y2 = (int) mY2;
            } else {
                x2 = (int) mMol.getAtomX(mCurrentHiliteAtom);
                y2 = (int) mMol.getAtomY(mCurrentHiliteAtom);
            }
            switch(mCurrentTool) {
                case JDrawToolbar.cToolStdBond:
                    g.drawLine(x1, y1, x2, y2);
                    break;
                case JDrawToolbar.cToolUpBond:
                    int[] x = new int[3];
                    int[] y = new int[3];
                    xdiff = (y1 - y2) / 9;
                    ydiff = (x2 - x1) / 9;
                    x[0] = x1;
                    y[0] = y1;
                    x[1] = x2 + xdiff;
                    y[1] = y2 + ydiff;
                    x[2] = x2 - xdiff;
                    y[2] = y2 - ydiff;
                    g.fillPolygon(x, y, 3);
                    break;
                case JDrawToolbar.cToolDownBond:
                    int xx1, xx2, yy1, yy2;
                    xdiff = x2 - x1;
                    ydiff = y2 - y1;
                    for (int i = 2; i < 17; i += 2) {
                        xx1 = x1 + i * xdiff / 17 - i * ydiff / 128;
                        yy1 = y1 + i * ydiff / 17 + i * xdiff / 128;
                        xx2 = x1 + i * xdiff / 17 + i * ydiff / 128;
                        yy2 = y1 + i * ydiff / 17 - i * xdiff / 128;
                        g.drawLine(xx1, yy1, xx2, yy2);
                    }
                    break;
            }
            break;
        case cRequestNewChain:
            if (mChainAtoms > 0) {
                g.drawLine((int) mX1, (int) mY1, (int) mChainAtomX[0], (int) mChainAtomY[0]);
            }
            if (mChainAtoms > 1) {
                for (int i = 1; i < mChainAtoms; i++) {
                    g.drawLine((int) mChainAtomX[i - 1], (int) mChainAtomY[i - 1], (int) mChainAtomX[i], (int) mChainAtomY[i]);
                }
            }
            break;
        case cRequestLassoSelect:
            g.setColor(lassoColor());
            g.drawPolygon(mLassoRegion);
            g.setColor(foreground);
            break;
        case cRequestSelectRect:
            int x = (mX1 < mX2) ? (int) mX1 : (int) mX2;
            int y = (mY1 < mY2) ? (int) mY1 : (int) mY2;
            int w = (int) Math.abs(mX2 - mX1);
            int h = (int) Math.abs(mY2 - mY1);
            g.setColor(lassoColor());
            g.drawRect(x, y, w, h);
            g.setColor(foreground);
            break;
        case cRequestMapAtoms:
            x1 = (int) mX1;
            y1 = (int) mY1;
            if (mCurrentHiliteAtom == -1 || mCurrentHiliteAtom == mAtom1) {
                x2 = (int) mX2;
                y2 = (int) mY2;
            } else {
                x2 = (int) mMol.getAtomX(mCurrentHiliteAtom);
                y2 = (int) mMol.getAtomY(mCurrentHiliteAtom);
            }
            g.setColor(mapToolColor());
            g.drawLine(x1, y1, x2, y2);
            g.setColor(foreground);
            break;
    }
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) ReactionArrow(com.actelion.research.chem.reaction.ReactionArrow) Reaction(com.actelion.research.chem.reaction.Reaction)

Example 3 with Reaction

use of com.actelion.research.chem.reaction.Reaction in project openchemlib by Actelion.

the class JDrawArea method pasteReaction.

private boolean pasteReaction() {
    boolean ret = false;
    if (mClipboardHandler != null) {
        Reaction rxn = mClipboardHandler.pasteReaction();
        if (rxn != null) {
            for (int i = 0; i < rxn.getMolecules(); i++) {
                rxn.getMolecule(i).setFragment(mMol.isFragment());
            }
            storeState();
            setReaction(rxn);
            ret = true;
        }
    }
    return ret;
}
Also used : Reaction(com.actelion.research.chem.reaction.Reaction)

Example 4 with Reaction

use of com.actelion.research.chem.reaction.Reaction in project openchemlib by Actelion.

the class Model method getIDCode.

public String getIDCode() {
    if (!isReaction()) {
        // getSelectedMolecule();
        StereoMolecule mol = getMolecule();
        if (mol != null && mMol.getAllAtoms() > 0) {
            Canonizer can = new Canonizer(mol);
            return (can.getIDCode() + " " + can.getEncodedCoordinates());
        }
    } else {
        Reaction rxn = getReaction();
        String idc = ReactionEncoder.encode(rxn, true, ReactionEncoder.INCLUDE_DEFAULT);
        if (idc != null)
            ReactionEncoder.decode(idc, ReactionEncoder.INCLUDE_DEFAULT);
        return idc;
    }
    return null;
}
Also used : Reaction(com.actelion.research.chem.reaction.Reaction)

Example 5 with Reaction

use of com.actelion.research.chem.reaction.Reaction in project openchemlib by Actelion.

the class Model method getReaction.

public Reaction getReaction() {
    if ((mMode & MODE_REACTION) == 0) {
        return null;
    }
    Reaction rxn = new Reaction();
    syncFragments();
    for (int i = 0; i < mFragment.length; i++) {
        if (i < mReactantCount) {
            rxn.addReactant(mFragment[i]);
        } else {
            rxn.addProduct(mFragment[i]);
        }
    }
    // 
    return rxn;
}
Also used : Reaction(com.actelion.research.chem.reaction.Reaction)

Aggregations

Reaction (com.actelion.research.chem.reaction.Reaction)9 MoleculeAutoMapper (com.actelion.research.chem.reaction.MoleculeAutoMapper)1 ReactionArrow (com.actelion.research.chem.reaction.ReactionArrow)1 IDrawingObject (com.actelion.research.share.gui.editor.chem.IDrawingObject)1 Point2D (java.awt.geom.Point2D)1 Rectangle2D (java.awt.geom.Rectangle2D)1