/** * Get the total number of bonds inside an IChemFile. * * @param file The IChemFile object. * @return The number of Bond object inside. */ public static int getBondCount(IChemFile file) { int count = 0; for (int i = 0; i < file.getChemSequenceCount(); i++) { count += ChemSequenceManipulator.getBondCount(file.getChemSequence(i)); } return count; }
/** * @cdk.bug 2697568 */ @Test public void testReadReactionWithPointersToMoleculeSet() throws Exception { String filename = "data/cml/AlanineTree.cml"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); CMLReader reader = new CMLReader(ins); IChemFile chemFile = new ChemFile(); chemFile = (IChemFile) reader.read(chemFile); reader.close(); Assert.assertSame(chemFile.getChemSequence(0).getChemModel(0).getMoleculeSet().getAtomContainer(0), chemFile .getChemSequence(0).getChemModel(0).getReactionSet().getReaction(0).getReactants().getAtomContainer(0)); }
/** * Get the total number of atoms inside an IChemFile. * * @param file The IChemFile object. * @return The number of Atom object inside. */ public static int getAtomCount(IChemFile file) { int count = 0; for (int i = 0; i < file.getChemSequenceCount(); i++) { count += ChemSequenceManipulator.getAtomCount(file.getChemSequence(i)); } return count; }
/** * @cdk.bug 2697568 */ @Test public void testBug2697568() throws Exception { String filename = "data/cml/AlanineTreeReverse.cml"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); CMLReader reader = new CMLReader(ins); IChemFile chemFile = new ChemFile(); chemFile = (IChemFile) reader.read(chemFile); reader.close(); Assert.assertSame(chemFile.getChemSequence(0).getChemModel(0).getMoleculeSet().getAtomContainer(0), chemFile .getChemSequence(0).getChemModel(0).getReactionSet().getReaction(0).getReactants().getAtomContainer(0)); }
/** * Returns a List of all IChemObject inside a ChemFile. * * @return A list of all ChemObjects */ public static List<IChemObject> getAllChemObjects(IChemFile file) { List<IChemObject> list = new ArrayList<IChemObject>(); //list.add(file); // should not add the original file for (int i = 0; i < file.getChemSequenceCount(); i++) { list.add(file.getChemSequence(i)); list.addAll(ChemSequenceManipulator.getAllChemObjects(file.getChemSequence(i))); } return list; }
@Test public void cod1100784AtomCount() throws IOException, CDKException { InputStream in = getClass().getResourceAsStream("1100784.cif"); CIFReader cifReader = new CIFReader(in); IChemFile chemFile = cifReader.read(new ChemFile()); ICrystal crystal = chemFile.getChemSequence(0).getChemModel(0).getCrystal(); Assert.assertEquals(72, crystal.getAtomCount()); cifReader.close(); }
/** * Get a list of all ChemModels inside an IChemFile. * * @param file The IChemFile object. * @return The List of IChemModel objects inside. */ public static List<IChemModel> getAllChemModels(IChemFile file) { List<IChemModel> modelsList = new ArrayList<IChemModel>(); for (int f = 0; f < file.getChemSequenceCount(); f++) { for (IChemModel model : file.getChemSequence(f).chemModels()) { modelsList.add(model); } } return modelsList; }
@Test public void testReadingCharges() throws Exception { String filename = "data/mdl/withcharges.mol"; logger.info("Testing: " + filename); InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLV2000Reader reader = new MDLV2000Reader(ins); IChemFile chemFile = reader.read(new ChemFile()); reader.close(); IAtomContainer container = chemFile.getChemSequence(0).getChemModel(0).getMoleculeSet().getAtomContainer(0); Assert.assertEquals(1, container.getAtom(6).getFormalCharge().intValue()); Assert.assertEquals(-1, container.getAtom(8).getFormalCharge().intValue()); }
public static List<String> getAllIDs(IChemFile file) { List<String> list = new ArrayList<String>(); if (file.getID() != null) list.add(file.getID()); for (int i = 0; i < file.getChemSequenceCount(); i++) { list.addAll(ChemSequenceManipulator.getAllIDs(file.getChemSequence(i))); } return list; }
/** */ @Test public void testReactionProperties() throws Exception { String filename = "data/cml/reaction.2.cml"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); CMLReader reader = new CMLReader(ins); IChemFile chemFile = new ChemFile(); chemFile = (IChemFile) reader.read(chemFile); reader.close(); IReaction reaction = chemFile.getChemSequence(0).getChemModel(0).getReactionSet().getReaction(0); Assert.assertEquals("3", (String) reaction.getProperty("Ka")); } }
private ValidationReport validateChemFileNulls(IChemFile chemFile) { ValidationReport report = new ValidationReport(); ValidationTest hasNulls = new ValidationTest(chemFile, "ChemFile contains a null ChemSequence."); for (int i = 0; i < chemFile.getChemSequenceCount(); i++) { // DIRTY !!!! FIXME !!!!! // but it does not seem to work on 1.4.2 otherwise.... if (chemFile.getChemSequence(i) == null) { report.addError(hasNulls); } else { report.addOK(hasNulls); } } return report; }
@Test() public void cod1100784CellLengths() throws IOException, CDKException { InputStream in = getClass().getResourceAsStream("1100784.cif"); CIFReader cifReader = new CIFReader(in); IChemFile chemFile = cifReader.read(new ChemFile()); ICrystal crystal = chemFile.getChemSequence(0).getChemModel(0).getCrystal(); Assert.assertTrue( java.lang.Math.abs(crystal.getA().length() - 10.9754) < 1E-5 ); Assert.assertTrue( java.lang.Math.abs(crystal.getB().length() - 11.4045) < 1E-5 ); Assert.assertTrue( java.lang.Math.abs(crystal.getC().length() - 12.9314) < 1E-5 ); cifReader.close(); }
private void checkMol(StringBuilder buf) throws Exception { StringReader sr = new StringReader(buf.toString()); Mol2Reader reader = new Mol2Reader(sr); IChemFile mol = (IChemFile) reader.read(SilentChemObjectBuilder.getInstance().newInstance(IChemFile.class)); reader.close(); Assert.assertTrue(mol.getChemSequenceCount() > 0); Assert.assertTrue(mol.getChemSequence(0).getChemModelCount() > 0); Assert.assertTrue(mol.getChemSequence(0).getChemModel(0).getMoleculeSet().getAtomContainerCount() > 0); Assert.assertTrue(mol.getChemSequence(0).getChemModel(0).getMoleculeSet().getAtomContainer(0).getAtomCount() > 0); }
@Test public void testCholoylCoA() throws Exception { IRingSet ringSet = null; AllRingsFinder arf = new AllRingsFinder(); String filename = "data/mdl/choloylcoa.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLV2000Reader reader = new MDLV2000Reader(ins); IChemFile chemFile = (IChemFile) reader.read(new org.openscience.cdk.ChemFile()); IChemSequence seq = chemFile.getChemSequence(0); IChemModel model = seq.getChemModel(0); IAtomContainer molecule = model.getMoleculeSet().getAtomContainer(0); ringSet = arf.findAllRings(molecule); Assert.assertEquals(14, ringSet.getAtomContainerCount()); }
public IAtomContainer getFirstAtomContainer(IChemFile chemFile, int chemSequenceCount, int chemModelCount, int moleculeCount) { Assert.assertNotNull(chemFile); Assert.assertEquals(chemSequenceCount, chemFile.getChemSequenceCount()); org.openscience.cdk.interfaces.IChemSequence seq = chemFile.getChemSequence(0); Assert.assertNotNull(seq); Assert.assertEquals(chemModelCount, seq.getChemModelCount()); IChemModel model = seq.getChemModel(0); Assert.assertNotNull(model); Assert.assertEquals(moleculeCount, model.getMoleculeSet().getAtomContainerCount()); return model.getMoleculeSet().getAtomContainer(0); }
@Test public void testAzulene() throws Exception { IRingSet ringSet = null; AllRingsFinder arf = new AllRingsFinder(); String filename = "data/mdl/azulene.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLV2000Reader reader = new MDLV2000Reader(ins); IChemFile chemFile = (IChemFile) reader.read(new org.openscience.cdk.ChemFile()); IChemSequence seq = chemFile.getChemSequence(0); IChemModel model = seq.getChemModel(0); IAtomContainer molecule = model.getMoleculeSet().getAtomContainer(0); ringSet = arf.findAllRings(molecule); Assert.assertEquals(3, ringSet.getAtomContainerCount()); }
@Test public void testPorphyrine() throws Exception { IRingSet ringSet = null; AllRingsFinder arf = new AllRingsFinder(); String filename = "data/mdl/porphyrin.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLV2000Reader reader = new MDLV2000Reader(ins); IChemFile chemFile = (IChemFile) reader.read(new org.openscience.cdk.ChemFile()); IChemSequence seq = chemFile.getChemSequence(0); IChemModel model = seq.getChemModel(0); IAtomContainer molecule = model.getMoleculeSet().getAtomContainer(0); ringSet = arf.findAllRings(molecule); Assert.assertEquals(20, ringSet.getAtomContainerCount()); }
@Test public void testBigRingSystem_MaxRingSize6_03419() throws Exception { IRingSet ringSet = null; AllRingsFinder arf = new AllRingsFinder(); String filename = "data/mdl/ring_03419.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLV2000Reader reader = new MDLV2000Reader(ins); IChemFile chemFile = (IChemFile) reader.read(new ChemFile()); IChemSequence seq = chemFile.getChemSequence(0); IChemModel model = seq.getChemModel(0); IAtomContainer molecule = model.getMoleculeSet().getAtomContainer(0); ringSet = arf.findAllRings(molecule, 6); Assert.assertEquals(12, ringSet.getAtomContainerCount()); }
@Test public void testBigRingSystem_MaxRingSize4_fourRing5x10() throws Exception { IRingSet ringSet = null; AllRingsFinder arf = new AllRingsFinder(); String filename = "data/mdl/four-ring-5x10.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLV2000Reader reader = new MDLV2000Reader(ins); IChemFile chemFile = (IChemFile) reader.read(new ChemFile()); IChemSequence seq = chemFile.getChemSequence(0); IChemModel model = seq.getChemModel(0); IAtomContainer molecule = model.getMoleculeSet().getAtomContainer(0); // there are 5x10 squares (four-rings) in the 5x10 molecule ringSet = arf.findAllRings(molecule, 4); Assert.assertEquals(50, ringSet.getAtomContainerCount()); }
@Test public void testGetChemSequence_int() { IChemFile cs = (IChemFile) newChemObject(); cs.addChemSequence(cs.getBuilder().newInstance(IChemSequence.class)); IChemSequence second = cs.getBuilder().newInstance(IChemSequence.class); cs.addChemSequence(second); cs.addChemSequence(cs.getBuilder().newInstance(IChemSequence.class)); Assert.assertEquals(second, cs.getChemSequence(1)); }