m6
This commit is contained in:
159
tests/AtomTests.cs
Normal file
159
tests/AtomTests.cs
Normal file
@@ -0,0 +1,159 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using VirtualChemistry.Chemistry.Atoms.Implements;
|
||||
using VirtualChemistry.Chemistry.Atoms.Resolver;
|
||||
using VirtualChemistry.Chemistry.Bonds.Implements;
|
||||
using VirtualChemistry.Constants;
|
||||
|
||||
namespace VirtualChemistryTest;
|
||||
|
||||
public static class AtomTests
|
||||
{
|
||||
[DatapointSource]
|
||||
private static readonly BaseAtom[] DataSource =
|
||||
ChemistryConstant.ElementSymbols.Select(AtomResolver.Resolve).ToArray();
|
||||
|
||||
private static readonly Action<BaseAtom> OnFailReport =
|
||||
atom => Console.WriteLine($" Fail - {atom.Element} - {atom.AtomicNumber}");
|
||||
|
||||
[Test]
|
||||
public static void AtomQStepByStep()
|
||||
{
|
||||
QAtom atom = new QAtom();
|
||||
atom.C();
|
||||
MBond b = (atom.Bonds.First() as MBond)!;
|
||||
Assert.IsNotNull(b);
|
||||
|
||||
SU3 s = b.EigenStateMatrix;
|
||||
LieSU3 tx = atom.LogEigenState.Get;
|
||||
Console.WriteLine(tx.PythonRepresentation);
|
||||
Console.WriteLine(atom.StateMatrix.Get.PythonRepresentation);
|
||||
var evs = tx.EigenValues();
|
||||
foreach (Complex ev in evs)
|
||||
{
|
||||
Console.WriteLine($"ev - {ev}");
|
||||
}
|
||||
|
||||
evs = atom.StateMatrix.Get.EigenValues();
|
||||
foreach (Complex ev in evs)
|
||||
{
|
||||
Console.WriteLine($"ev x - {ev}");
|
||||
}
|
||||
|
||||
|
||||
Console.WriteLine(s.CSharpRepresentation);
|
||||
Assert.IsTrue(b.StateMatrix.Get.IsEqualApprox(b.EigenStateMatrix));
|
||||
Assert.IsTrue(b.LogState.Get.IsEqualApprox(b.StateMatrix.Get.Log()));
|
||||
Assert.IsTrue(atom.BondInformationMatrix.Get.IsEqualApprox(b.StateMatrix.Get));
|
||||
Assert.IsTrue(atom.LogEigenState.Get.IsEqualApprox(atom.EigenStateMatrix.Log()));
|
||||
Assert.IsTrue((atom.LogEigenState.Get - atom.EigenStateMatrix.Log()).IsEqualApprox(C33.Zero));
|
||||
Assert.IsTrue(atom.LogEigenState.Get.Exp().IsEqualApprox(atom.EigenStateMatrix));
|
||||
Assert.IsTrue(atom.LogStateMatrix.Get.IsEqualApprox(b.StateMatrix.Get.ConjugateOn(atom.LogEigenState.Get)));
|
||||
Assert.IsTrue(atom.StateMatrix.Get.IsEqualApprox(b.StateMatrix.Get.ConjugateOn(atom.EigenStateMatrix)));
|
||||
|
||||
}
|
||||
|
||||
[Theory]
|
||||
public static void AtomMatrixTest(BaseAtom atom)
|
||||
{
|
||||
Assert.IsTrue(atom.LogStateMatrix.Get.Exp().IsEqualApprox(atom.StateMatrix.Get));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
public static void BondInfoTest(BaseAtom atom)
|
||||
{
|
||||
Console.WriteLine(atom.Element);
|
||||
foreach(var g in atom.Bonds.GroupBy(a => a.BondType))
|
||||
Console.WriteLine($"\t\t{g.Key}, {g.Count()}");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void AtomTestQ()
|
||||
{
|
||||
QAtom a = new QAtom();
|
||||
a.C();
|
||||
//LieSU3 x = a.LogStateMatrix.Get;
|
||||
//SU3 expx = a.StateMatrix.Get;
|
||||
//Assert.IsTrue(a.LogStateMatrix.Get.Exp().IsEqualApprox(a.StateMatrix.Get));
|
||||
Assert.That(a.NextUnconnected(ChemistryConstant.BondTypes.M), Is.Not.EqualTo(BaseBond.Null));
|
||||
Assert.That(a.NextUnconnected(ChemistryConstant.BondTypes.S), Is.EqualTo(BaseBond.Null));
|
||||
Assert.That(a.NextUnconnected(ChemistryConstant.BondTypes.D), Is.EqualTo(BaseBond.Null));
|
||||
Assert.That(a.NextUnconnected(ChemistryConstant.BondTypes.Y), Is.EqualTo(BaseBond.Null));
|
||||
Assert.That(a.NextUnconnected(ChemistryConstant.BondTypes.Q), Is.EqualTo(BaseBond.Null));
|
||||
Assert.That(a.NextUnconnected(ChemistryConstant.BondTypes.P), Is.EqualTo(BaseBond.Null));
|
||||
Assert.That(a.NextUnconnected(ChemistryConstant.BondTypes.H), Is.EqualTo(BaseBond.Null));
|
||||
Dictionary<string, int> bondTypeCount = new();
|
||||
foreach (BaseBond b in a.Bonds)
|
||||
{
|
||||
Assert.IsFalse(b.Connected);
|
||||
Assert.That(b.Atom, Is.EqualTo(a));
|
||||
Assert.That(b.Energy, Is.EqualTo(0));
|
||||
if (bondTypeCount.ContainsKey(b.BondType))
|
||||
bondTypeCount[b.BondType] += 1;
|
||||
else
|
||||
bondTypeCount[b.BondType] = 1;
|
||||
}
|
||||
Assert.That(bondTypeCount["m"], Is.EqualTo(1));
|
||||
|
||||
}
|
||||
[Test]
|
||||
public static void AtomTestR()
|
||||
{
|
||||
RAtom a = new RAtom();
|
||||
a.C();
|
||||
Assert.IsTrue(a.LogStateMatrix.Get.Exp().IsEqualApprox(a.StateMatrix.Get));
|
||||
Assert.That(a.NextUnconnected(ChemistryConstant.BondTypes.M), Is.Not.EqualTo(BaseBond.Null));
|
||||
Assert.That(a.NextUnconnected(ChemistryConstant.BondTypes.S), Is.Not.EqualTo(BaseBond.Null));
|
||||
Assert.That(a.NextUnconnected(ChemistryConstant.BondTypes.D), Is.EqualTo(BaseBond.Null));
|
||||
Assert.That(a.NextUnconnected(ChemistryConstant.BondTypes.Y), Is.EqualTo(BaseBond.Null));
|
||||
Assert.That(a.NextUnconnected(ChemistryConstant.BondTypes.Q), Is.EqualTo(BaseBond.Null));
|
||||
Assert.That(a.NextUnconnected(ChemistryConstant.BondTypes.P), Is.EqualTo(BaseBond.Null));
|
||||
Assert.That(a.NextUnconnected(ChemistryConstant.BondTypes.H), Is.EqualTo(BaseBond.Null));
|
||||
Dictionary<string, int> bondTypeCount = new Dictionary<string, int>();
|
||||
foreach (BaseBond b in a.Bonds)
|
||||
{
|
||||
Assert.IsFalse(b.Connected);
|
||||
Assert.That(b.Atom, Is.EqualTo(a));
|
||||
Assert.That(b.Energy, Is.EqualTo(0));
|
||||
if (bondTypeCount.ContainsKey(b.BondType))
|
||||
bondTypeCount[b.BondType] += 1;
|
||||
else
|
||||
bondTypeCount[b.BondType] = 1;
|
||||
}
|
||||
Assert.That(bondTypeCount["m"], Is.EqualTo(1));
|
||||
Assert.That(bondTypeCount["s"], Is.EqualTo(2));
|
||||
}
|
||||
[Test]
|
||||
public static void AtomTestA()
|
||||
{
|
||||
AAtom a = new AAtom();
|
||||
a.C();
|
||||
Assert.IsTrue(a.LogStateMatrix.Get.Exp().IsEqualApprox(a.StateMatrix.Get));
|
||||
Assert.That(a.NextUnconnected(ChemistryConstant.BondTypes.M), Is.Not.EqualTo(BaseBond.Null));
|
||||
Assert.That(a.NextUnconnected(ChemistryConstant.BondTypes.S), Is.Not.EqualTo(BaseBond.Null));
|
||||
Assert.That(a.NextUnconnected(ChemistryConstant.BondTypes.D), Is.Not.EqualTo(BaseBond.Null));
|
||||
Assert.That(a.NextUnconnected(ChemistryConstant.BondTypes.Y), Is.EqualTo(BaseBond.Null));
|
||||
Assert.That(a.NextUnconnected(ChemistryConstant.BondTypes.Q), Is.EqualTo(BaseBond.Null));
|
||||
Assert.That(a.NextUnconnected(ChemistryConstant.BondTypes.P), Is.EqualTo(BaseBond.Null));
|
||||
Assert.That(a.NextUnconnected(ChemistryConstant.BondTypes.H), Is.EqualTo(BaseBond.Null));
|
||||
Dictionary<string, int> bondTypeCount = new Dictionary<string, int>();
|
||||
foreach (BaseBond b in a.Bonds)
|
||||
{
|
||||
Assert.IsFalse(b.Connected);
|
||||
Assert.That(b.Atom, Is.EqualTo(a));
|
||||
Assert.That(b.Energy, Is.EqualTo(0));
|
||||
if (bondTypeCount.ContainsKey(b.BondType))
|
||||
bondTypeCount[b.BondType] += 1;
|
||||
else
|
||||
bondTypeCount[b.BondType] = 1;
|
||||
}
|
||||
Assert.That(bondTypeCount["m"], Is.EqualTo(1));
|
||||
Assert.That(bondTypeCount["s"], Is.EqualTo(2));
|
||||
Assert.That(bondTypeCount["d"], Is.EqualTo(1));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user