public final class SmilesGenerator extends Object
SmiFlavor
are used:
SmilesGenerator smigen = new SmilesGenerator(SmiFlavor.Isomeric);
SmiFlavor
provides more fine grained control, for example,
for the following is equivalent to SmiFlavor.Isomeric
:
SmilesGenerator smigen = new SmilesGenerator(SmiFlavor.Stereo | SmiFlavor.AtomicMass);Bitwise logic can be used such that we can remove options:
SmiFlavor.Isomeric
^
SmiFlavor.AtomicMass
will generate isomeric SMILES without atomic mass.
A generator instance is created using one of the static methods, the SMILES
are then created by invoking create(IAtomContainer)
.
The isomeric and absolute generator encode tetrahedral and double bond stereochemistry usingIAtomContainer ethanol = ...; SmilesGenerator sg = new SmilesGenerator(SmiFlavor.Generic); String smi = sg.create(ethanol); // CCO, C(C)O, C(O)C, or OCC SmilesGenerator sg = new SmilesGenerator(SmiFlavor.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
re-perceived by most tool kits whilst kekulisation may fail. If you
really want aromatic SMILES the following code demonstrates
It can be useful to know the output order of SMILES. On input the order of the atoms reflects the atom index. If we know this order we can refer to atoms by index and associate data with the SMILES string. The output order is obtained by parsing in an auxiliary array during creation. The following snippet demonstrates how we can write coordinates in order.IAtomContainer benzene = ...; // 'benzene' molecule has no arom flags, we always get Kekulé output SmilesGenerator sg = new SmilesGenerator(SmiFlavor.Generic); String smi = sg.create(benzene); // C1=CC=CC=C1 SmilesGenerator sg = new SmilesGenerator(SmiFlavor.Generic | SmiFlavor.UseAromaticSymbols); String smi = sg.create(benzene); // C1=CC=CC=C1 flags not set! // Note, in practice we'd use an aromaticity algorithm for (IAtom a : benzene.atoms()) a.setIsAromatic(true); for (IBond b : benzene.bond()) a.setIsAromatic(true); // 'benzene' molecule now has arom flags, we always get aromatic SMILES if we request it SmilesGenerator sg = new SmilesGenerator(SmiFlavor.Generic); String smi = sg.create(benzene); // C1=CC=CC=C1 SmilesGenerator sg = new SmilesGenerator(SmiFlavor.Generic | SmiFlavor.UseAromaticSymbols); String smi = sg.create(benzene); // c1ccccc1
Using the output order of SMILES forms the basis of ChemAxon Extended SMILES (CXSMILES) which can also be generated. Extended SMILES allows additional structure data to be serialized including, atom labels/values, fragment grouping (for salts in reactions), polymer repeats, multi center bonds, and coordinates. The CXSMILES layer is appended after the SMILES so that parser which don't interpret it can ignore it. The two aggregate flavours areIAtomContainer mol = ...; SmilesGenerator sg = new SmilesGenerator(SmiFlavor.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);
SmiFlavor.CxSmiles
and SmiFlavor.CxSmilesWithCoords
.
As with other flavours, fine grain control is possible SmiFlavor
.
Aromaticity
,
Stereocenters
,
StereoElementFactory
,
ITetrahedralChirality
,
IDoubleBondStereochemistry
,
CDKConstants
,
SmilesParser
Constructor and Description |
---|
SmilesGenerator()
Deprecated.
use
SmilesGenerator(int) configuring with SmiFlavor . |
SmilesGenerator(int flavour)
Create a SMILES generator with the specified
SmiFlavor . |
Modifier and Type | Method and Description |
---|---|
static SmilesGenerator |
absolute()
Create a absolute SMILES generator.
|
SmilesGenerator |
aromatic()
Deprecated.
configure with
SmiFlavor |
String |
create(IAtomContainer molecule)
Generate SMILES for the provided
molecule . |
String |
create(IAtomContainer molecule,
int[] order)
Creates a SMILES string of the flavour specified in the constructor
and write the output order to the provided array.
|
static String |
create(IAtomContainer molecule,
int flavour,
int[] order)
Creates a SMILES string of the flavour specified as a parameter
and write the output order to the provided array.
|
String |
create(IReaction reaction)
Create a SMILES for a reaction of the flavour specified in the constructor.
|
String |
create(IReaction reaction,
int[] ordering)
Create a SMILES for a reaction of the flavour specified in the constructor and
write the output order to the provided array.
|
String |
createReactionSMILES(IReaction reaction)
Deprecated.
|
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()
Deprecated.
configure with
SmiFlavor |
@Deprecated public SmilesGenerator()
SmiFlavor.Default
but is best to choose/set this flavor.SmiFlavor.Default
public SmilesGenerator aromatic()
SmiFlavor
SmilesGenerator(int)
constructor:
SmilesGenerator smigen = new SmilesGenerator(SmiFlavor.UseAromaticSymbols);
@Deprecated public SmilesGenerator withAtomClasses()
SmiFlavor
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 of@Deprecated public String createSMILES(IReaction reaction)
reaction
- the reaction to create the SMILES ofpublic 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 = new SmilesGenerator(); 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 static String create(IAtomContainer molecule, int flavour, int[] order) throws CDKException
IAtomContainer mol = ...; SmilesGenerator sg = new SmilesGenerator(); 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
- a valid SMILES could not be created@Deprecated public String createReactionSMILES(IReaction reaction) throws CDKException
create(IAtomContainer)
reaction
- CDK reaction instanceCDKException
- a valid SMILES could not be createdpublic String create(IReaction reaction) throws CDKException
reaction
- CDK reaction instanceCDKException
public String create(IReaction reaction, int[] ordering) throws CDKException
reaction
- CDK reaction instanceCDKException
@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 © 2017. All Rights Reserved.