-
-
Notifications
You must be signed in to change notification settings - Fork 5
Use with HelixToolkit (WPF)
Jens Krumsieck edited this page Jun 30, 2023
·
2 revisions
Install ChemSharp.Molecules.HelixToolkit
and add the following to your .xaml-Page:
<...>
<ROOTELEMENT
xmlns:h="http://helix-toolkit.org/wpf"
xmlns:controls="clr-namespace:ChemSharp.Molecules.HelixToolkit.Controls;assembly=ChemSharp.Molecules.HelixToolkit"
>
<...>
<h:HelixViewport3D x:Name="Viewport3D"
ShowViewCube="False" ShowCoordinateSystem="True"
ZoomExtentsWhenLoaded="True" IsHeadLightEnabled="True">
<h:DefaultLights/>
<h:DirectionalHeadLight/>
<controls:ItemsVisual3D ItemsSource="{Binding Atoms3D}"/>
<controls:ItemsVisual3D ItemsSource="{Binding Bonds3D}"/>
</h:HelixViewport3D>
An Example MainWindow.cs
could look like this:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
DataContext = this;
var filename = @"F:\Repositories\ChemSharp\ChemSharp.Tests\files\ptcor.mol2";
Molecule = Molecule.FromFile(filename);
Atoms3D = new ObservableCollection<Atom3D>(Molecule.Atoms.Select(s => new Atom3D(s)));
Bonds3D = new ObservableCollection<Bond3D>(Molecule.Bonds.Select(s => new Bond3D(s)));
}
public Molecule Molecule { get; }
/// <summary>
/// 3D Representation of Atoms
/// </summary>
public ObservableCollection<Atom3D> Atoms3D { get; }
/// <summary>
/// 3D Representation of Bonds
/// </summary>
public ObservableCollection<Bond3D> Bonds3D { get; }
}