Query Examples¶
The YAML config file for the query step accepts SQL-like query conditions
(without the WHERE keyword). Note that the file does not have to be named
query.yaml — any filename works, as long as it is passed via -c to the
CLI. Below is the checked-in example config, which can also be found in the
ChemReporter GitHub repository:
# Path to the ChemReporter query database where the queries will be executed
query_database_path: "/path/to/query_database/"
# Path to the results file where the filtered keys will be saved
results_path: "/path/to/results/filtered_keys.npy"
# The query to be executed
query: database_name = 'omol25' AND max_force_norm < 15 AND net_force_norm < 1.0e-3
# Sample actions to be executed - remove if not needed
sampling:
n_samples: 100000
method: random
seed: 42 # for reproducibility
For context: We build the SQL query internally as:
SELECT entry_key FROM table WHERE <query>
Basic Filtering¶
These simple examples show how to filter structures by basic dataset
properties, such as the number of atoms in a structure or which source
subset it belongs to. Note that fields like subset are populated
differently — or not at all — depending on the source dataset; see
Crucial Implementation Details
before relying on them across datasets.
# Filter by number of atoms
query: "num_atoms > 10 AND num_atoms < 50"
# Filter by subset
query: "subset = 'spice'"
# Multiple subsets
query: "subset IN ('spice', 'anix', 'biomolecules')"
Property-based Filtering¶
Beyond simple structural counts, you can also filter on computed physicochemical properties, such as lipophilicity, polarity, molecular weight, or overall net charge.
# Lipophilic molecules
query: "logp > 2.0 AND logp < 5.0"
# High polar surface area
query: "tpsa > 100"
# Light molecules with few atoms
query: "molecular_weight < 200 AND num_atoms < 15"
# Charged molecules
query: "net_charge != 0"
Reactivity Filters¶
For reaction datasets, you can select structures based on their role along a reaction pathway, for example to isolate transition states.
# Select only transition states
query: "is_transition_state = true"
Combined Filters¶
Real-world use cases often require combining several conditions into a single, more elaborate query. The examples below showcase common combined filters, ranging from element-based restrictions to a typical drug-likeness heuristic.
# molecules with element CHNO (and nothing else)
# (but CHN CHO .. are ok )
query: |
atomic_symbols ~ '^[CHNO]+$'
AND num_atoms > 3
# Large organic molecules
query: |
num_atoms > 30
AND molecular_weight > 300
AND graph_properties_candidate = true
# Clean database (no calculation errors)
query: |
error_graph_properties = false
AND graph_properties_candidate = true
AND subset IN ('spice', 'anix')
# Lipinski rule of 5 approximation
query: |
molecular_weight BETWEEN 150 AND 500
AND logp BETWEEN -0.5 AND 5
AND tpsa BETWEEN 20 AND 130
AND num_atoms BETWEEN 10 AND 50
AND error_graph_properties = false