Example #1
0
        public void TestNewStrand()
        {
            IChemObjectBuilder builder = RootObject.Builder;
            IStrand            strand  = builder.NewStrand();

            Assert.IsNotNull(strand);
        }
Example #2
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);
        }