When you perform an equilibrium calculation, ChemAppPy will return the result as an object containing all the values from the calculation. You can inspect the values like you would with any regular Python object. But what if you performed multiple equilibrium calculations over a range of variables? How would you then easily inspect that results that would now be spread among multiple result objects?
The DataCollector class is an awesome feature in ChemAppPy that allows you to access all your results via an intuitive query-style interface. It also allows you to easily perform post processing on an entire result set such as creating distribution plots or carrying out further calculations.
There are two types of data collectors in ChemAppPy: ListDataCollector and MongoDbDataCollector. They work in the same way, the only difference being in how the data is stored. The ListDataCollector stores data as a list of objects on your computer's memory (RAM). The MongoDbDataCollector (as the name suggests) uses a Mongo database. This database can be on your local machine, or even somewhere in the cloud.
Take note that it is completely optional to work with the MongoDbDataCollector. The main advantage is the fact that you do not use your local RAM to store result objects, which can get very large, very quickly!
In this post I will show you how to get started with MongoDB using Docker Compose. Docker Compose performs all the heavy lifting to help you set up Docker containers. It takes care of tasks such as Docker networking, volumes and ports. This will allow you to get started with MongoDB as a Docker container, without having to worry about the finer implementation details.
I will not go into any detail in terms of virtual container environments, you may find supplementary information on the Docker site.
Here are the steps to get MongoDB running on your local machine.
1. Install Docker
Run the following commands from the console:
If you get an error with the curl command, first run sudo apt install curl. Remember to replace $your_user with the username on you computer. The implication of this last command is that you will not have to run docker commands with the sudo keyword.
Head to the Docker Desktop for Windows - Docker Hub page and follow the instructions on how to download and install Docker Community Edition on Windows.
2. Install Docker Compose
Docker Compose is distributed together with the Docker Community Edition of Windows so it ought to be installed already. You can check the Install Docker Compose | Docker Documentation page for more information.
3. Download the Docker settings folder
Follow this link (Docker settings folder) to download the necessary files and folders that we have kindly set up for you to easily start the MongoDB Docker container. The settings are the same for both Windows and Linux.
The folder structure should look like this in your download location. The next step will assume you downloaded it to your home (Linux users) or Documents (Windows users) folder.
4. Start the MongoDB Docker
Open a console or command prompt and perform the following commands to start the MongoDB Docker:
Docker Compose does all the necessary work for you to correctly set up the port as well as the volumes. The advantage of setting up the volumes in this way will be discussed below. It will also ensure that the MongoDB Docker starts automatically when your system starts up.
5. Test the MongoDB container
Create a new Python script and paste the following block of code:
If this script does not raise any errors, it means that your setup was successful. Remember to run pip install pymongo before running this test script. When you install ChemAppPy, it will automatically install pymongo. You are now ready to start using the MongoDbDataCollector class.
Backup and restore your MongoDB data
Using Docker Compose to set up the volumes in such a way that the MongoDB data folders are easily accessible allows you to very easily back up and restore your data. If you navigate deeper into the docker/mongodb folder structure, you will find a db folder. This folder contains that actual MongoDB data.
If you ever wanted to back up your data, you can simply back up the entire docker/mongodb folder. Restoring or moving your data to another computer is just as easy. You simply copy the entire docker/mongodb folder to the new destination and rerun the docker-compose up -d command. Be sure to change the port number in the docker-compose.yml settings file if you are creating a duplicate instance on the same machine otherwise the port numbers will clash.