@@ -223,15 +223,15 @@ Where "command" is one of: tree, network, hiers, aggregate or select.
223223ScaffoldGraph makes it simple to construct a graph using the library API.
224224The resultant graphs follow the same API as a NetworkX DiGraph.
225225
226- ```python
227- import scaffoldgraph as sg
228-
229- # construct a scaffold network from an SDF file
230- network = sg.ScaffoldNetwork.from_sdf('my_sdf_file.sdf')
231-
232- # construct a scaffold tree from a SMILES file
233- tree = sg.ScaffoldTree.from_smiles('my_smiles_file.smi')
234- ```
226+ ```python
227+ import scaffoldgraph as sg
228+
229+ # construct a scaffold network from an SDF file
230+ network = sg.ScaffoldNetwork.from_sdf('my_sdf_file.sdf')
231+
232+ # construct a scaffold tree from a SMILES file
233+ tree = sg.ScaffoldTree.from_smiles('my_smiles_file.smi')
234+ ```
235235
236236
237237--------------------------------------------------------------------------------
@@ -244,25 +244,25 @@ The resultant graphs follow the same API as a NetworkX DiGraph.
244244 It is simple to construct a graph from multiple input source in parallel,
245245 using the concurrent.futures module and the sg.utils.aggregate function.
246246
247- ```python
248- from concurrent.futures import ProcessPoolExecutor
249- from functools import partial
250- import scaffoldgraph as sg
251- import os
252-
253- directory = './data'
254- sdf_files = [f for f in os.listdir(directory) if f.endswith('.sdf')]
255-
256- func = partial(sg.ScaffoldNetwork.from_sdf, ring_cutoff=10)
257-
258- graphs = []
259- with ProcessPoolExecutor(max_workers=4) as executor:
260- futures = executor.map(func, sdf_files)
261- for future in futures:
262- graphs.append(future)
263-
264- network = sg.utils.aggregate(graphs)
265- ```
247+ ``` python
248+ from concurrent.futures import ProcessPoolExecutor
249+ from functools import partial
250+ import scaffoldgraph as sg
251+ import os
252+
253+ directory = ' ./data'
254+ sdf_files = [f for f in os.listdir(directory) if f.endswith(' .sdf' )]
255+
256+ func = partial(sg.ScaffoldNetwork.from_sdf, ring_cutoff = 10 )
257+
258+ graphs = []
259+ with ProcessPoolExecutor(max_workers = 4 ) as executor:
260+ futures = executor.map(func, sdf_files)
261+ for future in futures:
262+ graphs.append(future)
263+
264+ network = sg.utils.aggregate(graphs)
265+ ```
266266
267267- ** Creating custom scaffold prioritisation rules**
268268
@@ -274,71 +274,71 @@ The resultant graphs follow the same API as a NetworkX DiGraph.
274274 When subclassing a name property must be defined and either a condition, get_property or filter function.
275275 Examples are shown below:
276276
277- ```python
278- import scaffoldgraph as sg
279- from scaffoldgraph.prioritization import *
280-
281- """
282- Scaffold filter rule (must implement name and condition)
283- The filter will retain all scaffolds which return a True condition
284- """
285-
286- class CustomRule01(ScaffoldFilterRule):
287- """Do not remove rings with >= 12 atoms if there are smaller rings to remove"""
288-
289- def condition(self, child, parent):
290- removed_ring = child.rings[parent.removed_ring_idx]
291- return removed_ring.size < 12
292-
293- @property
294- def name(self):
295- return 'custom rule 01'
296-
297- """
298- Scaffold min/max filter rule (must implement name and get_property)
299- The filter will retain all scaffolds with the min/max property value
300- """
301-
302- class CustomRule02(ScaffoldMinFilterRule):
303- """Smaller rings are removed first"""
304-
305- def get_property(self, child, parent):
306- return child.rings[parent.removed_ring_idx].size
307-
308- @property
309- def name(self):
310- return 'custom rule 02'
277+ ```python
278+ import scaffoldgraph as sg
279+ from scaffoldgraph.prioritization import *
280+
281+ """
282+ Scaffold filter rule (must implement name and condition)
283+ The filter will retain all scaffolds which return a True condition
284+ """
285+
286+ class CustomRule01(ScaffoldFilterRule):
287+ """ Do not remove rings with >= 12 atoms if there are smaller rings to remove"""
288+
289+ def condition(self , child, parent):
290+ removed_ring = child.rings[parent.removed_ring_idx]
291+ return removed_ring.size < 12
311292
293+ @ property
294+ def name(self ):
295+ return ' custom rule 01'
312296
313- """
314- Scaffold base filter rule (must implement name and filter)
315- The filter method must return a list of filtered parent scaffolds
316- This rule is used when a more complex rule is required, this example
317- defines a tiebreaker rule. Only one scaffold must be left at the end
318- of all filter rules in a rule set
319- """
297+ """
298+ Scaffold min/max filter rule (must implement name and get_property)
299+ The filter will retain all scaffolds with the min/max property value
300+ """
301+
302+ class CustomRule02(ScaffoldMinFilterRule):
303+ """ Smaller rings are removed first"""
304+
305+ def get_property(self , child, parent):
306+ return child.rings[parent.removed_ring_idx].size
307+
308+ @ property
309+ def name(self ):
310+ return ' custom rule 02'
311+
320312
321- class CustomRule03(BaseScaffoldFilterRule):
322- """Tie-breaker rule (alphabetical)"""
323-
324- def filter(self, child, parents):
325- return [sorted(parents, key=lambda p: p.smiles)[0]]
326-
327- @property
328- def name(self):
329- return 'cutstom rule 03'
330- ```
313+ """
314+ Scaffold base filter rule (must implement name and filter)
315+ The filter method must return a list of filtered parent scaffolds
316+ This rule is used when a more complex rule is required, this example
317+ defines a tiebreaker rule. Only one scaffold must be left at the end
318+ of all filter rules in a rule set
319+ """
320+
321+ class CustomRule03(BaseScaffoldFilterRule):
322+ """ Tie-breaker rule (alphabetical)"""
323+
324+ def filter (self , child, parents):
325+ return [sorted (parents, key = lambda p : p.smiles)[0 ]]
326+
327+ @ property
328+ def name(self ):
329+ return ' cutstom rule 03'
330+ ```
331331
332332 Custom rules can subsequently be added to a rule set and supplied to the scaffold tree constructor:
333333
334- ```python
335- ruleset = ScaffoldRuleSet(name='custom rules')
336- ruleset.add_rule(CustomRule01())
337- ruleset.add_rule(CustomRule02())
338- ruleset.add_rule(CustomRule03())
339-
340- graph = sg.ScaffoldTree.from_sdf('my_sdf_file.sdf', prioritization_rules=ruleset)
341- ```
334+ ```python
335+ ruleset = ScaffoldRuleSet(name = ' custom rules' )
336+ ruleset.add_rule(CustomRule01())
337+ ruleset.add_rule(CustomRule02())
338+ ruleset.add_rule(CustomRule03())
339+
340+ graph = sg.ScaffoldTree.from_sdf(' my_sdf_file.sdf' , prioritization_rules = ruleset)
341+ ```
342342
343343--------------------------------------------------------------------------------
344344
0 commit comments