Files
VirtualChemistry/README.md
2024-12-12 09:10:26 +00:00

3.5 KiB

VirtualChemistry

VirtualChemistry is a simulation framework. It is designed to model a fictional chemical reaction mechanism, including concepts analogous to atoms, bond structures, and homogeneous/heterogeneous mixtures in real chemistry.

Table of Contents

Features

Current Features

  • Methods to manipulate bonds, atoms, compounds (molecules), homogeneous mixtures, and heterogeneous mixtures.
  • Methods to manipulate environments (e.g., temperature, container volume).

Planned Features

  • A fast mode for reactions to improve computation speed by discarding structural information of compounds.
  • Support for custom reaction mechanisms and chemistry systems.
  • Meta-reaction mode (discard the process of heat exchange and volume updates of reactions; reactions no longer need an environment or a container, just input mixtures).

Prerequisites

Usage

Installation

Clone the repository to your local machine:

git clone https://git.hangman-lab.top/hzhang/VirtualChemistry.git
cd VirtualChemistry

Build the project using the .NET CLI:

dotnet build

This command compiles the source code and restores dependencies, preparing the project for execution.

Alternatively, use the NuGet package manager to add the repository source:

dotnet nuget add source --name hangman-lab https://git.hangman-lab.top/api/packages/hzhang/nuget/index.json

After adding the source, install the package:

dotnet add package VirtualChemistry

Examples

Manually Build a Compound

You can build a compound by manually connecting bonds of atoms:

Compound Q2()
{
    QAtom q1 = new();
    QAtom q2 = new();
    q1.C();
    q2.C();
    BaseBond b1 = q1.NextUnconnected("m");
    BaseBond b2 = q2.NextUnconnected("m");
    b1.Connect(b2);
    Compound c = q1.GrabCompound;
    c.Amount = 1;
    return c;
}

Manually Build a Mixture

Build Homogeneous Mixture by Compounds
HomogeneousMixture Mix(params Compound[] compounds)
{
    HomogeneousMixture res = new();
    foreach (Compound c in compounds)
        res.AddCompound(c);
    return res;
}
Build Heterogeneous Mixture by Homogeneous Mixtures
HeterogeneousMixture Mix(params HomogeneousMixture[] layers)
{
    HeterogeneousMixture res = new();
    foreach (HomogeneousMixture layer in layers)
        res.AddLayer(layer);
    return res;
}

Process Reaction of Mixture

To process a reaction for a heterogeneous mixture h, it needs to be in a container to provide its environment:

class Container : IChemicalContainer
{
    public Container(HeterogeneousMixture h) => Content = h;
    public double Volume() => 200;
    public HeterogeneousMixture Content { get; set; }
    public double EnvironmentPressure { get; set; }
    public double EnvironmentTemperature { get; set; }
}
h.Container = new Container(h);
h.Container.EnvironmentTemperature = 4.4;

Pressure will be updated automatically by compression stiffness and volume of the container:

h.OneStep();

This represents reacting h for 1dt.

License

MIT © hzhang