示例#1
0
        public MainWindow()
        {
            InitializeComponent();

            var filename = @"G:\Projects\HumanGenome\Protein-PDBs\2mgo.pdb";
            //var filename = @"G:\Projects\HumanGenome\AminoseqFiles\CFTR.aminoseq";
            ApproximatePeptide approximatePeptide;
            Peptide            peptide;

            if (filename.ToLowerInvariant().EndsWith(".pdb"))
            {
                peptide = PeptideLoader.Load(filename);
                peptide.Molecule.MarkBackbone(peptide.MoleculeReference);
                peptide.Molecule.PositionAtoms(peptide.MoleculeReference.FirstAtomId, peptide.MoleculeReference.LastAtomId);
                approximatePeptide = ApproximatePeptideBuilder.FromPeptide(peptide);
            }
            else
            {
                approximatePeptide = ApproximatePeptideBuilder.FromSequence(new string('A', 8), 1);
                //approximatePeptide = ApproximatePeptideBuilder.FromSequence(File.ReadAllLines(filename).Aggregate((a,b) => a + b));
                approximatePeptide.UpdatePositions();
                peptide = new ApproximatePeptideCompleter(approximatePeptide).GetFullPeptide();
            }

            var simulationSettings = new ApproximatePeptideSimulationSettings
            {
                TimeStep       = 2.To(SIPrefix.Femto, Unit.Second),
                SimulationTime = 10.To(SIPrefix.Nano, Unit.Second),
                ResetAtomVelocityAfterEachTimestep = false,
                UseCompactingForce   = true,
                UseRamachandranForce = true
            };
            var ramachadranDataDirectory           = @"G:\Projects\HumanGenome\ramachadranDistributions";
            var ramachandranPlotDistributionSource = new RamachandranPlotGradientDistributionFileSource(ramachadranDataDirectory);
            //var ramachandranPlotDistributionSource = new RamachandranPlotDistributionFixedSource(
            //    new RamachandranPlotFixedDistribution(AminoAcidName.Alanine, new UnitPoint2D(-57.To(Unit.Degree), -47.To(Unit.Degree))));
            //var simulationRunner = ApproximatePeptideFoldingSimulatorFactory.Create(
            //    approximatePeptide, simulationSettings, ramachadranDataDirectory);
            var simulationRunner = new ApproximatePeptideFoldingSimulator(approximatePeptide,
                                                                          simulationSettings,
                                                                          new CompactingForceCalculator(),
                                                                          new RamachandranForceCalculator(ramachandranPlotDistributionSource),
                                                                          new BondForceCalculator());

            //var simulationRunner = new MoleculeDynamicsSimulator(peptide.Molecule, new List<CustomAtomForce>(),
            //    new MoleculeDynamicsSimulationSettings
            //    {
            //        TimeStep = 2.To(SIPrefix.Femto, Unit.Second),
            //        SimulationTime = 10.To(SIPrefix.Pico, Unit.Second)
            //    });
            MoleculeViewModel = new MoleculeViewModel();
            //MoleculeViewModel.DrawAtoms(AtomExtractor.FromApproximatePeptide(approximatePeptide));
            MoleculeViewModel.DrawAtoms(AtomExtractor.FromMolecule(peptide.Molecule));
            simulationRunner.TimestepCompleted += (sender, args) => Application.Current.Dispatcher.BeginInvoke(new Action(() => MoleculeViewModel.DrawAtoms(args.Atoms)));
            SimulationViewModel = new SimulationViewModel(simulationRunner);
        }
        public void DihedralAnglesConverge()
        {
            var targetPhi = 40.To(Unit.Degree);
            var targetPsi = -10.To(Unit.Degree);

            var approximatePeptide = ApproximatePeptideBuilder.FromSequence(new [] { AminoAcidName.Alanine, AminoAcidName.Alanine, AminoAcidName.Alanine }, 1);

            approximatePeptide.UpdatePositions();
            var startAngles        = AminoAcidAngleMeasurer.MeasureAngles(approximatePeptide);
            var simulationSettings = new ApproximatePeptideSimulationSettings
            {
                SimulationTime = 500.To(SIPrefix.Femto, Unit.Second),
                TimeStep       = 2.To(SIPrefix.Femto, Unit.Second),
                ResetAtomVelocityAfterEachTimestep = true,
                UseCompactingForce = false
            };
            var ramachandranPlotDistribution = new RamachandranPlotFixedDistribution(AminoAcidName.Alanine, new UnitPoint2D(targetPhi, targetPsi));
            var distributionSource           = new RamachandranPlotDistributionFixedSource(ramachandranPlotDistribution);
            var sut       = new RamachandranForceCalculator(distributionSource);
            var simulator = new ApproximatePeptideFoldingSimulator(
                approximatePeptide,
                simulationSettings,
                new CompactingForceCalculator(),
                sut,
                new BondForceCalculator());
            var angleHistory = new List <AminoAcidAngles>();
            var simulationEndedWaitHandle = new ManualResetEvent(false);

            simulator.SimulationCompleted += (sender, args) => simulationEndedWaitHandle.Set();
            simulator.TimestepCompleted   += (sender, args) =>
            {
                var angles       = AminoAcidAngleMeasurer.MeasureAngles(args.PeptideCopy);
                var midAminoAcid = args.PeptideCopy.AminoAcids[1];
                angleHistory.Add(angles[midAminoAcid]);
            };
            simulator.StartSimulation();
            simulationEndedWaitHandle.WaitOne();
            File.WriteAllLines(@"G:\Projects\HumanGenome\angles.csv",
                               angleHistory.Select(angle => $"{angle.Omega.In(Unit.Degree).ToString(CultureInfo.InvariantCulture)};" +
                                                   $"{angle.Phi.In(Unit.Degree).ToString(CultureInfo.InvariantCulture)};" +
                                                   $"{angle.Psi.In(Unit.Degree).ToString(CultureInfo.InvariantCulture)}"));

            var finalAngles     = AminoAcidAngleMeasurer.MeasureAngles(approximatePeptide);
            var middleAminoAcid = approximatePeptide.AminoAcids[1];

            Assert.That((finalAngles[middleAminoAcid].Phi - targetPhi).Abs(),
                        Is.LessThan((startAngles[middleAminoAcid].Phi - targetPhi).Abs()));
            Assert.That((finalAngles[middleAminoAcid].Psi - targetPsi).Abs(),
                        Is.LessThan((startAngles[middleAminoAcid].Psi - targetPsi).Abs()));
        }
示例#3
0
        public void ApproximatePeptideIsFoldedToKnownStableState(string pdbFilePath)
        {
            var pdbReadResult      = PdbReader.ReadFile(pdbFilePath);
            var peptide            = pdbReadResult.Models.First().Chains.First();
            var approximatePeptide = ApproximatePeptideBuilder.FromPeptide(peptide);

            var simulationSettings = new ApproximatePeptideSimulationSettings
            {
                SimulationTime = 10.To(SIPrefix.Pico, Unit.Second),
                TimeStep       = 2.To(SIPrefix.Femto, Unit.Second)
            };
            var ramachadranDataDirectory = @"G:\Projects\HumanGenome\ramachadranDistributions";
            var simulator = ApproximatePeptideFoldingSimulatorFactory.Create(
                approximatePeptide, simulationSettings, ramachadranDataDirectory);

            simulator.TimestepCompleted   += Simulator_TimestepCompleted;
            simulator.SimulationCompleted += Simulator_SimulationCompleted;
            simulationWaitHandle.Reset();
            simulator.StartSimulation();

            simulationWaitHandle.WaitOne();
            Assert.Pass();
        }