static InductivePartialChargesTest()
        {
            mol = builder.NewAtomContainer();
            IAtom atom1 = builder.NewAtom("C");
            IAtom atom2 = builder.NewAtom("Cl");
            IAtom atom3 = builder.NewAtom("Br");
            IAtom atom4 = builder.NewAtom("H");
            IAtom atom5 = builder.NewAtom("O");

            atom5.Point3D = new Vector3(2.24, 1.33, 0.0);
            atom1.Point3D = new Vector3(1.80, 0.0, 0.0);
            atom2.Point3D = new Vector3(0.0, 0.0, 0.0);
            atom3.Point3D = new Vector3(2.60, -0.79, 1.59);
            atom4.Point3D = new Vector3(2.15, -0.60, -0.87);

            IBond bond1 = builder.NewBond(atom1, atom2, BondOrder.Single);
            IBond bond2 = builder.NewBond(atom1, atom3, BondOrder.Single);
            IBond bond3 = builder.NewBond(atom1, atom4, BondOrder.Single);
            IBond bond4 = builder.NewBond(atom1, atom5, BondOrder.Single);

            mol.Atoms.Add(atom1);
            mol.Atoms.Add(atom2);
            mol.Atoms.Add(atom3);
            mol.Atoms.Add(atom4);
            mol.Atoms.Add(atom5);

            mol.Bonds.Add(bond1);
            mol.Bonds.Add(bond2);
            mol.Bonds.Add(bond3);
            mol.Bonds.Add(bond4);
        }
        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));
        }
Пример #3
0
        public void TestGetLength2DIBond()
        {
            var o    = builder.NewAtom("O", new Vector2(0.0, 0.0));
            var c    = builder.NewAtom("C", new Vector2(1.0, 0.0));
            var bond = builder.NewBond(c, o);

            Assert.AreEqual(1.0, GeometryUtil.GetLength2D(bond), 0.001);
        }
        public void TestConstructor_TooManyBonds()
        {
            IChemObjectBuilder builder = ChemObjectBuilder.Instance;
            IBond b1 = builder.NewBond();
            IBond b2 = builder.NewBond();
            IBond b3 = builder.NewBond();

            new DoubleBondStereochemistry(builder.NewBond(), new IBond[] { b1, b2, b3 }, DoubleBondConformation.Opposite);
        }
Пример #5
0
 public void AddHydrogens(IAtomContainer mol, IAtom atom, int n)
 {
     for (int i = 0; i < n; i++)
     {
         IAtom h = builder.NewAtom("H");
         mol.Atoms.Add(h);
         mol.Bonds.Add(builder.NewBond(atom, h));
     }
 }
        public void TestUITSymmetricMatch()
        {
            var q = new QueryAtomContainer();

            if (!Smarts.Parse(q, "C**C"))
            {
                Assert.Fail(Smarts.GetLastErrorMessage());
            }

            //Creating 'SCCS' target molecule
            var target = builder.NewAtomContainer();
            //atoms
            var ta0 = builder.NewAtom("S");

            target.Atoms.Add(ta0);
            var ta1 = builder.NewAtom("C");

            target.Atoms.Add(ta1);
            var ta2 = builder.NewAtom("C");

            target.Atoms.Add(ta2);
            var ta3 = builder.NewAtom("S");

            target.Atoms.Add(ta3);
            //bonds
            var tb0 = builder.NewBond();

            tb0.SetAtoms(new IAtom[] { ta0, ta1 });
            tb0.Order = BondOrder.Single;
            target.Bonds.Add(tb0);

            var tb1 = builder.NewBond();

            tb1.SetAtoms(new IAtom[] { ta1, ta2 });
            tb1.Order = BondOrder.Single;
            target.Bonds.Add(tb1);

            var tb2 = builder.NewBond();

            tb2.SetAtoms(new IAtom[] { ta2, ta3 });
            tb2.Order = BondOrder.Single;
            target.Bonds.Add(tb2);

            //Isomorphism check
            var res = uiTester.IsSubgraph(target, q);

            Assert.IsFalse(res, "C**C should not match SCCS");
        }
Пример #7
0
        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));
        }
Пример #8
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);
            }
        }
Пример #9
0
        public void TestNewBond_arrayIAtom()
        {
            IChemObjectBuilder builder = RootObject.Builder;
            IBond bond = builder.NewBond(new IAtom[] { builder.NewAtom(), builder.NewAtom() });

            Assert.IsNotNull(bond);
        }
Пример #10
0
        public void TestNewBond()
        {
            IChemObjectBuilder builder = RootObject.Builder;
            IBond bond = builder.NewBond();

            Assert.IsNotNull(bond);
        }
Пример #11
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);
 }
Пример #12
0
        /// <inheritdoc/>
        public override void MakeEdge(int vertexIndex1, int vertexIndex2, string vertexSymbol1, string vertexSymbol2, string edgeLabel)
        {
            switch (edgeLabel)
            {
            case "":
                container.AddBond(container.Atoms[vertexIndex1], container.Atoms[vertexIndex2], BondOrder.Single);
                break;

            case "=":
                container.AddBond(container.Atoms[vertexIndex1], container.Atoms[vertexIndex2], BondOrder.Double);
                break;

            case "#":
                container.AddBond(container.Atoms[vertexIndex1], container.Atoms[vertexIndex2], BondOrder.Triple);
                break;

            case "p":
                IBond bond = builder.NewBond(container.Atoms[vertexIndex1], container.Atoms[vertexIndex2], BondOrder.Single);
                bond.IsAromatic = true;
                container.Bonds.Add(bond);
                break;

            default:
                break;
            }
        }
Пример #13
0
        static IBond Bond(IAtomContainer m, int v, int w, BondOrder ord, bool arom)
        {
            IBond b = builder.NewBond(m.Atoms[v], m.Atoms[w]);

            b.Order      = ord;
            b.IsAromatic = arom;
            return(b);
        }
Пример #14
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);
        }
Пример #15
0
        public void TestSulfite()
        {
            var mol = builder.NewAtomContainer();
            var s   = builder.NewAtom("S");
            var o1  = builder.NewAtom("O");
            var o2  = builder.NewAtom("O");
            var o3  = builder.NewAtom("O");

            mol.Atoms.Add(s);
            mol.Atoms.Add(o1);
            mol.Atoms.Add(o2);
            mol.Atoms.Add(o3);
            var b1 = builder.NewBond(s, o1, BondOrder.Single);
            var b2 = builder.NewBond(s, o2, BondOrder.Single);
            var b3 = builder.NewBond(s, o3, BondOrder.Double);

            mol.Bonds.Add(b1);
            mol.Bonds.Add(b2);
            mol.Bonds.Add(b3);
            var type = matcher.FindMatchingAtomType(mol, s);

            Assert.IsNotNull(type);
            AtomTypeManipulator.Configure(s, type);
            type = matcher.FindMatchingAtomType(mol, o1);
            Assert.IsNotNull(type);
            AtomTypeManipulator.Configure(o1, type);
            type = matcher.FindMatchingAtomType(mol, o2);
            Assert.IsNotNull(type);
            AtomTypeManipulator.Configure(o2, type);
            type = matcher.FindMatchingAtomType(mol, o3);
            Assert.IsNotNull(type);
            AtomTypeManipulator.Configure(o3, type);

            adder.AddImplicitHydrogens(mol);

            Assert.AreEqual(4, mol.Atoms.Count);
            Assert.AreEqual(3, mol.Bonds.Count);
            Assert.IsNotNull(s.ImplicitHydrogenCount);
            Assert.AreEqual(0, s.ImplicitHydrogenCount.Value);
            Assert.IsNotNull(o1.ImplicitHydrogenCount);
            Assert.AreEqual(1, o1.ImplicitHydrogenCount.Value);
            Assert.IsNotNull(o2.ImplicitHydrogenCount);
            Assert.AreEqual(1, o2.ImplicitHydrogenCount.Value);
            Assert.IsNotNull(o3.ImplicitHydrogenCount);
            Assert.AreEqual(0, o3.ImplicitHydrogenCount.Value);
        }
 public void SetUp()
 {
     mol1                             = builder.NewAtomContainer();
     atomInMol1                       = builder.NewAtom("Cl");
     atomInMol1.Charge                = -1.0;
     atomInMol1.FormalCharge          = -1;
     atomInMol1.ImplicitHydrogenCount = 1;
     mol1.Atoms.Add(atomInMol1);
     mol1.Atoms.Add(builder.NewAtom("Cl"));
     bondInMol1 = builder.NewBond(atomInMol1, mol1.Atoms[1]);
     mol1.Bonds.Add(bondInMol1);
     mol2       = builder.NewAtomContainer();
     atomInMol2 = builder.NewAtom("O");
     atomInMol2.ImplicitHydrogenCount = 2;
     mol2.Atoms.Add(atomInMol2);
     som.Add(mol1);
     som.Add(mol2);
 }
Пример #17
0
        public void TestDeltaVSulphurSO()
        {
            var s = builder.NewAtom("S");
            var o = builder.NewAtom("O");
            var b = builder.NewBond(s, o);

            b.Order = BondOrder.Double;

            var m = builder.NewAtomContainer();

            m.Atoms.Add(s);
            m.Atoms.Add(o);
            m.Bonds.Add(b);

            var deltav = ChiIndexUtils.DeltavSulphur(s, m);

            Assert.AreEqual(1.33, deltav, 0.01);
        }
Пример #18
0
        /// <summary>
        /// Converts a <see cref="IGraph"/> into an <see cref="IAtomContainer"/> using the given <see cref="IChemObjectBuilder"/>.
        /// </summary>
        /// <param name="builder"><see cref="IChemObjectBuilder"/> used to create new <see cref="IChemObject"/>s.</param>
        /// <returns>a <see cref="IAtomContainer"/> deserialized from the RDF graph.</returns>
        public IAtomContainer Model2Molecule(IChemObjectBuilder builder)
        {
            var            mols = g.GetTriplesWithPredicateObject(P_TYPE, R_MOLECULE);
            IAtomContainer mol  = null;

            foreach (var rdfMol in mols.Select(n => n.Subject))
            {
                mol = builder.NewAtomContainer();
                var rdfToCDKAtomMap = new Dictionary <INode, IAtom>();
                var atoms           = g.GetTriplesWithSubjectPredicate(rdfMol, P_HASATOM).Select(n => n.Object);
                foreach (var rdfAtom in atoms)
                {
                    IAtom atom = null;
                    if (g.GetTriplesWithSubjectPredicate(rdfAtom, P_TYPE).Where(n => n.Object.Equals(R_PSEUDOATOM)).Any())
                    {
                        atom = builder.NewPseudoAtom();
                        atom.StereoParity = 0;
                        var label = g.GetTriplesWithSubjectPredicate(rdfAtom, P_HASLABEL).Select(n => n.Object).FirstOrDefault();
                        if (label != null)
                        {
                            ((IPseudoAtom)atom).Label = label.ToString();
                        }
                    }
                    else
                    {
                        atom = builder.NewAtom();
                    }
                    var symbol = g.GetTriplesWithSubjectPredicate(rdfAtom, P_SYMBOL).Select(n => n.Object).FirstOrDefault();
                    if (symbol != null)
                    {
                        atom.Symbol = symbol.ToString();
                    }
                    rdfToCDKAtomMap[rdfAtom] = atom;
                    DeserializeAtomTypeFields(rdfAtom, atom);
                    mol.Atoms.Add(atom);
                }
                var bonds = g.GetTriplesWithSubjectPredicate(rdfMol, P_HASBOND).Select(n => n.Object);
                foreach (var rdfBond in bonds)
                {
                    var bondAtoms = g.GetTriplesWithSubjectPredicate(rdfBond, P_BINDSATOM).Select(n => n.Object);
                    var atomList  = new List <IAtom>();
                    foreach (var rdfAtom in bondAtoms)
                    {
                        IAtom atom = rdfToCDKAtomMap[rdfAtom];
                        atomList.Add(atom);
                    }
                    IBond bond  = builder.NewBond(atomList);
                    var   order = g.GetTriplesWithSubjectPredicate(rdfBond, P_HASORDER).Select(n => n.Object).FirstOrDefault();
                    bond.Order = Resource2Order(order);
                    mol.Bonds.Add(bond);
                    DeserializeElectronContainerFields(rdfBond, bond);
                }
            }
            return(mol);
        }
Пример #19
0
        public void NullBondOrder()
        {
            var mol = builder.NewAtomContainer();

            mol.Atoms.Add(builder.NewAtom("H"));
            mol.Atoms.Add(builder.NewAtom("C"));
            mol.Bonds.Add(builder.NewBond(mol.Atoms[0], mol.Atoms[1], BondOrder.Unset));
            mol.Atoms[0].ImplicitHydrogenCount = 0;
            mol.Atoms[0].MassNumber            = 2;
            mol.Atoms[1].ImplicitHydrogenCount = 3;
            WriteToStr(mol);
        }
        public void TestMap_Map_Map_EmptyMapping()
        {
            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
            IDoubleBondStereochemistry original = new DoubleBondStereochemistry(c1c2, new IBond[] { c1o3, c2o4 },
                                                                                DoubleBondConformation.Opposite);

            // map the existing element a new element - should through an ArgumentException
            IDoubleBondStereochemistry mapped = (IDoubleBondStereochemistry)original.Clone(new CDKObjectMap());

            Assert.AreSame(original, mapped);
        }
Пример #21
0
        public void TestDifferentRingFinders()
        {
            var fingerprinter = new ExtendedFingerprinter();
            var ac1           = builder.NewAtomContainer();
            var atom1         = builder.NewAtom("C");
            var atom2         = builder.NewAtom("C");
            var atom3         = builder.NewAtom("C");
            var atom4         = builder.NewAtom("C");
            var atom5         = builder.NewAtom("C");
            var atom6         = builder.NewAtom("C");

            ac1.Atoms.Add(atom1);
            ac1.Atoms.Add(atom2);
            ac1.Atoms.Add(atom3);
            ac1.Atoms.Add(atom4);
            ac1.Atoms.Add(atom5);
            ac1.Atoms.Add(atom6);
            var bond1 = builder.NewBond(atom1, atom2);
            var bond2 = builder.NewBond(atom2, atom3);
            var bond3 = builder.NewBond(atom3, atom4);
            var bond4 = builder.NewBond(atom4, atom5);
            var bond5 = builder.NewBond(atom5, atom6);
            var bond6 = builder.NewBond(atom6, atom1);

            ac1.Bonds.Add(bond1);
            ac1.Bonds.Add(bond2);
            ac1.Bonds.Add(bond3);
            ac1.Bonds.Add(bond4);
            ac1.Bonds.Add(bond5);
            ac1.Bonds.Add(bond6);
            var ac2 = builder.NewAtomContainer();

            ac2.Atoms.Add(atom1);
            ac2.Atoms.Add(atom2);
            ac2.Atoms.Add(atom3);
            ac2.Atoms.Add(atom4);
            ac2.Atoms.Add(atom5);
            ac2.Atoms.Add(atom6);
            var bond7 = builder.NewBond(atom3, atom1);

            ac2.Bonds.Add(bond1);
            ac2.Bonds.Add(bond2);
            ac2.Bonds.Add(bond3);
            ac2.Bonds.Add(bond4);
            ac2.Bonds.Add(bond5);
            ac2.Bonds.Add(bond6);
            ac2.Bonds.Add(bond7);
            var bs  = fingerprinter.GetBitFingerprint(ac1).AsBitSet();
            var bs1 = fingerprinter.GetBitFingerprint(ac2).AsBitSet();

            Assert.IsTrue(FingerprinterTool.IsSubset(bs1, bs));
            Assert.IsFalse(FingerprinterTool.IsSubset(bs, bs1));
        }
Пример #22
0
        public void TestModelBuilder3D_keepChemObjectIDs()
        {
            ModelBuilder3D mb3d = ModelBuilder3D.GetInstance();

            IAtomContainer     methanol = new Silent.AtomContainer();
            IChemObjectBuilder builder  = methanol.Builder;

            IAtom carbon1 = builder.NewAtom("C");

            carbon1.Id = "carbon1";
            methanol.Atoms.Add(carbon1);
            for (int i = 0; i < 3; i++)
            {
                IAtom hydrogen = builder.NewAtom("H");
                methanol.Atoms.Add(hydrogen);
                methanol.Bonds.Add(builder.NewBond(carbon1, hydrogen, BondOrder.Single));
            }
            IAtom oxygen1 = builder.NewAtom("O");

            oxygen1.Id = "oxygen1";
            methanol.Atoms.Add(oxygen1);
            methanol.Bonds.Add(builder.NewBond(carbon1, oxygen1, BondOrder.Single));
            {
                IAtom hydrogen = builder.NewAtom("H");
                methanol.Atoms.Add(hydrogen);
                methanol.Bonds.Add(builder.NewBond(hydrogen, oxygen1, BondOrder.Single));
            }

            Assert.AreEqual(6, methanol.Atoms.Count);
            Assert.AreEqual(5, methanol.Bonds.Count);

            mb3d.Generate3DCoordinates(methanol, false);

            CheckAverageBondLength(methanol);
            Assert.AreEqual("carbon1", carbon1.Id);
            Assert.AreEqual("oxygen1", oxygen1.Id);
        }
Пример #23
0
        /// <summary>
        /// Remove the following features from a molecule
        ///  - Atom non-standard mass
        ///  - Stereo chemistry
        ///  - explicit hydrogens
        /// </summary>
        /// <param name="src"></param>
        /// <returns>Modified mol</returns>

        public static IAtomContainer RemoveIsotopesStereoExplicitHydrogens(
            IAtomContainer src)
        {
            IAtom[] atoms = new IAtom[src.Atoms.Count];
            IBond[] bonds = new IBond[src.Bonds.Count];

            IChemObjectBuilder builder = src.Builder;

            for (int i = 0; i < atoms.Length; i++)
            {
                IAtom atom  = src.Atoms[i];
                IAtom atom2 = builder.NewAtom(atom.Symbol);
                SetImplicitHydrogenCount(atom2, GetImplicitHydrogenCount(atom));
                atom2.Point2D = atom.Point2D;
                atoms[i]      = atom2;
            }

            for (int i = 0; i < bonds.Length; i++)
            {
                IBond bond = src.Bonds[i];

                int u = bond.Atoms[0].Index;
                int v = bond.Atoms[1].Index;

                IBond bond2 = builder.NewBond(atoms[u], atoms[v]);

                bond2.IsAromatic = bond.IsAromatic;
                bond2.IsInRing   = bond.IsInRing;
                bond2.Order      = bond.Order;

                bond2.IsAromatic       = bond.IsAromatic;
                bond2.IsSingleOrDouble = bond.IsSingleOrDouble;

                bonds[i] = bond2;
            }

            IAtomContainer dest = ChemObjectBuilder.Instance.NewAtomContainer();

            dest.SetAtoms(atoms);
            dest.SetBonds(bonds);

            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(dest);
            dest = AtomContainerManipulator.SuppressHydrogens(dest);
            GetHydrogenAdder().AddImplicitHydrogens(dest);

            return(dest);
        }
Пример #24
0
        /// <summary>
        /// Creates a BioPolymer from a sequence of amino acid as identified by a
        /// the sequence of their one letter codes. It uses the given <see cref="IChemObjectBuilder"/>
        /// to create a data model.
        /// </summary>
        /// <example>
        /// For example:
        /// <code>
        /// IBioPolymer protein = ProteinBuilderTool.CreateProtein("GAGA", Silent.ChemObjectBuilder.Instance);
        /// </code>
        /// </example>
        /// <seealso cref="CreateProtein(string)"/>
        public static IBioPolymer CreateProtein(string sequence, IChemObjectBuilder builder)
        {
            var        templates  = AminoAcids.MapBySingleCharCode;
            var        protein    = builder.NewBioPolymer();
            var        strand     = builder.NewStrand();
            IAminoAcid previousAA = null;

            for (int i = 0; i < sequence.Length; i++)
            {
                string aminoAcidCode = "" + sequence[i];
                Debug.WriteLine($"Adding AA: {aminoAcidCode}");
                if (string.Equals(aminoAcidCode, " ", StringComparison.Ordinal))
                {
                    // fine, just skip spaces
                }
                else
                {
                    IAminoAcid aminoAcid = templates[aminoAcidCode];
                    if (aminoAcid == null)
                    {
                        throw new CDKException("Cannot build sequence! Unknown amino acid: " + aminoAcidCode);
                    }
                    aminoAcid             = (IAminoAcid)aminoAcid.Clone();
                    aminoAcid.MonomerName = aminoAcidCode + i;
                    Debug.WriteLine($"protein: {protein}");
                    Debug.WriteLine($"strand: {strand}");
                    AddAminoAcidAtCTerminus(protein, aminoAcid, strand, previousAA);
                    previousAA = aminoAcid;
                }
            }
            // add the last oxygen of the protein
            var oxygen = builder.NewAtom("O");

            // ... to amino acid
            previousAA.Atoms.Add(oxygen);
            var bond = builder.NewBond(oxygen, previousAA.CTerminus, BondOrder.Single);

            previousAA.Bonds.Add(bond);
            // ... and to protein
            protein.AddAtom(oxygen, previousAA, strand);
            protein.Bonds.Add(bond);
            return(protein);
        }
Пример #25
0
 private void ConstructObject(IChemObjectBuilder builder, string obj)
 {
     if (string.Equals("Atom", obj, StringComparison.Ordinal))
     {
         chemObject = builder.NewAtom("C");
     }
     else if (string.Equals("Bond", obj, StringComparison.Ordinal))
     {
         bondCounter++;
         chemObject = builder.NewBond();
     }
     else if (string.Equals("Model", obj, StringComparison.Ordinal))
     {
         modelStructure = builder.NewAtomContainer();
     }
     else
     {
         Trace.TraceError($"Cannot construct PMP object type: {obj}");
     }
 }
Пример #26
0
        public void TestH2()
        {
            var hydrogenPlacer = new HydrogenPlacer();

            // h1 has no coordinates
            var h1 = builder.NewAtom("H");
            var h2 = builder.NewAtom("H", Vector2.Zero);
            var m  = builder.NewAtomContainer();

            m.Atoms.Add(h1);
            m.Atoms.Add(h2);
            m.Bonds.Add(builder.NewBond(h1, h2));
            hydrogenPlacer.PlaceHydrogens2D(m, 1.5);
            Assert.IsNotNull(h1.Point2D);
        }
Пример #27
0
        public void TestCdkBondToCMLBond_Hatch()
        {
            IChemObjectBuilder builder = ChemObjectBuilder.Instance;
            IBond bond = builder.NewBond();

            bond.Order  = BondOrder.Single;
            bond.Stereo = BondStereo.Down;

            Convertor convertor = new Convertor(true, null);
            CMLBond   cmlBond   = convertor.CDKJBondToCMLBond(bond);

            var writer = new StringWriter();
            var d      = new XDocument(cmlBond);

            d.Save(writer);

            string expected = "<bondStereo dictRef=\"cml:H\">H</bondStereo>";
            string actual   = writer.ToString();

            Assert.IsTrue(actual.Contains(expected));
        }
        public void TestPossibleAtomTypes_IAtomContainer_IAtom()
        {
            var mol  = builder.NewAtomContainer();
            var atom = builder.NewAtom("C");

            atom.ImplicitHydrogenCount = 3;
            var atom2 = builder.NewAtom("N");

            atom.ImplicitHydrogenCount = 2;
            mol.Atoms.Add(atom);
            mol.Atoms.Add(atom2);
            mol.Bonds.Add(builder.NewBond(atom, atom2, BondOrder.Single));

            StructGenAtomTypeGuesser atm = new StructGenAtomTypeGuesser();
            var matched = atm.PossibleAtomTypes(mol, atom);

            Assert.IsNotNull(matched);
            Assert.IsTrue(matched.Count() > 0);
            Assert.IsTrue(matched.ElementAt(0) is IAtomType);

            Assert.AreEqual("C", ((IAtomType)matched.ElementAt(0)).Symbol);
        }
Пример #29
0
        public void TestBug1778479()
        {
            StringWriter   writer   = new StringWriter();
            IAtomContainer molecule = builder.NewAtomContainer();
            IAtom          atom1    = builder.NewPseudoAtom();
            IAtom          atom2    = builder.NewAtom("C");
            IBond          bond     = builder.NewBond(atom1, atom2);

            molecule.Atoms.Add(atom1);
            molecule.Atoms.Add(atom2);
            molecule.Bonds.Add(bond);

            MDLV2000Writer mdlWriter = new MDLV2000Writer(writer);

            mdlWriter.Write(molecule);
            mdlWriter.Close();
            string output = writer.ToString();

            Assert.AreEqual(-1,
                            output.IndexOf("0.0000    0.0000    0.0000     0  0  0  0  0  0  0  0  0  0  0  0"),
                            "Test for zero length pseudo atom label in MDL file");
        }
Пример #30
0
        public static IAtomContainer CreateHexane()
        {
            IAtomContainer result = builder.NewAtomContainer();
            IAtom          c1     = builder.NewAtom("C");

            c1.Id = "1";
            IAtom c2 = builder.NewAtom("C");

            c2.Id = "2";
            IAtom c3 = builder.NewAtom("C");

            c3.Id = "3";
            IAtom c4 = builder.NewAtom("C");

            c4.Id = "4";
            IAtom c5 = builder.NewAtom("C");

            c5.Id = "5";
            IAtom c6 = builder.NewAtom("C");

            c6.Id = "6";

            result.Atoms.Add(c1);
            result.Atoms.Add(c2);
            result.Atoms.Add(c3);
            result.Atoms.Add(c4);
            result.Atoms.Add(c5);
            result.Atoms.Add(c6);

            IBond bond1 = builder.NewBond(c1, c2, BondOrder.Single);
            IBond bond2 = builder.NewBond(c2, c3, BondOrder.Single);
            IBond bond3 = builder.NewBond(c3, c4, BondOrder.Single);
            IBond bond4 = builder.NewBond(c4, c5, BondOrder.Single);
            IBond bond5 = builder.NewBond(c5, c6, BondOrder.Single);

            result.Bonds.Add(bond1);
            result.Bonds.Add(bond2);
            result.Bonds.Add(bond3);
            result.Bonds.Add(bond4);
            result.Bonds.Add(bond5);

            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(result);

            return(result);
        }