@Override public IChemObject newTestObject() { return new ChemFile(); } });
public void visualBugPMR() throws Exception { String filename = "data/cml/SL0016a.cml"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); CMLReader reader = new CMLReader(ins); ChemFile chemFile = (ChemFile) reader.read((ChemObject) new ChemFile()); IChemSequence seq = chemFile.getChemSequence(0); IChemModel model = seq.getChemModel(0); IAtomContainer mol = model.getMoleculeSet().getAtomContainer(0); //MoleculeViewer2D.display(mol, true, false, JFrame.DO_NOTHING_ON_CLOSE,""); }
/** {@inheritDoc} */ @Override public int getChemSequenceCount() { logger.debug("Getting chemSequence count: ", super.getChemSequenceCount()); return super.getChemSequenceCount(); }
@Test public void testSDFFile() throws Exception { String filename = "data/mdl/test.sdf"; // a multi molecule SDF file InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLV2000Reader reader = new MDLV2000Reader(ins); ChemFile fileContents = (ChemFile) reader.read(new ChemFile()); reader.close(); Assert.assertEquals(1, fileContents.getChemSequenceCount()); org.openscience.cdk.interfaces.IChemSequence sequence = fileContents.getChemSequence(0); Assert.assertNotNull(sequence); Assert.assertEquals(9, sequence.getChemModelCount()); for (int i = 0; i < sequence.getChemModelCount(); i++) { Assert.assertNotNull(sequence.getChemModel(i)); } }
@Test public void testPropagation() { ChemFile cf = new ChemFile(); ChemSequence cs = new ChemSequence(); ChemModel cm = new ChemModel(); IAtomContainerSet som = new AtomContainerSet(); IAtomContainer mol = new AtomContainer(); Atom a1 = new Atom("C"); Atom a2 = new Atom("C"); Bond b1 = new Bond(a1, a2); mol.addAtom(a1); mol.addAtom(a2); mol.addBond(b1); som.addAtomContainer(mol); cm.setMoleculeSet(som); cs.addChemModel(cm); cf.addChemSequence(cs); TestListener ts = new TestListener(); cf.addListener(ts); a2.setSymbol("N"); Assert.assertTrue(ts.changedObject instanceof Atom); Assert.assertEquals("N", ((Atom) ts.changedObject).getSymbol()); }
/** {@inheritDoc} */ @Override public IChemSequence getChemSequence(int number) { logger.debug("Getting chemSequence at: ", number); return super.getChemSequence(number); }
@Override public void endDocument() { chemFile.addChemSequence(chemSequence); }
@Test public void testSDFFile5() throws Exception { String filename = "data/mdl/test5.sdf"; // a multi molecule SDF file InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLV2000Reader reader = new MDLV2000Reader(ins); ChemFile fileContents = (ChemFile) reader.read(new ChemFile()); reader.close(); Assert.assertEquals(1, fileContents.getChemSequenceCount()); org.openscience.cdk.interfaces.IChemSequence sequence = fileContents.getChemSequence(0); Assert.assertNotNull(sequence); Assert.assertEquals(2, sequence.getChemModelCount()); for (int i = 0; i < sequence.getChemModelCount(); i++) { Assert.assertNotNull(sequence.getChemModel(i)); } }
/** {@inheritDoc} */ @Override public void addChemSequence(IChemSequence chemSequence) { logger.debug("Adding sequence: ", chemSequence); super.addChemSequence(chemSequence); }
@Override public void startDocument() { chemFile = new ChemFile(); chemSequence = new ChemSequence(); chemModel = new ChemModel(); setOfMolecules = new AtomContainerSet(); }
@Test public void testSDFFile3() throws Exception { String filename = "data/mdl/test3.sdf"; // a multi molecule SDF file InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLV2000Reader reader = new MDLV2000Reader(ins); ChemFile fileContents = (ChemFile) reader.read(new ChemFile()); reader.close(); Assert.assertEquals(1, fileContents.getChemSequenceCount()); org.openscience.cdk.interfaces.IChemSequence sequence = fileContents.getChemSequence(0); Assert.assertNotNull(sequence); Assert.assertEquals(2, sequence.getChemModelCount()); for (int i = 0; i < sequence.getChemModelCount(); i++) { Assert.assertNotNull(sequence.getChemModel(i)); } }
public static IAtomContainer loadMolecule(String inFile) { MDLReader mr = null; ChemFile chemFile = null; IChemSequence chemSequence = null; IChemModel chemModel = null; IAtomContainerSet setOfMolecules = null; IAtomContainer molecule = null; try { FileInputStream fis = new FileInputStream(inFile); 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; }
/** * Allows for getting an clone of this object. * *@return a clone of this object */ @Override public Object clone() throws CloneNotSupportedException { ChemFile clone = (ChemFile) super.clone(); // clone the chemModels clone.chemSequenceCount = getChemSequenceCount(); clone.chemSequences = new ChemSequence[clone.chemSequenceCount]; for (int f = 0; f < clone.chemSequenceCount; f++) { clone.chemSequences[f] = (ChemSequence) ((ChemSequence) chemSequences[f]).clone(); } return clone; }
private IChemFile parseCMLString(String cmlString) throws Exception { IChemFile chemFile = null; CMLReader reader = new CMLReader(new ByteArrayInputStream(cmlString.getBytes())); chemFile = (IChemFile) reader.read(new org.openscience.cdk.ChemFile()); return chemFile; }
@Test public void testSDFFile4() throws Exception { String filename = "data/mdl/test4.sdf"; // a multi molecule SDF file InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLV2000Reader reader = new MDLV2000Reader(ins); ChemFile fileContents = (ChemFile) reader.read(new ChemFile()); reader.close(); Assert.assertEquals(1, fileContents.getChemSequenceCount()); org.openscience.cdk.interfaces.IChemSequence sequence = fileContents.getChemSequence(0); Assert.assertNotNull(sequence); Assert.assertEquals(2, sequence.getChemModelCount()); for (int i = 0; i < sequence.getChemModelCount(); i++) { Assert.assertNotNull(sequence.getChemModel(i)); } }
/** * @cdk.bug 2831420 */ @Test public void testBug2831420() throws Exception { String filename = "data/mdl/bug2831420.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLV2000Reader reader = new MDLV2000Reader(ins); ChemFile chemFile = (ChemFile) reader.read((ChemObject) new ChemFile()); IAtomContainer mol = chemFile.getChemSequence(0).getChemModel(0).getMoleculeSet().getAtomContainer(0); Assert.assertTrue(BondTools.isStereo(mol, mol.getAtom(5))); } }
/** * Allows for getting an clone of this object. * *@return a clone of this object */ @Override public Object clone() throws CloneNotSupportedException { ChemFile clone = (ChemFile) super.clone(); // clone the chemModels clone.chemSequenceCount = getChemSequenceCount(); clone.chemSequences = new ChemSequence[clone.chemSequenceCount]; for (int f = 0; f < clone.chemSequenceCount; f++) { clone.chemSequences[f] = (ChemSequence) ((ChemSequence) chemSequences[f]).clone(); } return clone; }
private IChemFile parseCMLString(String cmlString) throws Exception { IChemFile chemFile = null; CMLReader reader = new CMLReader(new ByteArrayInputStream(cmlString.getBytes())); chemFile = (IChemFile) reader.read(new org.openscience.cdk.ChemFile()); reader.close(); return chemFile; }
@Test public void testMultiple() throws Exception { String filename = "data/hin/multiple.hin"; logger.info("Testing: " + filename); InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); HINReader reader = new HINReader(ins); ChemFile chemFile = (ChemFile) reader.read((ChemObject) new ChemFile()); reader.close(); Assert.assertNotNull(chemFile); Assert.assertEquals(1, chemFile.getChemSequenceCount()); org.openscience.cdk.interfaces.IChemSequence seq = chemFile.getChemSequence(0); Assert.assertNotNull(seq); Assert.assertEquals(1, seq.getChemModelCount()); org.openscience.cdk.interfaces.IChemModel model = seq.getChemModel(0); Assert.assertNotNull(model); IAtomContainerSet som = model.getMoleculeSet(); Assert.assertNotNull(som); Assert.assertEquals(3, som.getAtomContainerCount()); }
@Test public void testMakeUpDownBonds_IAtomContainer() throws Exception { String filename = "data/mdl/tetrahedral_2_lazy.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLV2000Reader reader = new MDLV2000Reader(ins); ChemFile chemFile = (ChemFile) reader.read((ChemObject) new ChemFile()); IAtomContainer mol = chemFile.getChemSequence(0).getChemModel(0).getMoleculeSet().getAtomContainer(0); BondTools.makeUpDownBonds(mol); Assert.assertEquals(IBond.Stereo.DOWN, mol.getBond(3).getStereo()); }