Class Smirks

java.lang.Object
org.openscience.cdk.smirks.Smirks

public class Smirks extends Object
Support for parsing a SMIRKS transform and utilities to parse/apply in one step.

 if (Smirks.apply(mol, "[*:1][H]>>[*:1]Cl")) {
     System.err.println("Success!");
 }
 

If the SMIRKS is invalid a runtime exception is thrown. If you expect to be processing possibly invalid inputs consider using the more verbose parse(org.openscience.cdk.isomorphism.Transform, String) function and apply it separately. Note you can parse in either the low-level Transform or the higher-level SmirksTransform.

 {@code
 Transform transform = new Transform();
 if (!Smirks.parse(transform, "[*:1][H]>>[*:1]Cl"))
   System.err.println("BAD SMIRKS: " + transform.message());

 IAtomContainer mol = ...;
 if (transform.apply(mol)) {
     // was applied!
 } else {
     // was not apply!
 }

 // apply to a copy of the input molecule
 for (IAtomContainer cpy : transform.apply(mol, Transform.Mode.Exclusive)) {

 }
 </pre>

 The higher level 'SmirksTransform' will automatically prepare the molecule
 for matching (ring flags/aromaticity).

 <pre>
 Transform transform = Smirks.compile("[C:1][H]>>[C:1]Cl");
 IAtomContainer mol = ...;
 if (transform.apply(mol)) {
   // was applied!
 } else {
   // was not apply!
 }
 </pre>

 @see org.openscience.cdk.isomorphism.Transform
 @see org.openscience.cdk.smirks.SmirksTransform
  • Method Details

    • compile

      public static SmirksTransform compile(String smirks)
      Convenience function to compile a SMIRKS string into a transform.
      
       Smirks.compile("[*:1][H]>>[*:1]Cl")
             .apply(mol);
       

      If the SMIRKS is invalid a runtime exception is thrown. If you expect to be processing possibly invalid inputs consider using the more verbose parse(org.openscience.cdk.isomorphism.Transform, String) function.

      Parameters:
      smirks - the SMIRKS string
      Returns:
      a SmirksTransform
    • apply

      public static boolean apply(IAtomContainer mol, String smirks)
      Convenience function to compile and apply a SMIRKS string on a molecule to all non-overlapping (exclusive) matches.
      
       if (Smirks.apply(mol, "[*:1][H]>>[*:1]Cl")) {
           System.err.println("Success!");
       }
       

      If the SMIRKS is invalid a runtime exception is thrown. If you expect to be processing possibly invalid inputs consider using the more verbose parse(org.openscience.cdk.isomorphism.Transform, String) function and apply it separately.

      Parameters:
      mol - the molecule to apply the SMIRKS to
      smirks - the SMIRKS string
      Returns:
      the pattern was applied or not
      See Also:
    • apply

      public static Iterable<IAtomContainer> apply(IAtomContainer mol, String smirks, Transform.Mode mode)
      Convenience function to compile and apply a SMIRKS string on a copy of the molecule returning the places the transform matched and applied.
      
       for (IAtomContainer res : Smirks.apply(mol, "[*:1][H]>>[*:1]Cl")) {
          // ... further process result molecule
       }
       

      If the SMIRKS is invalid a runtime exception is thrown. If you expect to be processing possibly invalid inputs consider using the more verbose parse(org.openscience.cdk.isomorphism.Transform, String) function and apply it separately.

      Parameters:
      mol - the molecule to apply the SMIRKS to
      smirks - the SMIRKS string
      Returns:
      the pattern was applied or not
      See Also:
    • parse

      public static boolean parse(Transform transform, String smirks, Set<SmirksOption> options)
      Parse a SMIRKS string into a transform.
       
       Transform transform = new SmirksTransform();
       if (!Smirks.parse(transform, "[*:1][H]>>[*:1]Cl")) {
         System.err.println("BAD SMIRKS: " + transform.message());
         return;
       }
      
       IAtomContainer mol = ...;
       transform.apply(mol);
       
       

      If the SMIRKS could not be interpreted or was invalid this method returns false and sets the transform into an error state meaning calling apply() will do nothing. The Transform.message() may still be set if there were warnings generated when interpreting the SMIRKS.

      Parameters:
      transform - the transform to load into
      smirks - the SMIRKS string
      options - options for parsing a SMIRKS
      Returns:
      the SMIRKS interpretable or not (there was an error)
      See Also:
    • parse

      public static boolean parse(Transform transform, String smirks, SmirksOption... options)
      Parse a SMIRKS string into a transform.
       
       Transform transform = new SmirksTransform();
       if (!Smirks.parse(transform, "[*:1][H]>>[*:1]Cl")) {
         System.err.println("BAD SMIRKS: " + transform.message());
         return;
       }
      
       IAtomContainer mol = ...;
       transform.apply(mol);
       
       

      If the SMIRKS could not be interpreted or was invalid this method returns false and sets the transform into an error state meaning calling apply() will do nothing. The Transform.message() may still be set if there were warnings generated when interpreting the SMIRKS.

      Parameters:
      transform - the transform to load into
      smirks - the SMIRKS string
      options - options for parsing a SMIRKS
      Returns:
      the SMIRKS interpretable or not (there was an error)
      See Also:
    • parse

      public static boolean parse(Transform transform, String smirks)
      Parse a SMIRKS string into a transform.
       
       Transform transform = new SmirksTransform();
       if (!Smirks.parse(transform, "[*:1][H]>>[*:1]Cl")) {
         System.err.println("BAD SMIRKS: " + transform.message());
         return;
       }
      
       IAtomContainer mol = ...;
       transform.apply(mol);
       
       

      If the SMIRKS could not be interpreted or was invalid this method returns false and sets the transform into an error state meaning calling apply() will do nothing. The Transform.message() may still be set if there were warnings generated when interpreting the SMIRKS.

      Parameters:
      transform - the transform to load into
      smirks - the SMIRKS string
      Returns:
      the SMIRKS interpretable or not (there was an error)
      See Also: