@TestClass(value="org.openscience.cdk.smiles.SmilesGeneratorTest") public class SmilesGenerator extends Object
Some example code:
IMolecule benzene; // single/aromatic bonds between 6 carbons SmilesGenerator sg = new SmilesGenerator(); String smiles = sg.createSMILES(benzene); // C1CCCCC1 sg.setUseAromaticityFlag(true); smiles = sg.createSMILES(benzene); // c1ccccc1 IMolecule benzene2; // one of the two kekule structures with explicit double bond orders String smiles2 = sg.createSMILES(benzene2); // C1=CC=CC=C1NoteDue to the way the initial atom labeling is constructed, ensure that the input molecule is appropriately configured. In absence of such configuration it is possible that different forms of the same molecule will not result in the same canonical SMILES.
Constructor and Description |
---|
SmilesGenerator()
Create the SMILES generator.
|
SmilesGenerator(boolean useAromaticityFlag)
Create the SMILES generator.
|
Modifier and Type | Method and Description |
---|---|
String |
createChiralSMILES(IAtomContainer molecule,
boolean[] doubleBondConfiguration)
Generate canonical and chiral SMILES from the
molecule . |
String |
createSMILES(IAtomContainer molecule)
Generate canonical SMILES from the
molecule . |
String |
createSMILES(IAtomContainer molecule,
boolean chiral,
boolean[] doubleBondConfiguration)
Generate canonical SMILES from the
molecule . |
String |
createSMILES(IReaction reaction)
Generate a SMILES for the given
Reaction . |
String |
createSMILESWithoutCheckForMultipleMolecules(IAtomContainer molecule,
boolean chiral,
boolean[] doubleBondConfiguration)
Generate canonical SMILES from the
molecule . |
AllRingsFinder |
getRingFinder()
Returns the current AllRingsFinder instance
|
boolean |
isValidDoubleBondConfiguration(IAtomContainer container,
IBond bond)
Tells if a certain bond is center of a valid double bond configuration.
|
void |
setRingFinder(AllRingsFinder ringFinder)
Sets the current AllRingsFinder instance
Use this if you want to customize the timeout for
the AllRingsFinder.
|
SmilesGenerator |
setRings(IRingSet rings)
Provide a reference to a RingSet that holds ALL rings of the molecule.
During creation of a SMILES the aromaticity of the molecule has to be detected. |
void |
setUseAromaticityFlag(boolean useAromaticityFlag)
Indicates whether output should be an aromatic SMILES.
|
public SmilesGenerator()
public SmilesGenerator(boolean useAromaticityFlag)
useAromaticityFlag
- if false only SP2-hybridized atoms will be lower case (default), true=SP2 or aromaticity trigger lower case (same as using setUseAromaticityFlag later)public boolean isValidDoubleBondConfiguration(IAtomContainer container, IBond bond)
container
- The atomcontainer.bond
- The bond.public SmilesGenerator setRings(IRingSet rings)
rings
- RingSet that holds ALL rings of the molecule@TestMethod(value="testCisResorcinol,testEthylPropylPhenantren,testAlanin") public String createSMILES(IAtomContainer molecule)
molecule
. This method
canonicaly lables the molecule but does not perform any checks on the
chemical validity of the molecule.
IMPORTANT: A precomputed Set of All Rings (SAR) can be passed to this
SmilesGenerator in order to avoid recomputing it. Use setRings() to
assign the SAR.molecule
- The molecule to evaluateCanonicalLabeler.canonLabel(IAtomContainer)
public String createSMILES(IReaction reaction) throws CDKException
Reaction
.reaction
- the reaction in questionCDKException
- if there is an error during SMILES generation@TestMethod(value="testAlaSMILES,testSugarSMILES") public String createChiralSMILES(IAtomContainer molecule, boolean[] doubleBondConfiguration) throws CDKException
molecule
. This
method canonicaly lables the molecule but dose not perform any checks on
the chemical validity of the molecule. The chiral smiles is done like in
the
daylight theory manual . I did not find rules for canonical and chiral
smiles, therefore there is no guarantee that the smiles complies to any
externeal rules, but it is canonical compared to other smiles produced by
this method. The method checks if there are 2D coordinates but does not
check if coordinates make sense. Invalid stereo configurations are ignored;
if there are no valid stereo configuration the smiles will be the same as
the non-chiral one. Note that often stereo configurations are only complete
and can be converted to a smiles if explicit Hs are given.
IMPORTANT: A precomputed Set of All Rings (SAR) can be passed to this
SmilesGenerator in order to avoid recomputing it. Use setRings() to
assign the SAR.molecule
- The molecule to evaluate.doubleBondConfiguration
- Should E/Z configurations be read at these positions? If the flag at position X is set to true,
an E/Z configuration will be written from coordinates around bond X, if false, it will be ignored.
If flag is true for a bond which does not constitute a valid double bond configuration, it will be
ignored (meaning setting all to true will create E/Z indication will be pu in the smiles wherever
possible, but note the coordinates might be arbitrary).CDKException
- At least one atom has no Point2D;
coordinates are needed for creating the chiral smiles.CanonicalLabeler.canonLabel(IAtomContainer)
public String createSMILES(IAtomContainer molecule, boolean chiral, boolean[] doubleBondConfiguration) throws CDKException
molecule
. This method
canonicaly lables the molecule but dose not perform any checks on the
chemical validity of the molecule. This method also takes care of multiple
molecules.
IMPORTANT: A precomputed Set of All Rings (SAR) can be passed to this
SmilesGenerator in order to avoid recomputing it. Use setRings() to
assign the SAR.molecule
- The molecule to evaluate.chiral
- true=SMILES will be chiral, false=SMILES.
will not be chiral.doubleBondConfiguration
- Should E/Z configurations be read at these positions? If the flag at position X is set to true,
an E/Z configuration will be written from coordinates around bond X, if false, it will be ignored.
If flag is true for a bond which does not constitute a valid double bond configuration, it will be
ignored (meaning setting all to true will create E/Z indication will be pu in the smiles wherever
possible, but note the coordinates might be arbitrary).CDKException
- At least one atom has no Point2D;
coordinates are needed for crating the chiral smiles. This excpetion
can only be thrown if chiral smiles is created, ignore it if you want a
non-chiral smiles (createSMILES(AtomContainer) does not throw an
exception).CanonicalLabeler.canonLabel(IAtomContainer)
@TestMethod(value="testCreateSMILESWithoutCheckForMultipleMolecules_withDetectAromaticity,testCreateSMILESWithoutCheckForMultipleMolecules_withoutDetectAromaticity") public String createSMILESWithoutCheckForMultipleMolecules(IAtomContainer molecule, boolean chiral, boolean[] doubleBondConfiguration) throws CDKException
molecule
. This method
canonicaly lables the molecule but dose not perform any checks on the
chemical validity of the molecule. Does not care about multiple molecules.
IMPORTANT: A precomputed Set of All Rings (SAR) can be passed to this
SmilesGenerator in order to avoid recomputing it. Use setRings() to
assign the SAR.molecule
- The molecule to evaluate.chiral
- true=SMILES will be chiral, false=SMILES
will not be chiral.doubleBondConfiguration
- Should E/Z configurations be read at these positions? If the flag at position X is set to true,
an E/Z configuration will be written from coordinates around bond X, if false, it will be ignored.
If flag is true for a bond which does not constitute a valid double bond configuration, it will be
ignored (meaning setting all to true will create E/Z indication will be pu in the smiles wherever
possible, but note the coordinates might be arbitrary).CDKException
- At least one atom has no Point2D;
coordinates are needed for creating the chiral smiles. This excpetion
can only be thrown if chiral smiles is created, ignore it if you want a
non-chiral smiles (createSMILES(AtomContainer) does not throw an
exception).CanonicalLabeler.canonLabel(IAtomContainer)
public AllRingsFinder getRingFinder()
public void setRingFinder(AllRingsFinder ringFinder)
ringFinder
- The value to assign ringFinder.AllRingsFinder
@TestMethod(value="testSFBug956923") public void setUseAromaticityFlag(boolean useAromaticityFlag)
useAromaticityFlag
- if false only SP2-hybridized atoms will be lower case (default),
true=SP2 or aromaticity trigger lower case