protected override void Context()
 {
     base.Context();
     _alternative      = new ParameterAlternative();
     _groupAlternative = new ParameterAlternativeGroup();
     _groupAlternative.AddAlternative(_alternative);
 }
예제 #2
0
        protected override async Task Context()
        {
            await base.Context();

            A.CallTo(() => _compoundFactory.Create()).Returns(_compound);
            clearCompound();

            _snapshot = await sut.MapToSnapshot(_compound);

            _snapshot.PlasmaProteinBindingPartner = PlasmaProteinBindingPartner.Albumin;
            _snapshot.IsSmallMolecule             = false;
            _snapshot.PkaTypes = new[]
            {
                new PkaType {
                    Pka = 1, Type = CompoundType.Acid, ValueOrigin = _snapshotValueOrigin
                },
                new PkaType {
                    Pka = 2, Type = CompoundType.Base, ValueOrigin = _snapshotValueOrigin
                },
                new PkaType {
                    Pka = 3, Type = CompoundType.Acid, ValueOrigin = _snapshotValueOrigin
                },
            };

            _fractionUnboundAlternative    = new ParameterAlternative().WithName("Alternative");
            _fractionUnboundParameterGroup = _compound.ParameterAlternativeGroup(CoreConstants.Groups.COMPOUND_FRACTION_UNBOUND);
            A.CallTo(() => _alternativeMapper.MapToModel(_snapshot.FractionUnbound[0], _fractionUnboundParameterGroup)).Returns(_fractionUnboundAlternative);

            _snapshot.Processes = new[] { _snapshotProcess1 };
            _newProcess         = new EnzymaticProcess();
            A.CallTo(() => _processMapper.MapToModel(_snapshotProcess1)).Returns(_newProcess);
        }
        public ICommand UpdateValueOrigin(ParameterAlternative parameterAlternative, ValueOrigin newValueOrigin)
        {
            var shouldChangeBuildingBlockVersion = simulationsAreUsingAlternative(parameterAlternative);
            var updateValueOriginCommand         = new UpdateParametersValueOriginCommand(parameterAlternative.AlllParametersWithSameValueOrigin, newValueOrigin, shouldChangeBuildingBlockVersion);

            return(updateValueOriginCommand.Run(_executionContext));
        }
예제 #4
0
        protected override async Task Context()
        {
            await base.Context();

            _calculatedAlternative = A.Fake <ParameterAlternative>();
            A.CallTo(() => _calculatedAlternative.IsCalculated).Returns(true);
        }
        protected override void Context()
        {
            base.Context();

            _parameter1           = DomainHelperForSpecs.ConstantParameterWithValue(10).WithName("P1");
            _parameter1.IsDefault = false;

            var alternativeGroup = new ParameterAlternativeGroup().WithName("Gr");

            _parameterAlternative = new ParameterAlternative {
                _parameter1
            };
            _parameterAlternative.Name = "Alt";
            alternativeGroup.AddAlternative(_parameterAlternative);

            _newValueOrigin = new ValueOrigin
            {
                Method = ValueOriginDeterminationMethods.InVivo,
                Source = ValueOriginSources.Database
            };

            var simulation = new IndividualSimulation {
                Properties = new SimulationProperties()
            };

            A.CallTo(() => _buildingBlockRepository.All <Simulation>()).Returns(new[] { simulation });
        }
        protected override void Context()
        {
            base.Context();
            _updateTableFormulaCommand        = A.Fake <ICommand>();
            _editedTableFormula               = new TableFormula();
            _editSolubilityParameterPresenter = A.Fake <IEditTableSolubilityParameterPresenter>();
            _parameter = DomainHelperForSpecs.ConstantParameterWithValue().WithName("SOL");
            A.CallTo(() => _applicationController.Start <IEditTableSolubilityParameterPresenter>()).Returns(_editSolubilityParameterPresenter);

            A.CallTo(() => _editSolubilityParameterPresenter.Edit(_parameter)).Returns(true);
            A.CallTo(() => _editSolubilityParameterPresenter.EditedFormula).Returns(_editedTableFormula);

            A.CallTo(() => _parameterTask.UpdateTableFormula(_parameter, _editedTableFormula)).Returns(_updateTableFormulaCommand);


            var solGroup = new ParameterAlternativeGroup().WithName(CoreConstants.Groups.COMPOUND_SOLUBILITY);

            _alternative = new ParameterAlternative().WithName("ALT1");
            _alternative.Add(_parameter);
            solGroup.AddAlternative(_alternative);
            var simulation = new IndividualSimulation {
                Properties = new SimulationProperties()
            };

            A.CallTo(() => _buildingBlockRepository.All <Simulation>()).Returns(new[] { simulation });

            var compoundProperties = new CompoundProperties();

            simulation.Properties.AddCompoundProperties(compoundProperties);
            compoundProperties.AddCompoundGroupSelection(new CompoundGroupSelection {
                AlternativeName = _alternative.Name, GroupName = solGroup.Name
            });
        }
        protected override void Context()
        {
            base.Context();
            _formulaCache                = new FormulaCache();
            _compoundFactory             = IoC.Resolve <ICompoundFactory>();
            _parameterAlternativeFactory = IoC.Resolve <IParameterAlternativeFactory>();
            _compound = _compoundFactory.Create().WithName("Comp");
            _compound.Parameter(Constants.Parameters.MOL_WEIGHT).Value = 250;
            //Two simple parameters without alternatives

            //one parameter defined as a constant for which an alternative was also specififed
            var lipoGroup = _compound.ParameterAlternativeGroup(CoreConstants.Groups.COMPOUND_LIPOPHILICITY);

            _alternativeLipo1 = _parameterAlternativeFactory.CreateAlternativeFor(lipoGroup).WithName("ALT_LIPO1").WithId("ALT_LIPO1");
            _alternativeLipo1.Parameter(CoreConstants.Parameters.LIPOPHILICITY).Value = 2;
            _alternativeLipo2 = _parameterAlternativeFactory.CreateAlternativeFor(lipoGroup).WithName("ALT_LIPO2").WithId("ALT_LIPO2");
            _alternativeLipo2.Parameter(CoreConstants.Parameters.LIPOPHILICITY).Value = 5;
            lipoGroup.AddAlternative(_alternativeLipo1);
            lipoGroup.AddAlternative(_alternativeLipo2);

            //one parameter defined as a formula with a default calculated alternative

            var permAlternativeGroup = _compound.ParameterAlternativeGroup(CoreConstants.Groups.COMPOUND_PERMEABILITY);

            //value cannot be changed by user
            _alternativePerm1 = _parameterAlternativeFactory.CreateDefaultAlternativeFor(permAlternativeGroup).WithName("ALT_PERM1").WithId("ALT_PERM1");
            _alternativePerm2 = _parameterAlternativeFactory.CreateAlternativeFor(permAlternativeGroup).WithName("ALT_PERM2").WithId("ALT_PERM2");
            _alternativePerm2.Parameter(CoreConstants.Parameters.PERMEABILITY).Value = 10;
            permAlternativeGroup.AddAlternative(_alternativePerm1);
            permAlternativeGroup.AddAlternative(_alternativePerm2);
        }
예제 #8
0
        private void updateAlternativeParameters(ParameterAlternative alternative, IMoleculeBuilder drug)
        {
            var allParameters = alternative.AllParameters().ToList();

            foreach (var alternativeParameter in allParameters)
            {
                //Parameter does not exist in drug?
                var drugParameter = drug.Parameter(alternativeParameter.Name);
                if (drugParameter == null)
                {
                    continue;
                }

                //parameter is a rate. parameter in molecule should be readonly
                if (!alternativeParameter.Formula.IsConstant())
                {
                    drugParameter.Editable = false;
                }

                //target parameter is a rate and source parmaeter is constant
                else if (!drugParameter.Formula.IsConstant())
                {
                    drugParameter.Formula = _objectBaseFactory.Create <ConstantFormula>().WithValue(alternativeParameter.Value);
                }

                _parameterSetUpdater.UpdateValue(alternativeParameter, drugParameter);

                //only update value description if the alternative contains one and one only parameter
                if (allParameters.Count == 1)
                {
                    drugParameter.ValueDescription = alternative.Description;
                }
            }
        }
        protected override void Context()
        {
            base.Context();
            _solubilityGroup = new ParameterAlternativeGroup {
                Name = CoreConstants.Groups.COMPOUND_SOLUBILITY
            };
            _refPhParameter          = DomainHelperForSpecs.ConstantParameterWithValue(10).WithName(CoreConstants.Parameters.REFERENCE_PH);
            _solubilityRefPh         = DomainHelperForSpecs.ConstantParameterWithValue(10).WithName(CoreConstants.Parameters.SOLUBILITY_AT_REFERENCE_PH);
            _solubilityTable         = DomainHelperForSpecs.ConstantParameterWithValue(20).WithName(CoreConstants.Parameters.SOLUBILITY_TABLE);
            _solubilityGainParameter = DomainHelperForSpecs.ConstantParameterWithValue(20).WithName(CoreConstants.Parameters.SOLUBILITY_GAIN_PER_CHARGE);

            var compound = new Compound();

            _solubilityAlternativeNameParameter = A.Fake <ISolubilityAlternativeNamePresenter>();
            A.CallTo(() => _applicationController.Start <ISolubilityAlternativeNamePresenter>()).Returns(_solubilityAlternativeNameParameter);
            A.CallTo(() => _solubilityAlternativeNameParameter.Edit(_solubilityGroup)).Returns(true);
            A.CallTo(() => _solubilityAlternativeNameParameter.Name).Returns("new name");
            _solubilityAlternativeNameParameter.CreateAsTable = true;

            _newTableAlternative = new ParameterAlternative {
                _solubilityRefPh, _solubilityTable, _refPhParameter, _solubilityGainParameter
            };

            A.CallTo(() => _parameterAlternativeFactory.CreateTableAlternativeFor(_solubilityGroup, CoreConstants.Parameters.SOLUBILITY_TABLE)).Returns(_newTableAlternative);

            compound.Add(_solubilityGroup);

            _solubilityTableFormula  = new TableFormula();
            _solubilityTable.Formula = _solubilityTableFormula;
        }
        protected override void Context()
        {
            base.Context();
            _compound = new Compound();
            var solDim = new Dimension(new BaseDimensionRepresentation(), "Solubility", "m");

            solDim.AddUnit(new Unit("cm", 0.01, 0));
            _refPhValue         = 7;
            _solValue           = 100;
            _gainPerChargeValue = 1000;
            A.CallTo(() => _formulaFactory.CreateTableFormula()).Returns(new TableFormula());
            var refPh         = DomainHelperForSpecs.ConstantParameterWithValue(_refPhValue).WithName(CoreConstants.Parameter.RefpH).WithDimension(DomainHelperForSpecs.NoDimension());
            var solubilty     = DomainHelperForSpecs.ConstantParameterWithValue(_solValue).WithName(CoreConstants.Parameter.SolubilityAtRefpH).WithDimension(solDim);
            var gainPerCharge = DomainHelperForSpecs.ConstantParameterWithValue(_gainPerChargeValue).WithName(CoreConstants.Parameter.SolubilityGainPerCharge).WithDimension(DomainHelperForSpecs.NoDimension());

            _solubility_pKa_pH_Factor         = new PKSimParameter().WithName(CoreConstants.Parameter.SOLUBILITY_P_KA__P_H_FACTOR);
            _solubility_pKa_pH_Factor.Formula = new ExplicitFormula("10 * (pH +1)");
            _solubility_pKa_pH_Factor.Formula.AddObjectPath(new FormulaUsablePath(new[] { ObjectPath.PARENT_CONTAINER, CoreConstants.Parameter.RefpH }).WithAlias("pH"));
            _compound.Add(refPh);
            _compound.Add(solubilty);
            _compound.Add(gainPerCharge);
            _compound.Add(_solubility_pKa_pH_Factor);
            _solubilityAlternative = new ParameterAlternative();
            _solubilityAlternative.Add(refPh);
            _solubilityAlternative.Add(solubilty);
            _solubilityAlternative.Add(gainPerCharge);

            var solubilityAlternativeGroup = new ParameterAlternativeGroup();

            solubilityAlternativeGroup.AddAlternative(_solubilityAlternative);

            _compound.AddParameterAlternativeGroup(solubilityAlternativeGroup);
        }
예제 #11
0
 private CompoundParameter mapFrom(ParameterAlternative alternative, IParameter parameter)
 {
     return(_parameterElementMapper.MapFrom <CompoundParameter>(parameter, compoundParameter =>
     {
         compoundParameter.Alternative = alternative.Name;
         compoundParameter.Default = alternative.IsDefault;
     }));
 }
예제 #12
0
        public LipophilictyAlternativeDTO MapFrom(ParameterAlternative parameterAlternative)
        {
            var lipophilicity = parameterAlternative.Parameter(CoreConstants.Parameters.LIPOPHILICITY);
            var lipophilictyAlternativeDTO = new LipophilictyAlternativeDTO(parameterAlternative, lipophilicity.ValueOrigin);

            lipophilictyAlternativeDTO.LipophilictyParameter = _parameterDTOMapper.MapFrom(lipophilicity, lipophilictyAlternativeDTO, dto => dto.Lipophilicty, dto => dto.LipophilictyParameter);
            return(lipophilictyAlternativeDTO);
        }
        public PermeabilityAlternativeDTO MapFrom(ParameterAlternative parameterAlternative, string parameterName)
        {
            var permeability = parameterAlternative.Parameter(parameterName);
            var permeabilityAlternativeDTO = new PermeabilityAlternativeDTO(parameterAlternative, permeability.ValueOrigin);

            permeabilityAlternativeDTO.PermeabilityParameter = _parameterDTOMapper.MapFrom(permeability, permeabilityAlternativeDTO, dto => dto.Permeability, dto => dto.PermeabilityParameter);
            return(permeabilityAlternativeDTO);
        }
예제 #14
0
        protected override void Context()
        {
            base.Context();
            var alternative = new ParameterAlternative();

            A.CallTo(() => _objectBaseFactory.Create <ParameterAlternative>()).Returns(alternative);
            _compoundParameterGroup.Name = CoreConstants.Groups.COMPOUND_PERMEABILITY;
        }
 protected override void Context()
 {
     base.Context();
     _alternative           = new ParameterAlternative().WithName("Alt1");
     _alternative.IsDefault = true;
     _groupAlternative      = new ParameterAlternativeGroup();
     _groupAlternative.AddAlternative(_alternative);
     _groupAlternative.AddAlternative(new ParameterAlternative().WithName("Alt2"));
 }
예제 #16
0
        protected override void Context()
        {
            base.Context();
            var alternative = new ParameterAlternative();

            A.CallTo(() => _userSettings.DefaultLipophilicityName).Returns("MyLipo");
            A.CallTo(() => _objectBaseFactory.Create <ParameterAlternative>()).Returns(alternative);
            _compoundParameterGroup.Name = CoreConstants.Groups.COMPOUND_LIPOPHILICITY;
        }
예제 #17
0
        protected override void Context()
        {
            base.Context();
            var alternative = new ParameterAlternative();

            alternative.Add(new PKSimParameter().WithName("toto").WithFormula(new ExplicitFormula("2*3")));
            A.CallTo(() => _objectBaseFactory.Create <PKSim.Core.Model.ParameterAlternative>()).Returns(alternative);
            A.CallTo(() => _objectBaseFactory.Create <ConstantFormula>()).Returns(new ConstantFormula());
            _compoundParameterGroup.Name = CoreConstants.Groups.COMPOUND_PERMEABILITY;
        }
        private bool simulationsAreUsingAlternative(ParameterAlternative alternative)
        {
            var allCompoundGroupSelectionForAlternativeGroup = _buildingBlockRepository.All <Simulation>()
                                                               .SelectMany(x => x.CompoundPropertiesList)
                                                               .SelectMany(x => x.CompoundGroupSelections
                                                                           .Where(groupSel => string.Equals(groupSel.GroupName, alternative.GroupName))
                                                                           );

            return(allCompoundGroupSelectionForAlternativeGroup.Any(x => string.Equals(x.AlternativeName, alternative.Name)));
        }
        public LipophilictyAlternativeDTO MapFrom(ParameterAlternative parameterAlternative)
        {
            var lipophilictyAlternativeDTO = new LipophilictyAlternativeDTO(parameterAlternative);

            var lipophilicity = parameterAlternative.Parameter(CoreConstants.Parameter.Lipophilicity);

            lipophilictyAlternativeDTO.LipophilictyParameter = _parameterDTOMapper.MapFrom(lipophilicity, lipophilictyAlternativeDTO, dto => dto.Lipophilicty, dto => dto.LipophilictyParameter);

            return(lipophilictyAlternativeDTO);
        }
 protected override void Context()
 {
     base.Context();
     _group          = new ParameterAlternativeGroup();
     _newAlternative = new ParameterAlternative();
     A.CallTo(() => _parameterAlternativeFactory.CreateAlternativeFor(_group)).Returns(_newAlternative);
     _parameterAlternativePresenter = A.Fake <IParameterAlternativeNamePresenter>();
     A.CallTo(() => _parameterAlternativePresenter.Edit(_group)).Returns(true);
     A.CallTo(() => _parameterAlternativePresenter.Name).Returns("new name");
     A.CallTo(() => _applicationController.Start <IParameterAlternativeNamePresenter>()).Returns(_parameterAlternativePresenter);
 }
        protected override void Context()
        {
            base.Context();
            var lipoGroup = new ParameterAlternativeGroup().WithName(CoreConstants.Groups.COMPOUND_LIPOPHILICITY);

            _alternative            = new ParameterAlternative().WithName("ALT1");
            _parameterInAlternative = DomainHelperForSpecs.ConstantParameterWithValue(1).WithName(CoreConstants.Parameters.LIPOPHILICITY);
            _alternative.Add(_parameterInAlternative);
            lipoGroup.AddAlternative(_alternative);
            var simulation = A.Fake <Simulation>();

            A.CallTo(() => _buildingBlockRepository.All <Simulation>()).Returns(new[] { simulation });
        }
        public void PrepareSolubilityAlternativeForTableSolubility(ParameterAlternative solubilityAlternative)
        {
            var solubilityAtRefPhParameter = solubilityAlternative.Parameter(CoreConstants.Parameters.SOLUBILITY_AT_REFERENCE_PH);
            var phParameter             = solubilityAlternative.Parameter(CoreConstants.Parameters.REFERENCE_PH);
            var solubilityGainParameter = solubilityAlternative.Parameter(CoreConstants.Parameters.SOLUBILITY_GAIN_PER_CHARGE);

            resetParameters(solubilityGainParameter, solubilityAtRefPhParameter, phParameter);
            solubilityAtRefPhParameter.Value = 0;

            var tableParameter = solubilityAlternative.Parameter(CoreConstants.Parameters.SOLUBILITY_TABLE);

            tableParameter.Visible   = true;
            tableParameter.IsDefault = false;
        }
 protected override void Context()
 {
     base.Context();
     _solubilityAlternativeNameParameter = A.Fake <ISolubilityAlternativeNamePresenter>();
     _solubilityGroup = new ParameterAlternativeGroup {
         Name = CoreConstants.Groups.COMPOUND_SOLUBILITY
     };
     A.CallTo(() => _applicationController.Start <ISolubilityAlternativeNamePresenter>()).Returns(_solubilityAlternativeNameParameter);
     A.CallTo(() => _solubilityAlternativeNameParameter.Edit(_solubilityGroup)).Returns(true);
     A.CallTo(() => _solubilityAlternativeNameParameter.Name).Returns("new name");
     _solubilityAlternativeNameParameter.CreateAsTable = false;
     _newAlternative = new ParameterAlternative();
     A.CallTo(() => _parameterAlternativeFactory.CreateAlternativeFor(_solubilityGroup)).Returns(_newAlternative);
 }
 public SetDefaultAlternativeParameterCommand(ParameterAlternativeGroup parameterGroup, ParameterAlternative parameterAlternative, IExecutionContext context)
 {
     _parameterGroup          = parameterGroup;
     _parameterGroupId        = _parameterGroup.Id;
     _parameterAlternative    = parameterAlternative;
     _oldDefaultAlternative   = parameterGroup.DefaultAlternative;
     _oldDefaultAlternativeId = _oldDefaultAlternative.Id;
     ObjectType          = PKSimConstants.ObjectTypes.Compound;
     CommandType         = PKSimConstants.Command.CommandTypeEdit;
     BuildingBlockId     = context.BuildingBlockIdContaining(parameterGroup);
     Description         = PKSimConstants.Command.SetDefaultAlternativeParameterDescription(context.DisplayNameFor(parameterGroup), _oldDefaultAlternative.Name, parameterAlternative.Name);
     ShouldChangeVersion = false;
     context.UpdateBuildingBlockPropertiesInCommand(this, context.BuildingBlockContaining(parameterGroup));
 }
예제 #25
0
        public SolubilityAlternativeDTO MapFrom(ParameterAlternative parameterAlternative)
        {
            var solubilityAlternativeDTO = new SolubilityAlternativeDTO(parameterAlternative);

            var solubility    = parameterAlternative.Parameter(CoreConstants.Parameter.SolubilityAtRefpH);
            var refPh         = parameterAlternative.Parameter(CoreConstants.Parameter.RefpH);
            var gainPerCharge = parameterAlternative.Parameter(CoreConstants.Parameter.SolubilityGainPerCharge);

            solubilityAlternativeDTO.SolubilityParameter    = _parameterDTOMapper.MapFrom(solubility, solubilityAlternativeDTO, dto => dto.Solubility, dto => dto.SolubilityParameter);
            solubilityAlternativeDTO.RefpHParameter         = _parameterDTOMapper.MapFrom(refPh, solubilityAlternativeDTO, dto => dto.RefpH, dto => dto.RefpHParameter);
            solubilityAlternativeDTO.GainPerChargeParameter = _parameterDTOMapper.MapFrom(gainPerCharge, solubilityAlternativeDTO, dto => dto.GainPerCharge, dto => dto.GainPerChargeParameter);

            return(solubilityAlternativeDTO);
        }
        protected override void Context()
        {
            base.Context();
            //A compound with 2 lipo alternatives and MolWeight Eff
            _compound = new CompoundFactoryForSpecs().Create();
            var lipoGroup = new ParameterAlternativeGroup().WithName(CoreConstants.Groups.COMPOUND_LIPOPHILICITY);

            _alternative1 = new ParameterAlternative().WithName("ALT1");
            _alternative1.Add(DomainHelperForSpecs.ConstantParameterWithValue(1).WithName(CoreConstants.Parameters.LIPOPHILICITY));
            lipoGroup.AddAlternative(_alternative1);

            _alternative2 = new ParameterAlternative().WithName("ALT2");
            _alternative2.Add(DomainHelperForSpecs.ConstantParameterWithValue(2).WithName(CoreConstants.Parameters.LIPOPHILICITY));
            lipoGroup.AddAlternative(_alternative2);
            _compound.AddParameterAlternativeGroup(lipoGroup);
        }
        protected override void Context()
        {
            _view                    = A.Fake <ILipophilicityGroupView>();
            _dialogCreator           = A.Fake <IDialogCreator>();
            _compoundAlternativeTask = A.Fake <ICompoundAlternativeTask>();
            _reprInfoRepo            = A.Fake <IRepresentationInfoRepository>();
            _alternativeDTOMapper    = A.Fake <IParameterGroupAlternativeToLipophilicityAlternativeDTOMapper>();
            _compoundParamGroup      = new ParameterAlternativeGroup();
            _existingAlternative     = new ParameterAlternative().WithName("Existing").WithId("ID_Existing");
            _compoundParamGroup.AddAlternative(_existingAlternative);
            _compoundAlternativePresentationTask = A.Fake <ICompoundAlternativePresentationTask>();
            _newAlternative = new ParameterAlternative().WithName("New").WithId("ID_New");
            sut             = new LipophilicityGroupPresenter(_view, _compoundAlternativeTask, _compoundAlternativePresentationTask, _reprInfoRepo, _alternativeDTOMapper, _dialogCreator);

            _commandRegister = A.Fake <ICommandCollector>();
            sut.InitializeWith(_commandRegister);
        }
예제 #28
0
        protected override void Context()
        {
            base.Context();
            var parameter = new PKSimParameter {
                IsDefault = true
            }.WithName("toto").WithFormula(new ExplicitFormula("2*3"));

            parameter.ValueOrigin.Id     = 5;
            parameter.ValueOrigin.Method = ValueOriginDeterminationMethods.InVitro;
            var alternative = new ParameterAlternative {
                parameter
            };

            _nanConstantFormula = new ConstantFormula();
            A.CallTo(() => _objectBaseFactory.Create <ParameterAlternative>()).Returns(alternative);
            A.CallTo(() => _formulaFactory.ValueFor(double.NaN, parameter.Dimension)).Returns(_nanConstantFormula);
            _compoundParameterGroup.Name = CoreConstants.Groups.COMPOUND_PERMEABILITY;
        }
        public TableFormula SolubilityTableForPh(ParameterAlternative solubilityAlternative, Compound compound)
        {
            //Already a table formula. Use as IS!
            var tableSolubility = solubilityAlternative.Parameter(CoreConstants.Parameters.SOLUBILITY_TABLE);

            if (tableSolubility.Formula.IsTable())
            {
                return(tableSolubility.Formula.DowncastTo <TableFormula>());
            }

            //Sol(pH) = ref_Solubility * Solubility_Factor (ref_pH) / Solubility_Factor(pH)
            //Solubility_pKa_pH_Factor

            var refSolubility      = solubilityAlternative.Parameter(CoreConstants.Parameters.SOLUBILITY_AT_REFERENCE_PH);
            var refPh              = solubilityAlternative.Parameter(CoreConstants.Parameters.REFERENCE_PH);
            var gainPerCharge      = solubilityAlternative.Parameter(CoreConstants.Parameters.SOLUBILITY_GAIN_PER_CHARGE);
            var refSolubilityValue = refSolubility.Value;

            var compoundForCalculation = _executionContext.Clone(compound);
            var formula = initializeSolubilityTableFormula(_formulaFactory.CreateTableFormula(), refPh.Dimension, refSolubility.Dimension);

            compoundForCalculation.Parameter(CoreConstants.Parameters.REFERENCE_PH).Value = refPh.Value;
            compoundForCalculation.Parameter(CoreConstants.Parameters.SOLUBILITY_GAIN_PER_CHARGE).Value = gainPerCharge.Value;

            double solFactorRefpH = compoundForCalculation.Parameter(CoreConstants.Parameters.SOLUBILITY_P_KA__P_H_FACTOR).Value;
            var    allPh          = new List <double>();
            int    ph             = 0;

            while (ph <= 13)
            {
                allPh.AddRange(new[] { ph, ph + 0.5 });
                ph++;
            }

            allPh.Add(14);
            foreach (var pH in allPh)
            {
                compoundForCalculation.Parameter(CoreConstants.Parameters.REFERENCE_PH).Value = pH;
                double solFactorAtpH = compoundForCalculation.Parameter(CoreConstants.Parameters.SOLUBILITY_P_KA__P_H_FACTOR).Value;
                formula.AddPoint(pH, refSolubilityValue * solFactorRefpH / solFactorAtpH);
            }

            return(formula);
        }
예제 #30
0
        protected override async Task Context()
        {
            await base.Context();

            _snapshot = await sut.MapToSnapshot(_alternativeWithSpecies);

            var newAlternative = new ParameterAlternative();

            A.CallTo(() => _parameterAlternativeFactory.CreateAlternativeFor(_parameterGroup)).Returns(newAlternative);
            _parameterGroup.Name = CoreConstants.Groups.COMPOUND_SOLUBILITY;

            _snapshotParameter = new Parameter {
                Name = CoreConstants.Parameters.SOLUBILITY_TABLE
            };
            _alternativeParameter         = DomainHelperForSpecs.ConstantParameterWithValue(1).WithName(_snapshotParameter.Name);
            _alternativeParameter.Formula = new OSPSuite.Core.Domain.Formulas.TableFormula();
            newAlternative.Add(_alternativeParameter);
            _snapshot.Parameters = new[] { _snapshotParameter };
        }