Search in sources :

Example 6 with Reaction

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

the class Model method cleanReaction.

/*
    public void resizeReaction(Dimension os, Dimension ns)
    {
        Reaction rxn = getReaction(false);
        double offsetx = ns.getWidth() - os.getWidth();
        double offsety = ns.getHeight() - os.getHeight();
        double scale;

        if (Math.abs(offsetx) > Math.abs(offsety)) {
            scale = ns.getHeight() / os.getHeight();
        } else {
            scale = ns.getWidth() / os.getWidth();

        }
        ChemistryHelper.transformReaction(rxn, offsetx, offsety, scale);
        setValue(rxn);

    }
*/
public void cleanReaction(boolean cleanAll) {
    Reaction reaction = getReaction();
    // System.out.printf("cleanreaction %s\n",reaction.getReactants());
    Dimension dim = getDisplaySize();
    double w = dim.getWidth();
    double h = dim.getHeight();
    double width = w / 5;
    if (w > 0 && h > 0) {
        // new Arrow(mx , my, dx,20);
        IDrawingObject arrow = getDrawingObjects().get(0);
        arrow.setRect((float) (0.5f * w), (float) (0.5f * h), (float) (0.5f * .16 * w), 20);
        arrowPos = new Point2D.Double((0.5f * w), (0.5f * h));
        mMode = MODE_MULTIPLE_FRAGMENTS;
        if (cleanAll)
            cleanupCoordinates(true, true);
        ChemistryHelper.scaleInto(reaction, 0, 0, dim.getWidth(), dim.getHeight(), width);
        setValue(reaction);
    }
}
Also used : Point2D(java.awt.geom.Point2D) IDrawingObject(com.actelion.research.share.gui.editor.chem.IDrawingObject) Reaction(com.actelion.research.chem.reaction.Reaction)

Example 7 with Reaction

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

the class JDrawArea method tryAutoMapReaction.

private void tryAutoMapReaction() {
    if (mMapper == null) {
        new MoleculeAutoMapper(mMol).autoMap();
        return;
    }
    SSSearcher sss = new MySSSearcher();
    syncFragments();
    // new Reaction(reaction);
    Reaction rxn = getReaction();
    // Mark the manually mapped atoms, so we may re-assign them later
    for (int i = 0; i < rxn.getMolecules(); i++) {
        StereoMolecule mol = rxn.getMolecule(i);
        for (int a = 0; a < mol.getAtoms(); a++) {
            if (mol.getAtomMapNo(a) > 0) {
                mol.setAtomicNo(a, FAKE_ATOM_NO + mol.getAtomMapNo(a));
            }
        }
    }
    rxn = mMapper.matchReaction(rxn, sss);
    if (rxn != null) {
        int offset = 0;
        // Sync the display molecule with the reaction fragments
        {
            int[] fragmentAtom = new int[mFragment.length];
            for (int atom = 0; atom < mMol.getAllAtoms(); atom++) {
                int fragment = mFragmentNo[atom];
                if (mFragment[fragment].getAtomicNo(fragmentAtom[fragment]) > FAKE_ATOM_NO) {
                    mMol.setAtomMapNo(atom, mFragment[fragment].getAtomicNo(fragmentAtom[fragment]) - FAKE_ATOM_NO, false);
                    offset = Math.max(mMol.getAtomMapNo(atom), offset);
                }
                fragmentAtom[fragment]++;
            }
        }
        {
            int[] fragmentAtom = new int[mFragment.length];
            for (int atom = 0; atom < mMol.getAllAtoms(); atom++) {
                int fragment = mFragmentNo[atom];
                if (mFragment[fragment].getAtomMapNo(fragmentAtom[fragment]) > 0 && (mFragment[fragment].getAtomicNo(fragmentAtom[fragment]) <= FAKE_ATOM_NO)) {
                    mMol.setAtomMapNo(atom, mFragment[fragment].getAtomMapNo(fragmentAtom[fragment]) + offset, true);
                }
                fragmentAtom[fragment]++;
            }
        }
    }
    syncFragments();
// mMapper.resetFragments(mappedReaction);
// AStarReactionMapper m = new AStarReactionMapper();
// Reaction rxn = getReaction();
// List<AStarReactionMapper.SlimMapping> l = m.map(rxn);
// if (l != null && l.size() > 0) {
// AStarReactionMapper.SlimMapping sm = l.get(0);
// //			int[] mps = sm.getMapping();
// //			for (int i = 0; i < mps.length; i++) {
// //				System.out.printf("Maps %d -> %d\n", i, mps[i]);
// //			}
// m.activateMapping(sm);
// //			for (int i = 0; i < mFragment.length; i++) {
// //				StereoMolecule mol = mFragment[i];
// //				for (int a = 0; a < mol.getAllAtoms(); a++) {
// //					System.out.printf("T Map %d = %d\n", a, mol.getAtomMapNo(a));
// //				}
// //			}
// 
// int[] fragmentAtom = new int[mFragment.length];
// for (int atom = 0; atom < mMol.getAllAtoms(); atom++) {
// int fragment = mFragmentNo[atom];
// if (mMol.getAtomMapNo(atom) == 0)
// mMol.setAtomMapNo(atom, mFragment[fragment].getAtomMapNo(fragmentAtom[fragment]), true);
// fragmentAtom[fragment]++;
// }
// }
}
Also used : MoleculeAutoMapper(com.actelion.research.chem.reaction.MoleculeAutoMapper) Reaction(com.actelion.research.chem.reaction.Reaction)

Example 8 with Reaction

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

the class JDrawArea method setReactionMode.

public void setReactionMode(boolean rxn) {
    if (rxn) {
        Molecule[] m = this.getFragments();
        if (m == null) {
            setReaction(new Reaction(new StereoMolecule[] { new StereoMolecule(this.getMolecule()) }, 1));
        } else {
            mMode = MODE_MULTIPLE_FRAGMENTS | MODE_REACTION;
            Reaction r = getReaction();
            setReaction(r);
        }
    } else {
        mMode &= ~MODE_REACTION;
    }
}
Also used : Reaction(com.actelion.research.chem.reaction.Reaction)

Example 9 with Reaction

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

the class Model method tryAutoMapReaction.

public void tryAutoMapReaction() {
    SSSearcher sss = new MySSSearcher();
    // new Reaction(reaction);
    Reaction rxn = getReaction();
    // Mark the manually mapped atoms, so we may re-assign them later
    for (int i = 0; i < rxn.getMolecules(); i++) {
        StereoMolecule mol = rxn.getMolecule(i);
        for (int a = 0; a < mol.getAtoms(); a++) {
            if (mol.getAtomMapNo(a) > 0) {
                mol.setAtomicNo(a, FAKE_ATOM_NO + mol.getAtomMapNo(a));
            }
        }
    }
    rxn = mapper.matchReaction(rxn, sss);
    if (rxn != null) {
        int offset = 0;
        // Sync the display molecule with the reaction fragments
        {
            int[] fragmentAtom = new int[mFragment.length];
            for (int atom = 0; atom < mMol.getAllAtoms(); atom++) {
                int fragment = mFragmentNo[atom];
                if (mFragment[fragment].getAtomicNo(fragmentAtom[fragment]) > FAKE_ATOM_NO) {
                    mMol.setAtomMapNo(atom, mFragment[fragment].getAtomicNo(fragmentAtom[fragment]) - FAKE_ATOM_NO, false);
                    offset = Math.max(mMol.getAtomMapNo(atom), offset);
                }
                fragmentAtom[fragment]++;
            }
        }
        {
            int[] fragmentAtom = new int[mFragment.length];
            for (int atom = 0; atom < mMol.getAllAtoms(); atom++) {
                int fragment = mFragmentNo[atom];
                if (mFragment[fragment].getAtomMapNo(fragmentAtom[fragment]) > 0 && (mFragment[fragment].getAtomicNo(fragmentAtom[fragment]) <= FAKE_ATOM_NO)) {
                    mMol.setAtomMapNo(atom, mFragment[fragment].getAtomMapNo(fragmentAtom[fragment]) + offset, true);
                }
                fragmentAtom[fragment]++;
            }
        }
    }
    syncFragments();
}
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