public virtual void TestPropagation()
        {
            ChemFile     cf = new ChemFile();
            ChemSequence cs = new ChemSequence();
            ChemModel    cm = new ChemModel();
            IChemObjectSet <IAtomContainer> som = new ChemObjectSet <IAtomContainer>();
            var  mol = new AtomContainer();
            Atom a1  = new Atom("C");
            Atom a2  = new Atom("C");
            Bond b1  = new Bond(a1, a2);

            mol.Atoms.Add(a1);
            mol.Atoms.Add(a2);
            mol.Bonds.Add(b1);
            som.Add(mol);
            cm.MoleculeSet = som;
            cs.Add(cm);
            cf.Add(cs);
            TestListener ts = new TestListener();

            cf.Listeners.Add(ts);
            a2.Symbol = "N";
            Assert.IsInstanceOfType(ts.ChangedObject, typeof(Atom));
            Assert.AreEqual("N", ((Atom)ts.ChangedObject).Symbol);
        }
Esempio n. 2
0
        public virtual void TestChemModel()
        {
            IChemModel chemModel = new ChemModel();

            Assert.IsNotNull(chemModel);
            Assert.IsTrue(chemModel.IsEmpty());

            IAtom atom = new Atom("N");
            IRing mol  = new Ring();  // NCDK does not allow to add AtomContainer to RingSet
            IChemObjectSet <IAtomContainer> mset = new ChemObjectSet <IAtomContainer>();

            mol.Atoms.Add(atom);
            mset.Add(mol);
            chemModel.MoleculeSet = mset;
            Assert.IsFalse(chemModel.IsEmpty());
            mol.Atoms.Remove(atom);
            Assert.IsFalse(chemModel.IsEmpty());
            chemModel.MoleculeSet = null;
            Assert.IsTrue(chemModel.IsEmpty());

            IChemModel model1 = new ChemModel();

            mol.Atoms.Add(atom);
            IReaction react = new Reaction();

            react.Reactants.Add(mol);
            IReactionSet rset = new ReactionSet {
                react
            };

            model1.ReactionSet = rset;
            Assert.IsFalse(model1.IsEmpty());
            mol.Atoms.Remove(atom);
            Assert.IsFalse(model1.IsEmpty());
            model1.ReactionSet = null;
            Assert.IsTrue(model1.IsEmpty());

            IChemModel model2 = new ChemModel();

            mol.Atoms.Add(atom);
            IRingSet ringset = new RingSet();

            ringset.AddRange(mset.Cast <IRing>());  // NCDK does not allow to add AtomContainer to RingSet directly
            model2.RingSet = ringset;
            Assert.IsFalse(model2.IsEmpty());
            mol.Atoms.Remove(atom);
            Assert.IsFalse(model2.IsEmpty());
            model2.RingSet = null;
            Assert.IsTrue(model2.IsEmpty());

            IChemModel model3 = new ChemModel();

            mol.Atoms.Add(atom);
            ICrystal cry = new Crystal(mol);

            model3.Crystal = cry;
            Assert.IsFalse(model3.IsEmpty());
            mol.Atoms.Remove(atom);
            Assert.IsFalse(model3.IsEmpty());
            model3.Crystal = null;
            Assert.IsTrue(model3.IsEmpty());
        }