use of org.openscience.cdk.ChemFile in project MetFragRelaunched by ipb-halle.
the class OnlineChemSpiderDatabase method getAtomContainerFromString.
/**
* @param sdfString
* @return
* @throws CDKException
*/
protected ArrayList<IAtomContainer> getAtomContainerFromString(String sdfString) {
MDLV2000Reader reader = new MDLV2000Reader(new StringReader(sdfString));
java.util.List<IAtomContainer> containersList;
java.util.ArrayList<IAtomContainer> ret = new ArrayList<IAtomContainer>();
ChemFile chemFile = null;
try {
chemFile = (ChemFile) reader.read((ChemObject) new ChemFile());
} catch (CDKException e) {
try {
reader.close();
} catch (IOException e1) {
}
this.logger.error("Error: Could not perform database query. This could be caused by a temporal database timeout. Try again later.");
return new ArrayList<IAtomContainer>();
}
containersList = ChemFileManipulator.getAllAtomContainers(chemFile);
for (IAtomContainer container : containersList) {
ret.add(container);
}
try {
reader.close();
} catch (IOException e) {
this.logger.error("Error: Could not perform database query. This could be caused by a temporal database timeout. Try again later.");
return new ArrayList<IAtomContainer>();
}
return ret;
}
use of org.openscience.cdk.ChemFile in project cdk by cdk.
the class ConjugatedPiSystemsDetectorTest method testPiSystemWithCumulativeDB.
/**
* A unit test for JUnit
*
*@return Description of the Return Value
*/
@Test
public void testPiSystemWithCumulativeDB() throws Exception {
logger.info("Entering testPiSystemWithCumulativeDB.");
IAtomContainer mol;
String filename = "piSystemCumulative.mol";
InputStream ins = this.getClass().getResourceAsStream(filename);
MDLReader reader = new MDLReader(ins);
IChemFile chemFile = (IChemFile) reader.read((ChemObject) new ChemFile());
mol = chemFile.getChemSequence(0).getChemModel(0).getMoleculeSet().getAtomContainer(0);
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);
Aromaticity.cdkLegacy().apply(mol);
IAtomContainerSet acSet = ConjugatedPiSystemsDetector.detect(mol);
Assert.assertEquals(2, acSet.getAtomContainerCount());
IAtomContainer ac1 = acSet.getAtomContainer(0);
Assert.assertEquals(4, ac1.getAtomCount());
Assert.assertEquals(3, ac1.getBondCount());
for (int i = 0; i < ac1.getAtomCount(); i++) {
Assert.assertTrue(mol.contains(ac1.getAtom(i)));
}
for (int i = 0; i < ac1.getBondCount(); i++) {
Assert.assertTrue(mol.contains(ac1.getBond(i)));
}
IAtomContainer ac2 = acSet.getAtomContainer(0);
Assert.assertEquals(4, ac2.getAtomCount());
Assert.assertEquals(3, ac2.getBondCount());
for (int i = 0; i < ac2.getAtomCount(); i++) {
Assert.assertTrue(mol.contains(ac1.getAtom(i)));
}
for (int i = 0; i < ac2.getBondCount(); i++) {
Assert.assertTrue(mol.contains(ac1.getBond(i)));
}
}
use of org.openscience.cdk.ChemFile in project cdk by cdk.
the class ConjugatedPiSystemsDetectorTest method readCMLMolecule.
/**
* A unit test for JUnit
*
* @cdk.inchi
*
*@return Description of the Return Value
*/
private IAtomContainer readCMLMolecule(String filename) throws Exception {
IAtomContainer mol;
logger.debug("Filename: " + filename);
InputStream ins = this.getClass().getResourceAsStream(filename);
CMLReader reader = new CMLReader(ins);
IChemFile file = reader.read(new ChemFile());
Assert.assertNotNull(file);
Assert.assertEquals(1, file.getChemSequenceCount());
IChemSequence sequence = file.getChemSequence(0);
Assert.assertNotNull(sequence);
Assert.assertEquals(1, sequence.getChemModelCount());
IChemModel chemModel = sequence.getChemModel(0);
Assert.assertNotNull(chemModel);
IAtomContainerSet moleculeSet = chemModel.getMoleculeSet();
Assert.assertNotNull(moleculeSet);
Assert.assertEquals(1, moleculeSet.getAtomContainerCount());
mol = moleculeSet.getAtomContainer(0);
Assert.assertNotNull(mol);
return mol;
}
use of org.openscience.cdk.ChemFile in project cdk by cdk.
the class ChemFileManipulatorTest method testGetAllAtomContainers_IChemFile.
@Test
public void testGetAllAtomContainers_IChemFile() throws Exception {
String filename = "prev2000.sd";
logger.info("Testing: " + filename);
InputStream ins = this.getClass().getResourceAsStream(filename);
MDLReader reader = new MDLReader(ins, Mode.STRICT);
ChemFile chemFile = (ChemFile) reader.read((ChemObject) new ChemFile());
Assert.assertNotNull(chemFile);
List<IAtomContainer> containersList = ChemFileManipulator.getAllAtomContainers(chemFile);
Assert.assertEquals(2, containersList.size());
}
use of org.openscience.cdk.ChemFile in project cdk by cdk.
the class FingerprinterTest method testbug2917084.
@Test(expected = CDKException.class)
@Category(SlowTest.class)
public void testbug2917084() throws Exception {
String filename1 = "boronBuckyBall.mol";
logger.info("Testing: " + filename1);
InputStream ins1 = this.getClass().getResourceAsStream(filename1);
MDLV2000Reader reader = new MDLV2000Reader(ins1, Mode.STRICT);
IChemFile chemFile = reader.read(new ChemFile());
Assert.assertNotNull(chemFile);
IAtomContainer mol = ChemFileManipulator.getAllAtomContainers(chemFile).get(0);
Fingerprinter fingerprinter = new Fingerprinter(1024, 8);
Assert.assertNotNull(fingerprinter.getBitFingerprint(mol));
}
Aggregations