Package org.openscience.cdk.isomorphism
Class Transform
- java.lang.Object
-
- org.openscience.cdk.isomorphism.Transform
-
- Direct Known Subclasses:
SmirksTransform
public class Transform extends Object
Transform a molecule using a query pattern and a sequence ofTransformOp
s. The query pattern is matched against a given molecule and based on that mapping a series of additions/deletions/changes are made. Transformations can be used for both standardisation/normalisation and library generation.
This base class provides the low level implementation needed to run a transformation, in practice you would use something likeSmirks
in thecdk-smarts
module to parse a transform from a string representation.
The simplest way to use a transform is theapply(org.openscience.cdk.interfaces.IAtomContainer)
method, this runs the transform in-place over non-overlapping matches.
Note that non-overlapping matches can depend on the order of the atoms in a query or molecule being transformed. A more verbose mode is to provide the optional secondTransform tform = new Transform(); if (Smirks.parse(tform, "[*:1][NH2D1:2]>>[*:1]O amine to hydroxy")) { IAtomContainer mol = ...; tform.apply(mol); // replace all NH2 groups with OH }
Transform.Mode
argument, this results in a copy of the input molecule being made multiple results being returned:Transform tform = new Transform(); if (Smirks.parse(tform, "[*:1][NH2D1:2]>>[*:1]O amine to hydroxy")) { IAtomContainer mol = ...; // replace each NH2 groups with OH one at a time for (IAtomContainer copy : tform.apply(mol, Mode.All)) { } }
- Author:
- John Mayfield
- See Also:
Pattern
,TransformOp
,Smirks
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Transform.Mode
-
Constructor Summary
Constructors Constructor Description Transform()
Create an empty transform.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
apply(IAtomContainer mol)
Applies the exclusive transform to the provided molecule modifying it as required.boolean
apply(IAtomContainer mol, int limit)
Applies the exclusive transform to the provided molecule modifying it as required.Iterable<IAtomContainer>
apply(IAtomContainer mol, Transform.Mode mode)
Apply the transform to the provided molecule and obtain the results of applying the transform.Iterable<IAtomContainer>
apply(IAtomContainer mol, Transform.Mode mode, int limit)
Apply the transform to the provided molecule and obtain the results of applying the transform.void
init(Pattern pattern, List<TransformOp> ops)
Initialize the transform.void
init(Pattern pattern, List<TransformOp> ops, String warning)
Initialize the transform.String
message()
Access the warning/error message on a problem found with the transform.void
reset()
Reset this transform so it can be reused.boolean
setError(String message)
Indicate there is an error with this transform.
-
-
-
Method Detail
-
init
public void init(Pattern pattern, List<TransformOp> ops, String warning)
Initialize the transform.- Parameters:
pattern
- the substructure pattern to matchops
- the ops to run on the atoms of the patternwarning
- the warning message (optional)
-
init
public void init(Pattern pattern, List<TransformOp> ops)
Initialize the transform.- Parameters:
pattern
- the substructure pattern to matchops
- the ops to run on the atoms of the pattern
-
setError
public boolean setError(String message)
Indicate there is an error with this transform. This method will clear any existing message and status. Any attempt to callapply(org.openscience.cdk.interfaces.IAtomContainer)
will be ignored (no-op) and return false (did not apply).
You can clear the error status by calling,init(Pattern, java.util.List)
.- Parameters:
message
- the warning/error message- Returns:
- returns false
-
message
public String message()
Access the warning/error message on a problem found with the transform.- Returns:
- the message (null if there are no warnings or errors)
-
reset
public void reset()
Reset this transform so it can be reused. This will set the status to Error and indicate a message that the transform is not initialized.
-
apply
public Iterable<IAtomContainer> apply(IAtomContainer mol, Transform.Mode mode, int limit)
Apply the transform to the provided molecule and obtain the results of applying the transform. The original molecule is NOT modified.- Parameters:
mol
- the molecule to transformmode
- how to transform the moleculelimit
- maximum number of matches- Returns:
- an iterable which may be empty or contain copies of the molecule transformed
-
apply
public Iterable<IAtomContainer> apply(IAtomContainer mol, Transform.Mode mode)
Apply the transform to the provided molecule and obtain the results of applying the transform. The original molecule is NOT modified.- Parameters:
mol
- the molecule to transformmode
- how to transform the molecule- Returns:
- an iterable which may be empty or contain copies of the molecule transformed
-
apply
public boolean apply(IAtomContainer mol, int limit)
Applies the exclusive transform to the provided molecule modifying it as required.- Parameters:
mol
- the molecule to modifylimit
- limit the number of matches- Returns:
- the molecule was modified or not
-
apply
public boolean apply(IAtomContainer mol)
Applies the exclusive transform to the provided molecule modifying it as required.- Parameters:
mol
- the molecule to modify- Returns:
- the molecule was modified or not
-
-