public void undo() { if(chemModel.getMoleculeSet()==null) chemModel.setMoleculeSet(chemModel.getBuilder().newInstance(IAtomContainerSet.class)); chemModel.getMoleculeSet().addAtomContainer(oldContainer); chemModel.getReactionSet().removeReaction(ReactionSetManipulator.getReactionByAtomContainerID(chemModel.getReactionSet(), movedContainer.getID())); }
/** * Read a IChemModel from a file in MDL RDF format. * * @param chemModel The IChemModel * @return The IChemModel that was read from the RDF file */ private IChemModel readChemModel(IChemModel chemModel) throws CDKException { IReactionSet setOfReactions = chemModel.getReactionSet(); if (setOfReactions == null) { setOfReactions = chemModel.getBuilder().newInstance(IReactionSet.class); } chemModel.setReactionSet(readReactionSet(setOfReactions)); return chemModel; }
/** * Sets the AtomProperties of all Atoms inside an IChemModel. * * @param chemModel The IChemModel object. * @param propKey The key of the property. * @param propVal The value of the property. */ public static void setAtomProperties(IChemModel chemModel, Object propKey, Object propVal) { if (chemModel.getMoleculeSet() != null) { MoleculeSetManipulator.setAtomProperties(chemModel.getMoleculeSet(), propKey, propVal); } if (chemModel.getReactionSet() != null) { ReactionSetManipulator.setAtomProperties(chemModel.getReactionSet(), propKey, propVal); } if (chemModel.getCrystal() != null) { AtomContainerManipulator.setAtomProperties(chemModel.getCrystal(), propKey, propVal); } }
public void undo() { if(som!=null) chemModel.setMoleculeSet(som); if(sor!=null) chemModel.setReactionSet(sor); }
protected boolean isValidChemModel(IChemModel chemModel) { return chemModel != null && (chemModel.getMoleculeSet() != null || chemModel .getReactionSet() != null); }
private static void removeEmptyMolecules(IChemModel chemModel) { IAtomContainerSet moleculeSet = chemModel.getMoleculeSet(); if (moleculeSet != null && moleculeSet.getAtomContainerCount() == 0) { chemModel.setMoleculeSet(null); } }
private IChemModel readChemModel(IChemModel chemModel) throws CDKException { IAtomContainerSet setOfMolecules = chemModel.getMoleculeSet(); if (setOfMolecules == null) { setOfMolecules = chemModel.getBuilder().newInstance(IAtomContainerSet.class); } IAtomContainer m = readMolecule(chemModel.getBuilder().newInstance(IAtomContainer.class)); if (m != null) { setOfMolecules.addAtomContainer(m); } chemModel.setMoleculeSet(setOfMolecules); return chemModel; }
private void highlightPeakInSpectrumApplet(IAtom atom) { if(jcpApplet==null || jcpApplet.getParameter("spectrumRenderer")==null) return; try{ Method highlightMethod = getSpectrumApplet().getClass().getMethod("highlightPeakInSpectrum", new Class[] { Integer.TYPE }); highlightMethod.invoke(getSpectrumApplet(), new Object[] { new Integer(chemModelRelay.getIChemModel().getMoleculeSet().getAtomContainer(0).indexOf(atom)) }); spectrumApplet.repaint(); }catch(Exception ex){ ex.printStackTrace(); } }
/** * Returns all the AtomContainer's of a ChemModel. */ public static List<IAtomContainer> getAllAtomContainers(IChemModel chemModel) { IAtomContainerSet moleculeSet = chemModel.getBuilder().newInstance(IAtomContainerSet.class); if (chemModel.getMoleculeSet() != null) { moleculeSet.add(chemModel.getMoleculeSet()); } if (chemModel.getReactionSet() != null) { moleculeSet.add(ReactionSetManipulator.getAllMolecules(chemModel.getReactionSet())); } return MoleculeSetManipulator.getAllAtomContainers(moleculeSet); }
public static List<String> getAllIDs(IChemModel chemModel) { ArrayList<String> list = new ArrayList<String>(); if (chemModel.getID() != null) list.add(chemModel.getID()); ICrystal crystal = chemModel.getCrystal(); if (crystal != null) { list.addAll(AtomContainerManipulator.getAllIDs(crystal)); } IAtomContainerSet moleculeSet = chemModel.getMoleculeSet(); if (moleculeSet != null) { list.addAll(MoleculeSetManipulator.getAllIDs(moleculeSet)); } IReactionSet reactionSet = chemModel.getReactionSet(); if (reactionSet != null) { list.addAll(ReactionSetManipulator.getAllIDs(reactionSet)); } return list; } }
/** * This badly named methods tries to determine which AtomContainer in the * ChemModel is best suited to contain added Atom's and Bond's. */ public static IAtomContainer getRelevantAtomContainer(IChemModel chemModel, IAtom atom) { IAtomContainer result = null; if (chemModel.getMoleculeSet() != null) { IAtomContainerSet moleculeSet = chemModel.getMoleculeSet(); result = MoleculeSetManipulator.getRelevantAtomContainer(moleculeSet, atom); if (result != null) { return result; } } if (chemModel.getReactionSet() != null) { IReactionSet reactionSet = chemModel.getReactionSet(); return ReactionSetManipulator.getRelevantAtomContainer(reactionSet, atom); } if (chemModel.getCrystal() != null && chemModel.getCrystal().contains(atom)) { return chemModel.getCrystal(); } if (chemModel.getRingSet() != null) { return AtomContainerSetManipulator.getRelevantAtomContainer(chemModel.getRingSet(), atom); } throw new IllegalArgumentException("The provided atom is not part of this IChemModel."); }
@Test public void testClone_IAtomContainerSet() throws Exception { IChemModel model = (IChemModel) newChemObject(); IChemModel clone = (IChemModel) model.clone(); Assert.assertNull(clone.getMoleculeSet()); model.setMoleculeSet(model.getBuilder().newInstance(IAtomContainerSet.class)); clone = (IChemModel) model.clone(); Assert.assertNotNull(clone.getMoleculeSet()); Assert.assertNotSame(model.getMoleculeSet(), clone.getMoleculeSet()); }
@Override public void endDocument() { // cdo.endDocument(); if (currentReactionSet != null && currentReactionSet.getReactionCount() == 0 && currentReaction != null) { logger.debug("Adding reaction to ReactionSet"); currentReactionSet.addReaction(currentReaction); } if (currentReactionSet != null && currentChemModel.getReactionSet() == null) { logger.debug("Adding SOR to ChemModel"); currentChemModel.setReactionSet(currentReactionSet); } if (currentMoleculeSet != null && currentMoleculeSet.getAtomContainerCount() != 0) { logger.debug("Adding reaction to MoleculeSet"); currentChemModel.setMoleculeSet(currentMoleculeSet); } if (currentChemSequence.getChemModelCount() == 0) { logger.debug("Adding ChemModel to ChemSequence"); currentChemSequence.addChemModel(currentChemModel); } if (currentChemFile.getChemSequenceCount() == 0) { // assume there is one non-animation ChemSequence // addChemSequence(currentChemSequence); currentChemFile.addChemSequence(currentChemSequence); } logger.info("End XML Doc"); }
@Test @Override public void testStateChanged_IChemObjectChangeEvent() { ChemObjectListenerImpl listener = new ChemObjectListenerImpl(); IChemModel chemObject = (IChemModel) newChemObject(); chemObject.addListener(listener); chemObject.setMoleculeSet(chemObject.getBuilder().newInstance(IAtomContainerSet.class)); Assert.assertTrue(listener.changed); listener.reset(); Assert.assertFalse(listener.changed); chemObject.setReactionSet(chemObject.getBuilder().newInstance(IReactionSet.class)); Assert.assertTrue(listener.changed); listener.reset(); Assert.assertFalse(listener.changed); chemObject.setCrystal(chemObject.getBuilder().newInstance(ICrystal.class)); Assert.assertTrue(listener.changed); listener.reset(); Assert.assertFalse(listener.changed); chemObject.setRingSet(chemObject.getBuilder().newInstance(IRingSet.class)); Assert.assertTrue(listener.changed); }
public static void removeEmptyContainers(IChemModel chemModel) { Iterator<IAtomContainer> it = ChemModelManipulator .getAllAtomContainers(chemModel).iterator(); while (it.hasNext()) { IAtomContainer ac = it.next(); if (ac.getAtomCount() == 0) { chemModel.getMoleculeSet().removeAtomContainer(ac); } } if (chemModel.getMoleculeSet().getAtomContainerCount() == 0) chemModel.getMoleculeSet().addAtomContainer( chemModel.getBuilder().newInstance(IAtomContainer.class)); }
private org.openscience.cdk.interfaces.ICrystal checkForCrystalFile(IChemFile chemFile) { Assert.assertNotNull(chemFile); Assert.assertEquals(chemFile.getChemSequenceCount(), 1); org.openscience.cdk.interfaces.IChemSequence seq = chemFile.getChemSequence(0); Assert.assertNotNull(seq); Assert.assertEquals(seq.getChemModelCount(), 1); org.openscience.cdk.interfaces.IChemModel model = seq.getChemModel(0); Assert.assertNotNull(model); org.openscience.cdk.interfaces.ICrystal crystal = model.getCrystal(); if (crystal != null) return crystal; // null crystal, try and find it in the set IAtomContainerSet set = model.getMoleculeSet(); Assert.assertNotNull(set); for (IAtomContainer container : set.atomContainers()) { if (container instanceof ICrystal) { crystal = (ICrystal) container; return crystal; } } Assert.fail("no crystal could be found in the ChemModel"); return crystal; }
@Test public void testStateChanged_ButNotAfterRemoval_ReactionSet() { ChemObjectListenerImpl listener = new ChemObjectListenerImpl(); IChemModel chemObject = (IChemModel) newChemObject(); chemObject.addListener(listener); IReactionSet reactionSet = chemObject.getBuilder().newInstance(IReactionSet.class); chemObject.setReactionSet(reactionSet); Assert.assertTrue(listener.changed); // remove the set from the IChemModel chemObject.setReactionSet(null); // reset the listener listener.reset(); Assert.assertFalse(listener.changed); // changing the set must *not* trigger a change event in the IChemModel reactionSet.addReaction(chemObject.getBuilder().newInstance(IReaction.class)); Assert.assertFalse(listener.changed); }
@Test public void testClone_IReactionSet() throws Exception { IChemModel model = (IChemModel) newChemObject(); IChemModel clone = (IChemModel) model.clone(); Assert.assertNull(clone.getReactionSet()); model.setReactionSet(model.getBuilder().newInstance(IReactionSet.class)); clone = (IChemModel) model.clone(); Assert.assertNotNull(clone.getReactionSet()); Assert.assertNotSame(model.getReactionSet(), clone.getReactionSet()); }
/** * Create a new chem model for a single {@link IAtomContainer}. * * @param container the container to create the model for * @return a new {@link IChemModel} */ private static IChemModel newModel(final IAtomContainer container) { if (container == null) throw new NullPointerException("cannot create chem model for a null container"); final IChemObjectBuilder builder = container.getBuilder(); final IChemModel model = builder.newInstance(IChemModel.class); final IAtomContainerSet containers = builder.newInstance(IAtomContainerSet.class); containers.addAtomContainer(container); model.setMoleculeSet(containers); return model; }
@Test public void testStateChanged_ButNotAfterRemoval_Crystal() { ChemObjectListenerImpl listener = new ChemObjectListenerImpl(); IChemModel chemObject = (IChemModel) newChemObject(); chemObject.addListener(listener); ICrystal crystal = chemObject.getBuilder().newInstance(ICrystal.class); chemObject.setCrystal(crystal); Assert.assertTrue(listener.changed); // remove the set from the IChemModel chemObject.setCrystal(null); // reset the listener listener.reset(); Assert.assertFalse(listener.changed); // changing the set must *not* trigger a change event in the IChemModel crystal.add(chemObject.getBuilder().newInstance(IAtomContainer.class)); Assert.assertFalse(listener.changed); }