.NET Framework 4.6.2 or above is supported.
dll
files as references to your project:ChemAxon.NET.dll
ChemAxon.NET.Base.dll
ChemAxon.NET.IKVM.dll
ChemAxon.NET.Windows.Forms.dl
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();
- reusing our msm modules in msi installer package of you application (dlls in GAC)
- running our msi installer before installation of your application (dlls in GAC)
- local deployment without GAC, in your application folder all dlls have to be copied (copylocal = true)
dll
files as references to your project (like in these examples):
ChemAxon.NET.dllThe following third party
ChemAxon.NET.Base.dll
ChemAxon.NET.IKVM.dll
ChemAxon.NET.Windows.Forms.dl
dll
files may also be required (depending on usage):
Database drivers
jtds-1.2.2.dll - Library used to interact with MS SQL 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.
- reusing our msm modules in msi installer package of you application (dlls in GAC)
- running our msi installer before installation of your application (dlls in GAC)
- local deployment without GAC, in your application folder all dlls have to be copied (copylocal = true)
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.
Full examples with Visual Studio 2010 solutions are provided by the installer package.
Example gives a short demo how to visualize structures or molecule data in .NET Windows forms controls.
Supported controls are the following: read-only viewer control, in-place editor control and editor dialog and molecule grid control.
var benzeneData = new MoleculeData("[O-]C1=CC=CC=C1", MoleculeFormat.SMILES);
var benzeneMolecule = MainFactory.Chemistry.CreateMolecule(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 ...");
}
Example code => View ShowMarvinSketch.cs
// start loading controls (editor) on a separate thread
MainFactory.ControlLoader.BeginLoad();
// Button_Click event to Add structures
MainFactory.ControlLoader.EndLoad();
MarvinSketchForm editor = new MarvinSketchForm();
var result = editor.ShowAsDialog();
BindingList<BindableMolecule> list = new BindingList();
// Fill Data and Aromatize in one step
foreach (var mol in enumarator) {
list.Add(MainFactory.Chemistry.CreateBindableMolecule( mol.Transformations.Aromatize()));
}
// 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;
Example code => SDF into Grid View.cs
var benzeneMolecule = MainFactory.Chemistry.CreateMolecule("C1=CC=CC=C1", MoleculeFormat.Unknown);
DataTable tbl = new DataTable();
// columns
DataColumn colMolData = new DataColumn("Structure", typeof(string));
DataColumn colMolFormula = new DataColumn("Formula", typeof(string));
DataColumn colMolWeight = new DataColumn("Weight", typeof(float));
tbl.Columns.Add(colMolData); tbl.Columns.Add(colMolFormula); tbl.Columns.Add(colMolWeight);
// Data Fill
tbl.LoadDataRow(new object[] { benzeneMolecule.MoleculeData.StringData, benzeneMolecule.Formula, benzeneMolecule.Mass }, true);
tbl.LoadDataRow(new object[] { benzeneMolecule.Transformations.Aromatize().MoleculeData.StringData, benzeneMolecule.Transformations.Aromatize().Formula, benzeneMolecule.Transformations.Aromatize().Mass }, true);
// Grid visualization
MoleculeGridView gv = new MoleculeGridView ();
// settings
gv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;
gv. MoleculeCellSize = new System.Drawing.Size(150, 150);
// Binding
gv. DataSource = tbl;
gv. MoleculeColumns.Add ("Structure");
gv. FormulaColumn = "Formula";
Simple examples showing how to import structures from files, how to save molecule lists into files with different file formats.
The examples below show how single or multiple structures are available for clipboard manipulations, introduction to the new ChemAxon clipboard formats.
OLE data embedding, and OLE content on the clipboard is also demonstrated in the following example section.
IFileHandler fileHandler = MainFactory.IO.OpenFile(@"molecules.mrv");
IEnumerable<IJChemMolecule> molecules = fileHandler.Read();
foreach (IJChemMolecule molecule in molecules)
Console.WriteLine(molecule.Formula);
IFileHandler fileHandler = MainFactory.IO.OpenFile(@"molecules.mrv");
var newMolecules = new List<IJChemMolecule>();
fileHandler.Write(newMolecules);
Example code => FileExample.cs
var molecules = new List<IJChemMolecule>();
IClipboardHandler clipboard = MainFactory.IO.OpenClipboard();
clipboard.CopyTo(molecules);
IEnumerable<IJChemMolecule> molecules;
bool isMoleculeOnClipboard = clipboard.PasteFrom(out molecules);
IClipboardHandler clipboard = MainFactory.IO.OpenClipboard();
IClipboardTable clipboardData = clipboard.CreateClipboardTable(3, 2);
clipboardData[0, 0].Data.SetValue(MainFactory.Chemistry.CreateMolecule("benzene"));
clipboardData[1,1].Data.SetValue("Comment 1");
clipboardData[2, 0].Data.SetValue(MainFactory.Chemistry.CreateMolecule("methylpropane"));
clipboardData[0, 1].Data.SetValue("Comment 2");
clipboardData[1,0].Data.SetValue("Comment 3");
clipboardData[2, 1].Data.SetValue(MainFactory.Chemistry.CreateMolecule("hexane"));
clipboard.CopyTo(clipboardData);
IClipboardTable clipboardData;
bool isMixedDataOnClipboard = clipboard.PasteFrom(out clipboardData);
Example code => ClipboardExample.cs
IOleHandler ole = MainFactory.IO.OpenOle();
ole.CopyTo(MainFactory.Chemistry.CreateMolecule("benzene"));
if (ole.IsMarvinOleDocumentOnClipboard())
{
IJChemMolecule molecule;
ole.PasteFrom(out molecule);
Example code => OLEExample.cs
var benzeneData = new MoleculeData("C1=CC=CC=C1", MoleculeFormat.Unknown);
var benzeneMolecule = MainFactory.Chemistry.CreateMolecule(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);
Example code => View MoleculeImage.cs
OB
// simple representations => returning value Simple Representation MoleculeData
string molString = benzeneMolecule.Representations.Represent(MoleculeFormat.MOL).StringData;
Console.WriteLine("MOL: " + molString);
string mrvString = benzeneMolecule.Representations.Represent(MoleculeFormat.MRV).StringData;
Console.WriteLine("MRV: " + mrvString);
byte[] cdxBinary = benzeneMolecule.Representations.Represent(MoleculeFormat.CDX).BinaryData;
// aggregated representations => returning Multiple Representation MoleculeData
var aggregatedDescriptor = new MultipleMoleculeRepresentation(MoleculeFormat.MRV).Add(CompressionFormat.GZIP).Add(EncodingFormat.BASE64);
var multipleMoleculeData = benzeneMolecule.Representations.Represent(aggregatedDescriptor);
// read back multiple representation
benzeneMolecule2 = MainFactory.Chemistry.CreateMolecule(multipleMoleculeData);
// Calculated values
var chargeValue = benzeneMolecule.Calculations.GetCharge(5);
var logPValue = benzeneMolecule.Calculations.logP;
// Calculated molecules
var logPMolecule = benzeneMolecule.Calculations.GetlogPMolecule();
var view = new MarvinViewControl();
view.MoleculeObject = logPMolecule;
ShowMoleculeControl(view, "Calculated Molecules 1.");
// Single actions
var view = new MarvinViewControl();
var view2 = new MarvinViewControl();
view.MoleculeObject = benzeneMolecule;
view2.MoleculeObject = benzeneMolecule.Transformations.Aromatize();
// Batch actions
// A, by action steps in a document
const String XML_CONFIGURATION =
"<StandardizerConfiguration><Actions>" +
"<Aromatize ID=\"Aromatize\" Type=\"general\"/>" +
"<Transformation ID=\"Transform Nitro\" Structure=\"[O:3]=[N:1]=[O:2]>>[#8-:2][N+:1]=[O:3]\"/>" +
"</Actions></StandardizerConfiguration>";
view = new MarvinViewControl();
view.MoleculeObject = benzeneMolecule.Transformations.Standardize(XML_CONFIGURATION);
// B, by Action steps manually
view = new MarvinViewControl();
view2 = new MarvinViewControl();
view.MoleculeObject = wrongBenzeneMolecule.Transformations.Validation.CheckStructure( "moleculecharge" );
view2.MoleculeObject = wrongBenzeneMolecule.Transformations.Validation.FixStructure( "moleculecharge" );
The following section outlines how JChem library can be applied in .NET or ASP.NET integration. What areas are avilable in a middle layer code to manipulate backend.
The next major section is about how to do some database specific operation with molecules including
how to setup a database connection to have a gateway to certain database engines (like Oracle, MySQL, MS SQL, PostgreSQL).
Once we have set up the connection the next step is to focus on the table where structures are located.
The next step is to select one or more table and to start data manipulation actions.
Our new API gives you facility to easily add/insert new structures into the database returning the new assigned identifier.
Amend an existing molecule and restore it without extra effort.
Delete structure from the table.
All structure manipulations can be done in transaction otherwise the auto commitment takes place.
// DBType : MySQL, Oracle ...
IConnectionInfo connection = MainFactory.Database.CreateConnection(host, port, database, user, pwd, databaseType);
IJChemDatabaseHandler dbHandler = MainFactory.Database.OpenJChem(connection);
IEnumerable<IJChemTable> tables = database.GetTables();
return tables.First(table => table.Name == tableName);
IJChemMolecule molecule = MainFactory.Chemistry.CreateMolecule("benzene");
//set values based on the data column
molecule.Properties.Add("DATE_COLUMN", DateTime.Now);
molecule.Properties.Add("VARCHAR_255_COLUMN", "Corporate ID");
JChemDBMolecule insertedMolecule;
table.Insert(molecule, out insertedMolecule);
//Update the molecule
IJChemMolecule newMolecule = MainFactory.Chemistry.CreateMolecule("methylpropane");
insertedMolecule.ModifyWith(newMolecule);
insertedMolecule.Properties.Add("DATE_COLUMN") = new DateTime(1992, 12, 11);
insertedMolecule.Properties.Add("VARCHAR_255_COLUMN") = "Modified corporate ID";
//or use
insertedMolecule.Properties["DATE_COLUMN"] = new DateTime(1992, 12, 11);
insertedMolecule.Properties["VARCHAR_255_COLUMN"] = "Modified corporate ID";
table.Update(insertedMolecule);
// Delete molecule
table.Delete(insertedMolecule);
// Create a molecule first to be the query molecule e.g. in a substructure search
IJChemMolecule queryMolecule = MainFactory.Chemistry.CreateMolecule("Benzene");
// Create a filter criteria hanlder class and set the chemical filter options on it
IJChemMoleculeFilter moleculeFilter = MainFactory.Database.CreateJChemMoleculeFilter(queryMolecule);
moleculeFilter.SearchOption.InvertResults = false;
moleculeFilter.SearchOption.AbsoluteStereo = JChemAbsoluteStereoMatchingModes.AlwaysOn;
// Create conditions for the WHERE clause
IDBConditions dbConditions = MainFactory.Database.CreateDBConditions(ComparisonSqlOperatorType.Greater, new DateTime(1993,12,11), table["DATE_COLUMN"]);
// Extend the where clause with further crioterion
dbConditions.And(ComparisonSqlOperatorType.Less, DateTime.Now, table["DATE_COLUMN"]);
IEnumerable<JChemDBMolecule> molecules = table.GetMolecules(moleculeFilter, dbConditions);
Example code => DatabaseExample.cs
Sometimes e.g. in a web service the need comes up to store structures but not in a database even in a simpler way in a cache.
The key goal here is the faster storage and faster access of molecules without complicated infrastructure.
In addition to read and write molecules from and into a storage, the infrastucture provides a search feature on the data as Filter does (see in the next Filter section).
var memoryTable = MainFactory.Database.OpenMemoryCache();
memoryTable.Add(molecule);
IJChemMolecule[] molecules = new IJChemMolecule[]{
MainFactory.Chemistry.CreateMolecule("methylpropane"),
MainFactory.Chemistry.CreateMolecule("benzol")
};
memoryTable.Add(molecules);
IJChemMolecule query = MainFactory.Chemistry.CreateMolecule("benzene");
bool isMatch = memoryTable.IsMatch(query);
Example code => MemoryCacheExample.cs
The next section is demonstrating what other chemical services the new ChemAxon .NET API includes in addition to creating and visualizing of molecules.
If we have a backend service and we would like to create an "in-memory datacache/database" of molecules for chemical operations,
Chemical Filtering and R-group Decomposition services are natively included in the Chemistry Service Factory.
// Create chemical filter for the list of target molecules, SearchMode can be AtomAtom or Fingerprint
IFilter filter = MainFactory.Chemistry.CreateFilter(targets, SearchMode.AtomAtom);
// Set the search type and other options affecting the result set of the filtering
filter.Options.SearchType = Base.Search.Options.JChemSearchTypes.Substructure;
filter.Options.ChargeMatchingOption = Base.Search.Options.JChemChargeMatchingModes.Exact;
// Create a query molecule for the search and simply run it
IJChemMolecule query = MainFactory.Chemistry.CreateMolecule("methane");
IEnumerable<IJChemMolecule> filterResult = filter.FindAll(query);
Example code => FilterExample.cs
// Create chemical R-group decompoistion for the list of target molecules
IRGroupDecomposition rGroup = MainFactory.Chemistry.CreateRGroupDecomposition(targets);
// Set up options on R-group object e.g. the headers should be included with the fragments and so forth ...
rGroup.Options.IncludeHeader = true;
rGroup.Options.IncludeNonMatchingTarget = false;
It is easy to get the targets and the query molecule reusing the known controls
IJChemMolecule query = MainFactory.Chemistry.CreateMolecule("methane");
// Run the enumeration process with the query molecule
IEnumerable<IJChemMolecule[]> rGroupResult = rGroup.Decompose(query);
return rGroupResult;
Example code => RGroupExample.cs
The following section outlines what Workflow based reusable solutions we offer.... All workflows (behind the scene) consist of 3 layers.
View, which represents the widget (forms, dialogs in most cases)
Workflow model, which makes sure that the data capturing is done in the right way in order to run the workflow with
Workflow controller/presenter, which controls and leads the workflow with dropping the proper widget, letting the model be filled properly and finally doing the main job
In most cases the customer is allowed to change the widget part to their own one through an interface paramter, this will be demonstrated in the next sections ...
How to display molecules in a control has already been demonstrated above. Lets see now how it works by a controlled workflow
IJChemMolecule molecule = MainFactory.Chemistry.CreateMolecule("benzene");
// Show molecule simply through our predefined viewer dialog
MainFactory.Workflow.ShowMolecule(molecule);
// Setting up the custom molecule viewer implementing the IMoleculeViewer interface
IMoleculeViewer moleculeViewer = new CustomMoleculeViewer();
moleculeViewer.Caption = molecule.Formula;
moleculeViewer.DisplayHeight = 100;
moleculeViewer.DisplayWidth = 100;
moleculeViewer.Readonly = true;
// Show molecule thorugh a custom view form
MainFactory.Workflow.ShowMolecule(molecule, moleculeViewer);
IJChemMolecule molecule = MainFactory.Chemistry.CreateMolecule("benzene");
IJChemMolecule newMolecule;
bool isMoleculeChanged = MainFactory.Workflow.EditMolecule(molecule, out newMolecule);
Example code => WorkflowExample.cs
Visualization workflows might not highlight the main benefit of using complete workflows.
But if we think of how to set RGroupDecomposition or Filter or Database queries/options,
it is then not too too difficult to imagine how much work/effort might be to implement a widget for e.g.
|
|
Selecting the file is replaced by the determining database connection and its type. It is continued with specifiying the proper molecule table. |
When it is done the next step is to capture the query data that might contain the structure and
other additional chemical filter information. |
Property selection from the underlying table is very similar to the corresponding File Import step. |
Which is followed by executing the query and processing the hits in grid view control. |
Copyright © 1998-2010 ChemAxon Ltd. All rights reserved.