diff --git a/dimsim/_db/__init__.py b/dimsim/_db/__init__.py new file mode 100644 index 0000000..d2dba67 --- /dev/null +++ b/dimsim/_db/__init__.py @@ -0,0 +1 @@ +"""A database tracking lowest-energy coordinates for a packed box of a given (physical property or compute) target.""" diff --git a/dimsim/_db/get.py b/dimsim/_db/get.py new file mode 100644 index 0000000..f7c13ab --- /dev/null +++ b/dimsim/_db/get.py @@ -0,0 +1,17 @@ +import sqlite3 + + +def get_record(db_path: str, record_id: str) -> tuple[str, float]: + conn = sqlite3.connect(db_path) + cursor = conn.cursor() + + cursor.execute("SELECT filename, energy FROM records WHERE id = ?", (record_id,)) + row = cursor.fetchone() + + conn.close() + + if row is None: + raise KeyError(f"No record found with id={record_id!r}") + + filename, energy = row + return filename, energy diff --git a/dimsim/_db/insert.py b/dimsim/_db/insert.py new file mode 100644 index 0000000..8b4e668 --- /dev/null +++ b/dimsim/_db/insert.py @@ -0,0 +1,11 @@ +import sqlite3 + + +def insert_record(db_path: str, record_id: str, filename: str, energy: float): + conn = sqlite3.connect(db_path) + cursor = conn.cursor() + + cursor.execute("INSERT INTO records (id, filename, energy) VALUES (?, ?, ?)", (record_id, filename, energy)) + + conn.commit() + conn.close() diff --git a/dimsim/_db/start.py b/dimsim/_db/start.py new file mode 100644 index 0000000..4b52748 --- /dev/null +++ b/dimsim/_db/start.py @@ -0,0 +1,19 @@ +import sqlite3 + + +def create_database(db_path: str): + conn = sqlite3.connect(db_path) + cursor = conn.cursor() + + # not sure if we should be tracking file name (easy enough, brittle) + # or storing the full 3-D coordinates in the database + cursor.execute(""" + CREATE TABLE IF NOT EXISTS records ( + id TEXT PRIMARY KEY CHECK(length(id) = 16), + filename TEXT NOT NULL, + energy REAL NOT NULL + ) + """) + + conn.commit() + conn.close() diff --git a/dimsim/compute/workflow.py b/dimsim/compute/workflow.py index 5f35b1e..a83ffcf 100644 --- a/dimsim/compute/workflow.py +++ b/dimsim/compute/workflow.py @@ -3,6 +3,7 @@ import parsl +from dimsim._db.start import create_database from dimsim.compute.apps import ( minimize_energy, prepare_openmm_system, @@ -24,6 +25,8 @@ def __init__(self, base_dir, parsl_config): parsl.load(parsl_config) + self.low_energy_database = create_database(str(pathlib.Path(self.base_dir) / "minima.db")) + def _submit_compute( self, compute_config: BaseComputeConfig, @@ -50,15 +53,21 @@ def _submit_compute( # trajectory_dcd = File(f"{job_dir}/trajectory.dcd") # 1. pack from compute config + # TODO: Short-circuit if a packed topolgoy already exists pack_future = prepare_packed_topology(compute_config, job_dir) # 2. set up openmm system + # TODO: Also short-circuit here setup_future = prepare_openmm_system(pack_future, job_dir) # 3. (for now ...) get minimized energy + # TODO: Short-circuit here too + # TODO: Store the resulting energy into the database, as a starting point minimize_future = minimize_energy(setup_future, job_dir) # 4. run equilibration step + # TODO: Short-circuit here too + # TODO: Store resulting energy into the database equilibration_future = run_equilibration( compute_config=compute_config, equilibration_config=None, @@ -67,6 +76,7 @@ def _submit_compute( ) # 5. run "production" step + # TODO: Store resulting energy into the database production_future = run_production( compute_config=compute_config, production_config=None,