Class Transform

  • Direct Known Subclasses:
    SmirksTransform

    public class Transform
    extends Object
    Transform a molecule using a query pattern and a sequence of TransformOps. 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 like Smirks in the cdk-smarts module to parse a transform from a string representation.
    The simplest way to use a transform is the apply(org.openscience.cdk.interfaces.IAtomContainer) method, this runs the transform in-place over non-overlapping matches.
    
     Transform 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
     }
     
    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 second 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
    • Constructor Detail

      • Transform

        public Transform()
        Create an empty transform.
    • Method Detail

      • init

        public void init​(Pattern pattern,
                         List<TransformOp> ops,
                         String warning)
        Initialize the transform.
        Parameters:
        pattern - the substructure pattern to match
        ops - the ops to run on the atoms of the pattern
        warning - the warning message (optional)
      • init

        public void init​(Pattern pattern,
                         List<TransformOp> ops)
        Initialize the transform.
        Parameters:
        pattern - the substructure pattern to match
        ops - 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 call apply(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 transform
        mode - how to transform the molecule
        limit - 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 transform
        mode - 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 modify
        limit - 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