MolDraw.Maui
0.4.0
dotnet add package MolDraw.Maui --version 0.4.0
NuGet\Install-Package MolDraw.Maui -Version 0.4.0
<PackageReference Include="MolDraw.Maui" Version="0.4.0" />
<PackageVersion Include="MolDraw.Maui" Version="0.4.0" />
<PackageReference Include="MolDraw.Maui" />
paket add MolDraw.Maui --version 0.4.0
#r "nuget: MolDraw.Maui, 0.4.0"
#:package MolDraw.Maui@0.4.0
#addin nuget:?package=MolDraw.Maui&version=0.4.0
#tool nuget:?package=MolDraw.Maui&version=0.4.0
MolDraw.Maui
MoleculeView — an interactive 2D chemical structure control for .NET MAUI. Show structures from SMILES or from
precomputed coordinates, colour atoms by heat-map weights (perfect for mass-spec peaks, docking scores or model
attention), let the user tap and hover atoms through MVVM bindings, and follow the app's light/dark theme.
Runs on Windows (x64/ARM64), Android, iOS and Mac Catalyst — the .NET MAUI part contains no chemistry toolkit.
Install
dotnet add package MolDraw.Maui # the control (pulls MolDraw.Skia + MolDraw.Depiction)
dotnet add package MolDraw.Core # optional: NCDK engine so `Smiles` works out of the box
Requires .NET 11, .NET MAUI 11 and SkiaSharp 4.156.x.
Quick start
// MauiProgram.cs
using MolDraw.Core;
builder.UseMauiApp<App>()
.UseMolDraw(); // UseSkiaSharp() + renderer + depiction cache
builder.Services.AddMolDrawCore(); // chemistry engine (SMILES -> depiction); optional
<ContentPage xmlns:md="clr-namespace:MolDraw.Maui;assembly=MolDraw.Maui" ...>
<md:MoleculeView Smiles="{Binding Smiles}"
AtomWeights="{Binding AtomWeights}"
Colormap="{Binding Colormap}"
ShowColorBar="True"
SelectedAtomIndex="{Binding SelectedAtomIndex}"
AtomTappedCommand="{Binding AtomTappedCommand}"
ErrorMessage="{Binding SmilesError}" />
</ContentPage>
Highlighting atoms (MVVM)
public partial class PeakViewModel : ObservableObject
{
[ObservableProperty] private string smiles = "CC(=O)OC1=CC=CC=C1C(=O)O";
[ObservableProperty] private IReadOnlyList<float>? atomWeights; // 0..1 per atom index
[ObservableProperty] private int? selectedAtomIndex; // TwoWay: tap selects/deselects
[ObservableProperty] private string? smilesError; // pushed by the control
public void ShowPeak(float[] modelOutput) => AtomWeights = modelOutput; // assign a new list to refresh
[RelayCommand] private void AtomTapped(int atomIndex) { /* show matching peaks */ }
}
Atom indices in AtomWeights are the heavy-atom indices of the SMILES — the same order RDKit uses — so model outputs
can be bound directly. Recolouring never recomputes coordinates.
Properties
| Property | Default mode | Purpose |
|---|---|---|
Smiles |
OneWay | Depicted by the registered IChemistryEngine, cached by SMILES string |
Depiction (MoleculeDepiction) |
OneWay | Precomputed depiction, e.g. from RDKit or Indigo (takes precedence over Smiles) |
DepictionOptions |
OneWay | ForceLayout, PerceiveAromaticity, AssignMissingWedges, CarbonLabels |
RenderOptions |
OneWay | null → Light/Dark preset following Application.RequestedTheme |
AtomWeights (IReadOnlyList<float>) |
OneWay | 0..1 per atom, mapped through Colormap |
AtomColors, BondColors |
OneWay | Explicit per-index highlight colours (win over weights) |
Colormap, ShowColorBar, HighlightRadiusScale |
OneWay | Highlight customisation |
SelectedAtomIndex (int?) |
TwoWay | Tap selects; tapping again or empty space deselects |
HoveredAtomIndex (int?) |
OneWayToSource | Pointer hover (desktop) |
AtomTappedCommand, AtomHoveredCommand |
– | ICommand with the atom index |
ErrorMessage (string?) |
OneWayToSource | Invalid input, shown inside the control and never thrown |
IsInteractive, HitTolerance |
OneWay | Pointer handling |
Using another chemistry engine
MolDraw.Maui only knows IChemistryEngine (from MolDraw.Depiction).
Register your own implementation — RDKit, Indigo, a web service — before or after UseMolDraw() and Smiles follows it:
builder.Services.AddSingleton<IChemistryEngine, IndigoEngine>();
Without any engine, Smiles produces an explanatory ErrorMessage instead of a picture, while a bound Depiction
always renders. That also means: no LGPL dependency in this package — NCDK only enters your app via MolDraw.Core.
Platforms
| Platform | Package target |
|---|---|
| Windows 10/11 (WinUI), x64 + ARM64 | net11.0-windows10.0.19041.0 |
| Android (arm64-v8a, arm, x64, x86) | net11.0-android37.0 |
| iOS 15+ | net11.0-ios27.2 |
| Mac Catalyst 15+ | net11.0-maccatalyst27.2 |
The control is managed code; native Skia binaries come from SkiaSharp for the consuming app's runtime identifier.
Related packages
| Package | Purpose |
|---|---|
| MolDraw.Depiction | model + IChemistryEngine seam |
| MolDraw.Core | NCDK engine (AddMolDrawCore()) |
| MolDraw.Skia | renderer, highlights, PNG/SVG export |
| MolDraw.Maui | this package — MAUI control |
Documentation
- README – full quick start, XAML and ARM64 notes
- Samples
- Architecture
- Changelog
- Issues
License
Apache-2.0 © Agredo Application. Uses SkiaSharp and .NET MAUI (both MIT); no chemistry toolkit is bundled.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0-android37.0 is compatible. net11.0-ios27.2 is compatible. net11.0-maccatalyst27.2 is compatible. net11.0-windows10.0.19041 is compatible. |
-
net11.0-android37.0
- Microsoft.Maui.Controls (>= 11.0.10)
- MolDraw.Skia (>= 0.4.0)
- SkiaSharp (>= 4.156.1)
- SkiaSharp.Views.Maui.Controls (>= 4.156.1)
-
net11.0-ios27.2
- Microsoft.Maui.Controls (>= 11.0.10)
- MolDraw.Skia (>= 0.4.0)
- SkiaSharp (>= 4.156.1)
- SkiaSharp.Views.Maui.Controls (>= 4.156.1)
-
net11.0-maccatalyst27.2
- Microsoft.Maui.Controls (>= 11.0.10)
- MolDraw.Skia (>= 0.4.0)
- SkiaSharp (>= 4.156.1)
- SkiaSharp.Views.Maui.Controls (>= 4.156.1)
-
net11.0-windows10.0.19041
- Microsoft.Maui.Controls (>= 11.0.10)
- MolDraw.Skia (>= 0.4.0)
- SkiaSharp (>= 4.156.1)
- SkiaSharp.Views.Maui.Controls (>= 4.156.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.