Search in sources :

Example 41 with StereoMolecule

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

the class AtomHighlightAction method handleCharacter.

private boolean handleCharacter(IKeyEvent evt) {
    int theAtom = model.getSelectedAtom();
    StereoMolecule mol = model.getMolecule();
    StringBuilder keyStrokeBuffer = model.getKeyStrokeBuffer();
    if (mol == null) {
        return false;
    }
    int newRadical;
    String code = evt.getText();
    if (theAtom != -1) /*&& !evt.isShiftDown()*/
    {
        char c = code != null && code.length() > 0 ? code.charAt(0) : 0;
        boolean isFirst = (keyStrokeBuffer.length() == 0);
        if (isFirst) {
            switch(c) {
                case '+':
                case '-':
                    return mol.changeAtomCharge(theAtom, c == '+');
                case '.':
                    newRadical = (mol.getAtomRadical(theAtom) == Molecule.cAtomRadicalStateD) ? 0 : Molecule.cAtomRadicalStateD;
                    mol.setAtomRadical(theAtom, newRadical);
                    return true;
                case ':':
                    newRadical = (mol.getAtomRadical(theAtom) == Molecule.cAtomRadicalStateT) ? Molecule.cAtomRadicalStateS : (mol.getAtomRadical(theAtom) == Molecule.cAtomRadicalStateS) ? 0 : Molecule.cAtomRadicalStateT;
                    mol.setAtomRadical(theAtom, newRadical);
                    return true;
                case 'q':
                    return mol.isFragment() ? showAtomQFDialog(theAtom) : false;
                case '?':
                    return mol.changeAtom(theAtom, 0, 0, -1, 0);
                default:
                    break;
            }
        }
        return handleCharacter(mol, theAtom, evt);
    } else {
        return handleCharsNonSelected(code);
    }
}
Also used : StereoMolecule(com.actelion.research.chem.StereoMolecule)

Example 42 with StereoMolecule

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

the class AtomHighlightAction method expandAtomKeyStrokes.

private void expandAtomKeyStrokes(StereoMolecule mol, int highliteAtom, String keyStrokes) {
    int atomicNo = Molecule.getAtomicNoFromLabel(keyStrokes);
    if (atomicNo != 0) {
        if (mol.changeAtom(highliteAtom, atomicNo, 0, -1, 0)) {
            model.changed();
            return;
        }
    }
    StereoMolecule substituent = NamedSubstituents.getSubstituent(keyStrokes);
    if (substituent != null) {
        // Copy the the fragment containing the attachment point into a new molecule.
        // Then attach the substituent, create new atom coordinates for the substituent,
        // while retaining coordinates of the fragment.
        StereoMolecule fragment = new StereoMolecule();
        fragment.addFragment(mol, highliteAtom, null);
        double sourceAVBL = fragment.getAverageBondLength();
        int firstAtomInFragment = fragment.getAllAtoms();
        for (int atom = 0; atom < fragment.getAllAtoms(); atom++) {
            fragment.setAtomMarker(atom, true);
        }
        fragment.addSubstituent(substituent, 0);
        new CoordinateInventor(CoordinateInventor.MODE_KEEP_MARKED_ATOM_COORDS).invent(fragment);
        double dx = mol.getAtomX(highliteAtom) - sourceAVBL * fragment.getAtomX(0);
        double dy = mol.getAtomY(highliteAtom) - sourceAVBL * fragment.getAtomY(0);
        // Attach the substituent to the complete molecule and take coodinates from the
        // previously created fragment-substituent species.
        int firstAtomInMol = mol.getAllAtoms();
        mol.addSubstituent(substituent, highliteAtom);
        int substituentAtoms = mol.getAllAtoms() - firstAtomInMol;
        for (int i = 0; i < substituentAtoms; i++) {
            mol.setAtomX(firstAtomInMol + i, sourceAVBL * fragment.getAtomX(firstAtomInFragment + i) + dx);
            mol.setAtomY(firstAtomInMol + i, sourceAVBL * fragment.getAtomY(firstAtomInFragment + i) + dy);
        }
        mol.setStereoBondsFromParity();
        model.changed();
    }
}
Also used : CoordinateInventor(com.actelion.research.chem.coords.CoordinateInventor) StereoMolecule(com.actelion.research.chem.StereoMolecule)

Example 43 with StereoMolecule

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

the class AtomHighlightAction method onKeyPressed.

@Override
public boolean onKeyPressed(IKeyEvent evt) {
    GeomFactory factory = model.getGeomFactory();
    if (evt.getCode().equals(factory.getDeleteKey())) {
        int theAtom = model.getSelectedAtom();
        StereoMolecule mol = model.getMolecule();
        if (theAtom != -1) {
            mol.deleteAtom(theAtom);
            setHighlightAtom(mol, -1);
            return true;
        } else {
            boolean update = false;
            StereoMolecule m = model.getMolecule();
            if (m.deleteSelectedAtoms()) {
                update = true;
            }
            return update;
        }
    } else if (handleCharacter(evt)) {
        return true;
    }
    return false;
}
Also used : GeomFactory(com.actelion.research.share.gui.editor.geom.GeomFactory) StereoMolecule(com.actelion.research.chem.StereoMolecule)

Example 44 with StereoMolecule

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

the class AtomMapAction method onKeyPressed.

// @Override
// public boolean onMouseDown(ACTMouseEvent evt)
// {
// origin = new Point2D.Double(evt.getX(),evt.getY());
// return super.onMouseDown(evt);
// }
@Override
public boolean onKeyPressed(IKeyEvent evt) {
    GeomFactory builder = model.getGeomFactory();
    if (evt.getCode().equals(builder.getDeleteKey())) {
        StereoMolecule mMol = model.getMolecule();
        boolean found = false;
        for (int atom = 0; atom < mMol.getAllAtoms(); atom++) {
            if (mMol.getAtomMapNo(atom) != 0) {
                mMol.setAtomMapNo(atom, 0, false);
                found = true;
            }
        }
        return found;
    }
    return super.onKeyPressed(evt);
}
Also used : GeomFactory(com.actelion.research.share.gui.editor.geom.GeomFactory) StereoMolecule(com.actelion.research.chem.StereoMolecule)

Example 45 with StereoMolecule

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

the class AtomMapAction method onMouseMove.

@Override
public boolean onMouseMove(IMouseEvent evt, boolean drag) {
    firstPoint = lastPoint = null;
    if (model.isReaction()) {
        StereoMolecule mol = model.getMolecule();
        if (!drag) {
            java.awt.geom.Point2D pt = new Point2D.Double(evt.getX(), evt.getY());
            secondAtom = -1;
            if (trackHighLight(pt)) {
                int mCurrentHiliteAtom = model.getSelectedAtom();
                if (mCurrentHiliteAtom != -1) {
                    int mapNo = mol.getAtomMapNo(mCurrentHiliteAtom);
                    if (mapNo != 0) {
                        for (int atom = 0; atom < mol.getAtoms(); atom++) {
                            if (atom != mCurrentHiliteAtom && mol.getAtomMapNo(atom) == mapNo) {
                                secondAtom = atom;
                                break;
                            }
                        }
                    }
                }
                return true;
            }
        } else {
            int atom = model.getSelectedAtom();
            if (mol != null && atom != -1) {
                java.awt.geom.Point2D pt = new Point2D.Double(evt.getX(), evt.getY());
                firstPoint = new Point2D.Double(mol.getAtomX(atom), mol.getAtomY(atom));
                lastPoint = pt;
                return true;
            }
        }
    }
    return false;
}
Also used : Point2D(java.awt.geom.Point2D) Point2D(java.awt.geom.Point2D) 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