---
title: "CoRC Worksheet"
author: "Juergen Pahle (juergen@pahle.de)"
output:
  pdf_document: default
  html_document:
    df_print: paged
---

This document shows some of the functionality of CoRC, the Copasi R Connector. CoRC can be downloaded from [jpahle.github.io/CoRC](https://jpahle.github.io/CoRC). There, you will also find the documentation, further examples, complete function reference and more.

Load the CoRC library and, possibly, other utility libraries, such as the ones contained in tidyverse:

```{r, message = FALSE}
library(CoRC)
library(tidyverse) # autoplot()
```

# Model creation / editing

Create an empty model:

```{r}
newModel()
```

Change model name (and, possibly, other model properties):

```{r}
setModelName("Michaelis-Menten scheme")
getCurrentModel()
```

Create a reversible reaction (note: "=" for reversible, and "-\>" for irreversible reactions):

```{r}
newReaction("S + E = C", name = "Complex formation")
```

Show all compartments (note: COPASI created one default compartment simply called "compartment"):

```{r}
getCompartments()
```

Show all species (note: COPASI auto-created all species implicitly defined in a reaction):

```{r}
getSpecies()
```

Show all reactions:

```{r}
getReactions()
```

Create a reaction for product formation:

```{r}
newReaction("C -> E + P", name = "Product formation")
```

Set initial concentrations for all species

```{r}
setSpecies("S", initial_concentration = 10)
setSpecies("C", initial_concentration = 0)
setSpecies("P", initial_concentration = 0)
```

Simulate: calculate a timecourse for the first 300 seconds, and plot:
```{r}
timecourse <- runTimeCourse(300)
autoplot.copasi_ts(timecourse)
```

If you have COPASI installed, you can quickly open the GUI to manually inspect and work with your model:
```{r}
openCopasi()
```

If you want to free memory space, you can unload the model (CoRC allows you to have an arbitrary number of models opened at the same time):
```{r}
unloadModel()
```
