/** * * @param reaction * @param withoutH */ public AtomAtomMappingContainer(IReaction reaction, boolean withoutH) { for (IMapping m : reaction.mappings()) { IAtom rAtom = (IAtom) m.getChemObject(0); IAtom pAtom = (IAtom) m.getChemObject(1); if (withoutH && rAtom != null && pAtom != null && (rAtom.getSymbol().equalsIgnoreCase("H") || pAtom.getSymbol().equalsIgnoreCase("H"))) { } else { reactantAtomArray.add(rAtom); productAtomArray.add(pAtom); } } }
/** * * @param reaction * @param g */ public void drawMappings(IReaction reaction, Graphics2D g) { g.setColor(LIGHT_GRAY); for (IMapping mapping : reaction.mappings()) { IAtom a0 = (IAtom) mapping.getChemObject(0); IAtom a1 = (IAtom) mapping.getChemObject(1); Point2d p0 = a0.getPoint2d(); Point2d p1 = a1.getPoint2d(); g.drawLine((int) p0.x, (int) p0.y, (int) p1.x, (int) p1.y); } }
/** * get the IAtom which is mapped * * @param reaction The IReaction which contains the mapping * @param chemObject The IChemObject which will be searched its mapped IChemObject * @return The mapped IChemObject */ public static IChemObject getMappedChemObject(IReaction reaction, IChemObject chemObject) { for (IMapping mapping : reaction.mappings()) { if (mapping.getChemObject(0).equals(chemObject)) { return mapping.getChemObject(1); } else if (mapping.getChemObject(1).equals(chemObject)) return mapping.getChemObject(0); } return null; }
/** * * @param reaction */ protected void renumberMappingIDs(IReaction reaction) { int i = 1; for (IMapping mapping : reaction.mappings()) { IAtom a0 = (IAtom) mapping.getChemObject(0); IAtom a1 = (IAtom) mapping.getChemObject(1); a0.setID(valueOf(i)); a1.setID(valueOf(i)); mapping.setID(valueOf(i)); i++; } }
for (IMapping mapping : reaction.mappings()) { IAtom a0 = (IAtom) mapping.getChemObject(0); IAtom a1 = (IAtom) mapping.getChemObject(1);
/** * * @param reaction */ protected void setMappingIDs(IReaction reaction) { int i = 0; for (IMapping mapping : reaction.mappings()) { IAtom a0 = (IAtom) mapping.getChemObject(0); IAtom a1 = (IAtom) mapping.getChemObject(1); Object mappingID = a0.getProperty(ATOM_ATOM_MAPPING); // Integer mappingID = // (Integer)a0.getProperty(CDKConstants.ATOM_ATOM_MAPPING); if (mappingID != null) { a0.setID(valueOf(mappingID)); a1.setID(valueOf(mappingID)); } else { a0.setID(valueOf(i)); a1.setID(valueOf(i)); } i++; } }
public static void fixCoordinates(IReaction reaction) { for (IMapping mapping : reaction.mappings()) { IAtom a0 = (IAtom)mapping.getChemObject(0); IAtom a1 = (IAtom)mapping.getChemObject(1); if (a0 == null || a1 == null) continue; a1.setPoint2d(new Point2d(a0.getPoint2d())); } } }
private static void printIDs(IReaction reaction) { IAtomContainerSet reactants = reaction.getReactants(); IAtomContainerSet products = reaction.getProducts(); for (IAtomContainer reactant : reactants.atomContainers()) { out.print("["); for (int i = 0; i < reactant.getAtomCount(); i++) { IAtom atom = reactant.getAtom(i); out.print(atom.getSymbol() + i + "." + atom.getID() + ","); } out.println("]"); } for (IAtomContainer product : products.atomContainers()) { out.print("["); for (int i = 0; i < product.getAtomCount(); i++) { IAtom atom = product.getAtom(i); out.print(atom.getSymbol() + i + "." + atom.getID() + ","); } out.println("]"); } out.print("{"); for (IMapping mapping : reaction.mappings()) { IAtom a0 = (IAtom) mapping.getChemObject(0); IAtom a1 = (IAtom) mapping.getChemObject(1); out.print(format("%s-%s, ", a0.getID(), a1.getID())); } out.println("}"); }
/** * * @param reaction */ public static void fixCoordinates(IReaction reaction) { for (IMapping mapping : reaction.mappings()) { IAtom a0 = (IAtom) mapping.getChemObject(0); IAtom a1 = (IAtom) mapping.getChemObject(1); if (a0 != null && a1 != null) { a1.setPoint2d(new Point2d(a0.getPoint2d())); } } }
/** * * @param reaction * @return */ public static List<WedgeStereoComparisonResult> compare(IReaction reaction) { List<WedgeStereoComparisonResult> results = new ArrayList<>(); WedgeStereoLifter lifter = new WedgeStereoLifter(); IAtomContainerSet reactants = reaction.getReactants(); IAtomContainerSet products = reaction.getProducts(); for (IMapping mapping : reaction.mappings()) { IAtom atomA = (IAtom) mapping.getChemObject(0); IAtom atomB = (IAtom) mapping.getChemObject(1); IAtomContainer atomContainerA = getRelevantAtomContainer(reactants, atomA); IAtomContainer atomContainerB = getRelevantAtomContainer(products, atomB); results.add(compare(atomA, atomContainerA, atomB, atomContainerB, lifter)); } return results; }
private List<DefinedMapping> createDefinedMappings(IReaction reaction) { IAtomContainerSet reactants = reaction.getReactants(); IAtomContainerSet products = reaction.getProducts(); List<DefinedMapping> definedMappings = new ArrayList<>(); int i = 0; for (IMapping mapping : reaction.mappings()) { String id = mapping.getChemObject(0).getID(); AtomContainerAtomPair reactantPair = getByID(reactants, id); AtomContainerAtomPair productPair = getByID(products, id); if (reactantPair != null && productPair != null) { int rIndex = reactantPair.getIndex(); int pIndex = productPair.getIndex(); definedMappings.add( new DefinedMapping(rIndex, pIndex, i, reactantPair.atomContainer, productPair.atomContainer)); i++; } } return definedMappings; }
@Test public void testReadMapping() throws Exception { String filename2 = "data/mdl/mappingTest.rxn"; logger.info("Testing: " + filename2); InputStream ins2 = this.getClass().getClassLoader().getResourceAsStream(filename2); MDLRXNV2000Reader reader2 = new MDLRXNV2000Reader(ins2); IReaction reaction2 = new Reaction(); reaction2 = (IReaction) reader2.read(reaction2); reader2.close(); Assert.assertNotNull(reaction2); Iterator<IMapping> maps = reaction2.mappings().iterator(); maps.next(); Assert.assertTrue(maps.hasNext()); }
/** * * @param reaction * @return */ public List<DefinedMapping> createDefinedMappings(IReaction reaction) { IAtomContainerSet reactants = reaction.getReactants(); IAtomContainerSet products = reaction.getProducts(); List<DefinedMapping> definedMappings = new ArrayList<>(); int i = 0; for (IMapping mapping : reaction.mappings()) { String id = mapping.getChemObject(0).getID(); AtomContainerAtomPair reactantPair = getByID(reactants, id); AtomContainerAtomPair productPair = getByID(products, id); int rIndex = reactantPair.getIndex(); int pIndex = productPair.getIndex(); definedMappings.add( new DefinedMapping(rIndex, pIndex, i, reactantPair.atomContainer, productPair.atomContainer)); i++; } return definedMappings; }
@Test public void testReadMapping() throws Exception { String filename2 = "data/mdl/mappingTest.rxn"; logger.info("Testing: " + filename2); InputStream ins2 = this.getClass().getClassLoader().getResourceAsStream(filename2); MDLRXNReader reader2 = new MDLRXNReader(ins2); IReaction reaction2 = new Reaction(); reaction2 = (IReaction) reader2.read(reaction2); reader2.close(); Assert.assertNotNull(reaction2); Iterator<IMapping> maps = reaction2.mappings().iterator(); maps.next(); Assert.assertTrue(maps.hasNext()); }
@Test public void testClone_Mapping() throws Exception { IReaction reaction = (IReaction) newChemObject(); IMapping mapping = reaction.getBuilder().newInstance(IMapping.class, reaction.getBuilder().newInstance(IAtom.class, "C"), reaction.getBuilder().newInstance(IAtom.class, "C")); reaction.addMapping(mapping); IReaction clonedReaction = (IReaction) reaction.clone(); Iterator<IMapping> mappings = reaction.mappings().iterator(); Iterator<IMapping> clonedMappings = clonedReaction.mappings().iterator(); Assert.assertNotNull(mappings); Assert.assertTrue(mappings.hasNext()); Assert.assertNotNull(clonedMappings); Assert.assertTrue(clonedMappings.hasNext()); }
/** {@inheritDoc} */ @Override public IRenderingElement generate(IReaction reaction, RendererModel model) { if (!showAtomAtomMapping.getValue()) return null; ElementGroup elementGroup = new ElementGroup(); Color mappingColor = atomAtomMappingLineColor.getValue(); for (IMapping mapping : reaction.mappings()) { // XXX assume that there are only 2 endpoints! // XXX assume that the ChemObjects are actually IAtoms... IAtom endPointA = (IAtom) mapping.getChemObject(0); IAtom endPointB = (IAtom) mapping.getChemObject(1); Point2d pointA = endPointA.getPoint2d(); Point2d pointB = endPointB.getPoint2d(); elementGroup.add(new LineElement(pointA.x, pointA.y, pointB.x, pointB.y, getWidthForMappingLine(model), mappingColor)); } return elementGroup; }
@Test public void testAddMapping_IMapping() { IReaction reaction = (IReaction) newChemObject(); IMapping mapping = reaction.getBuilder().newInstance(IMapping.class, reaction.getBuilder().newInstance(IAtom.class, "C"), reaction.getBuilder().newInstance(IAtom.class, "C")); reaction.addMapping(mapping); Iterator<IMapping> mappings = reaction.mappings().iterator(); Assert.assertNotNull(mappings); Assert.assertTrue(mappings.hasNext()); Assert.assertEquals(mapping, (IMapping) mappings.next()); }
/** {@inheritDoc} */ @Override public IRenderingElement generate(IReaction reaction, RendererModel model) { if (!showAtomAtomMapping.getValue()) return null; ElementGroup elementGroup = new ElementGroup(); Color mappingColor = atomAtomMappingLineColor.getValue(); for (IMapping mapping : reaction.mappings()) { // XXX assume that there are only 2 endpoints! // XXX assume that the ChemObjects are actually IAtoms... IAtom endPointA = (IAtom) mapping.getChemObject(0); IAtom endPointB = (IAtom) mapping.getChemObject(1); Point2d pointA = endPointA.getPoint2d(); Point2d pointB = endPointB.getPoint2d(); elementGroup.add(new LineElement(pointA.x, pointA.y, pointB.x, pointB.y, getWidthForMappingLine(model), mappingColor)); } return elementGroup; }
public IRenderingElement generate(IReaction reaction, JChemPaintRendererModel model) { if(!model.getShowAtomAtomMapping()) return null; ElementGroup elementGroup = new ElementGroup(); Color mappingColor = model.getAtomAtomMappingLineColor(); for (IMapping mapping : reaction.mappings()) { // XXX assume that there are only 2 endpoints! // XXX assume that the ChemObjects are actually IAtoms... IAtom endPointA = (IAtom) mapping.getChemObject(0); IAtom endPointB = (IAtom) mapping.getChemObject(1); Point2d pA = endPointA.getPoint2d(); Point2d pB = endPointB.getPoint2d(); elementGroup.add( new LineElement(pA.x, pA.y, pB.x, pB.y, getWidthForMappingLine(model), mappingColor)); } return elementGroup; }
private IReaction layoutReaction( IReaction mappedReaction, String reactionID) { IReaction reactionWithLayout = new Reaction(); reactionWithLayout.setDirection(FORWARD); reactionWithLayout.setID(reactionID); for (IAtomContainer ac : mappedReaction.getReactants().atomContainers()) { IAtomContainer moleculeWithLayoutCheck = getMoleculeWithLayoutCheck(ac); moleculeWithLayoutCheck.setID(ac.getID()); reactionWithLayout.addReactant(ac, mappedReaction.getReactantCoefficient(ac)); } for (IAtomContainer ac : mappedReaction.getProducts().atomContainers()) { IAtomContainer moleculeWithLayoutCheck = getMoleculeWithLayoutCheck(ac); moleculeWithLayoutCheck.setID(ac.getID()); reactionWithLayout.addProduct(ac, mappedReaction.getProductCoefficient(ac)); } for (IMapping m : mappedReaction.mappings()) { reactionWithLayout.addMapping(m); } reactionWithLayout.setFlags(mappedReaction.getFlags()); reactionWithLayout.setProperties(mappedReaction.getProperties()); return reactionWithLayout; }