public override void TestClone() { IAminoAcid aa = (IAminoAcid)NewChemObject(); object clone = aa.Clone(); Assert.IsTrue(clone is IAminoAcid); Assert.AreNotSame(aa, clone); aa = (IAminoAcid)NewChemObject(); IAtom nTerminus = aa.Builder.NewAtom("N"); aa.AddNTerminus(nTerminus); clone = aa.Clone(); Assert.IsTrue(clone is IAminoAcid); Assert.AreNotSame(aa, clone); aa = (IAminoAcid)NewChemObject(); IAtom cTerminus = aa.Builder.NewAtom("C"); aa.AddCTerminus(cTerminus); clone = aa.Clone(); Assert.IsTrue(clone is IAminoAcid); Assert.AreNotSame(aa, clone); }
/// <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); }