public String perceiveCDKAtomTypes(IMolecule mol) throws InvocationTargetException { ICDKMolecule cdkmol; try { cdkmol = cdk.asCDKMolecule(mol); } catch ( BioclipseException e ) { e.printStackTrace(); throw new InvocationTargetException( e, "Error while creating a ICDKMolecule" ); } IAtomContainer ac = cdkmol.getAtomContainer(); CDKAtomTypeMatcher cdkMatcher = CDKAtomTypeMatcher.getInstance(ac.getBuilder()); StringBuffer result = new StringBuffer(); int i = 1; for (IAtom atom : ac.atoms()) { IAtomType type = null; try { type = cdkMatcher.findMatchingAtomType(ac, atom); } catch ( CDKException e ) {} result.append(i).append(':').append( type != null ? type.getAtomTypeName() : "null" ).append('\n'); // FIXME: should use NEWLINE here i++; } return result.toString(); }
@Test public void testSybylAtomTypePerceptionFromSMILES() throws FileNotFoundException, IOException, BioclipseException, CoreException, InvocationTargetException { ICDKMolecule mol = cdk.fromSMILES("C1CCCCC1CCOC"); debug.perceiveSybylAtomTypes(mol); for (int i = 0; i < mol.getAtomContainer().getAtomCount(); i++) { IAtom a = mol.getAtomContainer().getAtom(i); System.out.println("Atom: " + a.getSymbol() + i + ", type=" + a.getAtomTypeName()); } }
public DBMolecule(String name, ICDKMolecule cdkMolecule) throws BioclipseException { super(); this.name = name; try { fingerPrint = cdkMolecule.getFingerprint( net.bioclipse.core.domain.IMolecule.Property.USE_CACHED_OR_CALCULATED); } catch (BioclipseException e) { logger.error("Could not create fingerprint for molecule", e); } persistedFingerPrint = makePersistedFingerPrint(fingerPrint); setAtomContainer(cdkMolecule.getAtomContainer()); smiles = ""; annotations = new ArrayList<Annotation>(); }
@Test public void testSybylAtomTypePerception() throws FileNotFoundException, IOException, BioclipseException, CoreException, InvocationTargetException { String path = getClass().getResource("/testFiles/atp.mol").getPath(); ICDKMolecule mol = cdk.loadMolecule(new MockIFile(path)); System.out.println("mol: " + mol.toString()); debug.perceiveSybylAtomTypes(mol); for (int i = 0; i < mol.getAtomContainer().getAtomCount(); i++) { IAtom a = mol.getAtomContainer().getAtom(i); System.out.println("Atom: " + a.getSymbol() + i + ", type=" + a.getAtomTypeName()); } }
@Test public void testSybylAtomTypePerceptionBenzene() throws CDKException, FileNotFoundException, IOException, BioclipseException, CoreException, InvocationTargetException { IAtomContainer ac = MoleculeFactory.makeBenzene(); ICDKMolecule mol = new CDKMolecule(ac); debug.perceiveSybylAtomTypes(mol); System.out.println("** BENZENE **"); System.out.println(AtomContainerDiff.diff(ac, mol.getAtomContainer())); for (int i = 0; i < mol.getAtomContainer().getAtomCount(); i++) { IAtom a = mol.getAtomContainer().getAtom(i); System.out.println("Atom: " + a.getSymbol() + i + ", type=" + a.getAtomTypeName()); } assertEquals("C.ar", mol.getAtomContainer().getAtom(0).getAtomTypeName()); assertEquals("C.ar", mol.getAtomContainer().getAtom(1).getAtomTypeName()); assertEquals("C.ar", mol.getAtomContainer().getAtom(2).getAtomTypeName()); assertEquals("C.ar", mol.getAtomContainer().getAtom(3).getAtomTypeName()); assertEquals("C.ar", mol.getAtomContainer().getAtom(4).getAtomTypeName()); assertEquals("C.ar", mol.getAtomContainer().getAtom(5).getAtomTypeName()); }
public void runTest( String testID, IMolecule mol, IReturner<List<? extends ITestResult>> returner, IProgressMonitor monitor) throws BioclipseException { ICDKManager cdk = net.bioclipse.cdk.business.Activator.getDefault().getJavaCDKManager(); IDSTest test = getTest(testID); List<? extends ITestResult> ret = null; try { // Preprocess the molecule ICDKMolecule cdkmol = cdk.asCDKMolecule(mol); // Clone the mol IAtomContainer clonedAC = null; try { clonedAC = (IAtomContainer) cdkmol.getAtomContainer().clone(); } catch (CloneNotSupportedException e) { logger.error("Could not clone mol: " + cdkmol); return; } ICDKMolecule clonedMol = new CDKMolecule(clonedAC); ret = test.runWarningTest(clonedMol, monitor); } catch (Exception e) { // in case of error... LogUtils.debugTrace(logger, e); ITestResult er = new SimpleResult("Error: " + e.getMessage(), ITestResult.ERROR); er.setDetailedMessage(e.getMessage()); List<ITestResult> trlist = new ArrayList<ITestResult>(); trlist.add(er); monitor.done(); returner.completeReturn(trlist); return; } monitor.done(); returner.completeReturn(ret); }
public String perceiveSybylAtomTypes(IMolecule mol) throws InvocationTargetException { ICDKMolecule cdkmol; try { cdkmol = cdk.asCDKMolecule(mol); } catch (BioclipseException e) { System.out.println("Error converting cdk10 to cdk"); e.printStackTrace(); throw new InvocationTargetException(e); } IAtomContainer ac = cdkmol.getAtomContainer(); CDKAtomTypeMatcher cdkMatcher = CDKAtomTypeMatcher.getInstance(ac.getBuilder()); AtomTypeMapper mapper = AtomTypeMapper.getInstance( "org/openscience/cdk/dict/data/cdk-sybyl-mappings.owl" ); IAtomType[] sybylTypes = new IAtomType[ac.getAtomCount()]; int atomCounter = 0; int a=0; for (IAtom atom : ac.atoms()) { IAtomType type; try { type = cdkMatcher.findMatchingAtomType(ac, atom); } catch (CDKException e) { type = null; } if (type==null) { // logger.debug("AT null for atom: " + atom); type = atom.getBuilder().newAtomType(atom.getSymbol()); type.setAtomTypeName("X"); } AtomTypeManipulator.configure(atom, type); a++; } try { CDKHueckelAromaticityDetector.detectAromaticity(ac); // System.out.println("Arom: " // + CDKHueckelAromaticityDetector.detectAromaticity(ac) ); } catch (CDKException e) { logger.debug("Failed to perceive aromaticity: " + e.getMessage()); } for (IAtom atom : ac.atoms()) { String mappedType = mapper.mapAtomType(atom.getAtomTypeName()); if ("C.2".equals(mappedType) && atom.getFlag(CDKConstants.ISAROMATIC)) { mappedType = "C.ar"; } else if ("N.pl3".equals(mappedType) && atom.getFlag(CDKConstants.ISAROMATIC)) { mappedType = "N.ar"; } try { sybylTypes[atomCounter] = factory.getAtomType(mappedType); } catch (NoSuchAtomTypeException e) { // yes, setting null's here is important sybylTypes[atomCounter] = null; } atomCounter++; } StringBuffer result = new StringBuffer(); // now that full perception is finished, we can set atom type names: for (int i = 0; i < sybylTypes.length; i++) { if (sybylTypes[i] != null) { ac.getAtom(i).setAtomTypeName(sybylTypes[i].getAtomTypeName()); } else { ac.getAtom(i).setAtomTypeName("X"); } result.append(i).append(':').append(ac.getAtom(i).getAtomTypeName()) /*.append("\n")*/; } return result.toString(); }
public String debug(ICDKMolecule mol) { return mol.getAtomContainer().toString(); }
public String diff(ICDKMolecule mol, ICDKMolecule mol2) { return AtomContainerDiff.diff( mol.getAtomContainer(), mol2.getAtomContainer() ); }