/// <summary> /// Expression evaluator /// </summary> public NoStringEvaluator(ObjectPool <Stack <InternalEvaluatorValue> > stackPool, ObjectPool <List <InternalEvaluatorValue> > argsPool, ObjectPool <ExtraTypeIdContainer> extraTypeIdContainerPool, IFormulaCache formulaCache) { _stackPool = stackPool; _argsPool = argsPool; _extraTypeIdContainerPool = extraTypeIdContainerPool; _formulaCache = formulaCache; }
private IFormula checkFormula(IFormulaCache formulaCache, IFormula formula) { if (formula.IsExplicit()) { return(checkFormulaByType(formulaCache, (ExplicitFormula)formula, AreEqualExplicitFormula)); } if (formula.IsBlackBox()) { return(checkFormulaByType(formulaCache, (BlackBoxFormula)formula, AreEqualBalckBoxFormula)); } if (formula.IsTable()) { return(checkFormulaByType(formulaCache, (TableFormula)formula, AreEqualTableFormula)); } if (formula.IsTableWithOffSet()) { return(checkFormulaByType(formulaCache, (TableFormulaWithOffset)formula, AreEqualTableFormulaWithOffset)); } if (formula.IsDynamic()) { return(checkFormulaByType(formulaCache, (SumFormula)formula, AreEqualSumFormula)); } return(formula); }
private IMoleculeBuilder createFor(QuantityType moleculeType, IFormulaCache formulaCache) { switch (moleculeType) { case QuantityType.Drug: return(_moleculeMapper.MapFrom(_flatMoleculeRepository.FindBy(QuantityType.Drug), formulaCache) .WithIcon(ApplicationIcons.Drug.IconName)); case QuantityType.Enzyme: case QuantityType.OtherProtein: return(defaultProteinMoleculeFrom(moleculeType, formulaCache)); case QuantityType.Transporter: return(defaultTransporterMoleculeFrom(formulaCache)); case QuantityType.Metabolite: case QuantityType.Complex: return(defaultReactionProduct(moleculeType, formulaCache)); case QuantityType.Undefined: return(defaultFloatingNonXenobioticMolecule(moleculeType, formulaCache)); default: throw new ArgumentOutOfRangeException(nameof(moleculeType)); } }
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); }
private IMoleculeBuilder defaultTransporterMoleculeFrom(IFormulaCache formulaCache) { var transporter = defaultProteinMoleculeFrom(QuantityType.Transporter, formulaCache); removeGlobalExpressionsParameterFor(transporter); return(transporter); }
public IFormula RateFor(RateKey rateKey, IFormulaCache formulaCache) { if (rateKey == null) { return(null); } //no formula cache defined. Formula should be unique by id if (formulaCache == null) { return(createFormula(rateKey).WithId(_idGenerator.NewId())); } if (!formulaCache.Contains(rateKey)) { var formula = createFormula(rateKey); if (formula.IsConstant()) { return(formula); } formulaCache.Add(formula); } return(formulaCache[rateKey]); }
protected override void Context() { _formulaCache = A.Fake <IFormulaCache>(); _repository = A.Fake <IRepository <IInteractionKineticUpdaterSpecification> >(); _objectBaseFactory = A.Fake <IObjectBaseFactory>(); A.CallTo(() => _objectBaseFactory.Create <ExplicitFormula>()).ReturnsLazily(x => new ExplicitFormula()); A.CallTo(() => _repository.All()).Returns(_allKineticUpdaterSpecifications); sut = new InteractionKineticUpdater(_repository, _objectBaseFactory); _reaction = new ReactionBuilder(); _transporterMoleculeContainer = new TransporterMoleculeContainer(); _simulation = A.Fake <Simulation>(); _interactionProperties = new InteractionProperties(); _interactionProperties.AddInteraction(new InteractionSelection { MoleculeName = _enzymeName, ProcessName = _processName }); A.CallTo(() => _simulation.InteractionProperties).Returns(_interactionProperties); _kmFactor = new PKSimParameter().WithName(CoreConstants.Parameter.KM_INTERACTION_FACTOR).WithFormula(new ExplicitFormula("1")); _vmaxFactor = new PKSimParameter().WithName(CoreConstants.Parameter.KCAT_INTERACTION_FACTOR).WithFormula(new ExplicitFormula("1")); _reaction.Add(_kmFactor); _reaction.Add(_vmaxFactor); _transporterMoleculeContainer.Add(_kmFactor); _transporterMoleculeContainer.Add(_vmaxFactor); }
public IParameterStartValuesBuildingBlock CreateFor(IBuildConfiguration buildConfiguration, Simulation simulation) { try { //default default parameter start values matrix _spatialStructure = buildConfiguration.SpatialStructure; _defaultStartValues = _parameterStartValuesCreator.CreateFrom(_spatialStructure, buildConfiguration.Molecules); _formulaCache = _defaultStartValues.FormulaCache; var individual = simulation.Individual; //set the relative expression values for each protein defined in individual foreach (var protein in individual.AllMolecules <IndividualProtein>()) { updateProteinParametersValues(protein); } foreach (var transporter in individual.AllMolecules <IndividualTransporter>()) { updateTransporterParameterValues(transporter); } updateSimulationParameters(simulation); return(_defaultStartValues.WithName(simulation.Name)); } finally { _spatialStructure = null; _defaultStartValues = null; _formulaCache = null; } }
private void updateDose(ISchemaItem schemaItem, IContainer targetContainer, IFormulaCache formulaCache) { //now that parameter have been set, we need to update the dose by hand according to the selected unit var inputDose = schemaItem.Dose; var dose = targetContainer.Parameter(CoreConstants.Parameters.DOSE); var dosePerBodyWeight = targetContainer.Parameter(CoreConstants.Parameters.DOSE_PER_BODY_WEIGHT); var dosePerBodySurfaceArea = targetContainer.Parameter(CoreConstants.Parameters.DOSE_PER_BODY_SURFACE_AREA); if (schemaItem.DoseIsInMass()) { //we have to create a constant value for the dose parameter dose.Formula = _formulaFactory.ValueFor(inputDose.Value, _dimensionRepository.Mass); updateDoseParameter(inputDose, dose, dosePerBodyWeight, dosePerBodySurfaceArea); } else if (schemaItem.DoseIsPerBodyWeight()) { dose.Formula = _formulaFactory.DoseFromDosePerBodyWeightFor(formulaCache); updateDoseParameter(inputDose, dosePerBodyWeight, dose, dosePerBodySurfaceArea); } else if (schemaItem.DoseIsPerBodySurfaceArea()) { dose.Formula = _formulaFactory.DoseFromDosePerBodySurfaceAreaFor(formulaCache); updateDoseParameter(inputDose, dosePerBodySurfaceArea, dose, dosePerBodyWeight); } }
public void Convert(IMoleculeStartValue moleculeStartValue, IFormulaCache formulaCache) { if (!conversionRequired(moleculeStartValue)) { return; } moleculeStartValue.Dimension = _concentrationDimension; moleculeStartValue.DisplayUnit = _displayUnitRetriever.PreferredUnitFor(moleculeStartValue); if (moleculeStartValue.Formula.IsExplicit()) { convertExplicitFormula(moleculeStartValue.Formula, _concentrationDimension); return; } var startValue = moleculeStartValue.StartValue.GetValueOrDefault(0); if (startValue == 0) { return; } moleculeStartValue.Formula = createConcentrationFormulaFromConstantValue(startValue, moleculeStartValue.Path.ToPathString(), formulaCache); }
private void updateInteractionFactor(IContainer processParameterContainer, string compoundName, IEnumerable <IInteractionKineticUpdaterSpecification> allUpdatingKinetics, IFormulaCache formulaCache, string parameterName, Func <IParameter, string> createFormulaAction) { var interactionFactor = processParameterContainer.Parameter(parameterName); if (!allUpdatingKinetics.Any() || interactionFactor == null) { return; } var formulaName = CoreConstants.CompositeNameFor(processParameterContainer.Name, compoundName, parameterName); if (formulaCache.FindByName(formulaName) is ExplicitFormula formula) { interactionFactor.Formula = formula; return; } formula = _objectBaseFactory.Create <ExplicitFormula>() .WithName(formulaName) .WithDimension(interactionFactor.Dimension); interactionFactor.Formula = formula; formula.FormulaString = createFormulaAction(interactionFactor); formulaCache.Add(formula); }
public FlatEventChangedObjectToEventAssignmentBuilderMapper(IObjectBaseFactory objectBaseFactory, IFormulaFactory formulaFactory, IFlatObjectPathToObjectPathMapper objectPathMapper) { _objectBaseFactory = objectBaseFactory; _formulaFactory = formulaFactory; _objectPathMapper = objectPathMapper; _formulaCache = new FormulaCache(); }
/// <summary> /// Add start formula for the drug molecule. Will be created in the root application container /// </summary> private void addDrugStartFormula(IApplicationBuilder applicationBuilder, IFormulaCache formulaCache) { var applicationMoleculeBuilder = _objectBaseFactory.Create <IApplicationMoleculeBuilder>().WithName(applicationBuilder.Name); applicationMoleculeBuilder.RelativeContainerPath = _objectPathFactory.CreateObjectPathFrom(ObjectPath.PARENT_CONTAINER, applicationBuilder.Name); applicationMoleculeBuilder.Formula = _formulaFactory.DrugMassFormulaFor(formulaCache); applicationBuilder.AddMolecule(applicationMoleculeBuilder); }
protected override void Context() { base.Context(); _exisitingFormula = A.Fake <IFormula>().WithId(CoreConstants.Formula.Concentration); _formulaCache = new FormulaCache { _exisitingFormula }; }
public IFormula RHSRateFor(ParameterRateMetaData parameterRateDefinition, IFormulaCache formulaCache) { if (string.IsNullOrEmpty(parameterRateDefinition.RHSRate)) { return(null); } return(RateFor(parameterRateDefinition.CalculationMethod, parameterRateDefinition.RHSRate, formulaCache)); }
protected override void Context() { _dimensionRepository = A.Fake <IDimensionFactory>(); _dataRepositoryTask = A.Fake <IDataRepositoryTask>(); A.CallTo(() => _dimensionRepository.NoDimension).Returns(new Dimension()); _objectBaseFactory = new ObjectBaseFactoryForSpecs(_dimensionRepository); _objectToClone = createEntityToClone(); _formulaCache = new FormulaCache(); sut = new CloneManagerForBuildingBlock(_objectBaseFactory, _dataRepositoryTask); }
public IParameter CreateConcentrationParameterIn(IFormulaCache formulaCache) { var parameter = CreateFor(CoreConstants.Parameter.CONCENTRATION, PKSimBuildingBlockType.Simulation); parameter.BuildMode = ParameterBuildMode.Local; parameter.Info.Visible = false; parameter.Formula = _formulaFactory.ConcentrationFormulaFor(formulaCache); parameter.Dimension = _dimensionRepository.MolarConcentration; return(parameter); }
public IMoleculeBuilder Create(QuantityType moleculeType, IFormulaCache formulaCache) { var moleculeBuilder = createFor(moleculeType, formulaCache); moleculeBuilder.Dimension = _dimensionRepository.Amount; moleculeBuilder.DefaultStartFormula.Dimension = _dimensionRepository.Amount; addFormulaToCacheIfNecessary(moleculeBuilder.DefaultStartFormula, formulaCache); addConcentrationParmeterTo(moleculeBuilder, formulaCache); return(moleculeBuilder); }
public void Convert(IReactionBuilder reaction, IFormulaCache formulaCache) { if (!conversionRequired(reaction)) { return; } reaction.Dimension = _concentrationPerTimeDimension; convertExplicitFormula(reaction.Formula, _concentrationPerTimeDimension); }
public T Clone <T>(T objectToClone, IFormulaCache formulaCache) where T : class, IObjectBase { if (formulaCache == null) { throw new ArgumentNullException(Error.NullFormulaCachePassedToClone); } FormulaCache = formulaCache; return(Clone(objectToClone)); }
public IParameter CreateConcentrationParameter(IFormulaCache formulaCache) { var concentrationFormula = _formulaFactory.ConcentrationFormulaFor(formulaCache); var molarConcentrationDimension = _dimensionFactory.Dimension(Constants.Dimension.MOLAR_CONCENTRATION); var concentrationParameter = CreateParameter(Constants.Parameters.CONCENTRATION, dimension: molarConcentrationDimension, formula: concentrationFormula) .WithMode(ParameterBuildMode.Local); concentrationParameter.Info.ReadOnly = true; return(concentrationParameter); }
protected override void Context() { base.Context(); _buildingBlockToAddTo = A.Fake <IBuildingBlock>(); _formulaCache = new FormulaCache(); A.CallTo(() => _buildingBlockToAddTo.FormulaCache).Returns(_formulaCache); _totalyNewObject = new MoleculeBuilder().WithName("New"); _newFormula = A.Fake <ExplicitFormula>().WithName("New Formula").WithDimension(A.Fake <IDimension>()).WithFormulaString("1+1").WithId("1"); _newFormula.ObjectPaths = new IFormulaUsablePath[0]; _totalyNewObject.DefaultStartFormula = _newFormula; }
protected override void Context() { base.Context(); _buildingBlockToAddTo = A.Fake <IBuildingBlock>(); _formulaCache = new FormulaCache(); A.CallTo(() => _buildingBlockToAddTo.FormulaCache).Returns(_formulaCache); _totalyNewObject = new Parameter().WithName("New"); _newFormula = A.Fake <ExplicitFormula>().WithName("New Formula").WithDimension(A.Fake <IDimension>()).WithFormulaString("1+1").WithId("1"); _newFormula.ObjectPaths = new IFormulaUsablePath[0]; _totalyNewObject.Formula = _newFormula; A.CallTo(() => _objectBaseRepository.ContainsObjectWithId(A <string> ._)).Returns(false); }
protected override void Context() { base.Context(); _rateKey = new RateKey("CM1", "Rate1"); _formulaCache = new FormulaCache(); A.CallTo(() => _rateFormulaRepository.FormulaFor(_rateKey)).Returns("Time * 2"); A.CallTo(() => _objectBaseFactory.Create <ExplicitFormula>()).Returns(new ExplicitFormula()); A.CallTo(() => _rateObjectPathsRepository.ObjectPathsFor(_rateKey)).Returns( new List <IFormulaUsablePath>()); }
protected override void Context() { base.Context(); _formulaCache = A.Fake <IFormulaCache>(); _parameterRateDefinition = new ParameterRateMetaData(); _parameterRateDefinition.ParameterName = "Tralal"; _rateFormula = A.Fake <IFormula>(); _parameter = A.Fake <IParameter>(); A.CallTo(() => _formulaFactory.RateFor(_parameterRateDefinition, _formulaCache)).Returns(_rateFormula); A.CallTo(() => _objectBaseFactory.CreateParameter()).Returns(_parameter); A.CallTo(() => _dimensionRepository.DimensionByName(_parameterRateDefinition.Dimension)).Returns(_dimension); }
private IMoleculeBuilder defaultReactionProduct(QuantityType moleculeType, IFormulaCache formulaCache) { var metabolite = _objectBaseFactory.Create <IMoleculeBuilder>(); addDrugParametersTo(metabolite, formulaCache); metabolite.QuantityType = moleculeType; metabolite.Name = moleculeType.ToString(); metabolite.DefaultStartFormula = _objectBaseFactory.Create <ConstantFormula>().WithValue(0); metabolite.IsFloating = false; metabolite.IsXenobiotic = true; return(metabolite); }
/// <summary> /// add the given formula to the cache only if /// 1- the formula is not constant (constant formula are not registered in cache) /// 2- the formula was not registered already. /// </summary> /// <param name="formula">formula to add</param> /// <param name="formulaCache">formula cache</param> private void addFormulaToCacheIfNecessary(IFormula formula, IFormulaCache formulaCache) { if (formula.IsConstant()) { return; } if (formulaCache.Contains(formula.Id)) { return; } formulaCache.Add(formula); }
protected override void Context() { base.Context(); _formulaCache = A.Fake <IFormulaCache>(); _pkSimTransport = new PKSimTransport { Formula = A.Fake <IFormula>() }; _process = new SystemicProcess { InternalName = "Proc", Name = "BLA BLA" }; A.CallTo(() => _simulationActiveProcessRepository.ProcessFor <PKSimTransport>(_process.InternalName)).Returns(_pkSimTransport); A.CallTo(() => _cloneManager.Clone(_pkSimTransport)).Returns(_pkSimTransport); }
public IMoleculeBuilder MapFrom(FlatMolecule flatMolecule, IFormulaCache formulaCache) { var molecule = _objectBaseFactory.Create <IMoleculeBuilder>(); molecule.Name = flatMolecule.Id; molecule.IsFloating = flatMolecule.IsFloating; molecule.QuantityType = flatMolecule.MoleculeType; molecule.DefaultStartFormula = _formulaFactory.RateFor(flatMolecule, new FormulaCache()); _parameterContainerTask.AddMoleculeParametersTo(molecule, formulaCache); return(molecule); }
protected override void Context() { base.Context(); _formulaCache = new FormulaCache(); _protein = A.Fake <IMoleculeBuilder>().WithName("CYP3A4"); var reaction = new ReactionBuilder { Formula = new ExplicitFormula().WithName("ABC") }; reaction.Formula.AddObjectPath(new FormulaUsablePath(CoreConstants.KeyWords.Protein, "P1").WithAlias("P1")); reaction.Formula.AddObjectPath(new FormulaUsablePath(CoreConstants.KeyWords.Reaction, "R1").WithAlias("R1")); _template = A.Fake <IReactionBuilder>().WithName(CoreConstants.Reaction.TURNOVER); A.CallTo(() => _cloneManager.Clone(_template)).Returns(reaction); }