Skip to content

Commit 1294e67

Browse files
committed
Add visibility of drugs in pkpd time to LSTMDrugThreeComp and remove exit guards.
1 parent 3d31557 commit 1294e67

File tree

4 files changed

+47
-10
lines changed

4 files changed

+47
-10
lines changed

model/PkPd/Drug/LSTMDrugConversion.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@ gsl_integration_workspace *gsl_intgr_conv_wksp = gsl_integration_workspace_alloc
135135
//NOTE: we "should" free, but mem-leaks at end of program aren't really important
136136
// gsl_integration_workspace_free (gsl_intgr_conv_wksp);
137137
double LSTMDrugConversion::calculateFactor(const Params_convFactor& p, double duration) const{
138-
std::cout << "INSIDE LSTMDrugConversion::calculateFactor" << std::endl;
139-
exit(0);
140138
gsl_function F;
141139
F.function = &func_convFactor;
142140
// gsl_function doesn't accept const; we re-apply const later

model/PkPd/Drug/LSTMDrugThreeComp.cpp

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,6 @@ gsl_integration_workspace *gsl_intgr_wksp = gsl_integration_workspace_alloc (GSL
130130
// gsl_integration_workspace_free (gsl_intgr_wksp);
131131

132132
double LSTMDrugThreeComp::calculateFactor(const Params_fC& p, double duration) const{
133-
std::cout << "INSIDE LSTMDrugThreeComp::calculateFactor" << std::endl;
134-
exit(0);
135133
gsl_function F;
136134
F.function = &func_fC;
137135
// gsl_function doesn't accept const; we re-apply const later
@@ -160,7 +158,11 @@ double LSTMDrugThreeComp::calculateFactor(const Params_fC& p, double duration) c
160158

161159
// TODO: in high transmission, is this going to get called more often than updateConcentration?
162160
// When does it make sense to try to optimise (avoid doing decay calcuations here)?
163-
double LSTMDrugThreeComp::calculateDrugFactor(LocalRng& rng, WithinHost::CommonInfection *inf, double body_mass) const {
161+
double LSTMDrugThreeComp::calculateDrugFactor(LocalRng& rng, WithinHost::CommonInfection *inf, double body_mass,
162+
const std::string& drugName,
163+
std::vector<std::tuple<std::string, double, double>>& pkpdTimeToDrugConcentrationMap,
164+
std::vector<std::tuple<std::string, double, double>>& pkpdTimeToTotalFactorMap
165+
) const {
164166
if( conc() == 0.0 && doses.size() == 0 ) return 1.0; // nothing to do
165167
updateCached(body_mass);
166168

@@ -180,26 +182,61 @@ double LSTMDrugThreeComp::calculateDrugFactor(LocalRng& rng, WithinHost::CommonI
180182
if( time_conc.first < 1.0 /*i.e. today*/ ){
181183
if( time < time_conc.first ){
182184
double duration = time_conc.first - time;
185+
186+
// Add concentration and factor tracking before duration
187+
double current_conc = p.cA + p.cB + p.cC - p.cABC;
188+
pkpdTimeToDrugConcentrationMap.push_back(std::tuple<std::string, double, double>{drugName, time, current_conc});
189+
183190
totalFactor *= calculateFactor(p, duration);
191+
pkpdTimeToTotalFactorMap.push_back(std::tuple<std::string, double, double>{drugName, time, totalFactor});
192+
193+
// Update concentrations after duration
184194
p.cA *= exp(p.na * duration);
185195
p.cB *= exp(p.nb * duration);
186196
p.cC *= exp(p.ng * duration);
187197
p.cABC *= exp(p.nka * duration);
198+
199+
// Add concentration tracking after duration
200+
current_conc = p.cA + p.cB + p.cC - p.cABC;
201+
pkpdTimeToDrugConcentrationMap.push_back(std::tuple<std::string, double, double>{drugName, time, current_conc});
202+
188203
time = time_conc.first;
189204
}else{ assert( time == time_conc.first ); }
190205
// add dose:
191206
p.cA += A * time_conc.second;
192207
p.cB += B * time_conc.second;
193208
p.cC += C * time_conc.second;
194209
p.cABC += (A + B + C) * time_conc.second;
210+
211+
// Add concentration tracking after dose
212+
double current_conc = p.cA + p.cB + p.cC - p.cABC;
213+
pkpdTimeToDrugConcentrationMap.push_back(std::tuple<std::string, double, double>{drugName, time, current_conc});
195214
}else /*i.e. tomorrow or later*/{
196215
// ignore
197216
}
198217
}
199218
if( time < 1.0 ){
200-
totalFactor *= calculateFactor(p, 1.0 - time);
219+
double duration = 1.0 - time;
220+
221+
// // Add concentration and factor tracking before final duration
222+
// double current_conc = p.cA + p.cB + p.cC - p.cABC;
223+
// pkpdTimeToDrugConcentrationMap.push_back(std::tuple<std::string, double, double>{drugName, time, current_conc});
224+
225+
totalFactor *= calculateFactor(p, duration);
226+
pkpdTimeToTotalFactorMap.push_back(std::tuple<std::string, double, double>{drugName, time, totalFactor});
227+
228+
// // Add concentration tracking after final duration
229+
// p.cA *= exp(p.na * duration);
230+
// p.cB *= exp(p.nb * duration);
231+
// p.cC *= exp(p.ng * duration);
232+
// p.cABC *= exp(p.nka * duration);
233+
const double current_conc = p.cA + p.cB + p.cC - p.cABC;
234+
pkpdTimeToDrugConcentrationMap.push_back(std::tuple<std::string, double, double>{drugName, time, current_conc});
201235
}
202236

237+
// Add final total factor entry
238+
pkpdTimeToTotalFactorMap.push_back(std::tuple<std::string, double, double>{drugName, time, totalFactor});
239+
203240
return totalFactor;
204241
}
205242

model/PkPd/Drug/LSTMDrugThreeComp.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ class LSTMDrugThreeComp : public LSTMDrug {
5353
virtual size_t getIndex() const;
5454
virtual double getConcentration(size_t index) const;
5555

56-
virtual double calculateDrugFactor(LocalRng& rng, WithinHost::CommonInfection *inf, double body_mass) const;
56+
virtual double calculateDrugFactor(LocalRng& rng, WithinHost::CommonInfection *inf, double body_mass,
57+
const std::string& drugName,
58+
std::vector<std::tuple<std::string, double, double>>& pkpdTimeToDrugConcentrationMap,
59+
std::vector<std::tuple<std::string, double, double>>& pkpdTimeToTotalFactorMap
60+
) const;
5761
virtual void updateConcentration (double body_mass);
5862

5963
protected:

model/PkPd/Drug/LSTMDrugType.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,7 @@ unique_ptr<LSTMDrug> LSTMDrugType::createInstance(LocalRng& rng, size_t index) {
155155
throw std::runtime_error("Drug conversion not supported");
156156
}else if( typeData.k12 ){
157157
// k21 is set when k12 is set; k13 and k31 may be set
158-
// return unique_ptr<LSTMDrug>(new LSTMDrugThreeComp( typeData, rng ));
159-
// High velocity hack.
160-
throw std::runtime_error("Multi-compartment drug models not supported");
158+
return unique_ptr<LSTMDrug>(new LSTMDrugThreeComp( typeData, rng ));
161159
}else{
162160
// none of k12/k21/k13/k31 should be set in this case
163161
return unique_ptr<LSTMDrug>(new LSTMDrugOneComp( typeData, rng ));

0 commit comments

Comments
 (0)