/** * Returns the stoichiometry coefficient of the given product. * * @param product Product for which the coefficient is returned. * @return -1, if the given molecule is not a product in this Reaction * @see #setProductCoefficient */ @Override public Double getProductCoefficient(IAtomContainer product) { return products.getMultiplier(product); }
/** * Returns the stoichiometry coefficient of the given product. * * @param product Product for which the coefficient is returned. * @return -1, if the given molecule is not a product in this Reaction * @see #setProductCoefficient */ @Override public Double getProductCoefficient(IAtomContainer product) { return products.getMultiplier(product); }
/** * Returns the stoichiometry coefficient of the given reactant. * * @param reactant Reactant for which the coefficient is returned. * @return -1, if the given molecule is not a product in this Reaction * @see #setReactantCoefficient */ @Override public Double getReactantCoefficient(IAtomContainer reactant) { return reactants.getMultiplier(reactant); }
/** * Returns the stoichiometry coefficient of the given reactant. * * @param reactant Reactant for which the coefficient is returned. * @return -1, if the given molecule is not a product in this Reaction * @see #setReactantCoefficient */ @Override public Double getReactantCoefficient(IAtomContainer reactant) { return reactants.getMultiplier(reactant); }
/** * Returns the stoichiometry coefficient of the given product. * * @param product Product for which the coefficient is returned. * @return -1, if the given molecule is not a product in this Reaction * @see #setProductCoefficient */ @Override public Double getProductCoefficient(IAtomContainer product) { return products.getMultiplier(product); }
/** * Returns the stoichiometry coefficient of the given reactant. * * @param reactant Reactant for which the coefficient is returned. * @return -1, if the given molecule is not a product in this Reaction * @see #setReactantCoefficient */ @Override public Double getReactantCoefficient(IAtomContainer reactant) { return reactants.getMultiplier(reactant); }
/** * Returns the stoichiometry coefficient of the given reactant. * * @param reactant Reactant for which the coefficient is returned. * @return -1, if the given molecule is not a product in this Reaction * @see #setReactantCoefficient */ @Override public Double getReactantCoefficient(IAtomContainer reactant) { return reactants.getMultiplier(reactant); }
/** * Returns the stoichiometry coefficient of the given product. * * @param product Product for which the coefficient is returned. * @return -1, if the given molecule is not a product in this Reaction * @see #setProductCoefficient */ @Override public Double getProductCoefficient(IAtomContainer product) { return products.getMultiplier(product); }
/** * @param set The collection of IAtomContainer objects * @return The summed formal charges of all atoms in this set. */ public static double getTotalFormalCharge(IAtomContainerSet set) { int charge = 0; for (int i = 0; i < set.getAtomContainerCount(); i++) { int thisCharge = AtomContainerManipulator.getTotalFormalCharge(set.getAtomContainer(i)); double stoich = set.getMultiplier(i); charge += stoich * thisCharge; } return charge; }
/** * @param set The collection of IAtomContainer objects * @return The summed charges of all atoms in this set. */ public static double getTotalCharge(IAtomContainerSet set) { double charge = 0; for (int i = 0; i < set.getAtomContainerCount(); i++) { int thisCharge = AtomContainerManipulator.getTotalFormalCharge(set.getAtomContainer(i)); double stoich = set.getMultiplier(i); charge += stoich * thisCharge; } return charge; }
@Override public void endElement(CMLStack xpath, String uri, String local, String raw) { if ("reaction".equals(local)) { // cdo.endObject("Reaction"); currentReactionSet.addReaction(currentReaction); currentChemModel.setReactionSet(currentReactionSet); } else if ("reactionList".equals(local)) { // cdo.endObject("ReactionSet"); currentChemModel.setReactionSet(currentReactionSet); /* FIXME: this should be when document is closed! */ } else if ("reactant".equals(local)) { // cdo.endObject("Reactant"); currentReaction.addReactant(currentMolecule); } else if ("product".equals(local)) { // cdo.endObject("Product"); currentReaction.addProduct(currentMolecule); } else if ("substance".equals(local)) { // cdo.endObject("Agent"); currentReaction.addAgent(currentMolecule); } else if ("molecule".equals(local)) { logger.debug("Storing Molecule"); //if the current molecule exists in the currentMoleculeSet means that is a reference in these. if (currentMoleculeSet.getMultiplier(currentMolecule) == -1) super.storeData(); // do nothing else but store atom/bond information } else { super.endElement(xpath, uri, local, raw); } }
@Test public void testSetMultipliers_arrayDouble() { IAtomContainerSet som = (IAtomContainerSet) newChemObject(); IAtomContainer container = som.getBuilder().newInstance(IAtomContainer.class); som.addAtomContainer(container); IAtomContainer container2 = som.getBuilder().newInstance(IAtomContainer.class); som.addAtomContainer(container2); Assert.assertEquals(1.0, som.getMultiplier(0), 0.00001); Assert.assertEquals(1.0, som.getMultiplier(1), 0.00001); Double[] multipliers = new Double[2]; multipliers[0] = 2.0; multipliers[1] = 3.0; som.setMultipliers(multipliers); Assert.assertEquals(2.0, som.getMultiplier(0), 0.00001); Assert.assertEquals(3.0, som.getMultiplier(1), 0.00001); }
@Test public void testCloneMultiplier() throws Exception { IAtomContainerSet containerSet = (IAtomContainerSet) newChemObject(); containerSet.addAtomContainer(containerSet.getBuilder().newInstance(IAtomContainer.class), 2); Object clone = containerSet.clone(); Assert.assertTrue(clone instanceof IAtomContainerSet); IAtomContainerSet clonedSet = (IAtomContainerSet) clone; Assert.assertNotSame(containerSet, clonedSet); Assert.assertEquals(2, containerSet.getMultiplier(0).intValue()); Assert.assertEquals(2, clonedSet.getMultiplier(0).intValue()); }
@Test public void testSetMultiplier_int_Double() { IAtomContainerSet som = (IAtomContainerSet) newChemObject(); som.addAtomContainer(som.getBuilder().newInstance(IAtomContainer.class)); Assert.assertEquals(1.0, som.getMultiplier(0), 0.00001); som.setMultiplier(0, 2.0); Assert.assertEquals(2.0, som.getMultiplier(0), 0.00001); }
@Test public void testSetMultiplier_IAtomContainer_Double() { IAtomContainerSet som = (IAtomContainerSet) newChemObject(); IAtomContainer container = som.getBuilder().newInstance(IAtomContainer.class); som.addAtomContainer(container); Assert.assertEquals(1.0, som.getMultiplier(container), 0.00001); som.setMultiplier(container, 2.0); Assert.assertEquals(2.0, som.getMultiplier(container), 0.00001); }
public void redo() { if (containerToAddTo != null && chemModel.getMoleculeSet().getMultiplier(containerToAddTo) == -1) { chemModel.getMoleculeSet().addAtomContainer(containerToAddTo); } //markr: this code creates problems when dragging a bond across a structure, so that it merges with itself.. //if(removedAtomContainer!=null){ // containerToAddTo.add(removedAtomContainer); // chemModel.getMoleculeSet().removeAtomContainer(removedAtomContainer); //} for (int i = 0; i < undoRedoContainer.getBondCount(); i++) { IBond bond = undoRedoContainer.getBond(i); containerToAddTo.addBond(bond); } for (int i = 0; i < undoRedoContainer.getAtomCount(); i++) { IAtom atom = undoRedoContainer.getAtom(i); containerToAddTo.addAtom(atom); chemModelRelay.updateAtom(atom); } }
@Test public void testGetMultiplier_int() { IAtomContainerSet som = (IAtomContainerSet) newChemObject(); som.addAtomContainer(som.getBuilder().newInstance(IAtomContainer.class)); Assert.assertEquals(1.0, som.getMultiplier(0), 0.00001); }
@Test public void testAddAtomContainer_IAtomContainer_double() { IAtomContainerSet som = (IAtomContainerSet) newChemObject(); som.addAtomContainer(som.getBuilder().newInstance(IAtomContainer.class), 2.0); Assert.assertEquals(1, som.getAtomContainerCount()); Assert.assertEquals(2.0, som.getMultiplier(0), 0.00001); }
@Test public void testGetMultiplier_IAtomContainer() { IAtomContainerSet som = (IAtomContainerSet) newChemObject(); som.addAtomContainer(som.getBuilder().newInstance(IAtomContainer.class)); Assert.assertEquals(-1.0, som.getMultiplier(som.getBuilder().newInstance(IAtomContainer.class)), 0.00001); }
@Test public void testSortAtomContainers_WithMuliplier() { IAtomContainerSet som = (IAtomContainerSet) newChemObject(); IAtomContainer ac1 = som.getBuilder().newInstance(IAtomContainer.class); som.addAtomContainer(ac1, 2.0); ac1.setProperty("multiplierSortCode", "2"); IAtomContainer ac2 = som.getBuilder().newInstance(IAtomContainer.class); som.addAtomContainer(ac2, 1.0); ac2.setProperty("multiplierSortCode", "1"); som.sortAtomContainers(new Comparator<IAtomContainer>() { @Override public int compare(IAtomContainer o1, IAtomContainer o2) { return ((String) o1.getProperty("multiplierSortCode")).compareTo((String) o2 .getProperty("multiplierSortCode")); } }); Assert.assertEquals(2, som.getAtomContainerCount()); IAtomContainer newFirstAC = som.getAtomContainer(0); Assert.assertEquals(newFirstAC.getProperty("multiplierSortCode"), "1"); // OK, sorting worked as intended // The multiplier should have been resorted too: Assert.assertEquals(1.0, som.getMultiplier(newFirstAC), 0.00001); }