Search in sources :

Example 1 with OpenBabelShell

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());
                }
            }
    }
}
Also used : SmilesParser(org.openscience.cdk.smiles.SmilesParser) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) CDKException(org.openscience.cdk.exception.CDKException) InvalidSmilesException(org.openscience.cdk.exception.InvalidSmilesException) ShellException(ambit2.base.external.ShellException) InvalidSmilesException(org.openscience.cdk.exception.InvalidSmilesException) ShellException(ambit2.base.external.ShellException) CDKException(org.openscience.cdk.exception.CDKException)

Example 2 with OpenBabelShell

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();
}
Also used : OpenBabelShell(ambit2.core.smiles.OpenBabelShell) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) UniversalIsomorphismTester(org.openscience.cdk.isomorphism.UniversalIsomorphismTester) File(java.io.File) Test(org.junit.Test)

Example 3 with OpenBabelShell

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);
    }
}
Also used : OpenBabelShell(ambit2.core.smiles.OpenBabelShell) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) Test(org.junit.Test)

Aggregations

IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)3 OpenBabelShell (ambit2.core.smiles.OpenBabelShell)2 Test (org.junit.Test)2 ShellException (ambit2.base.external.ShellException)1 File (java.io.File)1 CDKException (org.openscience.cdk.exception.CDKException)1 InvalidSmilesException (org.openscience.cdk.exception.InvalidSmilesException)1 UniversalIsomorphismTester (org.openscience.cdk.isomorphism.UniversalIsomorphismTester)1 SmilesParser (org.openscience.cdk.smiles.SmilesParser)1