use of org.openscience.cdk.tools.CDKHydrogenAdder in project Smiles2Monomers by yoann-dufresne.
the class SmilesConverter method transform.
public Molecule transform(String smiles, boolean addHydrogens, boolean calculateCoordinate, boolean expliciteHydrogens) throws InvalidSmilesException {
Molecule imol = null;
try {
imol = new Molecule(sp.parseSmiles(smiles));
// Add hydrogens
if (addHydrogens) {
CDKHydrogenAdder adder = CDKHydrogenAdder.getInstance(imol.getBuilder());
try {
adder.addImplicitHydrogens(imol);
if (expliciteHydrogens)
AtomContainerManipulator.convertImplicitToExplicitHydrogens(imol);
} catch (CDKException e) {
e.printStackTrace();
}
} else {
for (IAtom a : imol.atoms()) a.setImplicitHydrogenCount(0);
if (!expliciteHydrogens)
imol = new Molecule(AtomContainerManipulator.removeHydrogens(imol));
}
if (calculateCoordinate) {
StructureDiagramGenerator sdg = new StructureDiagramGenerator(imol);
try {
sdg.generateCoordinates();
} catch (CDKException e) {
System.err.println(smiles);
e.printStackTrace();
}
imol = new Molecule(sdg.getMolecule());
}
} catch (InvalidSmilesException e) {
throw e;
}
return imol;
}
Aggregations