Skip to content

Instantly share code, notes, and snippets.

View fbergmann's full-sized avatar

Frank Bergmann fbergmann

View GitHub Profile
@fbergmann
fbergmann / drop_compartment_multiplication.py
Last active January 12, 2024 09:27
While generally not recommended to remove multiplications with compartment sizes from kinetics, here is how it could be done. All it needs to work is the python libsbml package installed.
from libsbml import *
def replace_compartment_multiplication(node, compartents):
"""Removes all multiplications with compartment sizes from the given ASTNode.
:param node: The ASTNode to process.
:type node: ASTNode
:param compartents: A list of compartment ids.
:type compartents: list[str]
We can make this file beautiful and searchable if this error is corrected: It looks like row 6 should actually have 25 columns, instead of 4. in line 5.
# [B].Independent Value [C].Measured Value [C].Fitted Value [C].Weighted Error [B].Independent Value [C].Measured Value [C].Fitted Value [C].Weighted Error [B].Independent Value [C].Measured Value [C].Fitted Value [C].Weighted Error [B].Independent Value [C].Measured Value [C].Fitted Value [C].Weighted Error [B].Independent Value [C].Measured Value [C].Fitted Value [C].Weighted Error [B].Independent Value [C].Measured Value [C].Fitted Value [C].Weighted Error
0 -0.2035 0 0.2035 0 0.1516 0 -0.1516 0 -0.08391 0 0.08391 0 -0.07386 0 0.07386 0 0.05275 0 -0.05275 0 -0.1253 0 0.047132
0.25 nan 0.0250421 nan 0.25 nan 0.0250421 nan 0.25 nan 0.0195793 nan 0.25 nan 0.0271863 nan 0.25 nan 0.0244024 nan 0.25 nan 0.0249364 nan
0.5 nan 0.0498096 nan 0.5 nan 0.0498096 nan 0.5 nan 0.0390793 nan 0.5 nan 0.0545824 nan 0.5 nan 0.0471641 nan 0.5 nan 0.0493817 nan
0.75 nan 0.0743206 nan 0.75 nan 0.0743206 nan 0.75 nan 0.0585314 nan 0.75 nan 0.0821648 nan 0.75 nan 0.0681604 nan 0.75 nan 0.0733473 nan
1 0.06739 0.0985929 0.031
@fbergmann
fbergmann / print_stoichiometries.py
Created July 6, 2021 20:57
python script, extracting stoichiometries form SBML file, printing as LP
# -*- coding: utf-8 -*-
"""
Basic example program reading an SBML file going through the reactions
and printing the stoichiometries as constraints in LP format.
Created on Thu Apr 14 19:12:41 2016
@author: fbergmann
"""
==68052== Invalid write of size 8
==68052== at 0xCE09A4: CMathContainer::analyzeRoots() (CMathContainer.cpp:2721)
==68052== by 0xCDACFD: CMathContainer::compile() (CMathContainer.cpp:1405)
==68052== by 0x97E318: CModel::compile() (CModel.cpp:510)
==68052== by 0x97E946: CModel::compileIfNecessary(CProcessReport*) (CModel.cpp:602)
==68052== by 0xA848A6: SBMLImporter::createCModelFromSBMLDocument(SBMLDocument*, std::map<CDataObject const*, SBase*, std::less<CDataObject const*>, std::allocator<std::pair<CDataObject const* const, SBase*> > >&) (SBMLImporter.cpp:1558)
==68052== by 0xA9105C: SBMLImporter::parseSBML(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, CFunctionDB*, SBMLDocument*&, std::map<CDataObject const*, SBase*, std::less<CDataObject const*>, std::allocator<std::pair<CDataObject const* const, SBase*> > >&, CListOfLayouts*&, CDataModel*) (SBMLImporter.cpp:3744)
--- a/COPASI.R
+++ b/COPASI.R
@@ -94,7 +94,9 @@ function(name, .values, where = topenv(parent.frame()), suffix = "Value")
enumToInteger <- function(name,type)
{
if (is.character(name)) {
- ans <- as.integer(get(paste(".__E__", type, sep = ""))[name])
+ gettype <- paste(".__E__", type, sep = "")
+ if (!exists(gettype)) gettype <- paste(".__E__", substr(type, 3, nchar(type)), sep = "")
+ ans <- as.integer(get(gettype)[name])
# example script using the copasi cmake config file
# that is usually installed into lib/cmake
cmake_minimum_required(VERSION 2.8.11)
project (example_copasi_program)
# this searches for the libcopasi-static-config.cmake file
# that is exported by COPASI and will figure out all the
# dependent libraries
find_package(libCOPASISE-static CONFIG REQUIRED)