From: <eg...@us...> - 2006-07-06 11:13:05
|
Revision: 6613 Author: egonw Date: 2006-07-06 04:12:38 -0700 (Thu, 06 Jul 2006) ViewCVS: http://svn.sourceforge.net/cdk/?rev=6613&view=rev Log Message: ----------- Moved another IMolecularDescriptor to the right package Modified Paths: -------------- trunk/cdk/src/org/openscience/cdk/qsar/descriptors/molecular/RuleOfFiveDescriptor.java trunk/cdk/src/org/openscience/cdk/test/io/cml/CML2WriterTest.java Added Paths: ----------- trunk/cdk/src/org/openscience/cdk/qsar/descriptors/molecular/WeightDescriptor.java trunk/cdk/src/org/openscience/cdk/test/qsar/descriptors/molecular/WeightDescriptorTest.java Removed Paths: ------------- trunk/cdk/src/org/openscience/cdk/qsar/descriptors/atomic/WeightDescriptor.java trunk/cdk/src/org/openscience/cdk/test/qsar/descriptors/atomic/WeightDescriptorTest.java Deleted: trunk/cdk/src/org/openscience/cdk/qsar/descriptors/atomic/WeightDescriptor.java =================================================================== --- trunk/cdk/src/org/openscience/cdk/qsar/descriptors/atomic/WeightDescriptor.java 2006-07-06 08:10:58 UTC (rev 6612) +++ trunk/cdk/src/org/openscience/cdk/qsar/descriptors/atomic/WeightDescriptor.java 2006-07-06 11:12:38 UTC (rev 6613) @@ -1,202 +0,0 @@ -/* - * $RCSfile$ - * $Author$ - * $Date$ - * $Revision$ - * - * Copyright (C) 2004-2006 The Chemistry Development Kit (CDK) project - * - * Contact: cdk...@li... - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - */ -package org.openscience.cdk.qsar.descriptors.atomic; - -import org.openscience.cdk.config.IsotopeFactory; -import org.openscience.cdk.exception.CDKException; -import org.openscience.cdk.interfaces.IAtomContainer; -import org.openscience.cdk.qsar.DescriptorSpecification; -import org.openscience.cdk.qsar.DescriptorValue; -import org.openscience.cdk.qsar.IMolecularDescriptor; -import org.openscience.cdk.qsar.result.DoubleResult; - -/** - * IDescriptor based on the weight of atoms of a certain element type. - * - * If the wild-card symbol * - * is specified, the returned value is the molecular weight. - * If an invalid element symbol is specified, the return value is - * 0 and no exception is thrown - * <p> - * - * <p>This descriptor uses these parameters: - * <table border="1"> - * <tr> - * <td>Name</td> - * <td>Default</td> - * <td>Description</td> - * </tr> - * <tr> - * <td>elementSymbol</td> - * <td>*</td> - * <td>If *, returns the molecular weight, otherwise the weight for the given element</td> - * </tr> - * </table> - * - * @author mfe4 - * @cdk.created 2004-11-13 - * @cdk.module qsar - * @cdk.set qsar-descriptors - * @cdk.dictref qsar-descriptors:weight - */ -public class WeightDescriptor implements IMolecularDescriptor { - - private String elementName = "*"; - - /** - * Constructor for the WeightDescriptor object. - */ - public WeightDescriptor() { } - - /** - * Returns a <code>Map</code> which specifies which descriptor is implemented by this class. - * - * These fields are used in the map: - * <ul> - * <li>Specification-Reference: refers to an entry in a unique dictionary - * <li>Implementation-Title: anything - * <li>Implementation-Identifier: a unique identifier for this version of - * this class - * <li>Implementation-Vendor: CDK, JOELib, or anything else - * </ul> - * - * @return An object containing the descriptor specification - */ - public DescriptorSpecification getSpecification() { - return new DescriptorSpecification( - "http://www.blueobelisk.org/ontologies/chemoinformatics-algorithms/#weight", - this.getClass().getName(), - "$Id$", - "The Chemistry Development Kit"); - }; - - /** - * Sets the parameters attribute of the WeightDescriptor object. - * - *@param params The new parameters value - *@throws CDKException if more than 1 parameter is specified or if the parameter - *is not of type String - *@see #getParameters - */ - public void setParameters(Object[] params) throws CDKException { - if (params.length > 1) { - throw new CDKException("weight only expects one parameter"); - } - if (!(params[0] instanceof String)) { - throw new CDKException("The parameter must be of type String"); - } - // ok, all should be fine - elementName = (String) params[0]; - } - - - /** - * Gets the parameters attribute of the WeightDescriptor object. - * - * @return The parameters value - * @see #setParameters - */ - public Object[] getParameters() { - // return the parameters as used for the descriptor calculation - Object[] params = new Object[1]; - params[0] = elementName; - return params; - } - - - /** - * Calculate the weight of specified element type in the supplied {@link IAtomContainer}. - * - * @param container The AtomContainer for which this descriptor is to be calculated. If 'H' - * is specified as the element symbol make sure that the AtomContainer has hydrogens. - *@return The total weight of atoms of the specified element type - */ - - public DescriptorValue calculate(IAtomContainer container) { - double weight = 0; - org.openscience.cdk.interfaces.IAtom[] atoms = container.getAtoms(); - if (elementName.equals("*")) { - try { - for (int i = 0; i < atoms.length; i++) { - //System.out.println("WEIGHT: "+container.getAtomAt(i).getSymbol() +" " +IsotopeFactory.getInstance().getMajorIsotope( container.getAtomAt(i).getSymbol() ).getExactMass()); - weight += IsotopeFactory.getInstance(container.getBuilder()).getMajorIsotope( container.getAtomAt(i).getSymbol() ).getExactMass(); - weight += (container.getAtomAt(i).getHydrogenCount() * 1.00782504); - } - } catch (Exception e) { - System.out.println(e.toString()); - } - } - else if (elementName.equals("H")) { - try { - for (int i = 0; i < atoms.length; i++) { - if (container.getAtomAt(i).getSymbol().equals(elementName)) { - weight += IsotopeFactory.getInstance(container.getBuilder()).getMajorIsotope( container.getAtomAt(i).getSymbol() ).getExactMass(); - } - else { - weight += (container.getAtomAt(i).getHydrogenCount() * 1.00782504); - } - } - } catch (Exception e) { - System.out.println(e.toString()); - } - } - else { - try { - for (int i = 0; i < atoms.length; i++) { - if (container.getAtomAt(i).getSymbol().equals(elementName)) { - weight += IsotopeFactory.getInstance(container.getBuilder()).getMajorIsotope( container.getAtomAt(i).getSymbol() ).getExactMass(); - } - } - } catch (Exception e) { - System.out.println(e.toString()); - } - } - return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), new DoubleResult(weight)); - } - - - /** - * Gets the parameterNames attribute of the WeightDescriptor object. - * - *@return The parameterNames value - */ - public String[] getParameterNames() { - String[] params = new String[1]; - params[0] = "elementSymbol"; - return params; - } - - - /** - * Gets the parameterType attribute of the WeightDescriptor object. - * - *@param name Description of the Parameter - *@return An Object whose class is that of the parameter requested - */ - public Object getParameterType(String name) { - return ""; - } -} - Modified: trunk/cdk/src/org/openscience/cdk/qsar/descriptors/molecular/RuleOfFiveDescriptor.java =================================================================== --- trunk/cdk/src/org/openscience/cdk/qsar/descriptors/molecular/RuleOfFiveDescriptor.java 2006-07-06 08:10:58 UTC (rev 6612) +++ trunk/cdk/src/org/openscience/cdk/qsar/descriptors/molecular/RuleOfFiveDescriptor.java 2006-07-06 11:12:38 UTC (rev 6613) @@ -28,7 +28,6 @@ import org.openscience.cdk.qsar.DescriptorSpecification; import org.openscience.cdk.qsar.DescriptorValue; import org.openscience.cdk.qsar.IMolecularDescriptor; -import org.openscience.cdk.qsar.descriptors.atomic.WeightDescriptor; import org.openscience.cdk.qsar.result.DoubleResult; import org.openscience.cdk.qsar.result.IntegerResult; @@ -139,7 +138,7 @@ *@return The number of failures of the Lipinski rule *@throws CDKException if the following descriptors throw an exception: * {@link org.openscience.cdk.qsar.descriptors.molecular.XLogPDescriptor}, {@link HBondAcceptorCountDescriptor}, {@link HBondDonorCountDescriptor}, - * {@link org.openscience.cdk.qsar.descriptors.atomic.WeightDescriptor}, {@link org.openscience.cdk.qsar.descriptors.molecular.RotatableBondsCountDescriptor}, + * {@link org.openscience.cdk.qsar.descriptors.molecular.WeightDescriptor}, {@link org.openscience.cdk.qsar.descriptors.molecular.RotatableBondsCountDescriptor}, */ public DescriptorValue calculate(IAtomContainer mol) throws CDKException { Copied: trunk/cdk/src/org/openscience/cdk/qsar/descriptors/molecular/WeightDescriptor.java (from rev 6609, trunk/cdk/src/org/openscience/cdk/qsar/descriptors/atomic/WeightDescriptor.java) =================================================================== --- trunk/cdk/src/org/openscience/cdk/qsar/descriptors/molecular/WeightDescriptor.java (rev 0) +++ trunk/cdk/src/org/openscience/cdk/qsar/descriptors/molecular/WeightDescriptor.java 2006-07-06 11:12:38 UTC (rev 6613) @@ -0,0 +1,202 @@ +/* + * $RCSfile$ + * $Author$ + * $Date$ + * $Revision$ + * + * Copyright (C) 2004-2006 The Chemistry Development Kit (CDK) project + * + * Contact: cdk...@li... + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ +package org.openscience.cdk.qsar.descriptors.molecular; + +import org.openscience.cdk.config.IsotopeFactory; +import org.openscience.cdk.exception.CDKException; +import org.openscience.cdk.interfaces.IAtomContainer; +import org.openscience.cdk.qsar.DescriptorSpecification; +import org.openscience.cdk.qsar.DescriptorValue; +import org.openscience.cdk.qsar.IMolecularDescriptor; +import org.openscience.cdk.qsar.result.DoubleResult; + +/** + * IDescriptor based on the weight of atoms of a certain element type. + * + * If the wild-card symbol * + * is specified, the returned value is the molecular weight. + * If an invalid element symbol is specified, the return value is + * 0 and no exception is thrown + * <p> + * + * <p>This descriptor uses these parameters: + * <table border="1"> + * <tr> + * <td>Name</td> + * <td>Default</td> + * <td>Description</td> + * </tr> + * <tr> + * <td>elementSymbol</td> + * <td>*</td> + * <td>If *, returns the molecular weight, otherwise the weight for the given element</td> + * </tr> + * </table> + * + * @author mfe4 + * @cdk.created 2004-11-13 + * @cdk.module qsar + * @cdk.set qsar-descriptors + * @cdk.dictref qsar-descriptors:weight + */ +public class WeightDescriptor implements IMolecularDescriptor { + + private String elementName = "*"; + + /** + * Constructor for the WeightDescriptor object. + */ + public WeightDescriptor() { } + + /** + * Returns a <code>Map</code> which specifies which descriptor is implemented by this class. + * + * These fields are used in the map: + * <ul> + * <li>Specification-Reference: refers to an entry in a unique dictionary + * <li>Implementation-Title: anything + * <li>Implementation-Identifier: a unique identifier for this version of + * this class + * <li>Implementation-Vendor: CDK, JOELib, or anything else + * </ul> + * + * @return An object containing the descriptor specification + */ + public DescriptorSpecification getSpecification() { + return new DescriptorSpecification( + "http://www.blueobelisk.org/ontologies/chemoinformatics-algorithms/#weight", + this.getClass().getName(), + "$Id$", + "The Chemistry Development Kit"); + }; + + /** + * Sets the parameters attribute of the WeightDescriptor object. + * + *@param params The new parameters value + *@throws CDKException if more than 1 parameter is specified or if the parameter + *is not of type String + *@see #getParameters + */ + public void setParameters(Object[] params) throws CDKException { + if (params.length > 1) { + throw new CDKException("weight only expects one parameter"); + } + if (!(params[0] instanceof String)) { + throw new CDKException("The parameter must be of type String"); + } + // ok, all should be fine + elementName = (String) params[0]; + } + + + /** + * Gets the parameters attribute of the WeightDescriptor object. + * + * @return The parameters value + * @see #setParameters + */ + public Object[] getParameters() { + // return the parameters as used for the descriptor calculation + Object[] params = new Object[1]; + params[0] = elementName; + return params; + } + + + /** + * Calculate the weight of specified element type in the supplied {@link IAtomContainer}. + * + * @param container The AtomContainer for which this descriptor is to be calculated. If 'H' + * is specified as the element symbol make sure that the AtomContainer has hydrogens. + *@return The total weight of atoms of the specified element type + */ + + public DescriptorValue calculate(IAtomContainer container) { + double weight = 0; + org.openscience.cdk.interfaces.IAtom[] atoms = container.getAtoms(); + if (elementName.equals("*")) { + try { + for (int i = 0; i < atoms.length; i++) { + //System.out.println("WEIGHT: "+container.getAtomAt(i).getSymbol() +" " +IsotopeFactory.getInstance().getMajorIsotope( container.getAtomAt(i).getSymbol() ).getExactMass()); + weight += IsotopeFactory.getInstance(container.getBuilder()).getMajorIsotope( container.getAtomAt(i).getSymbol() ).getExactMass(); + weight += (container.getAtomAt(i).getHydrogenCount() * 1.00782504); + } + } catch (Exception e) { + System.out.println(e.toString()); + } + } + else if (elementName.equals("H")) { + try { + for (int i = 0; i < atoms.length; i++) { + if (container.getAtomAt(i).getSymbol().equals(elementName)) { + weight += IsotopeFactory.getInstance(container.getBuilder()).getMajorIsotope( container.getAtomAt(i).getSymbol() ).getExactMass(); + } + else { + weight += (container.getAtomAt(i).getHydrogenCount() * 1.00782504); + } + } + } catch (Exception e) { + System.out.println(e.toString()); + } + } + else { + try { + for (int i = 0; i < atoms.length; i++) { + if (container.getAtomAt(i).getSymbol().equals(elementName)) { + weight += IsotopeFactory.getInstance(container.getBuilder()).getMajorIsotope( container.getAtomAt(i).getSymbol() ).getExactMass(); + } + } + } catch (Exception e) { + System.out.println(e.toString()); + } + } + return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), new DoubleResult(weight)); + } + + + /** + * Gets the parameterNames attribute of the WeightDescriptor object. + * + *@return The parameterNames value + */ + public String[] getParameterNames() { + String[] params = new String[1]; + params[0] = "elementSymbol"; + return params; + } + + + /** + * Gets the parameterType attribute of the WeightDescriptor object. + * + *@param name Description of the Parameter + *@return An Object whose class is that of the parameter requested + */ + public Object getParameterType(String name) { + return ""; + } +} + Property changes on: trunk/cdk/src/org/openscience/cdk/qsar/descriptors/molecular/WeightDescriptor.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native Modified: trunk/cdk/src/org/openscience/cdk/test/io/cml/CML2WriterTest.java =================================================================== --- trunk/cdk/src/org/openscience/cdk/test/io/cml/CML2WriterTest.java 2006-07-06 08:10:58 UTC (rev 6612) +++ trunk/cdk/src/org/openscience/cdk/test/io/cml/CML2WriterTest.java 2006-07-06 11:12:38 UTC (rev 6613) @@ -42,7 +42,7 @@ import org.openscience.cdk.protein.data.PDBAtom; import org.openscience.cdk.qsar.DescriptorValue; import org.openscience.cdk.qsar.IMolecularDescriptor; -import org.openscience.cdk.qsar.descriptors.atomic.WeightDescriptor; +import org.openscience.cdk.qsar.descriptors.molecular.WeightDescriptor; import org.openscience.cdk.templates.MoleculeFactory; import org.openscience.cdk.test.CDKTestCase; import org.openscience.cdk.tools.LoggingTool; Deleted: trunk/cdk/src/org/openscience/cdk/test/qsar/descriptors/atomic/WeightDescriptorTest.java =================================================================== --- trunk/cdk/src/org/openscience/cdk/test/qsar/descriptors/atomic/WeightDescriptorTest.java 2006-07-06 08:10:58 UTC (rev 6612) +++ trunk/cdk/src/org/openscience/cdk/test/qsar/descriptors/atomic/WeightDescriptorTest.java 2006-07-06 11:12:38 UTC (rev 6613) @@ -1,62 +0,0 @@ -/* $RCSfile$ - * $Author$ - * $Date$ - * $Revision$ - * - * Copyright (C) 2004-2006 The Chemistry Development Kit (CDK) project - * - * Contact: cdk...@li... - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - */ -package org.openscience.cdk.test.qsar.descriptors.atomic; - -import junit.framework.Test; -import junit.framework.TestSuite; -import org.openscience.cdk.AtomContainer; -import org.openscience.cdk.exception.CDKException; -import org.openscience.cdk.qsar.IMolecularDescriptor; -import org.openscience.cdk.qsar.descriptors.atomic.WeightDescriptor; -import org.openscience.cdk.qsar.result.DoubleResult; -import org.openscience.cdk.smiles.SmilesParser; -import org.openscience.cdk.test.CDKTestCase; - -/** - * TestSuite that runs a test for the AtomCountDescriptor. - * - * @cdk.module test-qsar - */ - -public class WeightDescriptorTest extends CDKTestCase { - - public WeightDescriptorTest() {} - - public static Test suite() { - return new TestSuite(WeightDescriptorTest.class); - } - - - public void testWeightDescriptor() throws ClassNotFoundException, CDKException, java.lang.Exception { - IMolecularDescriptor descriptor = new WeightDescriptor(); - Object[] params = {"*"}; - descriptor.setParameters(params); - SmilesParser sp = new SmilesParser(); - AtomContainer mol = sp.parseSmiles("CCC"); - assertEquals(44.06, ((DoubleResult)descriptor.calculate(mol).getValue()).doubleValue(), 0.1); - } - - -} - Copied: trunk/cdk/src/org/openscience/cdk/test/qsar/descriptors/molecular/WeightDescriptorTest.java (from rev 6609, trunk/cdk/src/org/openscience/cdk/test/qsar/descriptors/atomic/WeightDescriptorTest.java) =================================================================== --- trunk/cdk/src/org/openscience/cdk/test/qsar/descriptors/molecular/WeightDescriptorTest.java (rev 0) +++ trunk/cdk/src/org/openscience/cdk/test/qsar/descriptors/molecular/WeightDescriptorTest.java 2006-07-06 11:12:38 UTC (rev 6613) @@ -0,0 +1,62 @@ +/* $RCSfile$ + * $Author$ + * $Date$ + * $Revision$ + * + * Copyright (C) 2004-2006 The Chemistry Development Kit (CDK) project + * + * Contact: cdk...@li... + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ +package org.openscience.cdk.test.qsar.descriptors.molecular; + +import junit.framework.Test; +import junit.framework.TestSuite; +import org.openscience.cdk.AtomContainer; +import org.openscience.cdk.exception.CDKException; +import org.openscience.cdk.qsar.IMolecularDescriptor; +import org.openscience.cdk.qsar.descriptors.molecular.WeightDescriptor; +import org.openscience.cdk.qsar.result.DoubleResult; +import org.openscience.cdk.smiles.SmilesParser; +import org.openscience.cdk.test.CDKTestCase; + +/** + * TestSuite that runs a test for the AtomCountDescriptor. + * + * @cdk.module test-qsar + */ + +public class WeightDescriptorTest extends CDKTestCase { + + public WeightDescriptorTest() {} + + public static Test suite() { + return new TestSuite(WeightDescriptorTest.class); + } + + + public void testWeightDescriptor() throws ClassNotFoundException, CDKException, java.lang.Exception { + IMolecularDescriptor descriptor = new WeightDescriptor(); + Object[] params = {"*"}; + descriptor.setParameters(params); + SmilesParser sp = new SmilesParser(); + AtomContainer mol = sp.parseSmiles("CCC"); + assertEquals(44.06, ((DoubleResult)descriptor.calculate(mol).getValue()).doubleValue(), 0.1); + } + + +} + Property changes on: trunk/cdk/src/org/openscience/cdk/test/qsar/descriptors/molecular/WeightDescriptorTest.java ___________________________________________________________________ Name: svn:keywords + Author Date Id Revision Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |