@Override public IChemObject newTestObject() { return new ChemModel(); } });
/** * Read the InChI=.. lines from a give text file containing InChI(s) * @param url * @return chemModel with molecule set with molecule(s) created using InChI * @throws org.openscience.cdk.exception.CDKException */ public static IChemModel readInChI(URL url) throws CDKException { IChemModel chemModel = new ChemModel(); try { IAtomContainerSet moleculeSet = new AtomContainerSet(); chemModel.setMoleculeSet(moleculeSet); StdInChIParser parser = new StdInChIParser(); BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); String line; while ((line = in.readLine()) != null) { if (line.toLowerCase().startsWith("inchi=")) { IAtomContainer atc = parser.parseInchi(line); moleculeSet.addAtomContainer(atc); } } in.close(); } catch (Exception e) { e.printStackTrace(); throw new CDKException(e.getMessage()); } return chemModel; }
@Override public void startDocument() { chemFile = new ChemFile(); chemSequence = new ChemSequence(); chemModel = new ChemModel(); setOfMolecules = new AtomContainerSet(); }
public void init() { boolean fitToScreen = false; String scrollbarParam = this.getParameter("scrollbars"); if (scrollbarParam != null && scrollbarParam.equals("false")) { fitToScreen = true; } JChemPaintViewerPanel p = new JChemPaintViewerPanel( new ChemModel(), getWidth(), getHeight(), fitToScreen, debug, this); setTheJcpp(p); this.add(p); super.init(); }
@BeforeClass public static void setUp() { setTestObjectBuilder(new ITestObjectBuilder() { @Override public IChemObject newTestObject() { return new ChemModel(); } }); }
@Test public void testGetAllAtomContainers_IChemModel_WithReactions() throws Exception { String filename = "data/mdl/0024.stg02.rxn"; logger.info("Testing: " + filename); InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLRXNV2000Reader reader = new MDLRXNV2000Reader(ins, Mode.STRICT); ChemModel chemFile = (ChemModel) reader.read((ChemObject) new ChemModel()); Assert.assertNotNull(chemFile); List<IAtomContainer> containersList = ChemModelManipulator.getAllAtomContainers(chemFile); Assert.assertEquals(2, containersList.size()); }
@Test public void testGetAllAtomContainers_IChemModel() throws Exception { String filename = "data/mdl/a-pinene.mol"; logger.info("Testing: " + filename); InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLV2000Reader reader = new MDLV2000Reader(ins); ChemModel chemFile = (ChemModel) reader.read((ChemObject) new ChemModel()); Assert.assertNotNull(chemFile); List<IAtomContainer> containersList = ChemModelManipulator.getAllAtomContainers(chemFile); Assert.assertEquals(1, containersList.size()); }
/** * * @param mol * @return */ public static IChemModel getChemModelWithMoleculeWithLayoutCheck(IAtomContainer mol) { IChemModel chemModel = new ChemModel(); chemModel.setMoleculeSet(partitionIntoMolecules(mol)); for (IAtomContainer molecule : getAllAtomContainers(chemModel.getMoleculeSet())) { if (has2DCoordinates(molecule)) { try { StructureDiagramGenerator sdg = new StructureDiagramGenerator(new AtomContainer(molecule)); sdg.generateCoordinates(); chemModel = (IChemModel) sdg.getMolecule(); } catch (Exception e) { e.printStackTrace(); } } } return chemModel; }
protected static IChemObject[] acceptableChemObjects() { return new IChemObject[]{new ChemFile(), new ChemModel(), new AtomContainer(), new Reaction(), new RGroupQuery(DefaultChemObjectBuilder.getInstance())}; }
protected static IChemObject[] acceptableChemObjects() { return new IChemObject[]{new ChemFile(), new ChemModel(), new AtomContainer(), new Reaction(), new RGroupQuery(DefaultChemObjectBuilder.getInstance())}; }
/** * Returns molecule with new layout * * @return cleaned model */ public IChemModel getChemModelWithMoleculeWithLayoutCheck() { IChemModel chemModel = new ChemModel(); chemModel.setMoleculeSet(partitionIntoMolecules(molecule)); for (IAtomContainer ac : getAllAtomContainers(chemModel.getMoleculeSet())) { if (!has2DCoordinates(ac)) { try { IAtomContainer mol = ac.getBuilder().newInstance(IAtomContainer.class, ac); percieveAtomTypesAndConfigureAtoms(mol); StructureDiagramGenerator sdg = new StructureDiagramGenerator(new AtomContainer(mol)); sdg.generateCoordinates(); ac = sdg.getMolecule(); } catch (IllegalArgumentException | CDKException e) { e.printStackTrace(); } } } return chemModel; } }
void expectReader(String filename, IResourceFormat expectedFormat, int expectedAtomCount, int expectedBondCount) throws Exception { InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); Assert.assertNotNull("Cannot find file: " + filename, ins); if (expectedFormat instanceof IChemFormatMatcher) { factory.registerFormat((IChemFormatMatcher) expectedFormat); } ISimpleChemObjectReader reader = factory.createReader(ins); Assert.assertNotNull(reader); Assert.assertEquals(((IChemFormat) expectedFormat).getReaderClassName(), reader.getClass().getName()); // now try reading something from it IChemObject[] objects = {new ChemFile(), new ChemModel(), new AtomContainer(), new Reaction()}; boolean read = false; for (int i = 0; (i < objects.length && !read); i++) { if (reader.accepts(objects[i].getClass())) { IChemObject chemObject = reader.read(objects[i]); Assert.assertNotNull("Reader accepted a " + objects[i].getClass().getName() + " but failed to read it", chemObject); assertAtomCount(expectedAtomCount, chemObject); assertBondCount(expectedBondCount, chemObject); read = true; } } if (read) { // ok, reseting worked } else { Assert.fail("Reading an IChemObject from the Reader did not work properly."); } }
@Test public void testCreateNewMolecule_IChemModel() { IChemModel model = new ChemModel(); IAtomContainer ac = ChemModelManipulator.createNewMolecule(model); Assert.assertEquals(1, model.getMoleculeSet().getAtomContainerCount()); Assert.assertEquals(ac, model.getMoleculeSet().getAtomContainer(0)); }
@Test public void testMoleculeSet() throws Exception { IAtomContainerSet list = new AtomContainerSet(); list.addAtomContainer(new AtomContainer()); list.addAtomContainer(new AtomContainer()); IChemModel model = new ChemModel(); model.setMoleculeSet(list); IChemModel roundTripped = CMLRoundTripTool.roundTripChemModel(convertor, model); IAtomContainerSet newList = roundTripped.getMoleculeSet(); Assert.assertNotNull(newList); Assert.assertEquals(2, newList.getAtomContainerCount()); Assert.assertNotNull(newList.getAtomContainer(0)); Assert.assertNotNull(newList.getAtomContainer(1)); }
@Test public void testExample() throws Exception { String testfile = "!Header mm1gp 100\n" + "!Info 1\n" + "!Atoms 6\n" + "0 6 \n" + "1 6 \n" + "2 1 \n" + "3 1 \n" + "4 1 \n" + "5 1 \n" + "!Bonds 5\n" + "1 0 D \n" + "2 0 S \n" + "3 0 S \n" + "4 1 S \n" + "5 1 S \n" + "!Coord\n" + "0 0.06677 -0.00197151 4.968e-07 \n" + "1 -0.0667699 0.00197154 -5.19252e-07 \n" + "2 0.118917 -0.097636 2.03406e-06 \n" + "3 0.124471 0.0904495 -4.84021e-07 \n" + "4 -0.118917 0.0976359 -2.04017e-06 \n" + "5 -0.124471 -0.0904493 5.12591e-07 \n" + "!Charges\n" + "0 -0.2\n" + "1 -0.2\n" + "2 0.1\n" + "3 0.1\n" + "4 0.1\n" + "5 0.1\n" + "!End"; StringReader stringReader = new StringReader(testfile); GhemicalMMReader reader = new GhemicalMMReader(stringReader); ChemModel model = (ChemModel) reader.read((ChemObject) new ChemModel()); reader.close(); Assert.assertNotNull(model); Assert.assertNotNull(model.getMoleculeSet()); IAtomContainerSet som = model.getMoleculeSet(); Assert.assertNotNull(som); Assert.assertEquals(1, som.getAtomContainerCount()); IAtomContainer m = som.getAtomContainer(0); Assert.assertNotNull(m); Assert.assertEquals(6, m.getAtomCount()); Assert.assertEquals(5, m.getBondCount()); // test reading of formal charges org.openscience.cdk.interfaces.IAtom a = m.getAtom(0); Assert.assertNotNull(a); Assert.assertEquals(6, a.getAtomicNumber().intValue()); Assert.assertEquals(-0.2, a.getCharge(), 0.01); Assert.assertEquals(0.06677, a.getPoint3d().x, 0.01); }
@Before public void setUp() { molecule1 = new AtomContainer(); atomInMol1 = new Atom("Cl"); molecule1.addAtom(atomInMol1); molecule1.addAtom(new Atom("Cl")); bondInMol1 = new Bond(atomInMol1, molecule1.getAtom(1)); molecule1.addBond(bondInMol1); molecule2 = new AtomContainer(); atomInMol2 = new Atom("O"); atomInMol2.setImplicitHydrogenCount(2); molecule2.addAtom(atomInMol2); moleculeSet = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainerSet.class); moleculeSet.addAtomContainer(molecule1); moleculeSet.addAtomContainer(molecule2); reaction = new Reaction(); reaction.addReactant(molecule1); reaction.addProduct(molecule2); reactionSet = new ReactionSet(); reactionSet.addReaction(reaction); chemModel1 = new ChemModel(); chemModel1.setMoleculeSet(moleculeSet); chemModel2 = new ChemModel(); chemModel2.setReactionSet(reactionSet); chemSequence = new ChemSequence(); chemSequence.addChemModel(chemModel1); chemSequence.addChemModel(chemModel2); }
/** * @cdk.bug 1455346 */ @Test public void testChemModel() throws Exception { ChemModel model = new ChemModel(); IAtomContainerSet moleculeSet = new AtomContainerSet(); IAtomContainer mol = new AtomContainer(); PseudoAtom atom = new PseudoAtom("N"); mol.addAtom(atom); moleculeSet.addAtomContainer(mol); model.setMoleculeSet(moleculeSet); IChemModel roundTrippedModel = CMLRoundTripTool.roundTripChemModel(convertor, model); IAtomContainerSet roundTrippedMolSet = roundTrippedModel.getMoleculeSet(); Assert.assertNotNull(roundTrippedMolSet); Assert.assertEquals(1, roundTrippedMolSet.getAtomContainerCount()); IAtomContainer roundTrippedMolecule = roundTrippedMolSet.getAtomContainer(0); Assert.assertNotNull(roundTrippedMolecule); Assert.assertEquals(1, roundTrippedMolecule.getAtomCount()); }
@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()); }
@Before public void setUp() { molecule1 = new AtomContainer(); atomInMol1 = new Atom("Cl"); atomInMol1.setCharge(-1.0); atomInMol1.setFormalCharge(-1); atomInMol1.setImplicitHydrogenCount(1); molecule1.addAtom(atomInMol1); molecule1.addAtom(new Atom("Cl")); bondInMol1 = new Bond(atomInMol1, molecule1.getAtom(1)); molecule1.addBond(bondInMol1); molecule2 = new AtomContainer(); atomInMol2 = new Atom("O"); atomInMol2.setImplicitHydrogenCount(2); molecule2.addAtom(atomInMol2); moleculeSet = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainerSet.class); moleculeSet.addAtomContainer(molecule1); moleculeSet.addAtomContainer(molecule2); reaction = new Reaction(); reaction.addReactant(molecule1); reaction.addProduct(molecule2); reactionSet = new ReactionSet(); reactionSet.addReaction(reaction); chemModel = new ChemModel(); chemModel.setMoleculeSet(moleculeSet); chemModel.setReactionSet(reactionSet); }
@Test public void testRemoveElectronContainer_IChemModel_IElectronContainer() { IAtomContainer mol1 = new AtomContainer(); mol1.addAtom(new Atom("Cl")); mol1.addAtom(new Atom("Cl")); IBond bond1 = new Bond(mol1.getAtom(0), mol1.getAtom(1)); mol1.addBond(bond1); IAtomContainer mol2 = new AtomContainer(); mol2.addAtom(new Atom("I")); mol2.addAtom(new Atom("I")); IBond bond2 = new Bond(mol2.getAtom(0), mol2.getAtom(1)); mol2.addBond(bond2); IAtomContainerSet molSet = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainerSet.class); molSet.addAtomContainer(mol1); IReaction r = new Reaction(); r.addProduct(mol2); IReactionSet rSet = new ReactionSet(); rSet.addReaction(r); IChemModel model = new ChemModel(); model.setMoleculeSet(molSet); model.setReactionSet(rSet); IBond otherBond = new Bond(); Assert.assertEquals(2, ChemModelManipulator.getBondCount(model)); ChemModelManipulator.removeElectronContainer(model, otherBond); Assert.assertEquals(2, ChemModelManipulator.getBondCount(model)); ChemModelManipulator.removeElectronContainer(model, bond1); Assert.assertEquals(1, ChemModelManipulator.getBondCount(model)); ChemModelManipulator.removeElectronContainer(model, bond2); Assert.assertEquals(0, ChemModelManipulator.getBondCount(model)); }