public void ForceDirectionAsExpected()
        {
            var approximatePeptide = new ApproximatePeptide(new []
            {
                new ApproximatedAminoAcid(AminoAcidName.Alanine, 1)
                {
                    NitrogenPosition    = new UnitPoint3D(SIPrefix.Pico, Unit.Meter, -150, -150, 0),
                    CarbonAlphaPosition = new UnitPoint3D(SIPrefix.Pico, Unit.Meter, 0, -150, 0),
                    CarbonPosition      = new UnitPoint3D(SIPrefix.Pico, Unit.Meter, 0, 0, 0)
                },
                new ApproximatedAminoAcid(AminoAcidName.Alanine, 2)
                {
                    NitrogenPosition    = new UnitPoint3D(SIPrefix.Pico, Unit.Meter, 150, 0, 0),
                    CarbonAlphaPosition = new UnitPoint3D(SIPrefix.Pico, Unit.Meter, 150, 0, 150),
                    CarbonPosition      = new UnitPoint3D(SIPrefix.Pico, Unit.Meter, 300, 0, 150)
                }
            });
            var angles = AminoAcidAngleMeasurer.MeasureAngles(approximatePeptide);
            var ramachandranPlotDistribution = new RamachandranPlotFixedDistribution(AminoAcidName.Alanine, new UnitPoint2D(Unit.Degree, -90, -20));
            var distributionSource           = new RamachandranPlotDistributionFixedSource(ramachandranPlotDistribution);
            var sut    = new RamachandranForceCalculator(distributionSource);
            var forces = sut.Calculate(approximatePeptide);

            var aminoAcid1Forces = forces[approximatePeptide.AminoAcids[0]];
            var aminoAcid2Forces = forces[approximatePeptide.AminoAcids[1]];

            Assert.That(aminoAcid1Forces.CarbonAlphaForce.In(Unit.Newton).Z, Is.LessThan(0));
            Assert.That(aminoAcid1Forces.CarbonForce.Magnitude().In(Unit.Newton), Is.EqualTo(0).Within(1e-6));

            Assert.That(aminoAcid2Forces.NitrogenForce.Magnitude().In(Unit.Newton), Is.EqualTo(0).Within(1e-6));
            Assert.That(aminoAcid2Forces.CarbonAlphaForce.In(Unit.Newton).Y, Is.GreaterThan(0));
        }
예제 #2
0
        private void RunSimulation(CancellationToken cancellationToken)
        {
            var simulationTime = simulationSettings.SimulationTime;
            var dT             = simulationSettings.TimeStep;

            for (CurrentTime = 0.To(Unit.Second); CurrentTime < simulationTime; CurrentTime += dT)
            {
                cancellationToken.ThrowIfCancellationRequested();

                var compactnessForces = simulationSettings.UseCompactingForce
                    ? compactnessForceCalculator.Calculate(CompactnessMeasurer.Measure(Peptide))
                    : new Dictionary <ApproximatedAminoAcid, ApproximateAminoAcidForces>();
                var ramachandranForces = simulationSettings.UseRamachandranForce
                    ? ramachandranForceCalculator.Calculate(Peptide)
                    : new Dictionary <ApproximatedAminoAcid, ApproximateAminoAcidForces>();
                var bondForces = bondForceCalculator.Calculate(Peptide);
                foreach (var aminoAcid in Peptide.AminoAcids)
                {
                    var resultingForce = new ApproximateAminoAcidForces();
                    if (compactnessForces.ContainsKey(aminoAcid))
                    {
                        var compactnessForce = compactnessForces[aminoAcid];
                        resultingForce += compactnessForce;
                    }
                    if (ramachandranForces.ContainsKey(aminoAcid))
                    {
                        var ramachandranForce = ramachandranForces[aminoAcid];
                        resultingForce += ramachandranForce;
                    }
                    if (bondForces.ContainsKey(aminoAcid))
                    {
                        var bondForce = bondForces[aminoAcid];
                        resultingForce += bondForce;
                    }
                    ApplyForce(aminoAcid, resultingForce, dT, simulationSettings.ReservoirTemperature);
                }
                OnSimulationTimestepComplete(new SimulationTimestepCompleteEventArgs(CurrentTime, Peptide));
            }
            SimulationCompleted?.Invoke(this, EventArgs.Empty);
            IsSimulating = false;
        }