use of org.openscience.cdk.ChemFile in project cdk by cdk.
the class MoleculeFactory method loadMolecule.
public static IAtomContainer loadMolecule(String inFile) {
ChemFile chemFile;
IChemSequence chemSequence;
IChemModel chemModel;
IAtomContainerSet setOfMolecules;
IAtomContainer molecule = null;
try (FileInputStream fis = new FileInputStream(inFile);
MDLReader mr = new MDLReader(fis)) {
chemFile = (ChemFile) mr.read((ChemObject) new ChemFile());
mr.close();
chemSequence = chemFile.getChemSequence(0);
chemModel = chemSequence.getChemModel(0);
setOfMolecules = chemModel.getMoleculeSet();
molecule = setOfMolecules.getAtomContainer(0);
for (int i = 0; i < molecule.getAtomCount(); i++) {
molecule.getAtom(i).setPoint2d(null);
}
} catch (CDKException | IOException exc) {
// we just return null if something went wrong
logger.error("An exception occurred while loading a molecule: " + inFile);
logger.debug(exc);
}
return molecule;
}
use of org.openscience.cdk.ChemFile in project cdk by cdk.
the class Mol2ReaderTest method testMultiMol.
@Test
public void testMultiMol() throws Exception {
Assume.assumeTrue(runSlowTests());
String filename = "actives.mol2";
logger.info("Testing: ", filename);
InputStream ins = this.getClass().getResourceAsStream(filename);
Mol2Reader reader = new Mol2Reader(ins);
IChemFile chemFile = reader.read(new ChemFile());
reader.close();
List<IAtomContainer> mols = ChemFileManipulator.getAllAtomContainers(chemFile);
Assert.assertEquals(30, mols.size());
Assert.assertEquals(25, mols.get(0).getAtomCount());
Assert.assertEquals(24, mols.get(29).getAtomCount());
}
use of org.openscience.cdk.ChemFile in project cdk by cdk.
the class PCCompoundASNReaderTest method testReading.
@Test
public void testReading() throws Exception {
String filename = "cid1.asn";
logger.info("Testing: " + filename);
InputStream ins = this.getClass().getResourceAsStream(filename);
PCCompoundASNReader reader = new PCCompoundASNReader(ins);
IChemFile cFile = reader.read(new ChemFile());
reader.close();
List<IAtomContainer> containers = ChemFileManipulator.getAllAtomContainers(cFile);
Assert.assertEquals(1, containers.size());
Assert.assertTrue(containers.get(0) instanceof IAtomContainer);
IAtomContainer molecule = containers.get(0);
Assert.assertNotNull(molecule);
// check atom stuff
Assert.assertEquals(31, molecule.getAtomCount());
Assert.assertNotNull(molecule.getAtom(3));
Assert.assertEquals("O", molecule.getAtom(3).getSymbol());
Assert.assertNotNull(molecule.getAtom(4));
Assert.assertEquals("N", molecule.getAtom(4).getSymbol());
// check bond stuff
Assert.assertEquals(30, molecule.getBondCount());
Assert.assertNotNull(molecule.getBond(3));
Assert.assertEquals(molecule.getAtom(2), molecule.getBond(3).getBegin());
Assert.assertEquals(molecule.getAtom(11), molecule.getBond(3).getEnd());
// some extracted props
Assert.assertEquals("InChI=1/C9H17NO4/c1-7(11)14-8(5-9(12)13)6-10(2,3)4/h8H,5-6H2,1-4H3", molecule.getProperty(CDKConstants.INCHI));
Assert.assertEquals("CC(=O)OC(CC(=O)[O-])C[N+](C)(C)C", molecule.getProperty(CDKConstants.SMILES));
}
use of org.openscience.cdk.ChemFile in project cdk by cdk.
the class PMPReaderTest method testTwoAceticAcid.
@Test
public void testTwoAceticAcid() throws Exception {
String filename = "two_aceticacid.pmp";
InputStream ins = this.getClass().getResourceAsStream(filename);
PMPReader reader = new PMPReader(ins);
ChemFile chemFile = (ChemFile) reader.read((ChemObject) new ChemFile());
reader.close();
Assert.assertNotNull(chemFile);
Assert.assertEquals(1, chemFile.getChemSequenceCount());
IChemSequence seq = chemFile.getChemSequence(0);
Assert.assertNotNull(seq);
Assert.assertEquals(2, seq.getChemModelCount());
IChemModel model = seq.getChemModel(0);
Assert.assertNotNull(model);
ICrystal crystal = model.getCrystal();
Assert.assertNotNull(crystal);
Assert.assertEquals(32, crystal.getAtomCount());
Assert.assertEquals(28, crystal.getBondCount());
model = seq.getChemModel(1);
Assert.assertNotNull(model);
crystal = model.getCrystal();
Assert.assertNotNull(crystal);
Assert.assertEquals(32, crystal.getAtomCount());
Assert.assertEquals(28, crystal.getBondCount());
}
use of org.openscience.cdk.ChemFile in project cdk by cdk.
the class ReaderFactoryTest method testReadGzWithGzipDetection.
@Test
public void testReadGzWithGzipDetection() throws Exception {
String filename = "org/openscience/cdk/io/bf3.xyz.gz";
InputStream input = this.getClass().getClassLoader().getResourceAsStream(filename);
// ok, if format ok, try instantiating a reader
ISimpleChemObjectReader reader = factory.createReader(input);
Assert.assertNotNull(reader);
Assert.assertEquals(((IChemFormat) XYZFormat.getInstance()).getReaderClassName(), reader.getClass().getName());
// now try reading something from it
IChemFile chemFile = reader.read(new ChemFile());
IAtomContainer molecule = new AtomContainer();
for (IAtomContainer container : ChemFileManipulator.getAllAtomContainers(chemFile)) {
molecule.add(container);
}
Assert.assertNotNull(molecule);
Assert.assertEquals(4, molecule.getAtomCount());
}
Aggregations