1.1.1.3.1.1.1.3. ExplorationTree¶
- class molpher.swig_wrappers.core.ExplorationTree(*args, **kwargs)[source]¶
Represents an
exploration tree
and facilitates the most basic interaction with it. It is a tight wrapper around the C++ implementation. Themolpher.core.ExplorationTree
class extends upon this implementation and provides a more user-friendly version of this class.Attention
This class does not define a constructor. Use the
create()
factory method to spawn instances.- static create(*args)¶
Returns an
ExplorationTree
instance using a suppliedExplorationData
, tree snapshot or SMILES strings of the source molecule and the target molecule.- Parameters
*args (
ExplorationData
orstr
) – anExplorationData
instance, path to a tree snapshot or a source molecule and a target molecule as two arguments.- Returns
ExplorationTree
instance created from the supplied snapshot- Return type
- save(filename)[source]¶
Saves the tree to a snapshot file. The filename should end with either
.xml
or.snp
.- Parameters
filename (
str
) – path to the new snapshot file
- runOperation(operation)[source]¶
Takes a
TreeOperation
instance and attempts to run it by attaching itself to it and calling its__call__()
method.See also
Note
Doing this will also automatically attach the given
TreeOperation
instance to thisExplorationTree
object.- Parameters
operation (
TreeOperation
) – aTreeOperation
instance to run
- fetchLeaves(increase_dist_improve_counter=False)[source]¶
Gives a
tuple
ofMolpherMol
instances that represent the leaves of thisExplorationTree
.- Returns
tuple
ofMolpherMol
instances representing the leaves of this tree- Return type
- fetchMol(canonSMILES)[source]¶
Attempts to fetch a molecule (represented by its canonical SMILES string) from the current tree. If the molecule exists, it returns an appropriate
MolpherMol
instance. Otherewise, it raises aRuntimeError
.- Parameters
canonSMILES (
str
) – astr
representing SMILES of the molecule being searched for- Returns
MolpherMol
representing the looked up molecule- Return type
- Raises
RuntimeError
if the molecule specified could not be found in the tree
- hasMol(canonSMILES)[source]¶
Returns
True
orFalse
to indicate the presence of a molecule in the current tree.
- deleteSubtree(canonSMILES, descendents_only=False)[source]¶
Deletes a specified molecule from the tree and all of its descendents.
- generateMorphs(*args)[source]¶
Generates mew candidate morphs using the current exploration parameters and saves them (see
ExplorationData
for details).The generated compounds can be retrieved using the
getCandidateMorphs
method.Note
All morphs already present in the tree are filtered out automatically.
- sortMorphs()[source]¶
Sorts the candidate morphs according to their distances from the target molecule.
Warning
When morphs are generated the distance to the current target is saved for each morph. This distance is not updated if the target of the tree changes afterwards.
- filterMorphs(*args)[source]¶
Filters the candidate morphs according to the supplied filtering options (see the table below for a listing of the available filters). The filtering options can be easily combined and passed to the method using the
|
operator. For example, the method can be called like this:tree.filterMorphs(FilterMorphsOper.SYNTHESIS | FilterMorphsOper.PROBABILITY)
. If no filter information is passed, all filters are used automatically (equal to passingFilterMorphsOper.ALL
).¶ Option
Description
Filter the
candidate morphs
according to probability based on their position inExplorationTree.candidates
.Remove molecules that do not satisfy the weight constraints.
The inbuilt synthetic feasibility filter.
Maximum number of morphs derived from one molecule.
Remove candidates that are already in the tree (always on).
Remove candidates that have already been tried by their parents.
Use all of the above filters.
The results of the filtering can be observed using the
getCandidateMorphsMask
method.See also
- Parameters
*args (
FilterMorphsOper
options) – one or more filtering options combined using the|
operator
- extend()[source]¶
Attach all candidate morphs that have not been filtered out to the tree. In other words, make them the new leaves.
Note
By calling this method a
morphing iteration
is committed.
- prune()[source]¶
Perform the pruning of the tree according to the rules specified by current exploration parameters (see
ExplorationData
for details).
- getThreadCount()[source]¶
Returns the number of threads this particular
ExplorationTree
will use. The value of 0 indicates that the same number of threads as the number of available cores will be used.
- asData()[source]¶
Can be used to obtain the current exploration parameters.
- Returns
instance of
ExplorationData
, which holds the current configuration options for the computations on the tree- Return type
- getCandidateMorphs()[source]¶
Gives a
tuple
ofMolpherMol
instances that represent thecandidate morphs
of thisExplorationTree
instance.- Returns
tuple
ofMolpherMol
instances representing thecandidate morphs
- Return type
- getCandidateMorphsMask()[source]¶
Returns a mask for the
tuple
returned bygetCandidateMorphs
. The filtered out morphs are denoted byFalse
at the respective position in the mask.Morphs filtered out in this way will not be attached to the tree when
extend()
is called.- Returns
tuple
ofbool
instances which shows what candidate morphs were filtered out- Return type
- getGenerationCount()[source]¶
Returns the number of morph generations in the tree. Basically the number of morphing iterations performed so far.
- Returns
number of morphing iterations performed so far
- Return type
- setThreadCount(threadCnt)[source]¶
Sets the maximum number of threads used by this instance. The value of 0 indicates that the same number of threads as the number of available cores will be used.
- update(data)[source]¶
Change the current exploration parameters for this instance. If the supplied
ExplorationData
instance contains a tree topology, it is ignored and only the parameters are taken into account.Warning
This may invalidate some data in the tree (such as the distances from the target molecule computed so far).
- Parameters
param (
ExplorationData
) – an instance ofExplorationData
, which represents the new exploration parameters for this instance
- setCandidateMorphsMask(mask)[source]¶
Sets the morphs’ mask of this instance to a custom value. If the length of the new mask does not correspond to the number of candidate morphs in the tree, a
RuntimeError
will be raised.- Parameters
mask (
tuple
) –tuple
ofbool
instances which shows what candidate morphs will be filtered out (not attached to the tree whenextend()
is called)- Raises
RuntimeError
if the length of the new mask does not correspond to the number of candidate morphs in the tree
- traverse(*args)[source]¶
Traverses the tree and calls the
()
of the callback on each morph in it. A SMILES string of a root of a subtree can be specified before the callback in order to traverse just the subtree.- Parameters
*args (
TraverseCallback
orstr
andTraverseCallback
) – either an instance of a class derived fromTraverseCallback
or both SMILES of the root of a subtree and aTraverseCallback