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]); }
private void updateInteractionFactor(IContainer processParameterContainer, string moleculeName, 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, moleculeName, parameterName); var formula = formulaCache.FindByName(formulaName) as ExplicitFormula; if (formula != null) { interactionFactor.Formula = formula; return; } formula = _objectBaseFactory.Create <ExplicitFormula>() .WithName(formulaName) .WithDimension(interactionFactor.Dimension); interactionFactor.Formula = formula; formula.FormulaString = createFormulaAction(interactionFactor); formulaCache.Add(formula); }
protected override void Context() { base.Context(); _parameter = A.Fake <IParameter>(); _buidingBlockWithFormulaCache = A.Fake <IBuildingBlock>(); _formulaCache = new FormulaCache(); A.CallTo(() => _buidingBlockWithFormulaCache.FormulaCache).Returns(_formulaCache); _formulaCache.Add(new ExplicitFormula().WithId("A").WithName("A")); _formulaCache.Add(new TableFormulaWithOffset().WithId("B").WithName("B")); _formulaCache.Add(new SumFormula().WithId("C").WithName("C")); A.CallTo(() => _formulaTask.CreateNewFormulaInBuildingBlock(A <Type> ._, A <IDimension> ._, A <IEnumerable <string> > ._, _buidingBlockWithFormulaCache)) .Invokes(x => _availableFormulaNames = x.GetArgument <IEnumerable <string> >(2)) .Returns((A.Fake <IMoBiCommand>(), null)); sut.Init(_parameter, _buidingBlockWithFormulaCache, new UsingFormulaDecoder()); }
private ExplicitFormula createConcentrationFormulaFromConstantValue(double defaultStartValue, string usingFormulaName, IFormulaCache formulaCache) { var explicitFormulaInConcentration = _objectBaseFactory.Create <ExplicitFormula>() .WithName($"Amount_to_concentration for {usingFormulaName}") .WithDimension(_concentrationDimension); var volumeAlias = _formulaTask.AddParentVolumeReferenceToFormula(explicitFormulaInConcentration); explicitFormulaInConcentration.FormulaString = $"{defaultStartValue.ConvertedTo<string>()}/{volumeAlias}"; formulaCache.Add(explicitFormulaInConcentration); return(explicitFormulaInConcentration); }
public ITransportBuilder PassiveTransportProcessFrom(CompoundProcess compoundProcess, string compoundName, IFormulaCache formulaCache) { var passiveProcess = _cloner.Clone(_simulationActiveProcessRepository.ProcessFor <PKSimTransport>(compoundProcess.InternalName)); passiveProcess.Name = compoundProcess.Name; passiveProcess.ForAll = false; passiveProcess.AddMoleculeName(compoundName); updateTransporterFormulaFromCache(passiveProcess, formulaCache); passiveProcess.Parameters.Where(x => !x.Formula.IsConstant()).Each(p => formulaCache.Add(p.Formula)); _parameterSetUpdater.UpdateValuesByName(compoundProcess.AllParameters(), passiveProcess.Parameters); return(passiveProcess); }
/// <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); }
private IReactionBuilder interactionReactionFrom(InteractionProcess interactionProcess, IMoleculeBuilder protein, IReadOnlyCollection <string> forbiddenNames, IFormulaCache formulaCache) { var compound = interactionProcess.ParentCompound; var reactionName = CoreConstants.CompositeNameFor(compound.Name, interactionProcess.Name); var reaction = createReactionFromProcess(interactionProcess, reactionName, forbiddenNames); //replace keywords replaceKeywordsInProcess(reaction, new[] { CoreConstants.KeyWords.Molecule, CoreConstants.KeyWords.Protein, CoreConstants.KeyWords.Reaction }, new[] { compound.Name, protein.Name, interactionProcess.Name }); formulaCache.Add(reaction.Formula); return(reaction); }
public IReactionBuilder TurnoverReactionFrom(IReactionBuilder templateReaction, IMoleculeBuilder protein, IReadOnlyCollection <string> forbiddenNames, IFormulaCache formulaCache) { var reaction = createReactionFromProcess(templateReaction, forbiddenNames); reaction.Name = reactionNameFor(reaction.Name, protein.Name); reaction.Formula.Name = CoreConstants.CompositeNameFor(reaction.Name, reaction.Formula.Name); replaceKeywordsInProcess(reaction, new[] { CoreConstants.KeyWords.Protein, CoreConstants.KeyWords.Reaction }, new[] { protein.Name, reaction.Name }); reaction.AddProduct(new ReactionPartnerBuilder(protein.Name, 1)); formulaCache.Add(reaction.Formula); return(reaction); }
private void updateTransporterFormulaFromCache(ITransportBuilder transportBuilder, IFormulaCache formulaCache) { var formula = transportBuilder.Formula; //only add transporter formula if not already defined in the cache if (formulaCache.ExistsByName(formula.Name)) { transportBuilder.Formula = formulaCache.FindByName(formula.Name); } else { formulaCache.Add(formula); } }
private IFormula insolubleDrugStartFormula(IFormulaCache formulaCache) { if (formulaCache.ExistsByName(CoreConstants.Formula.InsolubleDrugStartFormula)) { return(formulaCache.FindByName(CoreConstants.Formula.InsolubleDrugStartFormula)); } var moleculeStartFormula = _objectBaseFactory.Create <ExplicitFormula>() .WithName(CoreConstants.Formula.InsolubleDrugStartFormula) .WithDimension(_dimensionRepository.Amount) .WithFormulaString("0"); formulaCache.Add(moleculeStartFormula); return(moleculeStartFormula); }
protected override void Context() { base.Context(); _buildingBlockToAddTo = A.Fake <IBuildingBlock>(); _formulaCache = new FormulaCache(); A.CallTo(() => _buildingBlockToAddTo.FormulaCache).Returns(_formulaCache); _totalyNewObject = new Parameter().WithName("New"); _theDimension = A.Fake <IDimension>(); _oldFormula = A.Fake <ExplicitFormula>().WithName("New Formula").WithDimension(_theDimension).WithFormulaString("1+1").WithId("1"); _newFormula = A.Fake <ExplicitFormula>().WithName("New Formula_2").WithDimension(_theDimension).WithFormulaString("1+1").WithId("1"); _newFormula.ObjectPaths = new IFormulaUsablePath[0]; _oldFormula.ObjectPaths = new IFormulaUsablePath[0]; _formulaCache.Add(_oldFormula); _totalyNewObject.Formula = _newFormula; }
public IReactionBuilder ComplexReactionFrom(CompoundProcess process, IMoleculeBuilder compoundBuilder, IMoleculeBuilder complex, string enzymeName, IReadOnlyCollection <string> forbiddenNames, IFormulaCache formulaCache) { //retrieve process for the simulation and create a clone var reaction = createReactionFromProcess(compoundBuilder, process, forbiddenNames); //replace keywords replaceKeywordsInProcess(reaction, new[] { CoreConstants.KeyWords.Molecule, CoreConstants.KeyWords.Protein, CoreConstants.KeyWords.Complex, CoreConstants.KeyWords.Reaction }, new[] { compoundBuilder.Name, enzymeName, complex.Name, reaction.Name }); reaction.AddEduct(new ReactionPartnerBuilder(compoundBuilder.Name, 1)); reaction.AddEduct(new ReactionPartnerBuilder(enzymeName, 1)); reaction.AddProduct(new ReactionPartnerBuilder(complex.Name, 1)); formulaCache.Add(reaction.Formula); return(reaction); }
public IReactionBuilder ReactionFrom(IReactionBuilder templateReactionBuilder, string compoundName, IReadOnlyCollection <string> forbiddenNames, IFormulaCache formulaCache) { //retrieve process for the simulation and create a clone var reaction = createReactionFromProcess(templateReactionBuilder, forbiddenNames); //adjust reaction name (e.g. replace "drug" placeholder with compound name if needed reaction.Name = reactionNameFor(reaction.Name, compoundName); //replace keywords replaceKeywordsInProcess(reaction, new[] { CoreConstants.Molecule.Drug, CoreConstants.KeyWords.Molecule, CoreConstants.KeyWords.Reaction, CoreConstants.Molecule.DrugFcRnComplexTemplate }, new[] { compoundName, compoundName, reaction.Name, CoreConstants.Molecule.DrugFcRnComplexName(compoundName) }); formulaCache.Add(reaction.Formula); return(reaction); }
public IFormula ConcentrationFormulaFor(IFormulaCache formulaCache) { if (formulaCache.Contains(CoreConstants.Formula.Concentration)) { return(formulaCache[CoreConstants.Formula.Concentration]); } var formula = _objectBaseFactory.Create <ExplicitFormula>() .WithId(CoreConstants.Formula.Concentration) .WithName(CoreConstants.Formula.Concentration) .WithFormulaString("V>0 ? M/V : 0"); formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPath.PARENT_CONTAINER).WithAlias("M").WithDimension(_dimensionRepository.Amount)); formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPath.PARENT_CONTAINER, ObjectPath.PARENT_CONTAINER, CoreConstants.Parameter.VOLUME).WithAlias("V").WithDimension(_dimensionRepository.Volume)); formulaCache.Add(formula); formula.Dimension = _dimensionRepository.MolarConcentration; return(formula); }
private IFormula drugMassFormula(IFormulaCache formulaCache) { if (formulaCache.ExistsByName(Constants.Parameters.DRUG_MASS)) { return(formulaCache.FindByName(Constants.Parameters.DRUG_MASS)); } var startFormula = _objectBaseFactory.Create <ExplicitFormula>() .WithFormulaString(Constants.Parameters.DRUG_MASS) .WithDimension(_dimensionRepository.Amount) .WithName(Constants.Parameters.DRUG_MASS); var pathToDrugMass = _objectPathFactory.CreateFormulaUsablePathFrom(ObjectPath.PARENT_CONTAINER, CoreConstants.ContainerName.ProtocolSchemaItem, Constants.Parameters.DRUG_MASS) .WithAlias(Constants.Parameters.DRUG_MASS) .WithDimension(_dimensionRepository.Amount); startFormula.AddObjectPath(pathToDrugMass); formulaCache.Add(startFormula); return(startFormula); }
protected override void Context() { base.Context(); _buildingBlockToAddTo = A.Fake <IBuildingBlock>(); _formulaCache = new FormulaCache(); A.CallTo(() => _buildingBlockToAddTo.FormulaCache).Returns(_formulaCache); _totalyNewObject = new Parameter().WithName("New"); _theDimension = A.Fake <IDimension>(); _oldFormula = A.Fake <ExplicitFormula>().WithName("New Formula").WithDimension(_theDimension).WithFormulaString("1+1").WithId("1"); _newFormula = A.Fake <ExplicitFormula>().WithName("New Formula").WithDimension(_theDimension).WithFormulaString("1+1").WithId("1"); _newFormula.ObjectPaths = new IFormulaUsablePath[0]; _oldFormula.ObjectPaths = new IFormulaUsablePath[0]; _formulaCache.Add(_oldFormula); _newRHSFormula = A.Fake <ExplicitFormula>().WithName("New Formula").WithDimension(_theDimension).WithFormulaString("1+5").WithId("RHS"); _totalyNewObject.Formula = _newFormula; A.CallTo(() => _nameCorrector.CorrectName(_formulaCache, _newRHSFormula)).Returns(true); A.CallTo(() => _objectBaseRepository.ContainsObjectWithId(_newRHSFormula.Id)).Returns(false); _totalyNewObject.RHSFormula = _newRHSFormula; }
public IFormula ConcentrationFormulaFor(IFormulaCache formulaCache) { if (formulaCache.ExistsByName(Constants.CONCENTRATION_FORMULA)) { return(formulaCache.FindByName(Constants.CONCENTRATION_FORMULA)); } var formula = _objectBaseFactory.Create <ExplicitFormula>() .WithName(Constants.CONCENTRATION_FORMULA) .WithFormulaString("V>0 ? M/V : 0"); formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPath.PARENT_CONTAINER) .WithAlias("M") .WithDimension(_dimensionFactory.Dimension(Constants.Dimension.MOLAR_AMOUNT))); formula.AddObjectPath(createVolumeReferencePath(ObjectPath.PARENT_CONTAINER, ObjectPath.PARENT_CONTAINER, Constants.Parameters.VOLUME)); formulaCache.Add(formula); formula.Dimension = _dimensionFactory.Dimension(Constants.Dimension.MOLAR_CONCENTRATION); return(formula); }
private void updateAlternativeParameters(ParameterAlternative alternative, IMoleculeBuilder drug, IFormulaCache formulaCache) { 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; } if (alternativeParameter.Formula.IsTable()) { var tableFormula = _cloner.Clone(alternativeParameter.Formula); formulaCache.Add(tableFormula); drugParameter.Formula = tableFormula; } //parameter is a rate. parameter in molecule should be readonly else if (!alternativeParameter.Formula.IsConstant()) { drugParameter.Editable = false; } //target parameter is a rate and source parameter is constant else if (!drugParameter.Formula.IsConstant()) { drugParameter.Formula = _objectBaseFactory.Create <ConstantFormula>().WithValue(alternativeParameter.Value); } _parameterSetUpdater.UpdateValue(alternativeParameter, drugParameter); //Default parameter Default and visible may not match database default and need to be set according to alternative parameter drugParameter.IsDefault = alternativeParameter.IsDefault; drugParameter.Visible = alternativeParameter.Visible; } }
private IFormula particleDrugMassFormula(IFormulaCache formulaCache) { if (formulaCache.ExistsByName(CoreConstants.Parameters.PARTICLE_BIN_DRUG_MASS)) { return(formulaCache.FindByName(CoreConstants.Parameters.PARTICLE_BIN_DRUG_MASS)); } var pathToDrugMass = _objectPathFactory.CreateFormulaUsablePathFrom(ObjectPath.PARENT_CONTAINER, CoreConstants.Parameters.PARTICLE_BIN_DRUG_MASS) .WithAlias("ParticleBinDrugMass") .WithDimension(_dimensionRepository.Amount); var startFormula = _objectBaseFactory.Create <ExplicitFormula>() .WithFormulaString(pathToDrugMass.Alias) .WithDimension(_dimensionRepository.Amount) .WithName(CoreConstants.Parameters.PARTICLE_BIN_DRUG_MASS); startFormula.AddObjectPath(pathToDrugMass); formulaCache.Add(startFormula); return(startFormula); }
private IFormula R1Formula(IFormulaCache formulaCache) { var formula = formulaCache.FirstOrDefault(x => string.Equals(x.Name, "R1")); if (formula != null) { return(formula); } formula = _objectBaseFactory.Create <ExplicitFormula>().WithFormulaString("A+B").WithName("R1"); formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPath.PARENT_CONTAINER, "A", Constants.Parameters.CONCENTRATION) .WithAlias("A") .WithDimension(_concentrationDimension)); formula.AddObjectPath(_objectPathFactory.CreateFormulaUsablePathFrom(ObjectPath.PARENT_CONTAINER, "B", Constants.Parameters.CONCENTRATION) .WithAlias("B") .WithDimension(_concentrationDimension)); formula.WithDimension(_concentrationPerTimeDimension); formulaCache.Add(formula); return(formula); }
protected override IFormula CreateFormulaCloneFor(IFormula srcFormula) { // constant formulas are always cloned if (srcFormula.IsConstant()) { return(CloneFormula(srcFormula)); } // Check if target formula cache already contains the formula // to be cloned. This can happen if we are cloning // any substructure within the same building block // In this case, all formulas are already present in the // formula cache of this building block if (_formulaCache.Contains(srcFormula.Id)) { return(srcFormula); } // Check if the formula was already cloned. Return the cloned // formula if so. if (_clonedFormulasByOriginalFormulaId.Contains(srcFormula.Id)) { return(_clonedFormulasByOriginalFormulaId[srcFormula.Id]); } // Formula is neither present in the passed formula cahce nor // was already cloned. So create a new clone and insert it // in both target formula cache and the cache of all cloned formulas var clonedFormula = CloneFormula(srcFormula); _formulaCache.Add(clonedFormula); _clonedFormulasByOriginalFormulaId.Add(srcFormula.Id, clonedFormula); return(clonedFormula); }
public void should_Not_Add_a_formula_to_formula_cache() { A.CallTo(() => _formulaCache.Add(A <Formula> ._)).MustNotHaveHappened(); A.CallTo(() => _buidingBlockWithFormulaCache.AddFormula(A <Formula> ._)).MustNotHaveHappened(); }