public void TotalBondEnergy_WhenThereAreBondRings_ReturnsTheSumOfAllBonds() { // Arrange var molecule = new AtomContainer(); // Bonds: 5 carbon ring, each with an H bonded by C-H molecule.addAtom(new Atom(new Element("C"))); molecule.addAtom(new Atom(new Element("C"))); molecule.addAtom(new Atom(new Element("C"))); molecule.addAtom(new Atom(new Element("C"))); molecule.addAtom(new Atom(new Element("C"))); molecule.addAtom(new Atom(new Element("H"))); molecule.addAtom(new Atom(new Element("H"))); molecule.addAtom(new Atom(new Element("H"))); molecule.addAtom(new Atom(new Element("H"))); molecule.addAtom(new Atom(new Element("H"))); // Ring molecule.addBond(0, 1, IBond.Order.SINGLE); molecule.addBond(1, 2, IBond.Order.SINGLE); molecule.addBond(2, 3, IBond.Order.SINGLE); molecule.addBond(3, 4, IBond.Order.SINGLE); molecule.addBond(4, 0, IBond.Order.SINGLE); // C-H bonds molecule.addBond(0, 5, IBond.Order.SINGLE); molecule.addBond(1, 6, IBond.Order.SINGLE); molecule.addBond(2, 7, IBond.Order.SINGLE); molecule.addBond(3, 8, IBond.Order.SINGLE); molecule.addBond(4, 9, IBond.Order.SINGLE); var calculator = new BondEnergyCalculator(molecule); // Act var bondEnergy = calculator.TotalBondEnergy(); // Assert Assert.That(bondEnergy, Is.EqualTo(5 * 348 + 5 * 412)); }
public void TotalBondEnergy_WhenThereAreBonds_ReturnsSumOfTheBondEnergies() { // Arrange var molecule = new AtomContainer(); // Bonds: C=C, C-H, C~N molecule.addAtom(new Atom(new Element("C"))); molecule.addAtom(new Atom(new Element("C"))); molecule.addAtom(new Atom(new Element("H"))); molecule.addAtom(new Atom(new Element("N"))); molecule.addBond(0, 1, IBond.Order.DOUBLE); molecule.addBond(1, 2, IBond.Order.SINGLE); molecule.addBond(1, 3, IBond.Order.TRIPLE); var calculator = new BondEnergyCalculator(molecule); // Act var bondEnergy = calculator.TotalBondEnergy(); // Assert Assert.That(bondEnergy, Is.EqualTo(612 + 412 + 890)); }
public void TotalBondEnergy_WhenThereAreUnknownBonds_ReplacesUnknownsWithC_CBond() { // Arrange var molecule = new AtomContainer(); // Bonds: C=C, C-H, C~N, N~X (Unknown) molecule.addAtom(new Atom(new Element("C"))); molecule.addAtom(new Atom(new Element("C"))); molecule.addAtom(new Atom(new Element("H"))); molecule.addAtom(new Atom(new Element("N"))); molecule.addAtom(new Atom(new Element("X"))); molecule.addBond(0, 1, IBond.Order.DOUBLE); molecule.addBond(1, 2, IBond.Order.SINGLE); molecule.addBond(1, 3, IBond.Order.TRIPLE); molecule.addBond(3, 4, IBond.Order.TRIPLE); var calculator = new BondEnergyCalculator(molecule); // Act var bondEnergy = calculator.TotalBondEnergy(); // Assert Assert.That(bondEnergy, Is.EqualTo(612 + 412 + 890 + 348)); }
private IAtomContainer makeAtomContainer(IAtom atom, List<IBond> parts) { IAtomContainer partContainer = new AtomContainer(); partContainer.addAtom(atom); foreach (var aBond in parts) { foreach (var bondedAtom in aBond.atoms().ToWindowsEnumerable<IAtom>()) { if (!partContainer.contains(bondedAtom)) { partContainer.addAtom(bondedAtom); } } partContainer.addBond(aBond); } return partContainer; }