Beispiel #1
0
        public void TestCalculatePiElectronegativity_IAtomContainer_IAtom()
        {
            PiElectronegativity pe = new PiElectronegativity();

            IAtomContainer molecule = builder.NewAtomContainer();

            molecule.Atoms.Add(builder.NewAtom("F"));
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[0], molecule.Atoms[1], BondOrder.Single);

            AddExplicitHydrogens(molecule);
            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule);
            CDK.LonePairElectronChecker.Saturate(molecule);

            for (int i = 0; i < molecule.Atoms.Count; i++)
            {
                if (i == 0)
                {
                    Assert.AreNotSame(0.0, pe.CalculatePiElectronegativity(molecule, molecule.Atoms[i]));
                }
                else
                {
                    Assert.AreEqual(0.0, pe.CalculatePiElectronegativity(molecule, molecule.Atoms[i]), 0.001);
                }
            }
        }
        public void Contains()
        {
            IChemObjectBuilder builder = ChemObjectBuilder.Instance;

            IAtom c1 = builder.NewAtom("C");
            IAtom c2 = builder.NewAtom("C");
            IAtom o3 = builder.NewAtom("O");
            IAtom o4 = builder.NewAtom("O");

            IBond c1c2 = builder.NewBond(c1, c2, BondOrder.Double);
            IBond c1o3 = builder.NewBond(c1, o3, BondOrder.Single);
            IBond c2o4 = builder.NewBond(c2, o4, BondOrder.Single);

            // new stereo element
            DoubleBondStereochemistry element = new DoubleBondStereochemistry(c1c2, new IBond[] { c1o3, c2o4 },
                                                                              DoubleBondConformation.Opposite);

            Assert.IsTrue(element.Contains(c1));
            Assert.IsTrue(element.Contains(c2));
            Assert.IsTrue(element.Contains(o3));
            Assert.IsTrue(element.Contains(o4));

            Assert.IsFalse(element.Contains(builder.NewAtom()));
            Assert.IsFalse(element.Contains(null));
        }
Beispiel #3
0
        public virtual void TestReSetFlags_IAtomContainer()
        {
            IAtomContainer atomContainer = builder.NewAtomContainer();
            IAtom          atom1         = builder.NewAtom("C");

            atom1.IsVisited = true;
            IAtom atom2 = builder.NewAtom("C");

            atom2.IsVisited = true;
            IBond bond1 = builder.NewBond(atom1, atom2, BondOrder.Single);

            atomContainer.Atoms.Add(atom1);
            atomContainer.Atoms.Add(atom2);
            atomContainer.Bonds.Add(bond1);

            PathTools.ResetFlags(atomContainer);

            // now assume that no VISITED is set
            IEnumerator <IAtom> atoms = atomContainer.Atoms.GetEnumerator();

            while (atoms.MoveNext())
            {
                Assert.IsFalse(atoms.Current.IsVisited);
            }
            IEnumerator <IBond> bonds = atomContainer.Bonds.GetEnumerator();

            while (bonds.MoveNext())
            {
                Assert.IsFalse(bonds.Current.IsVisited);
            }
        }
        public virtual void TestSort_BrokenComparator()
        {
            IChemObjectSet <T> set = (IChemObjectSet <T>)NewChemObject();

            IChemObjectBuilder builder = set.Builder;

            T a = NewContainerObject();
            T b = NewContainerObject();

            a.Atoms.Add(builder.NewAtom("C"));
            a.Atoms.Add(builder.NewAtom("C"));
            b.Atoms.Add(builder.NewAtom("C"));

            set.Add(a);
            set.Add(b);

            // this comparator is deliberately broken but serves for the test
            //  - null should be a high value (Interger.MAX)
            //  - also, avoid boxed primitives in comparators
            set.Sort(new ComparerByBroken());

            // despite null being low, the two atom containers should
            // still be in the first slot
            Assert.IsNotNull(set[0]);
            Assert.IsNotNull(set[1]);
            Assert.IsTrue(set.Count == 2 || set[2] == null);
        }
        public virtual void TestSort_Coefficients()
        {
            IChemObjectSet <T> set = (IChemObjectSet <T>)NewChemObject();

            IChemObjectBuilder builder = set.Builder;

            T a = NewContainerObject();
            T b = NewContainerObject();

            a.Atoms.Add(builder.NewAtom("C"));
            a.Atoms.Add(builder.NewAtom("C"));

            b.Atoms.Add(builder.NewAtom("C"));

            set.Add(a, 1);
            set.Add(b, 2);

            Assert.AreEqual(a, set[0]);
            Assert.AreEqual(1D, set.GetMultiplier(0));
            Assert.AreEqual(b, set[1]);
            Assert.AreEqual(2D, set.GetMultiplier(1));

            // sort by atom container count
            var orderedSet = set.OrderBy(n => n, new ComparerByCoefficients());

            AssertAreOrderLessEqual(
                new[] { a, b }.Cast <IChemObject>(),
                set.Cast <IChemObject>());
            Assert.IsTrue(Compares.AreDeepEqual(
                              new[] { 1D, 2D },
                              new[] { set.GetMultiplier(0), set.GetMultiplier(1) }));
        }
        public void TestCalculateNumberOfImplicitHydrogens()
        {
            IChemObjectBuilder builder = ChemObjectBuilder.Instance;

            IAtomContainer proton = builder.NewAtomContainer();
            IAtom          hplus  = builder.NewAtom("H");

            hplus.FormalCharge = 1;
            proton.Atoms.Add(hplus);
            Assert.AreEqual(0, satcheck.CalculateNumberOfImplicitHydrogens(hplus, proton));

            IAtomContainer hydrogenRadical = builder.NewAtomContainer();
            IAtom          hradical        = builder.NewAtom("H");

            hydrogenRadical.Atoms.Add(hradical);
            hydrogenRadical.SingleElectrons.Add(builder.NewSingleElectron(hradical));
            Assert.AreEqual(0, satcheck.CalculateNumberOfImplicitHydrogens(hradical, hydrogenRadical));

            IAtomContainer hydrogen = builder.NewAtomContainer();
            IAtom          h        = builder.NewAtom("H");

            hydrogen.Atoms.Add(h);
            Assert.AreEqual(1, satcheck.CalculateNumberOfImplicitHydrogens(h, hydrogen));

            IAtomContainer coRad = builder.NewAtomContainer();
            IAtom          c     = builder.NewAtom("C");
            IAtom          o     = builder.NewAtom("O");
            IBond          bond  = builder.NewBond(c, o, BondOrder.Double);

            coRad.Atoms.Add(c);
            coRad.Atoms.Add(o);
            coRad.Bonds.Add(bond);
            coRad.SingleElectrons.Add(builder.NewSingleElectron(c));
            Assert.AreEqual(1, satcheck.CalculateNumberOfImplicitHydrogens(c, coRad));
        }
Beispiel #7
0
        public void TestWriting()
        {
            StringWriter writer   = new StringWriter();
            var          molecule = builder.NewAtomContainer();
            IAtom        atom1    = builder.NewAtom("C");

            atom1.Point3D = new Vector3(1.0, 2.0, 3.0);
            IAtom atom2 = builder.NewAtom("C");

            atom2.Point3D = new Vector3(1.0, 2.0, 3.0);
            molecule.Atoms.Add(atom1);
            molecule.Atoms.Add(atom2);

            XYZWriter xyzWriter = new XYZWriter(writer);

            xyzWriter.Write(molecule);
            xyzWriter.Close();
            writer.Close();

            string output = writer.ToString();
            //        Debug.WriteLine(output);
            // count lines
            int lineCount = 0;
            var reader    = new StringReader(output);

            while (reader.ReadLine() != null)
            {
                lineCount++;
            }
            Assert.AreEqual(4, lineCount);
        }
Beispiel #8
0
        public void TestCalculatePositive_IAtomContainer_IAtom()
        {
            IAtomContainer molecule = builder.NewAtomContainer();

            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[0], molecule.Atoms[1], BondOrder.Single);
            molecule.Atoms[1].FormalCharge = +1;
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[1], molecule.Atoms[2], BondOrder.Single);
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[2], molecule.Atoms[3], BondOrder.Double);

            AddExplicitHydrogens(molecule);
            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule);
            CDK.LonePairElectronChecker.Saturate(molecule);

            for (int i = 0; i < molecule.Atoms.Count; i++)
            {
                if (i == 1)
                {
                    Assert.AreNotSame(0.0, StabilizationCharges.CalculatePositive(molecule, molecule.Atoms[i]));
                }
                else
                {
                    Assert.AreEqual(0.0, StabilizationCharges.CalculatePositive(molecule, molecule.Atoms[i]), 0.001);
                }
            }
        }
Beispiel #9
0
        public void TestRebond_IAtomContainer()
        {
            var rebonder = new RebondTool(2.0, 0.5, 0.5);
            var methane  = builder.NewAtomContainer();

            methane.Atoms.Add(builder.NewAtom("C", new Vector3(0.0, 0.0, 0.0)));
            methane.Atoms.Add(builder.NewAtom("H", new Vector3(0.6, 0.6, 0.6)));
            methane.Atoms.Add(builder.NewAtom("H", new Vector3(-0.6, -0.6, 0.6)));
            methane.Atoms.Add(builder.NewAtom("H", new Vector3(0.6, -0.6, -0.6)));
            methane.Atoms.Add(builder.NewAtom("H", new Vector3(-0.6, 0.6, -0.6)));

            // configure atoms
            var factory = AtomTypeFactory.GetInstance("NCDK.Config.Data.jmol_atomtypes.txt");

            //IAtom[] atoms = methane.GetAtoms();
            for (int i = 0; i < methane.Atoms.Count; i++)
            {
                factory.Configure(methane.Atoms[i]);
            }
            // rebond
            rebonder.Rebond(methane);

            Assert.AreEqual(5, methane.Atoms.Count);
            Assert.AreEqual(4, methane.Bonds.Count);
        }
        /// <summary>
        /// get the molecule 1: [C+]-O-H
        /// </summary>
        private IChemObjectSet <IAtomContainer> GetExampleReactants()
        {
            var setOfReactants = CDK.Builder.NewAtomContainerSet();

            var molecule = builder.NewAtomContainer();

            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.Atoms[0].FormalCharge = 1;
            molecule.Atoms.Add(builder.NewAtom("O"));
            molecule.AddBond(molecule.Atoms[0], molecule.Atoms[1], BondOrder.Single);

            try
            {
                AddExplicitHydrogens(molecule);
                AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule);

                CDK.LonePairElectronChecker.Saturate(molecule);
            }
            catch (Exception e)
            {
                Console.Out.WriteLine(e.StackTrace);
            }
            setOfReactants.Add(molecule);
            return(setOfReactants);
        }
Beispiel #11
0
        public void TestNewBond_arrayIAtom()
        {
            IChemObjectBuilder builder = RootObject.Builder;
            IBond bond = builder.NewBond(new IAtom[] { builder.NewAtom(), builder.NewAtom() });

            Assert.IsNotNull(bond);
        }
Beispiel #12
0
 public void SetUp()
 {
     molecule1  = builder.NewAtomContainer();
     atomInMol1 = builder.NewAtom("Cl");
     molecule1.Atoms.Add(atomInMol1);
     molecule1.Atoms.Add(builder.NewAtom("Cl"));
     bondInMol1 = builder.NewBond(atomInMol1, molecule1.Atoms[1]);
     molecule1.Bonds.Add(bondInMol1);
     molecule2  = builder.NewAtomContainer();
     atomInMol2 = builder.NewAtom("O");
     atomInMol2.ImplicitHydrogenCount = 2;
     molecule2.Atoms.Add(atomInMol2);
     moleculeSet = builder.NewChemObjectSet <IAtomContainer>();
     moleculeSet.Add(molecule1);
     moleculeSet.Add(molecule2);
     reaction = builder.NewReaction();
     reaction.Reactants.Add(molecule1);
     reaction.Products.Add(molecule2);
     reactionSet = builder.NewReactionSet();
     reactionSet.Add(reaction);
     chemModel             = builder.NewChemModel();
     chemModel.MoleculeSet = moleculeSet;
     chemModel.ReactionSet = reactionSet;
     chemSequence1         = builder.NewChemSequence();
     chemSequence1.Add(chemModel);
     chemSequence2 = builder.NewChemSequence();
     chemFile      = builder.NewChemFile();
     chemFile.Add(chemSequence1);
     chemFile.Add(chemSequence2);
 }
Beispiel #13
0
 public SpanningTreeTest()
 {
     if (azulene == null)
     {
         // load azulene
         var            filename        = "NCDK.Data.MDL.azulene.mol";
         var            ins             = ResourceLoader.GetAsStream(filename);
         var            reader          = new MDLV2000Reader(ins, ChemObjectReaderMode.Strict);
         var            chemFile        = reader.Read(builder.NewChemFile());
         var            seq             = chemFile[0];
         var            model           = seq[0];
         IAtomContainer azuleneMolecule = model.MoleculeSet[0];
         Assert.AreEqual(10, azuleneMolecule.Atoms.Count);
         Assert.AreEqual(11, azuleneMolecule.Bonds.Count);
         azulene = new SpanningTree(azuleneMolecule);
     }
     if (ethane == null)
     {
         // create ethane
         IAtomContainer ethaneMolecule = builder.NewAtomContainer();
         ethaneMolecule.Atoms.Add(builder.NewAtom("C"));
         ethaneMolecule.Atoms.Add(builder.NewAtom("C"));
         ethaneMolecule.AddBond(ethaneMolecule.Atoms[0], ethaneMolecule.Atoms[1], BondOrder.Single);
         ethane = new SpanningTree(ethaneMolecule);
     }
 }
Beispiel #14
0
        public void TestConfigureIAtom()
        {
            var isofac = BODRIsotopeFactory.Instance;
            var atom   = builder.NewAtom("H");

            isofac.Configure(atom);
            Assert.AreEqual(1, atom.AtomicNumber);
        }
Beispiel #15
0
        public void TestNewBond_IAtom_IAtom_BondOrder_IBond_Stereo()
        {
            IChemObjectBuilder builder = RootObject.Builder;
            IBond bond = builder.NewBond(builder.NewAtom(),
                                         builder.NewAtom(), BondOrder.Single, BondStereo.EOrZ);

            Assert.IsNotNull(bond);
        }
Beispiel #16
0
        public void TestNewBond_IAtom_IAtom()
        {
            IChemObjectBuilder builder = RootObject.Builder;
            IBond bond = builder.NewBond(builder.NewAtom(),
                                         builder.NewAtom());

            Assert.IsNotNull(bond);
        }
 public static void AddHydrogens(IAtomContainer mol, int carbonIndex, int count)
 {
     for (int i = 0; i < count; i++)
     {
         mol.Atoms.Add(builder.NewAtom("H"));
         int hydrogenIndex = mol.Atoms.Count - 1;
         mol.AddBond(mol.Atoms[carbonIndex], mol.Atoms[hydrogenIndex], BondOrder.Single);
     }
 }
Beispiel #18
0
 public MoleculeSignatureTest()
 {
     this.parser  = CDK.SmilesParser;
     this.builder = ChemObjectBuilder.Instance;
     mol          = builder.NewAtomContainer();
     mol.Atoms.Add(builder.NewAtom("C"));
     mol.Atoms.Add(builder.NewAtom("C"));
     mol.AddBond(mol.Atoms[0], mol.Atoms[1], BondOrder.Single);
     molSig = new MoleculeSignature(mol);
 }
        public void TestMap_Map_Map()
        {
            IChemObjectBuilder builder = ChemObjectBuilder.Instance;

            IAtom c1 = builder.NewAtom("C");
            IAtom o2 = builder.NewAtom("O");
            IAtom n3 = builder.NewAtom("N");
            IAtom c4 = builder.NewAtom("C");
            IAtom h5 = builder.NewAtom("H");

            // new stereo element
            ITetrahedralChirality original = new TetrahedralChirality(c1, new IAtom[] { o2, n3, c4, h5 }, TetrahedralStereo.Clockwise);

            // clone the atoms and place in a map
            var   mapping = new CDKObjectMap();
            IAtom c1clone = (IAtom)c1.Clone();

            mapping.Set(c1, c1clone);
            IAtom o2clone = (IAtom)o2.Clone();

            mapping.Set(o2, o2clone);
            IAtom n3clone = (IAtom)n3.Clone();

            mapping.Set(n3, n3clone);
            IAtom c4clone = (IAtom)c4.Clone();

            mapping.Set(c4, c4clone);
            IAtom h5clone = (IAtom)h5.Clone();

            mapping.Set(h5, h5clone);

            // map the existing element a new element
            ITetrahedralChirality mapped = (ITetrahedralChirality)original.Clone(mapping);

            Assert.AreNotSame(original.ChiralAtom, mapped.ChiralAtom, "mapped chiral atom was the same as the original");
            Assert.AreSame(c1clone, mapped.ChiralAtom, "mapped chiral atom was not the clone");

            var originalLigands = original.Ligands;
            var mappedLigands   = mapped.Ligands;

            Assert.AreNotSame(originalLigands[0], mappedLigands[0], "first ligand was the same as the original");
            Assert.AreSame(o2clone, mappedLigands[0], "first mapped ligand was not the clone");
            Assert.AreNotSame(originalLigands[1], mappedLigands[1], "second ligand was the same as the original");
            Assert.AreSame(n3clone, mappedLigands[1], "second mapped ligand was not the clone");
            Assert.AreNotSame(originalLigands[2], mappedLigands[2], "third ligand was the same as the original");
            Assert.AreSame(c4clone, mappedLigands[2], "third mapped ligand was not the clone");
            Assert.AreNotSame(originalLigands[3], mappedLigands[3], "forth ligand was te same as the original");
            Assert.AreSame(h5clone, mappedLigands[3], "forth mapped ligand was not the clone");

            Assert.AreEqual(original.Stereo, mapped.Stereo, "stereo was not mapped");
        }
Beispiel #20
0
        public static IAtomContainer GetIsobutane(IChemObjectBuilder builder)
        {
            IAtomContainer mol = builder.NewAtomContainer();

            mol.Atoms.Add(builder.NewAtom("C"));
            mol.Atoms.Add(builder.NewAtom("C"));
            mol.Atoms.Add(builder.NewAtom("C"));
            mol.Atoms.Add(builder.NewAtom("C"));

            mol.AddBond(mol.Atoms[0], mol.Atoms[1], BondOrder.Single);
            mol.AddBond(mol.Atoms[0], mol.Atoms[2], BondOrder.Single);
            mol.AddBond(mol.Atoms[0], mol.Atoms[3], BondOrder.Single);
            return(mol);
        }
        /// <summary>
        /// Get the molecule 1: [C+]-C=C-C
        /// </summary>
        private IChemObjectSet <IAtomContainer> GetExampleReactants()
        {
            var setOfReactants = CDK.Builder.NewAtomContainerSet();

            var molecule = builder.NewAtomContainer();

            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.Atoms[0].FormalCharge = 1;
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[0], molecule.Atoms[1], BondOrder.Single);
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[1], molecule.Atoms[2], BondOrder.Double);
            molecule.Atoms.Add(builder.NewAtom("C"));
            molecule.AddBond(molecule.Atoms[2], molecule.Atoms[3], BondOrder.Single);
            try
            {
                AddExplicitHydrogens(molecule);
            }
            catch (Exception e)
            {
                Console.Out.WriteLine(e.StackTrace);
            }

            setOfReactants.Add(molecule);
            return(setOfReactants);
        }
Beispiel #22
0
        public IAtomContainer MakeSquare()
        {
            IAtomContainer square = builder.NewAtomContainer();

            square.Atoms.Add(builder.NewAtom("C"));
            square.Atoms.Add(builder.NewAtom("C"));
            square.Atoms.Add(builder.NewAtom("C"));
            square.Atoms.Add(builder.NewAtom("C"));
            square.AddBond(square.Atoms[0], square.Atoms[1], BondOrder.Single);
            square.AddBond(square.Atoms[0], square.Atoms[3], BondOrder.Single);
            square.AddBond(square.Atoms[1], square.Atoms[2], BondOrder.Single);
            square.AddBond(square.Atoms[2], square.Atoms[3], BondOrder.Single);

            return(Layout(square));
        }
Beispiel #23
0
        public virtual void TestIsDisconnected()
        {
            Assert.IsFalse(azulene.IsDisconnected);

            IChemObjectBuilder builder = azulene.GetSpanningTree().Builder;
            IAtomContainer     disconnectedStructure = builder.NewAtomContainer();

            disconnectedStructure.Atoms.Add(builder.NewAtom("Na"));
            disconnectedStructure.Atoms[0].FormalCharge = +1;
            disconnectedStructure.Atoms.Add(builder.NewAtom("Cl"));
            disconnectedStructure.Atoms[1].FormalCharge = -1;
            SpanningTree stree = new SpanningTree(disconnectedStructure);

            Assert.IsTrue(stree.IsDisconnected);
        }
Beispiel #24
0
        public void TestNewLonePair_IAtom()
        {
            IChemObjectBuilder builder  = RootObject.Builder;
            ILonePair          lonePair = builder.NewLonePair(builder.NewAtom());

            Assert.IsNotNull(lonePair);
        }
Beispiel #25
0
        public void TestNewPseudoAtom_IAtom()
        {
            IChemObjectBuilder builder = RootObject.Builder;
            IPseudoAtom        atom    = builder.NewPseudoAtom(builder.NewAtom());

            Assert.IsNotNull(atom);
        }
Beispiel #26
0
        public void TestNewSingleElectron_IAtom()
        {
            IChemObjectBuilder builder  = RootObject.Builder;
            ISingleElectron    electron = builder.NewSingleElectron(builder.NewAtom());

            Assert.IsNotNull(electron);
        }
Beispiel #27
0
        public void TestGetAtomCount_IRingSet()
        {
            IRingSet rs  = builder.NewRingSet();
            IRing    ac1 = builder.NewRing();

            ac1.Atoms.Add(builder.NewAtom("O"));
            rs.Add(ac1);
            IRing ac2 = builder.NewRing();

            ac2.Atoms.Add(builder.NewAtom("C"));
            ac2.Atoms.Add(builder.NewAtom("C"));
            ac2.AddBond(ac2.Atoms[0], ac2.Atoms[1], BondOrder.Double);
            rs.Add(ac2);
            Assert.AreEqual(3, RingSetManipulator.GetAtomCount(rs));
            Assert.AreEqual(1, RingSetManipulator.GetBondCount(rs));
        }
        public void TestMap_Null_Map()
        {
            IChemObjectBuilder builder = ChemObjectBuilder.Instance;

            IAtom c1 = builder.NewAtom("C");
            IAtom o2 = builder.NewAtom("O");
            IAtom n3 = builder.NewAtom("N");
            IAtom c4 = builder.NewAtom("C");
            IAtom h5 = builder.NewAtom("H");

            // new stereo element
            ITetrahedralChirality original = new TetrahedralChirality(c1, new IAtom[] { o2, n3, c4, h5 }, TetrahedralStereo.Clockwise);

            // map the existing element a new element
            ITetrahedralChirality mapped = (ITetrahedralChirality)original.Clone(null);
        }
Beispiel #29
0
        public void TestCompare_NullHybridization()
        {
            SimpleAtomComparator comparator = new SimpleAtomComparator();

            IAtom a1 = builder.NewAtom("C");
            IAtom a2 = builder.NewAtom("C");

            Assert.AreEqual(0, comparator.Compare(a1, a2), "Null hybridzation should be equals");
        }
Beispiel #30
0
        static IAtom Atom(string symbol, int h, bool arom)
        {
            IAtom a = builder.NewAtom(symbol);

            a.ImplicitHydrogenCount = h;
            a.IsAromatic            = arom;
            return(a);
        }