Exemplo n.º 1
0
        public async Task <ActionResult> Index(string lastEditedMoleculeId)
        {
            var filter = new MoleculeFilter();

            // Get values from database.
            var molecules = await _moleculeService.GetAllAsync(filter);

            var substances = await _substanceService.GetAllAsync(new SubstanceFilter());

            IList <MoleculeViewModel> moleculeViewModels = new List <MoleculeViewModel>();

            // Create list of molecules for view.
            foreach (var molecule in molecules)
            {
                var model = new MoleculeViewModel(molecule, null);

                if (molecule.SubstanceIdString != null)
                {
                    var substance = await _moleculeService.GetSubstanceForMoleculeAsync(molecule.SubstanceIdString);

                    // Set name of substance for molecule.
                    model.SubstanceValue = substance.Name;
                }

                moleculeViewModels.Add(model);
            }

            // Create view model for Index view.
            var moleculeViewModelIndex = new MoleculeViewModelIndex(moleculeViewModels, substances);

            // Set value to where to scroll to.
            moleculeViewModelIndex.LastEditedMoleculeId = lastEditedMoleculeId;

            return(View(moleculeViewModelIndex));
        }
Exemplo n.º 2
0
        public async Task <ActionResult> CreateOrEdit(string id)
        {
            var substances = await _substanceService.GetAllAsync(new SubstanceFilter());

            MoleculeViewModel model;

            // Get MoleculeViewModel according to whether is edit or create.
            if (!string.IsNullOrEmpty(id))
            {
                // Edit
                var molecule = await _moleculeService.GetByIdAsync(id);

                if (molecule == null)
                {
                    Log.Error($"An unexpected error occurred while getting id. No entity with id {id} could be found.");
                    throw new ArgumentNullException(string.Format(Resources.Resources.Error_NoEntityWithIdFound, id));
                }

                model = new MoleculeViewModel(molecule, substances);
            }
            else
            {
                // Create
                model = new MoleculeViewModel(null, substances);
            }

            return(View(model));
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        public async Task <ActionResult> CreateOrEdit(MoleculeViewModel model)
        {
            var validationResult = new ValidationResultList();

            if (ModelState.IsValid)
            {
                try
                {
                    var molecule = new Molecule();

                    // Map view model to entity.
                    model.MapViewModelToEntity(molecule);

                    // Edit or create
                    if (molecule.Id != null)
                    {
                        // Edit
                        // Only update if molecule name doesn't already exist.
                        validationResult = await _moleculeService.UpdateAsync(molecule);
                    }
                    else
                    {
                        // Create
                        // Only insert if molecule name doesn't already exist.
                        validationResult = await _moleculeService.InsertAsync(molecule);

                        model.Id = molecule.Id;
                    }
                }
                catch (Exception e)
                {
                    Log.Error($"An unexpected error occurred while inserting or editing: {e}");
                    throw new ArgumentException(Resources.Resources.Error_UnexpectedError);
                }
            }

            // Show validation result, if validation error occurred while
            // inserting or if ModelState is invalid.
            if (validationResult.HasErrors || !ModelState.IsValid)
            {
                AddValidationResultsToModelStateErrors(validationResult.Errors);

                // Set substances to display in drop down.
                var substances = await _substanceService.GetAllAsync(new SubstanceFilter());

                model.Substances = substances;

                Log.Info("Show CreateOrEdit");
                return(View(nameof(CreateOrEdit), model));
            }

            Log.Info("Redirect to Index");
            return(RedirectToAction(nameof(Index), new { lastEditedMoleculeId = model.Id }));
        }