G'day,
My primary usage of CDK is for 2D structure diagram generation and layout.
Here's the code I currently use for this purpose (with some
simplification for brevity):
private static IAtomContainer layoutMolecule(final IMolecule mol)
{
// Implicit hydrogens.
final IAtomContainer ac = makeHydrogensImplicit(mol);
// Aromaticity.
try
{
HueckelAromaticityDetector.detectAromaticity(ac);
}
catch (final CDKException e)
{
DVLogger.warningDetailed("Failed to calculate aromaticity", e);
}
ac.setProperties(mol.getProperties()); // restore properties.
return layout2D(ac); // do layout.
}
public static IAtomContainer makeHydrogensImplicit(final IMolecule mol)
{
// Explicit -> Implicit H: addExH then removeH is better than
// removeH then addImpH.
final IMolecule m2 =
DefaultChemObjectBuilder.getInstance().newMolecule(mol);
try
{
new HydrogenAdder(new ValencyHybridChecker()).
addHydrogensToSatisfyValency(m2);
}
catch (final Throwable e)
{
DVLogger.warningDetailed("Failed to add hydrogens", e);
}
// Explicit -> Implicit H.
return new MFAnalyser(m2).removeHydrogensPreserveMultiplyBonded();
}
public static IAtomContainer layout2D(final IAtomContainer ac)
{
// Generate 2D coordinates?
if (GeometryTools.has2DCoordinates(ac))
{
return ac;
}
else
{
// Generate 2D structure diagram (for each connected component).
final AtomContainer ac2d = new AtomContainer();
final IMoleculeSet som =
ConnectivityChecker.partitionIntoMolecules(ac);
final StructureDiagramGenerator sdg =
new StructureDiagramGenerator();
for (int n = 0;
n < som.getMoleculeCount();
n++)
{
IMolecule mol = som.getMolecule(n);
sdg.setMolecule(mol, true);
try
{
// Generate 2D coords for this molecule.
sdg.generateCoordinates();
mol = sdg.getMolecule();
}
catch (final Exception e)
{
DVLogger.warning("Failed to generate 2D structure for " +
ac.getID() + " (" + n + ") - using projection", e);
Projector.project2D(mol);
}
ac2d.add(mol); // add 2D molecule.
}
return GeometryTools.has2DCoordinates(ac2d) ? ac2d : null;
}
}
However, this is based on CDK circa Aug 2005, so things might have
changed since then.
What's considered best-practise for 2D structure diagram generation with
CDK v1.0.x?
Our structures come primarily from SD files or SMILES strings.
Thanks,
Chris.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
Cdk-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cdk-user