1.1.1.3.1.1.1.2. ExplorationTree¶
-
class
molpher.swig_wrappers.core.ExplorationTree(*args, **kwargs)[source]¶ Represents an
exploration treeand facilitates the most basic interaction with it. It is a tight wrapper around the C++ implementation. Themolpher.core.ExplorationTreeclass 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
ExplorationTreeinstance using a suppliedExplorationData, tree snapshot or SMILES strings of the source molecule and the target molecule.Parameters: *args ( ExplorationDataorstr) – anExplorationDatainstance, path to a tree snapshot or a source molecule and a target molecule as two arguments.Returns: ExplorationTreeinstance created from the supplied snapshotReturn type: ExplorationTree
-
save(filename)[source]¶ Saves the tree to a snapshot file. The filename should end with either
.xmlor.snp.Parameters: filename ( str) – path to the new snapshot file
-
runOperation(operation)[source]¶ Takes a
TreeOperationinstance 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
TreeOperationinstance to thisExplorationTreeobject.Parameters: operation ( TreeOperation) – aTreeOperationinstance to run
-
fetchLeaves(increase_dist_improve_counter=False)[source]¶ Gives a
tupleofMolpherMolinstances that represent the leaves of thisExplorationTree.Returns: tupleofMolpherMolinstances representing the leaves of this treeReturn type: tuple
-
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
MolpherMolinstance. Otherewise, it raises aRuntimeError.Parameters: canonSMILES ( str) – astrrepresenting SMILES of the molecule being searched forReturns: MolpherMolrepresenting the looked up moleculeReturn type: MolpherMolRaises: RuntimeErrorif the molecule specified could not be found in the tree
-
hasMol(canonSMILES)[source]¶ Returns
TrueorFalseto indicate the presence of a molecule in the current tree.Parameters: canonSMILES ( str) – astrrepresenting SMILES of the molecule being searched forReturns: boolvalue representing the presence of the searched molecule in this tree (Trueif it is present,Falseotherwise)Return type: bool
-
deleteSubtree(canonSMILES, descendents_only=False)[source]¶ Deletes a specified molecule from the tree and all of its descendents.
Parameters: canonSMILES ( str) – astrrepresenting SMILES of the molecule being removed
-
generateMorphs()[source]¶ Generates mew candidate morphs using the current exploration parameters and saves them (see
ExplorationDatafor details).The generated compounds can be retrieved using the
getCandidateMorphsmethod.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).Table 1.5 Filtering options and their descriptions.¶ Option Description PROBABILITYFilter the candidate morphsaccording to probability based on their position inExplorationTree.candidates.WEIGHTRemove molecules that do not satisfy the weight constraints. SYNTHESISThe inbuilt synthetic feasibility filter. MAX_DERIVATIONSMaximum number of morphs derived from one molecule. DUPLICATESRemove candidates that are already in the tree (always on). HISTORIC_DESCENDENTSRemove candidates that have already been tried by their parents. ALLUse all of the above filters. The results of the filtering can be observed using the
getCandidateMorphsMaskmethod.See also
Parameters: *args ( FilterMorphsOperoptions) – 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 iterationis committed.
-
prune()[source]¶ Perform the pruning of the tree according to the rules specified by current exploration parameters (see
ExplorationDatafor details).
-
getThreadCount()[source]¶ Returns the number of threads this particular
ExplorationTreewill 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 treeReturn type: ExplorationData
-
getCandidateMorphs()[source]¶ Gives a
tupleofMolpherMolinstances that represent thecandidate morphsof thisExplorationTreeinstance.Returns: tupleofMolpherMolinstances representing thecandidate morphsReturn type: tuple
-
getCandidateMorphsMask()[source]¶ Returns a mask for the
tuplereturned bygetCandidateMorphs. The filtered out morphs are denoted byFalseat the respective position in the mask.Morphs filtered out in this way will not be attached to the tree when
extendis called.Returns: tupleofboolinstances which shows what candidate morphs were filtered outReturn type: tuple
-
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: int
-
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.
Parameters: threadCnt ( int) – anintindicating the number of threads to use
-
update(data)[source]¶ Change the current exploration parameters for this instance. If the supplied
ExplorationDatainstance 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
RuntimeErrorwill be raised.Parameters: mask ( tuple) –tupleofboolinstances which shows what candidate morphs will be filtered out (not attached to the tree whenextend()is called)Raises: RuntimeErrorif 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 ( TraverseCallbackorstrandTraverseCallback) – either an instance of a class derived fromTraverseCallbackor both SMILES of the root of a subtree and aTraverseCallback
-
static