Connecting to Postgres¶
Now that you have a Postgres instance running (either in the cloud or via Docker), let's connect Simmate to it.
1. Connection Details¶
Depending on your choice in the previous step, you will have different connection details.
For DigitalOcean (Option A):¶
On your database cluster's page, copy the Connection details. They will look something like this:
username = doadmin
password = your_secure_password
host = db-postgresql-nyc3-12345-do-user-1234567-0.b.db.ondigitalocean.com
port = 25060
database = defaultdb
sslmode = require
For Docker (Option B):¶
The default connection details for the command used in the previous step are:
username = postgres
password = mysecretpassword
host = localhost
port = 5432
database = postgres
2. Configuring Simmate¶
The easiest way to configure Simmate is via the command line. Replace the values below with your specific connection details from Step 1:
simmate config update "database.engine=django.db.backends.postgresql"
simmate config update "database.host=YOUR_HOST"
simmate config update "database.name=YOUR_DATABASE_NAME"
simmate config update "database.user=YOUR_USERNAME"
simmate config update "database.password=YOUR_PASSWORD"
simmate config update "database.port=YOUR_PORT"
# DigitalOcean also requires sslmode=require (Option A only)
simmate config update "database.options.sslmode=require"
Verify the settings are correctly loaded:
simmate config show --user-only
3. Creating a Separate Database (Optional)¶
Note
If you are using Docker (Option B), you can skip this step. The default postgres database is sufficient for local development.
It's best practice for cloud users to create a dedicated database for your Simmate project rather than using defaultdb.
- In the DigitalOcean dashboard, go to the "Settings" tab for your cluster.
- Scroll down to "Users & Databases" and click "Add New Database".
- Name it something like
simmate_db_01. - Update your Simmate settings to use this new name:
simmate config update "database.name=simmate_db_01"
4. Initializing the Database¶
Now that we've connected to our database, we can create the Simmate tables:
- Run the following command to initialize the database:
(Note: Use
simmate database resetsimmate database updatein the future if you add new apps and only want to apply changes without deleting existing data).
5. Creating a Connection Pool (Cloud Only)¶
Note
If you are using Docker (Option B), you can skip this step. Connection pooling is primarily needed for high-throughput cloud environments.
When running many calculations simultaneously (e.g., on a supercomputer), your database might receive hundreds of simultaneous connection requests. A connection pool manages these requests efficiently.
- In DigitalOcean, go to the "Connection Pools" tab and click "Create a Connection Pool".
- Name it
simmate-pool, select yoursimmate_db_01database, and set the mode to "Transaction". - Set the pool size (e.g., 20) and click "Create Pool".
- DigitalOcean will provide NEW connection details for this pool (different port and name). Update your Simmate settings:
simmate config update "database.name=simmate-pool" simmate config update "database.port=25061" # Pools often use a different port
6. Loading Third-Party Data¶
This step is optional but highly recommended if you want to search existing data (like the Materials Project).
To download and load data from a specific provider, use:
simmate database download materials-project
cod, oqmd, or jarvis. Depending on the dataset size and your connection, this can take anywhere from a few minutes to several hours.
7. Sharing the Database¶
To share this database with teammates, you can export your configuration to a file:
simmate config write
settings.yaml or {conda_env}-settings.yaml) in your ~/simmate directory. Your teammates can place this file in their own Simmate directory to instantly connect to the same shared database.