You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: main/blog/posts/tutorials/plugins/01-create-plugin/_post.md
+67-49Lines changed: 67 additions & 49 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,26 +22,29 @@ We'll use Greg Landrum's [2022 blog post on generating fingerprints with RDKIt](
22
22
This is an example plugin implementation. For a more general (and shorter) guide on building plugins for OpenAD, check out our [Plugin Developer Guide](/docs/plugin-development/index.md).
23
23
24
24
!!! note
25
-
Download the finished plugin from GitHub: [openad-plugin-tutorial](https://github.com/acceleratedscience/openad-plugin-tutorial)
25
+
Download the finished plugin from GitHub: [openad-plugin-tutorial](https://github.com/acceleratedscience/openad-plugin-tutorial)
26
26
27
27
## 1. Creating the Scaffold
28
28
29
29
<divclass="padded-list"markdown>
30
30
31
31
1. Clone the [demo plugin repository](https://github.com/acceleratedscience/openad-plugin-demo) to use as a scaffold.
3. Update `pyproject.toml` and set the `name` field to `openad_plugin_fingerprint`.
52
55
53
56
4. Update `plugin_metadata.yaml` - this is used for the help display.
57
+
54
58
```shell
55
59
name: Fingerprint
56
60
namespace: fp
@@ -70,11 +74,12 @@ website: null
70
74
4. Open `/calculate_fp/command.py` and look for`# <-- UPDATE` and update the import statements so they point to `openad_plugin_fingerprint`
71
75
72
76
5. Install the plugin
73
-
If you haven't already, make sure your file cursor is pointed to the parent `/openad-plugin-fingerprint` directory, and if you have installed OpenAD in a virtual environment, of course make sure you have the virtual environment activated. We'll install the plugin with the `--editable` flag, so we can update the code and see the results in real time.
77
+
If you haven't already, make sure your working directory is pointed to the parent `/openad-plugin-fingerprint` directory, and if you have installed OpenAD in a virtual environment, of course make sure you have the virtual environment activated. We'll install the plugin with the `--editable` flag, so we can update the code and see the results in real time.
74
78
75
79
```shell
76
80
cd openad-plugin-fingerprint
77
81
```
82
+
78
83
```shell
79
84
pip install -e .
80
85
```
@@ -91,41 +96,43 @@ We'll start with the command documentation. The `help_dict_create_v2()` function
91
96
92
97
Let's start with defining what our plugin will do:
93
98
94
-
- Input: one or more SMILES identifiers, or the molecules in your molecule working set (MWS)
95
-
- Calculate one of 5 types of fingerprints:
96
-
- `mfp` - Morgan fingerprint (default)
97
-
- `rdk` - RDKit fingerprint
98
-
- `ap` - Atom pair fingerprint
99
-
- `tt` - Topological torsion fingerprint
100
-
- `fm` - Feature Morgan fingerprint
101
-
- Optionally store the results in the MWS, if the MWS was the input source
99
+
- Input: one or more SMILES identifiers, or the molecules in your molecule working set (MWS)
100
+
- Calculate one of 5 types of fingerprints:
101
+
- `mfp` - Morgan fingerprint (default)
102
+
- `rdk` - RDKit fingerprint
103
+
- `ap` - Atom pair fingerprint
104
+
- `tt` - Topological torsion fingerprint
105
+
- `fm` - Feature Morgan fingerprint
106
+
- Optionally store the results in the MWS, if the MWS was the input source
102
107
103
108
### Defining Command Structure
104
109
105
110
We would like to enable the following command variations:
106
111
107
-
- `fp calc for C1=CC(=C(C=C1CCN)O)O`
108
-
Calculate default fingerprint for a single molecule.
109
-
- `fp calc for [CC(C)[N+](=O)[O-],O=C1CNC(=O)N1,Nc1ccccc1O]`
110
-
Calculate default fingerprint for a list of molecules.
111
-
- `fp calc for @mws`
112
-
Calculate default fingerprint for all molecules in my molecule working set.
113
-
- `fp calc for @mws update`
114
-
Calculate default fingerprint for all molecules in my MWS, then update MWS with results.
115
-
- `fp calc tt for C1=CC(=C(C=C1CCN)O)O`
116
-
Calculate topological torsion fingerprint for a single molecule.
117
-
- etc.
118
-
112
+
- `fp calc for C1=CC(=C(C=C1CCN)O)O`
113
+
Calculate default fingerprint for a single molecule.
114
+
- `fp calc for [CC(C)[N+](=O)[O-],O=C1CNC(=O)N1,Nc1ccccc1O]`
115
+
Calculate default fingerprint for a list of molecules.
116
+
- `fp calc for @mws`
117
+
Calculate default fingerprint for all molecules in my molecule working set.
118
+
- `fp calc for @mws update`
119
+
Calculate default fingerprint for all molecules in my MWS, then update MWS with results.
120
+
- `fp calc tt for C1=CC(=C(C=C1CCN)O)O`
121
+
Calculate topological torsion fingerprint for a single molecule.
122
+
- etc.
123
+
119
124
### Notating Command Structure
120
125
121
126
We can summarize this structure in three variations:
122
127
123
128
```shell
124
129
fp calc [ <fp_type> ] for <smiles>
125
130
```
131
+
126
132
```shell
127
133
fp calc [ <fp_type> ] for [<smiles>,<smiles>,...]
128
134
```
135
+
129
136
```shell
130
137
fp calc [ <fp_type> ] for @mws [ update ]
131
138
```
@@ -192,7 +199,6 @@ You can either pass a single SMILES, a a list of smiles, or refer to your molecu
192
199
<cmd>show mol Nc1ccccc1O</cmd>
193
200
```
194
201
195
-
196
202
To see the result, you can now run:
197
203
198
204
```shell
@@ -209,23 +215,23 @@ Earlier you duplicated `commands/hello_world` and renamed it to `commands/calcul
209
215
210
216
### Notes
211
217
212
-
- The command definition is created using PyParsing. If you're new to PyParsing, check out our [PyParsing 101](/docs/plugin-development/pyparsing-101.md) crash course to get up to speed in no time.
213
-
- Each word in a command is represented by a "grammar definition". We'll store our grammar definitions in `plugin_grammar_def.py` so they can be reused across commands.
214
-
- We have a number of readymade grammar definitions that can be imported as building blocks. You can check these out here: [openad_tools.grammar_def.py](https://github.com/acceleratedscience/openad-tools/blob/main/openad_tools/grammar_def.py)
218
+
-The command definition is created using PyParsing. If you're new to PyParsing, check out our [PyParsing 101](/docs/plugin-development/pyparsing-101.md) crash course to get up to speed in no time.
219
+
-Each word in a command is represented by a "grammar definition". We'll store our grammar definitions in `plugin_grammar_def.py` so they can be reused across commands.
220
+
-We have a number of readymade grammar definitions that can be imported as building blocks. You can check these out here: [openad_tools.grammar_def.py](https://github.com/acceleratedscience/openad-tools/blob/main/openad_tools/grammar_def.py)
215
221
216
222
### Compiling the Command
217
223
218
224
<divclass="padded-list"markdown>
219
225
220
-
1. We want to support an individual molecule identifier as well as a list of identifiers as input. For this we can simply import the `molecule_identifier_s` definition, which handles both.
226
+
1.We want to support an individual molecule identifier as well as a list of identifiers as input. For this we can simply import the `molecule_identifier_s` definition, which handles both.
221
227
222
228
```python
223
229
from openad_tools.grammar_def import molecule_identifier_s
224
230
```
225
231
226
-
2. Then we'll create the other parts of our command and store them in `plugin_grammar_def.py`.
232
+
2. Then we'll create the other parts of our command and store them in `plugin_grammar_def.py`.
227
233
Two things to note: we'll support both `calc` as `calculate`, and the identifier for the word `for` is called `f_or` so it doesn't interfer with the Python's "for" used for looping.
@@ -306,6 +318,7 @@ This is looking good. Let's move on to the command's logic.
306
318
To keep things organized, we'll put the functionality in a separate file which we'll call `calculate_fp.py`and store it in the command folder. This way we can separate the parsing logic from the function logic and keep things organized.
307
319
308
320
Parsing logic:
321
+
309
322
```python
310
323
# File: command.py
311
324
from openad_plugin_fingerprint.commands.calculate_fp.calculate_fp import calculate_fp, fp_to_list
0 commit comments