Configuration of the Molecular Verifier Server
Using a Pydantic BaseSettings
We use Pydantic's BaseSettings to manage the configuration of our application through environment variables. It automatically reads and validates environment variables, converting them to Python types defined in your settings class.
How it works:
When you define a class that inherits from BaseSettings, Pydantic:
- Looks for environment variables matching the field names (case-insensitive)
- Converts them to the appropriate Python types
- Validates them against the field constraints
- Falls back to default values if environment variables are not provided
Setting configuration: Simply export environment variables before starting the server:
Or set them inline:
Server Configuration
MolecularVerifierServerSettings
Bases: BaseSettings
Configuration settings for the Molecular Verifier server.
This class manages all configuration parameters for running the Molecular Verifier server, including docking settings, oracle configuration, and verifier behavior. Settings can be loaded from environment variables, .env files, or passed directly.
The settings are used to initialize verifier configurations for molecular property prediction, reaction verification, and molecular generation tasks. It provides validation of settings and conversion to verifier config models.
Attributes:
| Name | Type | Description |
|---|---|---|
server_mode |
Literal['singleton', 'batch']
|
Server operation mode.
|
scorer_exhaustiveness |
int
|
Exhaustiveness parameter for docking scoring. Controls the thoroughness of the docking search. Higher values increase accuracy but require more computation time. Default: 8 |
scorer_ncpus |
int
|
Number of CPU cores to allocate for scoring operations. Must be compatible with exhaustiveness. Default: 8 |
docking_concurrency_per_gpu |
int
|
Number of concurrent docking jobs per GPU. Controls GPU utilization. Default: 2 |
reaction_matrix_path |
str
|
Path to the pickled reaction matrix file. Must exist and be accessible for reaction verification tasks. Default: "data/rxn_matrix.pkl" |
docking_oracle |
Literal['pyscreener', 'autodock_gpu']
|
The docking software to use for molecular docking. "pyscreener" for PyScreener docking or "autodock_gpu" for GPU-accelerated AutoDock. Default: "autodock_gpu" |
vina_mode |
str
|
Command mode for AutoDock GPU execution. Example: "autodock_gpu_256wi" for 256 work items mode. Only used when docking_oracle is "autodock_gpu". Default: "autodock_gpu_256wi" |
data_path |
str
|
Path to the molecular data directory containing: - names_mapping.json: Property name mappings - docking_targets.json: Target definitions for docking Used by generation tasks, and must be accessible. Default: "data/molgendata" |
buffer_time |
int
|
Time in seconds to buffer requests before processing. Allows batch processing of concurrent requests to improve efficiency. Default: 20 |
parsing_method |
Literal['none', 'answer_tags', 'boxed']
|
Method to parse model completions:
|
debug_logging |
bool
|
Enable detailed debug logging for server operations. Useful for troubleshooting and development. Default: False |
Example
from mol_gen_docking.server_utils.server_setting import MolecularVerifierServerSettings
from mol_gen_docking.reward import MolecularVerifier
# Load settings from environment variables or .env file
settings = MolecularVerifierServerSettings()
# Convert to verifier configuration
config = settings.to_molecular_verifier_config(reward="property")
# Create verifier instance
verifier = MolecularVerifier(verifier_config=config)
Environment Variables
Settings can be configured via environment variables (non-case sensitive) names:
- SERVER_MODE
- SCORER_EXHAUSTIVENESS
- SCORER_NCPUS
- DOCKING_CONCURRENCY_PER_GPU
- REACTION_MATRIX_PATH
- DOCKING_ORACLE
- VINA_MODE
- DATA_PATH
- BUFFER_TIME
- PARSING_METHODS
- DEBUG_LOGGING
Source code in mol_gen_docking/server_utils/server_setting.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | |
__post_init__()
Validate all settings after initialization.
Performs critical validation checks to ensure settings are consistent and valid before the server starts. This method is called automatically after the pydantic BaseSettings initializes the instance.
Raises:
| Type | Description |
|---|---|
AssertionError
|
If any of the following conditions are not met:
|
Source code in mol_gen_docking/server_utils/server_setting.py
to_molecular_verifier_config(reward='property')
Convert server settings to a complete verifier configuration model.
Creates a MolecularVerifierConfigModel with all sub-verifier configurations (generation, reaction, and property) initialized from the server settings. This method bridges the gap between server-level settings and verifier-level configurations, ensuring consistent parameter propagation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reward
|
Literal['property', 'valid_smiles']
|
Type of reward to compute.
|
'property'
|
Returns:
| Name | Type | Description |
|---|---|---|
MolecularVerifierConfigModel |
MolecularVerifierConfigModel
|
A fully configured verifier model containing:
All sub-configs are automatically synced to the specified reward type. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If any of the referenced configuration paths don't exist. This can happen if data_path or reaction_matrix_path are invalid. |
Source code in mol_gen_docking/server_utils/server_setting.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 | |