use of ambit2.core.smiles.OpenBabelShell in project ambit-mirror by ideaconsult.
the class SmilesParserWrapper method parseSmiles.
public IAtomContainer parseSmiles(String smiles, boolean addHydrogens) throws InvalidSmilesException {
switch(parser) {
case OPENBABEL:
{
try {
if (babel == null) {
babel = new OpenBabelShell();
babel.setHydrogens(addHydrogens);
}
return babel.runShell(smiles);
} catch (ShellException x) {
setParser(SMILES_PARSER.CDK);
if (cdkParser == null)
cdkParser = new SmilesParser(SilentChemObjectBuilder.getInstance());
IAtomContainer mol = cdkParser.parseSmiles(smiles);
/*
if (addHydrogens)
try {
//logger.debug("Adding explicit hydrogens");
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);
h.addImplicitHydrogens(mol);
MoleeculeTools.convertImplicitToExplicitHydrogens(mol);
//h.addExplicitHydrogensToSatisfyValency((IAtomContainer)mol);
} catch (InvalidSmilesException x ) {
return null;
} catch (CDKException x) {
return null;
}
*/
try {
Kekulization.kekulize(mol);
return mol;
} catch (CDKException xx) {
logger.log(Level.WARNING, smiles, xx);
return mol;
// throw new InvalidSmilesException(xx.getMessage());
}
} catch (Exception x) {
throw new InvalidSmilesException(x.getMessage());
}
}
default:
{
if (cdkParser == null)
cdkParser = new SmilesParser(SilentChemObjectBuilder.getInstance());
IAtomContainer mol = cdkParser.parseSmiles(smiles);
try {
Kekulization.kekulize(mol);
return mol;
// return mol;
} catch (Exception xx) {
logger.log(Level.WARNING, smiles, xx);
return mol;
// throw new InvalidSmilesException(xx.getMessage());
}
}
}
}
use of ambit2.core.smiles.OpenBabelShell in project ambit-mirror by ideaconsult.
the class CommandShellTest method testOpenBabel.
@Test
public void testOpenBabel() throws Exception {
String testfile = "babel_test.sdf";
OpenBabelShell babel = new OpenBabelShell();
babel.setOutputFile(testfile);
IAtomContainer newmol = babel.runShell("c1ccccc1");
IAtomContainer c = AtomContainerManipulator.removeHydrogensPreserveMultiplyBonded(newmol);
IAtomContainer mol = MoleculeFactory.makeBenzene();
UniversalIsomorphismTester uit = new UniversalIsomorphismTester();
Assert.assertTrue(uit.isIsomorph(mol, c));
new File(babel.getOutputFile()).delete();
}
use of ambit2.core.smiles.OpenBabelShell in project ambit-mirror by ideaconsult.
the class TestOpenBabelShell method test.
@Test
public void test() throws Exception {
String osName = System.getProperty("os.name");
if (CommandShell.os_WINDOWS.equals(osName) || CommandShell.os_WINDOWSVISTA.equals(osName) || CommandShell.os_WINDOWS7.equals(osName)) {
OpenBabelShell ob = new OpenBabelShell();
IAtomContainer mol = ob.process("c12-c3c(cccc3)Nc1nc(N)cc2");
Assert.assertTrue(mol.getAtomCount() > 0);
}
}
Aggregations