/** * Get all templated coordinates for the provided molecule. The return collection has * coordinates ordered based on the input. * * @param mol molecule (or fragment) to lookup * @return the coordinates */ Collection<Point2d[]> getCoordinates(IAtomContainer mol) { try { // create the library key to lookup an entry, we also store // the canonical out ordering int n = mol.getAtomCount(); int[] ordering = new int[n]; String smiles = cansmi(mol, ordering); final Collection<Point2d[]> coordSet = templateMap.get(smiles); final List<Point2d[]> orderedCoordSet = new ArrayList<>(coordSet.size()); for (Point2d[] coords : coordSet) { Point2d[] orderedCoords = new Point2d[coords.length]; for (int i = 0; i < n; i++) { orderedCoords[i] = new Point2d(coords[ordering[i]]); } orderedCoordSet.add(orderedCoords); } return Collections.unmodifiableList(orderedCoordSet); } catch (CDKException e) { return Collections.emptyList(); } }
/** * Get all templated coordinates for the provided molecule. The return collection has * coordinates ordered based on the input. * * @param mol molecule (or fragment) to lookup * @return the coordinates */ Collection<Point2d[]> getCoordinates(IAtomContainer mol) { try { // create the library key to lookup an entry, we also store // the canonical out ordering int n = mol.getAtomCount(); int[] ordering = new int[n]; String smiles = cansmi(mol, ordering); final Collection<Point2d[]> coordSet = templateMap.get(smiles); final List<Point2d[]> orderedCoordSet = new ArrayList<>(coordSet.size()); for (Point2d[] coords : coordSet) { Point2d[] orderedCoords = new Point2d[coords.length]; for (int i = 0; i < n; i++) { orderedCoords[i] = new Point2d(coords[ordering[i]]); } orderedCoordSet.add(orderedCoords); } return Collections.unmodifiableList(orderedCoordSet); } catch (CDKException e) { return Collections.emptyList(); } }
/** * Update the template library - can be called for safety after * each load. * * @param bldr builder */ void update(IChemObjectBuilder bldr) { final SmilesParser smipar = new SmilesParser(bldr); Multimap<String,Point2d[]> updated = LinkedListMultimap.create(); for (Map.Entry<String,Collection<Point2d[]>> e : templateMap.asMap().entrySet()) { try { IAtomContainer mol = smipar.parseSmiles(e.getKey()); int[] order = new int[mol.getAtomCount()]; String key = cansmi(mol, order); for (Point2d[] coords : e.getValue()) { updated.put(key, reorderCoords(coords, order)); } } catch (CDKException ex) { System.err.println(e.getKey() + " could not be updated: " + ex.getMessage()); } } templateMap.clear(); templateMap.putAll(updated); }
/** * Update the template library - can be called for safety after * each load. * * @param bldr builder */ void update(IChemObjectBuilder bldr) { final SmilesParser smipar = new SmilesParser(bldr); Multimap<String,Point2d[]> updated = LinkedListMultimap.create(); for (Map.Entry<String,Collection<Point2d[]>> e : templateMap.asMap().entrySet()) { try { IAtomContainer mol = smipar.parseSmiles(e.getKey()); int[] order = new int[mol.getAtomCount()]; String key = cansmi(mol, order); for (Point2d[] coords : e.getValue()) { updated.put(key, reorderCoords(coords, order)); } } catch (CDKException ex) { System.err.println(e.getKey() + " could not be updated: " + ex.getMessage()); } } templateMap.clear(); templateMap.putAll(updated); }
/** * Assign a 2D layout to the atom container using the contents of the library. If multiple * coordinates are available the first is choosen. * * @param container structure representation * @return a layout was assigned */ boolean assignLayout(IAtomContainer container) { try { // create the library key to lookup an entry, we also store // the canonical out ordering int n = container.getAtomCount(); int[] ordering = new int[n]; String smiles = cansmi(container, ordering); // find the points in the library for (Point2d[] points : templateMap.get(smiles)) { // set the points for (int i = 0; i < n; i++) { container.getAtom(i).setPoint2d(new Point2d(points[ordering[i]])); } return true; } } catch (CDKException e) { // ignored } return false; }
/** * Assign a 2D layout to the atom container using the contents of the library. If multiple * coordinates are available the first is choosen. * * @param container structure representation * @return a layout was assigned */ boolean assignLayout(IAtomContainer container) { try { // create the library key to lookup an entry, we also store // the canonical out ordering int n = container.getAtomCount(); int[] ordering = new int[n]; String smiles = cansmi(container, ordering); // find the points in the library for (Point2d[] points : templateMap.get(smiles)) { // set the points for (int i = 0; i < n; i++) { container.getAtom(i).setPoint2d(new Point2d(points[ordering[i]])); } return true; } } catch (CDKException e) { // ignored } return false; }
/** * Create a library entry from an atom container. Note the entry is not added to the library. * * @param container structure representation * @return a new library entry (not stored). * @see #add(java.util.Map.Entry) */ Entry<String, Point2d[]> createEntry(final IAtomContainer container) { try { final int n = container.getAtomCount(); final int[] ordering = new int[n]; final String smiles = cansmi(container, ordering); // build point array that is in the canonical output order final Point2d[] points = new Point2d[n]; for (int i = 0; i < n; i++) { Point2d point = container.getAtom(i).getPoint2d(); if (point == null) { logger.warn("Atom at index ", i, " did not have coordinates."); return null; } points[ordering[i]] = point; } return new SimpleEntry<String, Point2d[]>(smiles, points); } catch (CDKException e) { logger.warn("Could not encode container as SMILES: ", e); } return null; }
/** * Create a library entry from an atom container. Note the entry is not added to the library. * * @param container structure representation * @return a new library entry (not stored). * @see #add(java.util.Map.Entry) */ Entry<String, Point2d[]> createEntry(final IAtomContainer container) { try { final int n = container.getAtomCount(); final int[] ordering = new int[n]; final String smiles = cansmi(container, ordering); // build point array that is in the canonical output order final Point2d[] points = new Point2d[n]; for (int i = 0; i < n; i++) { Point2d point = container.getAtom(i).getPoint2d(); if (point == null) { logger.warn("Atom at index ", i, " did not have coordinates."); return null; } points[ordering[i]] = point; } return new SimpleEntry<String, Point2d[]>(smiles, points); } catch (CDKException e) { logger.warn("Could not encode container as SMILES: ", e); } return null; }