Skip to content

Commit aa1ce2e

Browse files
author
“LRossentue”
committed
docs: expand plugin development section with practical examples
1 parent 54e29e3 commit aa1ce2e

File tree

1 file changed

+116
-7
lines changed

1 file changed

+116
-7
lines changed

README.md

Lines changed: 116 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -505,16 +505,125 @@ confs_params = GenerateConfsParams(
505505

506506
## Plugin Development
507507

508-
MolForge supports custom plugin actors. See `molforge/actor_plugins/example.py` for a complete, documented template.
508+
MolForge supports custom plugin actors for extending the pipeline with domain-specific functionality. Plugins are automatically discovered and integrate seamlessly with the core framework.
509509

510-
### Creating a Plugin
510+
### Quick Start
511511

512-
1. Create parameter class inheriting from `BaseParams`
513-
2. Create actor class inheriting from `BaseActor`
514-
3. Implement required methods (`process`, properties)
515-
4. Place in `molforge/actor_plugins/`
512+
Custom actors are placed in `molforge/actor_plugins/` and automatically loaded at runtime. Each plugin consists of a parameter class and an actor class:
516513

517-
See the example plugin for detailed guidance on parameter validation, error handling, and pipeline integration.
514+
```python
515+
from dataclasses import dataclass
516+
from molforge.actors.base import BaseActor
517+
from molforge.actors.params.base import BaseParams
518+
519+
@dataclass
520+
class MyPluginParams(BaseParams):
521+
my_parameter: str = 'default_value'
522+
523+
class MyPlugin(BaseActor):
524+
__step_name__ = 'my_plugin' # Used in pipeline configuration
525+
__param_class__ = MyPluginParams
526+
527+
def process(self, data):
528+
# Your processing logic here
529+
return data
530+
```
531+
532+
### Using Plugins in Pipelines
533+
534+
Reference plugins by their `__step_name__` in the pipeline steps, and configure them using `plugin_params`:
535+
536+
```python
537+
from molforge import MolForge, ForgeParams
538+
539+
params = ForgeParams(
540+
steps=['source', 'chembl', 'curate', 'my_plugin'], # Add plugin to steps
541+
plugin_params={
542+
'my_plugin': MyPluginParams(
543+
my_parameter='custom_value'
544+
)
545+
}
546+
)
547+
548+
forge = MolForge(params)
549+
df = forge.forge("CHEMBL234")
550+
```
551+
552+
### Common Patterns
553+
554+
#### Input and Output Specification
555+
556+
Declare required input columns and output columns for pipeline validation:
557+
558+
```python
559+
class MyPlugin(BaseActor):
560+
@property
561+
def required_columns(self):
562+
return ['curated_smiles'] # Columns needed from previous actors
563+
564+
@property
565+
def output_columns(self):
566+
return ['my_property'] # Columns added by this actor
567+
```
568+
569+
#### Handling Optional Dependencies
570+
571+
Use graceful error handling for optional dependencies:
572+
573+
```python
574+
@dataclass
575+
class MyPluginParams(BaseParams):
576+
def _validate_params(self):
577+
try:
578+
import optional_library
579+
except ImportError:
580+
raise ImportError(
581+
"optional_library required. Install with: pip install optional_library"
582+
)
583+
```
584+
585+
#### Pipeline Logging
586+
587+
Use `self.log()` for consistent logging integration:
588+
589+
```python
590+
def process(self, data):
591+
self.log(f"Processing {len(data)} molecules")
592+
# ... processing logic ...
593+
self.log(f"Completed processing", level='DEBUG')
594+
return data
595+
```
596+
597+
### Testing Plugins
598+
599+
Test plugins standalone before pipeline integration:
600+
601+
```python
602+
import pandas as pd
603+
604+
# Create test data
605+
test_data = pd.DataFrame({
606+
'curated_smiles': ['CCO', 'c1ccccc1', 'CC(=O)O']
607+
})
608+
609+
# Initialize and test
610+
params = MyPluginParams(my_parameter='test_value')
611+
plugin = MyPlugin(params)
612+
result = plugin.process(test_data)
613+
614+
print(result)
615+
```
616+
617+
### Complete Example
618+
619+
See `molforge/actor_plugins/example.py` for a fully documented plugin template covering:
620+
- Parameter validation with `_validate_params()`
621+
- Actor initialization with `__post_init__()`
622+
- Robust error handling for individual molecules
623+
- Custom metadata in `_create_output()`
624+
- Integration with pipeline configuration
625+
626+
The example plugin demonstrates calculating molecular descriptors with RDKit and serves as a reference for all plugin patterns.
518627

519628
---
520629

0 commit comments

Comments
 (0)