Search in sources :

Example 1 with CoordinateInventor

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

the class MarkushStructure method createCurrentEnumeration.

private StereoMolecule createCurrentEnumeration() {
    StereoMolecule mol = new StereoMolecule();
    mol.addMolecule(mCoreList.get(mCoreIndex));
    for (int atom = 0; atom < mol.getAllAtoms(); atom++) {
        int rGroup = getRGroupIndex(mol.getAtomicNo(atom));
        if (rGroup != -1)
            mol.addSubstituent(mSubstituent[rGroup][mSubstituentIndex[rGroup]], getAttachmentAtom(mol, atom));
    }
    for (int atom = 0; atom < mol.getAllAtoms(); atom++) mol.setAtomSelection(atom, getRGroupIndex(mol.getAtomicNo(atom)) != -1);
    mol.deleteSelectedAtoms();
    int coreAtoms = mCoreList.get(mCoreIndex).getAllAtoms() - mCoreRGroup[mCoreIndex].length;
    for (int atom = 0; atom < coreAtoms; atom++) mol.setAtomMarker(atom, true);
    new CoordinateInventor(CoordinateInventor.MODE_REMOVE_HYDROGEN | CoordinateInventor.MODE_PREFER_MARKED_ATOM_COORDS).invent(mol);
    return mol;
}
Also used : CoordinateInventor(com.actelion.research.chem.coords.CoordinateInventor)

Example 2 with CoordinateInventor

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

the class JDrawArea method cleanupMultiFragmentCoordinates.

private void cleanupMultiFragmentCoordinates(Graphics g, ExtendedDepictor depictor, boolean selectedOnly) {
    if (selectedOnly && mUpdateMode == UPDATE_INVENT_COORDS) {
        int[] fragmentAtom = new int[mFragment.length];
        for (int atom = 0; atom < mMol.getAllAtoms(); atom++) {
            int fragment = mFragmentNo[atom];
            mFragment[fragment].setAtomMarker(fragmentAtom[fragment], !mMol.isSelectedAtom(atom));
            fragmentAtom[fragment]++;
        }
    }
    Rectangle2D.Double[] boundingRect = new Rectangle2D.Double[mFragment.length];
    // float fragmentWidth = 0.0f;
    for (int fragment = 0; fragment < mFragment.length; fragment++) {
        if (mUpdateMode == UPDATE_INVENT_COORDS) {
            new CoordinateInventor(selectedOnly ? CoordinateInventor.MODE_KEEP_MARKED_ATOM_COORDS : 0).invent(mFragment[fragment]);
            mFragment[fragment].setStereoBondsFromParity();
        }
        Depictor d = new Depictor(mFragment[fragment]);
        d.updateCoords(g, null, AbstractDepictor.cModeInflateToMaxAVBL);
        boundingRect[fragment] = d.getBoundingRect();
    // fragmentWidth += boundingRect[fragment].width;
    }
    double spacing = FRAGMENT_CLEANUP_DISTANCE * AbstractDepictor.cOptAvBondLen;
    double avbl = mMol.getAverageBondLength();
    double arrowWidth = ((mMode & MODE_REACTION) == 0) ? 0f : (mUpdateMode == UPDATE_SCALE_COORDS_USE_FRAGMENTS) ? DEFAULT_ARROW_LENGTH * getWidth() : ((ReactionArrow) mDrawingObjectList.get(0)).getLength() * AbstractDepictor.cOptAvBondLen / avbl;
    double rawX = 0.5 * spacing;
    for (int fragment = 0; fragment <= mFragment.length; fragment++) {
        if ((mMode & MODE_REACTION) != 0 && fragment == mReactantCount) {
            ((ReactionArrow) mDrawingObjectList.get(0)).setCoordinates(rawX - spacing / 2, getHeight() / 2, rawX - spacing / 2 + arrowWidth, getHeight() / 2);
            rawX += arrowWidth;
        }
        if (fragment == mFragment.length) {
            break;
        }
        double dx = rawX - boundingRect[fragment].x;
        double dy = 0.5 * (getHeight() - boundingRect[fragment].height) - boundingRect[fragment].y;
        mFragment[fragment].translateCoords(dx, dy);
        rawX += spacing + boundingRect[fragment].width;
    }
    depictor.updateCoords(g, new Rectangle2D.Double(0, 0, getWidth(), getHeight()), maxUpdateMode());
    int[] fragmentAtom = new int[mFragment.length];
    for (int atom = 0; atom < mMol.getAllAtoms(); atom++) {
        int fragment = mFragmentNo[atom];
        mMol.setAtomX(atom, mFragment[fragment].getAtomX(fragmentAtom[fragment]));
        mMol.setAtomY(atom, mFragment[fragment].getAtomY(fragmentAtom[fragment]));
        fragmentAtom[fragment]++;
    }
    mMol.setStereoBondsFromParity();
}
Also used : CoordinateInventor(com.actelion.research.chem.coords.CoordinateInventor) Rectangle2D(java.awt.geom.Rectangle2D) ReactionArrow(com.actelion.research.chem.reaction.ReactionArrow)

Example 3 with CoordinateInventor

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

the class JDrawArea method expandAtomKeyStrokes.

private void expandAtomKeyStrokes(String keyStrokes) {
    mAtomKeyStrokeBuffer.setLength(0);
    int atomicNo = Molecule.getAtomicNoFromLabel(keyStrokes);
    if (atomicNo != 0) {
        storeState();
        if (mMol.changeAtom(mCurrentHiliteAtom, atomicNo, 0, -1, 0)) {
            fireMoleculeChanged();
            update(UPDATE_CHECK_COORDS);
            return;
        }
    }
    StereoMolecule substituent = NamedSubstituents.getSubstituent(keyStrokes);
    if (substituent != null) {
        storeState();
        // 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(mMol, mCurrentHiliteAtom, 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 = mMol.getAtomX(mCurrentHiliteAtom) - sourceAVBL * fragment.getAtomX(0);
        double dy = mMol.getAtomY(mCurrentHiliteAtom) - sourceAVBL * fragment.getAtomY(0);
        // Attach the substituent to the complete molecule and take coodinates from the
        // previously created fragment-substituent species.
        int firstAtomInMol = mMol.getAllAtoms();
        mMol.addSubstituent(substituent, mCurrentHiliteAtom);
        int substituentAtoms = mMol.getAllAtoms() - firstAtomInMol;
        for (int i = 0; i < substituentAtoms; i++) {
            mMol.setAtomX(firstAtomInMol + i, sourceAVBL * fragment.getAtomX(firstAtomInFragment + i) + dx);
            mMol.setAtomY(firstAtomInMol + i, sourceAVBL * fragment.getAtomY(firstAtomInFragment + i) + dy);
        }
        mMol.setStereoBondsFromParity();
        fireMoleculeChanged();
        update(UPDATE_CHECK_COORDS);
    }
}
Also used : CoordinateInventor(com.actelion.research.chem.coords.CoordinateInventor)

Example 4 with CoordinateInventor

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

the class Model method cleanupMultiFragmentCoordinates.

private void cleanupMultiFragmentCoordinates(AbstractExtendedDepictor depictor, boolean selectedOnly, boolean invent) {
    if (selectedOnly && invent) {
        int[] fragmentAtom = new int[mFragment.length];
        for (int atom = 0; atom < mMol.getAllAtoms(); atom++) {
            int fragment = mFragmentNo[atom];
            mFragment[fragment].setAtomMarker(fragmentAtom[fragment], !mMol.isSelectedAtom(atom));
            fragmentAtom[fragment]++;
        }
    }
    Rectangle2D.Double[] boundingRect = new Rectangle2D.Double[mFragment.length];
    // float fragmentWidth = 0.0f;
    for (int fragment = 0; fragment < mFragment.length; fragment++) {
        if (invent) {
            new CoordinateInventor(selectedOnly ? CoordinateInventor.MODE_KEEP_MARKED_ATOM_COORDS : 0).invent(mFragment[fragment]);
            mFragment[fragment].setStereoBondsFromParity();
        }
        AbstractDepictor d = createDepictor(mFragment[fragment]);
        d.updateCoords(null, null, AbstractDepictor.cModeInflateToMaxAVBL);
        boundingRect[fragment] = d.getBoundingRect();
    }
    double spacing = FRAGMENT_CLEANUP_DISTANCE * AbstractDepictor.cOptAvBondLen;
    double avbl = mMol.getAverageBondLength();
    double arrowWidth = isReaction() ? DEFAULT_ARROW_LENGTH * getWidth() : 0;
    // 0f : true ?
    // : (mMode == UPDATE_SCALE_COORDS_USE_FRAGMENTS) ?
    // DEFAULT_ARROW_LENGTH * getWidth()
    // : mDrawingObjectList.get(0).getBoundingRect().getWidth() * AbstractDepictor.cOptAvBondLen / avbl;
    double rawX = 0.5 * spacing;
    for (int fragment = 0; fragment <= mFragment.length; fragment++) {
        if (isReaction() && fragment == mReactantCount) {
            mDrawingObjectList.get(0).setRect((float) (rawX - spacing / 20), getHeight() / 2, (float) (/*rawX - spacing / 2 + */
            arrowWidth), getHeight() / 2);
            rawX += arrowWidth;
        }
        if (fragment == mFragment.length) {
            break;
        }
        double dx = rawX - boundingRect[fragment].x;
        double dy = 0.5 * (getHeight() - boundingRect[fragment].height) - boundingRect[fragment].y;
        mFragment[fragment].translateCoords(dx, dy);
        rawX += spacing + boundingRect[fragment].width;
    }
    depictor.updateCoords(null, new Rectangle2D.Double(0, 0, getWidth(), getHeight()), maxUpdateMode());
    int[] fragmentAtom = new int[mFragment.length];
    for (int atom = 0; atom < mMol.getAllAtoms(); atom++) {
        int fragment = mFragmentNo[atom];
        mMol.setAtomX(atom, mFragment[fragment].getAtomX(fragmentAtom[fragment]));
        mMol.setAtomY(atom, mFragment[fragment].getAtomY(fragmentAtom[fragment]));
        fragmentAtom[fragment]++;
    }
    mMol.setStereoBondsFromParity();
}
Also used : CoordinateInventor(com.actelion.research.chem.coords.CoordinateInventor) Rectangle2D(java.awt.geom.Rectangle2D)

Example 5 with CoordinateInventor

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

the class IDCodeParser method inventCoordinates.

@Override
protected void inventCoordinates(StereoMolecule mol) {
    CoordinateInventor inventor = new CoordinateInventor();
    // create reproducible coordinates
    inventor.setRandomSeed(0x1234567890L);
    inventor.invent(mol);
}
Also used : CoordinateInventor(com.actelion.research.chem.coords.CoordinateInventor)

Aggregations

CoordinateInventor (com.actelion.research.chem.coords.CoordinateInventor)9 Rectangle2D (java.awt.geom.Rectangle2D)4 StereoMolecule (com.actelion.research.chem.StereoMolecule)1 ReactionArrow (com.actelion.research.chem.reaction.ReactionArrow)1 TreeMap (java.util.TreeMap)1