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

Decouple loading of COPASI from loading of SBML and simulating. #2

Open
fbergmann opened this issue Apr 30, 2024 · 0 comments
Open
Assignees

Comments

@fbergmann
Copy link
Contributor

Looking at the latest version of the code, there is just one function loadCopasiAPI (see below) that loads the COPASI instance, immidiately loads the SBML model and simulates. This should be separated as follows:

  • just as with the antimony wrapper, save the COPASI instance variable globally, so you have access to it and only reload if that instance is Null | undefined.
  • you only want to load the SBML model if it has been changed internally since the last simulation run (or the antimony was changed), or it was never loaded. Otherwise everything will be reset all the time.

Alternatively you could of course just work with the state object. Only load the api, if the state instance is not set ...

 loadCopasiAPI = async () => {
        try {
            const { timeStart, timeEnd, numPoints } = this.state.simulationParameters;

            const cps = await createCpsModule();
            const instance = new COPASI(cps);

            const modelInfo = instance.loadModel(this.state.sbmlCode);
            const simResults = JSON.parse(instance.Module.simulateEx(timeStart,timeEnd,numPoints));

            this.setState({
                copasi: instance,
                data: {
                    columns: simResults.columns,
                    titles: simResults.titles // Assuming simResults contains a titles array
                },
                info: modelInfo,
                initialOptions: simResults.titles.reduce((acc, title) => ({ ...acc, [title]: true }), {})});
        } catch (err) {
            console.error(`Error in loadCopasiAPI: ${err.message}`);
        }
    };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants