Search in sources :

Example 26 with StereoMolecule

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

the class NewChainAction method onMouseUp.

public boolean onMouseUp(IMouseEvent evt) {
    boolean ok = false;
    model.pushUndo();
    java.awt.geom.Point2D pt = new Point2D.Double(evt.getX(), evt.getY());
    StereoMolecule mol = model.getMolecule();
    if (numChainAtoms == 0) {
        mol = model.getMoleculeAt(pt, false);
        if (mol != null) {
            int atom = model.getSelectedAtom();
            if (atom != -1) {
                addSingleBondAtAtom(mol, atom);
            }
        }
    } else if (numChainAtoms > 0) {
        if (sourceAtom == -1) {
            sourceAtom = mol.addAtom((float) origin.getX(), (float) origin.getY());
        }
        if (mChainAtom[0] == -1) {
            mChainAtom[0] = mol.addAtom((float) mChainAtomX[0], (float) mChainAtomY[0]);
        }
        if (mChainAtom[0] != -1) {
            mol.addBond(sourceAtom, mChainAtom[0]);
        }
        if (model.isReaction())
            model.needsLayout(true);
    }
    if (numChainAtoms > 1) {
        for (int i = 1; i < numChainAtoms; i++) {
            if (mChainAtom[i] == -1) {
                mChainAtom[i] = mol.addAtom((float) mChainAtomX[i], (float) mChainAtomY[i]);
            }
            if (mChainAtom[i] != -1) {
                mol.addBond(mChainAtom[i - 1], mChainAtom[i]);
            }
        }
        if (model.isReaction())
            model.needsLayout(true);
    }
    highlightAtom(mol, -1);
    ok = true;
    dragging = false;
    return ok;
}
Also used : Point2D(java.awt.geom.Point2D) StereoMolecule(com.actelion.research.chem.StereoMolecule)

Example 27 with StereoMolecule

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

the class ChemDrawCDX method getTransform.

private MolGeom getTransform(Reaction rxn) {
    double xmin = Double.MAX_VALUE;
    double xmax = Double.MIN_VALUE;
    double ymin = Double.MAX_VALUE;
    double ymax = Double.MIN_VALUE;
    double scale = Double.MAX_VALUE;
    int cnt = rxn.getMolecules();
    if (cnt < 1)
        return new MolGeom(0, 0, 1);
    for (int mi = 0; mi < cnt; mi++) {
        StereoMolecule m = rxn.getMolecule(mi);
        m.ensureHelperArrays(Molecule.cHelperCIP);
        int na = m.getAllAtoms();
        // if more than one atom....
        for (int i = 0; i < na; i++) {
            double x = m.getAtomX(i);
            double y = m.getAtomY(i);
            xmin = Math.min(xmin, x);
            xmax = Math.max(xmax, x);
            ymin = Math.min(ymin, y);
            ymax = Math.max(ymax, y);
        }
        double dx = xmax - xmin;
        double dy = xmax - ymin;
        debug(String.format("Mofile dx = %f dy = %f", dx, dy));
        double xscale = (double) 0x01000000 / dx;
        double yscale = (double) 0x01000000 / dy;
        debug(String.format("Mofile scale x = %.16f y = %.16f", xscale, yscale));
        scale = Math.min(xscale, yscale);
    }
    return new MolGeom(xmin, ymin, scale);
}
Also used : StereoMolecule(com.actelion.research.chem.StereoMolecule)

Example 28 with StereoMolecule

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

the class ChemDrawCDX method getChemDrawBuffer.

public byte[] getChemDrawBuffer(Reaction rxn) {
    CDXDocument doc = new CDXDocument();
    int r = rxn.getReactants();
    int p = rxn.getProducts();
    int mn = rxn.getMolecules();
    doc.add(new CDPShowEnhAtomStereo(true));
    doc.add(new CDPShowAtomStereo(true));
    doc.add(new CDPShowBondStereo(true));
    CDXNode page = new CDXPage();
    doc.add(page);
    MolGeom g = getTransform(rxn);
    int[] rids = new int[r];
    for (int i = 0; i < r; i++) {
        StereoMolecule m = rxn.getReactant(i);
        CDXNode frag = new CDXFragment();
        writeMolecule(m, frag, g);
        rids[i] = frag.getID();
        page.add(frag);
    }
    int[] pids = new int[p];
    for (int i = 0; i < p; i++) {
        StereoMolecule m = rxn.getProduct(i);
        CDXNode frag = new CDXFragment();
        writeMolecule(m, frag, g);
        pids[i] = frag.getID();
        page.add(frag);
    }
    CDXReactionStep step = new CDXReactionStep(rids, pids);
    page.add(step);
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    LittleEndianDataOutputStream l = new LittleEndianDataOutputStream(bos);
    write(l, doc);
    try {
        bos.close();
    } catch (IOException ex) {
        System.err.println("ChemDrawCDX::getChemDrawBuffer(): Error closing stream : " + ex);
    }
    return bos.toByteArray();
}
Also used : LittleEndianDataOutputStream(com.actelion.research.util.LittleEndianDataOutputStream) StereoMolecule(com.actelion.research.chem.StereoMolecule)

Example 29 with StereoMolecule

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

the class ChemDrawCDX method writeMolecule.

private void writeMolecule(StereoMolecule mol, CDXNode frag, MolGeom g) {
    StereoMolecule m = new StereoMolecule(mol);
    m.ensureHelperArrays(Molecule.cHelperCIP);
    int na = m.getAllAtoms();
    int nb = m.getAllBonds();
    CDXAtom[] atoms = new CDXAtom[na];
    if (false) {
        double xmin = m.getAtomX(0);
        double xmax = m.getAtomX(0);
        double ymin = m.getAtomY(0);
        double ymax = m.getAtomY(0);
        // if more than one atom....
        for (int i = 1; i < na; i++) {
            double x = m.getAtomX(i);
            double y = m.getAtomY(i);
            xmin = Math.min(xmin, x);
            xmax = Math.max(xmax, x);
            ymin = Math.min(ymin, y);
            ymax = Math.max(ymax, y);
        }
        double dx = xmax - xmin;
        double dy = xmax - ymin;
        debug(String.format("Mofile dx = %f dy = %f", dx, dy));
        double xscale = (double) 0x00800000 / dx;
        double yscale = (double) 0x00800000 / dy;
        debug(String.format("Mofile scale x = %.16f y = %.16f", xscale, yscale));
        debug("Before translate");
        for (int i = 0; i < na; i++) {
            double x = m.getAtomX(i);
            double y = m.getAtomY(i);
            debug(String.format("O Atom x = %.16f y = %.16f", x, y));
        }
        double scale = Math.min(xscale, yscale);
        m.translateCoords((float) xmin, (float) ymin);
        m.scaleCoords((float) scale);
    } else {
        // MolGeom g = getTransform(mol);
        m.translateCoords((float) -g.xmin, (float) -g.ymin);
        m.scaleCoords((float) g.scale);
    }
    // debug("After translate");
    // for(int i = 0;i < na;i++){
    // double x = m.getAtomX(i);
    // double y = m.getAtomY(i);
    // debug(String.format("Atom x = %.16f y = %.16f",x,y));
    // }
    boolean isMethane = na == 1 && m.getAtomicNo(0) == 6;
    for (int i = 0; i < na; i++) {
        double x = m.getAtomX(i);
        double y = m.getAtomY(i);
        debug(String.format("C Atom x = %.0f y = %.0f", x, y));
        CDXAtom atom = null;
        if (isMethane) {
            atom = new CDXMethane(0x00100000 + (int) x, 0x00100000 + (int) y);
        } else {
            atom = new CDXAtom((short) m.getAtomicNo(i), 0x00100000 + (int) x, 0x00100000 + (int) y);
        }
        if (m.isAtomStereoCenter(i)) {
            int grp = m.getAtomESRGroup(i);
            int esr = m.getAtomESRType(i);
            if (!m.isAtomConfigurationUnknown(i) && !m.getStereoProblem(i)) {
                atom.setAtomESRStereo(esr);
            }
            debug("Group is " + grp);
            if (grp != -1) {
                atom.setAtomESRGroup(grp + 1);
            }
            if (m.getAtomCIPParity(i) != 0) {
                atom.setAtomCIP(m.getAtomCIPParity(i), m.getAtomPi(i) == 2, m.isAtomParityPseudo(i));
            }
            if (m.getAtomMass(i) != 0) {
                atom.setAtomMass((short) m.getAtomMass(i));
            }
            if (m.getAtomCharge(i) != 0) {
                atom.setAtomCharge((byte) m.getAtomCharge(i));
            }
            if (m.getAtomRadical(i) != 0) {
                atom.setAtomRadical((byte) m.getAtomRadical(i));
            }
        }
        // CDXAtom at2 = new CDXAtom((short)8, 0x02000000, 0x00AC03BA);
        // CDXAtom atom = new CDXAtom((short)7,(int)x,(int)y);
        atoms[i] = atom;
        frag.add(atom);
    }
    // For all bonds
    for (int i = 0; i < nb; i++) {
        int a1 = m.getBondAtom(0, i);
        int a2 = m.getBondAtom(1, i);
        int o = m.getBondType(i);
        CDXBond b = new CDXBond(atoms[a1].getID(), atoms[a2].getID());
        b.setBondType(o);
        frag.add(b);
    }
}
Also used : StereoMolecule(com.actelion.research.chem.StereoMolecule)

Example 30 with StereoMolecule

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

the class ChemDrawCDX method getTransform.

private MolGeom getTransform(StereoMolecule mol) {
    StereoMolecule m = new StereoMolecule(mol);
    m.ensureHelperArrays(Molecule.cHelperCIP);
    int na = m.getAllAtoms();
    double xmin = m.getAtomX(0);
    double xmax = m.getAtomX(0);
    double ymin = m.getAtomY(0);
    double ymax = m.getAtomY(0);
    // if more than one atom....
    for (int i = 1; i < na; i++) {
        double x = m.getAtomX(i);
        double y = m.getAtomY(i);
        xmin = Math.min(xmin, x);
        xmax = Math.max(xmax, x);
        ymin = Math.min(ymin, y);
        ymax = Math.max(ymax, y);
    }
    double dx = xmax - xmin;
    double dy = xmax - ymin;
    debug(String.format("Mofile dx = %f dy = %f", dx, dy));
    double xscale = (double) 0x00A00000 / dx;
    double yscale = (double) 0x00A00000 / dy;
    debug(String.format("Mofile scale x = %.16f y = %.16f", xscale, yscale));
    return new MolGeom(xmin, ymin, Math.min(xscale, yscale));
}
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