/** * * @param reaction * @param w * @param g */ public void drawReactionID(IReaction reaction, int w, Graphics2D g) { String id = reaction.getID(); if (id == null) { return; } g.setColor(BLACK); g.drawString(id, w / 2, 10); }
/** * Gets a reaction from a ReactionSet by ID. If several exist, * only the first one will be returned. * * @param reactionSet The reactionSet to search in * @param id The id to search for. * @return The Reaction or null; */ public static IReaction getReactionByReactionID(IReactionSet reactionSet, String id) { Iterable<IReaction> reactionIter = reactionSet.reactions(); for (IReaction reaction : reactionIter) { if (reaction.getID() != null && reaction.getID().equals(id)) { return reaction; } } return null; } }
public static Set<String> currentIds(IReactionSet reactionSet) { Set<String> ids = new HashSet<String>(); for (IReaction reaction : reactionSet.reactions()) { ids.add(reaction.getID()); } return ids; } }
public void setChemObject(IChemObject object) { if (object instanceof IReaction) { source = object; // update table contents IReaction reaction = (IReaction)source; idField.setText(reaction.getID()); //TODO //directionField.setSelectedIndex(reaction.getDirection()); solventField.setText((String)reaction.getProperty(SOLVENT)); tempField.setText((String)reaction.getProperty(TEMPERATURE)); } else { throw new IllegalArgumentException("Argument must be an Reaction"); } }
/** {@inheritDoc} */ @Override public void removeReaction(IReaction reaction) { logger.debug("Removing reaction " + reaction.getID()); super.removeReaction(reaction); }
@Override public void store(IReaction reaction) { String id = reaction.getID(); File file = new File(reactionDir, id + ".rxn"); try { FileWriter writer = new FileWriter(file); rxnWriter = new MDLV2000RXNWriter(writer); // rxnWriter.setWriter(writer); rxnWriter.write(reaction); // writer.flush(); // writer.close(); rxnWriter.close(); } catch (CDKException | IOException e) { e.printStackTrace(); } }
public static List<String> getAllIDs(IReaction reaction) { List<String> idList = new ArrayList<String>(); if (reaction.getID() != null) idList.add(reaction.getID()); IAtomContainerSet reactants = reaction.getReactants(); for (int i = 0; i < reactants.getAtomContainerCount(); i++) { IAtomContainer mol = reactants.getAtomContainer(i); idList.addAll(AtomContainerManipulator.getAllIDs(mol)); } IAtomContainerSet products = reaction.getProducts(); for (int i = 0; i < products.getAtomContainerCount(); i++) { IAtomContainer mol = products.getAtomContainer(i); idList.addAll(AtomContainerManipulator.getAllIDs(mol)); } return idList; }
private static void setReactionIDs(IChemModel chemModel) { // we give all reactions an ID, in case they have none // IDs are needed for handling in JCP IReactionSet reactionSet = chemModel.getReactionSet(); if (reactionSet != null) { int i = 0; for (IReaction reaction : reactionSet.reactions()) { if (reaction.getID() == null) reaction.setID("Reaction " + (++i)); } } }
/** * Creates mapping PDFs for all the processed reaction mappings * * @param reactor * @param outputDirectoryName * @param outFileName * @throws Exception */ public static synchronized void writeMappingRXN(Reactor reactor, String outputDirectoryName, String outFileName) throws Exception { String reactionID = reactor.getReactionWithAtomAtomMapping().getID(); IReaction mappedReaction = reactor.getReactionWithAtomAtomMapping(); if (reactionID == null) { reactionID = valueOf(currentTimeMillis()); reactor.getReactionWithAtomAtomMapping().setID(reactionID); } String outputFile = outputDirectoryName; outputFile += separator + outFileName; try (MDLV2000RXNWriter rxnW = new MDLV2000RXNWriter(new FileWriter(new File(outputFile)))) { rxnW.write(mappedReaction); } } private Map<IMappingAlgorithm, Reactor> solution = null;
/** * @param chemModel * @param undoRedoContainer * @param c2dm The controller model; if none, set to null */ public MakeReactantOrProductInNewReactionEdit(IChemModel chemModel, IAtomContainer ac, IAtomContainer oldcontainer, boolean reactantOrProduct, String type) { this.type = type; this.movedContainer = ac; this.oldContainer = oldcontainer; this.chemModel = chemModel; this.reactionID = ReactionSetManipulator.getReactionByAtomContainerID(chemModel.getReactionSet(), movedContainer.getID()).getID(); this.reactantOrProduct = reactantOrProduct; }
/** * * @param reaction * @return New Standardized reaction Object * @throws Exception */ @Override public synchronized IReaction standardize(IReaction reaction) throws Exception { String ReactionID = reaction.getID(); cleanMapping(reaction); if (ReactionID == null) { ReactionID = Long.toString(currentTimeMillis()); reaction.setID(ReactionID); } CDKReactionBuilder rBuilder = new CDKReactionBuilder(); IReaction standardizedReaction = rBuilder.standardize(reaction); return standardizedReaction; } }
public IRenderingElement generate(IReaction reaction, JChemPaintRendererModel model) { if (!model.getShowReactionBoxes()) return null; double d = model.getBondLength() / model.getScale(); Rectangle2D totalBounds = Renderer.calculateBounds(reaction); if (totalBounds == null) return null; ElementGroup diagram = new ElementGroup(); diagram.add(new RectangleElement(totalBounds.getMinX()-d, totalBounds.getMaxY()+d, totalBounds.getMaxX()+d, totalBounds.getMinY()-d, model.getForeColor())); if (reaction.getID() != null) { diagram.add(new TextElement((totalBounds.getMinX() +totalBounds.getMaxX())/2, totalBounds.getMinY()-d, reaction.getID(), model.getForeColor())); } return diagram; }
/** {@inheritDoc} */ @Override public IRenderingElement generate(IReaction reaction, RendererModel model) { if (!model.getParameter(ShowReactionBoxes.class).getValue()) return null; double separation = model.getParameter(BondLength.class).getValue() / model.getParameter(Scale.class).getValue(); Rectangle2D totalBounds = BoundsCalculator.calculateBounds(reaction); if (totalBounds == null) return null; ElementGroup diagram = new ElementGroup(); Color foregroundColor = model.getParameter(BasicSceneGenerator.ForegroundColor.class).getValue(); diagram.add(new RectangleElement(totalBounds.getMinX() - separation, totalBounds.getMinY() - separation, totalBounds.getMaxX() + separation, totalBounds.getMaxY() + separation, foregroundColor)); if (reaction.getID() != null) { diagram.add(new TextElement((totalBounds.getMinX() + totalBounds.getMaxX()) / 2, totalBounds.getMinY() - separation, reaction.getID(), foregroundColor)); } return diagram; }
/** {@inheritDoc} */ @Override public IRenderingElement generate(IReaction reaction, RendererModel model) { if (!model.getParameter(ShowReactionBoxes.class).getValue()) return null; double separation = model.getParameter(BondLength.class).getValue() / model.getParameter(Scale.class).getValue(); Rectangle2D totalBounds = BoundsCalculator.calculateBounds(reaction); if (totalBounds == null) return null; ElementGroup diagram = new ElementGroup(); Color foregroundColor = model.getParameter(BasicSceneGenerator.ForegroundColor.class).getValue(); diagram.add(new RectangleElement(totalBounds.getMinX() - separation, totalBounds.getMinY() - separation, totalBounds.getMaxX() + separation, totalBounds.getMaxY() + separation, foregroundColor)); if (reaction.getID() != null) { diagram.add(new TextElement((totalBounds.getMinX() + totalBounds.getMaxX()) / 2, totalBounds.getMinY() - separation, reaction.getID(), foregroundColor)); } return diagram; }
/** * * @param reaction * @param labeller * @return */ public IReaction labelReaction( IReaction reaction, ICanonicalMoleculeLabeller labeller) { out.println("labelling " + reaction.getID()); IReaction canonReaction = new Reaction(); Map<IAtomContainer, int[]> permutationMap = new HashMap<>(); canonReaction.setProducts( canoniseAtomContainerSet( reaction.getProducts(), labeller, permutationMap)); canonReaction.setReactants( canoniseAtomContainerSet( reaction.getReactants(), labeller, permutationMap)); cloneAndSortMappings(reaction, canonReaction, permutationMap); canonReaction.setID(reaction.getID()); return canonReaction; } }
/** * * @param reaction * @return a new mol with explicit Hydrogens * @throws CloneNotSupportedException */ public static IReaction addExplicitH(IReaction reaction) throws CloneNotSupportedException { IReaction r = reaction.getBuilder().newInstance(IReaction.class); for (IAtomContainer ac : reaction.getReactants().atomContainers()) { IAtomContainer addExplicitH = ExtAtomContainerManipulator.addExplicitH(ac); r.addReactant(addExplicitH, reaction.getReactantCoefficient(ac)); } for (IAtomContainer ac : reaction.getProducts().atomContainers()) { IAtomContainer addExplicitH = ExtAtomContainerManipulator.addExplicitH(ac); r.addProduct(addExplicitH, reaction.getProductCoefficient(ac)); } r.setDirection(reaction.getDirection()); r.setID(reaction.getID() == null ? "" : reaction.getID()); return r; } }
/** * * @param reaction * @throws CDKException */ public ReactionFingerprinter(IReaction reaction) throws CDKException { IReaction r = expandReactionAndRemoveHydrogens(reaction); IPatternFingerprinter fpr = null; try { fpr = getSumOfFingerprints(r.getReactants()); } catch (Exception ex) { LOGGER.debug("ERROR: while get SumOfFingerprints for Reactants"); } IPatternFingerprinter fpp = null; try { fpp = getSumOfFingerprints(r.getProducts()); } catch (Exception ex) { LOGGER.debug("ERROR: while get SumOfFingerprints for Products"); } this.reactionFingerprint = summationPatterns(fpr, fpp); reactionFingerprint.setFingerprintID(r.getID()); }
@Override public IReaction getCanonicalReaction(IReaction reaction) { BlockMapping blockMapping = new BlockMapping(reaction); // printReaction(reaction); builder = reaction.getBuilder(); IReaction permutedReaction = builder.newInstance(IReaction.class); IAtomContainerSet reactants = reaction.getReactants(); IAtomContainerSet permutedReactants = permuteR(reactants, blockMapping); permutedReaction.setReactants(permutedReactants); IAtomContainerSet products = reaction.getProducts(); IAtomContainerSet permutedProducts = permuteP(products, blockMapping); permutedReaction.setProducts(permutedProducts); replaceMappings(reaction, permutedReaction); permutedReaction.setID(reaction.getID()); return permutedReaction; }
protected IReaction convertRoundTripRXNSMILES(IReaction r) throws CDKException { final SmilesGenerator sg = new SmilesGenerator( SmiFlavor.AtomAtomMap | SmiFlavor.UseAromaticSymbols | SmiFlavor.Stereo); String createSmilesFromReaction = sg.create(r); final SmilesParser smilesParser = new SmilesParser(SilentChemObjectBuilder.getInstance()); IReaction parseReactionSmiles = smilesParser.parseReactionSmiles(createSmilesFromReaction); parseReactionSmiles.setID(r.getID()); for (int i = 0; i < r.getReactantCount(); i++) { parseReactionSmiles.getReactants().getAtomContainer(i).setID(r.getReactants().getAtomContainer(i).getID()); } for (int i = 0; i < r.getProductCount(); i++) { parseReactionSmiles.getProducts().getAtomContainer(i).setID(r.getProducts().getAtomContainer(i).getID()); } return parseReactionSmiles; }
@Test public void testRemoveReaction_IReaction() { IReactionSet reactionSet = (IReactionSet) newChemObject(); IReaction reaction = reactionSet.getBuilder().newInstance(IReaction.class); reaction.setID("1"); reactionSet.addReaction(reaction); IReaction relevantReaction = reactionSet.getBuilder().newInstance(IReaction.class); relevantReaction.setID("2"); reactionSet.addReaction(relevantReaction); Assert.assertEquals(2, reactionSet.getReactionCount()); reactionSet.removeReaction(relevantReaction); Assert.assertEquals(1, reactionSet.getReactionCount()); Assert.assertEquals("1", reactionSet.getReaction(0).getID()); reactionSet.addReaction(relevantReaction); reactionSet.addReaction(relevantReaction); Assert.assertEquals(3, reactionSet.getReactionCount()); reactionSet.removeReaction(relevantReaction); Assert.assertEquals(1, reactionSet.getReactionCount()); Assert.assertEquals("1", reactionSet.getReaction(0).getID()); }