Search in sources :

Example 21 with StereoMolecule

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

the class ZoomRotateAction method onMouseDown.

@Override
public boolean onMouseDown(IMouseEvent ev) {
    origin = new Point2D.Double(ev.getX(), ev.getY());
    StereoMolecule mol = model.getMolecule();
    mol.zoomAndRotateInit((float) origin.getX(), (float) origin.getY());
    return false;
}
Also used : Point2D(java.awt.geom.Point2D) StereoMolecule(com.actelion.research.chem.StereoMolecule)

Example 22 with StereoMolecule

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

the class ReactionEncoder method decodeProducts.

/**
 * Generates an array of all products of the encoded reaction string as bytes.
 * If the string includes atom coordinates, these are used.
 * @param rxnBytes
 * @return null or StereoMolecule array with at least one molecule
 */
public static StereoMolecule[] decodeProducts(byte[] rxnBytes) {
    if (rxnBytes == null || rxnBytes.length == 0)
        return null;
    int productIndex = 1 + ArrayUtils.indexOf(rxnBytes, (byte) ReactionEncoder.PRODUCT_IDENTIFIER);
    if (productIndex == 0)
        return null;
    int productEnd = ArrayUtils.indexOf(rxnBytes, (byte) ReactionEncoder.OBJECT_DELIMITER, productIndex);
    if (productEnd == -1)
        productEnd = rxnBytes.length;
    if (productIndex == productEnd)
        return null;
    byte[] coords = null;
    int coordsIndex = 1 + ArrayUtils.indexOf(rxnBytes, (byte) ReactionEncoder.OBJECT_DELIMITER, productEnd + 1);
    if (coordsIndex != 0) {
        int reactantIndex = 0;
        while (reactantIndex < productIndex) {
            // advance coordinate index one step for every reactant
            reactantIndex = 1 + ArrayUtils.indexOf(rxnBytes, (byte) ReactionEncoder.MOLECULE_DELIMITER, reactantIndex);
            coordsIndex = 1 + ArrayUtils.indexOf(rxnBytes, (byte) ReactionEncoder.MOLECULE_DELIMITER, coordsIndex);
        }
        coords = rxnBytes;
    }
    ArrayList<StereoMolecule> productList = new ArrayList<StereoMolecule>();
    while (productIndex != -1 && productIndex < productEnd) {
        StereoMolecule product = new IDCodeParser().getCompactMolecule(rxnBytes, coords, productIndex, coordsIndex);
        if (product.getAllAtoms() != 0)
            productList.add(product);
        productIndex = 1 + ArrayUtils.indexOf(rxnBytes, (byte) ReactionEncoder.MOLECULE_DELIMITER, productIndex);
        coordsIndex = 1 + ArrayUtils.indexOf(rxnBytes, (byte) ReactionEncoder.MOLECULE_DELIMITER, coordsIndex);
    }
    return productList.size() == 0 ? null : productList.toArray(new StereoMolecule[0]);
}
Also used : IDCodeParser(com.actelion.research.chem.IDCodeParser) ArrayList(java.util.ArrayList) StereoMolecule(com.actelion.research.chem.StereoMolecule)

Example 23 with StereoMolecule

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

the class CopyAction method copy.

private void copy() {
    int mMode = model.getMode();
    boolean isReaction = ((mMode & Model.MODE_REACTION) != 0);
    boolean selectionFound = false;
    boolean isBothSideSelection = false;
    boolean isOnProductSide = false;
    StereoMolecule mMol = model.getMolecule();
    for (int atom = 0; atom < mMol.getAllAtoms(); atom++) {
        if (mMol.isSelectedAtom(atom)) {
            if (!selectionFound) {
                selectionFound = true;
                if (!isReaction) {
                    break;
                }
                isOnProductSide = model.isOnProductSide(mMol.getAtomX(atom), mMol.getAtomY(atom));
            } else {
                if (isOnProductSide != model.isOnProductSide(mMol.getAtomX(atom), mMol.getAtomY(atom))) {
                    isBothSideSelection = true;
                    break;
                }
            }
        }
    }
    if (isReaction) {
        if (isBothSideSelection) {
            copyReaction(true);
        } else if (selectionFound) {
            copyMolecule(true);
        } else {
            copyReaction(false);
        }
    } else {
        copyMolecule(selectionFound);
    }
}
Also used : StereoMolecule(com.actelion.research.chem.StereoMolecule)

Example 24 with StereoMolecule

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

the class DeleteAction method onMouseUp.

@Override
public boolean onMouseUp(IMouseEvent evt) {
    boolean ok = false;
    model.pushUndo();
    StereoMolecule mol = model.getMolecule();
    int theAtom = model.getSelectedAtom();
    int theBond = model.getSelectedBond();
    if (mol != null && theAtom != -1) {
        if (mol.isSelectedAtom(theAtom)) {
            mol.deleteSelectedAtoms();
        } else {
            mol.deleteAtom(theAtom);
        }
        ok = true;
    } else if (mol != null && theBond != -1) {
        if (mol.isSelectedBond(theBond)) {
            mol.deleteSelectedAtoms();
        } else {
            mol.deleteBondAndSurrounding(theBond);
        }
        ok = true;
    }
    setHighlightAtom(null, -1);
    setHighlightBond(null, -1);
    return ok;
}
Also used : StereoMolecule(com.actelion.research.chem.StereoMolecule)

Example 25 with StereoMolecule

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

the class NewChainAction method onDrag.

@Override
protected boolean onDrag(java.awt.geom.Point2D pt) {
    StereoMolecule mol = model.getMolecule();
    boolean repaintNeeded = false;
    if (mol != null) {
        double lastX, lastY;
        if (numChainAtoms > 0) {
            lastX = mChainAtomX[numChainAtoms - 1];
            lastY = mChainAtomY[numChainAtoms - 1];
        } else {
            lastX = 0.0;
            lastY = 0.0;
        }
        double avbl = mol.getAverageBondLength();
        // .floor();
        double s0 = avbl;
        // .floor();
        double s1 = (0.866 * avbl);
        // .floor();
        double s2 = (0.5 * avbl);
        double dx = pt.getX() - origin.getX();
        double dy = pt.getY() - origin.getY();
        // sqrt(avbl/2*avbl/2);
        double a = 1.0;
        // sqrt(avbl/2*avbl/2);
        double b = 1.0;
        if (Math.abs(dy) > Math.abs(dx)) {
            numChainAtoms = (int) (2 * Math.abs(dy) / (s0 + s2));
            if ((int) Math.abs(dy) % (int) (s0 + s2) > s0) {
                numChainAtoms++;
            }
            mChainAtomX = new double[numChainAtoms];
            mChainAtomY = new double[numChainAtoms];
            if (pt.getX() < origin.getX()) {
                b = -b;
            }
            if (pt.getY() < origin.getY()) {
                a = -a;
            }
            if (numChainAtoms > 0) {
                mChainAtomX[0] = origin.getX() + s1 * b;
                mChainAtomY[0] = origin.getY() + s2 * a;
                for (int i = 1; i < numChainAtoms; i++) {
                    if ((i & 1) == 0) {
                        mChainAtomX[i] = mChainAtomX[i - 1] + s0 * b;
                        mChainAtomY[i] = mChainAtomY[i - 1] + s2 * a;
                    } else {
                        mChainAtomX[i] = mChainAtomX[i - 1];
                        mChainAtomY[i] = mChainAtomY[i - 1] + s0 * a;
                    }
                }
            }
        } else {
            numChainAtoms = (int) (Math.abs(dx) / s1);
            mChainAtomX = new double[numChainAtoms];
            mChainAtomY = new double[numChainAtoms];
            if (pt.getX() < origin.getX()) {
                s1 = -s1;
            }
            if (pt.getY() < origin.getY()) {
                s2 = -s2;
            }
            for (int i = 0; i < numChainAtoms; i++) {
                mChainAtomX[i] = origin.getX() + (i + 1) * s1;
                mChainAtomY[i] = origin.getY();
                if ((i & 1) == 0) {
                    mChainAtomY[i] += s2;
                }
            }
        }
        if (numChainAtoms > 0) {
            mChainAtom = new int[numChainAtoms];
            for (int i = 0; i < numChainAtoms; i++) {
                mChainAtom[i] = mol.findAtom((float) mChainAtomX[i], (float) mChainAtomY[i]);
                if (mChainAtom[i] != -1) {
                    mChainAtomX[i] = mol.getAtomX(mChainAtom[i]);
                    mChainAtomY[i] = mol.getAtomY(mChainAtom[i]);
                }
            }
            if (mChainAtomX[numChainAtoms - 1] != lastX || mChainAtomY[numChainAtoms - 1] != lastY) {
                repaintNeeded = true;
            }
        } else if (lastX != 0 || lastY != 0) {
            repaintNeeded = true;
        }
    }
    return repaintNeeded;
}
Also used : StereoMolecule(com.actelion.research.chem.StereoMolecule)

Aggregations

StereoMolecule (com.actelion.research.chem.StereoMolecule)62 Point2D (java.awt.geom.Point2D)11 Canonizer (com.actelion.research.chem.Canonizer)8 IDCodeParser (com.actelion.research.chem.IDCodeParser)8 GeomFactory (com.actelion.research.share.gui.editor.geom.GeomFactory)7 SSSearcher (com.actelion.research.chem.SSSearcher)4 Rectangle2D (java.awt.geom.Rectangle2D)3 IDrawingObject (com.actelion.research.share.gui.editor.chem.IDrawingObject)2 IOException (java.io.IOException)2 Depictor2D (com.actelion.research.chem.Depictor2D)1 DrawingObjectList (com.actelion.research.chem.DrawingObjectList)1 CoordinateInventor (com.actelion.research.chem.coords.CoordinateInventor)1 IAtomPropertiesDialog (com.actelion.research.share.gui.editor.dialogs.IAtomPropertiesDialog)1 IAtomQueryFeaturesDialog (com.actelion.research.share.gui.editor.dialogs.IAtomQueryFeaturesDialog)1 IBondQueryFeaturesDialog (com.actelion.research.share.gui.editor.dialogs.IBondQueryFeaturesDialog)1 LittleEndianDataOutputStream (com.actelion.research.util.LittleEndianDataOutputStream)1 IntVec (com.actelion.research.util.datamodel.IntVec)1 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1 BufferedImage (java.awt.image.BufferedImage)1 ArrayList (java.util.ArrayList)1