Search in sources :

Example 1 with AtomContainer

use of org.openscience.cdk.silent.AtomContainer in project MetFragRelaunched by ipb-halle.

the class HighlightSubStructureImageGenerator method generateImage.

public RenderedImage generateImage(IMolecularStructure precursorMolecule, final DefaultBitArrayFragment structure) {
    Image image = new BufferedImage(this.imageWidth, this.imageHeight, BufferedImage.TYPE_INT_ARGB);
    try {
        IAtomContainer molecule = new AtomContainer(precursorMolecule.getStructureAsIAtomContainer());
        StructureDiagramGenerator sdg = new StructureDiagramGenerator();
        sdg.setMolecule(molecule);
        sdg.generateCoordinates();
        Rectangle drawArea = new Rectangle(this.imageWidth, this.imageHeight);
        IAtomContainer moleculeToDraw = sdg.getMolecule();
        this.renderer.setup(sdg.getMolecule(), drawArea);
        RendererModel rendererModel = this.renderer.getRenderer2DModel();
        // rendererModel.set(StandardGenerator.Visibility.class, SelectionVisibility.iupacRecommendations());
        // rendererModel.set(StandardGenerator.AtomColor.class, new CDK2DAtomColors());
        rendererModel.set(StandardGenerator.Highlighting.class, StandardGenerator.HighlightStyle.OuterGlow);
        rendererModel.set(StandardGenerator.StrokeRatio.class, this.strokeRatio);
        FastBitArray atoms = structure.getAtomsFastBitArray();
        for (int i = 0; i < atoms.getSize(); i++) {
            if (atoms.get(i))
                moleculeToDraw.getAtom(i).setProperty(StandardGenerator.HIGHLIGHT_COLOR, this.highlightColor);
            else
                moleculeToDraw.getAtom(i).removeProperty(StandardGenerator.HIGHLIGHT_COLOR);
        }
        FastBitArray bonds = structure.getBondsFastBitArray();
        for (int i = 0; i < bonds.getSize(); i++) {
            if (bonds.get(i))
                moleculeToDraw.getBond(i).setProperty(StandardGenerator.HIGHLIGHT_COLOR, this.highlightColor);
            else
                moleculeToDraw.getBond(i).removeProperty(StandardGenerator.HIGHLIGHT_COLOR);
        }
        Rectangle2D bounds = new Rectangle2D.Double(0, 0, this.imageWidth, this.imageHeight);
        Graphics2D g2 = (Graphics2D) image.getGraphics();
        g2.setColor(this.backgroundColor);
        g2.fillRect(0, 0, this.imageWidth, this.imageHeight);
        this.renderer.paint(moleculeToDraw, new AWTDrawVisitor(g2), bounds, true);
    } catch (Exception e) {
        return (RenderedImage) image;
    }
    return (RenderedImage) image;
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) Rectangle(java.awt.Rectangle) Rectangle2D(java.awt.geom.Rectangle2D) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) RenderedImage(java.awt.image.RenderedImage) BufferedImage(java.awt.image.BufferedImage) InvalidSmilesException(org.openscience.cdk.exception.InvalidSmilesException) IOException(java.io.IOException) StructureDiagramGenerator(org.openscience.cdk.layout.StructureDiagramGenerator) Graphics2D(java.awt.Graphics2D) RendererModel(org.openscience.cdk.renderer.RendererModel) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) AtomContainer(org.openscience.cdk.silent.AtomContainer) AWTDrawVisitor(org.openscience.cdk.renderer.visitor.AWTDrawVisitor) StandardGenerator(org.openscience.cdk.renderer.generators.standard.StandardGenerator) FastBitArray(de.ipbhalle.metfraglib.FastBitArray) RenderedImage(java.awt.image.RenderedImage)

Example 2 with AtomContainer

use of org.openscience.cdk.silent.AtomContainer in project ambit-mirror by ideaconsult.

the class MoleculeTools method readMolfile.

public static IAtomContainer readMolfile(String molfile) throws Exception {
    MDLV2000Reader r = null;
    try {
        StringReader reader = new StringReader(molfile);
        r = new MDLV2000Reader(reader);
        r.addSetting(new BooleanIOSetting("AddStereoElements", IOSetting.Importance.HIGH, "Assign stereo configurations to stereocenters utilising 2D/3D coordinates.", "false"));
        /*
			 * Properties customSettings = new Properties();
			 * customSettings.setProperty("AddStereoElements", "false");
			 * PropertiesListener listener = new
			 * PropertiesListener(customSettings);
			 * r.addChemObjectIOListener(listener);
			 */
        IAtomContainer mol = r.read(new AtomContainer());
        reader.close();
        return mol;
    } finally {
        try {
            r.close();
        } catch (Exception x) {
        }
    }
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) AtomContainer(org.openscience.cdk.silent.AtomContainer) BooleanIOSetting(org.openscience.cdk.io.setting.BooleanIOSetting) StringReader(java.io.StringReader) MDLV2000Reader(org.openscience.cdk.io.MDLV2000Reader) InvalidSmilesException(org.openscience.cdk.exception.InvalidSmilesException) CDKException(org.openscience.cdk.exception.CDKException) IOException(java.io.IOException)

Example 3 with AtomContainer

use of org.openscience.cdk.silent.AtomContainer in project ambit-mirror by ideaconsult.

the class SizeDescriptorTest method getTestMolecule.

public IAtomContainer getTestMolecule() throws Exception {
    IAtomContainer mol = new AtomContainer();
    MDLReader reader = new MDLReader(getClass().getClassLoader().getResourceAsStream("ambit2/descriptors/size/224824.sdf"));
    mol = (IAtomContainer) reader.read(mol);
    reader.close();
    return mol;
}
Also used : MDLReader(org.openscience.cdk.io.MDLReader) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) AtomContainer(org.openscience.cdk.silent.AtomContainer)

Example 4 with AtomContainer

use of org.openscience.cdk.silent.AtomContainer in project ambit-mirror by ideaconsult.

the class JChemPaintDialog method okAction.

public IAtomContainer okAction() {
    result = JOptionPane.OK_OPTION;
    setVisible(false);
    IAtomContainer updatedMolecule = new AtomContainer();
    IAtomContainerSet m = jcpep.getChemModel().getMoleculeSet();
    for (int i = 0; i < m.getAtomContainerCount(); i++) updatedMolecule.add(m.getAtomContainer(i));
    /*
		 * TODO MoleculeSetManipulator.getAllInOneContainer(
		 * jcpep.getJChemPaintModel().getChemModel().getMoleculeSet());
		 */
    SmilesGenerator g = SmilesGenerator.generic();
    try {
        updatedMolecule.setProperty("SMILES", g.create(updatedMolecule));
    } catch (Exception x) {
        x.printStackTrace();
    }
    return updatedMolecule;
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) AtomContainer(org.openscience.cdk.silent.AtomContainer) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) SmilesGenerator(org.openscience.cdk.smiles.SmilesGenerator) HeadlessException(java.awt.HeadlessException)

Example 5 with AtomContainer

use of org.openscience.cdk.silent.AtomContainer in project ambit-mirror by ideaconsult.

the class MoleculeEditAction method actionPerformed.

public void actionPerformed(ActionEvent arg0) {
    if (modal) {
        if (molecules != null) {
            jcpModel.setMoleculeSet(molecules);
            // JChemPaintPanel jcpep = new JChemPaintPanel(jcpModel,
            // JChemPaint.GUI_APPLICATION, false,null);
            JChemPaintPanel jcpep = new JChemPaintPanel(jcpModel);
            Dimension d = new Dimension(500, 500);
            jcpep.setPreferredSize(d);
            // jcpep.registerModel(jcpModel);
            // jcpep.setJChemPaintModel(jcpModel,d);
            JOptionPane pane = new JOptionPane(jcpep, JOptionPane.QUESTION_MESSAGE, JOptionPane.OK_CANCEL_OPTION);
            JDialog dialog = pane.createDialog(parentComponent, "Edit rule");
            dialog.setBounds(200, 200, 600, 600);
            dialog.setVisible(true);
            if (pane.getValue() == null)
                return;
            int value = ((Integer) pane.getValue()).intValue();
            if (value == 0) {
                // ok
                molecules = jcpep.getChemModel().getMoleculeSet();
                if (molecule == null)
                    molecule = new AtomContainer();
                else
                    molecule.removeAllElements();
                for (int i = 0; i < molecules.getAtomContainerCount(); i++) molecule.add(molecules.getAtomContainer(i));
                updateMolecule(molecule);
                return;
            }
        }
    } else
        editMolecule(true, parentComponent);
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) QueryAtomContainer(org.openscience.cdk.isomorphism.matchers.QueryAtomContainer) AtomContainer(org.openscience.cdk.silent.AtomContainer) JChemPaintPanel(org.openscience.jchempaint.JChemPaintPanel) Dimension(java.awt.Dimension) JOptionPane(javax.swing.JOptionPane) JDialog(javax.swing.JDialog)

Aggregations

IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)1081 AtomContainer (org.openscience.cdk.silent.AtomContainer)1081 Test (org.junit.Test)1043 IAtom (org.openscience.cdk.interfaces.IAtom)153 Atom (org.openscience.cdk.silent.Atom)73 IBond (org.openscience.cdk.interfaces.IBond)50 Atom (org.openscience.cdk.Atom)41 PseudoAtom (org.openscience.cdk.PseudoAtom)38 IStereoElement (org.openscience.cdk.interfaces.IStereoElement)35 QueryAtomContainer (org.openscience.cdk.isomorphism.matchers.QueryAtomContainer)30 ITetrahedralChirality (org.openscience.cdk.interfaces.ITetrahedralChirality)26 IAtomType (org.openscience.cdk.interfaces.IAtomType)24 InputStream (java.io.InputStream)22 Bond (org.openscience.cdk.silent.Bond)19 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)18 Expr (org.openscience.cdk.isomorphism.matchers.Expr)18 PseudoAtom (org.openscience.cdk.silent.PseudoAtom)17 TetrahedralChirality (org.openscience.cdk.stereo.TetrahedralChirality)16 EdgeToBondMap (org.openscience.cdk.graph.GraphUtil.EdgeToBondMap)15 IPseudoAtom (org.openscience.cdk.interfaces.IPseudoAtom)15