public void ValidateConfigurationFor(Simulation simulation) { var compounds = simulation.Compounds; var simulationSubject = simulation.BuildingBlock <ISimulationSubject>(); var protocols = simulation.Protocols; var formulations = simulation.AllBuildingBlocks <Formulation>(); var modelConfiguration = simulation.ModelConfiguration; //ForComp model can only be used with small molecules if (string.Equals(modelConfiguration.ModelName, CoreConstants.Model.FOUR_COMP) && compounds.Any(x => !x.IsSmallMolecule)) { throw new InvalidSimulationConfigurationException(PKSimConstants.Error.FourCompModelCannotBeUsedWithLargeMolecule); } if (simulation.NameIsOneOf(compounds.AllNames())) { throw new InvalidSimulationConfigurationException(PKSimConstants.Error.CompoundAndSimulationCannotShareTheSameName); } if (simulation.NameIsOneOf(simulationSubject.AllMolecules().AllNames())) { throw new InvalidSimulationConfigurationException(PKSimConstants.Error.IndividualMoleculesAnSimulationCannotShareTheSameName); } var schemaItems = protocols.SelectMany(x => _schemaItemsMapper.MapFrom(x)).ToList(); var speciesPopulation = simulationSubject.OriginData.Population; if (!speciesPopulation.IsBodySurfaceAreaDependent && schemaItems.Any(x => x.DoseIsPerBodySurfaceArea())) { throw new InvalidSimulationConfigurationException(PKSimConstants.Error.DosePerBodySurfaceAreaProtocolCannotBeUsedWithSpeciesPopulation(speciesPopulation.DisplayName)); } if (speciesPopulation.IsNamed(CoreConstants.Population.PREGNANT)) { throw new InvalidSimulationConfigurationException(PKSimConstants.Error.PregnantPopulationCanOnlyBeUsedWithMoBiModel(speciesPopulation.DisplayName)); } var administeredCompoundWithSuperSaturationEnabled = compounds.Where(x => x.SupersaturationEnabled).Select(x => new { Compound = x, simulation.CompoundPropertiesFor(x).ProtocolProperties }).Where(x => x.ProtocolProperties.IsAdministered).Select(x => new { x.Compound, x.ProtocolProperties.Protocol, x.ProtocolProperties.FormulationMappings }); administeredCompoundWithSuperSaturationEnabled.Each(x => validateSupersaturationUsageFor(x.Compound, x.Protocol, x.FormulationMappings)); formulations.Where(x => x.FormulationType == CoreConstants.Formulation.TABLE).Each(validateTableFormulation); }
private IReadOnlyList <ISchemaItem> schemaItemsFrom(Simulation simulation, Compound compound) { var protocol = simulation.CompoundPropertiesFor(compound).ProtocolProperties.Protocol; if (protocol == null) { return(new List <ISchemaItem>()); } return(_protocolToSchemaItemsMapper.MapFrom(protocol)); }
protected override void Context() { _simulation = new IndividualSimulation { Properties = new SimulationProperties(), SimulationSettings = new SimulationSettings(), ModelConfiguration = new ModelConfiguration() }; _individual = new Individual().WithName("MyIndividual"); _speciesPopulation = new SpeciesPopulation(); _individual.OriginData = new OriginData { SpeciesPopulation = _speciesPopulation }; _compound = A.Fake <Compound>().WithName("MyCompound"); _protocol = A.Fake <SimpleProtocol>().WithName("MyProtocol"); _formulation = A.Fake <Formulation>().WithName("Formulation"); _simulation.AddUsedBuildingBlock(new UsedBuildingBlock("Individual", PKSimBuildingBlockType.Individual) { BuildingBlock = _individual }); _simulation.AddUsedBuildingBlock(new UsedBuildingBlock("Compound", PKSimBuildingBlockType.Compound) { BuildingBlock = _compound }); _simulation.AddUsedBuildingBlock(new UsedBuildingBlock("Protocol", PKSimBuildingBlockType.Protocol) { BuildingBlock = _protocol }); _simulation.AddUsedBuildingBlock(new UsedBuildingBlock("Formulation", PKSimBuildingBlockType.Formulation) { BuildingBlock = _formulation }); _protocolToProtocolSchemaItemMapper = A.Fake <IProtocolToSchemaItemsMapper>(); sut = new SimulationConfigurationValidator(_protocolToProtocolSchemaItemMapper); _speciesPopulation.IsHeightDependent = false; _schemaItem = A.Fake <SchemaItem>(); _doseUnit = A.Fake <Unit>(); _schemaItem.Dose.DisplayUnit = _doseUnit; _protocolProperties = new ProtocolProperties(); _formulationMapping = new FormulationMapping { FormulationKey = "F1", Formulation = _formulation }; _simulation.Properties.AddCompoundProperties(new CompoundProperties { Compound = _compound, ProtocolProperties = _protocolProperties }); A.CallTo(() => _protocolToProtocolSchemaItemMapper.MapFrom(_protocol)).Returns(new [] { _schemaItem }); }
private void addProtocol(IEventGroupBuilder applicationSet, CompoundProperties compoundProperties) { var protocol = compoundProperties.ProtocolProperties.Protocol; if (protocol == null) { return; } var protocolEventGroup = _objectBaseFactory.Create <IEventGroupBuilder>() .WithName(protocol.Name) .WithParentContainer(applicationSet); _schemaItemsMapper.MapFrom(protocol).Each((schemaItem, index) => { //+1 to start at 1 for the nomenclature string applicationName = $"{CoreConstants.APPLICATION_NAME_TEMPLATE}{index + 1}"; addApplication(protocolEventGroup, schemaItem, applicationName, compoundProperties, protocol); }); _parameterIdUpdater.UpdateBuildingBlockId(protocolEventGroup, protocol); }
public void ValidateConfigurationFor(Simulation simulation) { var compounds = simulation.Compounds; var simulationSubject = simulation.BuildingBlock <ISimulationSubject>(); var protocols = simulation.Protocols; var modelConfiguration = simulation.ModelConfiguration; //ForComp model can only be used with small molecules if (string.Equals(modelConfiguration.ModelName, CoreConstants.Model.FourComp) && compounds.Any(x => !x.IsSmallMolecule)) { throw new InvalidSimulationConfigurationException(PKSimConstants.Error.FourCompModelCannotBeUsedWithLargeMolecule); } if (simulation.NameIsOneOf(compounds.AllNames())) { throw new InvalidSimulationConfigurationException(PKSimConstants.Error.CompoundAndSimulationCannotShareTheSameName); } if (simulation.NameIsOneOf(simulationSubject.AllMolecules().AllNames())) { throw new InvalidSimulationConfigurationException(PKSimConstants.Error.IndividualMoleculesAnSimulationCannotShareTheSameName); } var schemaItems = protocols.SelectMany(x => _schemaItemsMapper.MapFrom(x)).ToList(); var speciesPopulation = simulationSubject.OriginData.SpeciesPopulation; if (!speciesPopulation.IsBodySurfaceAreaDependent && schemaItems.Any(x => x.DoseIsPerBodySurfaceArea())) { throw new InvalidSimulationConfigurationException(PKSimConstants.Error.DosePerBodySurfaceAreaProtocolCannotBeUsedWithSpeciesPopulation(speciesPopulation.DisplayName)); } if (speciesPopulation.IsNamed(CoreConstants.Population.Pregnant)) { throw new InvalidSimulationConfigurationException(PKSimConstants.Error.PregnantPopulationCanOnlyBeUsedWithMoBiModel(speciesPopulation.DisplayName)); } }
protected override void Context() { _vssCalculator = A.Fake <IVSSCalculator>(); _parameterFactory = A.Fake <IParameterFactory>(); _protocolMapper = A.Fake <IProtocolToSchemaItemsMapper>(); _protocolFactory = A.Fake <IProtocolFactory>(); _globalPKAnalysisRunner = A.Fake <IGlobalPKAnalysisRunner>(); _pkCalculationOptionsFactory = A.Fake <IPKCalculationOptionsFactory>(); _pkAnalysisTask = A.Fake <IPKAnalysesTask>(); _interactionTask = A.Fake <IInteractionTask>(); _cloner = A.Fake <ICloner>(); sut = new GlobalPKAnalysisTask(_parameterFactory, _protocolMapper, _protocolFactory, _globalPKAnalysisRunner, _pkAnalysisTask, _pkCalculationOptionsFactory, _vssCalculator, _interactionTask, _cloner); var baseGrid = new BaseGrid("time", A.Fake <IDimension>()); _peripheralVenousBloodPlasma = CalculationColumnFor(baseGrid, CoreConstants.Organ.PeripheralVenousBlood, CoreConstants.Observer.PLASMA_PERIPHERAL_VENOUS_BLOOD, CoreConstants.Observer.PLASMA_PERIPHERAL_VENOUS_BLOOD, _compoundName); _venousBloodPlasma = CalculationColumnFor(baseGrid, CoreConstants.Organ.VenousBlood, CoreConstants.Compartment.Plasma, CoreConstants.Observer.CONCENTRATION_IN_CONTAINER, _compoundName); _individual = A.Fake <Individual>(); _species = new Species(); A.CallTo(() => _individual.Species).Returns(_species); _compound = new Compound().WithName(_compoundName); _compoundProperties = new CompoundProperties { Compound = _compound }; _simulationSchemaItems = new List <SchemaItem>(); _protocol = new SimpleProtocol(); _compoundProperties.ProtocolProperties.Protocol = _protocol; A.CallTo(() => _protocolMapper.MapFrom(_protocol)).Returns(_simulationSchemaItems); _simulation = new IndividualSimulation { Properties = new SimulationProperties() }; _simulation.Properties.AddCompoundProperties(_compoundProperties); _simulation.AddUsedBuildingBlock(new UsedBuildingBlock("CompId", PKSimBuildingBlockType.Compound) { BuildingBlock = _compound }); _simulation.AddUsedBuildingBlock(new UsedBuildingBlock("IndividualId", PKSimBuildingBlockType.Individual) { BuildingBlock = _individual }); _simulation.DataRepository = new DataRepository { _venousBloodPlasma, _peripheralVenousBloodPlasma }; _venousBloodPK = new PKValues(); _venousBloodPK.AddValue(Constants.PKParameters.Vss, 10); _venousBloodPK.AddValue(Constants.PKParameters.Vd, 11); _venousBloodPK.AddValue(Constants.PKParameters.CL, 12); _venousBloodPK.AddValue(Constants.PKParameters.AUC_inf, 13); _venousBloodPK.AddValue(Constants.PKParameters.AUC_inf_tD1_norm, 14); _peripheralVenousBloodPK = new PKValues(); _peripheralVenousBloodPK.AddValue(Constants.PKParameters.Vss, 21); _peripheralVenousBloodPK.AddValue(Constants.PKParameters.Vd, 22); _peripheralVenousBloodPK.AddValue(Constants.PKParameters.CL, 23); _peripheralVenousBloodPK.AddValue(Constants.PKParameters.AUC_inf, 24); _peripheralVenousBloodPK.AddValue(Constants.PKParameters.AUC_inf_tD1_norm, 25); _peripheralVenousBloodPK.AddValue(Constants.PKParameters.C_max, 26); _peripheralVenousBloodPK.AddValue(Constants.PKParameters.C_max_tDLast_tDEnd, 27); A.CallTo(() => _pkAnalysisTask.CalculatePK(_venousBloodPlasma, A <PKCalculationOptions> ._)).Returns(_venousBloodPK); A.CallTo(() => _pkAnalysisTask.CalculatePK(_peripheralVenousBloodPlasma, A <PKCalculationOptions> ._)).Returns(_peripheralVenousBloodPK); A.CallTo(() => _parameterFactory.CreateFor(A <string> ._, A <double> ._, A <string> ._, PKSimBuildingBlockType.Simulation)) .ReturnsLazily(s => new PKSimParameter().WithName((string)s.Arguments[0]) .WithDimension(A.Fake <IDimension>()) .WithFormula(new ConstantFormula((double)s.Arguments[1]))); }
private IReadOnlyList <SchemaItemDTO> schemaItemsDTOFrom(Protocol protocol) { return(_schemaItemsMapper.MapFrom(protocol).MapAllUsing(_schemaItemDTOMapper)); }