From d2d0de9d6747c6e0d2729c0f8d0dee37bcd044c0 Mon Sep 17 00:00:00 2001
From: Peter Schubert <Peter.Schubert@hhu.de>
Date: Mon, 13 Jun 2022 17:01:34 +0200
Subject: [PATCH] Report Density Constraint, Calculate degrees of freedom

---
 xbanalysis/problems/gba_problem.py      | 2 ++
 xbanalysis/solvers/gba_ipopt_problem.py | 3 ++-
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/xbanalysis/problems/gba_problem.py b/xbanalysis/problems/gba_problem.py
index 0e5dba8..966126c 100644
--- a/xbanalysis/problems/gba_problem.py
+++ b/xbanalysis/problems/gba_problem.py
@@ -78,6 +78,8 @@ class GbaProblem:
 
         # calculate stoichiometric sub-matrices and scale them according to volume
         # TODO: sparce matrix storage and calculations
+        specis_x_mrs = self.get_stoic_matrix(self.var_sids, self.mr_rids)
+        self.dof = specis_x_mrs.shape[1] - np.linalg.matrix_rank(specis_x_mrs)
         metab_x_mrs = self.get_stoic_matrix(self.var_metab_sids, self.mr_rids)
         self.metab_x_psrs = self.get_stoic_matrix(self.var_metab_sids, self.ps_rids)
         self.enz_x_mrs = self.get_stoic_matrix(self.var_enz_sids, self.mr_rids)
diff --git a/xbanalysis/solvers/gba_ipopt_problem.py b/xbanalysis/solvers/gba_ipopt_problem.py
index 7f3322b..958431c 100644
--- a/xbanalysis/solvers/gba_ipopt_problem.py
+++ b/xbanalysis/solvers/gba_ipopt_problem.py
@@ -81,4 +81,5 @@ class GbaIpoptProblem:
         self.nit = iter_count
         if self.report_freq > 0:
             if iter_count % self.report_freq == 0:
-                print(f'[{iter_count:5d}] growth rate: {-3600 *obj_value:.5f}')
+                print(f'[{iter_count:5d}] growth rate: {-3600 *obj_value:.5f}, '
+                      f"density constr: {self.gba_problem.last_values['heq_density'][1]}")
-- 
GitLab