Search in sources :

Example 1 with IChemObject

use of org.openscience.cdk.interfaces.IChemObject in project ambit-mirror by ideaconsult.

the class MultiFingerprintsWriter method write.

@Override
public void write(IChemObject mol) throws CDKException {
    for (int k = 0; k < tags.length; k++) tags[k] = null;
    Iterator<Entry<Object, Object>> i = mol.getProperties().entrySet().iterator();
    while (i.hasNext()) {
        Entry<Object, Object> entry = i.next();
        String p = entry.getKey() instanceof Property ? ((Property) entry.getKey()).getName() : entry.getKey().toString();
        int index = Arrays.binarySearch(tags_to_keep, p);
        if (index >= 0)
            tags[index] = entry.getValue();
    }
    i = mol.getProperties().entrySet().iterator();
    while (i.hasNext()) {
        Entry<Object, Object> entry = i.next();
        try {
            Object[] record = mol2record(tags, entry.getKey().toString(), entry.getValue());
            if (record != null) {
                CSVPrinter writer = getWriter(entry.getKey().toString());
                if (writer != null)
                    writer.printRecord(record);
            }
        } catch (Exception x) {
            Logger.getGlobal().log(Level.WARNING, x.getMessage());
        }
    }
}
Also used : CSVPrinter(org.apache.commons.csv.CSVPrinter) Entry(java.util.Map.Entry) IChemObject(org.openscience.cdk.interfaces.IChemObject) Property(ambit2.base.data.Property) ICountFingerprint(org.openscience.cdk.fingerprint.ICountFingerprint) IBitFingerprint(org.openscience.cdk.fingerprint.IBitFingerprint) CDKException(org.openscience.cdk.exception.CDKException) IOException(java.io.IOException)

Example 2 with IChemObject

use of org.openscience.cdk.interfaces.IChemObject in project ambit-mirror by ideaconsult.

the class InteractiveIteratingMDLReader method next.

/* (non-Javadoc)
     * @see org.openscience.cdk.io.iterator.IteratingMDLReader#next()
     */
public IAtomContainer next() {
    Object o = super.next();
    if (o instanceof IChemObject) {
        Map properties = ((IChemObject) o).getProperties();
        if (properties.size() > 0) {
            fireIOSettingQuestion(new StringIOSetting("", Importance.MEDIUM, Property.IO_QUESTION.IO_START.toString(), ""));
            Iterator i = properties.keySet().iterator();
            while (i.hasNext()) {
                String name = i.next().toString();
                fireIOSettingQuestion(new StringIOSetting(name, Importance.MEDIUM, Property.IO_QUESTION.IO_TRANSLATE_NAME.toString(), name));
            }
            fireIOSettingQuestion(new StringIOSetting("", Importance.MEDIUM, Property.IO_QUESTION.IO_STOP.toString(), ""));
        }
        return (IAtomContainer) o;
    }
    return null;
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IChemObject(org.openscience.cdk.interfaces.IChemObject) Iterator(java.util.Iterator) IChemObject(org.openscience.cdk.interfaces.IChemObject) StringIOSetting(org.openscience.cdk.io.setting.StringIOSetting) Map(java.util.Map)

Example 3 with IChemObject

use of org.openscience.cdk.interfaces.IChemObject in project ambit-mirror by ideaconsult.

the class ArffWriter method write.

public void write(IChemObject mol) throws CDKException {
    try {
        for (int i = 0; i < getHeader().size(); i++) {
            Object o = getHeader().get(i);
            if (i > 0)
                writer.write(',');
            Object p = mol.getProperty(o);
            writer.write(p == null ? "?" : p.toString());
        }
        writer.write('\n');
    } catch (IOException x) {
        throw new CDKException(x.getMessage());
    }
}
Also used : CDKException(org.openscience.cdk.exception.CDKException) IChemObject(org.openscience.cdk.interfaces.IChemObject) IOException(java.io.IOException)

Example 4 with IChemObject

use of org.openscience.cdk.interfaces.IChemObject in project ambit-mirror by ideaconsult.

the class MDLV2000ReaderExtendedTest method testMixture.

@Test
public void testMixture() throws Exception {
    IChemObject mol = readSGroup("mixture_unordered.mol");
    Assert.assertNotNull(mol);
    Assert.assertTrue(mol instanceof SuppleAtomContainer);
    SuppleAtomContainer sca = (SuppleAtomContainer) mol;
    sca.setFiltered(false);
    Assert.assertEquals(11, sca.getBondCount());
    Assert.assertEquals(15 + 4, sca.getAtomCount());
    List<ISGroup> superatom = getGroup(sca);
    Assert.assertNotNull(superatom);
    Assert.assertEquals(4, superatom.size());
    for (int i = 0; i < superatom.size(); i++) {
        if (superatom.get(i) instanceof ComponentGroup) {
            Assert.assertNotNull(superatom.get(i));
            Assert.assertNull(((ComponentGroup) superatom.get(i)).getOrder());
        } else if (superatom.get(i) instanceof ContainerGroup) {
            Assert.assertEquals(3, ((ContainerGroup) superatom.get(i)).getComponents().size());
        }
    }
    sca.setFiltered(true);
    verify((IAtomContainer) mol, superatom, false, 15, 11, true);
    verify((IAtomContainer) mol, superatom, true, 15, 11, true);
}
Also used : ISGroup(ambit2.core.groups.ISGroup) ComponentGroup(ambit2.core.groups.ComponentGroup) IChemObject(org.openscience.cdk.interfaces.IChemObject) SuppleAtomContainer(ambit2.core.groups.SuppleAtomContainer) ContainerGroup(ambit2.core.groups.ContainerGroup) Test(org.junit.Test)

Example 5 with IChemObject

use of org.openscience.cdk.interfaces.IChemObject in project ambit-mirror by ideaconsult.

the class MDLV2000ReaderExtendedTest method testGeneric.

@Test
public void testGeneric() throws Exception {
    IChemObject mol = readSGroup("generic.mol");
    Assert.assertNotNull(mol);
    Assert.assertTrue(mol instanceof SuppleAtomContainer);
    SuppleAtomContainer sca = (SuppleAtomContainer) mol;
    sca.setFiltered(false);
    Assert.assertEquals(11, sca.getBondCount());
    Assert.assertEquals(19, sca.getAtomCount());
    List<ISGroup> superatom = getGroup(sca);
    Assert.assertNotNull(superatom);
    Assert.assertEquals(2, superatom.size());
    Assert.assertNotNull(superatom.get(0));
    Assert.assertNotNull(superatom.get(1));
    sca.setFiltered(true);
    verify((IAtomContainer) mol, superatom, false, 17, 11, false);
    verify((IAtomContainer) mol, superatom, true, 17, 11, false);
}
Also used : ISGroup(ambit2.core.groups.ISGroup) IChemObject(org.openscience.cdk.interfaces.IChemObject) SuppleAtomContainer(ambit2.core.groups.SuppleAtomContainer) Test(org.junit.Test)

Aggregations

IChemObject (org.openscience.cdk.interfaces.IChemObject)195 Test (org.junit.Test)139 IAtom (org.openscience.cdk.interfaces.IAtom)61 IBond (org.openscience.cdk.interfaces.IBond)51 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)32 HashMap (java.util.HashMap)21 SuppleAtomContainer (ambit2.core.groups.SuppleAtomContainer)16 AbstractBondTest (org.openscience.cdk.test.interfaces.AbstractBondTest)16 ArrayList (java.util.ArrayList)15 ISGroup (ambit2.core.groups.ISGroup)14 IStereoElement (org.openscience.cdk.interfaces.IStereoElement)12 InputStream (java.io.InputStream)11 Sgroup (org.openscience.cdk.sgroup.Sgroup)11 IAtomContainerSet (org.openscience.cdk.interfaces.IAtomContainerSet)9 ISingleElectron (org.openscience.cdk.interfaces.ISingleElectron)9 Map (java.util.Map)8 CDKException (org.openscience.cdk.exception.CDKException)8 ChemObject (org.openscience.cdk.ChemObject)7 IElement (org.openscience.cdk.interfaces.IElement)7 IOException (java.io.IOException)6