@TestClass(value="org.openscience.cdk.smiles.SmilesGeneratorTest") public final class SmilesGenerator extends Object
create(IAtomContainer)
.
The isomeric and absolute generator encode tetrahedral and double bond stereochemistry usingIAtomContainer ethanol = ...; SmilesGenerator sg = SmilesGenerator.generic(); String smi = sg.create(ethanol); // CCO or OCC SmilesGenerator sg = SmilesGenerator.unique(); String smi = sg.create(ethanol); // only CCO
IStereoElement
s
provided on the IAtomContainer
. If stereochemistry is not being
written it may need to be determined from 2D/3D coordinates using
StereoElementFactory
.
By default the generator will not write aromatic SMILES. Kekulé SMILES are
generally preferred for compatibility and aromaticity can easily be
reperceived. Modifying a generator to produce aromatic()
SMILES
will use the CDKConstants.ISAROMATIC
flags.
These flags can be set manually or with the
Aromaticity
utility.
By default atom classes are not written. Atom classes can be written but creating a generatorIAtomContainer benzene = ...; // with no flags set the output is always kekule SmilesGenerator sg = SmilesGenerator.generic(); String smi = sg.create(benzene); // C1=CC=CC=C1 SmilesGenerator sg = SmilesGenerator.generic() .aromatic(); String smi = sg.create(ethanol); // C1=CC=CC=C1 for (IAtom a : benzene.atoms()) a.setFlag(CDKConstants.ISAROMATIC, true); for (IBond b : benzene.bond()) b.setFlag(CDKConstants.ISAROMATIC, true); // with flags set, the aromatic generator encodes this information SmilesGenerator sg = SmilesGenerator.generic(); String smi = sg.create(benzene); // C1=CC=CC=C1 SmilesGenerator sg = SmilesGenerator.generic() .aromatic(); String smi = sg.create(ethanol); // c1ccccc1
withAtomClasses()
.
Auxiliary data can be stored with SMILES by knowing the output order of atoms. The following example demonstrates the storage of 2D coordinates.IAtomContainer benzene = ...; // see CDKConstants for property key benzene.getAtom(3) .setProperty(ATOM_ATOM_MAPPING, 42); SmilesGenerator sg = SmilesGenerator.generic(); String smi = sg.create(benzene); // C1=CC=CC=C1 SmilesGenerator sg = SmilesGenerator.generic() .withAtomClasses(); String smi = sg.create(ethanol); // C1=CC=[CH:42]C=C1
* the unique SMILES generation uses a fast equitable labelling procedure and as such there are some structures which may not be unique. The number of such structures is generally minimal.IAtomContainer mol = ...; SmilesGenerator sg = SmilesGenerator.generic(); int n = mol.getAtomCount(); int[] order = new int[n]; // the order array is filled up as the SMILES is generated String smi = sg.create(mol, order); // load the coordinates array such that they are in the order the atoms // are read when parsing the SMILES Point2d[] coords = new Point2d[mol.getAtomCount()]; for (int i = 0; i < coords.length; i++) coords[order[i]] = container.getAtom(i).getPoint2d(); // SMILES string suffixed by the coordinates String smi2d = smi + " " + Arrays.toString(coords);
Aromaticity
,
Stereocenters
,
StereoElementFactory
,
ITetrahedralChirality
,
IDoubleBondStereochemistry
,
CDKConstants
,
SmilesParser
Constructor and Description |
---|
SmilesGenerator()
Create the generic SMILES generator.
|
Modifier and Type | Method and Description |
---|---|
static SmilesGenerator |
absolute()
Create a absolute SMILES generator.
|
SmilesGenerator |
aromatic()
The generator should write aromatic (lower-case) SMILES.
|
String |
create(IAtomContainer molecule)
Generate SMILES for the provided
molecule . |
String |
create(IAtomContainer molecule,
int[] order)
Create a SMILES string and obtain the order which the atoms were
written.
|
String |
createReactionSMILES(IReaction reaction)
Generate a SMILES for the given
Reaction . |
String |
createSMILES(IAtomContainer molecule)
Deprecated.
use #create
|
String |
createSMILES(IReaction reaction)
Deprecated.
use #createReactionSMILES
|
static SmilesGenerator |
generic()
Create a generator for generic SMILES.
|
static SmilesGenerator |
isomeric()
Convenience method for creating an isomeric generator.
|
void |
setUseAromaticityFlag(boolean useAromaticityFlag)
Deprecated.
since 1.5.6, use
aromatic - invoking this method
does nothing |
static SmilesGenerator |
unique()
Create a unique SMILES generator.
|
SmilesGenerator |
withAtomClasses()
Specifies that the generator should write atom classes in SMILES.
|
public SmilesGenerator()
generic()
public SmilesGenerator aromatic()
IAtomContainer container = ...; SmilesGenerator smilesGen = SmilesGenerator.unique() .aromatic(); smilesGen.createSMILES(container);
public SmilesGenerator withAtomClasses()
CDKConstants.ATOM_ATOM_MAPPING
property. This method returns a new SmilesGenerator to use.
IAtomContainer container = ...; SmilesGenerator smilesGen = SmilesGenerator.unique() .atomClasses(); smilesGen.createSMILES(container); // C[CH2:4]O second atom has class = 4
public static SmilesGenerator generic()
public static SmilesGenerator isomeric()
[13C]
) and
stereo-chemistry.public static SmilesGenerator unique()
public static SmilesGenerator absolute()
@Deprecated public String createSMILES(IAtomContainer molecule)
molecule
- the molecule to create the SMILES ofCDKException
- SMILES could not be generated@Deprecated public String createSMILES(IReaction reaction)
reaction
- the reaction to create the SMILES ofCDKException
- SMILES could not be generated@TestMethod(value="testCisResorcinol,testEthylPropylPhenantren,testAlanin") public String create(IAtomContainer molecule) throws CDKException
molecule
.molecule
- The molecule to evaluateCDKException
- SMILES could not be createdpublic String create(IAtomContainer molecule, int[] order) throws CDKException
IAtomContainer mol = ...; SmilesGenerator sg = SmilesGenerator.generic(); int n = mol.getAtomCount(); int[] order = new int[n]; // the order array is filled up as the SMILES is generated String smi = sg.create(mol, order); // load the coordinates array such that they are in the order the atoms // are read when parsing the SMILES Point2d[] coords = new Point2d[mol.getAtomCount()]; for (int i = 0; i < coords.length; i++) coords[order[i]] = container.getAtom(i).getPoint2d(); // SMILES string suffixed by the coordinates String smi2d = smi + " " + Arrays.toString(coords);
molecule
- the molecule to writeorder
- array to store the output order of atomsCDKException
- SMILES could not be createdpublic String createReactionSMILES(IReaction reaction) throws CDKException
Reaction
.reaction
- the reaction in questionCDKException
- if there is an error during SMILES generation@TestMethod(value="testSFBug956923") @Deprecated public void setUseAromaticityFlag(boolean useAromaticityFlag)
aromatic
- invoking this method
does nothinguseAromaticityFlag
- if false only SP2-hybridized atoms will be lower case (default),
true=SP2 or aromaticity trigger lower caseCopyright © 2014. All Rights Reserved.