Generation Verifier
The GenerationVerifier computes rewards for de novo molecular generation tasks, evaluating generated molecules against property optimization criteria such as docking scores, QED, synthetic accessibility, and other molecular descriptors.
Overview
The Generation Verifier supports:
- Multi-property Optimization: Optimize multiple properties simultaneously
- Docking Score Computation: GPU-accelerated molecular docking with AutoDock
- RDKit Descriptors: QED, SA score, LogP, molecular weight, etc.
- SMILES Extraction: Robust parsing of SMILES from model completions
Supported Properties
| Property | Type | Description |
|---|---|---|
| Docking Targets | Slow (GPU) | Binding affinity to protein pockets |
| Physico-Chemical Properties | Fast | QED, SA score, Molecular Weight, ... |
SMILES Extraction
The verifier extracts SMILES from completions using:
- Answer Tags: Content between
<answer>and</answer>tags - Pattern Matching: Identifies possible valid SMILES patterns (extracted word with no characters outside SMILES charset, and that contains at least one
Ccharacter, or multiplec) - Validation: Verifies molecules with RDKit
Extraction Failures
| Failure Reason | Description |
|---|---|
no_answer |
No answer tags found |
no_smiles |
No SMILES-like strings in answer |
no_valid_smiles |
SMILES strings are invalid |
multiple_smiles |
Multiple valid SMILES found (ambiguous) |
DockingConfigModel
Bases: BaseModel
Pydantic model for docking configuration.
This model defines the configuration parameters for docking operations, providing validation and documentation for all docking options.
Attributes:
| Name | Type | Description |
|---|---|---|
exhaustiveness |
int
|
Docking exhaustiveness parameter. |
n_cpu |
int
|
Number of CPUs to use for docking. |
docking_oracle |
Literal['pyscreener', 'autodock_gpu']
|
Type of docking oracle to use ("pyscreener" or "autodock_gpu"). |
Source code in mol_gen_docking/reward/verifiers/generation_reward/generation_verifier_pydantic_model.py
DockingGPUConfigModel
Bases: DockingConfigModel
Pydantic model for AutoDock GPU docking configuration.
This model defines the configuration parameters specific to the AutoDock GPU docking software, providing validation and documentation for all options.
Attributes:
| Name | Type | Description |
|---|---|---|
exhaustiveness |
int
|
Docking exhaustiveness parameter. |
n_cpu |
int
|
Number of CPUs to use for docking. |
docking_oracle |
Literal['pyscreener', 'autodock_gpu']
|
Type of docking oracle to use (must be "autodock_gpu"). |
vina_mode |
str
|
Command mode for AutoDock GPU. |
Source code in mol_gen_docking/reward/verifiers/generation_reward/generation_verifier_pydantic_model.py
PyscreenerConfigModel
Bases: DockingConfigModel
Pydantic model for PyScreener docking configuration.
This model defines the configuration parameters specific to the PyScreener docking software, providing validation and documentation for all options.
Attributes:
| Name | Type | Description |
|---|---|---|
exhaustiveness |
int
|
Docking exhaustiveness parameter. |
n_cpu |
int
|
Number of CPUs to use for docking. |
docking_oracle |
Literal['pyscreener', 'autodock_gpu']
|
Type of docking oracle to use (must be "pyscreener"). |
software_class |
Literal['vina', 'qvina', 'smina', 'psovina', 'dock', 'dock6', 'ucsfdock']
|
Docking software class to use with PyScreener. |
Source code in mol_gen_docking/reward/verifiers/generation_reward/generation_verifier_pydantic_model.py
GenerationVerifierInputMetadataModel
Bases: BaseModel
Input metadata model for generation verifier.
Defines the verification criteria for molecular generation tasks, including properties to optimize, objectives for each property, and target values.
Attributes:
| Name | Type | Description |
|---|---|---|
properties |
List[str]
|
List of property names to verify (e.g., "QED", "SA", "docking_target_name"). Each property should be a valid molecular descriptor or a docking target name. Must have the same length as objectives and target. |
objectives |
List[GenerationObjT]
|
List of objectives for each property. Must have the same length as properties and target. Valid values: - "maximize": Reward increases with property value - "minimize": Reward increases as property value decreases - "above": Reward is 1.0 if property >= target, 0.0 otherwise - "below": Reward is 1.0 if property <= target, 0.0 otherwise |
target |
List[float]
|
List of target values for each property. Must have the same length as properties and objectives. For "maximize"/"minimize": Used as reference point for rescaling (when enabled) For "above"/"below": Used as threshold for binary reward computation |
Source code in mol_gen_docking/reward/verifiers/generation_reward/input_metadata.py
validate_properties()
Validate that properties, objectives, and target have the same length.
Source code in mol_gen_docking/reward/verifiers/generation_reward/input_metadata.py
GenerationVerifierOutputModel
Bases: VerifierOutputModel
Output model for generation verifier results.
Attributes:
| Name | Type | Description |
|---|---|---|
reward |
float
|
The computed reward for the generation verification. |
parsed_answer |
str
|
The parsed answer extracted from the model completion. |
verifier_metadata |
GenerationVerifierMetadataModel
|
Metadata related to the generation verification process. |
Source code in mol_gen_docking/reward/verifiers/generation_reward/generation_verifier_pydantic_model.py
GenerationVerifierMetadataModel
Bases: BaseModel
Metadata model for generation verifier results.
Contains detailed information about the generation verification process, including all extracted SMILES, their individual rewards, and any extraction failures.
Attributes:
| Name | Type | Description |
|---|---|---|
properties |
List[str]
|
List of property names that were evaluated (e.g., "docking_score", "QED", "SA"). Each property corresponds to a molecular descriptor or docking target that was optimized. |
individual_rewards |
List[float]
|
List of individual rewards for each property in the properties list. Each value is typically in [0.0, 1.0] range when rescaling is enabled, representing how well the molecule satisfies each property objective. |
all_smi_rewards |
List[float]
|
List of rewards for all SMILES found in the completion. When multiple SMILES are extracted, each gets its own reward. The final reward is typically the best among these values. |
all_smi |
List[str]
|
List of all SMILES strings extracted from the completion. May contain multiple SMILES if the model generated several molecules. Empty if SMILES extraction failed. |
smiles_extraction_failure |
str
|
Error message if SMILES extraction failed. Empty string if extraction was successful. Common values include:
|
Source code in mol_gen_docking/reward/verifiers/generation_reward/generation_verifier_pydantic_model.py
GenerationVerifierConfigModel
Bases: BaseModel
Pydantic model for generation verifier configuration.
This model defines the configuration parameters for the GenerationVerifier class, providing validation and documentation for all configuration options.
Attributes:
| Name | Type | Description |
|---|---|---|
path_to_mappings |
str
|
Optional path to property mappings and docking targets configuration directory. Should contain 'names_mapping.json' and 'docking_targets.json' files. |
reward |
Literal['property', 'valid_smiles']
|
Type of reward to compute. Either "property" for property-based rewards or "valid_smiles" for validity-based rewards. |
rescale |
bool
|
Whether to rescale the rewards to a normalized range. |
oracle_kwargs |
DockingGPUConfigModel | PyscreenerConfigModel
|
Dictionary of keyword arguments to pass to the docking oracle. Can include: |
docking_concurrency_per_gpu |
int
|
Number of concurrent docking runs to allow per GPU. Default is 2 (uses ~1GB per run on 80GB GPU). |
Source code in mol_gen_docking/reward/verifiers/generation_reward/generation_verifier_pydantic_model.py
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 | |
Config
Pydantic configuration.
Source code in mol_gen_docking/reward/verifiers/generation_reward/generation_verifier_pydantic_model.py
check_mappings_path()
Validate that the path_to_mappings exists and contains required files.
Source code in mol_gen_docking/reward/verifiers/generation_reward/generation_verifier_pydantic_model.py
Generation verifier for de novo molecular generation tasks.
This module provides the GenerationVerifier class which computes rewards for molecular generation based on property optimization objectives such as docking scores, QED, synthetic accessibility, and other molecular descriptors.
GenerationVerifier
Bases: Verifier
Verifier for de novo molecular generation tasks.
This verifier computes rewards for generated molecules based on how well they meet specified property optimization criteria. It supports multiple property types including docking scores, QED, SA score, and RDKit descriptors.
The verifier uses Ray for parallel computation and supports GPU-accelerated docking calculations when configured with AutoDock GPU.
Attributes:
| Name | Type | Description |
|---|---|---|
verifier_config |
GenerationVerifierConfigModel
|
Configuration for the generation verifier. |
property_name_mapping |
Mapping of property names to oracle names. |
|
docking_target_list |
List of valid docking target names. |
|
oracles |
Dict[str, OracleWrapper]
|
Cache of oracle instances for property computation. |
debug |
If True, enables debug mode with additional logging. |
Example
from mol_gen_docking.reward.verifiers import (
GenerationVerifier,
GenerationVerifierConfigModel,
BatchVerifiersInputModel,
GenerationVerifierInputMetadataModel
)
config = GenerationVerifierConfigModel(
path_to_mappings="data/molgendata",
reward="property"
)
verifier = GenerationVerifier(config)
inputs = BatchVerifiersInputModel(
completions=["<answer>CCO</answer>"],
metadatas=[GenerationVerifierInputMetadataModel(
properties=["QED"], objectives=["maximize"], target=[0.0]
)]
)
results = verifier.get_score(inputs)
Source code in mol_gen_docking/reward/verifiers/generation_reward/generation_verifier.py
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 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 | |
__init__(verifier_config)
Initialize the GenerationVerifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
verifier_config
|
GenerationVerifierConfigModel
|
Configuration containing paths to mappings, reward type, and docking oracle settings. |
required |
Source code in mol_gen_docking/reward/verifiers/generation_reward/generation_verifier.py
fill_df_properties(df_properties)
Compute property values for all molecules in a DataFrame.
This method fills in the 'value' column of the DataFrame with computed property values using the appropriate oracles. It uses Ray for parallel computation, with GPU resources allocated for docking calculations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df_properties
|
DataFrame
|
DataFrame with columns ['smiles', 'property', 'value', 'obj', 'target_value', 'id_completion']. The 'value' column will be filled with computed property values. |
required |
Source code in mol_gen_docking/reward/verifiers/generation_reward/generation_verifier.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 | |
get_all_completions_smiles(completions)
Extract SMILES from multiple completions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
completions
|
List[str]
|
List of model completion strings. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[List[List[str]], List[str]]
|
Tuple containing: - List of SMILES lists (one per completion) - List of failure reasons (one per completion) |
Source code in mol_gen_docking/reward/verifiers/generation_reward/generation_verifier.py
get_reward(row)
Compute reward for a single property-molecule pair.
This method computes the reward based on the objective type: - "below": 1.0 if property <= target, else 0.0 - "above": 1.0 if property >= target, else 0.0 - "maximize": Returns the property value directly - "minimize": Returns 1 - property value - "equal": Returns clipped value based on squared error
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
row
|
Series
|
DataFrame row containing 'obj', 'value', 'target_value', 'property'. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Computed reward value (typically 0.0 to 1.0). |
Source code in mol_gen_docking/reward/verifiers/generation_reward/generation_verifier.py
get_score(inputs)
Compute generation rewards for a batch of completions.
This method extracts SMILES from completions, computes property values, and calculates rewards based on the specified objectives. The final reward is the geometric mean of per-property rewards.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs
|
BatchVerifiersInputModel
|
Batch of completions and metadata for verification. |
required |
Returns:
| Type | Description |
|---|---|
List[GenerationVerifierOutputModel]
|
List of GenerationVerifierOutputModel containing rewards and metadata |
List[GenerationVerifierOutputModel]
|
for each completion. |
Notes
- If reward type is "valid_smiles", returns 1.0 for valid single SMILES
- Multiple SMILES in a completion result in 0.0 reward
- Uses geometric mean to aggregate multi-property rewards
Source code in mol_gen_docking/reward/verifiers/generation_reward/generation_verifier.py
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 | |
get_smiles_from_completion(comp)
Extract SMILES strings from a model completion.
This method parses a model completion to extract valid SMILES strings. It handles various formats including answer tags and markdown formatting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
comp
|
str
|
The model completion string to parse. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[List[str], str]
|
Tuple containing: - List of valid SMILES strings found in the completion - Failure reason string (empty if successful, otherwise one of: "no_answer", "no_smiles", "no_valid_smiles", "multiple_smiles") |
Example
Source code in mol_gen_docking/reward/verifiers/generation_reward/generation_verifier.py
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 | |
Related
- Molecular Verifier - Main orchestrator
- Property Verifier - Molecular property prediction tasks
- Reaction Verifier - Reaction prediction and retro-synthesis tasks