Class Smirks
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 Summary
Modifier and TypeMethodDescriptionstatic booleanapply(IAtomContainer mol, String smirks) Convenience function to compile and apply a SMIRKS string on a molecule to all non-overlapping (exclusive) matches.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.static SmirksTransformConvenience function to compile a SMIRKS string into a transform.static booleanParse a SMIRKS string into a transform.static booleanparse(Transform transform, String smirks, Set<SmirksOption> options) Parse a SMIRKS string into a transform.static booleanparse(Transform transform, String smirks, SmirksOption... options) Parse a SMIRKS string into a transform.
-
Method Details
-
compile
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
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 tosmirks- 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 tosmirks- the SMIRKS string- Returns:
- the pattern was applied or not
- See Also:
-
parse
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. TheTransform.message()may still be set if there were warnings generated when interpreting the SMIRKS.- Parameters:
transform- the transform to load intosmirks- the SMIRKS stringoptions- options for parsing a SMIRKS- Returns:
- the SMIRKS interpretable or not (there was an error)
- See Also:
-
parse
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. TheTransform.message()may still be set if there were warnings generated when interpreting the SMIRKS.- Parameters:
transform- the transform to load intosmirks- the SMIRKS stringoptions- options for parsing a SMIRKS- Returns:
- the SMIRKS interpretable or not (there was an error)
- See Also:
-
parse
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. TheTransform.message()may still be set if there were warnings generated when interpreting the SMIRKS.- Parameters:
transform- the transform to load intosmirks- the SMIRKS string- Returns:
- the SMIRKS interpretable or not (there was an error)
- See Also:
-