示例#1
0
        public Peptide GetFullPeptide()
        {
            var aminoAcids = new List <AminoAcidReference>();

            foreach (var approximatedAminoAcid in approximatePeptide.AminoAcids)
            {
                var aminoAcid = AminoAcidLibrary.Get(approximatedAminoAcid.Name, approximatedAminoAcid.SequenceNumber);
                PdbAminoAcidAtomNamer.AssignNames(aminoAcid);

                var nitrogen = aminoAcid.GetAtomFromName("N");
                nitrogen.Position        = approximatedAminoAcid.NitrogenPosition;
                nitrogen.IsPositionFixed = true;

                var carbonAlpha = aminoAcid.GetAtomFromName("CA");
                carbonAlpha.Position        = approximatedAminoAcid.CarbonAlphaPosition;
                carbonAlpha.IsPositionFixed = true;

                var carbon = aminoAcid.GetAtomFromName("C");
                carbon.Position        = approximatedAminoAcid.CarbonPosition;
                carbon.IsPositionFixed = true;

                aminoAcid.Molecule.PositionAtoms();
                aminoAcids.Add(aminoAcid);
            }

            var peptide = PeptideBuilder.PeptideFromAminoAcids(aminoAcids);

            peptide.Molecule.PositionAtoms();

            return(peptide);
        }
示例#2
0
        public static ApproximatePeptide FromPeptide(Peptide peptide)
        {
            var dihedralAngles = AminoAcidAngleMeasurer.MeasureAngles(peptide);

            var approximateAminoAcids = new List <ApproximatedAminoAcid>();

            foreach (var aminoAcid in peptide.AminoAcids)
            {
                PdbAminoAcidAtomNamer.AssignNames(aminoAcid);
                var nitrogen                = aminoAcid.GetAtomFromName("N");
                var carbonAlpha             = aminoAcid.GetAtomFromName("CA");
                var carbon                  = aminoAcid.GetAtomFromName("C");
                var aminoAcidDihedralAngles = dihedralAngles[aminoAcid];

                var approximateAminoAcid = new ApproximatedAminoAcid(aminoAcid.Name, aminoAcid.SequenceNumber)
                {
                    NitrogenPosition    = nitrogen.Position,
                    CarbonAlphaPosition = carbonAlpha.Position,
                    CarbonPosition      = carbon.Position,
                    OmegaAngle          = aminoAcidDihedralAngles.Omega,
                    PhiAngle            = aminoAcidDihedralAngles.Phi,
                    PsiAngle            = aminoAcidDihedralAngles.Psi,
                    IsFrozen            = true
                };
                approximateAminoAcids.Add(approximateAminoAcid);
            }
            return(new ApproximatePeptide(approximateAminoAcids));
        }
示例#3
0
        public void ProlineNamedCorrectly()
        {
            var aminoAcidReference = AminoAcidLibrary.Proline(1);

            PdbAminoAcidAtomNamer.AssignNames(aminoAcidReference);

            var moleculeStructure = aminoAcidReference.Molecule.MoleculeStructure;
            var nitrogen          = moleculeStructure.GetVertexFromId(aminoAcidReference.FirstAtomId).Object;

            Assume.That(nitrogen.Element, Is.EqualTo(ElementName.Nitrogen));
            Assert.That(nitrogen.AminoAcidAtomName, Is.EqualTo("N"));

            var carbonEnd = moleculeStructure.GetVertexFromId(aminoAcidReference.LastAtomId).Object;

            Assume.That(carbonEnd.Element, Is.EqualTo(ElementName.Carbon));
            Assert.That(carbonEnd.AminoAcidAtomName, Is.EqualTo("C"));

            var remainingNonHydrogenAtoms = moleculeStructure.Vertices
                                            .Select(v => v.Object)
                                            .Where(atom => atom.Element != ElementName.Hydrogen)
                                            .Except(new[] { nitrogen, carbonEnd })
                                            .ToList();

            Assert.That(remainingNonHydrogenAtoms.Count, Is.EqualTo(5));
            var oxygen = remainingNonHydrogenAtoms.Single(atom => atom.Element == ElementName.Oxygen);

            Assert.That(oxygen.AminoAcidAtomName, Is.EqualTo("O"));

            var sideChainCarbons = remainingNonHydrogenAtoms.Where(atom => atom.Element == ElementName.Carbon).ToList();

            Assert.That(sideChainCarbons.Count, Is.EqualTo(4));
            Assert.That(sideChainCarbons.Select(atom => atom.AminoAcidAtomName), Is.EquivalentTo(new[] { "CA", "CB", "CG", "CD" }));
        }
示例#4
0
        private static string SerializeAtoms(Peptide peptide)
        {
            var output     = "";
            var atomIdx    = 1;
            var chainId    = 'A';
            var aminoAcids = peptide.AminoAcids;

            for (int residueIdx = 0; residueIdx < aminoAcids.Count; residueIdx++)
            {
                var aminoAcid = aminoAcids[residueIdx];
                PdbAminoAcidAtomNamer.AssignNames(aminoAcid);
                var aminoAcidVertices = aminoAcid.VertexIds
                                        .Select(vId => aminoAcid.Molecule.MoleculeStructure.GetVertexFromId(vId));
                var residueName    = aminoAcid.Name.ToThreeLetterCode();
                var sequenceNumber = aminoAcid.SequenceNumber;
                foreach (var vertex in aminoAcidVertices)
                {
                    var atom = aminoAcid.Molecule.GetAtom(vertex.Id);
                    if (atom.Element == ElementName.Hydrogen)
                    {
                        continue;
                    }
                    if (atom.Position == null)
                    {
                        continue;
                    }
                    var atomName          = atom.AminoAcidAtomName ?? atom.Element.ToElementSymbol().ToString();
                    var x                 = (1e10 * atom.Position.X).ToString("F3");
                    var y                 = (1e10 * atom.Position.Y).ToString("F3");
                    var z                 = (1e10 * atom.Position.Z).ToString("F3");
                    var occupancy         = 1.0.ToString("F2");
                    var temperatureFactor = 0.0.ToString("F2");
                    var elementSymbol     = atom.Element.ToElementSymbol();
                    var charge            = "";

                    if (atomIdx > 1)
                    {
                        output += Environment.NewLine;
                    }
                    output += $"ATOM  {atomIdx,5} {atomName,4} {residueName,3} {chainId}{sequenceNumber,4}    " +
                              $"{x,8}{y,8}{z,8}{occupancy,6}{temperatureFactor,6}          " +
                              $"{elementSymbol,2}{charge,2}";
                    atomIdx++;
                }
            }
            output += Environment.NewLine;
            output += $"TER   {atomIdx,5}      {aminoAcids.Last().Name.ToThreeLetterCode()} {chainId}{aminoAcids.Count-1,4}".PadRight(80);
            return(output);
        }
        public void Psi90PlusMeasuredCorrectly()
        {
            var peptide        = PeptideBuilder.PeptideFromString("GG");
            var firstAminoAcid = peptide.AminoAcids.First();
            var lastAminoAcid  = peptide.AminoAcids.Last();

            PdbAminoAcidAtomNamer.AssignNames(firstAminoAcid);
            PdbAminoAcidAtomNamer.AssignNames(lastAminoAcid);
            var N1  = firstAminoAcid.GetAtomFromName("N");
            var Ca1 = firstAminoAcid.GetAtomFromName("CA");
            var C1  = firstAminoAcid.GetAtomFromName("C");
            var N2  = lastAminoAcid.GetAtomFromName("N");
            var Ca2 = lastAminoAcid.GetAtomFromName("CA");
            var C2  = lastAminoAcid.GetAtomFromName("C");

            N1.Position        = new UnitPoint3D(SIPrefix.Pico, Unit.Meter, 0, 0, 0);
            N1.IsPositionFixed = true;

            Ca1.Position        = new UnitPoint3D(SIPrefix.Pico, Unit.Meter, 100, 0, 0);
            Ca1.IsPositionFixed = true;

            C1.Position        = new UnitPoint3D(SIPrefix.Pico, Unit.Meter, 100, 100, 0);
            C1.IsPositionFixed = true;

            N2.Position        = new UnitPoint3D(SIPrefix.Pico, Unit.Meter, 100, 100, 100);
            N2.IsPositionFixed = true;

            Ca2.Position        = new UnitPoint3D(SIPrefix.Pico, Unit.Meter, 200, 100, 100);
            Ca2.IsPositionFixed = true;

            C2.Position        = new UnitPoint3D(SIPrefix.Pico, Unit.Meter, 200, 200, 100);
            C2.IsPositionFixed = true;

            var measurements = AminoAcidAngleMeasurer.MeasureAngles(peptide);

            Assert.That(measurements.ContainsKey(firstAminoAcid));
            Assert.That(measurements.ContainsKey(lastAminoAcid));

            var firstAngles = measurements[firstAminoAcid];
            var lastAngles  = measurements[lastAminoAcid];

            Assert.That(firstAngles.Omega, Is.Null);
            Assert.That(firstAngles.Phi, Is.Null);
            Assert.That(firstAngles.Psi, Is.Not.Null);
            Assert.That(firstAngles.Psi.In(Unit.Degree), Is.EqualTo(90));

            Assert.That(lastAngles.Omega, Is.Not.Null);
            Assert.That(lastAngles.Omega.In(Unit.Degree), Is.EqualTo(90));
        }
示例#6
0
        private static void ReadAtomPositions(IList <string> lines, char chainId, Peptide peptide)
        {
            var aminoAcidAtomGroups = lines
                                      .Where(line => ReadLineCode(line) == "ATOM")
                                      .Select(ParseAtomLine)
                                      .Where(atom => atom.ChainId == chainId)
                                      .Where(atom => atom.AlternateConformationId == ' ' || atom.AlternateConformationId == 'A')
                                      .Where(atom => !atom.IsAlternative)
                                      .GroupBy(atom => atom.ResidueNumber);

            foreach (var aminoAcidAtomInfos in aminoAcidAtomGroups)
            {
                if (aminoAcidAtomInfos.Key < peptide.AminoAcids.First().SequenceNumber) // TODO: Log warning
                {
                    continue;
                }
                if (aminoAcidAtomInfos.Key > peptide.AminoAcids.Last().SequenceNumber) // TODO: Log warning
                {
                    continue;
                }
                var residueNumber = aminoAcidAtomInfos.Key;
                var aminoAcid     = peptide.AminoAcids.SingleOrDefault(aa => aa.SequenceNumber == residueNumber);
                if (aminoAcid == null) // TODO: Log warning
                {
                    continue;
                }
                PdbAminoAcidAtomNamer.AssignNames(aminoAcid);
                foreach (var atomInfo in aminoAcidAtomInfos)
                {
                    var correspondingAtom = aminoAcid.GetAtomFromName(atomInfo.Name);
                    if (correspondingAtom == null)
                    {
                        continue;
                    }
                    correspondingAtom.Position = new UnitPoint3D(SIPrefix.Pico, Unit.Meter,
                                                                 100 * atomInfo.X,
                                                                 100 * atomInfo.Y,
                                                                 100 * atomInfo.Z);
                    correspondingAtom.IsPositioned    = true;
                    correspondingAtom.IsPositionFixed = true;
                }
            }
        }
示例#7
0
        public static Dictionary <AminoAcidReference, AminoAcidAngles> MeasureAngles(Peptide peptide)
        {
            var             measurements = new Dictionary <AminoAcidReference, AminoAcidAngles>();
            AminoAcidAngles lastAngles   = null;

            UnitPoint3D lastNitrogenPosition    = null;
            UnitPoint3D lastCarbonAlphaPosition = null;
            UnitPoint3D lastCarbonPosition      = null;

            foreach (var aminoAcid in peptide.AminoAcids)
            {
                PdbAminoAcidAtomNamer.AssignNames(aminoAcid);
                var nitrogen         = aminoAcid.GetAtomFromName("N");
                var carbonAlpha      = aminoAcid.GetAtomFromName("CA");
                var carbon           = aminoAcid.GetAtomFromName("C");
                var nitrogenPosition = nitrogen != null && nitrogen.IsPositionFixed
                    ? nitrogen.Position
                    : null;
                var carbonAlphaPosition = carbonAlpha != null && carbonAlpha.IsPositionFixed
                    ? carbonAlpha.Position
                    : null;
                var carbonPosition = carbon != null && carbon.IsPositionFixed
                    ? carbon.Position
                    : null;

                if (lastAngles != null &&
                    lastNitrogenPosition != null &&
                    lastCarbonAlphaPosition != null &&
                    lastCarbonPosition != null &&
                    nitrogenPosition != null)
                {
                    var psi = DihedralAngleCalculator.Calculate(
                        lastNitrogenPosition,
                        lastCarbonAlphaPosition,
                        lastCarbonPosition,
                        nitrogenPosition);
                    lastAngles.Psi = psi;
                }

                UnitValue omega = null;
                if (lastCarbonAlphaPosition != null &&
                    lastCarbonPosition != null &&
                    nitrogenPosition != null &&
                    carbonAlphaPosition != null)
                {
                    omega = DihedralAngleCalculator.Calculate(
                        lastCarbonAlphaPosition,
                        lastCarbonPosition,
                        nitrogenPosition,
                        carbonAlphaPosition);
                }
                UnitValue phi = null;
                if (lastCarbonPosition != null &&
                    nitrogenPosition != null &&
                    carbonAlphaPosition != null &&
                    carbonPosition != null)
                {
                    phi = DihedralAngleCalculator.Calculate(
                        lastCarbonPosition,
                        nitrogenPosition,
                        carbonAlphaPosition,
                        carbonPosition);
                }

                var angles = new AminoAcidAngles
                {
                    Omega = omega,
                    Phi   = phi
                };
                measurements.Add(aminoAcid, angles);

                lastNitrogenPosition    = nitrogenPosition;
                lastCarbonAlphaPosition = carbonAlphaPosition;
                lastCarbonPosition      = carbonPosition;
                lastAngles = angles;
            }
            return(measurements);
        }