/**{@inheritDoc} */ @Override public void setProperties(Map<Object, Object> properties) { this.properties = null; if (properties != null) addProperties(properties); }
@Override public IAtom clone() throws CloneNotSupportedException { // XXX: clone always dodgy return (IAtom) super.clone(); }
/** *{@inheritDoc} */ @Override public boolean[] getFlags() { // could use a list a invoke .toArray() on the return boolean[] flagArray = new boolean[CDKConstants.MAX_FLAG_INDEX + 1]; for (int i = 0; i < CDKConstants.FLAG_MASKS.length; i++) { int mask = CDKConstants.FLAG_MASKS[i]; flagArray[i] = getFlag(mask); } return flagArray; }
/** * Sets the properties of this object. * *@param properties a Hashtable specifying the property values *@see #getProperties */ @Override public void addProperties(Map<Object, Object> properties) { if (properties == null) return; lazyProperties().putAll(properties); notifyChanged(); }
/** * This should be triggered by an method that changes the content of an object * to that the registered listeners can react to it. This is a version of * notifyChanged() which allows to propagate a change event while preserving * the original origin. * *@param evt A ChemObjectChangeEvent pointing to the source of where * the change happend */ @Override public void notifyChanged(IChemObjectChangeEvent evt) { if (getNotification() && getListenerCount() > 0) { List<IChemObjectListener> listeners = lazyChemObjectListeners(); for (Object listener : listeners) { ((IChemObjectListener) listener).stateChanged(evt); } } }
@Test public void testFingerprints() throws Exception { BitSet[] expected = new BitSet[]{ parseBitSet("{3, 5, 8, 18, 29, 33, 39, 65, 71, 90, 105, 125, 140, 170, 182, 192, 199, 203, 209, 213, 226, 271, 272, 287, 301, 304, 319, 368, 386, 423, 433, 540, 590, 605, 618, 620, 629, 641, 649, 672, 681, 690, 694, 696, 697, 716, 726, 745, 748, 751, 760, 765, 775, 777, 780, 792, 799, 805, 810, 825, 829, 836, 844, 850, 876, 880, 882, 888, 899, 914, 924, 929, 932, 935, 967, 971, 1004, 1013, 1015, 1023}"), parseBitSet("{3, 8, 18, 29, 33, 65, 90, 101, 109, 117, 125, 127, 140, 170, 190, 192, 209, 213, 218, 226, 271, 272, 286, 287, 301, 304, 319, 386, 423, 433, 566, 590, 605, 618, 629, 641, 646, 649, 672, 690, 694, 696, 716, 726, 745, 748, 765, 775, 777, 780, 783, 792, 805, 810, 825, 829, 836, 844, 850, 876, 882, 899, 914, 924, 932, 934, 956, 967, 971, 994, 1004, 1013, 1015, 1023}"), parseBitSet("{3, 18, 26, 32, 33, 43, 140, 155, 188, 189, 226, 238, 262, 267, 287, 315, 319, 326, 375, 450, 577, 629, 644, 690, 719, 732, 745, 746, 751, 775, 847, 850, 881, 959, 971, 995, 1015, 1019}"), parseBitSet("{3, 18, 33, 192, 319, 745, 780, 882}"), parseBitSet("{3, 13, 18, 22, 26, 29, 33, 43, 71, 85, 90, 101, 103, 109, 117, 118, 125, 127, 140, 145, 153, 155, 182, 188, 189, 190, 199, 218, 225, 226, 238, 269, 272, 286, 287, 301, 304, 315, 319, 326, 370, 375, 386, 408, 423, 433, 450, 493, 502, 556, 566, 577, 590, 598, 605, 617, 618, 629, 644, 649, 672, 679, 690, 691, 694, 696, 716, 719, 727, 732, 745, 748, 751, 760, 762, 765, 775, 777, 783, 805, 806, 810, 821, 829, 844, 847, 850, 876, 888, 899, 914, 923, 924, 926, 927, 929, 934, 956, 959, 966, 971, 990, 995, 1006, 1013, 1015, 1019}"), parseBitSet("{3, 18, 29, 33, 53, 65, 90, 105, 125, 192, 203, 269, 271, 272, 293, 301, 319, 345, 364, 376, 386, 433, 540, 569, 590, 605, 618, 641, 649, 672, 675, 681, 696, 745, 748, 765, 780, 790, 798, 799, 801, 805, 825, 829, 836, 837, 844, 853, 876, 882, 891, 899, 914, 924, 932, 967, 996, 1004, 1013}"), parseBitSet("{3, 18, 33, 192, 319, 745, 780, 882}"), parseBitSet("{3, 18, 33, 192, 319, 745, 780, 882}"), parseBitSet("{3, 18, 26, 32, 33, 43, 140, 155, 188, 189, 226, 238, 262, 267, 287, 315, 319, 326, 375, 450, 577, 629, 644, 690, 719, 732, 745, 746, 751, 775, 847, 850, 881, 959, 971, 995, 1015, 1019}"), parseBitSet("{3, 18, 29, 33, 90, 105, 125, 272, 280, 301, 433, 521, 590, 618, 651, 672, 696, 698, 745, 760, 829, 844, 876, 890, 899, 924, 1013}")}; String filename = "data/mdl/fingerprints_from_modelbuilder3d.sdf"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); List<IBitFingerprint> data = new TemplateExtractor().makeFingerprintsFromSdf(true, false, new HashMap<String, Integer>(), new BufferedReader(new InputStreamReader(ins)), 10); QueryChemObject obj = new QueryChemObject(DefaultChemObjectBuilder.getInstance()); obj.getBuilder(); for (int i = 0; i < data.size(); i++) { IBitFingerprint bs = data.get(i); Assert.assertEquals(expected[i], bs.asBitSet()); } }
/** * Returns a Map with the IChemObject's properties. * *@return The object's properties as an Hashtable *@see #addProperties */ @Override public Map<Object, Object> getProperties() { return lazyProperties(); }
/** * Returns the number of ChemObjectListeners registered with this object. * *@return the number of registered listeners. */ @Override public int getListenerCount() { if (chemObjectListeners == null) { return 0; } return lazyChemObjectListeners().size(); }
/** * Sets the identifier (ID) of this object. * *@param identifier a String representing the ID value *@see #getID */ @Override public void setID(String identifier) { this.identifier = identifier; notifyChanged(); }
/** * This should be triggered by an method that changes the content of an object * to that the registered listeners can react to it. */ @Override public void notifyChanged() { if (getNotification() && getListenerCount() > 0) { List<IChemObjectListener> listeners = lazyChemObjectListeners(); for (Object listener : listeners) { ((IChemObjectListener) listener).stateChanged(new QueryChemObjectChangeEvent(this)); } } }
/** * Sets a property for a IChemObject. * *@param description An object description of the property (most likely a * unique string) *@param property An object with the property itself *@see #getProperty *@see #removeProperty */ @Override public void setProperty(Object description, Object property) { lazyProperties().put(description, property); notifyChanged(); }
@Test public void testAnonFingerprints() throws Exception { BitSet[] expected = new BitSet[]{ parseBitSet("{148, 206, 392, 542, 637, 742, 752, 830}"), parseBitSet("{148, 206, 392, 542, 637, 742, 752, 830}"), parseBitSet("{148, 206, 392, 542, 637, 742, 752, 830}"), parseBitSet("{148, 206, 392, 542, 637, 742, 752, 830}"), parseBitSet("{148, 206, 392, 542, 637, 742, 752, 830}"), parseBitSet("{148, 206, 392, 542, 637, 742, 752, 830}"), parseBitSet("{148, 206, 392, 542, 637, 742, 752, 830}"), parseBitSet("{148, 206, 392, 542, 637, 742, 752, 830}"), parseBitSet("{148, 206, 392, 542, 637, 742, 752, 830}"), parseBitSet("{148, 206, 392, 542, 637, 742, 752, 830}")}; String filename = "data/mdl/fingerprints_from_modelbuilder3d.sdf"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); List<IBitFingerprint> data = new TemplateExtractor().makeFingerprintsFromSdf(true, true, new HashMap<String, Integer>(), new BufferedReader(new InputStreamReader(ins)), 10); QueryChemObject obj = new QueryChemObject(DefaultChemObjectBuilder.getInstance()); obj.getBuilder(); for (int i = 0; i < data.size(); i++) { IBitFingerprint bs = data.get(i); Assert.assertEquals(expected[i], bs.asBitSet()); } }
/** * Returns a property for the IChemObject. * *@param description An object description of the property (most likely a * unique string) *@return The object containing the property. Returns null if * propert is not set. *@see #setProperty *@see #removeProperty */ @Override public <T> T getProperty(Object description) { // can't check the type @SuppressWarnings("unchecked") T value = (T) lazyProperties().get(description); return value; }
/** * Use this to add yourself to this IChemObject as a listener. In order to do * so, you must implement the ChemObjectListener Interface. * *@param col the ChemObjectListener *@see #removeListener */ @Override public void addListener(IChemObjectListener col) { List<IChemObjectListener> listeners = lazyChemObjectListeners(); if (!listeners.contains(col)) { listeners.add(col); } // Should we throw an exception if col is already in here or // just silently ignore it? }
/** *{@inheritDoc} */ @Override public void setFlag(int mask, boolean value) { // set/unset a bit in the flags value if (value) flags |= mask; else flags &= ~(mask); notifyChanged(); }
/** * Removes a property for a IChemObject. * *@param description The object description of the property (most likely a * unique string) *@see #setProperty *@see #getProperty */ @Override public void removeProperty(Object description) { if (properties == null) { return; } if (lazyProperties().remove(description) != null) notifyChanged(); }
/** *{@inheritDoc} */ @Override public <T> T getProperty(Object description, Class<T> c) { Object value = lazyProperties().get(description); if (c.isInstance(value)) { @SuppressWarnings("unchecked") T typed = (T) value; return typed; } else if (value != null) { throw new IllegalArgumentException("attempted to access a property of incorrect type, expected " + c.getSimpleName() + " got " + value.getClass().getSimpleName()); } return null; }
/** * Clones this query bond object, including clones of the atoms between which the * query bond is defined. * * @return The cloned object */ @Override public IQueryBond clone() throws CloneNotSupportedException { QueryBond clone = (QueryBond) super.clone(); // clone all the Atoms if (atoms != null) { clone.atoms = new IAtom[atoms.length]; for (int f = 0; f < atoms.length; f++) { if (atoms[f] != null) { clone.atoms[f] = (IAtom) (atoms[f]).clone(); } } } return clone; }
/** * Use this to remove a ChemObjectListener from the ListenerList of this * IChemObject. It will then not be notified of change in this object anymore. * *@param col The ChemObjectListener to be removed *@see #addListener */ @Override public void removeListener(IChemObjectListener col) { if (chemObjectListeners == null) { return; } List<IChemObjectListener> listeners = lazyChemObjectListeners(); if (listeners.contains(col)) { listeners.remove(col); } }
public IQueryAtomContainer clone() throws CloneNotSupportedException { IAtom[] newAtoms; IQueryAtomContainer clone = (IQueryAtomContainer) super.clone();