.NET Examples

Table of Contents


1. Setting up a project using Marvin

  1. Download and install (extract) the .NET package here.
  2. Add the following dll files as references to your project:
    ChemAxon.NET.dll
    ChemAxon.NET.Base.dll
    ChemAxon.NET.IKVM.dll
    ChemAxon.NET.Windows.Forms.dl
  3. Recommended initialization step for Marvin:
    No other initialization needed.
    Except only if you would like to run Marvin Sketcher as a stand alone application then please use: ChemAxon.JChem.Common.Init();

2. Setting up a project using JChem

  1. Download and install the .NET package here.
  2. Add the following dll files as references to your project (like in these examples):
    The following third party dll files may also be required (depending on usage):
    Database drivers
    jtds-1.2.2.dll - Library used to interact with MSSql 2005 database.
    mysql-connector-java-bin.dll - Library used to interact with MySQL database.
    ojdbc14.dll - Library used to interact with Oracle database.
    postgresql-8.3-604.jdbc4.dll - Library used to interact with Postgresql database.

3. API documentation

The NEW ChemAxon .NET API documentation is available in PPT format while all programming areas are not covered (in 6.3).

The JChem .NET API documentation is available in CHM and online.

4. Marvin and New Molecule Representation Examples

Full examples with Visual Studio 2010 solutions are provided by the installer package.

1. Integrating MarvinSketch into a .NET Winforms application

Example gives a short demo how to visualize structures or molecule data in .NET Windows forms controls.

var benzeneData = new MoleculeData("[O-]C1=CC=CC=C1", MoleculeFormat.SMILES);
var benzeneMolecule = new JChemMolecule(benzeneData);
////////////////////////////////////////////////////
// viewer
var viewer = new MarvinViewControl();
viewer.Molecule = "C1=CC=CC=C1";
viewer = new MarvinViewControl();
viewer.MoleculeData = benzeneData;
viewer = new MarvinViewControl();
viewer.MoleculeObject = benzeneMolecule.Transformations.AddHAtoms();

/////////////////////////////////////////////////////////
// editor
var editor = new MarvinEditorControl();
editor.Molecule = "C1=CC=CC=C1";
editor.MoleculeFormat = MoleculeFormat.SMILES.GetDescription().CodeName;
editor = new MarvinEditorControl();
editor.MoleculeData = benzeneData;
editor = new MarvinEditorControl();
editor.MoleculeObject = benzeneMolecule.Transformations.AddHAtoms();

//////////////////////////////////////////////////////////////
// sketcher form
IMoleculeEditorView view = new MarvinSketchForm();
view.MoleculeData = benzeneData;
if (view.ShowAsDialog() == DialogResponse.OK) {
Console.WriteLine("Molecule has been amended ...");
}
else {
Console.WriteLine("Editing cancelled ...");
}

View ShowMarvinSketch.cs

2. Simple Import of molecule(s)

A simple example showing how to import structures.
//////////////////////////////////////////////////////////
// Data sources - lazy-read molecules
var enumarator = IOHelper.LoadAllFromFile(fileName);
BindingList<BindableMolecule> list = new BindingList();

////////////////////////////////////////////////////////////////
// Fill Data and Aromatize in one step
foreach (var mol in enumarator) {
list.Add(new BindableMolecule( mol.Transformations.Aromatize().ToJChemMolecule()));
}

//////////////////////////////////////////////////////////
// Visualization in Grid
MoleculeGridView gv = new MoleculeGridView();

//////////////////////////////////////////////////////////
// Settings
gv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
gv.MoleculeCellSize = new System.Drawing.Size(150, 150);
gv.AutoGenerateColumns = false;
// Binding
gv.DataSource = list;

View Import.cs

3. Molecule and Image generation (also for web/browser applications)

The simplest way of rendering a molecule with ChemAxon.NET libraries:

var benzeneData = new MoleculeData("C1=CC=CC=C1", MoleculeFormat.Unknown);
var benzeneMolecule = new JChemMolecule(benzeneData);
/////////////////////////////////////////////////////////////////////////////////////////
// simple benzene rendering with default rendering settings
var image = benzeneMolecule.Renderer.RenderToImage(ImageFormat.Emf);

/////////////////////////////////////////////////////////////////////////////////////////
// changing the settings and reredering of the same molecule
benzeneMolecule.Renderer.Settings.DrawingInfo.Size = new Size(120, 120);
benzeneMolecule.Renderer.Settings.DrawingInfo.StructureDrawingSettings.WireThickness = 0.23;
var image = benzeneMolecule.Renderer.RenderToImage(ImageFormat.Emf);

/////////////////////////////////////////////////////////////////////////////////////////
// changing the background color and rendering the molecule as bitmap
benzeneMolecule.Renderer.Settings.DrawingInfo.Transparent = false;
benzeneMolecule.Renderer.Settings.DrawingInfo.BackgroundColor = Color.LightGreen;
var image = benzeneMolecule.Renderer.RenderToImage(ImageFormat.Bmp);

View MoleculeImage.cs

5. JChem Examples

Full examples with Visual Studio 2010 solutions are provided by the installer package.

1. JChemBase Search

A simple example of JChem Base Search.

View BaseSearchForm.cs   View DataAccess.cs   View NetMolImporter.cs

2. Insert, Delete, Update Molecules

An example with simple insert, delete, update operations for molecules within a database.
You will also find in this example how to use database drivers for Oracle, MSSql2005, MySQL, Postgresql, ODBC connections.

View MainForm.cs

 

 

Copyright © 1998-2010 ChemAxon Ltd.    All rights reserved.