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;
}
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) {
}
}
}
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;
}
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;
}
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);
}
Aggregations