Search in sources :

Example 31 with StereoMolecule

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

the class MoleculeDragAdapter method drawDragImage.

public Image drawDragImage(Transferable transferable, int width, int height) {
    if (transferable instanceof MoleculeTransferable) {
        try {
            MoleculeTransferable t = (MoleculeTransferable) transferable;
            Object o = t.getTransferData(MoleculeFlavors.DF_SERIALIZEDOBJECT);
            if (o instanceof StereoMolecule) {
                StereoMolecule mol = (StereoMolecule) o;
                Depictor2D depict = new Depictor2D(mol);
                BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
                Graphics g = img.getGraphics();
                ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
                ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
                depict.validateView(g, new Rectangle2D.Double(0, 0, width, height), AbstractDepictor.cModeInflateToMaxAVBL);
                depict.paint(g);
                return img;
            }
        } catch (IOException e1) {
            System.err.println(e1);
        } catch (UnsupportedFlavorException e1) {
            System.err.println(e1);
        }
    }
    return null;
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) Depictor2D(com.actelion.research.chem.Depictor2D) IOException(java.io.IOException) StereoMolecule(com.actelion.research.chem.StereoMolecule) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) BufferedImage(java.awt.image.BufferedImage)

Example 32 with StereoMolecule

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

the class DruglikenessPredictor method assessDruglikeness.

public double assessDruglikeness(StereoMolecule testMolecule, ThreadMaster threadMaster) {
    ParameterizedStringList detail = new ParameterizedStringList();
    if (!sInitialized) {
        detail.add("Druglikeness predictor not properly initialized.", ParameterizedStringList.cStringTypeText);
        return cDruglikenessUnknown;
    }
    detail.add("Found sub-structure fragments and their contributions:", ParameterizedStringList.cStringTypeText);
    detail.add("(yellow atoms carry at least one more substituent)", ParameterizedStringList.cStringTypeText);
    double nastyIncrementSum = 0.0;
    double incrementSum = 0.0;
    int fragmentCount = 0;
    SSSearcher sss = new SSSearcher(SSSearcher.cMatchAtomCharge);
    StereoMolecule fragment = new StereoMolecule();
    for (int i = 0; i < sIncrementTable.getSize(); i++) {
        if (threadMaster != null && threadMaster.threadMustDie())
            return cDruglikenessUnknown;
        Thread.yield();
        new IDCodeParser(false).parse(fragment, sIncrementTable.getFragment(i));
        sss.setMol(fragment, testMolecule);
        if (sss.isFragmentInMolecule()) {
            double increment = sIncrementTable.getIncrement(i);
            if (increment < -1)
                nastyIncrementSum += increment;
            else {
                incrementSum += increment;
                fragmentCount++;
            }
            detail.add(sIncrementTable.getFragment(i), ParameterizedStringList.cStringTypeIDCode);
            detail.add(Double.toString(increment), ParameterizedStringList.cStringTypeDouble);
        }
    }
    if (fragmentCount == 0)
        return -1;
    double druglikeness = nastyIncrementSum + incrementSum / Math.sqrt(fragmentCount);
    // correct cut-off by also treating molecules
    // with more than 50 found fragments as more drug-like
    druglikeness = druglikeness + 0.0625 * (fragmentCount - 40);
    mDetail = detail;
    return druglikeness;
}
Also used : IDCodeParser(com.actelion.research.chem.IDCodeParser) SSSearcher(com.actelion.research.chem.SSSearcher) StereoMolecule(com.actelion.research.chem.StereoMolecule)

Example 33 with StereoMolecule

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

the class ToxicityPredictor method getDetail.

public ParameterizedStringList getDetail(StereoMolecule testMolecule, int riskType) {
    ParameterizedStringList theDetail = new ParameterizedStringList();
    if (!sInitialized) {
        theDetail.add("Toxicity predictor not properly initialized.", ParameterizedStringList.cStringTypeText);
        return theDetail;
    }
    String idcode = new Canonizer(testMolecule).getIDCode();
    if (sRiskMolecules[riskType].contains(idcode)) {
        theDetail.add("This molecule is known to be " + cRiskNameA[riskType] + ":", ParameterizedStringList.cStringTypeText);
        theDetail.add(idcode, ParameterizedStringList.cStringTypeIDCode);
        return theDetail;
    }
    SSSearcher sss = new SSSearcher(SSSearcher.cMatchAtomCharge);
    boolean found = false;
    StereoMolecule fragment = new StereoMolecule();
    for (int i = 0; i < sHighRiskFragments[riskType].size(); i++) {
        new IDCodeParser(false).parse(fragment, sHighRiskFragments[riskType].get(i));
        sss.setMol(fragment, testMolecule);
        if (sss.isFragmentInMolecule()) {
            if (!found)
                theDetail.add("High-risk fragments indicating " + cRiskNameN[riskType] + ":", ParameterizedStringList.cStringTypeText);
            found = true;
            theDetail.add(sHighRiskFragments[riskType].get(i), ParameterizedStringList.cStringTypeIDCode);
        }
    }
    found = false;
    for (int i = 0; i < sLowRiskFragments[riskType].size(); i++) {
        new IDCodeParser(false).parse(fragment, sLowRiskFragments[riskType].get(i));
        sss.setMol(fragment, testMolecule);
        if (sss.isFragmentInMolecule()) {
            if (!found)
                theDetail.add("Medium-risk fragments indicating " + cRiskNameN[riskType] + ":", ParameterizedStringList.cStringTypeText);
            found = true;
            theDetail.add(sLowRiskFragments[riskType].get(i), ParameterizedStringList.cStringTypeIDCode);
        }
    }
    if (theDetail.getSize() == 0)
        theDetail.add("No indication for " + cRiskNameN[riskType] + " found.", ParameterizedStringList.cStringTypeText);
    return theDetail;
}
Also used : IDCodeParser(com.actelion.research.chem.IDCodeParser) SSSearcher(com.actelion.research.chem.SSSearcher) StereoMolecule(com.actelion.research.chem.StereoMolecule) Canonizer(com.actelion.research.chem.Canonizer)

Example 34 with StereoMolecule

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

the class FragmentSpec method matchFragments.

private void matchFragments() {
    // locate disconnected unmapped areas as fragments
    for (int atom = 0; atom < mMol.getAtoms(); atom++) mMol.setAtomMarker(atom, mMol.getAtomMapNo(atom) == 0);
    for (int atom = mMol.getAtoms(); atom < mMol.getAllAtoms(); atom++) mMol.setAtomMarker(atom, false);
    int[] fragmentNo = new int[mMol.getAllAtoms()];
    // TODO: check metal bond behaviour
    int fragmentCount = mMol.getFragmentNumbers(fragmentNo, true, false);
    mMol.removeAtomMarkers();
    if (fragmentCount == 0)
        return;
    StereoMolecule[] fragment = mMol.getFragments(fragmentNo, fragmentCount);
    FragmentSpec[] spec = new FragmentSpec[fragmentCount];
    for (int i = 0; i < fragmentCount; i++) {
        fragment[i].ensureHelperArrays(Molecule.cHelperRings);
        spec[i] = new FragmentSpec();
        spec[i].atomMap = new int[fragment[i].getAtoms()];
        spec[i].rank = new int[fragment[i].getAtoms()];
    }
    // create mapping from fragment's atom indices to mMol atom index
    int[] fragmentAtom = new int[fragmentCount];
    for (int atom = 0; atom < mMol.getAtoms(); atom++) {
        if (mMol.getAtomMapNo(atom) == 0) {
            int fNo = fragmentNo[atom];
            int fAtom = fragmentAtom[fNo]++;
            String label = encodeMappedNeighbors(atom);
            if (label != null) {
                fragment[fNo].setAtomCustomLabel(fAtom, label);
                int highNeighbor = getHighestMappedNeighbor(atom);
                if (spec[fNo].highestMappedNeighbor < highNeighbor)
                    spec[fNo].highestMappedNeighbor = highNeighbor;
            }
            spec[fNo].atomMap[fAtom] = atom;
        }
    }
    for (int i = 0; i < fragmentCount; i++) {
        Canonizer canonizer = new Canonizer(fragment[i], Canonizer.ENCODE_ATOM_CUSTOM_LABELS);
        spec[i].code = canonizer.getIDCode();
        for (int a = 0; a < fragment[i].getAtoms(); a++) spec[i].rank[a] = canonizer.getFinalRank()[a];
    }
    for (int i = 0; i < fragmentCount - 1; i++) {
        if (!spec[i].isMapped) {
            for (int j = i + 1; j < fragmentCount; j++) {
                if (!spec[j].isMapped && spec[i].code.equals(spec[j].code) && spec[i].highestMappedNeighbor != spec[j].highestMappedNeighbor) {
                    mapFragments(spec[i], spec[j]);
                    break;
                }
            }
        }
    }
}
Also used : StereoMolecule(com.actelion.research.chem.StereoMolecule) Canonizer(com.actelion.research.chem.Canonizer)

Example 35 with StereoMolecule

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

the class Reaction method normalize.

public void normalize() {
    int size = mReactant.size();
    for (int i = size - 1; i >= 0; i--) {
        StereoMolecule mol = mReactant.get(i);
        if (mol.getAllAtoms() == 0) {
            mReactant.remove(i);
        }
    }
    size = mProduct.size();
    for (int i = size - 1; i >= 0; i--) {
        StereoMolecule mol = mProduct.get(i);
        if (mol.getAllAtoms() == 0) {
            mProduct.remove(i);
        }
    }
}
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