Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #248 solubility as table #610

Merged

Conversation

msevestre
Copy link
Member

No description provided.

@msevestre msevestre requested a review from Yuri05 April 18, 2018 00:12
@msevestre msevestre changed the title 248 solubility as table Fixes #248 solubility as table Apr 18, 2018
@msevestre
Copy link
Member Author

msevestre commented Apr 18, 2018

@Yuri05 Big pull request that should basically support Table solubility in PK-Sim
There is a test that creates a simulation using Table Solubility. This test WILL fail as long as the implementation is not supported in SimModel.

SimModelNET.SimModelException : Formula type 'TableFormulaWithXArgument' is unknown

@@ -2235,7 +2239,7 @@ public static string ImportFormulationDescription
{
var sb = new StringBuilder();
sb.AppendLine("The Excel table for formulation import should have a format of two colums.");
sb.AppendLine("The first column represents the Time (unit Time e.g. in years).");
sb.AppendLine("The first column represents the Time (unit Time e.g. in hours).");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of wrong :)

@@ -51,7 +54,6 @@ private void initializeCalculationMethods(Compound compound)
private void readCompoundFromTemplate(Compound compound)
{
//STEP1: Add all parameters defined for the compound from the database
//need to set the name of the compound to drug in order to load parameter from database
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as always, comments are lying

@@ -311,6 +311,9 @@ private IFormula createFormula(RateKey rateKey)
if (rateKey.IsTableWithOffsetFormula)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should theoretically not be required once we upgrade the code

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be required for old projects (unless we don't convert old TableWithOffset formulas into TableWithXArg)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No this is only used when creating a new Formula using the RateKey (e..g from DB).
That should never happen anymore. TableWithOffset will still be available as an object for backward compatibility

/// Performs initalization steps for a brand new solubility alternative that should behave as a Table alternative
/// </summary>
/// <param name="solubilityAlternative"></param>
void PrepareSolubilityAlternativeForTableSolubility(ParameterAlternative solubilityAlternative);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a public method for that because the same logic needs to be called when loading from snapshot. Not ideal at the moment but works until something better falls into place

simulation.Compounds.Each(convertCompound);
}

private void convertCompound(Compound compound)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Project conversion also implemented. Simply adds a clone of the default Table parameter

@@ -49,16 +51,21 @@ public bool Edit(IParameter tableParameter)
private void tableFormulaChanged(object sender, EventArgs eventArgs)
{
plotTable();
View.OkEnabled = CanClose;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IT was possible to close the table edit without any points. This create a table that is not suppored by schema

if (_editedFormula == null)
return base.CanClose;

return base.CanClose && _editedFormula.AllPoints().Any();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can only close if there is at least one point

case IQuantity quantity:
return _quantityDisplayPathMapper.DisplayPathAsStringFor(quantity, addSimulationName);
case ParameterAlternativeGroup parameterAlternativeGroup:
return displayFor(parameterAlternativeGroup);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was also a little bug in the way we display a parameter alternative in the command description

@@ -149,7 +149,6 @@ public void BindTo(IEnumerable<ParameterDTO> parameters)
//necessary to bind to binding list to enable automatic update from value since we are
//using the autobind property from devexpress which only (!!) reacts to IBindingList properties.
_gridViewBinder.BindToSource(parameters.ToBindingList());
gridView.BestFitColumns();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was removed to ensure that the ValueOrigin column does not take a crazy amount of space

@msevestre
Copy link
Member Author

@Yuri05
Table is exported as follow:

 "UseDerivedValues": true,
        "Points": [
          {
            "X": 5.0,
            "Y": 22.0,
            "RestartSolver": false
          },
          {
            "X": 10.0,
            "Y": 50.0,
            "RestartSolver": false
          }

Is this correct (I do not know what UseDerivedValues means anymore)

@Yuri05
Copy link
Member

Yuri05 commented Apr 18, 2018

Is this correct

No, must be "UseDerivedValues": false
Otherwise dY/dX (here: dSolubility/dpH) will be used in the simulation

@@ -2157,6 +2160,7 @@ public static class UI
public static readonly string UseWatermark = "Use watermark in charts when exporting to clipboard?";
public static readonly string WatermarkText = "Text";
public static readonly string WatermarkProperties = "Watermark Properties";
public static readonly string CreateTableSolubilityAlternative = "Create as pH-Sol table";

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think Create as pH-Solubility table would be better

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:)
image

changed

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

_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;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Yuri05 This is important here to ensure that parameter such as RefPh, SolubilityAtRefPh etc.. do not appear as changed. By default they are IsDefault= false. But in this case, they need to inherit from the compound value

@@ -2157,6 +2160,7 @@ public static class UI
public static readonly string UseWatermark = "Use watermark in charts when exporting to clipboard?";
public static readonly string WatermarkText = "Text";
public static readonly string WatermarkProperties = "Watermark Properties";
public static readonly string CreateTableSolubilityAlternative = "Create as pH-Sol table";

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:)
image

changed

@@ -311,6 +311,9 @@ private IFormula createFormula(RateKey rateKey)
if (rateKey.IsTableWithOffsetFormula)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No this is only used when creating a new Formula using the RateKey (e..g from DB).
That should never happen anymore. TableWithOffset will still be available as an object for backward compatibility


return formula;
}

private IFormula createTableFormulaWithOffset(RateKey rateKey)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of that should go to

@@ -2157,6 +2160,7 @@ public static class UI
public static readonly string UseWatermark = "Use watermark in charts when exporting to clipboard?";
public static readonly string WatermarkText = "Text";
public static readonly string WatermarkProperties = "Watermark Properties";
public static readonly string CreateTableSolubilityAlternative = "Create as pH-Sol table";

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


}

public static string ImportSolubilityTableDescription
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a description too

@@ -2238,13 +2238,25 @@ public static string ImportFormulationDescription
get
{
var sb = new StringBuilder();
sb.AppendLine("The Excel table for formulation import should have a format of two colums.");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was not not english

@@ -260,9 +261,10 @@ public IFormula RateFor(RateKey rateKey, IFormulaCache formulaCache)
return formulaCache[rateKey];
}

public TableFormula CreateTableFormula()
public TableFormula CreateTableFormula(bool useDerivedValues = true)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add the parameter. Default is true (same behavior as previous)

@@ -59,11 +59,10 @@ public ParameterAlternative CreateTableAlternativeFor(ParameterAlternativeGroup
var alternative = CreateAlternativeFor(compoundParameterGroup);

var tableParameter = alternative.Parameter(tableParameterName);
var tableFormula = _formulaFactory.CreateTableFormula();
var tableFormula = _formulaFactory.CreateTableFormula(useDerivedValues:false);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

creates with false in this case

@Yuri05 Yuri05 merged commit 574a77a into Open-Systems-Pharmacology:develop Apr 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants