@Override public IChemObject newTestObject() { return new ChemModel(); } });
/** {@inheritDoc} */ @Override public void setMoleculeSet(IAtomContainerSet setOfMolecules) { logger.debug("Setting setOfMolecules: ", setOfMolecules); super.setMoleculeSet(setOfMolecules); }
/** * Returns a String representation of the contents of this * IChemObject. * * @return String representation of content */ @Override public String toString() { StringBuffer buffer = new StringBuffer(64); buffer.append("ChemModel("); buffer.append(hashCode()); if (getMoleculeSet() != null) { buffer.append(", "); buffer.append(getMoleculeSet().toString()); } if (getCrystal() != null) { buffer.append(", "); buffer.append(getCrystal().toString()); } if (getReactionSet() != null) { buffer.append(", "); buffer.append(getReactionSet().toString()); } buffer.append(')'); return buffer.toString(); }
chemModel = (ChemModel) cor.read((IChemObject) new ChemModel()); if (chemModel == null) { error = "The object chemModel was empty unexpectedly!"; chemModel = new ChemModel(); chemModel.setMoleculeSet(som); } catch (Exception exception) { error = "Error while reading file: " + exception.getMessage(); IAtomContainerSet newSet = new AtomContainerSet(); newSet.addAtomContainer(mol); chemModel = new ChemModel(); chemModel.setMoleculeSet(newSet); } catch (Exception exception) { error = "Error while reading file: " + exception.getMessage(); if(rgroupQuery!=null ) try{ chemModel = new ChemModel(); RGroupHandler rgHandler = new RGroupHandler(rgroupQuery, panel); panel.get2DHub().setRGroupHandler(rgHandler); chemModel.setMoleculeSet(rgHandler.getMoleculeSet(chemModel)); rgHandler.layoutRgroup();
@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); }
if (model.getReactionSet() != null && model.getReactionSet().getReactionCount() > 0) { dialog.setMessage( GT.get("Problem"), int i = 0; String eol = System.getProperty("line.separator"); for (IAtomContainer container : model.getMoleculeSet() .atomContainers()) { if (model.getMoleculeSet().getAtomContainerCount() > 1) { dialogText.append(GT.get("Structure") + " #" + (i + 1) + eol);
/** {@inheritDoc} */ @Override public IAtomContainerSet getMoleculeSet() { logger.debug("Getting setOfMolecules: ", super.getMoleculeSet()); return super.getMoleculeSet(); }
/** {@inheritDoc} */ @Override public IReactionSet getReactionSet() { logger.debug("Getting setOfReactions: ", super.getReactionSet()); return super.getReactionSet(); }
/** {@inheritDoc} */ @Override public Object clone() throws CloneNotSupportedException { Object clone = null; try { clone = super.clone(); } catch (Exception exception) { logger.error("Could not clone DebugAtom: " + exception.getMessage(), exception); logger.debug(exception); } return clone; }
/** {@inheritDoc} */ @Override public ICrystal getCrystal() { logger.debug("Getting crystal: ", super.getCrystal()); return super.getCrystal(); }
/** * @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()); }
@Override public Object clone() throws CloneNotSupportedException { ChemSequence clone = (ChemSequence) super.clone(); // clone the chemModels clone.chemModelCount = getChemModelCount(); clone.chemModels = new ChemModel[clone.chemModelCount]; for (int f = 0; f < clone.chemModelCount; f++) { clone.chemModels[f] = (ChemModel) ((ChemModel) chemModels[f]).clone(); } return clone; }
/** * Load an IChemModel from an InChI. * * @param url location * @return InChI instance * @throws CDKException InChI could not be generated */ public static IChemModel readInChI(URL url) throws CDKException { IChemModel chemModel = new ChemModel(); try { IAtomContainerSet moleculeSet = new AtomContainerSet(); chemModel.setMoleculeSet(moleculeSet); BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); String line; while ((line = in.readLine()) != null) { if (line.toLowerCase().startsWith("inchi=")) { moleculeSet.addAtomContainer(parseInChI(line)); } } in.close(); } catch (Exception e) { e.printStackTrace(); throw new CDKException(e.getMessage()); } return chemModel; } }
@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()); }
/** * Returns a String representation of the contents of this * IChemObject. * * @return String representation of content */ @Override public String toString() { StringBuffer buffer = new StringBuffer(64); buffer.append("ChemModel("); buffer.append(hashCode()); if (getMoleculeSet() != null) { buffer.append(", "); buffer.append(getMoleculeSet().toString()); } if (getCrystal() != null) { buffer.append(", "); buffer.append(getCrystal().toString()); } if (getReactionSet() != null) { buffer.append(", "); buffer.append(getReactionSet().toString()); } buffer.append(')'); return buffer.toString(); }
@Override public void endElement(String uri, String local, String raw) { logger.debug("end element: ", raw); if ("identifier".equals(local)) { if (tautomer != null) { // ok, add tautomer setOfMolecules.addAtomContainer(tautomer); chemModel.setMoleculeSet(setOfMolecules); chemSequence.addChemModel(chemModel); } } else if ("formula".equals(local)) { if (tautomer != null) { logger.info("Parsing <formula> chars: ", currentChars); tautomer = new AtomContainer(inchiTool.processFormula( setOfMolecules.getBuilder().newInstance(IAtomContainer.class), currentChars)); } else { logger.warn("Cannot set atom info for empty tautomer"); } } else if ("connections".equals(local)) { if (tautomer != null) { logger.info("Parsing <connections> chars: ", currentChars); inchiTool.processConnections(currentChars, tautomer, -1); } else { logger.warn("Cannot set dbond info for empty tautomer"); } } else { // skip all other elements } }
@Override public Object clone() throws CloneNotSupportedException { ChemSequence clone = (ChemSequence) super.clone(); // clone the chemModels clone.chemModelCount = getChemModelCount(); clone.chemModels = new ChemModel[clone.chemModelCount]; for (int f = 0; f < clone.chemModelCount; f++) { clone.chemModels[f] = (ChemModel) ((ChemModel) chemModels[f]).clone(); } return clone; }
/** * 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(); }