Search in sources :

Example 36 with StereoMolecule

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

the class ReactionEncoder method decode.

/**
 * Creates a Reaction object by interpreting a reaction code,
 * mapping, coordinates and drawing objects that were earlier created
 * by this class.
 * If rxnCoords are relative or null, and if ensureCoordinates==true
 * then all reactants and products are placed automatically along a
 * horizontal line.
 *
 * @return Reaction
 */
public static Reaction decode(String rxnCode, String rxnMapping, String rxnCoords, String rxnObjects, String rxnCatalysts, boolean ensureCoordinates) {
    if (rxnCode == null || rxnCode.length() == 0) {
        return null;
    }
    boolean isProduct = false;
    int idcodeIndex = 0;
    int mappingIndex = 0;
    int coordsIndex = 0;
    boolean reactionLayoutRequired = false;
    int productIndex = rxnCode.indexOf(PRODUCT_IDENTIFIER);
    if (productIndex == -1) {
        return null;
    }
    Reaction rxn = new Reaction();
    while (idcodeIndex != -1) {
        if (idcodeIndex > productIndex) {
            isProduct = true;
        }
        int delimiterIndex = rxnCode.indexOf(MOLECULE_DELIMITER, idcodeIndex);
        if (!isProduct && (delimiterIndex > productIndex || delimiterIndex == -1)) {
            delimiterIndex = productIndex;
        }
        String idcode = null;
        if (delimiterIndex == -1) {
            idcode = rxnCode.substring(idcodeIndex);
            idcodeIndex = -1;
        } else {
            idcode = rxnCode.substring(idcodeIndex, delimiterIndex);
            idcodeIndex = delimiterIndex + 1;
        }
        String mapping = null;
        if (rxnMapping != null && rxnMapping.length() != 0) {
            delimiterIndex = rxnMapping.indexOf(MOLECULE_DELIMITER, mappingIndex);
            if (delimiterIndex == -1) {
                mapping = rxnMapping.substring(mappingIndex);
            } else {
                mapping = rxnMapping.substring(mappingIndex, delimiterIndex);
                mappingIndex = delimiterIndex + 1;
            }
        }
        String coords = null;
        if (rxnCoords != null && rxnCoords.length() != 0) {
            delimiterIndex = rxnCoords.indexOf(MOLECULE_DELIMITER, coordsIndex);
            if (delimiterIndex == -1) {
                coords = rxnCoords.substring(coordsIndex);
            } else {
                coords = rxnCoords.substring(coordsIndex, delimiterIndex);
                coordsIndex = delimiterIndex + 1;
            }
        }
        IDCodeParser parser = new IDCodeParser(ensureCoordinates);
        StereoMolecule mol = parser.getCompactMolecule(idcode, coords);
        if (!reactionLayoutRequired && (coords == null || !parser.coordinatesAreAbsolute(coords)))
            reactionLayoutRequired = true;
        if (mapping != null) {
            parser.parseMapping(mapping.getBytes());
        }
        if (isProduct) {
            rxn.addProduct(mol);
        } else {
            rxn.addReactant(mol);
        }
    }
    if (rxnObjects != null && rxnObjects.length() != 0) {
        rxn.setDrawingObjects(new DrawingObjectList(rxnObjects));
    }
    if (rxnCatalysts != null && rxnCatalysts.length() != 0) {
        IDCodeParser parser = new IDCodeParser(ensureCoordinates);
        int index1 = 0;
        int index2 = rxnCatalysts.indexOf(CATALYST_DELIMITER);
        while (index2 != -1) {
            rxn.addCatalyst(parser.getCompactMolecule(rxnCatalysts.substring(index1, index2)));
            index1 = index2 + 1;
            index2 = rxnCatalysts.indexOf(CATALYST_DELIMITER, index1);
        }
        rxn.addCatalyst(parser.getCompactMolecule(rxnCatalysts.substring(index1)));
    }
    rxn.setReactionLayoutRequired(reactionLayoutRequired);
    return rxn;
}
Also used : IDCodeParser(com.actelion.research.chem.IDCodeParser) DrawingObjectList(com.actelion.research.chem.DrawingObjectList) StereoMolecule(com.actelion.research.chem.StereoMolecule)

Example 37 with StereoMolecule

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

the class HoseCodeCreator method main.

public static void main(String[] args) {
    StereoMolecule molecule = new IDCodeParser(false).getCompactMolecule("deT@@DjU_k``b`@@");
    StereoMolecule otherMolecule = new StereoMolecule(molecule.getAtoms(), molecule.getBonds());
    boolean[] atomMask = new boolean[molecule.getAtoms()];
    Arrays.fill(atomMask, true);
    molecule.copyMoleculeByAtoms(otherMolecule, atomMask, true, null);
    System.out.println(new Canonizer(otherMolecule, Canonizer.ENCODE_ATOM_CUSTOM_LABELS).getIDCode());
    // String id="deT@`@f\bbbRK]@PT@@";
    String id = "fi{qa@DyZkQPSI`cHhhdhdhddhekF\\\\fNXBBjfjjjaXTh@RB@QJh";
    String[] hoses = HoseCodeCreator.getHoseCodesFromDiaID(id, 20, FULL_HOSE_CODE);
    for (int i = 0; i < hoses.length; i++) {
        System.out.println(hoses[i]);
    }
    hoses = HoseCodeCreator.getHoseCodesFromDiaID(id, 8, HOSE_CODE_CUT_C_SP3_SP3);
    for (int i = 0; i < hoses.length; i++) {
        System.out.println(hoses[i]);
    }
}
Also used : IDCodeParser(com.actelion.research.chem.IDCodeParser) StereoMolecule(com.actelion.research.chem.StereoMolecule) Canonizer(com.actelion.research.chem.Canonizer)

Example 38 with StereoMolecule

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

the class HoseCodeCreator method getHoseCodesForAtom.

private static String[] getHoseCodesForAtom(StereoMolecule mol, int rootAtom, int maxSphereSize, int type) {
    StereoMolecule fragment = new StereoMolecule(mol.getAtoms(), mol.getBonds());
    Vector<String> ids = new Vector();
    int min = 0;
    int max = 0;
    boolean[] atomMask = new boolean[mol.getAtoms()];
    int[] atomList = new int[mol.getAtoms()];
    for (int sphere = 0; sphere < maxSphereSize && max < mol.getAtoms(); sphere++) {
        if (max == 0) {
            atomList[0] = rootAtom;
            atomMask[rootAtom] = true;
            max = 1;
        } else {
            int newMax = max;
            for (int i = min; i < max; i++) {
                int atom = atomList[i];
                for (int j = 0; j < mol.getConnAtoms(atom); j++) {
                    int connAtom = mol.getConnAtom(atom, j);
                    if (DEBUG)
                        System.out.println("---> " + atom + " to " + connAtom);
                    if (!atomMask[connAtom]) {
                        switch(type) {
                            case FULL_HOSE_CODE:
                                atomMask[connAtom] = true;
                                atomList[newMax++] = connAtom;
                                break;
                            case HOSE_CODE_CUT_C_SP3_SP3:
                                if (!(isCsp3(mol, atom) && isCsp3(mol, connAtom))) {
                                    if (DEBUG)
                                        System.out.println("NO SKIP");
                                    atomMask[connAtom] = true;
                                    atomList[newMax++] = connAtom;
                                } else {
                                    if (DEBUG)
                                        System.out.println("SKIP");
                                }
                                break;
                        }
                    }
                }
            }
            min = max;
            max = newMax;
        }
        mol.copyMoleculeByAtoms(fragment, atomMask, true, null);
        // TO GET ONLY THE SKELETON
        /*
			for (int atom=0; atom<fragment.getAllAtoms(); atom++)  {
				fragment.setAtomicNo(atom, 6); 
			}
			*/
        ids.add(new Canonizer(fragment, Canonizer.ENCODE_ATOM_CUSTOM_LABELS).getIDCode());
    }
    return ids.toArray(new String[ids.size()]);
}
Also used : StereoMolecule(com.actelion.research.chem.StereoMolecule) Vector(java.util.Vector) Canonizer(com.actelion.research.chem.Canonizer)

Example 39 with StereoMolecule

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

the class DescriptorHandlerSkeletonSpheres method createDescriptor.

/**
 * This descriptor requires proper up/down bonds, because it encodes stereo parities.
 * If a passed molecule is generated from idcode parsing, make sure that coordinates
 * and up/down/bonds are available, i.e. that the IDCodeParser was instantiated with
 * the respective option.
 */
public byte[] createDescriptor(StereoMolecule mol) {
    if (mol == null)
        return null;
    mol.ensureHelperArrays(Molecule.cHelperRings);
    StereoMolecule fragment = new StereoMolecule(mol.getAtoms(), mol.getBonds());
    byte[] descriptor = new byte[DESCRIPTOR_SIZE];
    // System.out.println("descriptor skeleton spheres:");
    int[] atomList = new int[mol.getAtoms()];
    boolean[] atomMask = new boolean[mol.getAtoms()];
    for (int rootAtom = 0; rootAtom < mol.getAtoms(); rootAtom++) {
        if (rootAtom != 0)
            Arrays.fill(atomMask, false);
        int min = 0;
        int max = 0;
        for (int sphere = 0; sphere < MAX_SPHERE_COUNT && max < mol.getAtoms(); sphere++) {
            if (max == 0) {
                atomList[0] = rootAtom;
                atomMask[rootAtom] = true;
                max = 1;
            } else {
                int newMax = max;
                for (int i = min; i < max; i++) {
                    int atom = atomList[i];
                    for (int j = 0; j < mol.getConnAtoms(atom); j++) {
                        int connAtom = mol.getConnAtom(atom, j);
                        if (!atomMask[connAtom]) {
                            atomMask[connAtom] = true;
                            atomList[newMax++] = connAtom;
                        }
                    }
                }
                min = max;
                max = newMax;
            }
            mol.copyMoleculeByAtoms(fragment, atomMask, true, null);
            // take fragment as it is
            if (sphere < EXACT_SPHERE_COUNT) {
                String idcode = new Canonizer(fragment).getIDCode();
                int h = BurtleHasher.hashlittle(idcode, HASH_INIT);
                h = (h & BurtleHasher.hashmask(HASH_BITS));
                if (descriptor[h] < DescriptorEncoder.MAX_COUNT_VALUE)
                    descriptor[h]++;
            // System.out.println("atom:"+rootAtom+"\tfragment\tradius:"+sphere+"\thash:"+h+"\t"+idcode);
            }
            // take atomic no reduced fragment skeleton also
            if (sphere < SKELETON_SPHERE_COUNT) {
                for (int atom = 0; atom < fragment.getAllAtoms(); atom++) fragment.setAtomicNo(atom, 6);
                String idcode = new Canonizer(fragment).getIDCode();
                int h = BurtleHasher.hashlittle(idcode, HASH_INIT);
                h = (h & BurtleHasher.hashmask(HASH_BITS));
                if (descriptor[h] < DescriptorEncoder.MAX_COUNT_VALUE)
                    descriptor[h]++;
            // System.out.println("atom:"+rootAtom+"\tskeleton\tradius:"+sphere+"\thash:"+h+"\t"+idcode);
            }
        }
    }
    return descriptor;
}
Also used : StereoMolecule(com.actelion.research.chem.StereoMolecule) Canonizer(com.actelion.research.chem.Canonizer)

Example 40 with StereoMolecule

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

the class AtomHighlightAction method trackHighLight.

boolean trackHighLight(java.awt.geom.Point2D pt) {
    StereoMolecule mol = model.getMolecule();
    int currentAtom = model.getSelectedAtom();
    int atom = findAtom(mol, pt);
    // Update at least when current selected atom and new selected atom differ
    boolean ok = atom != -1;
    lastHightlightPoint = pt;
    String keyStrokes = model.getKeyStrokeBuffer().toString();
    if (currentAtom != -1 && atom != currentAtom) {
        if (keyStrokes.length() > 0) {
            StereoMolecule currentMol = model.getMolecule();
            expandAtomKeyStrokes(currentMol, currentAtom, keyStrokes);
            model.getKeyStrokeBuffer().setLength(0);
        }
    }
    if (mol != null) {
        setHighlightAtom(mol, atom);
    } else {
        if (model.getSelectedAtom() != -1) {
            model.getKeyStrokeBuffer().setLength(0);
            ok = true;
        }
    }
    atom = model.getSelectedAtom();
    ok = ok | atom != -1;
    return ok;
}
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