Search in sources :

Example 1 with MoleculeAutoMapper

use of com.actelion.research.chem.reaction.MoleculeAutoMapper 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)

Aggregations

MoleculeAutoMapper (com.actelion.research.chem.reaction.MoleculeAutoMapper)1 Reaction (com.actelion.research.chem.reaction.Reaction)1