Update of /cvsroot/cdk/cdk/src/org/openscience/cdk/qsar
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14758/src/org/openscience/cdk/qsar
Modified Files:
WeightDescriptor.java
Log Message:
fixed bug 1178447, now used wild card symbol for MW calculation, and added test file
Index: WeightDescriptor.java
===================================================================
RCS file: /cvsroot/cdk/cdk/src/org/openscience/cdk/qsar/WeightDescriptor.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- WeightDescriptor.java 28 Feb 2005 12:09:35 -0000 1.11
+++ WeightDescriptor.java 11 Apr 2005 10:29:57 -0000 1.12
@@ -34,12 +34,13 @@
import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.qsar.result.*;
+import org.openscience.cdk.config.IsotopeFactory;
import java.util.Map;
import java.util.Hashtable;
/**
- * Descriptor based on the weight of atoms of a certain element type. If no
- * element is specified, the returned value is the molecular weight.
+ * Descriptor 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.
*
* <p>This descriptor uses these parameters:
* <table border="1">
@@ -50,8 +51,8 @@
* </tr>
* <tr>
* <td>elementSymbol</td>
- * <td>null</td>
- * <td>If null, returns the molecular weight, otherwise the weight for the given element</td>
+ * <td>*</td>
+ * <td>If *, returns the molecular weight, otherwise the weight for the given element</td>
* </tr>
* </table>
*
@@ -62,10 +63,10 @@
*/
public class WeightDescriptor implements Descriptor {
- private String elementName = null;
+ private String elementName = "*";
/**
- * Constructor for the AtomCountDescriptor object
+ * Constructor for the WeightDescriptor object
*/
public WeightDescriptor() { }
@@ -78,7 +79,7 @@
};
/**
- * Sets the parameters attribute of the AtomCountDescriptor object
+ * Sets the parameters attribute of the WeightDescriptor object
*
*@param params The new parameters value
*@exception CDKException Description of the Exception
@@ -96,7 +97,7 @@
/**
- * Gets the parameters attribute of the AtomCountDescriptor object
+ * Gets the parameters attribute of the WeightDescriptor object
*
*@return The parameters value
*/
@@ -118,28 +119,40 @@
public DescriptorValue calculate(AtomContainer container) {
double weight = 0;
Atom[] atoms = container.getAtoms();
- if (elementName == "") {
- for (int i = 0; i < atoms.length; i++) {
- weight += container.getAtomAt(i).getExactMass();
- weight += (container.getAtomAt(i).getHydrogenCount() * 1.00782504);
+ 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().getMajorIsotope( container.getAtomAt(i).getSymbol() ).getExactMass();
+ weight += (container.getAtomAt(i).getHydrogenCount() * 1.00782504);
+ }
+ } catch (Exception e) {
+ System.out.println(e.toString());
}
-
}
- else if (elementName == "H") {
- for (int i = 0; i < atoms.length; i++) {
- if (container.getAtomAt(i).getSymbol().equals(elementName)) {
- weight += container.getAtomAt(i).getExactMass();
- }
- else {
- weight += (container.getAtomAt(i).getHydrogenCount() * 1.00782504);
+ else if (elementName.equals("H")) {
+ try {
+ for (int i = 0; i < atoms.length; i++) {
+ if (container.getAtomAt(i).getSymbol().equals(elementName)) {
+ weight += IsotopeFactory.getInstance().getMajorIsotope( container.getAtomAt(i).getSymbol() ).getExactMass();
+ }
+ else {
+ weight += (container.getAtomAt(i).getHydrogenCount() * 1.00782504);
+ }
}
+ } catch (Exception e) {
+ System.out.println(e.toString());
}
}
else {
- for (int i = 0; i < atoms.length; i++) {
- if (container.getAtomAt(i).getSymbol().equals(elementName)) {
- weight += container.getAtomAt(i).getExactMass();
+ try {
+ for (int i = 0; i < atoms.length; i++) {
+ if (container.getAtomAt(i).getSymbol().equals(elementName)) {
+ weight += IsotopeFactory.getInstance().getMajorIsotope( container.getAtomAt(i).getSymbol() ).getExactMass();
+ }
}
+ } catch (Exception e) {
+ System.out.println(e.toString());
}
}
return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), new DoubleResult(weight));
@@ -147,7 +160,7 @@
/**
- * Gets the parameterNames attribute of the AtomCountDescriptor object
+ * Gets the parameterNames attribute of the WeightDescriptor object
*
*@return The parameterNames value
*/
@@ -159,7 +172,7 @@
/**
- * Gets the parameterType attribute of the AtomCountDescriptor object
+ * Gets the parameterType attribute of the WeightDescriptor object
*
*@param name Description of the Parameter
*@return The parameterType value
|